mirror of
https://github.com/moparisthebest/SSLDroid
synced 2024-11-30 04:42:17 -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:
parent
79c357576c
commit
a4489bcd97
BIN
bin/SSLDroid.apk
BIN
bin/SSLDroid.apk
Binary file not shown.
BIN
bin/classes.dex
BIN
bin/classes.dex
Binary file not shown.
Binary file not shown.
@ -11,7 +11,6 @@ import hu.blint.ssldroid.db.SSLDroidDbAdapter;
|
|||||||
public class SSLDroid extends Service {
|
public class SSLDroid extends Service {
|
||||||
|
|
||||||
final String TAG = "SSLDroid";
|
final String TAG = "SSLDroid";
|
||||||
public static final String PREFS_NAME = "SSLDroid";
|
|
||||||
TcpProxy tp[];
|
TcpProxy tp[];
|
||||||
private SSLDroidDbAdapter dbHelper;
|
private SSLDroidDbAdapter dbHelper;
|
||||||
|
|
||||||
@ -44,11 +43,15 @@ public class SSLDroid extends Service {
|
|||||||
String keyPass = cursor.getString(cursor
|
String keyPass = cursor.getString(cursor
|
||||||
.getColumnIndexOrThrow(SSLDroidDbAdapter.KEY_PKCSPASS));
|
.getColumnIndexOrThrow(SSLDroidDbAdapter.KEY_PKCSPASS));
|
||||||
try {
|
try {
|
||||||
tp[i] = new TcpProxy();
|
tp[i] = new TcpProxy(listenPort, targetHost, targetPort, keyFile, keyPass);
|
||||||
tp[i].serve(listenPort, targetHost, targetPort, keyFile, keyPass);
|
tp[i].serve();
|
||||||
Log.d(TAG, "Tunnel: "+listenPort+" "+targetHost+" "+targetPort+" "+keyFile);
|
Log.d(TAG, "Tunnel: "+listenPort+" "+targetHost+" "+targetPort+" "+keyFile);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.d(TAG, "Error:" + e.toString());
|
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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,7 +129,6 @@ public class SSLDroidTunnelDetails extends Activity {
|
|||||||
.setItems(namesList, new OnClickListener() {
|
.setItems(namesList, new OnClickListener() {
|
||||||
public void onClick(DialogInterface arg0, int arg1) {
|
public void onClick(DialogInterface arg0, int arg1) {
|
||||||
String name = namesList[arg1];
|
String name = namesList[arg1];
|
||||||
|
|
||||||
pkcsfile.setText(sdcard+"/"+name);
|
pkcsfile.setText(sdcard+"/"+name);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -165,7 +164,7 @@ public class SSLDroidTunnelDetails extends Activity {
|
|||||||
@Override
|
@Override
|
||||||
protected void onPause() {
|
protected void onPause() {
|
||||||
super.onPause();
|
super.onPause();
|
||||||
//saveState();
|
saveState();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -17,19 +17,25 @@ public class TcpProxy {
|
|||||||
Thread server = null;
|
Thread server = null;
|
||||||
ServerSocket ss = 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 {
|
try {
|
||||||
ss = new ServerSocket(listenPort);
|
ss = new ServerSocket(listenPort);
|
||||||
Log.d("SSLDroid", "Listening for connections on port "
|
Log.d("SSLDroid", "Listening for connections on port "
|
||||||
+ listenPort + " ...");
|
+ this.listenPort + " ...");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.d("SSLDroid", "Error setting up listening socket: " + e.toString());
|
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();
|
server.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -43,7 +49,7 @@ public class TcpProxy {
|
|||||||
Log.d("SSLDroid", "Interrupt failure: " + e.toString());
|
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
|
//if the listening socket is still active, we're alive
|
||||||
|
@ -112,6 +112,12 @@ public class TcpProxyServerThread extends Thread {
|
|||||||
if (Thread.interrupted()) {
|
if (Thread.interrupted()) {
|
||||||
// We've been interrupted: no more relaying
|
// We've been interrupted: no more relaying
|
||||||
Log.d("SSLDroid", "Interrupted thread");
|
Log.d("SSLDroid", "Interrupted thread");
|
||||||
|
try {
|
||||||
|
in.close();
|
||||||
|
out.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
Log.d("SSLDroid", e.toString());
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
out.write(buf, 0, n);
|
out.write(buf, 0, n);
|
||||||
@ -149,9 +155,9 @@ public class TcpProxyServerThread extends Thread {
|
|||||||
Log.d("SSLDroid", "Interrupted server thread, closing sockets...");
|
Log.d("SSLDroid", "Interrupted server thread, closing sockets...");
|
||||||
ss.close();
|
ss.close();
|
||||||
if (fromBrowserToServer != null)
|
if (fromBrowserToServer != null)
|
||||||
fromBrowserToServer.wait();
|
fromBrowserToServer.notify();
|
||||||
if (fromServerToBrowser != null)
|
if (fromServerToBrowser != null)
|
||||||
fromServerToBrowser.wait();
|
fromServerToBrowser.notify();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// accept the connection from my client
|
// accept the connection from my client
|
||||||
@ -165,22 +171,27 @@ public class TcpProxyServerThread extends Thread {
|
|||||||
Socket st = null;
|
Socket st = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
st = (SSLSocket) getSocketFactory(keyFile, keyPass).createSocket(tunnelHost, tunnelPort);
|
st = (SSLSocket) getSocketFactory(this.keyFile, this.keyPass).createSocket(this.tunnelHost, this.tunnelPort);
|
||||||
((SSLSocket) st).startHandshake();
|
((SSLSocket) st).startHandshake();
|
||||||
} catch (Exception e) {
|
} catch (IOException e){
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
Log.d("SSLDroid", "SSL failure: " + e.toString());
|
Log.d("SSLDroid", "SSL failure: " + e.toString());
|
||||||
//Thread.sleep(10000);
|
|
||||||
//continue;
|
|
||||||
sc.close();
|
sc.close();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (sc == null){
|
||||||
|
Log.d("SSLDroid", "Trying socket operation on a null socket, returning");
|
||||||
|
return;
|
||||||
|
}
|
||||||
Log.d("SSLDroid", "Tunnelling port "
|
Log.d("SSLDroid", "Tunnelling port "
|
||||||
+ listenPort + " to port "
|
+ listenPort + " to port "
|
||||||
+ tunnelPort + " on host "
|
+ tunnelPort + " on host "
|
||||||
+ tunnelHost + " ...");
|
+ tunnelHost + " ...");
|
||||||
|
|
||||||
// relay the stuff thru
|
// relay the stuff through
|
||||||
fromBrowserToServer = new Relay(
|
fromBrowserToServer = new Relay(
|
||||||
sc.getInputStream(), st.getOutputStream());
|
sc.getInputStream(), st.getOutputStream());
|
||||||
fromServerToBrowser = new Relay(
|
fromServerToBrowser = new Relay(
|
||||||
|
Loading…
Reference in New Issue
Block a user