From c2be4ac15b4faeb65d00965ba2d5dc02b15a52cd Mon Sep 17 00:00:00 2001 From: Nathan Freitas Date: Wed, 11 Jun 2014 11:26:30 -0400 Subject: [PATCH] ensure polipo conf is updated; default to 9051 for ctrl port --- .../android/service/TorResourceInstaller.java | 16 ++++++++++++++++ .../torproject/android/service/TorService.java | 7 ++++++- .../android/service/TorServiceConstants.java | 2 ++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/org/torproject/android/service/TorResourceInstaller.java b/src/org/torproject/android/service/TorResourceInstaller.java index b8cdf262..414c33c5 100644 --- a/src/org/torproject/android/service/TorResourceInstaller.java +++ b/src/org/torproject/android/service/TorResourceInstaller.java @@ -138,6 +138,22 @@ public class TorResourceInstaller implements TorServiceConstants { return true; } + public boolean installPolipoConf () throws IOException, FileNotFoundException, TimeoutException + { + + InputStream is; + File outFile; + + Shell shell = Shell.startShell(new ArrayList(),installFolder.getAbsolutePath()); + + is = context.getResources().openRawResource(R.raw.torpolipo); + outFile = new File(installFolder, POLIPOCONFIG_ASSET_KEY); + shell.add(new SimpleCommand(COMMAND_RM_FORCE + outFile.getAbsolutePath())).waitForFinish(); + streamToFile(is,outFile, false, false); + + return true; + } + /* * Extract the Tor binary from the APK file using ZIP */ diff --git a/src/org/torproject/android/service/TorService.java b/src/org/torproject/android/service/TorService.java index 49bd6722..aac581b8 100644 --- a/src/org/torproject/android/service/TorService.java +++ b/src/org/torproject/android/service/TorService.java @@ -561,6 +561,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst String extraLines = prefs.getString("pref_custom_torrc", null); boolean success = installer.installTorrc(extraLines); + success = installer.installPolipoConf(); if (version == null || (!version.equals(BINARY_TOR_VERSION)) || (!fileTor.exists())) { @@ -881,10 +882,14 @@ public class TorService extends Service implements TorServiceConstants, TorConst { int controlPort = getControlPort(); - logNotice( "Connecting to control port: " + controlPort); + + if (controlPort == -1 && i == maxAttempts) + controlPort = DEFAULT_CONTROL_PORT; if (controlPort != -1) { + logNotice( "Connecting to control port: " + controlPort); + torConnSocket = new Socket(IP_LOCALHOST, controlPort); torConnSocket.setSoTimeout(CONTROL_SOCKET_TIMEOUT); diff --git a/src/org/torproject/android/service/TorServiceConstants.java b/src/org/torproject/android/service/TorServiceConstants.java index 449e5359..58f59ab8 100644 --- a/src/org/torproject/android/service/TorServiceConstants.java +++ b/src/org/torproject/android/service/TorServiceConstants.java @@ -88,5 +88,7 @@ public interface TorServiceConstants { //name of the iptables binary public final static String IPTABLES_ASSET_KEY = "xtables"; + public final static int DEFAULT_CONTROL_PORT = 9051; + }