1
0
mirror of https://github.com/moparisthebest/SSLDroid synced 2024-11-27 03:12:18 -05:00

Basically undone these commits:

82da2651b2
780d221b2f

Instead of wait()-ing which has just made the problem worse, the
socket used for passing data between the threads needs to be closed.

The second is yet to be solved, onPause() is called even if the
Activity is being canceled, need to check somehow why this is needed
for saving the instance state.

Signed-off-by: Balint Kovacs <blint@blint.hu>
This commit is contained in:
Balint Kovacs 2011-04-20 23:34:35 +02:00
parent 79c357576c
commit a4489bcd97
7 changed files with 37 additions and 18 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -11,7 +11,6 @@ import hu.blint.ssldroid.db.SSLDroidDbAdapter;
public class SSLDroid extends Service {
final String TAG = "SSLDroid";
public static final String PREFS_NAME = "SSLDroid";
TcpProxy tp[];
private SSLDroidDbAdapter dbHelper;
@ -44,11 +43,15 @@ public class SSLDroid extends Service {
String keyPass = cursor.getString(cursor
.getColumnIndexOrThrow(SSLDroidDbAdapter.KEY_PKCSPASS));
try {
tp[i] = new TcpProxy();
tp[i].serve(listenPort, targetHost, targetPort, keyFile, keyPass);
tp[i] = new TcpProxy(listenPort, targetHost, targetPort, keyFile, keyPass);
tp[i].serve();
Log.d(TAG, "Tunnel: "+listenPort+" "+targetHost+" "+targetPort+" "+keyFile);
} catch (Exception e) {
Log.d(TAG, "Error:" + e.toString());
new AlertDialog.Builder(SSLDroid.this)
.setTitle("SSLDroid encountered a fatal error: "+e.getMessage())
.setPositiveButton(android.R.string.ok, null)
.create();
}
}

View File

@ -129,7 +129,6 @@ public class SSLDroidTunnelDetails extends Activity {
.setItems(namesList, new OnClickListener() {
public void onClick(DialogInterface arg0, int arg1) {
String name = namesList[arg1];
pkcsfile.setText(sdcard+"/"+name);
}
})
@ -165,7 +164,7 @@ public class SSLDroidTunnelDetails extends Activity {
@Override
protected void onPause() {
super.onPause();
//saveState();
saveState();
}
@Override

View File

@ -17,19 +17,25 @@ public class TcpProxy {
Thread server = null;
ServerSocket ss = null;
public TcpProxy() {
public TcpProxy(int listenPort, String targetHost, int targetPort, String keyFile, String keyPass) {
this.listenPort = listenPort;
this.tunnelHost = targetHost;
this.tunnelPort = targetPort;
this.keyFile = keyFile;
this.keyPass = keyPass;
}
public void serve(int listenPort, String tunnelHost, int tunnelPort, String keyFile, String keyPass) throws IOException {
public void serve() throws IOException {
try {
ss = new ServerSocket(listenPort);
Log.d("SSLDroid", "Listening for connections on port "
+ listenPort + " ...");
+ this.listenPort + " ...");
} catch (Exception e) {
Log.d("SSLDroid", "Error setting up listening socket: " + e.toString());
System.exit(1);
return;
}
server = new TcpProxyServerThread(ss, listenPort, tunnelHost, tunnelPort, keyFile, keyPass);
server = new TcpProxyServerThread(this.ss, this.listenPort, this.tunnelHost,
this.tunnelPort, this.keyFile, this.keyPass);
server.start();
}
@ -43,7 +49,7 @@ public class TcpProxy {
Log.d("SSLDroid", "Interrupt failure: " + e.toString());
}
}
Log.d("SSLDroid", "Stopping service");
Log.d("SSLDroid", "Stopping tunnel "+this.listenPort+":"+this.tunnelHost+":"+this.tunnelPort);
}
//if the listening socket is still active, we're alive

View File

@ -112,6 +112,12 @@ public class TcpProxyServerThread extends Thread {
if (Thread.interrupted()) {
// We've been interrupted: no more relaying
Log.d("SSLDroid", "Interrupted thread");
try {
in.close();
out.close();
} catch (IOException e) {
Log.d("SSLDroid", e.toString());
}
return;
}
out.write(buf, 0, n);
@ -149,9 +155,9 @@ public class TcpProxyServerThread extends Thread {
Log.d("SSLDroid", "Interrupted server thread, closing sockets...");
ss.close();
if (fromBrowserToServer != null)
fromBrowserToServer.wait();
fromBrowserToServer.notify();
if (fromServerToBrowser != null)
fromServerToBrowser.wait();
fromServerToBrowser.notify();
return;
}
// accept the connection from my client
@ -165,22 +171,27 @@ public class TcpProxyServerThread extends Thread {
Socket st = null;
try {
st = (SSLSocket) getSocketFactory(keyFile, keyPass).createSocket(tunnelHost, tunnelPort);
st = (SSLSocket) getSocketFactory(this.keyFile, this.keyPass).createSocket(this.tunnelHost, this.tunnelPort);
((SSLSocket) st).startHandshake();
} catch (Exception e) {
} catch (IOException e){
}
catch (Exception e) {
Log.d("SSLDroid", "SSL failure: " + e.toString());
//Thread.sleep(10000);
//continue;
sc.close();
return;
}
if (sc == null){
Log.d("SSLDroid", "Trying socket operation on a null socket, returning");
return;
}
Log.d("SSLDroid", "Tunnelling port "
+ listenPort + " to port "
+ tunnelPort + " on host "
+ tunnelHost + " ...");
// relay the stuff thru
// relay the stuff through
fromBrowserToServer = new Relay(
sc.getInputStream(), st.getOutputStream());
fromServerToBrowser = new Relay(