From 32c6e62c45a196a96dc88c22b90c5ce31c5dd312 Mon Sep 17 00:00:00 2001 From: Nathan Freitas Date: Sat, 6 Mar 2010 14:56:39 +0000 Subject: [PATCH] many fixes include landscape view, invalid settings handling and cleanup of shell cmd code svn:r21829 --- Orbot/res/values/strings.xml | 7 +- Orbot/res/xml/preferences.xml | 29 ++-- Orbot/src/org/torproject/android/Orbot.java | 62 ++++++-- .../org/torproject/android/TorConstants.java | 2 +- .../android/service/TorService.java | 138 +++++++++++++----- .../android/service/TorServiceConstants.java | 4 +- .../android/service/TorServiceUtils.java | 97 ++++-------- .../android/service/TorTransProxy.java | 8 +- 8 files changed, 214 insertions(+), 133 deletions(-) diff --git a/Orbot/res/values/strings.xml b/Orbot/res/values/strings.xml index 9675a10d..95b55394 100644 --- a/Orbot/res/values/strings.xml +++ b/Orbot/res/values/strings.xml @@ -16,10 +16,11 @@ Orbot is shutting down Starting Tor... -authenticating... +authenticating control connection... complete. waiting. +WARNING: Your traffic is not anonymous yet! Please configure your applications to use HTTP proxy 127.0.0.1:8118 or SOCKS5 proxy 127.0.0.1:9050 Home Browse Settings @@ -36,9 +37,9 @@ Please visit https://www.torproject.org/docs/android.html for the latest information. \n\n For non-rooted Android 1.x devices (G1, MyTouch3G, Hero): Please use the "ProxySurf" browser available in the Android Market, and set -the HTTP Proxy to 127.0.0.1 and port 8118. For Instant Messsaging, try "Beem" in the market, and set the SOCKS5 proxy to 127.0.0.1 / port 9050. +the HTTP Proxy to 127.0.0.1 and port 8118, for HTTP traffic only (HTTP/S will not work). For Instant Messsaging, try "Beem" in the market, and set the SOCKS5 proxy to 127.0.0.1 / port 9050. \n\n -For Android 2.x devices, you MUST ROOT your device in order for Orbot to work transparently for all web and DNS traffic. Otherwise, the "Beem" app will allow +For Android 2.x devices, you MUST ROOT your device in order for Orbot to work transparently, as there is no browser that will work for non-root devices. Otherwise, the "Beem" app will allow you to set the SOCKS5 proxy to 127.0.0.1 and port 9050. You should also enable SSL to protect your username and password. \n\n If you root your device, whether it is 1.x or 2.x based, Orbot will automatically, transparently proxy all web traffic (http and https) diff --git a/Orbot/res/xml/preferences.xml b/Orbot/res/xml/preferences.xml index 6ba32ee9..0aba469e 100644 --- a/Orbot/res/xml/preferences.xml +++ b/Orbot/res/xml/preferences.xml @@ -1,13 +1,24 @@ - + + + + + + + - + - - + - + +android:enabled="true"> 0) - Toast.makeText(this, torServiceMsg, Toast.LENGTH_LONG).show(); + // if (torServiceMsg != null && torServiceMsg.length()>0) + // Toast.makeText(this, torServiceMsg, Toast.LENGTH_LONG).show(); } @@ -623,6 +660,7 @@ public class Orbot extends Activity implements OnClickListener, TorConstants, On String pComp = torServiceMsg.substring(idx-2,idx).trim(); int ipComp = Integer.parseInt(pComp); progressDialog.setProgress(ipComp); + } } @@ -631,8 +669,8 @@ public class Orbot extends Activity implements OnClickListener, TorConstants, On imgStatus.setImageResource(R.drawable.torstopping); lblStatus.setText(getString(R.string.status_shutting_down)); - if (torServiceMsg != null && torServiceMsg.length()>0) - Toast.makeText(this, torServiceMsg, Toast.LENGTH_LONG).show(); + //if (torServiceMsg != null && torServiceMsg.length()>0) + //Toast.makeText(this, torServiceMsg, Toast.LENGTH_LONG).show(); @@ -640,8 +678,8 @@ public class Orbot extends Activity implements OnClickListener, TorConstants, On else { - if (torServiceMsg != null && torServiceMsg.length()>0) - Toast.makeText(this, torServiceMsg, Toast.LENGTH_LONG).show(); + //if (torServiceMsg != null && torServiceMsg.length()>0) + //Toast.makeText(this, torServiceMsg, Toast.LENGTH_LONG).show(); if (progressDialog != null) diff --git a/Orbot/src/org/torproject/android/TorConstants.java b/Orbot/src/org/torproject/android/TorConstants.java index 48b16d52..73d9622b 100644 --- a/Orbot/src/org/torproject/android/TorConstants.java +++ b/Orbot/src/org/torproject/android/TorConstants.java @@ -24,7 +24,7 @@ public interface TorConstants { public final static String NEWLINE = "\n"; public final static String TORRC_DEFAULT = - "SocksPort 9050\nSocksListenAddress 127.0.0.1\nSafeSocks 1\nDNSPort 5400\nLog notice stdout\nLog debug syslog\nDataDirectory /data/data/org.torproject.android/data\n" + "SocksPort 9050\nSocksListenAddress 127.0.0.1\nSafeSocks 1\nDNSPort 5400\nLog debug syslog\nDataDirectory /data/data/org.torproject.android/data\n" + "ControlPort 9051\nCookieAuthentication 1\nRelayBandwidthRate 20 KBytes\nRelayBandwidthBurst 20 KBytes\nAutomapHostsOnResolve 1\nTransPort 9040\n"; public final static String INTENT_TOR_SERVICE = "org.torproject.android.service.TOR_SERVICE"; diff --git a/Orbot/src/org/torproject/android/service/TorService.java b/Orbot/src/org/torproject/android/service/TorService.java index cab21339..ecb0a652 100644 --- a/Orbot/src/org/torproject/android/service/TorService.java +++ b/Orbot/src/org/torproject/android/service/TorService.java @@ -6,7 +6,9 @@ import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.net.Socket; +import java.util.ArrayList; import java.util.Arrays; +import java.util.Iterator; import java.util.List; import net.freehaven.tor.control.ConfigEntry; @@ -277,6 +279,7 @@ public class TorService extends Service implements TorServiceConstants, Runnable conn = null; } + StringBuilder log = new StringBuilder(); int procId = TorServiceUtils.findProcessId(TorServiceConstants.TOR_BINARY_INSTALL_PATH); @@ -285,7 +288,8 @@ public class TorService extends Service implements TorServiceConstants, Runnable Log.i(TAG,"Found Tor PID=" + procId + " - killing now..."); - TorServiceUtils.doCommand(SHELL_CMD_KILL, procId + ""); + String[] cmd = { SHELL_CMD_KILL + ' ' + procId + "" }; + TorServiceUtils.doShellCommand(cmd,log, false, false); procId = TorServiceUtils.findProcessId(TorServiceConstants.TOR_BINARY_INSTALL_PATH); } @@ -296,8 +300,9 @@ public class TorService extends Service implements TorServiceConstants, Runnable { Log.i(TAG,"Found Privoxy PID=" + procId + " - killing now..."); - - TorServiceUtils.doCommand(SHELL_CMD_KILL, procId + ""); + String[] cmd = { SHELL_CMD_KILL + ' ' + procId + "" }; + + TorServiceUtils.doShellCommand(cmd,log, false, false); procId = TorServiceUtils.findProcessId(TorServiceConstants.PRIVOXY_INSTALL_PATH); } @@ -346,12 +351,15 @@ public class TorService extends Service implements TorServiceConstants, Runnable } - + StringBuilder log = new StringBuilder (); + Log.i(TAG,"Setting permission on Tor binary"); - TorServiceUtils.doCommand(SHELL_CMD_CHMOD, CHMOD_EXE_VALUE + ' ' + TOR_BINARY_INSTALL_PATH); + String[] cmd1 = {SHELL_CMD_CHMOD + ' ' + CHMOD_EXE_VALUE + ' ' + TOR_BINARY_INSTALL_PATH}; + TorServiceUtils.doShellCommand(cmd1, log, false, true); Log.i(TAG,"Setting permission on Privoxy binary"); - TorServiceUtils.doCommand(SHELL_CMD_CHMOD, CHMOD_EXE_VALUE + ' ' + PRIVOXY_INSTALL_PATH); + String[] cmd2 = {SHELL_CMD_CHMOD + ' ' + CHMOD_EXE_VALUE + ' ' + PRIVOXY_INSTALL_PATH}; + TorServiceUtils.doShellCommand(cmd2, log, false, true); return true; } @@ -368,41 +376,82 @@ public class TorService extends Service implements TorServiceConstants, Runnable checkTorBinaries (); - - Log.i(TAG,"Starting tor process"); - - TorServiceUtils.doCommand(TOR_BINARY_INSTALL_PATH, TOR_COMMAND_LINE_ARGS); - - int procId = TorServiceUtils.findProcessId(TorServiceConstants.TOR_BINARY_INSTALL_PATH); - - while (procId == -1) + new Thread() { - TorServiceUtils.doCommand(TOR_BINARY_INSTALL_PATH, TOR_COMMAND_LINE_ARGS); - procId = TorServiceUtils.findProcessId(TorServiceConstants.TOR_BINARY_INSTALL_PATH); - - if (procId == -1) + public void run () { - this.sendCallbackMessage("Couldn't start Tor process... retrying..."); - Thread.sleep(3000); + try { + runPrivoxyShellCmd(); + } catch (Exception e) { + Log.w(TAG,"Error starting Privoxy",e); + } } - } + }.start(); - Log.i(TAG,"Tor process id=" + procId); + new Thread() + { + public void run () + { + try { + runTorShellCmd(); + } catch (Exception e) { + Log.w(TAG,"Error starting Tor",e); + } + } + }.start(); - showToolbarNotification("Orbot starting...", "Orbot is starting up", R.drawable.tornotification); - initControlConnection (); + } + + private void runTorShellCmd() throws Exception + { + StringBuilder log = new StringBuilder(); + + Log.i(TAG,"Starting tor process"); + + String[] torCmd = {TOR_BINARY_INSTALL_PATH + ' ' + TOR_COMMAND_LINE_ARGS}; + TorServiceUtils.doShellCommand(torCmd, log, false, false); + + Thread.sleep(1000); + int procId = TorServiceUtils.findProcessId(TorServiceConstants.TOR_BINARY_INSTALL_PATH); + + while (procId == -1) + { + log = new StringBuilder(); + + TorServiceUtils.doShellCommand(torCmd, log, false, false); + procId = TorServiceUtils.findProcessId(TorServiceConstants.TOR_BINARY_INSTALL_PATH); + if (procId == -1) + { + this.sendCallbackMessage("Couldn't start Tor process...\n" + log.toString()); + Thread.sleep(5000); + } + } + + Log.i(TAG,"Tor process id=" + procId); + + showToolbarNotification("Orbot starting...", "Orbot is starting up", R.drawable.tornotification); + + initControlConnection (); + } + + private void runPrivoxyShellCmd () throws Exception + { int privoxyProcId = TorServiceUtils.findProcessId(TorServiceConstants.PRIVOXY_INSTALL_PATH); + StringBuilder log = new StringBuilder(); + while (privoxyProcId == -1) { - TorServiceUtils.doCommand(PRIVOXY_INSTALL_PATH, PRIVOXY_COMMAND_LINE_ARGS); + String[] cmds = + { PRIVOXY_INSTALL_PATH + " " + PRIVOXY_COMMAND_LINE_ARGS }; + TorServiceUtils.doShellCommand(cmds, log, false, true); privoxyProcId = TorServiceUtils.findProcessId(TorServiceConstants.PRIVOXY_INSTALL_PATH); if (privoxyProcId == -1) { - this.sendCallbackMessage("Couldn't start Privoxy process... retrying..."); + this.sendCallbackMessage("Couldn't start Privoxy process... retrying...\n" + log); Thread.sleep(3000); } } @@ -705,19 +754,40 @@ public class TorService extends Service implements TorServiceConstants, Runnable }; - private void sendCallbackMessage (String status) + private ArrayList callbackBuffer = new ArrayList(); + + private void sendCallbackMessage (String newStatus) { // Broadcast to all clients the new value. final int N = mCallbacks.beginBroadcast(); - for (int i=0; i 0) + { + + Iterator it = callbackBuffer.iterator(); + String status = null; + + while (it.hasNext()) + { + status = it.next(); + + for (int i=0; i