[tor-commits] [orbot/master] fixes for settings processing and QRCode scanning of bridges

n8fr8 at torproject.org n8fr8 at torproject.org
Wed Jan 13 14:47:35 UTC 2016


commit 8f7165ce5764fe873efaa35c27a2b1f3c41f33b4
Author: Nathan Freitas <nathan at freitas.net>
Date:   Tue Jan 12 23:57:37 2016 -0500

    fixes for settings processing and QRCode scanning of bridges
    - support new JSON array form bridges.torproject.org
    - only enable TransProxy and DNSPort settings if the user enables transproxy
---
 src/org/torproject/android/OrbotMainActivity.java  |   27 ++++--
 .../android/service/TorResourceInstaller.java      |    6 +-
 src/org/torproject/android/service/TorService.java |   94 ++++++--------------
 .../android/service/TorServiceConstants.java       |    2 +-
 4 files changed, 55 insertions(+), 74 deletions(-)

diff --git a/src/org/torproject/android/OrbotMainActivity.java b/src/org/torproject/android/OrbotMainActivity.java
index 0b292d2..3e64e5f 100644
--- a/src/org/torproject/android/OrbotMainActivity.java
+++ b/src/org/torproject/android/OrbotMainActivity.java
@@ -56,6 +56,8 @@ import android.widget.ToggleButton;
 import com.google.zxing.integration.android.IntentIntegrator;
 import com.google.zxing.integration.android.IntentResult;
 
+import org.json.JSONArray;
+import org.json.JSONObject;
 import org.torproject.android.service.TorService;
 import org.torproject.android.service.TorServiceConstants;
 import org.torproject.android.service.TorServiceUtils;
@@ -263,11 +265,11 @@ public class OrbotMainActivity extends Activity
 		boolean useVPN = Prefs.useVpn();
 		mBtnVPN.setChecked(useVPN);
 		
