[tbb-commits] [Git][tpo/applications/tor-browser][tor-browser-115.6.0esr-13.5-1] fixup! Bug 40597: Implement TorSettings module

Pier Angelo Vendrame (@pierov) git at gitlab.torproject.org
Tue Jan 9 16:58:42 UTC 2024



Pier Angelo Vendrame pushed to branch tor-browser-115.6.0esr-13.5-1 at The Tor Project / Applications / Tor Browser


Commits:
afe1be79 by Pier Angelo Vendrame at 2024-01-09T17:57:06+01:00
fixup! Bug 40597: Implement TorSettings module

Bug 42359: Handle firewall and proxy in setSettings.

- - - - -


1 changed file:

- toolkit/modules/TorSettings.sys.mjs


Changes:

=====================================
toolkit/modules/TorSettings.sys.mjs
=====================================
@@ -301,8 +301,12 @@ class TorSettingsImpl {
           return this.#parsePort(val, false) ?? 0;
         },
       },
-      username: {},
-      password: {},
+      username: {
+        transform: val => val ?? "",
+      },
+      password: {
+        transform: val => val ?? "",
+      },
       uri: {
         getter: () => {
           const { type, address, port, username, password } = this.proxy;
@@ -910,7 +914,11 @@ class TorSettingsImpl {
   }
 
   /**
-   * Set all of our settings at once from a settings object.
+   * Set blocks of settings at once from an object.
+   *
+   * It is possible to set all settings, or only some sections (e.g., only
+   * bridges), but if a key is present, its settings must make sense (e.g., if
+   * bridges are enabled, a valid source must be provided).
    *
    * @param {object} settings The settings object to set
    */
@@ -924,35 +932,59 @@ class TorSettingsImpl {
     // Hold off on lots of notifications until all settings are changed.
     this.freezeNotifications();
     try {
-      this.bridges.enabled = !!settings.bridges.enabled;
-      this.bridges.source = settings.bridges.source;
-      switch (settings.bridges.source) {
-        case TorBridgeSource.BridgeDB:
-        case TorBridgeSource.UserProvided:
-          this.bridges.bridge_strings = settings.bridges.bridge_strings;
-          break;
-        case TorBridgeSource.BuiltIn: {
-          this.bridges.builtin_type = settings.bridges.builtin_type;
-          if (!this.bridges.bridge_strings.length) {
-            // No bridges were found when setting the builtin_type.
-            throw new Error(
-              `No available builtin bridges of type ${settings.bridges.builtin_type}`
-            );
-          }
-          break;
+      if ("bridges" in settings) {
+        this.bridges.enabled = !!settings.bridges.enabled;
+        // Currently, disabling bridges in the UI does not remove the lines,
+        // because we call only the `enabled` setter.
+        // So, if the bridge source is undefined but bridges are disabled,
+        // do not force Invalid. Instead, keep the current source.
+        if (this.bridges.enabled || settings.bridges.source !== undefined) {
+          this.bridges.source = settings.bridges.source;
         }
-        case TorBridgeSource.Invalid:
-          break;
-        default:
-          if (settings.bridges.enabled) {
-            throw new Error(
-              `Bridge source '${settings.source}' is not a valid source`
-            );
+        switch (settings.bridges.source) {
+          case TorBridgeSource.BridgeDB:
+          case TorBridgeSource.UserProvided:
+            this.bridges.bridge_strings = settings.bridges.bridge_strings;
+            break;
+          case TorBridgeSource.BuiltIn: {
+            this.bridges.builtin_type = settings.bridges.builtin_type;
+            if (!this.bridges.bridge_strings.length) {
+              // No bridges were found when setting the builtin_type.
+              throw new Error(
+                `No available builtin bridges of type ${settings.bridges.builtin_type}`
+              );
+            }
+            break;
           }
-          break;
+          case TorBridgeSource.Invalid:
+            break;
+          default:
+            if (settings.bridges.enabled) {
+              throw new Error(
+                `Bridge source '${settings.source}' is not a valid source`
+              );
+            }
+            break;
+        }
       }
 
-      // TODO: proxy and firewall
+      if ("proxy" in settings) {
+        this.proxy.enabled = !!settings.proxy.enabled;
+        if (this.proxy.enabled) {
+          this.proxy.type = settings.proxy.type;
+          this.proxy.address = settings.proxy.address;
+          this.proxy.port = settings.proxy.port;
+          this.proxy.username = settings.proxy.username;
+          this.proxy.password = settings.proxy.password;
+        }
+      }
+
+      if ("firewall" in settings) {
+        this.firewall.enabled = !!settings.firewall.enabled;
+        if (this.firewall.enabled) {
+          this.firewall.allowed_ports = settings.firewall.allowed_ports;
+        }
+      }
     } catch (ex) {
       // Restore the old settings without any new notifications generated from
       // the above code.



View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser/-/commit/afe1be797c9b0aab70e56f3a858653b49f445b9e

-- 
View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser/-/commit/afe1be797c9b0aab70e56f3a858653b49f445b9e
You're receiving this email because of your account on gitlab.torproject.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.torproject.org/pipermail/tbb-commits/attachments/20240109/c4c84ba6/attachment-0001.htm>


More information about the tbb-commits mailing list