diff --git a/AndroidManifest.xml b/AndroidManifest.xml index ac8a37d..d02df83 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -1,23 +1,30 @@ - + package="hu.blint.ssldroid" android:versionCode="1" + android:versionName="1.0"> + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - \ No newline at end of file diff --git a/bin/SSLDroid.apk b/bin/SSLDroid.apk index c991f20..15a982a 100644 Binary files a/bin/SSLDroid.apk and b/bin/SSLDroid.apk differ diff --git a/bin/classes.dex b/bin/classes.dex index e49b01a..78f586a 100644 Binary files a/bin/classes.dex and b/bin/classes.dex differ diff --git a/bin/resources.ap_ b/bin/resources.ap_ index 30b719c..3d6a417 100644 Binary files a/bin/resources.ap_ and b/bin/resources.ap_ differ diff --git a/res/drawable-hdpi/icon.png b/res/drawable-hdpi/icon.png index 8074c4c..c258f93 100644 Binary files a/res/drawable-hdpi/icon.png and b/res/drawable-hdpi/icon.png differ diff --git a/res/drawable-ldpi/icon.png b/res/drawable-ldpi/icon.png index 1095584..c2d4359 100644 Binary files a/res/drawable-ldpi/icon.png and b/res/drawable-ldpi/icon.png differ diff --git a/res/drawable-mdpi/icon.png b/res/drawable-mdpi/icon.png index a07c69f..4f03c33 100644 Binary files a/res/drawable-mdpi/icon.png and b/res/drawable-mdpi/icon.png differ diff --git a/src/hu/blint/ssldroid/SSLDroid.java b/src/hu/blint/ssldroid/SSLDroid.java index 9616e34..ccc9346 100644 --- a/src/hu/blint/ssldroid/SSLDroid.java +++ b/src/hu/blint/ssldroid/SSLDroid.java @@ -2,6 +2,8 @@ package hu.blint.ssldroid; import hu.blint.ssldroid.TcpProxy; import android.app.*; +import android.content.BroadcastReceiver; +import android.content.Context; import android.content.Intent; import android.os.IBinder; import android.util.Log; @@ -11,40 +13,57 @@ public class SSLDroid extends Service { final String TAG = "SSLDroid"; TcpProxy tp; - + @Override - public void onCreate() { - Toast.makeText(this, "SSLDroid Service Started", Toast.LENGTH_LONG).show(); - Log.d(TAG, "onStart"); - } + public void onCreate() { + // Toast.makeText(this, "SSLDroid Service Started", + // Toast.LENGTH_LONG).show(); + // Log.d(TAG, "onStart"); + } @Override public void onStart(Intent intent, int startid) { - int listenPort = 9999; // port to listen on - int targetPort = 443; // port to connect to - String targetHost = "sogo.balabit.com"; //remote host - String keyFile = "/mnt/sdcard/blint-imaps.p12"; - String keyPass = "titkos"; + int listenPort = 9999; // port to listen on + int targetPort = 443; // port to connect to + String targetHost = "sogo.balabit.com"; // remote host + String keyFile = "/mnt/sdcard/blint-imaps.p12"; + String keyPass = "titkos"; - Toast.makeText(this, "SSLDroid Service Created", Toast.LENGTH_LONG).show(); + Toast.makeText(this, "SSLDroid Service Started", Toast.LENGTH_LONG).show(); Log.d(TAG, "onCreate"); - - tp = new TcpProxy(); - try { - tp.serve(listenPort, targetHost, targetPort, keyFile, keyPass); - } catch (Exception e) { - Log.d(TAG, "SSLDroid Sulyos Errorhiba" + e.getMessage()); - } - } - - @Override - public IBinder onBind(Intent intent) { - return null; - } - @Override - public void onDestroy() { - tp.stop(); - } + tp = new TcpProxy(); + try { + tp.serve(listenPort, targetHost, targetPort, keyFile, keyPass); + } catch (Exception e) { + Log.d(TAG, "SSLDroid Sulyos Errorhiba" + e.getMessage()); + } + } + + @Override + public IBinder onBind(Intent intent) { + return null; + } + + @Override + public void onDestroy() { + try { + tp.stop(); + } catch (Exception e) { + Log.d("SSLDroid", "Error stopping service: " + e.getMessage()); + } + } } + +/* +public class MyStartupIntentReceiver extends BroadcastReceiver{ + @Override + public void onReceive(Context context, Intent intent) { + } + Intent serviceIntent = new Intent(); + serviceIntent.setAction("hu.blint.ssldroid"); + context.startService(serviceIntent); + } + +*/ \ No newline at end of file diff --git a/src/hu/blint/ssldroid/SSLDroidGui.java b/src/hu/blint/ssldroid/SSLDroidGui.java index b016f55..9062112 100644 --- a/src/hu/blint/ssldroid/SSLDroidGui.java +++ b/src/hu/blint/ssldroid/SSLDroidGui.java @@ -9,31 +9,31 @@ import android.view.View.OnClickListener; import android.widget.Button; public class SSLDroidGui extends Activity implements OnClickListener { - private static final String TAG = "ServicesDemo"; - Button buttonStart, buttonStop; + private static final String TAG = "ServicesDemo"; + Button buttonStart, buttonStop; - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.main); + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.main); - buttonStart = (Button) findViewById(R.id.buttonStart); - buttonStop = (Button) findViewById(R.id.buttonStop); + buttonStart = (Button) findViewById(R.id.buttonStart); + buttonStop = (Button) findViewById(R.id.buttonStop); - buttonStart.setOnClickListener(this); - buttonStop.setOnClickListener(this); - } + buttonStart.setOnClickListener(this); + buttonStop.setOnClickListener(this); + } - public void onClick(View src) { - switch (src.getId()) { - case R.id.buttonStart: - Log.d(TAG, "onClick: starting service"); - startService(new Intent(this, SSLDroid.class)); - break; - case R.id.buttonStop: - Log.d(TAG, "onClick: stopping service"); - stopService(new Intent(this, SSLDroid.class)); - break; - } - } + public void onClick(View src) { + switch (src.getId()) { + case R.id.buttonStart: + Log.d(TAG, "onClick: starting service"); + startService(new Intent(this, SSLDroid.class)); + break; + case R.id.buttonStop: + Log.d(TAG, "onClick: stopping service"); + stopService(new Intent(this, SSLDroid.class)); + break; + } + } } \ No newline at end of file diff --git a/src/hu/blint/ssldroid/TcpProxy.java b/src/hu/blint/ssldroid/TcpProxy.java index 2e1483d..dd1a007 100644 --- a/src/hu/blint/ssldroid/TcpProxy.java +++ b/src/hu/blint/ssldroid/TcpProxy.java @@ -17,179 +17,210 @@ import android.util.Log; import android.widget.Toast; /** - * This is a modified version of the TcpTunnelGui utility - * borrowed from the xml.apache.org project. - * @author Balint Kovacs (blint@blint.hu) + * This is a modified version of the TcpTunnelGui utility borrowed from the + * xml.apache.org project. */ public class TcpProxy { - int listenPort; - String tunnelHost; - int tunnelPort; - String keyFile, keyPass; - Relay inRelay, outRelay; - Thread server = null; + int listenPort; + String tunnelHost; + int tunnelPort; + String keyFile, keyPass; + Relay inRelay, outRelay; + Thread server = null; - public TcpProxy() { - } - - public TcpProxy(int listenPort, String tunnelHost, int tunnelPort, String keyFile, String keyPass) { - this.listenPort = listenPort; - this.tunnelHost = tunnelHost; - this.tunnelPort = tunnelPort; - this.keyFile = keyFile; - this.keyPass = keyPass; - } - - public int getListenPort() { - return listenPort; - } - - public String getTunnelHost() { - return tunnelHost; - } - - public int getTunnelPort() { - return tunnelPort; - } - - public String getKeyFile() { - return keyFile; - } - public String getKeyPass() { - return keyPass; - } - - private static SSLSocketFactory sslSocketFactory; - public static final SSLSocketFactory getSocketFactory(String pkcsFile, String pwd) { - if (sslSocketFactory == null) { - try { - KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance("X509"); - KeyStore keyStore = KeyStore.getInstance("PKCS12"); - keyStore.load(new FileInputStream(pkcsFile), pwd.toCharArray()); - keyManagerFactory.init(keyStore, pwd.toCharArray()); - SSLContext context = SSLContext.getInstance("TLS"); - context.init(keyManagerFactory.getKeyManagers(), null, new SecureRandom()); - sslSocketFactory = (SSLSocketFactory) context.getSocketFactory(); - - } 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","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) { - Log.d("SSLDroid","Error loading the client certificate:" + e.getMessage()); - } catch (IOException e) { - Log.d("SSLDroid","Error loading the client certificate file:" + e.getMessage()); - } catch (UnrecoverableKeyException e) { - Log.d("SSLDroid","Error loading the client certificate:" + e.getMessage()); - } - } - return sslSocketFactory; + public TcpProxy() { } - - public void serve(int listenPort, String tunnelHost, int tunnelPort, String keyFile, String keyPass) throws IOException { - final TcpProxy ttg = new TcpProxy(listenPort, tunnelHost, tunnelPort, keyFile, keyPass); - - // create the server 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", "Error setting up listening socket: " + e.getMessage()); - //e.printStackTrace(); - System.exit(1); - } - while (true) { - try { - // accept the connection from my client - Socket sc = ss.accept(); - Socket st; - - try { - st = (SSLSocket) getSocketFactory(ttg.getKeyFile(), ttg.getKeyPass()).createSocket(ttg.getTunnelHost(), ttg.getTunnelPort()); - ((SSLSocket)st).startHandshake(); - } catch (Exception e) { - Log.d("SSLDroid","SSL failure: " + e.toString()); - st = new Socket(ttg.getTunnelHost(),ttg.getTunnelPort()); - } - Log.d("SSLDroid","Tunnelling port " + ttg.getListenPort() + " to port " + ttg.getTunnelPort() + " on host " + ttg.getTunnelHost() + " ..."); + public TcpProxy(int listenPort, String tunnelHost, int tunnelPort, + String keyFile, String keyPass) { + this.listenPort = listenPort; + this.tunnelHost = tunnelHost; + this.tunnelPort = tunnelPort; + this.keyFile = keyFile; + this.keyPass = keyPass; + } - // relay the stuff thru - Thread fromBrowserToServer = new Relay(sc.getInputStream(), st.getOutputStream(), "<<< B2S <<<"); - Thread fromServerToBrowser = new Relay(st.getInputStream(), sc.getOutputStream(), ">>> S2B >>>"); + public int getListenPort() { + return listenPort; + } - fromBrowserToServer.start(); - fromServerToBrowser.start(); + public String getTunnelHost() { + return tunnelHost; + } - if (server.isInterrupted()) - ss.close(); - - } catch (Exception ee) { - Log.d("SSLDroid","Ouch: "+ ee.getMessage()); - //ee.printStackTrace(); - } - } - } - }; - server.start(); - } + public int getTunnelPort() { + return tunnelPort; + } - public void stop(){ - if (server != null) - server.interrupt(); - } - - public static class Relay extends Thread { - private InputStream in; - private OutputStream out; - private final static int BUFSIZ = 4096; - private byte buf[] = new byte[BUFSIZ]; + public String getKeyFile() { + return keyFile; + } - public Relay(InputStream in, OutputStream out, String prefix) { - this.in = in; - this.out = out; - } + public String getKeyPass() { + return keyPass; + } - public void run() { - int n = 0; + private static SSLSocketFactory sslSocketFactory; - try { - while ((n = in.read(buf)) > 0) { - out.write(buf, 0, n); - out.flush(); + public static final SSLSocketFactory getSocketFactory(String pkcsFile, + String pwd) { + if (sslSocketFactory == null) { + try { + KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance("X509"); + KeyStore keyStore = KeyStore.getInstance("PKCS12"); + keyStore.load(new FileInputStream(pkcsFile), pwd.toCharArray()); + keyManagerFactory.init(keyStore, pwd.toCharArray()); + SSLContext context = SSLContext.getInstance("TLS"); + context.init(keyManagerFactory.getKeyManagers(), null, + new SecureRandom()); + sslSocketFactory = (SSLSocketFactory) context + .getSocketFactory(); - for (int i = 0; i < n; i++) { - if (buf[i] == 7) - buf[i] = '#'; - } - - 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()); - } finally { - try { - in.close(); - out.close(); - } catch (IOException e) { - Log.d("SSLDroid", e.getMessage()); - } - } + } 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", "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) { + Log.d("SSLDroid", "Error loading the client certificate:" + + e.getMessage()); + } catch (IOException e) { + Log.d("SSLDroid", "Error loading the client certificate file:" + + e.getMessage()); + } catch (UnrecoverableKeyException e) { + Log.d("SSLDroid", "Error loading the client certificate:" + + e.getMessage()); + } + } + return sslSocketFactory; + } - Log.d("SSLDroid", "Quitting stream proxy..."); - } - } + public void serve(int listenPort, String tunnelHost, int tunnelPort, + String keyFile, String keyPass) throws IOException { + final TcpProxy ttg = new TcpProxy(listenPort, tunnelHost, tunnelPort, + keyFile, keyPass); + + // create the server 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", "Error setting up listening socket: " + + e.getMessage()); + // e.printStackTrace(); + System.exit(1); + } + while (true) { + try { + // accept the connection from my client + Socket sc = ss.accept(); + Socket st; + + try { + st = (SSLSocket) getSocketFactory(ttg.getKeyFile(), + ttg.getKeyPass()).createSocket( + ttg.getTunnelHost(), ttg.getTunnelPort()); + ((SSLSocket) st).startHandshake(); + } catch (Exception e) { + Log.d("SSLDroid", "SSL failure: " + e.toString()); + st = new Socket(ttg.getTunnelHost(), ttg.getTunnelPort()); + } + + Log.d("SSLDroid", "Tunnelling port " + + ttg.getListenPort() + " to port " + + ttg.getTunnelPort() + " on host " + + ttg.getTunnelHost() + " ..."); + + // relay the stuff thru + Thread fromBrowserToServer = new Relay(sc + .getInputStream(), st.getOutputStream(), + "<<< B2S <<<"); + Thread fromServerToBrowser = new Relay(st + .getInputStream(), sc.getOutputStream(), + ">>> S2B >>>"); + + fromBrowserToServer.start(); + fromServerToBrowser.start(); + + if (server.isInterrupted()) { + ss.close(); + return; + } + + } catch (Exception ee) { + Log.d("SSLDroid", "Ouch: " + ee.getMessage()); + // ee.printStackTrace(); + } + } + } + }; + server.start(); + } + + public void stop() { + if (server != null) + server.interrupt(); + Log.d("SSLDroid", "Stopping service"); + } + + public static class Relay extends Thread { + private InputStream in; + private OutputStream out; + private final static int BUFSIZ = 4096; + private byte buf[] = new byte[BUFSIZ]; + + public Relay(InputStream in, OutputStream out, String prefix) { + this.in = in; + this.out = out; + } + + public void run() { + int n = 0; + + try { + while ((n = in.read(buf)) > 0) { + out.write(buf, 0, n); + out.flush(); + + for (int i = 0; i < n; i++) { + if (buf[i] == 7) + buf[i] = '#'; + } + + 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()); + } finally { + try { + in.close(); + out.close(); + } catch (IOException e) { + Log.d("SSLDroid", e.getMessage()); + } + } + + Log.d("SSLDroid", "Quitting stream proxy..."); + } + } } \ No newline at end of file