-		/**
+		//auto start VPN if VPN is enabled
 		if (useVPN)
 		{
 			startActivity(new Intent(OrbotMainActivity.this,VPNEnableActivity.class));
-		}*/
+		}
 		
 		mBtnVPN.setOnClickListener(new View.OnClickListener ()
 		{
@@ -827,16 +829,31 @@ public class OrbotMainActivity extends Activity
         	if (results != null && results.length() > 0)
         	{
 	        	try {
-					results = URLDecoder.decode(results, "UTF-8");
 					
 					int urlIdx = results.indexOf("://");
 					
 					if (urlIdx!=-1)
+					{
+						results = URLDecoder.decode(results, "UTF-8");
 						results = results.substring(urlIdx+3);
+						setNewBridges(results);
+					}
+					else
+					{
+						JSONArray bridgeJson = new JSONArray(results);
+						StringBuffer bridgeLines = new StringBuffer();
+						
+						for (int i = 0; i < bridgeJson.length(); i++)
+						{
+							String bridgeLine = bridgeJson.getString(i);
+							bridgeLines.append(bridgeLine).append("\n");
+						}
+						
+						setNewBridges(bridgeLines.toString());
+					}
 					
-					setNewBridges(results);
 					
-				} catch (UnsupportedEncodingException e) {
+				} catch (Exception e) {
 					Log.e(TAG,"unsupported",e);
 				}
         	}
diff --git a/src/org/torproject/android/service/TorResourceInstaller.java b/src/org/torproject/android/service/TorResourceInstaller.java
index 97e691c..1fad991 100644
--- a/src/org/torproject/android/service/TorResourceInstaller.java
+++ b/src/org/torproject/android/service/TorResourceInstaller.java
@@ -132,6 +132,8 @@ public class TorResourceInstaller implements TorServiceConstants {
         shell.add(new SimpleCommand(COMMAND_RM_FORCE + outFile.getAbsolutePath())).waitForFinish();
         streamToFile(is,outFile, false, true);
         setExecutable(outFile);
+        
+        installGeoIP();
     
         return true;
     }
@@ -196,14 +198,14 @@ public class TorResourceInstaller implements TorServiceConstants {
      * Extract the Tor binary from the APK file using ZIP
      */
     
-    public boolean installGeoIP () throws IOException, FileNotFoundException
+    private boolean installGeoIP () throws IOException, FileNotFoundException
     {
         
         InputStream is;
         File outFile;
         
-        is = context.getResources().openRawResource(R.raw.geoip);
         outFile = new File(installFolder, GEOIP_ASSET_KEY);
+        is = context.getResources().openRawResource(R.raw.geoip);
         streamToFile(is, outFile, false, true);
         
         is = context.getResources().openRawResource(R.raw.geoip6);
diff --git a/src/org/torproject/android/service/TorService.java b/src/org/torproject/android/service/TorService.java
index a1c0bfe..ca92dbb 100644
--- a/src/org/torproject/android/service/TorService.java
+++ b/src/org/torproject/android/service/TorService.java
@@ -621,8 +621,8 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
         fileControlPort = new File(OrbotApp.appBinHome, "control.txt");
         extraLines.append(TORRC_CONTROLPORT_FILE_KEY).append(' ').append(fileControlPort.getCanonicalPath()).append('\n');
 
-         extraLines.append("RunAsDaemon 1").append('\n');
-         extraLines.append("AvoidDiskWrites 1").append('\n');
+//         extraLines.append("RunAsDaemon 1").append('\n');
+ //        extraLines.append("AvoidDiskWrites 1").append('\n');
         
          String socksPortPref = prefs.getString(OrbotConstants.PREF_SOCKS,
                  String.valueOf(TorServiceConstants.SOCKS_PROXY_PORT_DEFAULT));
@@ -634,18 +634,26 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
         extraLines.append("TestSocks 0").append('\n');
         extraLines.append("WarnUnsafeSocks 1").append('\n');
     
-        extraLines.append("TransPort ").append("auto").append('\n');
-    	extraLines.append("DNSPort ").append(TorServiceConstants.TOR_DNS_PORT_DEFAULT).append("\n");
-        
-        if (Prefs.transparentTethering())
+        if (Prefs.useTransparentProxying())
         {
-            extraLines.append("TransListenAddress 0.0.0.0").append('\n');
-            extraLines.append("DNSListenAddress 0.0.0.0").append('\n');            
-        }
 
-        extraLines.append("VirtualAddrNetwork 10.192.0.0/10").append('\n');
-        extraLines.append("AutomapHostsOnResolve 1").append('\n');
+            String transPort = prefs.getString("pref_transport", TorServiceConstants.TOR_TRANSPROXY_PORT_DEFAULT+"");
+            String dnsPort = prefs.getString("pref_dnsport", TorServiceConstants.TOR_DNS_PORT_DEFAULT+"");
+            
+	        extraLines.append("TransPort ").append(transPort).append('\n');
+	    	extraLines.append("DNSPort ").append(dnsPort).append("\n");
+	        
+	        if (Prefs.transparentTethering())
+	        {
+	            extraLines.append("TransListenAddress 0.0.0.0").append('\n');
+	            extraLines.append("DNSListenAddress 0.0.0.0").append('\n');            
+	        }
        
+	        extraLines.append("VirtualAddrNetwork 10.192.0.0/10").append('\n');
+	        extraLines.append("AutomapHostsOnResolve 1").append('\n');
+	       
+        }
+
         extraLines.append("DisableNetwork 0").append('\n');
                 
         if (Prefs.useDebugLogging())
@@ -654,7 +662,6 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
         	extraLines.append("Log info syslog").append('\n');
         	extraLines.append("SafeLogging 0").append('\n');   
 
-        	//extraLines.append("Log debug stdout").append('\n');
         }
         
         processSettingsImpl(extraLines);
@@ -1936,17 +1943,6 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
         logNotice(getString(R.string.updating_settings_in_tor_service));
         
         SharedPreferences prefs = TorServiceUtils.getSharedPrefs(getApplicationContext());
-
-        /*
-        String socksConfig = prefs.getString(TorConstants.PREF_SOCKS, TorServiceConstants.PORT_SOCKS_DEFAULT);
-
-        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.bridgesEnabled();
 
@@ -2034,11 +2030,11 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
 
 	            for (String bridgeConfigLine : bridgeListLines)
 	            {
-	                if (bridgeConfigLine != null && bridgeConfigLine.length() > 0)
+	                if (!TextUtils.isEmpty(bridgeConfigLine))
 	                {
 	                	extraLines.append("Bridge ");
 	                	
-	                	bridgeConfigLine = bridgeConfigLine.replace('�', ' ');
+	                	//bridgeConfigLine = bridgeConfigLine.replace('�', ' ');
 	                	
 	                	StringTokenizer st = new StringTokenizer (bridgeConfigLine," ");
 	                	while (st.hasMoreTokens())
@@ -2093,15 +2089,13 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
         if (entranceNodes.length() > 0 || exitNodes.length() > 0 || excludeNodes.length() > 0)
         {
            
-            if (enableGeoIP ())
-            { //only apply GeoIP if you need it
-                File fileGeoIP = new File(OrbotApp.appBinHome, GEOIP_ASSET_KEY);
-                File fileGeoIP6 = new File(OrbotApp.appBinHome, GEOIP6_ASSET_KEY);
-                    
-                extraLines.append("GeoIPFile" + ' ' + fileGeoIP.getCanonicalPath()).append('\n');
-                extraLines.append("GeoIPv6File" + ' ' + fileGeoIP6.getCanonicalPath()).append('\n');
-            }
-            
+            //only apply GeoIP if you need it
+            File fileGeoIP = new File(OrbotApp.appBinHome, GEOIP_ASSET_KEY);
+            File fileGeoIP6 = new File(OrbotApp.appBinHome, GEOIP6_ASSET_KEY);
+                
+            extraLines.append("GeoIPFile" + ' ' + fileGeoIP.getCanonicalPath()).append('\n');
+            extraLines.append("GeoIPv6File" + ' ' + fileGeoIP6.getCanonicalPath()).append('\n');
+        
         }
 
         if (!TextUtils.isEmpty(entranceNodes))
@@ -2354,9 +2348,6 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
         	{
     	    	try
     	    	{
-    	    		
-    	    		enableGeoIP ();
-    	    			
                     File fileGeoIP = new File(OrbotApp.appBinHome, GEOIP_ASSET_KEY);
                     File fileGeoIP6 = new File(OrbotApp.appBinHome, GEOIP6_ASSET_KEY);
                         
@@ -2369,8 +2360,6 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
     	    		conn.setConf("DisableNetwork","1");
     	    		conn.setConf("DisableNetwork","0");
     	    		
-    	    		
-    	    		
 
     	    	}
     	    	catch (IOException ioe)
@@ -2379,34 +2368,7 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
     	    	}
         	}
     	}
-    	
-    	
-
-    }
-    
-    private boolean enableGeoIP ()
-    {
-    	 File fileGeoIP = new File(OrbotApp.appBinHome, GEOIP_ASSET_KEY);
-         File fileGeoIP6 = new File(OrbotApp.appBinHome, GEOIP6_ASSET_KEY);
-        
-    	 try
-         {
-             if ((!fileGeoIP.exists()))
-             {
-                 TorResourceInstaller installer = new TorResourceInstaller(this, OrbotApp.appBinHome);
-                 boolean success = installer.installGeoIP();
-                 
-             }
-             
-             return true;
-             
-         }
-         catch (Exception e)
-         {
-              showToolbarNotification (getString(R.string.error_installing_binares),ERROR_NOTIFY_ID,R.drawable.ic_stat_notifyerr);
 
-             return false;
-         }
     }
 
 }
diff --git a/src/org/torproject/android/service/TorServiceConstants.java b/src/org/torproject/android/service/TorServiceConstants.java
index 2e2002d..c21b227 100644
--- a/src/org/torproject/android/service/TorServiceConstants.java
+++ b/src/org/torproject/android/service/TorServiceConstants.java
@@ -150,7 +150,7 @@ public interface TorServiceConstants {
 	public final static String PDNSD_ASSET_KEY = "pdnsd";
 
 	//EXIT COUNTRY CODES
-	public final static String[] COUNTRY_CODES = {"DE","AT","SE","CH","IS","CA","US","FR","BG","AU","BR","CZ","DK","FI","GB","HU","NL","JP","HK","RO","RU","SG","SK","CN"};
+	public final static String[] COUNTRY_CODES = {"DE","AT","SE","CH","IS","CA","US","ES","FR","BG","PL","AU","BR","CZ","DK","FI","GB","HU","NL","JP","RO","RU","SG","SK"};
 	
 	
 }





More information about the tor-commits mailing list