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

[tor-commits] [orbot/master] fix 448: hosted v3 onions would generate a new address on backup/restore, files from backup weren't being read in OrbotService but were in Orbot



commit 09230c030491a88479e2fd76c609560bb8132533
Author: bim <dsnake@xxxxxxxxxxxxxx>
Date:   Mon Apr 12 13:52:57 2021 -0400

    fix 448: hosted v3 onions would generate a new address on backup/restore, files from backup weren't being read in OrbotService but were in Orbot
---
 .../android/ui/hiddenservices/backup/BackupUtils.java    | 16 +++++++++++++---
 app/src/main/res/values/strings.xml                      |  1 +
 .../org/torproject/android/service/OrbotService.java     | 10 +++-------
 3 files changed, 17 insertions(+), 10 deletions(-)

diff --git a/app/src/main/java/org/torproject/android/ui/hiddenservices/backup/BackupUtils.java b/app/src/main/java/org/torproject/android/ui/hiddenservices/backup/BackupUtils.java
index af7f1333..d6cb091c 100644
--- a/app/src/main/java/org/torproject/android/ui/hiddenservices/backup/BackupUtils.java
+++ b/app/src/main/java/org/torproject/android/ui/hiddenservices/backup/BackupUtils.java
@@ -187,7 +187,17 @@ public class BackupUtils {
             else
                 mResolver.update(OnionServiceContentProvider.CONTENT_URI, fields, OnionServiceContentProvider.OnionService.PORT + "=" + port, null);
             dbService.close();
-            Toast.makeText(mContext, R.string.backup_restored, Toast.LENGTH_LONG).show();
+
+            configFile.delete();
+            if (v3Path.renameTo(new File(v3BasePath, "/v3" + port))) {
+                Toast.makeText(mContext, R.string.backup_restored, Toast.LENGTH_LONG).show();
+            } else {
+                // collision, clean up files
+                for (File file: v3Path.listFiles())
+                    file.delete();
+                v3Path.delete();
+                Toast.makeText(mContext, mContext.getString(R.string.backup_port_exist, port), Toast.LENGTH_LONG).show();
+            }
         } catch (IOException | JSONException e) {
             e.printStackTrace();
             Toast.makeText(mContext, R.string.error, Toast.LENGTH_LONG).show();
@@ -309,8 +319,8 @@ public class BackupUtils {
         returnCursor.close();
 
         String v3Dir = backupName.substring(0, backupName.lastIndexOf('.'));
-        File v3Paath = new File(getV3BasePath().getAbsolutePath(), v3Dir);
-        if (new ZipUtilities(null, zipUri, mResolver).unzip(v3Paath.getAbsolutePath()))
+        File v3Path = new File(getV3BasePath().getAbsolutePath(), v3Dir);
+        if (new ZipUtilities(null, zipUri, mResolver).unzip(v3Path.getAbsolutePath()))
             extractConfigFromUnzippedBackupV3(backupName);
         else
             Toast.makeText(mContext, R.string.error, Toast.LENGTH_LONG).show();
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 5df2f74d..55637899 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -190,6 +190,7 @@
     <string name="delete_service">Delete Service</string>
     <string name="backup_saved_at_external_storage">Backup saved at external storage</string>
     <string name="backup_restored">Backup restored</string>
+    <string name="backup_port_exist">Error: An Onion Service is Already Using Port %s</string>
     <string name="restore_backup">Restore Backup</string>
     <string name="create_a_backup_first">Create a backup first</string>
     <string name="start_tor_again_for_finish_the_process">Start Tor again for finish the process</string>
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 8f843189..5d5eb3fd 100644
--- a/orbotservice/src/main/java/org/torproject/android/service/OrbotService.java
+++ b/orbotservice/src/main/java/org/torproject/android/service/OrbotService.java
@@ -65,14 +65,10 @@ import java.io.InputStreamReader;
 import java.io.PrintStream;
 import java.io.PrintWriter;
 import java.net.Socket;
-import java.net.URL;
-import java.net.URLConnection;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
-import java.util.Date;
 import java.util.HashMap;
-import java.util.Iterator;
 import java.util.Objects;
 import java.util.Random;
 import java.util.StringTokenizer;
@@ -936,7 +932,7 @@ public class OrbotService extends VpnService implements TorServiceConstants, Orb
                 + " --defaults-torrc " + fileTorRc.getAbsolutePath()
                 + " -f " + fileTorrcCustom.getAbsolutePath();
 
-        int exitCode = -1;
+        int exitCode;
 
         try {
             exitCode = exec(torCmdString + " --verify-config", true);
@@ -1373,7 +1369,7 @@ public class OrbotService extends VpnService implements TorServiceConstants, Orb
                 extraLines.append("ServerDNSResolvConfFile").append(' ').append(dnsFile).append('\n');
                 extraLines.append("ORPort").append(' ').append(ORPort).append('\n');
                 extraLines.append("Nickname").append(' ').append(nickname).append('\n');
-                StringBuffer append = extraLines.append("ExitPolicy").append(' ').append("reject *:*").append('\n');
+                extraLines.append("ExitPolicy").append(' ').append("reject *:*").append('\n');
 
             }
         } catch (Exception e) {
@@ -1424,8 +1420,8 @@ public class OrbotService extends VpnService implements TorServiceConstants, Orb
                         debug("Adding hidden service on port: " + HSLocalPort);
 
                         torrc.append("HiddenServiceDir" + ' ' + hsDirPath).append('\n');
-                        torrc.append("HiddenServicePort" + ' ' + HSOnionPort + " 127.0.0.1:" + HSLocalPort).append('\n');
                         torrc.append("HiddenServiceVersion 2").append('\n');
+                        torrc.append("HiddenServicePort" + ' ' + HSOnionPort + " 127.0.0.1:" + HSLocalPort).append('\n');
 
                         if (HSAuthCookie == 1)
                             torrc.append("HiddenServiceAuthorizeClient stealth " + HSname).append('\n');



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