1
0
mirror of https://github.com/moparisthebest/SSLDroid synced 2025-01-05 10:28:00 -05:00

Support for local settings

Signed-off-by: Balint Kovacs <blint@blint.hu>
This commit is contained in:
Balint Kovacs 2011-04-15 11:50:00 +02:00
parent 02465d3450
commit a447f4419f
7 changed files with 162 additions and 14 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,12 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center">
<TableRow android:id="@+id/tableRow1" android:layout_width="wrap_content" android:layout_height="wrap_content">
<TextView android:text="@string/local_port" android:gravity="left" android:layout_height="wrap_content" android:layout_width="wrap_content" android:textSize="15sp" android:id="@+id/localportlabel"></TextView>
<EditText android:layout_width="70dip" android:text="@string/empty" android:id="@+id/localport" android:digits="0123456789" android:layout_height="35dip"></EditText>
</TableRow>
<TextView android:text="@string/remote_host" android:gravity="center" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="15sp" android:id="@+id/remotehostlabel"></TextView>
<EditText android:layout_width="wrap_content" android:id="@+id/remotehost" android:text="@string/empty" android:layout_height="35dip"></EditText>
<TableRow android:id="@+id/tableRow3" android:layout_width="wrap_content" android:layout_height="wrap_content">
<TextView android:text="@string/remote_port" android:gravity="center" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="15sp" android:id="@+id/remoteportlabel"></TextView>
<EditText android:text="@string/empty" android:layout_width="70dip" android:id="@+id/remoteport" android:digits="0123456789" android:layout_height="35dip"></EditText>
</TableRow>
<TextView android:text="@string/cert_file" android:gravity="center" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="15sp" android:id="@+id/certfilelabel"></TextView>
<EditText android:text="@string/empty" android:layout_width="wrap_content" android:layout_height="35dip" android:id="@+id/pkcsfile"></EditText>
<TextView android:layout_width="wrap_content" android:id="@+id/pkcspasslabel" android:layout_height="wrap_content" android:text="@string/pkcspass"></TextView>
<EditText android:layout_width="wrap_content" android:text="@string/empty" android:password="true" android:layout_height="35dip" android:id="@+id/pkcspass"></EditText>
<Button android:id="@+id/buttonApply" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/apply"></Button>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content" android:text="SSLDroid service control" android:gravity="center" android:textSize="20sp" android:padding="20dp"/>
<Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/buttonStart" android:text="Start"></Button>
<Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Stop" android:id="@+id/buttonStop"></Button>
</LinearLayout>
android:layout_height="wrap_content" android:gravity="center" android:textSize="20sp" android:padding="20dp" android:text="@string/service_control" android:id="@+id/servicecontrollabel"/>
<TableRow android:id="@+id/tableRow2" android:layout_width="wrap_content" android:layout_height="wrap_content">
<Button android:id="@+id/buttonStart" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Start"></Button>
<Button android:id="@+id/buttonStop" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Stop"></Button>
</TableRow>
</TableLayout>

View File

@ -2,4 +2,12 @@
<resources>
<string name="hello">Hello World, SSLDroidGui!</string>
<string name="app_name">SSLDroid</string>
<string name="service_control">Service Control</string>
<string name="local_port">Local port to listen on</string>
<string name="remote_host">Remote host to connect to</string>
<string name="remote_port">Remote port to connect to</string>
<string name="cert_file">PKCS12 file to use for auth</string>
<string name="empty"></string>
<string name="apply">Apply</string>
<string name="pkcspass">PKCS12 password</string>
</resources>

View File

@ -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");

View File

@ -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;
}
}
}