From 167ec2e5c8894e343847decbdff12a954d48abcd Mon Sep 17 00:00:00 2001 From: Nathan Freitas Date: Fri, 17 Sep 2010 16:52:41 +0000 Subject: [PATCH] making sure the latest updates are pushed up svn:r23210 --- AndroidManifest.xml | 5 +- .../android/service/TorServiceConstants.java | 5 +- .../android/service/TorTransProxy.java | 68 ++++++++++++++++--- 3 files changed, 67 insertions(+), 11 deletions(-) diff --git a/AndroidManifest.xml b/AndroidManifest.xml index de67238e..471b1213 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -5,7 +5,7 @@ - + @@ -33,7 +33,8 @@ - + + diff --git a/src/org/torproject/android/service/TorServiceConstants.java b/src/org/torproject/android/service/TorServiceConstants.java index 1f0eb1e0..dc51c2cc 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"; @@ -56,6 +56,9 @@ public interface TorServiceConstants { public final static String IP_LOCALHOST = "127.0.0.1"; public final static int TOR_CONTROL_PORT = 9051; public final static int UPDATE_TIMEOUT = 1000; + public final static int TOR_TRANSPROXY_PORT = 9040; + public final static int STANDARD_DNS_PORT = 53; + public final static int TOR_DNS_PORT = 5400; //path to check Tor against public final static String URL_TOR_CHECK = "https://check.torproject.org"; diff --git a/src/org/torproject/android/service/TorTransProxy.java b/src/org/torproject/android/service/TorTransProxy.java index f46190a9..170feea0 100644 --- a/src/org/torproject/android/service/TorTransProxy.java +++ b/src/org/torproject/android/service/TorTransProxy.java @@ -112,6 +112,8 @@ public class TorTransProxy implements TorServiceConstants { public static int purgeIptables(Context context, TorifiedApp[] apps) throws Exception { + //restoreDNSResolvConf(); //not working yet + String baseDir = findBaseDir(); final StringBuilder script = new StringBuilder(); @@ -145,11 +147,52 @@ public class TorTransProxy implements TorServiceConstants { } + public static int redirectDNSResolvConf () throws Exception + { + StringBuilder script = new StringBuilder(); + StringBuilder res = new StringBuilder(); + int code = -1; + + //mv resolv.conf to resolve.conf.bak + String cmd = "mv /etc/resolv.conf /etc/resolv.conf.bak"; + script.append(cmd); + + //create new resolve.conf pointing to localhost/127.0.0.1 + cmd = "echo \"nameserver 127.0.0.1\" > /etc/resolv.conf"; + script.append(cmd); + + String[] cmdFlush = {script.toString()}; + code = TorServiceUtils.doShellCommand(cmdFlush, res, true, true); + //String msg = res.toString(); //get stdout from command + + + return code; + } + + public static int restoreDNSResolvConf () throws Exception + { + StringBuilder script = new StringBuilder(); + StringBuilder res = new StringBuilder(); + int code = -1; + + //mv resolv.conf to resolve.conf.bak + String cmd = "mv /etc/resolv.conf.bak /etc/resolv.conf"; + script.append(cmd); + script.append(" || exit\n"); + + String[] cmdFlush = {script.toString()}; + code = TorServiceUtils.doShellCommand(cmdFlush, res, true, true); + //String msg = res.toString(); //get stdout from command + + return code; + } public static int setTransparentProxyingByApp(Context context, TorifiedApp[] apps, boolean forceAll) throws Exception { - //android.os.Debug.waitForDebugger(); + android.os.Debug.waitForDebugger(); + + //redirectDNSResolvConf(); //not working yet String baseDir = findBaseDir(); @@ -210,9 +253,11 @@ public class TorTransProxy implements TorServiceConstants { script.append(" -m tcp --syn"); if (ipTablesOld) - script.append(" -j DNAT --to 127.0.0.1:9040"); + script.append(" -j DNAT --to 127.0.0.1:"); else - script.append(" -j REDIRECT --to-ports 9040"); + script.append(" -j REDIRECT --to-ports "); + + script.append(TOR_TRANSPROXY_PORT); script.append(" || exit\n"); @@ -221,12 +266,15 @@ 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 53"); //drop all UDP packets as Tor won't handle them + script.append(" --dport "); + script.append(STANDARD_DNS_PORT); if (ipTablesOld) - script.append(" -j DNAT --to 127.0.0.1:5400"); + script.append(" -j DNAT --to 127.0.0.1:"); else - script.append(" -j REDIRECT --to-ports 5400"); + script.append(" -j REDIRECT --to-ports "); + + script.append(TOR_DNS_PORT); script.append(" || exit\n"); @@ -249,7 +297,9 @@ public class TorTransProxy implements TorServiceConstants { script.append(" -A OUTPUT -p tcp"); script.append(" -m owner --uid-owner "); script.append(apps[i].getUid()); - script.append(" -m tcp --dport 9040 -j ACCEPT"); + script.append(" -m tcp --dport "); + script.append(TOR_TRANSPROXY_PORT); + script.append(" -j ACCEPT"); script.append(" || exit\n"); script.append(baseDir); @@ -257,7 +307,9 @@ public class TorTransProxy implements TorServiceConstants { script.append(" -A OUTPUT -p udp"); script.append(" -m owner --uid-owner "); script.append(apps[i].getUid()); - script.append(" -m udp --dport 5400 -j ACCEPT"); + script.append(" -m udp --dport "); + script.append(TOR_DNS_PORT); + script.append(" -j ACCEPT"); script.append(" || exit\n"); script.append(baseDir);