[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [orbot/master] fixes #12411 and #12412 enables DNS and transport by default



commit b6715b4d3c3e84caab6108e3702010066f2b36db
Author: Nathan Freitas <nathan@xxxxxxxxxxx>
Date:   Tue Jun 17 15:42:54 2014 -0400

    fixes #12411 and #12412 enables DNS and transport by default
    with new Orbot settings to enable user to easily change/disable
---
 res/values/strings.xml                             |   14 ++++++-
 res/xml/preferences.xml                            |   14 +++++++
 src/org/torproject/android/service/TorService.java |   42 +++++++++++++++-----
 .../android/service/TorServiceConstants.java       |    4 +-
 .../torproject/android/service/TorTransProxy.java  |   32 ++++++++++-----
 5 files changed, 84 insertions(+), 22 deletions(-)

diff --git a/res/values/strings.xml b/res/values/strings.xml
index 4456aff..d380579 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -258,8 +258,18 @@
     <string name="updating_settings_in_tor_service">updating settings in Tor service</string>
   
     <string name="pref_socks_title">Tor SOCKS</string>
-    <string name="pref_socks_summary">IP and Port that Tor offers its SOCKS proxy on (default: 9050)</string>
-    <string name="pref_socks_dialog">SOCKS Config (ip:port)</string>
+    <string name="pref_socks_summary">Port that Tor offers its SOCKS proxy on (default: 9050 or 0 to disable)</string>
+    <string name="pref_socks_dialog">SOCKS Port Config</string>
+    
+    <string name="pref_transport_title">Tor TransProxy Port</string>
+    <string name="pref_transport_summary">Port that Tor offers its Transparent Proxy on (default: 9040 or 0 to disable)</string>
+    <string name="pref_transport_dialog">TransProxy Port Config</string>
+    
+    
+    <string name="pref_dnsport_title">Tor DNS Port</string>
+    <string name="pref_dnsport_summary">Port that Tor offers its DNS on (default: 5400 or 0 to disable)</string>
+    <string name="pref_dnsport_dialog">DNS Port Config</string>
+    
     
     <string name="pref_torrc_title">Torrc Custom Config</string>
     <string name="pref_torrc_summary">EXPERTS ONLY: enter direct torrc config lines</string>
diff --git a/res/xml/preferences.xml b/res/xml/preferences.xml
index 0277343..22502b6 100644
--- a/res/xml/preferences.xml
+++ b/res/xml/preferences.xml
@@ -204,6 +204,20 @@ android:dialogTitle="@string/pref_socks_dialog"
 android:defaultValue="9050"
 />
     
+      <EditTextPreference android:key="pref_transport"
+android:title="@string/pref_transport_title"
+android:summary="@string/pref_transport_summary"
+android:dialogTitle="@string/pref_transport_dialog"
+android:defaultValue="9040"
+/>
+      
+        <EditTextPreference android:key="pref_dnsport"
+android:title="@string/pref_dnsport_title"
+android:summary="@string/pref_dnsport_summary"
+android:dialogTitle="@string/pref_dnsport_dialog"
+android:defaultValue="5400"
+/>
+    
   <EditTextPreference android:key="pref_custom_torrc"
 android:title="@string/pref_torrc_title"
 android:summary="@string/pref_torrc_summary"
diff --git a/src/org/torproject/android/service/TorService.java b/src/org/torproject/android/service/TorService.java
index 5f9e178..5acb900 100644
--- a/src/org/torproject/android/service/TorService.java
+++ b/src/org/torproject/android/service/TorService.java
@@ -659,19 +659,24 @@ public class TorService extends Service implements TorServiceConstants, TorConst
  		{
  			mTransProxy = new TorTransProxy(this, fileXtables);
  			
- 			
  		}
  		
 
-     	logMessage ("Transparent Proxying: updating Tor settings...");
-     	
- 		mBinder.updateConfiguration("TransPort","9040",false);
- 		mBinder.updateConfiguration("DNSPort","5400",false);
- 		mBinder.updateConfiguration("VirtualAddrNetwork","10.192.0.0/10",false);
- 		mBinder.updateConfiguration("AutomapHostsOnResolve","1",false);
- 		mBinder.saveConfiguration();
-	 		
 
+		SharedPreferences prefs = TorServiceUtils.getSharedPrefs(getApplicationContext());
+		String transProxy = prefs.getString("pref_transport", TorServiceConstants.TOR_TRANSPROXY_PORT_DEFAULT+"");
+		String dnsPort = prefs.getString("pref_dnsport", TorServiceConstants.TOR_TRANSPROXY_PORT_DEFAULT+"");
+		
+		if (transProxy.indexOf(':')!=-1) //we just want the port for this
+			transProxy = transProxy.split(":")[1];
+		
+		if (dnsPort.indexOf(':')!=-1) //we just want the port for this
+			dnsPort = dnsPort.split(":")[1];
+		
+		mTransProxy.setTransProxyPort(Integer.parseInt(transProxy));
+		mTransProxy.setDNSPort(Integer.parseInt(dnsPort));
+
+     
 		//TODO: Find a nice place for the next (commented) line
 		//TorTransProxy.setDNSProxying(); 
 		
@@ -1781,6 +1786,12 @@ public class TorService extends Service implements TorServiceConstants, TorConst
 
 		enableSocks (socksConfig,false);
 		
+		String transPort = prefs.getString("pref_transport", TorServiceConstants.TOR_TRANSPROXY_PORT_DEFAULT+"");
+		String dnsPort = prefs.getString("pref_dnsport", TorServiceConstants.TOR_DNS_PORT_DEFAULT+"");
+		
+		enableTransProxyAndDNSPorts(transPort, dnsPort);
+		
+		
 		boolean useBridges = prefs.getBoolean(TorConstants.PREF_BRIDGES_ENABLED, false);
 		
 		//boolean autoUpdateBridges = prefs.getBoolean(TorConstants.PREF_BRIDGES_UPDATED, false);
@@ -2041,6 +2052,19 @@ public class TorService extends Service implements TorServiceConstants, TorConst
         
     }
     
