diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 88ba21f..9b11f93 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -9,6 +9,8 @@ + diff --git a/bin/SSLDroid.apk b/bin/SSLDroid.apk index f25cb15..237d209 100644 Binary files a/bin/SSLDroid.apk and b/bin/SSLDroid.apk differ diff --git a/bin/classes.dex b/bin/classes.dex index f0c2b52..3820e59 100644 Binary files a/bin/classes.dex and b/bin/classes.dex differ diff --git a/bin/resources.ap_ b/bin/resources.ap_ index 728932e..ca8a129 100644 Binary files a/bin/resources.ap_ and b/bin/resources.ap_ differ diff --git a/res/layout/main.xml b/res/layout/main.xml index de86a89..097bbb0 100644 --- a/res/layout/main.xml +++ b/res/layout/main.xml @@ -3,27 +3,28 @@ android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" - android:gravity="center"> - - - + android:gravity="center" + android:paddingLeft="10dip" + android:paddingRight="10dip"> + + + + - - - + + + + + + + + - - - - - \ No newline at end of file diff --git a/res/layout/tunnel_details.xml b/res/layout/tunnel_details.xml new file mode 100644 index 0000000..5abf36c --- /dev/null +++ b/res/layout/tunnel_details.xml @@ -0,0 +1,68 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/res/layout/tunnel_list.xml b/res/layout/tunnel_list.xml new file mode 100644 index 0000000..994f278 --- /dev/null +++ b/res/layout/tunnel_list.xml @@ -0,0 +1,9 @@ + + + + + diff --git a/res/layout/tunnel_list_item.xml b/res/layout/tunnel_list_item.xml new file mode 100644 index 0000000..b0faba8 --- /dev/null +++ b/res/layout/tunnel_list_item.xml @@ -0,0 +1,14 @@ + + + + + + diff --git a/res/menu/main.xml b/res/menu/main.xml new file mode 100644 index 0000000..cfc1a96 --- /dev/null +++ b/res/menu/main.xml @@ -0,0 +1,7 @@ + + + + + + diff --git a/res/values/strings.xml b/res/values/strings.xml index 15e5ca6..b43a30f 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -3,11 +3,17 @@ Hello World, SSLDroidGui! SSLDroid Service Control - Local port to listen on - Remote host to connect to - Remote port to connect to - PKCS12 file to use for auth + Local port + Remote host + Remote port + PKCS12 file Apply - PKCS12 password + PKCS12 pass + Tunnel name + Add tunnel + Stop service + Start service + No tunnels configured yet + Delete tunnel diff --git a/src/hu/blint/ssldroid/SSLDroid.java b/src/hu/blint/ssldroid/SSLDroid.java index 0e3ff43..4a12e5e 100644 --- a/src/hu/blint/ssldroid/SSLDroid.java +++ b/src/hu/blint/ssldroid/SSLDroid.java @@ -3,75 +3,59 @@ package hu.blint.ssldroid; import hu.blint.ssldroid.TcpProxy; import android.app.*; import android.content.Intent; -import android.content.SharedPreferences; +import android.database.Cursor; import android.os.IBinder; import android.util.Log; -import android.widget.Toast; +import hu.blint.ssldroid.db.SSLDroidDbAdapter; public class SSLDroid extends Service { final String TAG = "SSLDroid"; - public static final String PREFS_NAME = "MyPrefsFile"; + public static final String PREFS_NAME = "SSLDroid"; TcpProxy tp[]; + private SSLDroidDbAdapter dbHelper; @Override public void onCreate() { - // Restore preferences - SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0); - int settingLocalport = settings.getInt("0.localPort", 0); - String settingRemotehost = settings.getString("0.remoteHost", ""); - int settingRemoteport = settings.getInt("0.remotePort", 0); - String settingPkcsfile = settings.getString("0.pkcsFile", ""); - String settingPkcspass = settings.getString("0.pkcsPass", ""); - - int listenPort; - int targetPort; - String targetHost; - String keyFile; - String keyPass; - - if (settingLocalport!=0) - listenPort = settingLocalport; - else { - Toast.makeText(this, "Please set up local port first", Toast.LENGTH_LONG).show(); - return; - } - if (settingRemotehost!="") - targetHost = settingRemotehost; - else { - Toast.makeText(this, "Please set up remote host first", Toast.LENGTH_LONG).show(); - return; - } - if (settingRemoteport!=0) - targetPort = settingRemoteport; - else { - Toast.makeText(this, "Please set up remote port first", Toast.LENGTH_LONG).show(); - return; - } - if (settingPkcsfile!="") - keyFile = settingPkcsfile; - else { - Toast.makeText(this, "Please set up PKCS12 file first", Toast.LENGTH_LONG).show(); - return; - } - keyPass = settingPkcspass; + dbHelper = new SSLDroidDbAdapter(this); + dbHelper.open(); + Cursor cursor = dbHelper.fetchAllTunnels(); - //Toast.makeText(this, "SSLDroid Service Started", Toast.LENGTH_LONG).show(); - createNotification(0, true, "SSLDroid is running", listenPort+"->"+targetHost+":"+targetPort); - Log.d(TAG, "SSLDroid Service Started"); - - //createNotification("test", "This is a test of the emergency broadcast system"); - - tp = new TcpProxy[2]; - try { - tp[0] = new TcpProxy(); - tp[0].serve(listenPort, targetHost, targetPort, keyFile, keyPass); - tp[1] = new TcpProxy(); - tp[1].serve(9998, "imaps.balabit.hu", 993, keyFile, keyPass); - } catch (Exception e) { - Log.d(TAG, "Error:" + e.toString()); + int tunnelcount = cursor.getCount(); + + //skip start if the db is empty yet + if (tunnelcount == 0) + return; + + tp = new TcpProxy[tunnelcount]; + + int i; + for (i=0; i 0) { + rowId = id; + } + } else { + dbHelper.updateTunnel(rowId, sName, sLocalport, sRemotehost, sRemoteport, sPkcsfile, sPkcspass); + } + Log.d("SSLDroid", "Saving settings..."); + + //restart the service + stopService(new Intent(this, SSLDroid.class)); + startService(new Intent(this, SSLDroid.class)); + Log.d("SSLDroid", "Restarting service after settings save..."); + + } +} + diff --git a/src/hu/blint/ssldroid/TcpProxy.java b/src/hu/blint/ssldroid/TcpProxy.java index a928be4..510b966 100644 --- a/src/hu/blint/ssldroid/TcpProxy.java +++ b/src/hu/blint/ssldroid/TcpProxy.java @@ -68,5 +68,8 @@ public class TcpProxy { Log.d("SSLDroid", "Stopping service"); } + public boolean isAlive(){ + return ss.isBound(); + } } diff --git a/src/hu/blint/ssldroid/db/SSLDroidDbAdapter.java b/src/hu/blint/ssldroid/db/SSLDroidDbAdapter.java new file mode 100644 index 0000000..1e2d690 --- /dev/null +++ b/src/hu/blint/ssldroid/db/SSLDroidDbAdapter.java @@ -0,0 +1,109 @@ +package hu.blint.ssldroid.db; + +import android.content.ContentValues; +import android.content.Context; +import android.database.Cursor; +import android.database.SQLException; +import android.database.sqlite.SQLiteDatabase; + +public class SSLDroidDbAdapter { + + // Database fields + public static final String KEY_ROWID = "_id"; + public static final String KEY_NAME = "name"; + public static final String KEY_LOCALPORT = "localport"; + public static final String KEY_REMOTEHOST = "remotehost"; + public static final String KEY_REMOTEPORT = "remoteport"; + public static final String KEY_PKCSFILE = "pkcsfile"; + public static final String KEY_PKCSPASS = "pkcspass"; + private static final String DATABASE_TABLE = "tunnels"; + private Context context; + private SQLiteDatabase database; + private SSLDroidDbHelper dbHelper; + + public SSLDroidDbAdapter(Context context) { + this.context = context; + } + + public SSLDroidDbAdapter open() throws SQLException { + dbHelper = new SSLDroidDbHelper(context); + database = dbHelper.getWritableDatabase(); + return this; + } + + public void close() { + dbHelper.close(); + database.close(); + } + + /** + * Create a new tunnel If the tunnel is successfully created return the new + * rowId for that note, otherwise return a -1 to indicate failure. + */ + public long createTunnel(String name, int localport, String remotehost, int remoteport, + String pkcsfile, String pkcspass) { + ContentValues initialValues = createContentValues(name, localport, remotehost, + remoteport, pkcsfile, pkcspass); + + return database.insert(DATABASE_TABLE, null, initialValues); + } + + /** + * Update the tunnel + */ + public boolean updateTunnel(long rowId, String name, int localport, String remotehost, + int remoteport, String pkcsfile, String pkcspass) { + ContentValues updateValues = createContentValues(name, localport, remotehost, + remoteport, pkcsfile, pkcspass); + + return database.update(DATABASE_TABLE, updateValues, KEY_ROWID + "=" + + rowId, null) > 0; + } + + /** + * Deletes tunnel + */ + public boolean deleteTunnel(long rowId) { + return database.delete(DATABASE_TABLE, KEY_ROWID + "=" + rowId, null) > 0; + } + + /** + * Return a Cursor over the list of all tunnel in the database + * + * @return Cursor over all notes + */ + public Cursor fetchAllTunnels() { + return database.query(DATABASE_TABLE, new String[] { KEY_ROWID, + KEY_NAME, KEY_LOCALPORT, KEY_REMOTEHOST, KEY_REMOTEPORT, KEY_PKCSFILE, + KEY_PKCSPASS }, null, null, null, null, null); + } + + /** + * Return a Cursor positioned at the defined tunnel + */ + public Cursor fetchTunnel(long rowId) throws SQLException { + Cursor mCursor = database.query(true, DATABASE_TABLE, new String[] { + KEY_ROWID, KEY_NAME, KEY_LOCALPORT, KEY_REMOTEHOST, KEY_REMOTEPORT, + KEY_PKCSFILE, KEY_PKCSPASS }, + KEY_ROWID + "=" + rowId, null, null, null, null, null); + if (mCursor != null) { + mCursor.moveToFirst(); + } + return mCursor; + } + + private ContentValues createContentValues(String name, int localport, String remotehost, int remoteport, + String pkcsfile, String pkcspass) { + ContentValues values = new ContentValues(); + values.put(KEY_NAME, name); + values.put(KEY_LOCALPORT, localport); + values.put(KEY_REMOTEHOST, remotehost); + values.put(KEY_REMOTEPORT, remoteport); + values.put(KEY_REMOTEPORT, remoteport); + values.put(KEY_PKCSFILE, pkcsfile); + values.put(KEY_PKCSPASS, pkcspass); + return values; + } +} + + diff --git a/src/hu/blint/ssldroid/db/SSLDroidDbHelper.java b/src/hu/blint/ssldroid/db/SSLDroidDbHelper.java new file mode 100644 index 0000000..0d2446e --- /dev/null +++ b/src/hu/blint/ssldroid/db/SSLDroidDbHelper.java @@ -0,0 +1,39 @@ +package hu.blint.ssldroid.db; + +import android.content.Context; +import android.database.sqlite.SQLiteDatabase; +import android.database.sqlite.SQLiteOpenHelper; + +public class SSLDroidDbHelper extends SQLiteOpenHelper { + private static final String DATABASE_NAME = "applicationdata"; + + private static final int DATABASE_VERSION = 1; + + // Database creation sql statement + private static final String DATABASE_CREATE = "create table tunnels (_id integer primary key autoincrement, " + + "name text not null, localport integer not null, remotehost text not null, " + + "remoteport integer not null, pkcsfile text not null, pkcspass text );"; + + public SSLDroidDbHelper(Context context) { + super(context, DATABASE_NAME, null, DATABASE_VERSION); + } + + // Method is called during creation of the database + @Override + public void onCreate(SQLiteDatabase database) { + database.execSQL(DATABASE_CREATE); + } + + // Method is called during an update of the database, e.g. if you increase + // the database version + @Override + public void onUpgrade(SQLiteDatabase database, int oldVersion, + int newVersion) { + /* Log.w(SSLDroidDbHelper.class.getName(), + "Upgrading database from version " + oldVersion + " to " + + newVersion + ", which will destroy all old data"); + database.execSQL("DROP TABLE IF EXISTS todo"); + onCreate(database); */ + } +} +