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

[tor-commits] [orbot/master] add overall preference for enabling/disabling onion service hosting



commit 0e39a7776c03d82f8e5dc08a639b401b75de0f08
Author: n8fr8 <nathan@xxxxxxxxxxxxxxxxxxxx>
Date:   Thu May 20 10:50:49 2021 -0400

    add overall preference for enabling/disabling onion service hosting
---
 orbotservice/build.gradle                          |   2 +-
 orbotservice/src/main/assets/fronts                |   5 +-
 .../torproject/android/service/OrbotService.java   | 126 ++++++++++-----------
 .../org/torproject/android/service/util/Prefs.java |  10 ++
 4 files changed, 75 insertions(+), 68 deletions(-)

diff --git a/orbotservice/build.gradle b/orbotservice/build.gradle
index 9f79f17f..67770146 100644
--- a/orbotservice/build.gradle
+++ b/orbotservice/build.gradle
@@ -64,5 +64,5 @@ dependencies {
     api 'info.guardianproject:jtorctl:0.4.5.7'
     implementation 'info.guardianproject:tor-android:0.4.5.7'
 
-    implementation 'com.github.tladesignz:IPtProxy:0.5.2'
+    implementation 'com.github.tladesignz:IPtProxy:0.6.0'
 }
diff --git a/orbotservice/src/main/assets/fronts b/orbotservice/src/main/assets/fronts
index 6782446d..6cafa57b 100644
--- a/orbotservice/src/main/assets/fronts
+++ b/orbotservice/src/main/assets/fronts
@@ -1,5 +1,6 @@
-snowflake https://d2kt284300pde7.cloudfront.net/
-snowflake-stun stun:stun.l.google.com:19302
+snowflake-target https://snowflake-broker.torproject.net.global.prod.fastly.net/
+snowflake-front cdn.sstatic.net
+snowflake-stun stun:stun.stunprotocol.org:3478
 moat-cdn https://d50gd378qj74g.cloudfront.net/
 moat-url https://moat.torproject.org.global.prod.fastly.net/
 moat-front cdn.sstatic.net
\ No newline at end of file
diff --git a/orbotservice/src/main/java/org/torproject/android/service/OrbotService.java b/orbotservice/src/main/java/org/torproject/android/service/OrbotService.java
index 5077ed6c..ed463752 100644
--- a/orbotservice/src/main/java/org/torproject/android/service/OrbotService.java
+++ b/orbotservice/src/main/java/org/torproject/android/service/OrbotService.java
@@ -296,32 +296,29 @@ public class OrbotService extends VpnService implements TorServiceConstants, Orb
 
     private void stopTorAsync() {
 
-        new Thread(() -> {
-            Log.i("OrbotService", "stopTor");
-            try {
-                sendCallbackStatus(STATUS_STOPPING);
-                sendCallbackLogMessage(getString(R.string.status_shutting_down));
-
-                if (useIPtObfsMeekProxy())
-                    IPtProxy.stopObfs4Proxy();
+        Log.i("OrbotService", "stopTor");
+        try {
+            sendCallbackStatus(STATUS_STOPPING);
+            sendCallbackLogMessage(getString(R.string.status_shutting_down));
 
-                if (useIPtSnowflakeProxy())
-                    IPtProxy.stopSnowflake();
+            if (useIPtObfsMeekProxy())
+                IPtProxy.stopObfs4Proxy();
 
+            if (useIPtSnowflakeProxy())
+                IPtProxy.stopSnowflake();
 
-                stopTorDaemon(true);
+            stopTor();
 
-                //stop the foreground priority and make sure to remove the persistant notification
-                stopForeground(true);
+            //stop the foreground priority and make sure to remove the persistant notification
+            stopForeground(true);
 
-                sendCallbackLogMessage(getString(R.string.status_disabled));
-            } catch (Exception e) {
-                logNotice("An error occured stopping Tor: " + e.getMessage());
-                sendCallbackLogMessage(getString(R.string.something_bad_happened));
-            }
-            clearNotifications();
-            sendCallbackStatus(STATUS_OFF);
-        }).start();
+            sendCallbackLogMessage(getString(R.string.status_disabled));
+        } catch (Exception e) {
+            logNotice("An error occured stopping Tor: " + e.getMessage());
+            sendCallbackLogMessage(getString(R.string.something_bad_happened));
+        }
+        clearNotifications();
+        sendCallbackStatus(STATUS_OFF);
     }
 
     private void stopTorOnError(String message) {
@@ -377,11 +374,12 @@ public class OrbotService extends VpnService implements TorServiceConstants, Orb
 
     private void startSnowflakeClient() {
         //this is using the current, default Tor snowflake infrastructure
-        String front = getCdnFront(this,"snowflake");
+        String target = getCdnFront(this, "snowflake-target");
+        String front = getCdnFront(this,"snowflake-front");
         String stunServer = getCdnFront(this, "snowflake-stun");
 
-        IPtProxy.startSnowflake(stunServer, front,
-                null, null, true, false, true, 3);
+        IPtProxy.startSnowflake(stunServer, target, front,
+                 null, true, false, true, 3);
 
     }
 
@@ -408,41 +406,33 @@ public class OrbotService extends VpnService implements TorServiceConstants, Orb
         boolean unsafeLogging = false;
         IPtProxy.startSnowflakeProxy(capacity, broker, relay, stun, logFile, keepLocalAddresses, unsafeLogging);
     }
