[tbb-commits] [tor-browser/tor-browser-91.4.0esr-11.5-1] fixup! Bug 31286: Implementation of bridge, proxy, and firewall settings in about:preferences#tor

gk at torproject.org gk at torproject.org
Tue Dec 21 21:28:04 UTC 2021


commit 4cfbf6e5718da6e7186e391ebf42a62e08692d19
Author: Richard Pospesel <richard at torproject.org>
Date:   Fri Oct 15 16:16:32 2021 +0200

    fixup! Bug 31286: Implementation of bridge, proxy, and firewall settings in about:preferences#tor
---
 .../torpreferences/content/requestBridgeDialog.jsm |  27 +++--
 .../components/torpreferences/content/torPane.js   |   1 -
 browser/modules/BridgeDB.jsm                       | 119 ++++++---------------
 3 files changed, 51 insertions(+), 96 deletions(-)

diff --git a/browser/components/torpreferences/content/requestBridgeDialog.jsm b/browser/components/torpreferences/content/requestBridgeDialog.jsm
index 807d46cdfb18..44ae11762def 100644
--- a/browser/components/torpreferences/content/requestBridgeDialog.jsm
+++ b/browser/components/torpreferences/content/requestBridgeDialog.jsm
@@ -16,7 +16,6 @@ class RequestBridgeDialog {
     this._incorrectCaptchaHbox = null;
     this._incorrectCaptchaLabel = null;
     this._bridges = [];
-    this._proxyURI = null;
   }
 
   static get selectors() {
@@ -77,7 +76,7 @@ class RequestBridgeDialog {
     this._captchaImage = this._dialog.querySelector(selectors.captchaImage);
 
     // request captcha from bridge db
-    BridgeDB.requestNewCaptchaImage(this._proxyURI).then(uri => {
+    BridgeDB.requestNewCaptchaImage().then(uri => {
       this._setcaptchaImage(uri);
     });
 
@@ -160,17 +159,24 @@ class RequestBridgeDialog {
 
     BridgeDB.submitCaptchaGuess(captchaText)
       .then(aBridges => {
-        this._bridges = aBridges;
-
-        this._submitButton.disabled = false;
-        // This was successful, but use cancelDialog() to close, since
-        // we intercept the `dialogaccept` event.
-        this._dialog.cancelDialog();
+        if (aBridges) {
+          this._bridges = aBridges;
+          this._submitButton.disabled = false;
+          // This was successful, but use cancelDialog() to close, since
+          // we intercept the `dialogaccept` event.
+          this._dialog.cancelDialog();
+        } else {
+          this._bridges = [];
+          this._setUIDisabled(false);
+          this._incorrectCaptchaHbox.style.visibility = "visible";
+        }
       })
       .catch(aError => {
+        // TODO: handle other errors properly here when we do the bridge settings re-design
         this._bridges = [];
         this._setUIDisabled(false);
         this._incorrectCaptchaHbox.style.visibility = "visible";
+        console.log(eError);
       });
   }
 
@@ -182,13 +188,12 @@ class RequestBridgeDialog {
     this._captchaEntryTextbox.value = "";
     this._incorrectCaptchaHbox.style.visibility = "hidden";
 
-    BridgeDB.requestNewCaptchaImage(this._proxyURI).then(uri => {
+    BridgeDB.requestNewCaptchaImage().then(uri => {
       this._setcaptchaImage(uri);
     });
   }
 
-  openDialog(gSubDialog, aProxyURI, aCloseCallback) {
-    this._proxyURI = aProxyURI;
+  openDialog(gSubDialog, aCloseCallback) {
     gSubDialog.open(
       "chrome://browser/content/torpreferences/requestBridgeDialog.xhtml",
       {
diff --git a/browser/components/torpreferences/content/torPane.js b/browser/components/torpreferences/content/torPane.js
index 2df71db9327e..58eec7ff74aa 100644
--- a/browser/components/torpreferences/content/torPane.js
+++ b/browser/components/torpreferences/content/torPane.js
@@ -686,7 +686,6 @@ const gTorPane = (function() {
       let requestBridgeDialog = new RequestBridgeDialog();
       requestBridgeDialog.openDialog(
         gSubDialog,
-        TorSettings.proxy.uri,
         aBridges => {
           if (aBridges.length > 0) {
             let bridgeStrings = aBridges.join("\n");
diff --git a/browser/modules/BridgeDB.jsm b/browser/modules/BridgeDB.jsm
index 9f76b4f05a69..50665710ebf4 100644
--- a/browser/modules/BridgeDB.jsm
+++ b/browser/modules/BridgeDB.jsm
@@ -2,109 +2,60 @@
 
 var EXPORTED_SYMBOLS = ["BridgeDB"];
 
-const { TorLauncherBridgeDB } = ChromeUtils.import(
-  "resource://torlauncher/modules/tl-bridgedb.jsm"
-);
-const { TorProtocolService } = ChromeUtils.import(
-  "resource:///modules/TorProtocolService.jsm"
-);
-const { TorStrings } = ChromeUtils.import("resource:///modules/TorStrings.jsm");
+const { MoatRPC } = ChromeUtils.import("resource:///modules/Moat.jsm");
 
 var BridgeDB = {
-  _moatRequestor: null,
-  _currentCaptchaInfo: null,
+  _moatRPC: null,
+  _challenge: null,
+  _image: null,
   _bridges: null,
 
   get currentCaptchaImage() {
-    if (this._currentCaptchaInfo) {
-      return this._currentCaptchaInfo.captchaImage;
-    }
-    return null;
+    return this._image;
   },
 
   get currentBridges() {
     return this._bridges;
   },
 
-  async submitCaptchaGuess(aCaptchaSolution) {
-    if (this._moatRequestor && this._currentCaptchaInfo) {
-      return this._moatRequestor
-        .finishFetch(
-          this._currentCaptchaInfo.transport,
-          this._currentCaptchaInfo.challenge,
-          aCaptchaSolution
-        )
-        .then(aBridgeInfo => {
-          this._moatRequestor.close();
-          this._moatRequestor = null;
-          this._currentCaptchaInfo = null;
-          this._bridges = aBridgeInfo.bridges;
-          // array of bridge strings
-          return this._bridges;
-        });
+  async submitCaptchaGuess(solution) {
+    if (!this._moatRPC) {
+      this._moatRPC = new MoatRPC();
+      await this._moatRPC.init();
     }
 
-    return new Promise((aResponse, aReject) => {
-      aReject(new Error("Invalid _moatRequestor or _currentCaptchaInfo"));
-    });
-  },
-
-  async requestNewCaptchaImage(aProxyURI) {
-    // close and clear out existing state on captcha request
-    this.close();
-
-    let transportPlugins = await TorProtocolService.readStringArraySetting(
-      TorStrings.configKeys.clientTransportPlugin
+    const response = await this._moatRPC.check(
+      "obfs4",
+      this._challenge,
+      solution,
+      false
     );
+    this._bridges = response?.bridges;
+    return this._bridges;
+  },
 
-    let meekClientPath;
-    let meekTransport; // We support both "meek" and "meek_lite".
-    let meekClientArgs;
-    // TODO: shouldn't this early out once meek settings are found?
-    for (const line of transportPlugins) {
-      // Parse each ClientTransportPlugin line and look for the meek or
-      // meek_lite transport. This code works a lot like the Tor daemon's
-      // parse_transport_line() function.
-      let tokens = line.split(" ");
-      if (tokens.length > 2 && tokens[1] == "exec") {
-        let transportArray = tokens[0].split(",").map(aStr => aStr.trim());
-        let transport = transportArray.find(
-          aTransport => aTransport === "meek"
-        );
-        if (!transport) {
-          transport = transportArray.find(
-            aTransport => aTransport === "meek_lite"
-          );
-        }
-        if (transport) {
-          meekTransport = transport;
-          meekClientPath = tokens[2];
-          meekClientArgs = tokens.slice(3);
-        }
+  async requestNewCaptchaImage() {
+    try {
+      if (!this._moatRPC) {
+        this._moatRPC = new MoatRPC();
+        await this._moatRPC.init();
       }
-    }
-
-    this._moatRequestor = TorLauncherBridgeDB.createMoatRequestor();
 
-    return this._moatRequestor
-      .init(aProxyURI, meekTransport, meekClientPath, meekClientArgs)
-      .then(() => {
-        // TODO: get this from TorLauncherUtil
-        let bridgeType = "obfs4";
-        return this._moatRequestor.fetchBridges([bridgeType]);
-      })
-      .then(aCaptchaInfo => {
-        // cache off the current captcha info as the challenge is needed for response
-        this._currentCaptchaInfo = aCaptchaInfo;
-        return aCaptchaInfo.captchaImage;
-      });
+      const response = await this._moatRPC.fetch(["obfs4"]);
+      this._challenge = response.challenge;
+      this._image =
+        "data:image/jpeg;base64," + encodeURIComponent(response.image);
+    } catch (err) {
+      console.log(`error : ${err}`);
+    }
+    return this._image;
   },
 
   close() {
-    if (this._moatRequestor) {
-      this._moatRequestor.close();
-      this._moatRequestor = null;
-    }
-    this._currentCaptchaInfo = null;
+    this._moatRPC?.uninit();
+    this._moatRPC = null;
+    this._challenge = null;
+    this._image = null;
+    this._bridges = null;
   },
 };



More information about the tbb-commits mailing list