2011-03-21 12:27:51 +01:00
|
|
|
package hu.blint.ssldroid;
|
|
|
|
|
2011-04-12 17:06:00 +02:00
|
|
|
import java.io.FileWriter;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.PrintWriter;
|
|
|
|
import java.net.ServerSocket;
|
|
|
|
import java.sql.Timestamp;
|
|
|
|
import java.util.Date;
|
2011-03-21 12:27:51 +01:00
|
|
|
|
|
|
|
import android.util.Log;
|
|
|
|
|
|
|
|
/**
|
2011-03-24 20:59:48 +01:00
|
|
|
* This is a modified version of the TcpTunnelGui utility borrowed from the
|
|
|
|
* xml.apache.org project.
|
2011-03-21 12:27:51 +01:00
|
|
|
*/
|
|
|
|
public class TcpProxy {
|
2011-03-24 20:59:48 +01:00
|
|
|
int listenPort;
|
|
|
|
String tunnelHost;
|
|
|
|
int tunnelPort;
|
|
|
|
String keyFile, keyPass;
|
|
|
|
Thread server = null;
|
2011-04-12 17:06:00 +02:00
|
|
|
ServerSocket ss = null;
|
2011-03-24 20:59:48 +01:00
|
|
|
|
|
|
|
public TcpProxy() {
|
|
|
|
}
|
|
|
|
|
2011-04-12 17:06:00 +02:00
|
|
|
/*public TcpProxy(int listenPort, String tunnelHost, int tunnelPort,
|
2011-03-24 20:59:48 +01:00
|
|
|
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;
|
|
|
|
}
|
2011-04-12 17:06:00 +02:00
|
|
|
*/
|
|
|
|
public void createNotification(String title, String text) {
|
|
|
|
try {
|
|
|
|
FileWriter outFile = new FileWriter("/mnt/sdcard/ssldroid.txt");
|
|
|
|
PrintWriter out = new PrintWriter(outFile);
|
|
|
|
Date date= new Date();
|
|
|
|
|
|
|
|
out.println(new Timestamp(date.getTime())+" "+title+" "+text);
|
|
|
|
out.close();
|
|
|
|
} catch (IOException e){
|
|
|
|
return;
|
2011-03-24 20:59:48 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void serve(int listenPort, String tunnelHost, int tunnelPort,
|
|
|
|
String keyFile, String keyPass) throws IOException {
|
2011-04-12 17:06:00 +02:00
|
|
|
//final TcpProxy ttg = new TcpProxy(listenPort, tunnelHost, tunnelPort,keyFile, keyPass);
|
2011-03-24 20:59:48 +01:00
|
|
|
// create the server thread
|
2011-04-12 17:06:00 +02:00
|
|
|
try {
|
|
|
|
ss = new ServerSocket(listenPort);
|
|
|
|
Log.d("SSLDroid", "Listening for connections on port "
|
|
|
|
+ listenPort + " ...");
|
|
|
|
//ttg.doLog("Listening for connections on port " + ttg.getListenPort() + " ...");
|
|
|
|
} catch (Exception e) {
|
|
|
|
Log.d("SSLDroid", "Error setting up listening socket: "
|
|
|
|
+ e.toString());
|
|
|
|
//createNotification(e.getMessage(), "Error setting up listening socket: "+e.toString());
|
|
|
|
//e.printStackTrace();
|
|
|
|
System.exit(1);
|
|
|
|
}
|
|
|
|
server = new TcpProxyServerThread(ss, listenPort, tunnelHost, tunnelPort, keyFile, keyPass);
|
2011-03-24 20:59:48 +01:00
|
|
|
server.start();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void stop() {
|
2011-04-12 17:06:00 +02:00
|
|
|
if (server != null){
|
2011-03-24 20:59:48 +01:00
|
|
|
try {
|
2011-04-12 17:06:00 +02:00
|
|
|
ss.close();
|
|
|
|
server.interrupt();
|
|
|
|
} catch (Exception e) {
|
|
|
|
Log.d("SSLDroid", "Interrupt failure: " + e.toString());
|
|
|
|
createNotification(e.getMessage(), "Ouch: "+e.toString());;
|
2011-03-21 12:27:51 +01:00
|
|
|
}
|
2011-03-24 20:59:48 +01:00
|
|
|
}
|
2011-04-12 17:06:00 +02:00
|
|
|
Log.d("SSLDroid", "Stopping service");
|
2011-03-21 12:27:51 +01:00
|
|
|
}
|
2011-04-12 17:06:00 +02:00
|
|
|
|
|
|
|
|
|
|
|
}
|