diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 8941c9a8..bdf8bfbd 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -1,6 +1,6 @@
- * SSLSocketFactory can be used to validate the identity of the HTTPS
- * server against a list of trusted certificates and to authenticate to
- * the HTTPS server using a private key.
- *
- * SSLSocketFactory will enable server authentication when supplied with
- * a {@link KeyStore truststore} file containg one or several trusted
- * certificates. The client secure socket will reject the connection during
- * the SSL session handshake if the target HTTPS server attempts to
- * authenticate itself with a non-trusted certificate.
- *
- * Use JDK keytool utility to import a trusted certificate and generate a truststore file:
- *
- * keytool -import -alias "my server cert" -file server.crt -keystore my.truststore
- *
- *
- * SSLSocketFactory will enable client authentication when supplied with - * a {@link KeyStore keystore} file containg a private key/public certificate - * pair. The client secure socket will use the private key to authenticate - * itself to the target HTTPS server during the SSL session handshake if - * requested to do so by the server. - * The target HTTPS server will in its turn verify the certificate presented - * by the client in order to establish client's authenticity - *
- * - *- * Use the following sequence of actions to generate a keystore file - *
- *- * Use JDK keytool utility to generate a new key - *
keytool -genkey -v -alias "my client key" -validity 365 -keystore my.keystore- * For simplicity use the same password for the key as that of the keystore - * - *
- * Issue a certificate signing request (CSR) - *
keytool -certreq -alias "my client key" -file mycertreq.csr -keystore my.keystore- * - *
- * Send the certificate request to the trusted Certificate Authority for signature. - * One may choose to act as her own CA and sign the certificate request using a PKI - * tool, such as OpenSSL. - *
- *- * Import the trusted CA root certificate - *
keytool -import -alias "my trusted ca" -file caroot.crt -keystore my.keystore- * - *
- * Import the PKCS#7 file containg the complete certificate chain - *
keytool -import -alias "my client key" -file mycert.p7 -keystore my.keystore- * - *
- * Verify the content the resultant keystore file - *
keytool -list -v -keystore my.keystore- * - *
true
- *
- * @throws IllegalArgumentException if the argument is invalid
- */
- public boolean isSecure(Socket sock)
- throws IllegalArgumentException {
-
- if (sock == null) {
- throw new IllegalArgumentException("Socket may not be null.");
- }
- // This instanceof check is in line with createSocket() above.
- if (!(sock instanceof SSLSocket)) {
- throw new IllegalArgumentException
- ("Socket not created by this factory.");
- }
- // This check is performed last since it calls the argument object.
- if (sock.isClosed()) {
- throw new IllegalArgumentException("Socket is closed.");
- }
-
- return true;
-
- } // isSecure
-
-
- // non-javadoc, see interface LayeredSocketFactory
- public Socket createSocket(
- final Socket socket,
- final String host,
- final int port,
- final boolean autoClose
- ) throws IOException, UnknownHostException {
- SSLSocket sslSocket = (SSLSocket) this.socketfactory.createSocket(
- socket,
- host,
- port,
- autoClose
- );
- hostnameVerifier.verify(host, sslSocket);
- // verifyHostName() didn't blowup - good!
- return sslSocket;
- }
-
- public void setHostnameVerifier(X509HostnameVerifier hostnameVerifier) {
- if ( hostnameVerifier == null ) {
- throw new IllegalArgumentException("Hostname verifier may not be null");
- }
- this.hostnameVerifier = hostnameVerifier;
- }
-
- public X509HostnameVerifier getHostnameVerifier() {
- return hostnameVerifier;
- }
-
- public class SSLException extends IOException {
- private static final long serialVersionUID = 1L;
-
- public SSLException(String msg) {
- super(msg);
- }
- };
-
-
-}
\ No newline at end of file
diff --git a/src/org/torproject/android/net/MyDefaultClientConnectionOperator.java b/src/org/torproject/android/net/MyDefaultClientConnectionOperator.java
deleted file mode 100644
index 94200880..00000000
--- a/src/org/torproject/android/net/MyDefaultClientConnectionOperator.java
+++ /dev/null
@@ -1,70 +0,0 @@
-package org.torproject.android.net;
-
-import java.io.IOException;
-import java.net.ConnectException;
-import java.net.InetAddress;
-import java.net.Socket;
-
-import org.apache.http.HttpHost;
-import org.apache.http.conn.HttpHostConnectException;
-import org.apache.http.conn.OperatedClientConnection;
-import org.apache.http.conn.scheme.Scheme;
-import org.apache.http.conn.scheme.SchemeRegistry;
-import org.apache.http.conn.scheme.SocketFactory;
-import org.apache.http.impl.conn.DefaultClientConnectionOperator;
-import org.apache.http.params.HttpParams;
-import org.apache.http.protocol.HttpContext;
-
-public class MyDefaultClientConnectionOperator extends
- DefaultClientConnectionOperator {
-
- public MyDefaultClientConnectionOperator(SchemeRegistry schemes) {
- super(schemes);
- }
-
- @Override
- public void openConnection(OperatedClientConnection conn, HttpHost target,
- InetAddress local, HttpContext context, HttpParams params)
- throws IOException {
- if (conn == null) {
- throw new IllegalArgumentException
- ("Connection must not be null.");
- }
- if (target == null) {
- throw new IllegalArgumentException
- ("Target host must not be null.");
- }
- // local address may be null
- //@@@ is context allowed to be null?
- if (params == null) {
- throw new IllegalArgumentException
- ("Parameters must not be null.");
- }
- if (conn.isOpen()) {
- throw new IllegalArgumentException
- ("Connection must not be open.");
- }
-
- final Scheme schm = schemeRegistry.getScheme(target.getSchemeName());
- final SocketFactory sf = schm.getSocketFactory();
-
- Socket sock = sf.createSocket();
- conn.opening(sock, target);
-
- try {
- Socket connsock = sf.connectSocket(sock, target.getHostName(),
- schm.resolvePort(target.getPort()),
- local, 0, params);
-
- if (sock != connsock) {
- sock = connsock;
- conn.opening(sock, target);
- }
- } catch (ConnectException ex) {
- throw new HttpHostConnectException(target, ex);
- }
- prepareSocket(sock, context, params);
- conn.openCompleted(sf.isSecure(sock), params);
- }
-
-}
diff --git a/src/org/torproject/android/net/MyThreadSafeClientConnManager.java b/src/org/torproject/android/net/MyThreadSafeClientConnManager.java
deleted file mode 100644
index 77e9c2ca..00000000
--- a/src/org/torproject/android/net/MyThreadSafeClientConnManager.java
+++ /dev/null
@@ -1,21 +0,0 @@
-package org.torproject.android.net;
-
-import org.apache.http.conn.ClientConnectionOperator;
-import org.apache.http.conn.scheme.SchemeRegistry;
-import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
-import org.apache.http.params.HttpParams;
-
-
-public class MyThreadSafeClientConnManager extends ThreadSafeClientConnManager {
-
- public MyThreadSafeClientConnManager(HttpParams params, SchemeRegistry schreg) {
- super(params, schreg);
-
- }
-
- @Override
- protected ClientConnectionOperator createConnectionOperator(
- SchemeRegistry schreg) {
- return new MyDefaultClientConnectionOperator(schreg);
- }
-}
diff --git a/src/org/torproject/android/net/SOCKSHttpClient.java b/src/org/torproject/android/net/SOCKSHttpClient.java
deleted file mode 100644
index d49d67ce..00000000
--- a/src/org/torproject/android/net/SOCKSHttpClient.java
+++ /dev/null
@@ -1,71 +0,0 @@
-package org.torproject.android.net;
-
-import org.apache.http.HttpVersion;
-import org.apache.http.conn.ClientConnectionManager;
-import org.apache.http.conn.scheme.PlainSocketFactory;
-import org.apache.http.conn.scheme.Scheme;
-import org.apache.http.conn.scheme.SchemeRegistry;
-import org.apache.http.conn.ssl.SSLSocketFactory;
-import org.apache.http.impl.client.DefaultHttpClient;
-import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
-import org.apache.http.params.BasicHttpParams;
-import org.apache.http.params.HttpParams;
-import org.apache.http.params.HttpProtocolParams;
-
-public class SOCKSHttpClient extends DefaultHttpClient {
-
- private final static String DEFAULT_HOST = "127.0.0.1";
- private final static int DEFAULT_PORT = 9050;
-
- private static ClientConnectionManager ccm = null;
- private static HttpParams params = null;
-
- public SOCKSHttpClient ()
- {
-
- super(initConnectionManager(), initParams());
-
-
- }
-
- private void setSystemProperties ()
- {
-// System.getProperties().put("socks.proxySet","true");
- // System.getProperties().put("socks.proxyHost",DEFAULT_HOST);
- // System.getProperties().put("socks.proxyPort", DEFAULT_PORT+"");
-
- }
-
- private static ClientConnectionManager initConnectionManager ()
- {
- if (ccm == null)
- {
- SchemeRegistry supportedSchemes = new SchemeRegistry();
-
-
- supportedSchemes.register(new Scheme("http",
- SocksSocketFactory.getSocketFactory(), 80));
-
- supportedSchemes.register(new Scheme("https",
- ModSSLSocketFactory.getSocketFactory(), 443));
-
- ccm = new MyThreadSafeClientConnManager(initParams(), supportedSchemes);
- }
-
- return ccm;
- }
-
- private static HttpParams initParams ()
- {
- if (params == null)
- {
- // prepare parameters
- params = new BasicHttpParams();
- HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
- HttpProtocolParams.setContentCharset(params, "UTF-8");
- HttpProtocolParams.setUseExpectContinue(params, true);
- }
-
- return params;
- }
-}
diff --git a/src/org/torproject/android/net/SocksClient.java b/src/org/torproject/android/net/SocksClient.java
deleted file mode 100644
index bf8fd49d..00000000
--- a/src/org/torproject/android/net/SocksClient.java
+++ /dev/null
@@ -1,146 +0,0 @@
-/* Copyright (c) 2009, Nathan Freitas, Orbot / The Guardian Project - http://openideals.com/guardian */
-/* See LICENSE for licensing information */
-
-/** SOCKS aware echo client*/
-
-package org.torproject.android.net;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.OutputStream;
-import java.net.InetAddress;
-import java.net.Socket;
-import java.net.UnknownHostException;
-
-import net.sourceforge.jsocks.socks.InetRange;
-import net.sourceforge.jsocks.socks.Proxy;
-import net.sourceforge.jsocks.socks.SocksException;
-import net.sourceforge.jsocks.socks.SocksSocket;
-
-import org.torproject.android.TorConstants;
-
-import android.util.Log;
-
-
-public class SocksClient implements Runnable {
-
- @SuppressWarnings("unused")
- private int port;
-
- @SuppressWarnings("unused")
- private InetAddress hostIP;
-
- private Socket ss;
- private InputStream in;
- private OutputStream out;
-
- @SuppressWarnings("unused")
-private static final int BUF_SIZE = 1024;
- private static final String IP_LOCALHOST = "127.0.0.1";
-
- public SocksClient(String host,int port)
- throws IOException,UnknownHostException,SocksException{
- this.port = port;
-
- ss = new SocksSocket(host, port);
- out = ss.getOutputStream();
- in = ss.getInputStream();
- Log.d(getClass().getName(),"Connected...");
- Log.d(getClass().getName(),"TO: "+host+":"+port);
- Log.d(getClass().getName(),"ViaProxy: "+ss.getLocalAddress().getHostAddress()
- +":"+ss.getLocalPort());
-
- }
-
- public void close()throws IOException{
- ss.close();
- }
- public void send(String s) throws IOException{
- out.write(s.getBytes());
- }
-
- public void run(){
- byte[] buf = new byte[1024];
- int bytes_read;
- try{
- while((bytes_read = in.read(buf)) > 0){
- System.out.write(buf,0,bytes_read);
- }
- }catch(IOException io_ex){
- io_ex.printStackTrace();
- }
- }
-
- public static void usage(){
- System.err.print(
- "Usage: java SocksTest host port [socksHost socksPort]\n");
- }
-
-
- public static void main(String args[]){
- int port;
- String host;
- int proxyPort;
- String proxyHost;
-
- if(args.length > 1 && args.length < 5){
- try{
-
- host = args[0];
- port = Integer.parseInt(args[1]);
-
- proxyPort =(args.length > 3)? Integer.parseInt(args[3])
- : 9050;
-
- host = args[0];
- proxyHost =(args.length > 2)? args[2]
- : IP_LOCALHOST;
-
- Proxy.setDefaultProxy(proxyHost,proxyPort,"KOUKY001");
- //Proxy.setDefaultProxy(proxyHost,proxyPort);
- InetRange inetRange = new InetRange();
- inetRange.add(InetAddress.getByName("localhost"));
- Proxy.getDefaultProxy().setDirect(inetRange);
-
-
- SocksClient st = new SocksClient(host,port);
- Thread thread = new Thread(st);
- thread.start();
-
- BufferedReader in = new BufferedReader(
- new InputStreamReader(System.in));
- String s;
-
- s = in.readLine();
- while(s != null){
- st.send(s+"\r\n");
- //try{
- //Thread.currentThread().sleep(10);
- //}catch(InterruptedException i_ex){
- //}
- s = in.readLine();
- }
- st.close();
- System.exit(1);
-
- }catch(SocksException s_ex){
- System.err.println("SocksException:"+s_ex);
- s_ex.printStackTrace();
- System.exit(1);
- }catch(IOException io_ex){
- io_ex.printStackTrace();
- System.exit(1);
- }catch(NumberFormatException num_ex){
- usage();
- num_ex.printStackTrace();
- System.exit(1);
- }
-
- }else{
- usage();
- }
- }
-
-}//End of class
diff --git a/src/org/torproject/android/net/SocksSocketFactory.java b/src/org/torproject/android/net/SocksSocketFactory.java
deleted file mode 100644
index fa2ca4f7..00000000
--- a/src/org/torproject/android/net/SocksSocketFactory.java
+++ /dev/null
@@ -1,141 +0,0 @@
-/**
- * Shadow - Anonymous web browser for Android devices
- * Copyright (C) 2009 Connell Gauld
- *
- * Thanks to University of Cambridge,
- * Alastair Beresford and Andrew Rice
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * version 2 as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
- */
-
-package org.torproject.android.net;
-
-import java.io.IOException;
-import java.net.InetAddress;
-import java.net.InetSocketAddress;
-import java.net.Socket;
-import java.net.UnknownHostException;
-
-import net.sourceforge.jsocks.socks.Socks5Proxy;
-import net.sourceforge.jsocks.socks.SocksException;
-import net.sourceforge.jsocks.socks.SocksSocket;
-
-
-import org.apache.http.conn.ConnectTimeoutException;
-import org.apache.http.conn.scheme.SocketFactory;
-import org.apache.http.params.HttpConnectionParams;
-import org.apache.http.params.HttpParams;
-
-import android.util.Log;
-
-
-/**
- * Provides sockets for an HttpClient connection.
- * @author cmg47
- *
- */
-public class SocksSocketFactory implements SocketFactory {
-
- SocksSocket server = null;
- private static Socks5Proxy sProxy = null;
-
- private final static String DEFAULT_HOST = "127.0.0.1";
- private final static int DEFAULT_PORT = 9050;
-
- /**
- * Construct a SocksSocketFactory that uses the provided SOCKS proxy.
- * @param proxyaddress the IP address of the SOCKS proxy
- * @param proxyport the port of the SOCKS proxy
- */
- public SocksSocketFactory(String proxyaddress, int proxyport) {
-
-
- try {
- sProxy = new Socks5Proxy(proxyaddress, proxyport);
- } catch (UnknownHostException e) {
- // TODO Auto-generated catch block
- Log.d("TOR_SERVICE","SocksSF couldn't connect",e);
- }
-
- sProxy.resolveAddrLocally(false);
-
-
- }
-
- public Socket connectSocket(Socket sock, String host, int port,
- InetAddress localAddress, int localPort, HttpParams params) throws IOException,
- UnknownHostException, ConnectTimeoutException {
-
- Log.d("TOR_SERVICE","SocksSocketFactory: connectSocket: " + host + ":" + port);
-
- if (host == null) {
- throw new IllegalArgumentException("Target host may not be null.");
- }
- if (params == null) {
- throw new IllegalArgumentException("Parameters may not be null.");
- }
-
- // int timeout = HttpConnectionParams.getConnectionTimeout(params);
-
- // Pipe this socket over the proxy
- // sock = mSocksProxy.connectSocksProxy(sock, host, port, timeout);
-
-
-
- try {
- sock = new SocksSocket(sProxy,host, port);
-
-
-
- sock.setSoTimeout(0); //indef
-
-
- if ((localAddress != null) || (localPort > 0)) {
-
- // we need to bind explicitly
- if (localPort < 0)
- localPort = 0; // indicates "any"
-
- InetSocketAddress isa =
- new InetSocketAddress(localAddress, localPort);
- sock.bind(isa);
- }
-
-
- } catch (SocksException e) {
- Log.e("TOR_SERVICE","error connecting socks to" + host + ":" + port,e);
- } catch (UnknownHostException e) {
- Log.e("TOR_SERVICE","error connecting socks to" + host + ":" + port,e);
- }
-
- return sock;
-
- }
-
-
-
- public Socket createSocket() throws IOException {
- return new Socket();
- }
-
- public boolean isSecure(Socket sock) throws IllegalArgumentException {
- return false;
- }
-
- public static SocketFactory getSocketFactory ()
- {
- return new SocksSocketFactory (DEFAULT_HOST, DEFAULT_PORT);
- }
-
-}
diff --git a/src/org/torproject/android/service/TorService.java b/src/org/torproject/android/service/TorService.java
index b1ad2beb..24d80053 100644
--- a/src/org/torproject/android/service/TorService.java
+++ b/src/org/torproject/android/service/TorService.java
@@ -294,6 +294,8 @@ public class TorService extends Service implements TorServiceConstants, Runnable
private void killTorProcess () throws Exception
{
+ //android.os.Debug.waitForDebugger();
+
StringBuilder log = new StringBuilder();
int procId = -1;
@@ -301,9 +303,9 @@ public class TorService extends Service implements TorServiceConstants, Runnable
{
logNotice("Using control port to shutdown Tor");
+
try {
logNotice("sending SHUTDOWN signal to Tor process");
-
conn.shutdownTor("SHUTDOWN");
@@ -313,30 +315,18 @@ public class TorService extends Service implements TorServiceConstants, Runnable
conn = null;
}
- else
- {
-
- logNotice("Checking for existing Tor process via path: " + torBinaryPath);
- procId = TorServiceUtils.findProcessId(torBinaryPath);
-
- while (procId != -1)
- {
-
- logNotice("Found Tor PID=" + procId + " - killing now...");
-
- String[] cmd = { SHELL_CMD_KILL + ' ' + procId + "" };
- TorServiceUtils.doShellCommand(cmd,log, false, false);
-
- procId = TorServiceUtils.findProcessId(torBinaryPath);
- }
-
- }
-
- logNotice("Checking for existing Privoxy process via path: " + privoxyPath);
- procId = TorServiceUtils.findProcessId(privoxyPath);
+ while ((procId = TorServiceUtils.findProcessId(torBinaryPath)) != -1)
+ {
+
+ logNotice("Found Tor PID=" + procId + " - killing now...");
+
+ String[] cmd = { SHELL_CMD_KILL + ' ' + procId + "" };
+ TorServiceUtils.doShellCommand(cmd,log, false, false);
- while (procId != -1)
+ }
+
+ while ((procId = TorServiceUtils.findProcessId(privoxyPath)) != -1)
{
logNotice("Found Privoxy PID=" + procId + " - killing now...");
@@ -344,7 +334,6 @@ public class TorService extends Service implements TorServiceConstants, Runnable
TorServiceUtils.doShellCommand(cmd,log, false, false);
- procId = TorServiceUtils.findProcessId(privoxyPath);
}
}
@@ -444,7 +433,6 @@ public class TorService extends Service implements TorServiceConstants, Runnable
private boolean checkTorBinaries () throws Exception
{
-
appHome = "/data/data/" + TOR_APP_USERNAME + "/";
//appHome = getApplicationContext().getFilesDir().getAbsolutePath();
@@ -1353,8 +1341,11 @@ public class TorService extends Service implements TorServiceConstants, Runnable
boolean enableTransparentProxy = prefs.getBoolean("pref_transparent", false);
boolean transProxyAll = prefs.getBoolean("pref_transparent_all", false);
+ boolean transProxyPortFallback = prefs.getBoolean("pref_transparent_port_fallback", false);
+
logNotice ("Transparent Proxying: " + enableTransparentProxy);
+ String portProxyList = prefs.getString("pref_port_list", "");
if (enabled)
{
@@ -1371,6 +1362,16 @@ public class TorService extends Service implements TorServiceConstants, Runnable
logNotice ("TorTransProxy resp code: " + code);
+ //this is for Androids w/o owner module support as a circumvention only fallback
+ if (transProxyPortFallback)
+ {
+ StringTokenizer st = new StringTokenizer(portProxyList, ",");
+
+ while (st.hasMoreTokens())
+ TorTransProxy.setTransparentProxyingByPort(this, Integer.parseInt(st.nextToken()));
+
+ }
+
return true;
diff --git a/src/org/torproject/android/service/TorServiceConstants.java b/src/org/torproject/android/service/TorServiceConstants.java
index 5dbc031d..caadf35d 100644
--- a/src/org/torproject/android/service/TorServiceConstants.java
+++ b/src/org/torproject/android/service/TorServiceConstants.java
@@ -6,7 +6,7 @@ public interface TorServiceConstants {
public final static String TAG = "ORBOT";
- public static boolean LOG_OUTPUT_TO_DEBUG = false;
+ public static boolean LOG_OUTPUT_TO_DEBUG = true;
public final static String TOR_APP_USERNAME = "org.torproject.android";
@@ -31,7 +31,7 @@ public interface TorServiceConstants {
//various console cmds
public final static String SHELL_CMD_CHMOD = "chmod";
- public final static String SHELL_CMD_KILL = "kill";
+ public final static String SHELL_CMD_KILL = "kill -9";
public final static String SHELL_CMD_RM = "rm";
public final static String SHELL_CMD_PS = "ps";
public final static String SHELL_CMD_PIDOF = "pidof";
diff --git a/src/org/torproject/android/service/TorServiceUtils.java b/src/org/torproject/android/service/TorServiceUtils.java
index 9d0c7c60..f61ea2be 100644
--- a/src/org/torproject/android/service/TorServiceUtils.java
+++ b/src/org/torproject/android/service/TorServiceUtils.java
@@ -3,6 +3,7 @@
package org.torproject.android.service;
import java.io.BufferedReader;
+import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
@@ -66,7 +67,6 @@ public class TorServiceUtils implements TorServiceConstants {
try
{
procId = findProcessIdWithPS(command);
-
}
catch (Exception e2)
{
@@ -87,23 +87,27 @@ public class TorServiceUtils implements TorServiceConstants {
Process procPs = null;
- procPs = r.exec(SHELL_CMD_PIDOF);
+ String baseName = new File(command).getName();
+ //fix contributed my mikos on 2010.12.10
+ procPs = r.exec(new String[] {SHELL_CMD_PIDOF, baseName});
+ //procPs = r.exec(SHELL_CMD_PIDOF);
BufferedReader reader = new BufferedReader(new InputStreamReader(procPs.getInputStream()));
String line = null;
-
while ((line = reader.readLine())!=null)
{
- if (line.indexOf(command)!=-1)
+
+ try
{
-
//this line should just be the process id
procId = Integer.parseInt(line.trim());
-
-
break;
}
+ catch (NumberFormatException e)
+ {
+ logNotice("unable to parse process pid: " + line);
+ }
}
@@ -128,7 +132,7 @@ public class TorServiceUtils implements TorServiceConstants {
while ((line = reader.readLine())!=null)
{
- if (line.indexOf(command)!=-1)
+ if (line.indexOf(' ' + command)!=-1)
{
StringTokenizer st = new StringTokenizer(line," ");
diff --git a/src/org/torproject/android/service/TorTransProxy.java b/src/org/torproject/android/service/TorTransProxy.java
index b9a44380..00610f93 100644
--- a/src/org/torproject/android/service/TorTransProxy.java
+++ b/src/org/torproject/android/service/TorTransProxy.java
@@ -42,7 +42,7 @@ public class TorTransProxy implements TorServiceConstants {
out = out.substring(out.indexOf(" v")+2);
out = out.substring(0,out.indexOf(":"));
- return out;
+ return out.trim();
}
@@ -221,6 +221,15 @@ public class TorTransProxy implements TorServiceConstants {
logNotice("enabling transproxy for app: " + apps[i].getUsername() + "(" + apps[i].getUid() + ")");
+ /*
+ * iptables -t nat -A OUTPUT -p tcp -m owner --uid-owner anonymous -m tcp --syn -j REDIRECT --to-ports 9040
+iptables -t nat -A OUTPUT -p udp -m owner --uid-owner anonymous -m udp --dport 53 -j REDIRECT --to-ports 53
+iptables -t nat -A OUTPUT -m owner --uid-owner anonymous -j DROP
+ */
+
+
+ //iptables -t nat -A output -p tcp -m owner --uid-owner 100 -m tcp --sync -j REDIRECT --to-ports 9040
+
//TCP
script.append(baseDir);
script.append("iptables -t nat");
@@ -243,7 +252,7 @@ public class TorTransProxy implements TorServiceConstants {
script.append("iptables -t nat");
script.append(" -A OUTPUT -p udp -m owner --uid-owner ");
script.append(apps[i].getUid());
- script.append(" --dport ");
+ script.append(" -m udp --dport ");
script.append(STANDARD_DNS_PORT);
if (ipTablesOld)
@@ -256,15 +265,14 @@ public class TorTransProxy implements TorServiceConstants {
script.append(" || exit\n");
- //EVERYTHING ELSE UDP - DROP!
+ //EVERYTHING ELSE - DROP!
if (ipTablesOld) //for some reason this doesn't work on iptables 1.3.7
{
- script.append(baseDir);
- script.append("iptables");
- script.append(" -t nat -A OUTPUT -m owner --uid-owner ");
+ script.append("iptables -t nat");
+ script.append(" -A OUTPUT -m owner --uid-owner ");
script.append(apps[i].getUid());
- script.append(" -j DROP"); //drop all other packets as Tor won't handle them
+ script.append(" -j DROP");
script.append(" || exit\n");
}
else
@@ -310,5 +318,92 @@ public class TorTransProxy implements TorServiceConstants {
return code;
}
+ public static int setTransparentProxyingByPort(Context context, int port) throws Exception
+ {
+
+ //android.os.Debug.waitForDebugger();
+
+ //redirectDNSResolvConf(); //not working yet
+
+ String baseDir = findBaseDir();
+
+ String iptablesVersion = getIPTablesVersion();
+ logNotice( "iptables version: " + iptablesVersion);
+
+ boolean ipTablesOld = false;
+ if (iptablesVersion != null && iptablesVersion.startsWith("1.3")){
+ ipTablesOld = true;
+ }
+
+ StringBuilder script = new StringBuilder();
+
+ StringBuilder res = new StringBuilder();
+ int code = -1;
+
+ String[] cmdFlush = {script.toString()};
+ code = TorServiceUtils.doShellCommand(cmdFlush, res, true, true);
+ //String msg = res.toString(); //get stdout from command
+
+ script = new StringBuilder();
+
+ //TCP
+ //iptables -t nat -A PREROUTING -i eth0 -p tcp --dport $srcPortNumber -j REDIRECT --to-port $dstPortNumbe
+
+ script.append(baseDir);
+ script.append("iptables -t nat");
+ script.append(" -A OUTPUT -p tcp");
+ script.append(" --dport ");
+ script.append(port);
+ //script.append(" -m tcp --syn");
+
+ if (ipTablesOld)
+ script.append(" -j DNAT --to 127.0.0.1:");
+ else
+ script.append(" -j REDIRECT --to-ports ");
+
+ script.append(TOR_TRANSPROXY_PORT);
+
+ script.append(" || exit\n");
+
+ script.append(baseDir);
+ script.append("iptables -t nat");
+ script.append(" -A OUTPUT -p udp");
+ script.append(" --dport ");
+ script.append(port);
+
+ if (ipTablesOld)
+ script.append(" -j DNAT --to 127.0.0.1:");
+ else
+ script.append(" -j REDIRECT --to-ports ");
+
+ script.append(TOR_TRANSPROXY_PORT);
+
+ script.append(" || exit\n");
+
+ //DNS
+ script.append(baseDir);
+ script.append("iptables -t nat");
+ script.append(" -A OUTPUT -p udp ");
+ script.append(" -m udp --dport ");
+ script.append(STANDARD_DNS_PORT);
+
+ if (ipTablesOld)
+ script.append(" -j DNAT --to 127.0.0.1:");
+ else
+ script.append(" -j REDIRECT --to-ports ");
+
+ script.append(TOR_DNS_PORT);
+
+ script.append(" || exit\n");
+
+
+ String[] cmdAdd = {script.toString()};
+ code = TorServiceUtils.doShellCommand(cmdAdd, res, true, true);
+ String msg = res.toString();
+ logNotice(cmdAdd[0] + ";errCode=" + code + ";resp=" + msg);
+
+ return code;
+ }
+
}