1
0
mirror of https://github.com/moparisthebest/SSLDroid synced 2024-11-23 09:22:16 -05:00

Minor logging cleanup and bugfixes

Finally a working proof-of-concept

Signed-off-by: Balint Kovacs <blint@blint.hu>
This commit is contained in:
Balint Kovacs 2011-03-22 14:47:14 +01:00
parent 4ba06a0131
commit 484d940be9
6 changed files with 29 additions and 39 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -6,7 +6,7 @@
android:gravity="center"> android:gravity="center">
<TextView <TextView
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:text="Services Demo" android:gravity="center" android:textSize="20sp" android:padding="20dp"/> 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: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> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Stop" android:id="@+id/buttonStop"></Button>
</LinearLayout> </LinearLayout>

View File

@ -10,6 +10,7 @@ import android.widget.Toast;
public class SSLDroid extends Service { public class SSLDroid extends Service {
final String TAG = "SSLDroid"; final String TAG = "SSLDroid";
TcpProxy tp;
@Override @Override
public void onCreate() { public void onCreate() {
@ -29,11 +30,11 @@ public class SSLDroid extends Service {
Toast.makeText(this, "SSLDroid Service Created", Toast.LENGTH_LONG).show(); Toast.makeText(this, "SSLDroid Service Created", Toast.LENGTH_LONG).show();
Log.d(TAG, "onCreate"); Log.d(TAG, "onCreate");
TcpProxy tp = new TcpProxy(); tp = new TcpProxy();
try { try {
tp.serve(listenPort, targetHost, targetPort, keyFile, keyPass); tp.serve(listenPort, targetHost, targetPort, keyFile, keyPass);
} catch (Exception e) { } catch (Exception e) {
Toast.makeText(this, "SSLDroid Sulyos Errorhiba" + e.getMessage(), Toast.LENGTH_LONG).show(); Log.d(TAG, "SSLDroid Sulyos Errorhiba" + e.getMessage());
} }
} }
@ -44,23 +45,6 @@ public class SSLDroid extends Service {
@Override @Override
public void onDestroy() { public void onDestroy() {
tp.stop();
} }
} }
/*public class SSLDroid
{
public static final int listenPort = 9999, // port to listen on
targetPort = 443; // port to connect to
public static final String targetHost = "sogo.balabit.com"; //remote host
static String keyFile = "/home/blint/vpn/blint-imaps.p12";
static String keyPass = "titkos";
public static void main(String[] args) {
TcpProxy tp = new TcpProxy();
try {
tp.serve(listenPort, targetHost, targetPort, keyFile, keyPass);
} catch (Exception e) {
}
}
} */

View File

@ -14,6 +14,7 @@ import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory; import javax.net.ssl.SSLSocketFactory;
import android.util.Log; import android.util.Log;
import android.widget.Toast;
/** /**
* This is a modified version of the TcpTunnelGui utility * This is a modified version of the TcpTunnelGui utility
@ -26,6 +27,7 @@ public class TcpProxy {
int tunnelPort; int tunnelPort;
String keyFile, keyPass; String keyFile, keyPass;
Relay inRelay, outRelay; Relay inRelay, outRelay;
Thread server = null;
public TcpProxy() { public TcpProxy() {
} }
@ -61,7 +63,7 @@ public class TcpProxy {
public static final SSLSocketFactory getSocketFactory(String pkcsFile, String pwd) { public static final SSLSocketFactory getSocketFactory(String pkcsFile, String pwd) {
if (sslSocketFactory == null) { if (sslSocketFactory == null) {
try { try {
KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance("SunX509"); KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance("X509");
KeyStore keyStore = KeyStore.getInstance("PKCS12"); KeyStore keyStore = KeyStore.getInstance("PKCS12");
keyStore.load(new FileInputStream(pkcsFile), pwd.toCharArray()); keyStore.load(new FileInputStream(pkcsFile), pwd.toCharArray());
keyManagerFactory.init(keyStore, pwd.toCharArray()); keyManagerFactory.init(keyStore, pwd.toCharArray());
@ -71,10 +73,11 @@ public class TcpProxy {
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
Log.d("SSLDroid","Error loading the client certificate file:" + e.getMessage()); Log.d("SSLDroid","Error loading the client certificate file:" + e.getMessage());
//Toast.makeText(none, "SSLDroid Sulyos Errorhiba" + e.getMessage(), Toast.LENGTH_LONG).show();
} catch (KeyManagementException e) { } catch (KeyManagementException e) {
Log.d("SSLDroid","No SSL algorithm support: " + e.getMessage()); Log.d("SSLDroid","No SSL algorithm support: " + e.getMessage());
} catch (NoSuchAlgorithmException e) { } catch (NoSuchAlgorithmException e) {
Log.d("SSLDroid","Exception when setting up the Naive key management."); Log.d("SSLDroid","No common SSL algorithm found: " + e.getMessage());
} catch (KeyStoreException e) { } catch (KeyStoreException e) {
Log.d("SSLDroid","Error setting up keystore:" + e.getMessage()); Log.d("SSLDroid","Error setting up keystore:" + e.getMessage());
} catch (java.security.cert.CertificateException e) { } catch (java.security.cert.CertificateException e) {
@ -92,19 +95,19 @@ public class TcpProxy {
final TcpProxy ttg = new TcpProxy(listenPort, tunnelHost, tunnelPort, keyFile, keyPass); final TcpProxy ttg = new TcpProxy(listenPort, tunnelHost, tunnelPort, keyFile, keyPass);
// create the server thread // create the server thread
Thread server = new Thread() { server = new Thread() {
public void run() { public void run() {
ServerSocket ss = null; ServerSocket ss = null;
try { try {
ss = new ServerSocket(ttg.getListenPort()); ss = new ServerSocket(ttg.getListenPort());
Log.d("SSLDroid","Listening for connections on port " + ttg.getListenPort() + " ...");
} catch (Exception e) { } catch (Exception e) {
Log.d("SSLDroid", e.getMessage()); Log.d("SSLDroid", "Error setting up listening socket: " + e.getMessage());
//e.printStackTrace(); //e.printStackTrace();
System.exit(1); System.exit(1);
} }
while (true) { while (true) {
try { try {
Log.d("SSLDroid","Listening for connections on port " + ttg.getListenPort() + " ...");
// accept the connection from my client // accept the connection from my client
Socket sc = ss.accept(); Socket sc = ss.accept();
Socket st; Socket st;
@ -113,7 +116,7 @@ public class TcpProxy {
st = (SSLSocket) getSocketFactory(ttg.getKeyFile(), ttg.getKeyPass()).createSocket(ttg.getTunnelHost(), ttg.getTunnelPort()); st = (SSLSocket) getSocketFactory(ttg.getKeyFile(), ttg.getKeyPass()).createSocket(ttg.getTunnelHost(), ttg.getTunnelPort());
((SSLSocket)st).startHandshake(); ((SSLSocket)st).startHandshake();
} catch (Exception e) { } catch (Exception e) {
Log.d("SSLDroid","SSL FAIL!\n" + e.toString()); Log.d("SSLDroid","SSL failure: " + e.toString());
st = new Socket(ttg.getTunnelHost(),ttg.getTunnelPort()); st = new Socket(ttg.getTunnelHost(),ttg.getTunnelPort());
} }
@ -126,6 +129,9 @@ public class TcpProxy {
fromBrowserToServer.start(); fromBrowserToServer.start();
fromServerToBrowser.start(); fromServerToBrowser.start();
if (server.isInterrupted())
ss.close();
} catch (Exception ee) { } catch (Exception ee) {
Log.d("SSLDroid","Ouch: "+ ee.getMessage()); Log.d("SSLDroid","Ouch: "+ ee.getMessage());
//ee.printStackTrace(); //ee.printStackTrace();
@ -136,6 +142,11 @@ public class TcpProxy {
server.start(); server.start();
} }
public void stop(){
if (server != null)
server.interrupt();
}
public static class Relay extends Thread { public static class Relay extends Thread {
private InputStream in; private InputStream in;
private OutputStream out; private OutputStream out;
@ -151,9 +162,6 @@ public class TcpProxy {
int n = 0; int n = 0;
try { try {
//System.err.println(
// "\n\n=== START OF A TRANSMISSION : " + dateFormat.format(new Date()) + " =======================================\n");
while ((n = in.read(buf)) > 0) { while ((n = in.read(buf)) > 0) {
out.write(buf, 0, n); out.write(buf, 0, n);
out.flush(); out.flush();
@ -162,28 +170,26 @@ public class TcpProxy {
if (buf[i] == 7) if (buf[i] == 7)
buf[i] = '#'; buf[i] = '#';
} }
//String msg = new String(buf, 0, n); if (Thread.interrupted()) {
//System.out.println(prefix + " : " + msg.length()); //We've been interrupted: no more serving.
//System.err.println(msg); return;
}
} }
} catch (SocketException e) { } catch (SocketException e) {
Log.d("SSLDroid", e.getMessage());
} catch (IOException e) { } catch (IOException e) {
Log.d("SSLDroid", e.getMessage()); Log.d("SSLDroid", e.getMessage());
//e.printStackTrace();
} finally { } finally {
try { try {
in.close(); in.close();
out.close(); out.close();
} catch (IOException e) { } catch (IOException e) {
Log.d("SSLDroid", e.getMessage()); Log.d("SSLDroid", e.getMessage());
//e.printStackTrace();
} }
} }
//System.out.println("Quiting stream proxy " + prefix + "..."); Log.d("SSLDroid", "Quitting stream proxy...");
} }
} }
//private static final Format dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss,SSS");
} }