Skip to content
Snippets Groups Projects
Verified Commit e5a43ae9 authored by Pier Angelo Vendrame's avatar Pier Angelo Vendrame :jack_o_lantern:
Browse files

fixup! Bug 40597: Implement TorSettings module

Bug 42348: Do not use TorSettings.defaultSettings as a starting point
for the settings object we receive from Moat.

Also, removed the TODO about proxy and firewall, since Moat is not
going to send them for now, but throw when we do not receive bridge
settings.
parent 3f0efca2
No related branches found
No related tags found
1 merge request!889Bug 42366: Tor Browser 115.7.0esr alpha rebase
......@@ -2,10 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import {
TorSettings,
TorBridgeSource,
} from "resource://gre/modules/TorSettings.sys.mjs";
import { TorBridgeSource } from "resource://gre/modules/TorSettings.sys.mjs";
const lazy = {};
......@@ -204,68 +201,52 @@ export class MoatRPC {
// Convert received settings object to format used by TorSettings module
// In the event of error, just return null
#fixupSettings(settings) {
try {
let retval = TorSettings.defaultSettings();
if ("bridges" in settings) {
retval.bridges.enabled = true;
if (!("bridges" in settings)) {
throw new Error("Expected to find `bridges` in the settings object.");
}
const retval = {
bridges: {
enabled: true,
},
};
switch (settings.bridges.source) {
case "builtin":
retval.bridges.source = TorBridgeSource.BuiltIn;
retval.bridges.builtin_type = settings.bridges.type;
// Tor Browser will periodically update the built-in bridge strings list using the
// circumvention_builtin() function, so we can ignore the bridge strings we have received here;
// BridgeDB only returns a subset of the available built-in bridges through the circumvention_settings()
// function which is fine for our 3rd parties, but we're better off ignoring them in Tor Browser, otherwise
// we get in a weird situation of needing to update our built-in bridges in a piece-meal fashion which
// seems over-complicated/error-prone
// TorSettings will ignore strings for built-in bridges, and use the
// ones it already knows, instead.
break;
case "bridgedb":
retval.bridges.source = TorBridgeSource.BridgeDB;
if (settings.bridges.bridge_strings) {
retval.bridges.bridge_strings = settings.bridges.bridge_strings;
retval.bridges.disabled_strings = [];
} else {
throw new Error(
"MoatRPC::_fixupSettings(): Received no bridge-strings for BridgeDB bridge source"
"Received no bridge-strings for BridgeDB bridge source"
);
}
break;
default:
throw new Error(
`MoatRPC::_fixupSettings(): Unexpected bridge source '${settings.bridges.source}'`
`Unexpected bridge source '${settings.bridges.source}'`
);
}
}
if ("proxy" in settings) {
// TODO: populate proxy settings
}
if ("firewall" in settings) {
// TODO: populate firewall settings
}
return retval;
} catch (ex) {
console.log(ex.message);
return null;
}
}
// Converts a list of settings objects received from BridgeDB to a list of settings objects
// understood by the TorSettings module
// In the event of error, returns and empty list
#fixupSettingsList(settingsList) {
const retval = [];
for (const settings of settingsList) {
try {
let retval = [];
for (let settings of settingsList) {
settings = this.#fixupSettings(settings);
if (settings != null) {
retval.push(settings);
retval.push(this.#fixupSettings(settings));
} catch (ex) {
console.log(ex);
}
}
return retval;
} catch (ex) {
console.log(ex.message);
return [];
}
}
// Request tor settings for the user optionally based on their location (derived
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment