mirror of
https://github.com/moparisthebest/SSLDroid
synced 2025-02-19 20:41:49 -05:00
New icon and some minor reformattings
Signed-off-by: Balint Kovacs <blint@blint.hu>
This commit is contained in:
parent
484d940be9
commit
99fb986ac4
@ -1,23 +1,30 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
package="hu.blint.ssldroid"
|
package="hu.blint.ssldroid" android:versionCode="1"
|
||||||
android:versionCode="1"
|
android:versionName="1.0">
|
||||||
android:versionName="1.0">
|
<uses-permission android:name="android.permission.SET_ACTIVITY_WATCHER"></uses-permission>
|
||||||
<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>
|
</manifest>
|
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.
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 |
@ -2,6 +2,8 @@ package hu.blint.ssldroid;
|
|||||||
|
|
||||||
import hu.blint.ssldroid.TcpProxy;
|
import hu.blint.ssldroid.TcpProxy;
|
||||||
import android.app.*;
|
import android.app.*;
|
||||||
|
import android.content.BroadcastReceiver;
|
||||||
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
@ -11,40 +13,57 @@ public class SSLDroid extends Service {
|
|||||||
|
|
||||||
final String TAG = "SSLDroid";
|
final String TAG = "SSLDroid";
|
||||||
TcpProxy tp;
|
TcpProxy tp;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate() {
|
public void onCreate() {
|
||||||
Toast.makeText(this, "SSLDroid Service Started", Toast.LENGTH_LONG).show();
|
// Toast.makeText(this, "SSLDroid Service Started",
|
||||||
Log.d(TAG, "onStart");
|
// Toast.LENGTH_LONG).show();
|
||||||
}
|
// Log.d(TAG, "onStart");
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStart(Intent intent, int startid) {
|
public void onStart(Intent intent, int startid) {
|
||||||
|
|
||||||
int listenPort = 9999; // port to listen on
|
int listenPort = 9999; // port to listen on
|
||||||
int targetPort = 443; // port to connect to
|
int targetPort = 443; // port to connect to
|
||||||
String targetHost = "sogo.balabit.com"; //remote host
|
String targetHost = "sogo.balabit.com"; // remote host
|
||||||
String keyFile = "/mnt/sdcard/blint-imaps.p12";
|
String keyFile = "/mnt/sdcard/blint-imaps.p12";
|
||||||
String keyPass = "titkos";
|
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");
|
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
|
tp = new TcpProxy();
|
||||||
public void onDestroy() {
|
try {
|
||||||
tp.stop();
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
*/
|
@ -9,31 +9,31 @@ import android.view.View.OnClickListener;
|
|||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
|
|
||||||
public class SSLDroidGui extends Activity implements OnClickListener {
|
public class SSLDroidGui extends Activity implements OnClickListener {
|
||||||
private static final String TAG = "ServicesDemo";
|
private static final String TAG = "ServicesDemo";
|
||||||
Button buttonStart, buttonStop;
|
Button buttonStart, buttonStop;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.main);
|
setContentView(R.layout.main);
|
||||||
|
|
||||||
buttonStart = (Button) findViewById(R.id.buttonStart);
|
buttonStart = (Button) findViewById(R.id.buttonStart);
|
||||||
buttonStop = (Button) findViewById(R.id.buttonStop);
|
buttonStop = (Button) findViewById(R.id.buttonStop);
|
||||||
|
|
||||||
buttonStart.setOnClickListener(this);
|
buttonStart.setOnClickListener(this);
|
||||||
buttonStop.setOnClickListener(this);
|
buttonStop.setOnClickListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onClick(View src) {
|
public void onClick(View src) {
|
||||||
switch (src.getId()) {
|
switch (src.getId()) {
|
||||||
case R.id.buttonStart:
|
case R.id.buttonStart:
|
||||||
Log.d(TAG, "onClick: starting service");
|
Log.d(TAG, "onClick: starting service");
|
||||||
startService(new Intent(this, SSLDroid.class));
|
startService(new Intent(this, SSLDroid.class));
|
||||||
break;
|
break;
|
||||||
case R.id.buttonStop:
|
case R.id.buttonStop:
|
||||||
Log.d(TAG, "onClick: stopping service");
|
Log.d(TAG, "onClick: stopping service");
|
||||||
stopService(new Intent(this, SSLDroid.class));
|
stopService(new Intent(this, SSLDroid.class));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -17,179 +17,210 @@ import android.util.Log;
|
|||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is a modified version of the TcpTunnelGui utility
|
* This is a modified version of the TcpTunnelGui utility borrowed from the
|
||||||
* borrowed from the xml.apache.org project.
|
* xml.apache.org project.
|
||||||
* @author Balint Kovacs (blint@blint.hu)
|
|
||||||
*/
|
*/
|
||||||
public class TcpProxy {
|
public class TcpProxy {
|
||||||
int listenPort;
|
int listenPort;
|
||||||
String tunnelHost;
|
String tunnelHost;
|
||||||
int tunnelPort;
|
int tunnelPort;
|
||||||
String keyFile, keyPass;
|
String keyFile, keyPass;
|
||||||
Relay inRelay, outRelay;
|
Relay inRelay, outRelay;
|
||||||
Thread server = null;
|
Thread server = null;
|
||||||
|
|
||||||
public TcpProxy() {
|
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 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
|
public int getListenPort() {
|
||||||
Thread fromBrowserToServer = new Relay(sc.getInputStream(), st.getOutputStream(), "<<< B2S <<<");
|
return listenPort;
|
||||||
Thread fromServerToBrowser = new Relay(st.getInputStream(), sc.getOutputStream(), ">>> S2B >>>");
|
}
|
||||||
|
|
||||||
fromBrowserToServer.start();
|
public String getTunnelHost() {
|
||||||
fromServerToBrowser.start();
|
return tunnelHost;
|
||||||
|
}
|
||||||
|
|
||||||
if (server.isInterrupted())
|
public int getTunnelPort() {
|
||||||
ss.close();
|
return tunnelPort;
|
||||||
|
}
|
||||||
} catch (Exception ee) {
|
|
||||||
Log.d("SSLDroid","Ouch: "+ ee.getMessage());
|
|
||||||
//ee.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
server.start();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void stop(){
|
public String getKeyFile() {
|
||||||
if (server != null)
|
return keyFile;
|
||||||
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 Relay(InputStream in, OutputStream out, String prefix) {
|
public String getKeyPass() {
|
||||||
this.in = in;
|
return keyPass;
|
||||||
this.out = out;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public void run() {
|
private static SSLSocketFactory sslSocketFactory;
|
||||||
int n = 0;
|
|
||||||
|
|
||||||
try {
|
public static final SSLSocketFactory getSocketFactory(String pkcsFile,
|
||||||
while ((n = in.read(buf)) > 0) {
|
String pwd) {
|
||||||
out.write(buf, 0, n);
|
if (sslSocketFactory == null) {
|
||||||
out.flush();
|
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++) {
|
} catch (FileNotFoundException e) {
|
||||||
if (buf[i] == 7)
|
Log.d("SSLDroid", "Error loading the client certificate file:"
|
||||||
buf[i] = '#';
|
+ e.getMessage());
|
||||||
}
|
// Toast.makeText(none, "SSLDroid Sulyos Errorhiba" +
|
||||||
|
// e.getMessage(), Toast.LENGTH_LONG).show();
|
||||||
if (Thread.interrupted()) {
|
} catch (KeyManagementException e) {
|
||||||
//We've been interrupted: no more serving.
|
Log
|
||||||
return;
|
.d("SSLDroid", "No SSL algorithm support: "
|
||||||
}
|
+ e.getMessage());
|
||||||
}
|
} catch (NoSuchAlgorithmException e) {
|
||||||
} catch (SocketException e) {
|
Log.d("SSLDroid", "No common SSL algorithm found: "
|
||||||
Log.d("SSLDroid", e.getMessage());
|
+ e.getMessage());
|
||||||
} catch (IOException e) {
|
} catch (KeyStoreException e) {
|
||||||
Log.d("SSLDroid", e.getMessage());
|
Log
|
||||||
} finally {
|
.d("SSLDroid", "Error setting up keystore:"
|
||||||
try {
|
+ e.getMessage());
|
||||||
in.close();
|
} catch (java.security.cert.CertificateException e) {
|
||||||
out.close();
|
Log.d("SSLDroid", "Error loading the client certificate:"
|
||||||
} catch (IOException e) {
|
+ e.getMessage());
|
||||||
Log.d("SSLDroid", 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...");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user