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

Commits:

1 changed file:

Changes:

  • toolkit/modules/Moat.sys.mjs
    ... ... @@ -2,10 +2,7 @@
    2 2
      * License, v. 2.0. If a copy of the MPL was not distributed with this
    
    3 3
      * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
    
    4 4
     
    
    5
    -import {
    
    6
    -  TorSettings,
    
    7
    -  TorBridgeSource,
    
    8
    -} from "resource://gre/modules/TorSettings.sys.mjs";
    
    5
    +import { TorBridgeSource } from "resource://gre/modules/TorSettings.sys.mjs";
    
    9 6
     
    
    10 7
     const lazy = {};
    
    11 8
     
    
    ... ... @@ -204,68 +201,52 @@ export class MoatRPC {
    204 201
       // Convert received settings object to format used by TorSettings module
    
    205 202
       // In the event of error, just return null
    
    206 203
       #fixupSettings(settings) {
    
    207
    -    try {
    
    208
    -      let retval = TorSettings.defaultSettings();
    
    209
    -      if ("bridges" in settings) {
    
    210
    -        retval.bridges.enabled = true;
    
    211
    -        switch (settings.bridges.source) {
    
    212
    -          case "builtin":
    
    213
    -            retval.bridges.source = TorBridgeSource.BuiltIn;
    
    214
    -            retval.bridges.builtin_type = settings.bridges.type;
    
    215
    -            // Tor Browser will periodically update the built-in bridge strings list using the
    
    216
    -            // circumvention_builtin() function, so we can ignore the bridge strings we have received here;
    
    217
    -            // BridgeDB only returns a subset of the available built-in bridges through the circumvention_settings()
    
    218
    -            // function which is fine for our 3rd parties, but we're better off ignoring them in Tor Browser, otherwise
    
    219
    -            // we get in a weird situation of needing to update our built-in bridges in a piece-meal fashion which
    
    220
    -            // seems over-complicated/error-prone
    
    221
    -            break;
    
    222
    -          case "bridgedb":
    
    223
    -            retval.bridges.source = TorBridgeSource.BridgeDB;
    
    224
    -            if (settings.bridges.bridge_strings) {
    
    225
    -              retval.bridges.bridge_strings = settings.bridges.bridge_strings;
    
    226
    -              retval.bridges.disabled_strings = [];
    
    227
    -            } else {
    
    228
    -              throw new Error(
    
    229
    -                "MoatRPC::_fixupSettings(): Received no bridge-strings for BridgeDB bridge source"
    
    230
    -              );
    
    231
    -            }
    
    232
    -            break;
    
    233
    -          default:
    
    234
    -            throw new Error(
    
    235
    -              `MoatRPC::_fixupSettings(): Unexpected bridge source '${settings.bridges.source}'`
    
    236
    -            );
    
    204
    +    if (!("bridges" in settings)) {
    
    205
    +      throw new Error("Expected to find `bridges` in the settings object.");
    
    206
    +    }
    
    207
    +    const retval = {
    
    208
    +      bridges: {
    
    209
    +        enabled: true,
    
    210
    +      },
    
    211
    +    };
    
    212
    +    switch (settings.bridges.source) {
    
    213
    +      case "builtin":
    
    214
    +        retval.bridges.source = TorBridgeSource.BuiltIn;
    
    215
    +        retval.bridges.builtin_type = settings.bridges.type;
    
    216
    +        // TorSettings will ignore strings for built-in bridges, and use the
    
    217
    +        // ones it already knows, instead.
    
    218
    +        break;
    
    219
    +      case "bridgedb":
    
    220
    +        retval.bridges.source = TorBridgeSource.BridgeDB;
    
    221
    +        if (settings.bridges.bridge_strings) {
    
    222
    +          retval.bridges.bridge_strings = settings.bridges.bridge_strings;
    
    223
    +        } else {
    
    224
    +          throw new Error(
    
    225
    +            "Received no bridge-strings for BridgeDB bridge source"
    
    226
    +          );
    
    237 227
             }
    
    238
    -      }
    
    239
    -      if ("proxy" in settings) {
    
    240
    -        // TODO: populate proxy settings
    
    241
    -      }
    
    242
    -      if ("firewall" in settings) {
    
    243
    -        // TODO: populate firewall settings
    
    244
    -      }
    
    245
    -      return retval;
    
    246
    -    } catch (ex) {
    
    247
    -      console.log(ex.message);
    
    248
    -      return null;
    
    228
    +        break;
    
    229
    +      default:
    
    230
    +        throw new Error(
    
    231
    +          `Unexpected bridge source '${settings.bridges.source}'`
    
    232
    +        );
    
    249 233
         }
    
    234
    +    return retval;
    
    250 235
       }
    
    251 236
     
    
    252 237
       // Converts a list of settings objects received from BridgeDB to a list of settings objects
    
    253 238
       // understood by the TorSettings module
    
    254 239
       // In the event of error, returns and empty list
    
    255 240
       #fixupSettingsList(settingsList) {
    
    256
    -    try {
    
    257
    -      let retval = [];
    
    258
    -      for (let settings of settingsList) {
    
    259
    -        settings = this.#fixupSettings(settings);
    
    260
    -        if (settings != null) {
    
    261
    -          retval.push(settings);
    
    262
    -        }
    
    241
    +    const retval = [];
    
    242
    +    for (const settings of settingsList) {
    
    243
    +      try {
    
    244
    +        retval.push(this.#fixupSettings(settings));
    
    245
    +      } catch (ex) {
    
    246
    +        console.log(ex);
    
    263 247
           }
    
    264
    -      return retval;
    
    265
    -    } catch (ex) {
    
    266
    -      console.log(ex.message);
    
    267
    -      return [];
    
    268 248
         }
    
    249
    +    return retval;
    
    269 250
       }
    
    270 251
     
    
    271 252
       // Request tor settings for the user optionally based on their location (derived