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:
parent
4ba06a0131
commit
484d940be9
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.
@ -6,7 +6,7 @@
|
||||
android:gravity="center">
|
||||
<TextView
|
||||
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:text="Stop" android:id="@+id/buttonStop"></Button>
|
||||
</LinearLayout>
|
@ -10,6 +10,7 @@ import android.widget.Toast;
|
||||
public class SSLDroid extends Service {
|
||||
|
||||
final String TAG = "SSLDroid";
|
||||
TcpProxy tp;
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
@ -29,11 +30,11 @@ public class SSLDroid extends Service {
|
||||
Toast.makeText(this, "SSLDroid Service Created", Toast.LENGTH_LONG).show();
|
||||
Log.d(TAG, "onCreate");
|
||||
|
||||
TcpProxy tp = new TcpProxy();
|
||||
tp = new TcpProxy();
|
||||
try {
|
||||
tp.serve(listenPort, targetHost, targetPort, keyFile, keyPass);
|
||||
} 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
|
||||
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) {
|
||||
}
|
||||
}
|
||||
} */
|
||||
|
@ -14,6 +14,7 @@ import javax.net.ssl.SSLSocket;
|
||||
import javax.net.ssl.SSLSocketFactory;
|
||||
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
/**
|
||||
* This is a modified version of the TcpTunnelGui utility
|
||||
@ -26,6 +27,7 @@ public class TcpProxy {
|
||||
int tunnelPort;
|
||||
String keyFile, keyPass;
|
||||
Relay inRelay, outRelay;
|
||||
Thread server = null;
|
||||
|
||||
public TcpProxy() {
|
||||
}
|
||||
@ -61,7 +63,7 @@ public class TcpProxy {
|
||||
public static final SSLSocketFactory getSocketFactory(String pkcsFile, String pwd) {
|
||||
if (sslSocketFactory == null) {
|
||||
try {
|
||||
KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance("SunX509");
|
||||
KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance("X509");
|
||||
KeyStore keyStore = KeyStore.getInstance("PKCS12");
|
||||
keyStore.load(new FileInputStream(pkcsFile), pwd.toCharArray());
|
||||
keyManagerFactory.init(keyStore, pwd.toCharArray());
|
||||
@ -71,10 +73,11 @@ public class TcpProxy {
|
||||
|
||||
} catch (FileNotFoundException e) {
|
||||
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) {
|
||||
Log.d("SSLDroid","No SSL algorithm support: " + e.getMessage());
|
||||
} 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) {
|
||||
Log.d("SSLDroid","Error setting up keystore:" + e.getMessage());
|
||||
} catch (java.security.cert.CertificateException e) {
|
||||
@ -92,19 +95,19 @@ public class TcpProxy {
|
||||
final TcpProxy ttg = new TcpProxy(listenPort, tunnelHost, tunnelPort, keyFile, keyPass);
|
||||
|
||||
// create the server thread
|
||||
Thread server = new Thread() {
|
||||
server = new Thread() {
|
||||
public void run() {
|
||||
ServerSocket ss = null;
|
||||
try {
|
||||
ss = new ServerSocket(ttg.getListenPort());
|
||||
Log.d("SSLDroid","Listening for connections on port " + ttg.getListenPort() + " ...");
|
||||
} catch (Exception e) {
|
||||
Log.d("SSLDroid", e.getMessage());
|
||||
Log.d("SSLDroid", "Error setting up listening socket: " + e.getMessage());
|
||||
//e.printStackTrace();
|
||||
System.exit(1);
|
||||
}
|
||||
while (true) {
|
||||
try {
|
||||
Log.d("SSLDroid","Listening for connections on port " + ttg.getListenPort() + " ...");
|
||||
// accept the connection from my client
|
||||
Socket sc = ss.accept();
|
||||
Socket st;
|
||||
@ -113,7 +116,7 @@ public class TcpProxy {
|
||||
st = (SSLSocket) getSocketFactory(ttg.getKeyFile(), ttg.getKeyPass()).createSocket(ttg.getTunnelHost(), ttg.getTunnelPort());
|
||||
((SSLSocket)st).startHandshake();
|
||||
} 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());
|
||||
}
|
||||
|
||||
@ -126,6 +129,9 @@ public class TcpProxy {
|
||||
fromBrowserToServer.start();
|
||||
fromServerToBrowser.start();
|
||||
|
||||
if (server.isInterrupted())
|
||||
ss.close();
|
||||
|
||||
} catch (Exception ee) {
|
||||
Log.d("SSLDroid","Ouch: "+ ee.getMessage());
|
||||
//ee.printStackTrace();
|
||||
@ -136,6 +142,11 @@ public class TcpProxy {
|
||||
server.start();
|
||||
}
|
||||
|
||||
public void stop(){
|
||||
if (server != null)
|
||||
server.interrupt();
|
||||
}
|
||||
|
||||
public static class Relay extends Thread {
|
||||
private InputStream in;
|
||||
private OutputStream out;
|
||||
@ -151,9 +162,6 @@ public class TcpProxy {
|
||||
int n = 0;
|
||||
|
||||
try {
|
||||
//System.err.println(
|
||||
// "\n\n=== START OF A TRANSMISSION : " + dateFormat.format(new Date()) + " =======================================\n");
|
||||
|
||||
while ((n = in.read(buf)) > 0) {
|
||||
out.write(buf, 0, n);
|
||||
out.flush();
|
||||
@ -163,27 +171,25 @@ public class TcpProxy {
|
||||
buf[i] = '#';
|
||||
}
|
||||
|
||||
//String msg = new String(buf, 0, n);
|
||||
//System.out.println(prefix + " : " + msg.length());
|
||||
//System.err.println(msg);
|
||||
if (Thread.interrupted()) {
|
||||
//We've been interrupted: no more serving.
|
||||
return;
|
||||
}
|
||||
}
|
||||
} catch (SocketException e) {
|
||||
Log.d("SSLDroid", e.getMessage());
|
||||
} catch (IOException e) {
|
||||
Log.d("SSLDroid", e.getMessage());
|
||||
//e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
in.close();
|
||||
out.close();
|
||||
} catch (IOException e) {
|
||||
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");
|
||||
}
|
Loading…
Reference in New Issue
Block a user