mirror of
https://github.com/moparisthebest/SSLDroid
synced 2024-11-23 01:12:15 -05:00
Initial commit
So far done: - ssl proxying - basic android conversion Signed-off-by: Balint Kovacs <blint@blint.hu>
This commit is contained in:
commit
4ba06a0131
7
.classpath
Normal file
7
.classpath
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<classpath>
|
||||||
|
<classpathentry kind="src" path="src"/>
|
||||||
|
<classpathentry kind="src" path="gen"/>
|
||||||
|
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
|
||||||
|
<classpathentry kind="output" path="bin"/>
|
||||||
|
</classpath>
|
33
.project
Normal file
33
.project
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<projectDescription>
|
||||||
|
<name>SSLDroid</name>
|
||||||
|
<comment></comment>
|
||||||
|
<projects>
|
||||||
|
</projects>
|
||||||
|
<buildSpec>
|
||||||
|
<buildCommand>
|
||||||
|
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
<buildCommand>
|
||||||
|
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
<buildCommand>
|
||||||
|
<name>com.android.ide.eclipse.adt.ApkBuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
</buildSpec>
|
||||||
|
<natures>
|
||||||
|
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
|
||||||
|
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||||
|
</natures>
|
||||||
|
</projectDescription>
|
5
.settings/org.eclipse.jdt.core.prefs
Normal file
5
.settings/org.eclipse.jdt.core.prefs
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
#Sat Mar 19 16:20:10 CET 2011
|
||||||
|
eclipse.preferences.version=1
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
|
||||||
|
org.eclipse.jdt.core.compiler.compliance=1.5
|
||||||
|
org.eclipse.jdt.core.compiler.source=1.5
|
23
AndroidManifest.xml
Normal file
23
AndroidManifest.xml
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
<?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>
|
||||||
|
|
||||||
|
<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>
|
BIN
bin/SSLDroid.apk
Normal file
BIN
bin/SSLDroid.apk
Normal file
Binary file not shown.
BIN
bin/classes.dex
Normal file
BIN
bin/classes.dex
Normal file
Binary file not shown.
BIN
bin/resources.ap_
Normal file
BIN
bin/resources.ap_
Normal file
Binary file not shown.
11
default.properties
Normal file
11
default.properties
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
# This file is automatically generated by Android Tools.
|
||||||
|
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
|
||||||
|
#
|
||||||
|
# This file must be checked in Version Control Systems.
|
||||||
|
#
|
||||||
|
# To customize properties used by the Ant build system use,
|
||||||
|
# "build.properties", and override values to adapt the script to your
|
||||||
|
# project structure.
|
||||||
|
|
||||||
|
# Project target.
|
||||||
|
target=android-7
|
36
proguard.cfg
Normal file
36
proguard.cfg
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
-optimizationpasses 5
|
||||||
|
-dontusemixedcaseclassnames
|
||||||
|
-dontskipnonpubliclibraryclasses
|
||||||
|
-dontpreverify
|
||||||
|
-verbose
|
||||||
|
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
|
||||||
|
|
||||||
|
-keep public class * extends android.app.Activity
|
||||||
|
-keep public class * extends android.app.Application
|
||||||
|
-keep public class * extends android.app.Service
|
||||||
|
-keep public class * extends android.content.BroadcastReceiver
|
||||||
|
-keep public class * extends android.content.ContentProvider
|
||||||
|
-keep public class * extends android.app.backup.BackupAgentHelper
|
||||||
|
-keep public class * extends android.preference.Preference
|
||||||
|
-keep public class com.android.vending.licensing.ILicensingService
|
||||||
|
|
||||||
|
-keepclasseswithmembernames class * {
|
||||||
|
native <methods>;
|
||||||
|
}
|
||||||
|
|
||||||
|
-keepclasseswithmembernames class * {
|
||||||
|
public <init>(android.content.Context, android.util.AttributeSet);
|
||||||
|
}
|
||||||
|
|
||||||
|
-keepclasseswithmembernames class * {
|
||||||
|
public <init>(android.content.Context, android.util.AttributeSet, int);
|
||||||
|
}
|
||||||
|
|
||||||
|
-keepclassmembers enum * {
|
||||||
|
public static **[] values();
|
||||||
|
public static ** valueOf(java.lang.String);
|
||||||
|
}
|
||||||
|
|
||||||
|
-keep class * implements android.os.Parcelable {
|
||||||
|
public static final android.os.Parcelable$Creator *;
|
||||||
|
}
|
BIN
res/drawable-hdpi/icon.png
Normal file
BIN
res/drawable-hdpi/icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.0 KiB |
BIN
res/drawable-ldpi/icon.png
Normal file
BIN
res/drawable-ldpi/icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.7 KiB |
BIN
res/drawable-mdpi/icon.png
Normal file
BIN
res/drawable-mdpi/icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.5 KiB |
12
res/layout/main.xml
Normal file
12
res/layout/main.xml
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="fill_parent"
|
||||||
|
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"/>
|
||||||
|
<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>
|
5
res/values/strings.xml
Normal file
5
res/values/strings.xml
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<resources>
|
||||||
|
<string name="hello">Hello World, SSLDroidGui!</string>
|
||||||
|
<string name="app_name">SSLDroid</string>
|
||||||
|
</resources>
|
66
src/hu/blint/ssldroid/SSLDroid.java
Normal file
66
src/hu/blint/ssldroid/SSLDroid.java
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
package hu.blint.ssldroid;
|
||||||
|
|
||||||
|
import hu.blint.ssldroid.TcpProxy;
|
||||||
|
import android.app.*;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.os.IBinder;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
public class SSLDroid extends Service {
|
||||||
|
|
||||||
|
final String TAG = "SSLDroid";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
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";
|
||||||
|
|
||||||
|
Toast.makeText(this, "SSLDroid Service Created", Toast.LENGTH_LONG).show();
|
||||||
|
Log.d(TAG, "onCreate");
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IBinder onBind(Intent intent) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDestroy() {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*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) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} */
|
39
src/hu/blint/ssldroid/SSLDroidGui.java
Normal file
39
src/hu/blint/ssldroid/SSLDroidGui.java
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
package hu.blint.ssldroid;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.view.View;
|
||||||
|
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;
|
||||||
|
|
||||||
|
@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.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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
189
src/hu/blint/ssldroid/TcpProxy.java
Normal file
189
src/hu/blint/ssldroid/TcpProxy.java
Normal file
@ -0,0 +1,189 @@
|
|||||||
|
package hu.blint.ssldroid;
|
||||||
|
|
||||||
|
import java.net.*;
|
||||||
|
import java.io.*;
|
||||||
|
import java.security.KeyManagementException;
|
||||||
|
import java.security.KeyStore;
|
||||||
|
import java.security.KeyStoreException;
|
||||||
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
import java.security.SecureRandom;
|
||||||
|
import java.security.UnrecoverableKeyException;
|
||||||
|
import javax.net.ssl.KeyManagerFactory;
|
||||||
|
import javax.net.ssl.SSLContext;
|
||||||
|
import javax.net.ssl.SSLSocket;
|
||||||
|
import javax.net.ssl.SSLSocketFactory;
|
||||||
|
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is a modified version of the TcpTunnelGui utility
|
||||||
|
* borrowed from the xml.apache.org project.
|
||||||
|
* @author Balint Kovacs (blint@blint.hu)
|
||||||
|
*/
|
||||||
|
public class TcpProxy {
|
||||||
|
int listenPort;
|
||||||
|
String tunnelHost;
|
||||||
|
int tunnelPort;
|
||||||
|
String keyFile, keyPass;
|
||||||
|
Relay inRelay, outRelay;
|
||||||
|
|
||||||
|
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("SunX509");
|
||||||
|
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());
|
||||||
|
} 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.");
|
||||||
|
} 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 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
|
||||||
|
Thread server = new Thread() {
|
||||||
|
public void run() {
|
||||||
|
ServerSocket ss = null;
|
||||||
|
try {
|
||||||
|
ss = new ServerSocket(ttg.getListenPort());
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.d("SSLDroid", 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;
|
||||||
|
|
||||||
|
try {
|
||||||
|
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());
|
||||||
|
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();
|
||||||
|
|
||||||
|
} catch (Exception ee) {
|
||||||
|
Log.d("SSLDroid","Ouch: "+ ee.getMessage());
|
||||||
|
//ee.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
server.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
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 {
|
||||||
|
//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();
|
||||||
|
|
||||||
|
for (int i = 0; i < n; i++) {
|
||||||
|
if (buf[i] == 7)
|
||||||
|
buf[i] = '#';
|
||||||
|
}
|
||||||
|
|
||||||
|
//String msg = new String(buf, 0, n);
|
||||||
|
//System.out.println(prefix + " : " + msg.length());
|
||||||
|
//System.err.println(msg);
|
||||||
|
}
|
||||||
|
} catch (SocketException e) {
|
||||||
|
} 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 + "...");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//private static final Format dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss,SSS");
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user