+
+    private void stopSnowflakeProxy () {
+
+        IPtProxy.stopSnowflakeProxy();
+    }
     /**
      * if someone stops during startup, we may have to wait for the conn port to be setup, so we can properly shutdown tor
      */
-    private void stopTorDaemon(boolean waitForConnection) throws Exception {
+    private void stopTor() throws Exception {
 
-        int tryCount = 0;
-
-        while (tryCount++ < 3) {
-            if (conn != null) {
-                logNotice("Using control port to shutdown Tor");
-
-                try {
-                    logNotice("sending HALT signal to Tor process");
-                    conn.shutdownTor(TorControlCommands.SIGNAL_SHUTDOWN);
-
-                } catch (IOException e) {
-                    Log.d(OrbotConstants.TAG, "error shutting down Tor via connection", e);
-                }
+        if (conn != null) {
+            logNotice("Using control port to shutdown Tor");
 
-                if (shouldUnbindTorService) {
-                    unbindService(torServiceConnection);
-                    shouldUnbindTorService = false;
-                }
+            try {
+                logNotice("sending HALT signal to Tor process");
+                conn.shutdownTor(TorControlCommands.SIGNAL_SHUTDOWN);
 
-                conn = null;
-                break;
+            } catch (IOException e) {
+                Log.d(OrbotConstants.TAG, "error shutting down Tor via connection", e);
             }
 
-            if (!waitForConnection)
-                break;
-
-            try {
-                Thread.sleep(3000);
-            } catch (Exception e) {
+            if (shouldUnbindTorService) {
+                unbindService(torServiceConnection);
+                shouldUnbindTorService = false;
             }
+
+            conn = null;
         }
     }
 
@@ -728,7 +718,7 @@ public class OrbotService extends VpnService implements TorServiceConstants, Orb
             sendCallbackStatus(STATUS_STARTING);
 
             // make sure there are no stray daemons running
-            stopTorDaemon(false);
+            stopTor();
 
             showToolbarNotification(getString(R.string.status_starting_up), NOTIFY_ID, R.drawable.ic_stat_tor);
             //sendCallbackLogMessage(getString(R.string.status_starting_up));
@@ -742,15 +732,18 @@ public class OrbotService extends VpnService implements TorServiceConstants, Orb
                 }
 
             runTorShellCmd();
-            try {
-                updateLegacyV2OnionNames();
-            } catch (SecurityException se) {
-                logNotice("unable to upload legacy v2 onion names");
-            }
-            try {
-                updateV3OnionNames();
-            } catch (SecurityException se) {
-                logNotice("unable to upload v3 onion names");
+
+            if (Prefs.hostOnionServicesEnabled()) {
+                try {
+                    updateLegacyV2OnionNames();
+                } catch (SecurityException se) {
+                    logNotice("unable to upload legacy v2 onion names");
+                }
+                try {
+                    updateV3OnionNames();
+                } catch (SecurityException se) {
+                    logNotice("unable to upload v3 onion names");
+                }
             }
         } catch (Exception e) {
             logException("Unable to start Tor: " + e.toString(), e);
@@ -1205,11 +1198,14 @@ public class OrbotService extends VpnService implements TorServiceConstants, Orb
             return null;
         }
 
-        ContentResolver contentResolver = getApplicationContext().getContentResolver();
-        addV3OnionServicesToTorrc(extraLines, contentResolver);
-        addV3ClientAuthToTorrc(extraLines, contentResolver);
-        addV2HiddenServicesToTorrc(extraLines, contentResolver);
-        addV2ClientCookiesToTorrc(extraLines, contentResolver);
+        if (Prefs.hostOnionServicesEnabled()) {
+            ContentResolver contentResolver = getApplicationContext().getContentResolver();
+            addV3OnionServicesToTorrc(extraLines, contentResolver);
+            addV3ClientAuthToTorrc(extraLines, contentResolver);
+            addV2HiddenServicesToTorrc(extraLines, contentResolver);
+            addV2ClientCookiesToTorrc(extraLines, contentResolver);
+        }
+
         return extraLines;
     }
 
diff --git a/orbotservice/src/main/java/org/torproject/android/service/util/Prefs.java b/orbotservice/src/main/java/org/torproject/android/service/util/Prefs.java
index 1b2922a7..5c36793d 100644
--- a/orbotservice/src/main/java/org/torproject/android/service/util/Prefs.java
+++ b/orbotservice/src/main/java/org/torproject/android/service/util/Prefs.java
@@ -21,6 +21,8 @@ public class Prefs {
     private final static String PREF_USE_VPN = "pref_vpn";
     private final static String PREF_EXIT_NODES = "pref_exit_nodes";
     private final static String PREF_BE_A_SNOWFLAKE = "pref_be_a_snowflake";
+    private final static String PREF_HOST_ONION_SERVICES = "pref_host_onionservices";
+
 
     private static SharedPreferences prefs;
 
@@ -37,6 +39,14 @@ public class Prefs {
         prefs.edit().putString(key, value).apply();
     }
 
+    public static boolean hostOnionServicesEnabled () {
+        return prefs.getBoolean(PREF_HOST_ONION_SERVICES, true);
+    }
+
+    public static void putHostOnionServicesEnabled(boolean value) {
+        putBoolean(PREF_HOST_ONION_SERVICES, value);
+    }
+
     public static boolean bridgesEnabled() {
         //if phone is in Farsi, enable bridges by default
         boolean bridgesEnabledDefault = Locale.getDefault().getLanguage().equals("fa");



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