+    private void enableTransProxyAndDNSPorts (String transPort, String dnsPort) throws RemoteException
+    {
+    	logMessage ("Transparent Proxying: enabling port...");
+     	
+ 		mBinder.updateConfiguration("TransPort",transPort,false);
+ 		mBinder.updateConfiguration("DNSPort",dnsPort,false);
+ 		mBinder.updateConfiguration("VirtualAddrNetwork","10.192.0.0/10",false);
+ 		mBinder.updateConfiguration("AutomapHostsOnResolve","1",false);
+ 		mBinder.saveConfiguration();
+	 		
+
+    }
+    
     private void blockPlaintextPorts (String portList) throws RemoteException
     {
     	
diff --git a/src/org/torproject/android/service/TorServiceConstants.java b/src/org/torproject/android/service/TorServiceConstants.java
index 0890f9e..8c53779 100644
--- a/src/org/torproject/android/service/TorServiceConstants.java
+++ b/src/org/torproject/android/service/TorServiceConstants.java
@@ -54,9 +54,9 @@ public interface TorServiceConstants {
 	//what is says!
 	public final static String IP_LOCALHOST = "127.0.0.1";
 	public final static int UPDATE_TIMEOUT = 1000;
-	public final static int TOR_TRANSPROXY_PORT = 9040;
+	public final static int TOR_TRANSPROXY_PORT_DEFAULT = 9040;
 	public final static int STANDARD_DNS_PORT = 53;
-	public final static int TOR_DNS_PORT = 5400;
+	public final static int TOR_DNS_PORT_DEFAULT = 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 4999777..400b1db 100644
--- a/src/org/torproject/android/service/TorTransProxy.java
+++ b/src/org/torproject/android/service/TorTransProxy.java
@@ -23,10 +23,24 @@ public class TorTransProxy implements TorServiceConstants {
 	
 	private final static String ALLOW_LOCAL = " ! -o lo ! -d 127.0.0.1 ! -s 127.0.0.1 ";
 
+	private int mTransProxyPort = TorServiceConstants.TOR_TRANSPROXY_PORT_DEFAULT;
+	private int mDNSPort = TorServiceConstants.TOR_DNS_PORT_DEFAULT;
+	
 	public TorTransProxy (TorService torService, File fileXTables)
 	{
 		mTorService = torService;
 		mFileXtables = fileXTables;
+		
+	}
+	
+	public void setTransProxyPort (int transProxyPort)
+	{
+		mTransProxyPort = transProxyPort;
+	}
+	
+	public void setDNSPort (int dnsPort)
+	{
+		mDNSPort = dnsPort;
 	}
 	
 	public String getIpTablesPath (Context context)
@@ -383,7 +397,7 @@ public class TorTransProxy implements TorServiceConstants {
 				script.append(tApp.getUid());
 				script.append(" -m tcp --syn");
 				script.append(" -j REDIRECT --to-ports ");
-				script.append(TOR_TRANSPROXY_PORT);
+				script.append(mTransProxyPort);
 				
 				executeCommand (shell, script.toString());
 				script = new StringBuilder();
@@ -398,7 +412,7 @@ public class TorTransProxy implements TorServiceConstants {
 				script.append(" -m udp --dport "); 
 				script.append(STANDARD_DNS_PORT);
 				script.append(" -j REDIRECT --to-ports ");
-				script.append(TOR_DNS_PORT);
+				script.append(mDNSPort);
 
 				executeCommand (shell, script.toString());
 				script = new StringBuilder();
@@ -454,7 +468,7 @@ public class TorTransProxy implements TorServiceConstants {
 			script.append(" -t nat -A PREROUTING -i ");
 			script.append(hwinterfaces[i]);
 			script.append(" -p udp --dport 53 -j REDIRECT --to-ports ");
-			script.append(TOR_DNS_PORT);
+			script.append(mDNSPort);
 			
 			executeCommand (shell, script.toString());
 			script = new StringBuilder();
@@ -465,7 +479,7 @@ public class TorTransProxy implements TorServiceConstants {
 			script.append(" -t nat -A PREROUTING -i ");
 			script.append(hwinterfaces[i]);
 			script.append(" -p tcp -j REDIRECT --to-ports ");
-			script.append(TOR_TRANSPROXY_PORT);
+			script.append(mTransProxyPort);
 			
 			lastExit = executeCommand (shell, script.toString());
 			script = new StringBuilder();
@@ -642,7 +656,7 @@ public class TorTransProxy implements TorServiceConstants {
 		script.append(torUid);
 		script.append(" -m tcp --syn");
 		script.append(" -j REDIRECT --to-ports ");
-		script.append(TOR_TRANSPROXY_PORT);
+		script.append(mTransProxyPort);
 
 		executeCommand (shell, script.toString());
 		script = new StringBuilder();
@@ -658,7 +672,7 @@ public class TorTransProxy implements TorServiceConstants {
 		script.append(" -m udp --dport "); 
 		script.append(STANDARD_DNS_PORT);
 		script.append(" -j REDIRECT --to-ports ");
-		script.append(TOR_DNS_PORT);
+		script.append(mDNSPort);
 
 		executeCommand (shell, script.toString());
 		script = new StringBuilder();
@@ -699,7 +713,7 @@ public class TorTransProxy implements TorServiceConstants {
 		script.append(" -A ").append(srcChainName);
 		script.append(" -p tcp");
 		script.append(" -m tcp");
-		script.append(" --dport ").append(TOR_TRANSPROXY_PORT);
+		script.append(" --dport ").append(mTransProxyPort);
 		script.append(" -j ACCEPT");
 
 		executeCommand (shell, script.toString());
@@ -735,7 +749,7 @@ public class TorTransProxy implements TorServiceConstants {
 		script.append(" -A ").append(srcChainName);
 		script.append(" -p udp");
 		script.append(" -m udp");
-		script.append(" --dport ").append(TOR_DNS_PORT);
+		script.append(" --dport ").append(mDNSPort);
 		script.append(" -j ACCEPT");
 
 		executeCommand (shell, script.toString());
@@ -747,7 +761,7 @@ public class TorTransProxy implements TorServiceConstants {
 		script.append(" -A ").append(srcChainName);
 		script.append(" -p udp");
 		script.append(" -m udp");
-		script.append(" --dport ").append(TOR_DNS_PORT);
+		script.append(" --dport ").append(mDNSPort);
 		script.append(" -j ACCEPT");
 
 		executeCommand (shell, script.toString());



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits