mirror of
https://github.com/moparisthebest/SSLDroid
synced 2024-11-10 11:05:05 -05:00
Added log tags and session ID to the stream related error messages
Signed-off-by: Balint Kovacs <blint@blint.hu>
This commit is contained in:
parent
a094fa8be1
commit
de7a264296
@ -32,6 +32,8 @@ public class SSLDroid extends Service {
|
|||||||
int i;
|
int i;
|
||||||
for (i=0; i<tunnelcount; i++){
|
for (i=0; i<tunnelcount; i++){
|
||||||
cursor.moveToPosition(i);
|
cursor.moveToPosition(i);
|
||||||
|
String tunnelName = cursor.getString(cursor
|
||||||
|
.getColumnIndexOrThrow(SSLDroidDbAdapter.KEY_NAME));
|
||||||
int listenPort = cursor.getInt(cursor
|
int listenPort = cursor.getInt(cursor
|
||||||
.getColumnIndexOrThrow(SSLDroidDbAdapter.KEY_LOCALPORT));
|
.getColumnIndexOrThrow(SSLDroidDbAdapter.KEY_LOCALPORT));
|
||||||
int targetPort = cursor.getInt(cursor
|
int targetPort = cursor.getInt(cursor
|
||||||
@ -43,9 +45,9 @@ 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(listenPort, targetHost, targetPort, keyFile, keyPass);
|
tp[i] = new TcpProxy(tunnelName, listenPort, targetHost, targetPort, keyFile, keyPass);
|
||||||
tp[i].serve();
|
tp[i].serve();
|
||||||
Log.d(TAG, "Tunnel: "+listenPort+" "+targetHost+" "+targetPort+" "+keyFile);
|
Log.d(TAG, "Tunnel: "+tunnelName+" "+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)
|
new AlertDialog.Builder(SSLDroid.this)
|
||||||
|
@ -11,6 +11,7 @@ import android.util.Log;
|
|||||||
* xml.apache.org project.
|
* xml.apache.org project.
|
||||||
*/
|
*/
|
||||||
public class TcpProxy {
|
public class TcpProxy {
|
||||||
|
String tunnelName;
|
||||||
int listenPort;
|
int listenPort;
|
||||||
String tunnelHost;
|
String tunnelHost;
|
||||||
int tunnelPort;
|
int tunnelPort;
|
||||||
@ -18,7 +19,8 @@ public class TcpProxy {
|
|||||||
Thread server = null;
|
Thread server = null;
|
||||||
ServerSocket ss = null;
|
ServerSocket ss = null;
|
||||||
|
|
||||||
public TcpProxy(int listenPort, String targetHost, int targetPort, String keyFile, String keyPass) {
|
public TcpProxy(String tunnelName, int listenPort, String targetHost, int targetPort, String keyFile, String keyPass) {
|
||||||
|
this.tunnelName = tunnelName;
|
||||||
this.listenPort = listenPort;
|
this.listenPort = listenPort;
|
||||||
this.tunnelHost = targetHost;
|
this.tunnelHost = targetHost;
|
||||||
this.tunnelPort = targetPort;
|
this.tunnelPort = targetPort;
|
||||||
@ -35,7 +37,7 @@ public class TcpProxy {
|
|||||||
Log.d("SSLDroid", "Error setting up listening socket: " + e.toString());
|
Log.d("SSLDroid", "Error setting up listening socket: " + e.toString());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
server = new TcpProxyServerThread(this.ss, this.listenPort, this.tunnelHost,
|
server = new TcpProxyServerThread(this.ss, this.tunnelName, this.listenPort, this.tunnelHost,
|
||||||
this.tunnelPort, this.keyFile, this.keyPass);
|
this.tunnelPort, this.keyFile, this.keyPass);
|
||||||
server.start();
|
server.start();
|
||||||
}
|
}
|
||||||
|
@ -26,14 +26,17 @@ import android.util.Log;
|
|||||||
|
|
||||||
public class TcpProxyServerThread extends Thread {
|
public class TcpProxyServerThread extends Thread {
|
||||||
|
|
||||||
|
String tunnelName;
|
||||||
int listenPort;
|
int listenPort;
|
||||||
String tunnelHost;
|
String tunnelHost;
|
||||||
int tunnelPort;
|
int tunnelPort;
|
||||||
String keyFile, keyPass;
|
String keyFile, keyPass;
|
||||||
Relay inRelay, outRelay;
|
Relay inRelay, outRelay;
|
||||||
ServerSocket ss = null;
|
ServerSocket ss = null;
|
||||||
|
int sessionid = 0;
|
||||||
|
|
||||||
public TcpProxyServerThread(ServerSocket ss, int listenPort, String tunnelHost, int tunnelPort, String keyFile, String keyPass) {
|
public TcpProxyServerThread(ServerSocket ss,String tunnelName, int listenPort, String tunnelHost, int tunnelPort, String keyFile, String keyPass) {
|
||||||
|
this.tunnelName = tunnelName;
|
||||||
this.listenPort = listenPort;
|
this.listenPort = listenPort;
|
||||||
this.tunnelHost = tunnelHost;
|
this.tunnelHost = tunnelHost;
|
||||||
this.tunnelPort = tunnelPort;
|
this.tunnelPort = tunnelPort;
|
||||||
@ -61,7 +64,7 @@ public class TcpProxyServerThread extends Thread {
|
|||||||
private static SSLSocketFactory sslSocketFactory;
|
private static SSLSocketFactory sslSocketFactory;
|
||||||
|
|
||||||
public final SSLSocketFactory getSocketFactory(String pkcsFile,
|
public final SSLSocketFactory getSocketFactory(String pkcsFile,
|
||||||
String pwd) {
|
String pwd, int sessionid) {
|
||||||
if (sslSocketFactory == null) {
|
if (sslSocketFactory == null) {
|
||||||
try {
|
try {
|
||||||
KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance("X509");
|
KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance("X509");
|
||||||
@ -74,20 +77,20 @@ public class TcpProxyServerThread extends Thread {
|
|||||||
sslSocketFactory = (SSLSocketFactory) context.getSocketFactory();
|
sslSocketFactory = (SSLSocketFactory) context.getSocketFactory();
|
||||||
|
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
Log.d("SSLDroid", "Error loading the client certificate file:"
|
Log.d("SSLDroid", tunnelName+"/"+sessionid+": Error loading the client certificate file:"
|
||||||
+ e.toString());
|
+ e.toString());
|
||||||
} catch (KeyManagementException e) {
|
} catch (KeyManagementException e) {
|
||||||
Log.d("SSLDroid", "No SSL algorithm support: " + e.toString());
|
Log.d("SSLDroid", tunnelName+"/"+sessionid+": No SSL algorithm support: " + e.toString());
|
||||||
} catch (NoSuchAlgorithmException e) {
|
} catch (NoSuchAlgorithmException e) {
|
||||||
Log.d("SSLDroid", "No common SSL algorithm found: " + e.toString());
|
Log.d("SSLDroid", tunnelName+"/"+sessionid+": No common SSL algorithm found: " + e.toString());
|
||||||
} catch (KeyStoreException e) {
|
} catch (KeyStoreException e) {
|
||||||
Log.d("SSLDroid", "Error setting up keystore:" + e.toString());
|
Log.d("SSLDroid", tunnelName+"/"+sessionid+": Error setting up keystore:" + e.toString());
|
||||||
} catch (java.security.cert.CertificateException e) {
|
} catch (java.security.cert.CertificateException e) {
|
||||||
Log.d("SSLDroid", "Error loading the client certificate:" + e.toString());
|
Log.d("SSLDroid", tunnelName+"/"+sessionid+": Error loading the client certificate:" + e.toString());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Log.d("SSLDroid", "Error loading the client certificate file:" + e.toString());
|
Log.d("SSLDroid", tunnelName+"/"+sessionid+": Error loading the client certificate file:" + e.toString());
|
||||||
} catch (UnrecoverableKeyException e) {
|
} catch (UnrecoverableKeyException e) {
|
||||||
Log.d("SSLDroid", "Error loading the client certificate:" + e.toString());
|
Log.d("SSLDroid", tunnelName+"/"+sessionid+": Error loading the client certificate:" + e.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return sslSocketFactory;
|
return sslSocketFactory;
|
||||||
@ -96,12 +99,16 @@ public class TcpProxyServerThread extends Thread {
|
|||||||
public class Relay extends Thread {
|
public class Relay extends Thread {
|
||||||
private InputStream in;
|
private InputStream in;
|
||||||
private OutputStream out;
|
private OutputStream out;
|
||||||
|
private String side;
|
||||||
|
private int sessionid;
|
||||||
private final static int BUFSIZ = 4096;
|
private final static int BUFSIZ = 4096;
|
||||||
private byte buf[] = new byte[BUFSIZ];
|
private byte buf[] = new byte[BUFSIZ];
|
||||||
|
|
||||||
public Relay(InputStream in, OutputStream out) {
|
public Relay(InputStream in, OutputStream out, String side, int sessionid) {
|
||||||
this.in = in;
|
this.in = in;
|
||||||
this.out = out;
|
this.out = out;
|
||||||
|
this.side = side;
|
||||||
|
this.sessionid = sessionid;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
@ -111,12 +118,12 @@ public class TcpProxyServerThread extends Thread {
|
|||||||
while ((n = in.read(buf)) > 0) {
|
while ((n = in.read(buf)) > 0) {
|
||||||
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", tunnelName+"/"+sessionid+": Interrupted "+side+" thread");
|
||||||
try {
|
try {
|
||||||
in.close();
|
in.close();
|
||||||
out.close();
|
out.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Log.d("SSLDroid", e.toString());
|
Log.d("SSLDroid", tunnelName+"/"+sessionid+": "+e.toString());
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -129,23 +136,22 @@ public class TcpProxyServerThread extends Thread {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (SocketException e) {
|
} catch (SocketException e) {
|
||||||
Log.d("SSLDroid", e.toString());
|
Log.d("SSLDroid", tunnelName+"/"+sessionid+": "+e.toString());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Log.d("SSLDroid", e.toString());
|
Log.d("SSLDroid", tunnelName+"/"+sessionid+": "+e.toString());
|
||||||
} finally {
|
} finally {
|
||||||
try {
|
try {
|
||||||
in.close();
|
in.close();
|
||||||
out.close();
|
out.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Log.d("SSLDroid", e.toString());
|
Log.d("SSLDroid", tunnelName+"/"+sessionid+": "+e.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Log.d("SSLDroid", "Quitting stream proxy...");
|
Log.d("SSLDroid", tunnelName+"/"+sessionid+": Quitting "+side+"-side stream proxy...");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
//TODO: logging session ID
|
|
||||||
while (true) {
|
while (true) {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
@ -153,7 +159,7 @@ public class TcpProxyServerThread extends Thread {
|
|||||||
Thread fromServerToBrowser = null;
|
Thread fromServerToBrowser = null;
|
||||||
|
|
||||||
if (isInterrupted()){
|
if (isInterrupted()){
|
||||||
Log.d("SSLDroid", "Interrupted server thread, closing sockets...");
|
Log.d("SSLDroid", tunnelName+"/"+sessionid+": Interrupted server thread, closing sockets...");
|
||||||
ss.close();
|
ss.close();
|
||||||
if (fromBrowserToServer != null)
|
if (fromBrowserToServer != null)
|
||||||
fromBrowserToServer.notify();
|
fromBrowserToServer.notify();
|
||||||
@ -165,6 +171,7 @@ public class TcpProxyServerThread extends Thread {
|
|||||||
Socket sc = null;
|
Socket sc = null;
|
||||||
try {
|
try {
|
||||||
sc = ss.accept();
|
sc = ss.accept();
|
||||||
|
sessionid++;
|
||||||
} catch (SocketException e){
|
} catch (SocketException e){
|
||||||
Log.d("SSLDroid", "Accept failure: " + e.toString());
|
Log.d("SSLDroid", "Accept failure: " + e.toString());
|
||||||
}
|
}
|
||||||
@ -172,37 +179,37 @@ public class TcpProxyServerThread extends Thread {
|
|||||||
Socket st = null;
|
Socket st = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
st = (SSLSocket) getSocketFactory(this.keyFile, this.keyPass).createSocket(this.tunnelHost, this.tunnelPort);
|
st = (SSLSocket) getSocketFactory(this.keyFile, this.keyPass, this.sessionid).createSocket(this.tunnelHost, this.tunnelPort);
|
||||||
((SSLSocket) st).startHandshake();
|
((SSLSocket) st).startHandshake();
|
||||||
} catch (IOException e){
|
} catch (IOException e){
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
Log.d("SSLDroid", "SSL failure: " + e.toString());
|
Log.d("SSLDroid", tunnelName+"/"+sessionid+": SSL failure: " + e.toString());
|
||||||
sc.close();
|
sc.close();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sc == null){
|
if (sc == null){
|
||||||
Log.d("SSLDroid", "Trying socket operation on a null socket, returning");
|
Log.d("SSLDroid", tunnelName+"/"+sessionid+": Trying socket operation on a null socket, returning");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Log.d("SSLDroid", "Tunnelling port "
|
Log.d("SSLDroid", tunnelName+"/"+sessionid+": Tunnelling port "
|
||||||
+ listenPort + " to port "
|
+ listenPort + " to port "
|
||||||
+ tunnelPort + " on host "
|
+ tunnelPort + " on host "
|
||||||
+ tunnelHost + " ...");
|
+ tunnelHost + " ...");
|
||||||
|
|
||||||
// relay the stuff through
|
// relay the stuff through
|
||||||
fromBrowserToServer = new Relay(
|
fromBrowserToServer = new Relay(
|
||||||
sc.getInputStream(), st.getOutputStream());
|
sc.getInputStream(), st.getOutputStream(), "client", sessionid);
|
||||||
fromServerToBrowser = new Relay(
|
fromServerToBrowser = new Relay(
|
||||||
st.getInputStream(), sc.getOutputStream());
|
st.getInputStream(), sc.getOutputStream(), "server", sessionid);
|
||||||
|
|
||||||
fromBrowserToServer.start();
|
fromBrowserToServer.start();
|
||||||
fromServerToBrowser.start();
|
fromServerToBrowser.start();
|
||||||
|
|
||||||
} catch (Exception ee) {
|
} catch (Exception ee) {
|
||||||
Log.d("SSLDroid", "Ouch: " + ee.getMessage());
|
Log.d("SSLDroid", tunnelName+"/"+sessionid+": Ouch: " + ee.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user