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

[tor-commits] [orbot/master] update service for VPN mode and startup fixes



commit bbf5fcb3fb346e9bba712d12bf4934cf925cb2bd
Author: n8fr8 <nathan@xxxxxxxxxxxxxxxxxxxx>
Date:   Wed Aug 7 13:33:30 2019 -0400

    update service for VPN mode and startup fixes
---
 orbotservice/build.gradle                          |   4 +-
 .../java/org/torproject/android/control/.cvsignore |   1 -
 .../java/org/torproject/android/control/README     |   4 -
 .../android/control/TorControlConnection.java      |  12 +-
 .../torproject/android/control/examples/.cvsignore |   1 -
 .../control/examples/DebuggingEventHandler.java    |  44 -------
 .../torproject/android/control/examples/Main.java  | 146 ---------------------
 .../org/torproject/android/service/TorService.java |  16 ++-
 .../service/util/CustomTorResourceInstaller.java   |   4 +-
 .../android/service/vpn/OrbotVpnManager.java       |  28 ++--
 .../android/service/vpn/TorVpnService.java         |  19 ++-
 11 files changed, 50 insertions(+), 229 deletions(-)

diff --git a/orbotservice/build.gradle b/orbotservice/build.gradle
index 7e933c7f..f8e96bf5 100644
--- a/orbotservice/build.gradle
+++ b/orbotservice/build.gradle
@@ -13,8 +13,8 @@ android {
     defaultConfig {
         minSdkVersion 16
         targetSdkVersion 28
-        versionCode 16060001
-        versionName '16.0.6-BETA-1-tor-0.3.5.8-orbotservice'
+        versionCode 16111000
+        versionName '16.1.1-BETA-2-tor-0.4.0.4-rc-orbotservice'
         archivesBaseName = "OrbotService-$versionName"
 
     }
diff --git a/orbotservice/src/main/java/org/torproject/android/control/.cvsignore b/orbotservice/src/main/java/org/torproject/android/control/.cvsignore
deleted file mode 100644
index 6b468b62..00000000
--- a/orbotservice/src/main/java/org/torproject/android/control/.cvsignore
+++ /dev/null
@@ -1 +0,0 @@
-*.class
diff --git a/orbotservice/src/main/java/org/torproject/android/control/README b/orbotservice/src/main/java/org/torproject/android/control/README
deleted file mode 100644
index b310c7d5..00000000
--- a/orbotservice/src/main/java/org/torproject/android/control/README
+++ /dev/null
@@ -1,4 +0,0 @@
-We broke the version detection stuff in Tor 0.1.2.16 / 0.2.0.4-alpha.
-Somebody should rip out the v0 control protocol stuff from here, and
-it should start working again. -RD
-
diff --git a/orbotservice/src/main/java/org/torproject/android/control/TorControlConnection.java b/orbotservice/src/main/java/org/torproject/android/control/TorControlConnection.java
index 05ed8c3c..4f1fe95b 100644
--- a/orbotservice/src/main/java/org/torproject/android/control/TorControlConnection.java
+++ b/orbotservice/src/main/java/org/torproject/android/control/TorControlConnection.java
@@ -312,12 +312,12 @@ public class TorControlConnection implements TorControlCommands {
                 handleEvent(lst);
             else {
                 synchronized (waiters) {
- 		if (!waiters.isEmpty())
-		{
-                    Waiter w;
-                    w = waiters.removeFirst();
-                    w.setResponse(lst);
-		}
+                    if (!waiters.isEmpty())
+                    {
+                                Waiter w;
+                                w = waiters.removeFirst();
+                                w.setResponse(lst);
+                    }
                 }		
 
             }
diff --git a/orbotservice/src/main/java/org/torproject/android/control/examples/.cvsignore b/orbotservice/src/main/java/org/torproject/android/control/examples/.cvsignore
deleted file mode 100644
index 6b468b62..00000000
--- a/orbotservice/src/main/java/org/torproject/android/control/examples/.cvsignore
+++ /dev/null
@@ -1 +0,0 @@
-*.class
diff --git a/orbotservice/src/main/java/org/torproject/android/control/examples/DebuggingEventHandler.java b/orbotservice/src/main/java/org/torproject/android/control/examples/DebuggingEventHandler.java
deleted file mode 100644
index 48c49a28..00000000
--- a/orbotservice/src/main/java/org/torproject/android/control/examples/DebuggingEventHandler.java
+++ /dev/null
@@ -1,44 +0,0 @@
-// Copyright 2005 Nick Mathewson, Roger Dingledine
-// See LICENSE file for copying information
-package org.torproject.android.control.examples;
-
-import java.io.PrintWriter;
-import java.util.Iterator;
-import org.torproject.android.control.EventHandler;
-
-public class DebuggingEventHandler implements EventHandler {
-
-    private final PrintWriter out;
-
-    public DebuggingEventHandler(PrintWriter p) {
-        out = p;
-    }
-
-    public void circuitStatus(String status, String circID, String path) {
-        out.println("Circuit "+circID+" is now "+status+" (path="+path+")");
-    }
-    public void streamStatus(String status, String streamID, String target) {
-        out.println("Stream "+streamID+" is now "+status+" (target="+target+")");
-    }
-    public void orConnStatus(String status, String orName) {
-        out.println("OR connection to "+orName+" is now "+status);
-    }
-    public void bandwidthUsed(long read, long written) {
-        out.println("Bandwidth usage: "+read+" bytes read; "+
-                    written+" bytes written.");
-    }
-    public void newDescriptors(java.util.List<String> orList) {
-        out.println("New descriptors for routers:");
-        for (Iterator<String> i = orList.iterator(); i.hasNext(); )
-            out.println("   "+i.next());
-    }
-    public void message(String type, String msg) {
-        out.println("["+type+"] "+msg.trim());
-    }
-
-    public void unrecognized(String type, String msg) {
-        out.println("unrecognized event ["+type+"] "+msg.trim());
-    }
-
-}
-
diff --git a/orbotservice/src/main/java/org/torproject/android/control/examples/Main.java b/orbotservice/src/main/java/org/torproject/android/control/examples/Main.java
deleted file mode 100644
index b0e0a3c0..00000000
--- a/orbotservice/src/main/java/org/torproject/android/control/examples/Main.java
+++ /dev/null
@@ -1,146 +0,0 @@
-// Copyright 2005 Nick Mathewson, Roger Dingledine
-// See LICENSE file for copying information
-package org.torproject.android.control.examples;
-
-import org.torproject.android.control.*;
-import java.io.EOFException;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.net.Socket;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Arrays;
-import java.util.Map;
-import java.util.Iterator;
-
-public class Main implements TorControlCommands {
-
-    public static void main(String args[]) {
-        if (args.length < 1) {
-            System.err.println("No command given.");
-            return;
-        }
-        try {
-            if (args[0].equals("set-config")) {
-                setConfig(args);
-            } else if (args[0].equals("get-config")) {
-                getConfig(args);
-            } else if (args[0].equals("get-info")) {
-                getInfo(args);
-            } else if (args[0].equals("listen")) {
-                listenForEvents(args);
-            } else if (args[0].equals("signal")) {
-                signal(args);
-            } else if (args[0].equals("auth")) {
-                authDemo(args);
-            } else {
-                System.err.println("Unrecognized command: "+args[0]);
-            }
-        } catch (EOFException ex) {
-            System.out.println("Control socket closed by Tor.");
-        } catch (TorControlError ex) {
-            System.err.println("Error from Tor process: "+
-                               ex+" ["+ex.getErrorMsg()+"]");
-        } catch (IOException ex) {
-            System.err.println("IO exception when talking to Tor process: "+
-                               ex);
-            ex.printStackTrace(System.err);
-        }
-    }
-
-    private static TorControlConnection getConnection(String[] args,
-        boolean daemon) throws IOException {
-        Socket s = new Socket("127.0.0.1", 9100);
-        TorControlConnection conn = new TorControlConnection(s);
-        conn.launchThread(daemon);
-        conn.authenticate(new byte[0]);
-        return conn;
-    }
-
-    private static TorControlConnection getConnection(String[] args)
-        throws IOException {
-        return getConnection(args, true);
-    }
-
-    public static void setConfig(String[] args) throws IOException {
-        // Usage: "set-config [-save] key value key value key value"
-        TorControlConnection conn = getConnection(args);
-        ArrayList<String> lst = new ArrayList<String>();
-        int i = 1;
-        boolean save = false;
-        if (args[i].equals("-save")) {
-            save = true;
-            ++i;
-        }
-        for (; i < args.length; i +=2) {
-            lst.add(args[i]+" "+args[i+1]);
-        }
-        conn.setConf(lst);
-        if (save) {
-            conn.saveConf();
-        }
-    }
-
-    public static void getConfig(String[] args) throws IOException {
-        // Usage: get-config key key key
-        TorControlConnection conn = getConnection(args);
-        List<ConfigEntry> lst = conn.getConf(Arrays.asList(args).subList(1,args.length));
-        for (Iterator<ConfigEntry> i = lst.iterator(); i.hasNext(); ) {
-            ConfigEntry e = i.next();
-            System.out.println("KEY: "+e.key);
-            System.out.println("VAL: "+e.value);
-        }
-    }
-
-    public static void getInfo(String[] args) throws IOException {
-        TorControlConnection conn = getConnection(args);
-        Map<String,String> m = conn.getInfo(Arrays.asList(args).subList(1,args.length));
-        for (Iterator<Map.Entry<String, String>> i = m.entrySet().iterator(); i.hasNext(); ) {
-            Map.Entry<String,String> e = i.next();
-            System.out.println("KEY: "+e.getKey());
-            System.out.println("VAL: "+e.getValue());
-        }
-    }
-
-    public static void listenForEvents(String[] args) throws IOException {
-        // Usage: listen [circ|stream|orconn|bw|newdesc|info|notice|warn|error]*
-        TorControlConnection conn = getConnection(args, false);
-        ArrayList<String> lst = new ArrayList<String>();
-        for (int i = 1; i < args.length; ++i) {
-            lst.add(args[i]);
-        }
-        conn.setEventHandler(
-            new DebuggingEventHandler(new PrintWriter(System.out, true)));
-        conn.setEvents(lst);
-    }
-
-    public static void signal(String[] args) throws IOException {
-        // Usage signal [reload|shutdown|dump|debug|halt]
-        TorControlConnection conn = getConnection(args, false);
-        // distinguish shutdown signal from other signals
-        if ("SHUTDOWN".equalsIgnoreCase(args[1])
-        		|| "HALT".equalsIgnoreCase(args[1])) {
-        	conn.shutdownTor(args[1].toUpperCase());
-        } else {
-        	conn.signal(args[1].toUpperCase());
-        }
-    }
-
-    public static void authDemo(String[] args) throws IOException {
-
-        PasswordDigest pwd = PasswordDigest.generateDigest();
-        Socket s = new Socket("127.0.0.1", 9100);
-        TorControlConnection conn = new TorControlConnection(s);
-        conn.launchThread(true);
-        conn.authenticate(new byte[0]);
-
-        conn.setConf("HashedControlPassword", pwd.getHashedPassword());
-
-        s = new Socket("127.0.0.1", 9100);
-        conn = new TorControlConnection(s);
-        conn.launchThread(true);
-        conn.authenticate(pwd.getSecret());
-    }
-
-}
-
diff --git a/orbotservice/src/main/java/org/torproject/android/service/TorService.java b/orbotservice/src/main/java/org/torproject/android/service/TorService.java
index 65f0d179..fc518024 100644
--- a/orbotservice/src/main/java/org/torproject/android/service/TorService.java
+++ b/orbotservice/src/main/java/org/torproject/android/service/TorService.java
@@ -723,9 +723,10 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
         extraLines.append("VirtualAddrNetwork 10.192.0.0/10").append('\n');
         extraLines.append("AutomapHostsOnResolve 1").append('\n');
 
-        extraLines.append("DisableNetwork 0").append('\n');
         extraLines.append("DormantClientTimeout 10 minutes").append('\n');
-        extraLines.append("DormantOnFirstStartup 1").append('\n');
+        extraLines.append("DormantOnFirstStartup 0").append('\n');
+
+        extraLines.append("DisableNetwork 0").append('\n');
 
         if (Prefs.useDebugLogging())
         {
@@ -1051,7 +1052,7 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
                         torConnSocket.setSoTimeout(CONTROL_SOCKET_TIMEOUT);
                         
                         conn = new TorControlConnection(torConnSocket);
-                        conn.launchThread(true);//is daemon
+                        conn.launchThread(false);//is daemon
                         
                         break;
                     }
@@ -1197,7 +1198,6 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
 
         conn.setEventHandler(mEventHandler);
 
-        
         conn.setEvents(Arrays.asList(new String[]{
               "ORCONN", "CIRC", "NOTICE", "WARN", "ERR","BW"}));
           // conn.setEvents(Arrays.asList(new String[]{
@@ -1509,11 +1509,13 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
             }
             
             mNetworkType = newNetType;
-        	mConnectivity = newConnectivityState;
 
-        	if (mConnectivity)
-                newIdentity();
+            if (newConnectivityState != mConnectivity) {
+                mConnectivity = newConnectivityState;
 
+                if (mConnectivity)
+                    newIdentity();
+            }
 
             /**
             if (doNetworKSleep && mCurrentStatus != STATUS_OFF)
diff --git a/orbotservice/src/main/java/org/torproject/android/service/util/CustomTorResourceInstaller.java b/orbotservice/src/main/java/org/torproject/android/service/util/CustomTorResourceInstaller.java
index a2561238..cb4f5c6a 100644
--- a/orbotservice/src/main/java/org/torproject/android/service/util/CustomTorResourceInstaller.java
+++ b/orbotservice/src/main/java/org/torproject/android/service/util/CustomTorResourceInstaller.java
@@ -64,6 +64,7 @@ public class CustomTorResourceInstaller implements TorServiceConstants {
             }
         }
 
+        //it exists but we can't execute it, so copy it to a new path
         if (fileTor.exists()) {
             InputStream is = new FileInputStream(fileTor);
             streamToFile(is, fileTor, false, true);
@@ -76,7 +77,8 @@ public class CustomTorResourceInstaller implements TorServiceConstants {
         //let's try another approach
         fileTor = CustomNativeLoader.loadNativeBinary(context,TOR_ASSET_KEY,new File(installFolder, TOR_ASSET_KEY));
 
-        setExecutable(fileTor);
+        if (fileTor != null && fileTor.exists())
+            setExecutable(fileTor);
 
         if (fileTor != null && fileTor.exists() && fileTor.canExecute())
             return fileTor;
diff --git a/orbotservice/src/main/java/org/torproject/android/service/vpn/OrbotVpnManager.java b/orbotservice/src/main/java/org/torproject/android/service/vpn/OrbotVpnManager.java
index 65db4659..0af6dcff 100644
--- a/orbotservice/src/main/java/org/torproject/android/service/vpn/OrbotVpnManager.java
+++ b/orbotservice/src/main/java/org/torproject/android/service/vpn/OrbotVpnManager.java
@@ -95,9 +95,8 @@ public class OrbotVpnManager implements Handler.Callback {
 
 		filePdnsd = CustomNativeLoader.loadNativeBinary(service.getApplicationContext(),PDNSD_BIN,new File(service.getFilesDir(),PDNSD_BIN));
 
-		// if that fails, try again using native utils
 		try {
-			killProcess(filePdnsd, "-1"); // this is -HUP
+			killProcess(filePdnsd, "-1");
 		} catch (Exception e) {
 			e.printStackTrace();
 		}
@@ -144,14 +143,17 @@ public class OrbotVpnManager implements Handler.Callback {
 			{
 				Log.d(TAG,"starting OrbotVPNService service!");
 
-				int newTorSocks = intent.getIntExtra(TorService.EXTRA_SOCKS_PROXY_PORT,-1);
-				int newTorDns = intent.getIntExtra(TorService.EXTRA_DNS_PORT,-1);
+				int torSocks = intent.getIntExtra(TorService.EXTRA_SOCKS_PROXY_PORT,-1);
+				int torDns = intent.getIntExtra(TorService.EXTRA_DNS_PORT,-1);
+
+				//if running, we need to restart
+				if ((torSocks != mTorSocks || torDns != mTorDns)) {
 
-				if ((mTorSocks != newTorSocks || mTorDns != newTorDns)) {
-					mTorSocks = newTorSocks;
-					mTorDns = newTorDns;
+					mTorSocks = torSocks;
+					mTorDns = torDns;
 
 					if (!mIsLollipop) {
+						stopSocksBypass();
 						startSocksBypass();
 					}
 
@@ -444,12 +446,14 @@ public class OrbotVpnManager implements Handler.Callback {
 
 			try {
 				BufferedReader reader = new BufferedReader(new FileReader(filePid));
-				pid = reader.readLine().trim();
-
-				VpnUtils.killProcess(pid,"-9");
-				filePid.delete();
-				return true;
+				String line = reader.readLine();
+				if (line != null) {
+					pid = reader.readLine().trim();
 
+					VpnUtils.killProcess(pid, "-9");
+					filePid.delete();
+					return true;
+				}
 			} catch (Exception e) {
 				Log.e(TAG,"error killing DNS Process: " + pid,e);
 			}
diff --git a/orbotservice/src/main/java/org/torproject/android/service/vpn/TorVpnService.java b/orbotservice/src/main/java/org/torproject/android/service/vpn/TorVpnService.java
index e70753f6..78c405f4 100644
--- a/orbotservice/src/main/java/org/torproject/android/service/vpn/TorVpnService.java
+++ b/orbotservice/src/main/java/org/torproject/android/service/vpn/TorVpnService.java
@@ -31,9 +31,7 @@ public class TorVpnService extends VpnService {
             e.printStackTrace();
         }
 
-        LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(this);
-        lbm.registerReceiver(mLocalBroadcastReceiver,
-                new IntentFilter(TorServiceConstants.LOCAL_ACTION_PORTS));
+
     }
 
     /* (non-Javadoc)
@@ -41,6 +39,18 @@ public class TorVpnService extends VpnService {
      */
     public int onStartCommand(Intent intent, int flags, int startId) {
 
+        if (intent.getAction().equals("start"))
+        {
+            LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(this);
+            lbm.registerReceiver(mLocalBroadcastReceiver,
+                    new IntentFilter(TorServiceConstants.LOCAL_ACTION_PORTS));
+        }
+        else if (intent.getAction().equals("stop"))
+        {
+            LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(this);
+            lbm.unregisterReceiver(mLocalBroadcastReceiver);
+        }
+
         mVpnManager.handleIntent(new Builder(), intent);
 
         return Service.START_STICKY;
@@ -50,8 +60,7 @@ public class TorVpnService extends VpnService {
     public void onDestroy() {
         super.onDestroy();
 
-        LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(this);
-        lbm.unregisterReceiver(mLocalBroadcastReceiver);
+
     }
 
     /**



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