New icon and some minor reformattings

Signed-off-by: Balint Kovacs <blint@blint.hu>
This commit is contained in:
Balint Kovacs 2011-03-24 20:59:48 +01:00
parent 484d940be9
commit 99fb986ac4
10 changed files with 288 additions and 231 deletions

View File

@ -1,23 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="hu.blint.ssldroid"
android:versionCode="1"
android:versionName="1.0">
<uses-permission android:name="android.permission.SET_ACTIVITY_WATCHER"></uses-permission>
package="hu.blint.ssldroid" android:versionCode="1"
android:versionName="1.0">
<uses-permission android:name="android.permission.SET_ACTIVITY_WATCHER"></uses-permission>
<application android:label="@string/app_name" android:icon="@drawable/icon">
<activity android:name=".SSLDroidGui" android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:enabled="true" android:name=".SSLDroid" />
</application>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<receiver android:name=".BootStartupReceiver"
android:enabled="true" android:exported="false" android:label="StartServiceAtBootReceiver">
<intent-filter>
<action android:name="android.intent.action._BOOT_COMPLETED" />
</intent-filter>
</receiver>
<application android:label="@string/app_name" android:icon="@drawable/icon">
<activity android:name=".SSLDroidGui"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:enabled="true" android:name=".SSLDroid"/>
</application>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
</manifest>

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.0 KiB

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.5 KiB

After

Width:  |  Height:  |  Size: 1.9 KiB

View File

@ -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);
}
*/

View File

@ -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;
}
}
}

View File

@ -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...");
}
}
}