diff --git a/bin/SSLDroid.apk b/bin/SSLDroid.apk index 7432a98..c691a50 100644 Binary files a/bin/SSLDroid.apk and b/bin/SSLDroid.apk differ diff --git a/bin/classes.dex b/bin/classes.dex index f54c7c0..09d31d0 100644 Binary files a/bin/classes.dex and b/bin/classes.dex differ diff --git a/bin/resources.ap_ b/bin/resources.ap_ index 40337c3..728932e 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 8b8d97a..de86a89 100644 --- a/res/layout/main.xml +++ b/res/layout/main.xml @@ -1,12 +1,29 @@ - + + + + + + + + + + + + + + + - - - \ No newline at end of file + android:layout_height="wrap_content" android:gravity="center" android:textSize="20sp" android:padding="20dp" android:text="@string/service_control" android:id="@+id/servicecontrollabel"/> + + + + + \ No newline at end of file diff --git a/res/values/strings.xml b/res/values/strings.xml index 1208a6e..15e5ca6 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -2,4 +2,12 @@ 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 + + Apply + PKCS12 password diff --git a/src/hu/blint/ssldroid/SSLDroid.java b/src/hu/blint/ssldroid/SSLDroid.java index 5ae8bb2..8c92d81 100644 --- a/src/hu/blint/ssldroid/SSLDroid.java +++ b/src/hu/blint/ssldroid/SSLDroid.java @@ -3,22 +3,60 @@ package hu.blint.ssldroid; import hu.blint.ssldroid.TcpProxy; import android.app.*; import android.content.Intent; +import android.content.SharedPreferences; import android.os.IBinder; import android.util.Log; +import android.widget.Toast; public class SSLDroid extends Service { final String TAG = "SSLDroid"; + public static final String PREFS_NAME = "MyPrefsFile"; TcpProxy tp; @Override public void onCreate() { - int listenPort = 9999; // port to listen on - int targetPort = 443; // port to connect to - String targetHost = "sogo.balabit.com"; // remote host - String keyFile = "/mnt/sdcard/blint-imaps.p12"; - String keyPass = "titkos"; - + + // 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; + //Toast.makeText(this, "SSLDroid Service Started", Toast.LENGTH_LONG).show(); createNotification(0, "SSLDroid is running", "SSLDroid service is running"); Log.d(TAG, "SSLDroid Service Started"); diff --git a/src/hu/blint/ssldroid/SSLDroidGui.java b/src/hu/blint/ssldroid/SSLDroidGui.java index e520eb2..a561749 100644 --- a/src/hu/blint/ssldroid/SSLDroidGui.java +++ b/src/hu/blint/ssldroid/SSLDroidGui.java @@ -2,16 +2,66 @@ package hu.blint.ssldroid; import android.app.Activity; import android.content.Intent; +import android.content.SharedPreferences; import android.os.Bundle; import android.util.Log; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; +import android.widget.TextView; +import android.widget.Toast; public class SSLDroidGui extends Activity implements OnClickListener { private static final String TAG = "SSLDroidGui"; - Button buttonStart, buttonStop, showLog; + public static final String PREFS_NAME = "MyPrefsFile"; + Button buttonStart, buttonStop, buttonApply; + public boolean saveSettings(){ + SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0); + SharedPreferences.Editor editor = settings.edit(); + + TextView localport = (TextView) findViewById(R.id.localport); + TextView remotehost = (TextView) findViewById(R.id.remotehost); + TextView remoteport = (TextView) findViewById(R.id.remoteport); + TextView pkcsfile = (TextView) findViewById(R.id.pkcsfile); + TextView pkcspass = (TextView) findViewById(R.id.pkcspass); + + String settingLocalport = localport.getText().toString(); + String settingRemotehost = remotehost.getText().toString(); + String settingRemoteport = remoteport.getText().toString(); + String settingPkcsfile = pkcsfile.getText().toString(); + String settingPkcspass = pkcspass.getText().toString(); + + if (settingLocalport.length() == 0) { + Toast.makeText(this, "Required local port parameter not setup, skipping save", 5).show(); + return false; + } + if (settingRemotehost.length() == 0){ + Toast.makeText(this, "Required remote host parameter not setup, skipping save", 5).show(); + return false; + } + if (settingRemoteport.length() == 0){ + Toast.makeText(this, "Required remote port parameter not setup, skipping save", 5).show(); + return false; + } + if (settingPkcsfile.length() == 0){ + Toast.makeText(this, "Required PKCS12 file parameter not setup, skipping save", 5).show(); + return false; + } + editor.putInt("0.localPort", Integer.parseInt(settingLocalport)); + //Log.d(TAG, "settingSave: '"+ settingLocalport+"'"); + editor.putString("0.remoteHost", settingRemotehost); + //Log.d(TAG, "settingSave: '"+ settingRemotehost+"'"); + editor.putInt("0.remotePort", Integer.parseInt(settingRemoteport)); + //Log.d(TAG, "settingSave: '"+ settingRemoteport+"'"); + editor.putString("0.pkcsFile", settingPkcsfile); + //Log.d(TAG, "settingSave: '"+ settingPkcsfile+"'"); + editor.putString("0.pkcsPass", settingPkcspass); + //Log.d(TAG, "settingSave: '"+ settingPkcspass+"'"); + editor.commit(); + return true; + } + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -19,21 +69,56 @@ public class SSLDroidGui extends Activity implements OnClickListener { buttonStart = (Button) findViewById(R.id.buttonStart); buttonStop = (Button) findViewById(R.id.buttonStop); + buttonApply = (Button) findViewById(R.id.buttonApply); buttonStart.setOnClickListener(this); buttonStop.setOnClickListener(this); + buttonApply.setOnClickListener(this); + + TextView localport = (TextView) findViewById(R.id.localport); + TextView remotehost = (TextView) findViewById(R.id.remotehost); + TextView remoteport = (TextView) findViewById(R.id.remoteport); + TextView pkcsfile = (TextView) findViewById(R.id.pkcsfile); + TextView pkcspass = (TextView) findViewById(R.id.pkcspass); + + // 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", ""); + + if (settingLocalport!=0) + localport.setText(String.valueOf(settingLocalport)); + if (settingRemotehost!="") + remotehost.setText(settingRemotehost); + if (settingRemoteport!=0) + remoteport.setText(String.valueOf(settingRemoteport)); + if (settingPkcsfile!="") + pkcsfile.setText(settingPkcsfile); + if (settingPkcspass!="") + pkcspass.setText(settingPkcspass); } public void onClick(View src) { switch (src.getId()) { case R.id.buttonStart: - Log.d(TAG, "onClick: starting service"); + Log.d(TAG, "Starting service"); startService(new Intent(this, SSLDroid.class)); break; case R.id.buttonStop: - Log.d(TAG, "onClick: stopping service"); + Log.d(TAG, "Stopping service"); stopService(new Intent(this, SSLDroid.class)); break; + case R.id.buttonApply: + Log.d(TAG, "Saving settings..."); + if (saveSettings()){ + Log.d(TAG, "Restarting service after setting save"); + stopService(new Intent(this, SSLDroid.class)); + startService(new Intent(this, SSLDroid.class)); + } + break; } } } \ No newline at end of file