Commits:
-
c3db620a
by Elena at 2026-11-17T11:31:40+01:00
fixup! TB 44806: Implement the tor integration in Rust.
TB 44930: Implement the commands on the Rust control port
Expose the new methods over the control port.
-
499ed2b8
by Elena at 2026-11-17T11:38:16+01:00
fixup! TB 44806: Implement the tor integration in Rust.
TB 44930: Implement the commands on the Rust control port
JS wrappers for the Rust control port.
-
c441ec64
by Elena at 2026-11-17T11:38:17+01:00
fixup! TB 44806: Implement the tor integration in Rust.
TB 44930: Implement the commands on the Rust control port
Integration tests
-
a4bd8746
by Elena at 2026-11-17T11:38:17+01:00
fixup! TB 44806: Implement the tor integration in Rust.
TB 44930: Implement the commands on the Rust control port
Actually use the new control port.
15 changed files:
Changes:
Cargo.lock
| ... |
... |
@@ -8283,10 +8283,13 @@ version = "0.1.0" |
|
8283
|
8283
|
dependencies = [
|
|
8284
|
8284
|
"bytes",
|
|
8285
|
8285
|
"cstr",
|
|
|
8286
|
+ "hex",
|
|
8286
|
8287
|
"log",
|
|
8287
|
8288
|
"moz_task",
|
|
8288
|
8289
|
"nserror",
|
|
8289
|
8290
|
"nsstring",
|
|
|
8291
|
+ "serde",
|
|
|
8292
|
+ "serde_json",
|
|
8290
|
8293
|
"thin-vec",
|
|
8291
|
8294
|
"tor_provider",
|
|
8292
|
8295
|
"xpcom",
|
toolkit/components/tor-integration/OxidationAdapters.sys.mjs
|
|
1
|
+/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
2
|
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
3
|
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
4
|
+
|
|
|
5
|
+/**
|
|
|
6
|
+ * Converters from the JSON created by the Rust crates to the objects expected
|
|
|
7
|
+ * by the JS tor-launcher.
|
|
|
8
|
+ */
|
|
|
9
|
+export class OxidationAdapters {
|
|
|
10
|
+ static #bytesToHex(bytes) {
|
|
|
11
|
+ return Array.from(bytes, b => b.toString(16).padStart(2, "0")).join("");
|
|
|
12
|
+ }
|
|
|
13
|
+
|
|
|
14
|
+ static convertCircuit(circuit) {
|
|
|
15
|
+ const circ = {
|
|
|
16
|
+ id: circuit.id,
|
|
|
17
|
+ nodes: circuit.path.map(fp => OxidationAdapters.#bytesToHex(fp)),
|
|
|
18
|
+ };
|
|
|
19
|
+ if (circuit.conflux_id) {
|
|
|
20
|
+ circ.confluxId = OxidationAdapters.#bytesToHex(circuit.conflux_id);
|
|
|
21
|
+ }
|
|
|
22
|
+ return circ;
|
|
|
23
|
+ }
|
|
|
24
|
+
|
|
|
25
|
+ static convertBootstrapPhase(phase) {
|
|
|
26
|
+ return Object.fromEntries(
|
|
|
27
|
+ Object.entries(phase).map(([key, value]) => {
|
|
|
28
|
+ if (key === "severity") {
|
|
|
29
|
+ key = "TYPE";
|
|
|
30
|
+ value = value.toUpperCase();
|
|
|
31
|
+ } else if (key === "should_warn") {
|
|
|
32
|
+ key = "RECOMMENDATION";
|
|
|
33
|
+ value = value ? "warn" : "ignore";
|
|
|
34
|
+ } else {
|
|
|
35
|
+ key = key.toUpperCase();
|
|
|
36
|
+ }
|
|
|
37
|
+ return [key, value];
|
|
|
38
|
+ })
|
|
|
39
|
+ );
|
|
|
40
|
+ }
|
|
|
41
|
+
|
|
|
42
|
+ static convertBridge(b) {
|
|
|
43
|
+ const bridge = {
|
|
|
44
|
+ transport: b.transport ?? "vanilla",
|
|
|
45
|
+ addr: b.address,
|
|
|
46
|
+ };
|
|
|
47
|
+ if (b.fingerprint) {
|
|
|
48
|
+ bridge.id = b.fingerprint;
|
|
|
49
|
+ }
|
|
|
50
|
+ if (b.args) {
|
|
|
51
|
+ bridge.args = b.args;
|
|
|
52
|
+ }
|
|
|
53
|
+ return bridge;
|
|
|
54
|
+ }
|
|
|
55
|
+
|
|
|
56
|
+ static convertPluggableTransports(pts) {
|
|
|
57
|
+ return pts.map(pt => {
|
|
|
58
|
+ if (pt.pt_type === "exec") {
|
|
|
59
|
+ return {
|
|
|
60
|
+ transports: pt.transports,
|
|
|
61
|
+ type: pt.pt_type,
|
|
|
62
|
+ pathToBinary: pt.path_to_binary,
|
|
|
63
|
+ options: pt.options ?? "",
|
|
|
64
|
+ };
|
|
|
65
|
+ }
|
|
|
66
|
+ return {
|
|
|
67
|
+ transports: pt.transports,
|
|
|
68
|
+ type: pt.pt_type,
|
|
|
69
|
+ ip: pt.ip,
|
|
|
70
|
+ port: pt.port,
|
|
|
71
|
+ };
|
|
|
72
|
+ });
|
|
|
73
|
+ }
|
|
|
74
|
+
|
|
|
75
|
+ static convertOnionKeys(keys) {
|
|
|
76
|
+ return keys.map(k => {
|
|
|
77
|
+ const key = {
|
|
|
78
|
+ address: k.address,
|
|
|
79
|
+ keyType: k.key_type,
|
|
|
80
|
+ keyBlob: k.key_blob,
|
|
|
81
|
+ flags: [],
|
|
|
82
|
+ };
|
|
|
83
|
+ if (k.is_permanent) {
|
|
|
84
|
+ key.flags.push("Permanent");
|
|
|
85
|
+ }
|
|
|
86
|
+ return key;
|
|
|
87
|
+ });
|
|
|
88
|
+ }
|
|
|
89
|
+}
|
|
|
90
|
+
|
|
|
91
|
+/**
|
|
|
92
|
+ * A class that converts an XPCOM callback to a JS promise.
|
|
|
93
|
+ */
|
|
|
94
|
+class PromisifiedCallback {
|
|
|
95
|
+ #promise;
|
|
|
96
|
+ #resolve;
|
|
|
97
|
+ #reject;
|
|
|
98
|
+
|
|
|
99
|
+ constructor() {
|
|
|
100
|
+ const { promise, resolve, reject } = Promise.withResolvers();
|
|
|
101
|
+ this.#promise = promise;
|
|
|
102
|
+ this.#resolve = resolve;
|
|
|
103
|
+ this.#reject = reject;
|
|
|
104
|
+ }
|
|
|
105
|
+
|
|
|
106
|
+ get promise() {
|
|
|
107
|
+ return this.#promise;
|
|
|
108
|
+ }
|
|
|
109
|
+
|
|
|
110
|
+ onReply(reply) {
|
|
|
111
|
+ if (reply) {
|
|
|
112
|
+ this.#resolve(JSON.parse(reply));
|
|
|
113
|
+ } else {
|
|
|
114
|
+ this.#resolve();
|
|
|
115
|
+ }
|
|
|
116
|
+ }
|
|
|
117
|
+
|
|
|
118
|
+ onTorError(code, message) {
|
|
|
119
|
+ const err = new Error(message);
|
|
|
120
|
+ err.code = code;
|
|
|
121
|
+ this.#reject(err);
|
|
|
122
|
+ }
|
|
|
123
|
+
|
|
|
124
|
+ onGenericError(message) {
|
|
|
125
|
+ this.#reject(new Error(message));
|
|
|
126
|
+ }
|
|
|
127
|
+}
|
|
|
128
|
+
|
|
|
129
|
+/**
|
|
|
130
|
+ * Promisify an XPCOM method that has a signature that looks like:
|
|
|
131
|
+ * void name(<args>, in torITorReplyCallback callback);
|
|
|
132
|
+ *
|
|
|
133
|
+ * @param {object} obj The oject that contains the method to call
|
|
|
134
|
+ * @param {string} method The name of the method to call
|
|
|
135
|
+ * @param {...any} args The arguments to pass before the callback
|
|
|
136
|
+ * @returns {PromiseLike} A promise that will be resolved/rejected by the native
|
|
|
137
|
+ * method
|
|
|
138
|
+ */
|
|
|
139
|
+export async function promisifyMethod(obj, method, ...args) {
|
|
|
140
|
+ const cb = new PromisifiedCallback();
|
|
|
141
|
+ obj[method](...args, cb);
|
|
|
142
|
+ return cb.promise;
|
|
|
143
|
+} |
toolkit/components/tor-integration/OxidizedControlPort.sys.mjs
|
|
1
|
+/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
2
|
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
3
|
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
4
|
+
|
|
|
5
|
+import {
|
|
|
6
|
+ OxidationAdapters,
|
|
|
7
|
+ promisifyMethod,
|
|
|
8
|
+} from "moz-src:///toolkit/components/tor-integration/OxidationAdapters.sys.mjs";
|
|
|
9
|
+
|
|
|
10
|
+/**
|
|
|
11
|
+ * An adapter between torITorNotificationListener and TorEventHandler.
|
|
|
12
|
+ */
|
|
|
13
|
+class NotificationAdapter {
|
|
|
14
|
+ #actualHandler;
|
|
|
15
|
+
|
|
|
16
|
+ constructor(handler) {
|
|
|
17
|
+ this.#actualHandler = handler;
|
|
|
18
|
+ }
|
|
|
19
|
+
|
|
|
20
|
+ logMessage(severity, message) {
|
|
|
21
|
+ this.#actualHandler.onLogMessage(severity, message);
|
|
|
22
|
+ }
|
|
|
23
|
+
|
|
|
24
|
+ bootstrapStatus(status) {
|
|
|
25
|
+ this.#actualHandler.onBootstrapStatus(
|
|
|
26
|
+ OxidationAdapters.convertBootstrapPhase(JSON.parse(status))
|
|
|
27
|
+ );
|
|
|
28
|
+ }
|
|
|
29
|
+
|
|
|
30
|
+ circuitBuilt(circuit) {
|
|
|
31
|
+ this.#actualHandler.onCircuitBuilt(
|
|
|
32
|
+ OxidationAdapters.convertCircuit(JSON.parse(circuit))
|
|
|
33
|
+ );
|
|
|
34
|
+ }
|
|
|
35
|
+
|
|
|
36
|
+ circuitClosed(id) {
|
|
|
37
|
+ this.#actualHandler.onCircuitClosed(id);
|
|
|
38
|
+ }
|
|
|
39
|
+
|
|
|
40
|
+ streamSentConnect(stream) {
|
|
|
41
|
+ stream = JSON.parse(stream);
|
|
|
42
|
+ this.#actualHandler.onStreamSentConnect(
|
|
|
43
|
+ stream.stream_id,
|
|
|
44
|
+ stream.circuit_id,
|
|
|
45
|
+ stream.socks_username,
|
|
|
46
|
+ stream.socks_password
|
|
|
47
|
+ );
|
|
|
48
|
+ }
|
|
|
49
|
+
|
|
|
50
|
+ connectionClosed() {
|
|
|
51
|
+ this.#actualHandler.onClosed();
|
|
|
52
|
+ }
|
|
|
53
|
+}
|
|
|
54
|
+
|
|
|
55
|
+/**
|
|
|
56
|
+ * An adapter to allow TorProvider use the Rust implementation of the
|
|
|
57
|
+ * controller.
|
|
|
58
|
+ */
|
|
|
59
|
+export class OxidizedControlPort {
|
|
|
60
|
+ #native;
|
|
|
61
|
+
|
|
|
62
|
+ static fromIpcFile(ipcFile) {
|
|
|
63
|
+ return new OxidizedControlPort(Services.tor.createControlPortIPC(ipcFile));
|
|
|
64
|
+ }
|
|
|
65
|
+
|
|
|
66
|
+ static fromSocketAddress(host, port) {
|
|
|
67
|
+ return new OxidizedControlPort(Services.tor.createControlPort(host, port));
|
|
|
68
|
+ }
|
|
|
69
|
+
|
|
|
70
|
+ constructor(native) {
|
|
|
71
|
+ this.#native = native;
|
|
|
72
|
+ }
|
|
|
73
|
+
|
|
|
74
|
+ setEventHandler(eventHandler) {
|
|
|
75
|
+ this.#native.setNotificationListener(new NotificationAdapter(eventHandler));
|
|
|
76
|
+ }
|
|
|
77
|
+
|
|
|
78
|
+ close() {
|
|
|
79
|
+ this.#native?.close();
|
|
|
80
|
+ this.#native = null;
|
|
|
81
|
+ }
|
|
|
82
|
+
|
|
|
83
|
+ get isOpen() {
|
|
|
84
|
+ return !!this.#native;
|
|
|
85
|
+ }
|
|
|
86
|
+
|
|
|
87
|
+ authenticate(password) {
|
|
|
88
|
+ return promisifyMethod(this.#native, "authenticate", Array.from(password));
|
|
|
89
|
+ }
|
|
|
90
|
+
|
|
|
91
|
+ async getBootstrapPhase() {
|
|
|
92
|
+ return OxidationAdapters.convertBootstrapPhase(
|
|
|
93
|
+ await promisifyMethod(this.#native, "getBootstrapPhase")
|
|
|
94
|
+ );
|
|
|
95
|
+ }
|
|
|
96
|
+
|
|
|
97
|
+ async getNodeAddresses(id) {
|
|
|
98
|
+ const addrs = await promisifyMethod(this.#native, "getNodeAddresses", id);
|
|
|
99
|
+ const rv = [addrs.ipv4];
|
|
|
100
|
+ if (addrs.ipv6) {
|
|
|
101
|
+ rv.push(addrs.ipv6);
|
|
|
102
|
+ }
|
|
|
103
|
+ return rv;
|
|
|
104
|
+ }
|
|
|
105
|
+
|
|
|
106
|
+ async getIPCountry(ip) {
|
|
|
107
|
+ return promisifyMethod(this.#native, "getIpCountry", ip);
|
|
|
108
|
+ }
|
|
|
109
|
+
|
|
|
110
|
+ getSocksListeners() {
|
|
|
111
|
+ return promisifyMethod(this.#native, "getSocksListeners");
|
|
|
112
|
+ }
|
|
|
113
|
+
|
|
|
114
|
+ async getCircuits() {
|
|
|
115
|
+ const circuits = await promisifyMethod(this.#native, "getCircuits");
|
|
|
116
|
+ return circuits.map(OxidationAdapters.convertCircuit);
|
|
|
117
|
+ }
|
|
|
118
|
+
|
|
|
119
|
+ async getBridges() {
|
|
|
120
|
+ const bridges = await promisifyMethod(this.#native, "getBridges");
|
|
|
121
|
+ return bridges.map(OxidationAdapters.convertBridge);
|
|
|
122
|
+ }
|
|
|
123
|
+
|
|
|
124
|
+ async getPluggableTransports() {
|
|
|
125
|
+ return OxidationAdapters.convertPluggableTransports(
|
|
|
126
|
+ await promisifyMethod(this.#native, "getPluggableTransports")
|
|
|
127
|
+ );
|
|
|
128
|
+ }
|
|
|
129
|
+
|
|
|
130
|
+ setConf(values) {
|
|
|
131
|
+ return promisifyMethod(this.#native, "setConf", JSON.stringify(values));
|
|
|
132
|
+ }
|
|
|
133
|
+
|
|
|
134
|
+ setNetworkEnabled(enabled) {
|
|
|
135
|
+ return promisifyMethod(this.#native, "setNetworkEnabled", enabled);
|
|
|
136
|
+ }
|
|
|
137
|
+
|
|
|
138
|
+ flushSettings() {
|
|
|
139
|
+ return promisifyMethod(this.#native, "flushSettings");
|
|
|
140
|
+ }
|
|
|
141
|
+
|
|
|
142
|
+ async onionAuthViewKeys() {
|
|
|
143
|
+ return OxidationAdapters.convertOnionKeys(
|
|
|
144
|
+ await promisifyMethod(this.#native, "onionAuthViewKeys")
|
|
|
145
|
+ );
|
|
|
146
|
+ }
|
|
|
147
|
+
|
|
|
148
|
+ onionAuthAdd(address, b64PrivateKey, isPermanent) {
|
|
|
149
|
+ return promisifyMethod(
|
|
|
150
|
+ this.#native,
|
|
|
151
|
+ "onionAuthAdd",
|
|
|
152
|
+ address,
|
|
|
153
|
+ b64PrivateKey,
|
|
|
154
|
+ isPermanent
|
|
|
155
|
+ );
|
|
|
156
|
+ }
|
|
|
157
|
+
|
|
|
158
|
+ onionAuthRemove(address) {
|
|
|
159
|
+ return promisifyMethod(this.#native, "onionAuthRemove", address);
|
|
|
160
|
+ }
|
|
|
161
|
+
|
|
|
162
|
+ takeOwnership() {
|
|
|
163
|
+ return promisifyMethod(this.#native, "takeOwnership");
|
|
|
164
|
+ }
|
|
|
165
|
+
|
|
|
166
|
+ resetOwningControllerProcess() {
|
|
|
167
|
+ return promisifyMethod(this.#native, "resetOwningControllerProcess");
|
|
|
168
|
+ }
|
|
|
169
|
+
|
|
|
170
|
+ newnym() {
|
|
|
171
|
+ return promisifyMethod(this.#native, "newnym");
|
|
|
172
|
+ }
|
|
|
173
|
+
|
|
|
174
|
+ setEvents(types) {
|
|
|
175
|
+ return promisifyMethod(this.#native, "setEvents", types);
|
|
|
176
|
+ }
|
|
|
177
|
+} |
toolkit/components/tor-integration/moz.build
| ... |
... |
@@ -11,3 +11,5 @@ XPCOM_MANIFESTS += [ |
|
11
|
11
|
EXPORTS.torproject += ["TorService.h"]
|
|
12
|
12
|
|
|
13
|
13
|
XPCSHELL_TESTS_MANIFESTS += ["test/xpcshell/xpcshell.toml"]
|
|
|
14
|
+
|
|
|
15
|
+MOZ_SRC_FILES += ["OxidationAdapters.sys.mjs", "OxidizedControlPort.sys.mjs"] |
toolkit/components/tor-integration/test/xpcshell/head.js
| ... |
... |
@@ -13,7 +13,7 @@ class ControlPortServer { |
|
13
|
13
|
#ipcFile;
|
|
14
|
14
|
#protocol;
|
|
15
|
15
|
|
|
16
|
|
- constructor(protocol, listener) {
|
|
|
16
|
+ constructor(protocol) {
|
|
17
|
17
|
this.#server = Cc["@mozilla.org/network/server-socket;1"].createInstance(
|
|
18
|
18
|
Ci.nsIServerSocket
|
|
19
|
19
|
);
|
| ... |
... |
@@ -35,19 +35,23 @@ class ControlPortServer { |
|
35
|
35
|
return;
|
|
36
|
36
|
}
|
|
37
|
37
|
this.#protocol = protocol;
|
|
|
38
|
+ }
|
|
38
|
39
|
|
|
|
40
|
+ listenOnce() {
|
|
39
|
41
|
const address =
|
|
40
|
|
- protocol === "tcp"
|
|
|
42
|
+ this.#protocol === "tcp"
|
|
41
|
43
|
? `localhost:${this.#server.port}`
|
|
42
|
44
|
: this.#ipcFile.path;
|
|
43
|
|
- this.#server.asyncListen({
|
|
44
|
|
- onSocketAccepted(_socket, transport) {
|
|
45
|
|
- info(`Got a new connection on ${address}.`);
|
|
46
|
|
- listener(new Transport(transport));
|
|
47
|
|
- },
|
|
48
|
|
- onStopListening() {
|
|
49
|
|
- info(`Stopped listening on ${address}.`);
|
|
50
|
|
- },
|
|
|
45
|
+ return new Promise(resolve => {
|
|
|
46
|
+ this.#server.asyncListen({
|
|
|
47
|
+ onSocketAccepted(_socket, transport) {
|
|
|
48
|
+ info(`Got a new connection on ${address}.`);
|
|
|
49
|
+ resolve(new Transport(transport));
|
|
|
50
|
+ },
|
|
|
51
|
+ onStopListening() {
|
|
|
52
|
+ info(`Stopped listening on ${address}.`);
|
|
|
53
|
+ },
|
|
|
54
|
+ });
|
|
51
|
55
|
});
|
|
52
|
56
|
}
|
|
53
|
57
|
|
| ... |
... |
@@ -73,6 +77,7 @@ class ControlPortServer { |
|
73
|
77
|
this.#server.close();
|
|
74
|
78
|
if (this.#ipcFile) {
|
|
75
|
79
|
this.#ipcFile.remove(false);
|
|
|
80
|
+ this.#ipcFile = null;
|
|
76
|
81
|
}
|
|
77
|
82
|
}
|
|
78
|
83
|
}
|
| ... |
... |
@@ -111,11 +116,13 @@ class Transport { |
|
111
|
116
|
try {
|
|
112
|
117
|
available = this.#scriptableInputStream.available();
|
|
113
|
118
|
} catch (e) {
|
|
114
|
|
- reject(e);
|
|
115
|
|
- return;
|
|
|
119
|
+ if (e.result !== Cr?.NS_BASE_STREAM_CLOSED) {
|
|
|
120
|
+ reject(e);
|
|
|
121
|
+ return;
|
|
|
122
|
+ }
|
|
116
|
123
|
}
|
|
117
|
124
|
if (!available) {
|
|
118
|
|
- reject(new Error("Connection closed"));
|
|
|
125
|
+ resolve("");
|
|
119
|
126
|
return;
|
|
120
|
127
|
}
|
|
121
|
128
|
const str = this.#scriptableInputStream.read(available);
|
| ... |
... |
@@ -131,7 +138,7 @@ class Transport { |
|
131
|
138
|
|
|
132
|
139
|
async readLine() {
|
|
133
|
140
|
const updateBuffer = idx => {
|
|
134
|
|
- const line = this.#lineBuffer.substring(0, idx);
|
|
|
141
|
+ const line = this.#lineBuffer.substring(0, idx + 2);
|
|
135
|
142
|
this.#lineBuffer = this.#lineBuffer.substring(idx + 2);
|
|
136
|
143
|
return line;
|
|
137
|
144
|
};
|
| ... |
... |
@@ -140,7 +147,13 @@ class Transport { |
|
140
|
147
|
return updateBuffer(idx);
|
|
141
|
148
|
}
|
|
142
|
149
|
do {
|
|
143
|
|
- this.#lineBuffer += await this.read();
|
|
|
150
|
+ const r = await this.read();
|
|
|
151
|
+ if (!r) {
|
|
|
152
|
+ const line = this.#lineBuffer;
|
|
|
153
|
+ this.#lineBuffer = "";
|
|
|
154
|
+ return line;
|
|
|
155
|
+ }
|
|
|
156
|
+ this.#lineBuffer += r;
|
|
144
|
157
|
idx = this.#lineBuffer.indexOf("\r\n");
|
|
145
|
158
|
} while (idx == -1);
|
|
146
|
159
|
return updateBuffer(idx);
|
| ... |
... |
@@ -172,47 +185,3 @@ class Transport { |
|
172
|
185
|
this.#transport.close(Cr.NS_OK);
|
|
173
|
186
|
}
|
|
174
|
187
|
} |
|
175
|
|
-
|
|
176
|
|
-/**
|
|
177
|
|
- * A wrapper to the XPCOM code we are testing for turning it into async JS.
|
|
178
|
|
- * It can be extended to actually handle async notifications.
|
|
179
|
|
- */
|
|
180
|
|
-class ControlPortClient {
|
|
181
|
|
- #controlPort;
|
|
182
|
|
- constructor(server) {
|
|
183
|
|
- if (server.protocol === "tcp") {
|
|
184
|
|
- this.#controlPort = Services.tor.createControlPort(
|
|
185
|
|
- "localhost",
|
|
186
|
|
- server.port
|
|
187
|
|
- );
|
|
188
|
|
- } else if (server.protocol === "ipc") {
|
|
189
|
|
- this.#controlPort = Services.tor.createControlPortIPC(server.ipcFile);
|
|
190
|
|
- } else {
|
|
191
|
|
- throw new Error("Unknown server protocol");
|
|
192
|
|
- }
|
|
193
|
|
- this.#controlPort.start(this);
|
|
194
|
|
- }
|
|
195
|
|
-
|
|
196
|
|
- sendCommand(command) {
|
|
197
|
|
- const { promise, resolve, reject } = Promise.withResolvers();
|
|
198
|
|
- this.#controlPort.sendCommand(`${command}\r\n`, {
|
|
199
|
|
- onMessage(message) {
|
|
200
|
|
- resolve(message);
|
|
201
|
|
- },
|
|
202
|
|
- onError(error) {
|
|
203
|
|
- reject(new Error(error));
|
|
204
|
|
- },
|
|
205
|
|
- });
|
|
206
|
|
- return promise;
|
|
207
|
|
- }
|
|
208
|
|
-
|
|
209
|
|
- close() {
|
|
210
|
|
- this.#controlPort.close();
|
|
211
|
|
- }
|
|
212
|
|
-
|
|
213
|
|
- onAsyncMessage(_message) {
|
|
214
|
|
- Assert.ok(false, "This test does not use async notifications.");
|
|
215
|
|
- }
|
|
216
|
|
-
|
|
217
|
|
- onClosed() {}
|
|
218
|
|
-} |
toolkit/components/tor-integration/test/xpcshell/test_adapters.js
|
|
1
|
+/* Any copyright is dedicated to the Public Domain.
|
|
|
2
|
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
|
|
|
3
|
+
|
|
|
4
|
+"use strict";
|
|
|
5
|
+
|
|
|
6
|
+const { OxidationAdapters, PromisifiedCallback } = ChromeUtils.importESModule(
|
|
|
7
|
+ "moz-src:///toolkit/components/tor-integration/OxidationAdapters.sys.mjs"
|
|
|
8
|
+);
|
|
|
9
|
+
|
|
|
10
|
+add_task(async function test_callback_happy() {
|
|
|
11
|
+ {
|
|
|
12
|
+ const cb = new PromisifiedCallback();
|
|
|
13
|
+ cb.onReply("");
|
|
|
14
|
+ Assert.strictEqual(await cb.promise, undefined);
|
|
|
15
|
+ }
|
|
|
16
|
+ {
|
|
|
17
|
+ const cb = new PromisifiedCallback();
|
|
|
18
|
+ cb.onReply("1234");
|
|
|
19
|
+ Assert.strictEqual(await cb.promise, 1234);
|
|
|
20
|
+ }
|
|
|
21
|
+ {
|
|
|
22
|
+ const cb = new PromisifiedCallback();
|
|
|
23
|
+ cb.onReply('"1234"');
|
|
|
24
|
+ Assert.strictEqual(await cb.promise, "1234");
|
|
|
25
|
+ }
|
|
|
26
|
+ {
|
|
|
27
|
+ const cb = new PromisifiedCallback();
|
|
|
28
|
+ cb.onReply('"a string"');
|
|
|
29
|
+ Assert.strictEqual(await cb.promise, "a string");
|
|
|
30
|
+ }
|
|
|
31
|
+ {
|
|
|
32
|
+ const cb = new PromisifiedCallback();
|
|
|
33
|
+ cb.onReply('["an", "array"]');
|
|
|
34
|
+ Assert.deepEqual(await cb.promise, ["an", "array"]);
|
|
|
35
|
+ }
|
|
|
36
|
+ {
|
|
|
37
|
+ const cb = new PromisifiedCallback();
|
|
|
38
|
+ cb.onReply('{"an": "object"}');
|
|
|
39
|
+ Assert.deepEqual(await cb.promise, { an: "object" });
|
|
|
40
|
+ }
|
|
|
41
|
+});
|
|
|
42
|
+
|
|
|
43
|
+add_task(async function test_callback_tor_error() {
|
|
|
44
|
+ let hadError = false;
|
|
|
45
|
+ try {
|
|
|
46
|
+ const cb = new PromisifiedCallback();
|
|
|
47
|
+ cb.onTorError(400, "Some error message");
|
|
|
48
|
+ await cb.promise;
|
|
|
49
|
+ } catch (e) {
|
|
|
50
|
+ hadError = true;
|
|
|
51
|
+ Assert.equal(e.code, 400);
|
|
|
52
|
+ Assert.equal(e.message, "Some error message");
|
|
|
53
|
+ }
|
|
|
54
|
+ Assert.ok(hadError, "We did not get an error, but we expected one.");
|
|
|
55
|
+});
|
|
|
56
|
+
|
|
|
57
|
+add_task(async function test_callback_generic_error() {
|
|
|
58
|
+ const message = "A more specific error message, maybe not machine-friendly.";
|
|
|
59
|
+ let hadError = false;
|
|
|
60
|
+ try {
|
|
|
61
|
+ const cb = new PromisifiedCallback();
|
|
|
62
|
+ cb.onGenericError(message);
|
|
|
63
|
+ await cb.promise;
|
|
|
64
|
+ } catch (e) {
|
|
|
65
|
+ hadError = true;
|
|
|
66
|
+ Assert.equal(e.message, message);
|
|
|
67
|
+ }
|
|
|
68
|
+ Assert.ok(hadError, "We did not get an error, but we expected one.");
|
|
|
69
|
+});
|
|
|
70
|
+
|
|
|
71
|
+add_task(function test_adapter_circuit() {
|
|
|
72
|
+ Assert.deepEqual(
|
|
|
73
|
+ OxidationAdapters.convertCircuit({
|
|
|
74
|
+ id: "123",
|
|
|
75
|
+ path: [
|
|
|
76
|
+ [1, 2, 3],
|
|
|
77
|
+ [4, 5, 6],
|
|
|
78
|
+ [10, 16, 32],
|
|
|
79
|
+ ],
|
|
|
80
|
+ }),
|
|
|
81
|
+ {
|
|
|
82
|
+ id: "123",
|
|
|
83
|
+ nodes: ["010203", "040506", "0a1020"],
|
|
|
84
|
+ }
|
|
|
85
|
+ );
|
|
|
86
|
+
|
|
|
87
|
+ Assert.deepEqual(
|
|
|
88
|
+ OxidationAdapters.convertCircuit({
|
|
|
89
|
+ id: "abc",
|
|
|
90
|
+ path: [
|
|
|
91
|
+ [1, 2, 3],
|
|
|
92
|
+ [4, 5, 6],
|
|
|
93
|
+ [10, 16, 32],
|
|
|
94
|
+ ],
|
|
|
95
|
+ conflux_id: [0xaa, 0xbb, 0xcc, 0xe, 0xf, 1, 2, 3],
|
|
|
96
|
+ }),
|
|
|
97
|
+ {
|
|
|
98
|
+ id: "abc",
|
|
|
99
|
+ nodes: ["010203", "040506", "0a1020"],
|
|
|
100
|
+ confluxId: "aabbcc0e0f010203",
|
|
|
101
|
+ }
|
|
|
102
|
+ );
|
|
|
103
|
+});
|
|
|
104
|
+
|
|
|
105
|
+add_task(function test_adapter_bootstrap_phase() {
|
|
|
106
|
+ Assert.deepEqual(
|
|
|
107
|
+ OxidationAdapters.convertBootstrapPhase({
|
|
|
108
|
+ severity: "WARN",
|
|
|
109
|
+ should_warn: true,
|
|
|
110
|
+ progress: 25,
|
|
|
111
|
+ tag: "orconn",
|
|
|
112
|
+ summary: "Connection to an onion router",
|
|
|
113
|
+ reason: "No route to host",
|
|
|
114
|
+ }),
|
|
|
115
|
+ {
|
|
|
116
|
+ TYPE: "WARN",
|
|
|
117
|
+ RECOMMENDATION: "warn",
|
|
|
118
|
+ PROGRESS: 25,
|
|
|
119
|
+ TAG: "orconn",
|
|
|
120
|
+ SUMMARY: "Connection to an onion router",
|
|
|
121
|
+ REASON: "No route to host",
|
|
|
122
|
+ }
|
|
|
123
|
+ );
|
|
|
124
|
+
|
|
|
125
|
+ Assert.deepEqual(
|
|
|
126
|
+ OxidationAdapters.convertBootstrapPhase({
|
|
|
127
|
+ severity: "NOTICE",
|
|
|
128
|
+ should_warn: false,
|
|
|
129
|
+ progress: 75,
|
|
|
130
|
+ tag: "loading_descriptors",
|
|
|
131
|
+ summary: "Loading relay descriptors",
|
|
|
132
|
+ }),
|
|
|
133
|
+ {
|
|
|
134
|
+ TYPE: "NOTICE",
|
|
|
135
|
+ RECOMMENDATION: "ignore",
|
|
|
136
|
+ PROGRESS: 75,
|
|
|
137
|
+ TAG: "loading_descriptors",
|
|
|
138
|
+ SUMMARY: "Loading relay descriptors",
|
|
|
139
|
+ }
|
|
|
140
|
+ );
|
|
|
141
|
+});
|
|
|
142
|
+
|
|
|
143
|
+add_task(function test_adapter_bridge() {
|
|
|
144
|
+ Assert.deepEqual(
|
|
|
145
|
+ OxidationAdapters.convertBridge({ address: "192.168.1.3:443" }),
|
|
|
146
|
+ {
|
|
|
147
|
+ transport: "vanilla",
|
|
|
148
|
+ addr: "192.168.1.3:443",
|
|
|
149
|
+ }
|
|
|
150
|
+ );
|
|
|
151
|
+
|
|
|
152
|
+ Assert.deepEqual(
|
|
|
153
|
+ OxidationAdapters.convertBridge({ address: "[2001:dead::beef]:9010" }),
|
|
|
154
|
+ {
|
|
|
155
|
+ transport: "vanilla",
|
|
|
156
|
+ addr: "[2001:dead::beef]:9010",
|
|
|
157
|
+ }
|
|
|
158
|
+ );
|
|
|
159
|
+
|
|
|
160
|
+ Assert.deepEqual(
|
|
|
161
|
+ OxidationAdapters.convertBridge({
|
|
|
162
|
+ transport: "meek",
|
|
|
163
|
+ address: "192.168.1.3:443",
|
|
|
164
|
+ }),
|
|
|
165
|
+ {
|
|
|
166
|
+ transport: "meek",
|
|
|
167
|
+ addr: "192.168.1.3:443",
|
|
|
168
|
+ }
|
|
|
169
|
+ );
|
|
|
170
|
+
|
|
|
171
|
+ Assert.deepEqual(
|
|
|
172
|
+ OxidationAdapters.convertBridge({
|
|
|
173
|
+ transport: "meek",
|
|
|
174
|
+ address: "192.168.1.3:443",
|
|
|
175
|
+ args: null,
|
|
|
176
|
+ }),
|
|
|
177
|
+ {
|
|
|
178
|
+ transport: "meek",
|
|
|
179
|
+ addr: "192.168.1.3:443",
|
|
|
180
|
+ }
|
|
|
181
|
+ );
|
|
|
182
|
+
|
|
|
183
|
+ Assert.deepEqual(
|
|
|
184
|
+ OxidationAdapters.convertBridge({
|
|
|
185
|
+ transport: "meek",
|
|
|
186
|
+ address: "192.168.1.3:443",
|
|
|
187
|
+ args: "",
|
|
|
188
|
+ }),
|
|
|
189
|
+ {
|
|
|
190
|
+ transport: "meek",
|
|
|
191
|
+ addr: "192.168.1.3:443",
|
|
|
192
|
+ }
|
|
|
193
|
+ );
|
|
|
194
|
+
|
|
|
195
|
+ Assert.deepEqual(
|
|
|
196
|
+ OxidationAdapters.convertBridge({
|
|
|
197
|
+ transport: "meek",
|
|
|
198
|
+ address: "192.168.1.3:443",
|
|
|
199
|
+ fingerprint: null,
|
|
|
200
|
+ }),
|
|
|
201
|
+ {
|
|
|
202
|
+ transport: "meek",
|
|
|
203
|
+ addr: "192.168.1.3:443",
|
|
|
204
|
+ }
|
|
|
205
|
+ );
|
|
|
206
|
+
|
|
|
207
|
+ Assert.deepEqual(
|
|
|
208
|
+ OxidationAdapters.convertBridge({
|
|
|
209
|
+ transport: "snowflake",
|
|
|
210
|
+ address: "192.168.1.4:443",
|
|
|
211
|
+ args: "some=param another=one",
|
|
|
212
|
+ }),
|
|
|
213
|
+ {
|
|
|
214
|
+ transport: "snowflake",
|
|
|
215
|
+ addr: "192.168.1.4:443",
|
|
|
216
|
+ args: "some=param another=one",
|
|
|
217
|
+ }
|
|
|
218
|
+ );
|
|
|
219
|
+
|
|
|
220
|
+ Assert.deepEqual(
|
|
|
221
|
+ OxidationAdapters.convertBridge({
|
|
|
222
|
+ transport: "obfs4",
|
|
|
223
|
+ address: "192.168.1.5:443",
|
|
|
224
|
+ fingerprint: "010203cafe",
|
|
|
225
|
+ args: "some=param another=one",
|
|
|
226
|
+ }),
|
|
|
227
|
+ {
|
|
|
228
|
+ transport: "obfs4",
|
|
|
229
|
+ addr: "192.168.1.5:443",
|
|
|
230
|
+ id: "010203cafe",
|
|
|
231
|
+ args: "some=param another=one",
|
|
|
232
|
+ }
|
|
|
233
|
+ );
|
|
|
234
|
+
|
|
|
235
|
+ Assert.deepEqual(
|
|
|
236
|
+ OxidationAdapters.convertBridge({
|
|
|
237
|
+ transport: "obfs4",
|
|
|
238
|
+ address: "192.168.1.5:443",
|
|
|
239
|
+ fingerprint: "010203cafe",
|
|
|
240
|
+ }),
|
|
|
241
|
+ {
|
|
|
242
|
+ transport: "obfs4",
|
|
|
243
|
+ addr: "192.168.1.5:443",
|
|
|
244
|
+ id: "010203cafe",
|
|
|
245
|
+ }
|
|
|
246
|
+ );
|
|
|
247
|
+});
|
|
|
248
|
+
|
|
|
249
|
+add_task(function test_adapter_pluggable_transports() {
|
|
|
250
|
+ Assert.deepEqual(OxidationAdapters.convertPluggableTransports([]), []);
|
|
|
251
|
+
|
|
|
252
|
+ Assert.deepEqual(
|
|
|
253
|
+ OxidationAdapters.convertPluggableTransports([
|
|
|
254
|
+ {
|
|
|
255
|
+ transports: ["obfs4", "meek_lite"],
|
|
|
256
|
+ type: "exec",
|
|
|
257
|
+ pathToBinary: "TorBrowser/Tor/PluggableTransports/lyrebird",
|
|
|
258
|
+ },
|
|
|
259
|
+ {
|
|
|
260
|
+ transports: ["snowflake"],
|
|
|
261
|
+ type: "exec",
|
|
|
262
|
+ pathToBinary: "TorBrowser/Tor/PluggableTransports/lyrebird",
|
|
|
263
|
+ options: "some=option",
|
|
|
264
|
+ ip: null,
|
|
|
265
|
+ port: null,
|
|
|
266
|
+ },
|
|
|
267
|
+ {
|
|
|
268
|
+ transports: ["conjure"],
|
|
|
269
|
+ type: "exec",
|
|
|
270
|
+ pathToBinary: "TorBrowser/Tor/PluggableTransports/conjure-client",
|
|
|
271
|
+ // Ignored even when not null.
|
|
|
272
|
+ ip: "10.0.2.2",
|
|
|
273
|
+ port: 80,
|
|
|
274
|
+ },
|
|
|
275
|
+ {
|
|
|
276
|
+ transports: ["proxy1"],
|
|
|
277
|
+ type: "socks4",
|
|
|
278
|
+ pathToBinary: null,
|
|
|
279
|
+ ip: "10.0.2.2",
|
|
|
280
|
+ port: 80,
|
|
|
281
|
+ },
|
|
|
282
|
+ {
|
|
|
283
|
+ transports: ["proxy2"],
|
|
|
284
|
+ type: "socks5",
|
|
|
285
|
+ pathToBinary: "an/ignored/binary",
|
|
|
286
|
+ ip: "[::1]",
|
|
|
287
|
+ port: 80,
|
|
|
288
|
+ },
|
|
|
289
|
+ ]),
|
|
|
290
|
+ [
|
|
|
291
|
+ {
|
|
|
292
|
+ transports: ["obfs4", "meek_lite"],
|
|
|
293
|
+ type: "exec",
|
|
|
294
|
+ pathToBinary: "TorBrowser/Tor/PluggableTransports/lyrebird",
|
|
|
295
|
+ options: "",
|
|
|
296
|
+ },
|
|
|
297
|
+ {
|
|
|
298
|
+ transports: ["snowflake"],
|
|
|
299
|
+ type: "exec",
|
|
|
300
|
+ pathToBinary: "TorBrowser/Tor/PluggableTransports/lyrebird",
|
|
|
301
|
+ options: "some=option",
|
|
|
302
|
+ },
|
|
|
303
|
+ {
|
|
|
304
|
+ transports: ["conjure"],
|
|
|
305
|
+ type: "exec",
|
|
|
306
|
+ pathToBinary: "TorBrowser/Tor/PluggableTransports/conjure-client",
|
|
|
307
|
+ options: "",
|
|
|
308
|
+ },
|
|
|
309
|
+ {
|
|
|
310
|
+ transports: ["proxy1"],
|
|
|
311
|
+ type: "socks4",
|
|
|
312
|
+ ip: "10.0.2.2",
|
|
|
313
|
+ port: 80,
|
|
|
314
|
+ },
|
|
|
315
|
+ {
|
|
|
316
|
+ transports: ["proxy2"],
|
|
|
317
|
+ type: "socks5",
|
|
|
318
|
+ ip: "[::1]",
|
|
|
319
|
+ port: 80,
|
|
|
320
|
+ },
|
|
|
321
|
+ ]
|
|
|
322
|
+ );
|
|
|
323
|
+});
|
|
|
324
|
+
|
|
|
325
|
+add_task(function test_adapter_onion_keys() {
|
|
|
326
|
+ const address = "PG6MMJIYJMCRSSLVYKFWNNTLARU7P5SVN6Y2YMMJU6NUBXNDF4PSCRYD";
|
|
|
327
|
+ const keyType = "x25519";
|
|
|
328
|
+ const keyBlob = "abase64key";
|
|
|
329
|
+
|
|
|
330
|
+ Assert.deepEqual(OxidationAdapters.convertOnionKeys([]), []);
|
|
|
331
|
+
|
|
|
332
|
+ Assert.deepEqual(
|
|
|
333
|
+ OxidationAdapters.convertOnionKeys([
|
|
|
334
|
+ {
|
|
|
335
|
+ address,
|
|
|
336
|
+ key_type: keyType,
|
|
|
337
|
+ key_blob: keyBlob,
|
|
|
338
|
+ is_permanent: false,
|
|
|
339
|
+ },
|
|
|
340
|
+ {
|
|
|
341
|
+ address,
|
|
|
342
|
+ key_type: keyType,
|
|
|
343
|
+ key_blob: keyBlob,
|
|
|
344
|
+ is_permanent: true,
|
|
|
345
|
+ },
|
|
|
346
|
+ ]),
|
|
|
347
|
+ [
|
|
|
348
|
+ {
|
|
|
349
|
+ address,
|
|
|
350
|
+ keyType,
|
|
|
351
|
+ keyBlob,
|
|
|
352
|
+ flags: [],
|
|
|
353
|
+ },
|
|
|
354
|
+ {
|
|
|
355
|
+ address,
|
|
|
356
|
+ keyType,
|
|
|
357
|
+ keyBlob,
|
|
|
358
|
+ flags: ["Permanent"],
|
|
|
359
|
+ },
|
|
|
360
|
+ ]
|
|
|
361
|
+ );
|
|
|
362
|
+}); |
toolkit/components/tor-integration/test/xpcshell/test_control_port.js
| ... |
... |
@@ -3,170 +3,935 @@ |
|
3
|
3
|
|
|
4
|
4
|
"use strict";
|
|
5
|
5
|
|
|
|
6
|
+const { OxidizedControlPort } = ChromeUtils.importESModule(
|
|
|
7
|
+ "moz-src:///toolkit/components/tor-integration/OxidizedControlPort.sys.mjs"
|
|
|
8
|
+);
|
|
|
9
|
+
|
|
|
10
|
+/**
|
|
|
11
|
+ * Mock server to handle control port commands.
|
|
|
12
|
+ */
|
|
|
13
|
+class MockServer {
|
|
|
14
|
+ #transport;
|
|
|
15
|
+ noPassword = false;
|
|
|
16
|
+ listeners = [];
|
|
|
17
|
+ conf = new Map();
|
|
|
18
|
+ onionAuth = new Map();
|
|
|
19
|
+ events = [];
|
|
|
20
|
+
|
|
|
21
|
+ constructor(transport) {
|
|
|
22
|
+ this.#transport = transport;
|
|
|
23
|
+ }
|
|
|
24
|
+
|
|
|
25
|
+ async start() {
|
|
|
26
|
+ info("Starting a mock server");
|
|
|
27
|
+ let line;
|
|
|
28
|
+ while ((line = await this.#transport.readLine())) {
|
|
|
29
|
+ if (line.endsWith("\r\n")) {
|
|
|
30
|
+ line = line.slice(0, -2);
|
|
|
31
|
+ }
|
|
|
32
|
+ const spaceIdx = line.indexOf(" ");
|
|
|
33
|
+ const command = spaceIdx !== -1 ? line.slice(0, spaceIdx) : line;
|
|
|
34
|
+ const args = spaceIdx !== -1 ? line.slice(spaceIdx + 1) : "";
|
|
|
35
|
+ switch (command.toUpperCase()) {
|
|
|
36
|
+ case "AUTHENTICATE":
|
|
|
37
|
+ await this.#authenticate(args);
|
|
|
38
|
+ break;
|
|
|
39
|
+ case "GETINFO":
|
|
|
40
|
+ await this.#getInfo(args);
|
|
|
41
|
+ break;
|
|
|
42
|
+ case "GETCONF":
|
|
|
43
|
+ await this.#getConf(args);
|
|
|
44
|
+ break;
|
|
|
45
|
+ case "SETCONF":
|
|
|
46
|
+ await this.#setConf(args);
|
|
|
47
|
+ break;
|
|
|
48
|
+ case "ONION_CLIENT_AUTH_VIEW":
|
|
|
49
|
+ await this.#onionView();
|
|
|
50
|
+ break;
|
|
|
51
|
+ case "ONION_CLIENT_AUTH_ADD":
|
|
|
52
|
+ await this.#onionAdd(args);
|
|
|
53
|
+ break;
|
|
|
54
|
+ case "ONION_CLIENT_AUTH_REMOVE":
|
|
|
55
|
+ await this.#onionRemove(args);
|
|
|
56
|
+ break;
|
|
|
57
|
+ case "SETEVENTS":
|
|
|
58
|
+ await this.#setEvents(args);
|
|
|
59
|
+ break;
|
|
|
60
|
+ case "SAVECONF":
|
|
|
61
|
+ case "TAKEOWNERSHIP":
|
|
|
62
|
+ case "RESETCONF":
|
|
|
63
|
+ case "SIGNAL":
|
|
|
64
|
+ await this.write("250 OK\r\n");
|
|
|
65
|
+ break;
|
|
|
66
|
+ default:
|
|
|
67
|
+ await this.write(`510 Unrecognized command "${command}"\r\n`);
|
|
|
68
|
+ break;
|
|
|
69
|
+ }
|
|
|
70
|
+ }
|
|
|
71
|
+ }
|
|
|
72
|
+
|
|
|
73
|
+ async write(str) {
|
|
|
74
|
+ await this.#transport.write(str);
|
|
|
75
|
+ }
|
|
|
76
|
+
|
|
|
77
|
+ close() {
|
|
|
78
|
+ this.#transport.close();
|
|
|
79
|
+ }
|
|
|
80
|
+
|
|
|
81
|
+ async #authenticate(args) {
|
|
|
82
|
+ if (args == "01234567" || (this.noPassword && !args)) {
|
|
|
83
|
+ await this.write("250 OK\r\n");
|
|
|
84
|
+ return;
|
|
|
85
|
+ }
|
|
|
86
|
+ await this.write(`515 Authentication failed: wrong password ${args}\r\n`);
|
|
|
87
|
+ this.close();
|
|
|
88
|
+ }
|
|
|
89
|
+
|
|
|
90
|
+ async #getInfo(args) {
|
|
|
91
|
+ // We support only a single keyword in this mock server.
|
|
|
92
|
+ if (args === "status/bootstrap-phase") {
|
|
|
93
|
+ await this.#bootstrapPhase();
|
|
|
94
|
+ } else if (args.startsWith("ns/id/")) {
|
|
|
95
|
+ await this.#nodeInfo(args.substring(6));
|
|
|
96
|
+ } else if (args.startsWith("ip-to-country/")) {
|
|
|
97
|
+ await this.#ipToCountry(args.substring("ip-to-country/".length));
|
|
|
98
|
+ } else if (args === "net/listeners/socks") {
|
|
|
99
|
+ await this.#socksListeners();
|
|
|
100
|
+ } else if (args === "circuit-status") {
|
|
|
101
|
+ await this.#circuitStatus();
|
|
|
102
|
+ } else {
|
|
|
103
|
+ await this.write(`552 Unrecognized key "${args}"\r\n`);
|
|
|
104
|
+ }
|
|
|
105
|
+ }
|
|
|
106
|
+
|
|
|
107
|
+ async #bootstrapPhase() {
|
|
|
108
|
+ await this.write(
|
|
|
109
|
+ '250-status/bootstrap-phase=NOTICE BOOTSTRAP PROGRESS=100 TAG=done SUMMARY="Done"\r\n'
|
|
|
110
|
+ );
|
|
|
111
|
+ await this.write("250 OK\r\n");
|
|
|
112
|
+ }
|
|
|
113
|
+
|
|
|
114
|
+ async #nodeInfo(id) {
|
|
|
115
|
+ const reply =
|
|
|
116
|
+ `250+ns/id/${id}=\r\n` +
|
|
|
117
|
+ "r nickname RGiAFtNSR33prk7Csp+CQCVNgOg rLB4YR4Xkky0sutW2EvMJKmWj/y 2038-01-01 00:00:00 12.34.56.78 9001 0\r\n" +
|
|
|
118
|
+ "a [2001:0000:123:4567::89ab]:9001\r\n" +
|
|
|
119
|
+ "s Fast Guard Running Stable V2Dir Valid\r\n" +
|
|
|
120
|
+ "w Bandwidth=5000\r\n" +
|
|
|
121
|
+ ".\r\n" +
|
|
|
122
|
+ "250 OK\r\n";
|
|
|
123
|
+ await this.write(reply);
|
|
|
124
|
+ }
|
|
|
125
|
+
|
|
|
126
|
+ async #ipToCountry(ip) {
|
|
|
127
|
+ const reply = code =>
|
|
|
128
|
+ this.write(`250-ip-to-country/${ip}=${code}\r\n250 OK\r\n`);
|
|
|
129
|
+ if (ip === "1.2.3.4") {
|
|
|
130
|
+ await reply("au");
|
|
|
131
|
+ } else if (ip === "12.34.56.78") {
|
|
|
132
|
+ await reply("US");
|
|
|
133
|
+ } else if (ip === "127.0.0.1") {
|
|
|
134
|
+ // tor would say ??, but we use it to trigger a parsing error.
|
|
|
135
|
+ await reply("invalid");
|
|
|
136
|
+ } else {
|
|
|
137
|
+ await reply("??");
|
|
|
138
|
+ }
|
|
|
139
|
+ }
|
|
|
140
|
+
|
|
|
141
|
+ async #socksListeners() {
|
|
|
142
|
+ await this.write(
|
|
|
143
|
+ `250-net/listeners/socks=${this.listeners.join(" ")}\r\n250 OK\r\n`
|
|
|
144
|
+ );
|
|
|
145
|
+ }
|
|
|
146
|
+
|
|
|
147
|
+ async #circuitStatus() {
|
|
|
148
|
+ const reply =
|
|
|
149
|
+ "250+circuit-status=\r\n" +
|
|
|
150
|
+ "67 BUILT $1111111111111111111111111111111111111111~R1,$2222222222222222222222222222222222222222~Re2,$3333333333333333333333333333333333333333~Relay3 CONFLUX_ID=cccccccccccccccccccccccccccccccc\r\n" +
|
|
|
151
|
+ "68 BUILT $4444444444444444444444444444444444444444~Rel4,$5555555555555555555555555555555555555555~Rela5,$3333333333333333333333333333333333333333~Relay3 CONFLUX_ID=cccccccccccccccccccccccccccccccc\r\n" +
|
|
|
152
|
+ "6fF BUILT $1111111111111111111111111111aAbBcCdDeEfF,$7777777777777777777777777777777777777777,$8888888888888888888888888888888888888888\r\n" +
|
|
|
153
|
+ "111 OTHER_STATUS SHOULD=BE_IGNORED\r\n" +
|
|
|
154
|
+ ".\r\n" +
|
|
|
155
|
+ "250 OK\r\n";
|
|
|
156
|
+ await this.write(reply);
|
|
|
157
|
+ }
|
|
|
158
|
+
|
|
|
159
|
+ async #getConf(key) {
|
|
|
160
|
+ switch (key.toLowerCase()) {
|
|
|
161
|
+ case "bridge":
|
|
|
162
|
+ await this.#getBridges();
|
|
|
163
|
+ break;
|
|
|
164
|
+ case "clienttransportplugin":
|
|
|
165
|
+ this.#getClientTransportPlugin();
|
|
|
166
|
+ break;
|
|
|
167
|
+ default:
|
|
|
168
|
+ await this.write(`552 Unrecognized configuration key "${key}"\r\n`);
|
|
|
169
|
+ }
|
|
|
170
|
+ }
|
|
|
171
|
+
|
|
|
172
|
+ async #getBridges() {
|
|
|
173
|
+ const reply =
|
|
|
174
|
+ "250-Bridge=obfs4 1.2.3.4:443 1111111111111111111111111111111111111111 cert=IiE5kF0SGOWNDF2nN2RQA5iMszRJdvHA3/6JNr0vPZRO5ra2GslNPT46c1Hkj4O5O0a8/g iat-mode=0\r\n" +
|
|
|
175
|
+ "250-Bridge=obfs4 123.4.56.78:80 2222222222222222222222222222222222222222 cert=tTo5rWWGawTCMsEHM3DKVPzFni8d0BZib6xtcPVk6F2spWavYyZ5FXqlsaq8exih/6n+UD iat-mode=1\r\n" +
|
|
|
176
|
+ "250-Bridge=snowflake 5.6.7.8:443\r\n" +
|
|
|
177
|
+ "250-Bridge=snowflake 12.3.4.5:443 some=param\r\n" +
|
|
|
178
|
+ "250 Bridge=123.45.6.78:9050\r\n";
|
|
|
179
|
+ await this.write(reply);
|
|
|
180
|
+ }
|
|
|
181
|
+
|
|
|
182
|
+ async #getClientTransportPlugin() {
|
|
|
183
|
+ const reply =
|
|
|
184
|
+ "250-ClientTransportPlugin=meek_lite,obfs2,obfs3,obfs4,scramblesuit,webtunnel exec ./TorBrowser/Tor/PluggableTransports/lyrebird\r\n" +
|
|
|
185
|
+ "250-ClientTransportPlugin=snowflake exec .\\TorBrowser\\Tor\\PluggableTransports\\lyrebird\r\n" +
|
|
|
186
|
+ "250-ClientTransportPlugin=conjure exec ./TorBrowser/Tor/PluggableTransports/conjure-client -registerURL https://registration.refraction.network/api\r\n" +
|
|
|
187
|
+ "250-ClientTransportPlugin=pt1 socks4 127.0.0.1:9052\r\n" +
|
|
|
188
|
+ "250 ClientTransportPlugin=pt2 socks5 [::1]:9053\r\n";
|
|
|
189
|
+ await this.write(reply);
|
|
|
190
|
+ }
|
|
|
191
|
+
|
|
|
192
|
+ async #setConf(args) {
|
|
|
193
|
+ // Notice: this does not handle escaped quotes.
|
|
|
194
|
+ const re = /(\w+)(?:=(\d+)|="([^"]*)")?/g;
|
|
|
195
|
+ const conf = new Map();
|
|
|
196
|
+ for (const m of args.matchAll(re)) {
|
|
|
197
|
+ const key = m[1];
|
|
|
198
|
+ // Special key we handled differently to simulate a failure.
|
|
|
199
|
+ if (key.toUpperCase() === "INVALID") {
|
|
|
200
|
+ await this.write(
|
|
|
201
|
+ `552 Unrecognized option: Unknown option '${key}'. Failing.\r\n`
|
|
|
202
|
+ );
|
|
|
203
|
+ return;
|
|
|
204
|
+ }
|
|
|
205
|
+ const intVal = m[2] !== undefined ? parseInt(m[2]) : undefined;
|
|
|
206
|
+ const value = intVal ?? m[3] ?? null;
|
|
|
207
|
+ const existing = conf.get(key);
|
|
|
208
|
+ if (existing === undefined) {
|
|
|
209
|
+ conf.set(key, value);
|
|
|
210
|
+ } else if (Array.isArray(existing)) {
|
|
|
211
|
+ existing.push(value);
|
|
|
212
|
+ } else {
|
|
|
213
|
+ conf.set(key, [existing, value]);
|
|
|
214
|
+ }
|
|
|
215
|
+ }
|
|
|
216
|
+ conf.forEach((v, k) => this.conf.set(k, v));
|
|
|
217
|
+ await this.write("250 OK\r\n");
|
|
|
218
|
+ }
|
|
|
219
|
+
|
|
|
220
|
+ async #onionView() {
|
|
|
221
|
+ let reply = "250-ONION_CLIENT_AUTH_VIEW\r\n";
|
|
|
222
|
+ for (const [address, info] of this.onionAuth) {
|
|
|
223
|
+ reply += `250-CLIENT ${address} ${info.key} Flags=${info.flags}\r\n`;
|
|
|
224
|
+ }
|
|
|
225
|
+ reply += "250 OK\r\n";
|
|
|
226
|
+ await this.write(reply);
|
|
|
227
|
+ }
|
|
|
228
|
+
|
|
|
229
|
+ async #onionAdd(args) {
|
|
|
230
|
+ args = args.split(" ");
|
|
|
231
|
+ const address = args.shift();
|
|
|
232
|
+ const info = { key: args.shift() };
|
|
|
233
|
+ while (args.length) {
|
|
|
234
|
+ const arg = args.shift();
|
|
|
235
|
+ if (arg.startsWith("Flags=")) {
|
|
|
236
|
+ info.flags = arg.substring(6);
|
|
|
237
|
+ }
|
|
|
238
|
+ }
|
|
|
239
|
+ this.onionAuth.set(address, info);
|
|
|
240
|
+ await this.write("250 OK\r\n");
|
|
|
241
|
+ }
|
|
|
242
|
+
|
|
|
243
|
+ async #onionRemove(args) {
|
|
|
244
|
+ if (this.onionAuth.delete(args)) {
|
|
|
245
|
+ await this.write("250 OK\r\n");
|
|
|
246
|
+ } else {
|
|
|
247
|
+ await this.write(`251 No credentials for "args"\r\n`);
|
|
|
248
|
+ }
|
|
|
249
|
+ }
|
|
|
250
|
+
|
|
|
251
|
+ async #setEvents(args) {
|
|
|
252
|
+ this.events = args.split(" ");
|
|
|
253
|
+ await this.write("250 OK\r\n");
|
|
|
254
|
+ }
|
|
|
255
|
+}
|
|
|
256
|
+
|
|
6
|
257
|
async function runTest(func) {
|
|
7
|
|
- info(`Running ${func.name} with TCP`);
|
|
8
|
|
- await func("tcp");
|
|
|
258
|
+ const run = async (server, client) => {
|
|
|
259
|
+ try {
|
|
|
260
|
+ const serverTransport = await server.listenOnce();
|
|
|
261
|
+ const controlServer = new MockServer(serverTransport);
|
|
|
262
|
+ const serverLoopDone = controlServer.start();
|
|
|
263
|
+
|
|
|
264
|
+ try {
|
|
|
265
|
+ await func(controlServer, client);
|
|
|
266
|
+ } finally {
|
|
|
267
|
+ try {
|
|
|
268
|
+ serverTransport.close();
|
|
|
269
|
+ } catch (e) {
|
|
|
270
|
+ info(`Failed to close the server-side transport: ${e}`);
|
|
|
271
|
+ }
|
|
|
272
|
+ try {
|
|
|
273
|
+ await serverLoopDone;
|
|
|
274
|
+ } catch (e) {
|
|
|
275
|
+ info(`Exception on the server loop: ${e}`);
|
|
|
276
|
+ }
|
|
|
277
|
+ }
|
|
|
278
|
+ } finally {
|
|
|
279
|
+ try {
|
|
|
280
|
+ client?.close();
|
|
|
281
|
+ } catch (e) {
|
|
|
282
|
+ info(`Failed to close the client: ${e}`);
|
|
|
283
|
+ }
|
|
|
284
|
+ try {
|
|
|
285
|
+ server?.close();
|
|
|
286
|
+ } catch (e) {
|
|
|
287
|
+ info(`Failed to close the server: ${e}`);
|
|
|
288
|
+ }
|
|
|
289
|
+ }
|
|
|
290
|
+ };
|
|
|
291
|
+
|
|
|
292
|
+ {
|
|
|
293
|
+ info("Running with TCP");
|
|
|
294
|
+ const server = new ControlPortServer("tcp");
|
|
|
295
|
+ const client = OxidizedControlPort.fromSocketAddress(
|
|
|
296
|
+ "127.0.0.1",
|
|
|
297
|
+ server.port
|
|
|
298
|
+ );
|
|
|
299
|
+ await run(server, client);
|
|
|
300
|
+ }
|
|
|
301
|
+
|
|
9
|
302
|
if (IPC_SUPPORTED) {
|
|
10
|
|
- info(`Running ${func.name} with Unix-domain sockets`);
|
|
11
|
|
- await func("ipc");
|
|
|
303
|
+ info("Running with Unix-domain sockets.");
|
|
|
304
|
+ const server = new ControlPortServer("ipc");
|
|
|
305
|
+ const client = OxidizedControlPort.fromIpcFile(server.ipcFile);
|
|
|
306
|
+ await run(server, client);
|
|
12
|
307
|
}
|
|
13
|
308
|
}
|
|
14
|
309
|
|
|
15
|
|
-add_task(async function test_simple() {
|
|
16
|
|
- await runTest(async function testSimple(protocol) {
|
|
17
|
|
- const server = new ControlPortServer(protocol, async transport => {
|
|
18
|
|
- const s = await transport.readLine();
|
|
19
|
|
- Assert.equal(s, "TEST");
|
|
20
|
|
- await transport.write("250 OK\r\n");
|
|
21
|
|
- transport.close();
|
|
22
|
|
- });
|
|
|
310
|
+add_task(async function test_authenticate_happy() {
|
|
|
311
|
+ await runTest(async (_server, client) => {
|
|
|
312
|
+ try {
|
|
|
313
|
+ await client.authenticate([0x01, 0x23, 0x45, 0x67]);
|
|
|
314
|
+ Assert.ok(true, "Authentication succeeded.");
|
|
|
315
|
+ } catch (e) {
|
|
|
316
|
+ Assert.ok(false, `Authenticate failed: ${e.message}.`);
|
|
|
317
|
+ }
|
|
|
318
|
+ });
|
|
|
319
|
+});
|
|
23
|
320
|
|
|
24
|
|
- let cp;
|
|
|
321
|
+add_task(async function test_authenticate_failure() {
|
|
|
322
|
+ await runTest(async (_server, client) => {
|
|
|
323
|
+ let failed = false;
|
|
25
|
324
|
try {
|
|
26
|
|
- cp = new ControlPortClient(server);
|
|
27
|
|
- const reply = await cp.sendCommand("TEST");
|
|
28
|
|
- Assert.equal(reply, "250 OK");
|
|
29
|
|
- } finally {
|
|
30
|
|
- cp?.close();
|
|
31
|
|
- server.close();
|
|
|
325
|
+ await client.authenticate([]);
|
|
|
326
|
+ } catch (e) {
|
|
|
327
|
+ Assert.ok(true, `Authenticate failed as expected: ${e.message}.`);
|
|
|
328
|
+ failed = true;
|
|
|
329
|
+ }
|
|
|
330
|
+ Assert.ok(failed, "Wrong authentication succeeded.");
|
|
|
331
|
+ });
|
|
|
332
|
+
|
|
|
333
|
+ await runTest(async (_server, client) => {
|
|
|
334
|
+ let failed = false;
|
|
|
335
|
+ try {
|
|
|
336
|
+ await client.authenticate([0xde, 0xad, 0xbe, 0xef]);
|
|
|
337
|
+ } catch (e) {
|
|
|
338
|
+ Assert.ok(true, `Authenticate failed as expected: ${e.message}.`);
|
|
|
339
|
+ failed = true;
|
|
32
|
340
|
}
|
|
|
341
|
+ Assert.ok(failed, "Wrong authentication succeeded.");
|
|
33
|
342
|
});
|
|
34
|
343
|
});
|
|
35
|
344
|
|
|
36
|
|
-add_task(async function test_invalidSyntax() {
|
|
37
|
|
- await runTest(async function testInvalidSyntax(protocol) {
|
|
38
|
|
- const server = new ControlPortServer(protocol, async transport => {
|
|
39
|
|
- await transport.read();
|
|
40
|
|
- await transport.write("250|OK\r\n");
|
|
41
|
|
- transport.close();
|
|
42
|
|
- });
|
|
|
345
|
+add_task(async function test_authenticate_no_password() {
|
|
|
346
|
+ await runTest(async (server, client) => {
|
|
|
347
|
+ server.noPassword = true;
|
|
|
348
|
+ try {
|
|
|
349
|
+ await client.authenticate([]);
|
|
|
350
|
+ Assert.ok(true, "Authentication succeeded.");
|
|
|
351
|
+ } catch (e) {
|
|
|
352
|
+ Assert.ok(false, `Authenticate failed: ${e.message}.`);
|
|
|
353
|
+ }
|
|
|
354
|
+ });
|
|
|
355
|
+});
|
|
|
356
|
+
|
|
|
357
|
+add_task(async function test_bootstrap_phase() {
|
|
|
358
|
+ await runTest(async (_server, client) => {
|
|
|
359
|
+ // TODO: Add various phases to the mock server.
|
|
|
360
|
+ let phase = await client.getBootstrapPhase();
|
|
|
361
|
+ Assert.equal(phase.TYPE, "NOTICE");
|
|
|
362
|
+ Assert.equal(phase.PROGRESS, 100);
|
|
|
363
|
+ Assert.equal(phase.TAG, "done");
|
|
|
364
|
+ Assert.equal(phase.SUMMARY, "Done");
|
|
|
365
|
+ });
|
|
|
366
|
+});
|
|
|
367
|
+
|
|
|
368
|
+add_task(async function test_node_address() {
|
|
|
369
|
+ await runTest(async (_server, client) => {
|
|
|
370
|
+ const addresses = await client.getNodeAddresses(
|
|
|
371
|
+ "1111111111111111111111111111111111111111"
|
|
|
372
|
+ );
|
|
|
373
|
+ Assert.equal(addresses.length, 2);
|
|
|
374
|
+ Assert.equal(addresses[0], "12.34.56.78");
|
|
|
375
|
+ Assert.equal(addresses[1], "2001:0:123:4567::89ab");
|
|
|
376
|
+ });
|
|
|
377
|
+});
|
|
|
378
|
+
|
|
|
379
|
+add_task(async function test_ip_country() {
|
|
|
380
|
+ await runTest(async (_server, client) => {
|
|
|
381
|
+ // Test we do not change the case of the code.
|
|
|
382
|
+ Assert.equal(await client.getIPCountry("1.2.3.4"), "au");
|
|
|
383
|
+ Assert.equal(await client.getIPCountry("12.34.56.78"), "US");
|
|
|
384
|
+ Assert.equal(await client.getIPCountry("123.4.56.78"), "??");
|
|
43
|
385
|
|
|
44
|
386
|
let failed = true;
|
|
45
|
|
- let cp;
|
|
46
|
387
|
try {
|
|
47
|
|
- cp = new ControlPortClient(server);
|
|
48
|
|
- await cp.sendCommand("TEST");
|
|
|
388
|
+ // The real tor would not fail, it is a peculiarity of our mock server.
|
|
|
389
|
+ await client.getIPCountry("127.0.0.1");
|
|
|
390
|
+ failed = false;
|
|
49
|
391
|
} catch (e) {
|
|
50
|
|
- Assert.ok(true, `We got the expected failure: ${e.message}`);
|
|
51
|
|
- } finally {
|
|
52
|
|
- try {
|
|
53
|
|
- cp.close();
|
|
54
|
|
- } catch (e) {
|
|
55
|
|
- info(`The control port threw when closing: ${e.message}.`);
|
|
|
392
|
+ Assert.ok(true, `Got the expected failure: ${e.message}`);
|
|
|
393
|
+ }
|
|
|
394
|
+ Assert.ok(failed, "Failed when expected");
|
|
|
395
|
+ });
|
|
|
396
|
+});
|
|
|
397
|
+
|
|
|
398
|
+add_task(async function test_socks_listeners() {
|
|
|
399
|
+ await runTest(async (server, client) => {
|
|
|
400
|
+ // Before bootstrap: no listeners
|
|
|
401
|
+ server.listeners = [];
|
|
|
402
|
+ let listeners = await client.getSocksListeners();
|
|
|
403
|
+ Assert.equal(listeners.length, 0);
|
|
|
404
|
+
|
|
|
405
|
+ // Normal TCP
|
|
|
406
|
+ server.listeners = ['"127.0.0.1:9150"'];
|
|
|
407
|
+ listeners = await client.getSocksListeners();
|
|
|
408
|
+ Assert.deepEqual(listeners, [{ host: "127.0.0.1", port: 9150 }]);
|
|
|
409
|
+
|
|
|
410
|
+ // Unix sockets
|
|
|
411
|
+ server.listeners = ['"unix:/run/user/1000/Tor/socks.socket"'];
|
|
|
412
|
+ listeners = await client.getSocksListeners();
|
|
|
413
|
+ Assert.deepEqual(listeners, [
|
|
|
414
|
+ { ipcPath: "/run/user/1000/Tor/socks.socket" },
|
|
|
415
|
+ ]);
|
|
|
416
|
+
|
|
|
417
|
+ // Multiple
|
|
|
418
|
+ server.listeners = ['"127.0.0.1:9050"', '"127.0.0.1:9150"'];
|
|
|
419
|
+ listeners = await client.getSocksListeners();
|
|
|
420
|
+ Assert.deepEqual(listeners, [
|
|
|
421
|
+ { host: "127.0.0.1", port: 9050 },
|
|
|
422
|
+ { host: "127.0.0.1", port: 9150 },
|
|
|
423
|
+ ]);
|
|
|
424
|
+
|
|
|
425
|
+ // IPv6
|
|
|
426
|
+ server.listeners = ['"[2001:0db8:7000:0000:0000:dead:beef:1234]:9150"'];
|
|
|
427
|
+ listeners = await client.getSocksListeners();
|
|
|
428
|
+ Assert.deepEqual(listeners, [
|
|
|
429
|
+ { host: "2001:db8:7000::dead:beef:1234", port: 9150 },
|
|
|
430
|
+ ]);
|
|
|
431
|
+ });
|
|
|
432
|
+});
|
|
|
433
|
+
|
|
|
434
|
+add_task(async function test_circuits() {
|
|
|
435
|
+ await runTest(async (_server, client) => {
|
|
|
436
|
+ const circs = await client.getCircuits();
|
|
|
437
|
+ Assert.deepEqual(circs, [
|
|
|
438
|
+ {
|
|
|
439
|
+ id: "67",
|
|
|
440
|
+ nodes: [
|
|
|
441
|
+ "1111111111111111111111111111111111111111",
|
|
|
442
|
+ "2222222222222222222222222222222222222222",
|
|
|
443
|
+ "3333333333333333333333333333333333333333",
|
|
|
444
|
+ ],
|
|
|
445
|
+ confluxId: "cccccccccccccccccccccccccccccccc",
|
|
|
446
|
+ },
|
|
|
447
|
+ {
|
|
|
448
|
+ id: "68",
|
|
|
449
|
+ nodes: [
|
|
|
450
|
+ "4444444444444444444444444444444444444444",
|
|
|
451
|
+ "5555555555555555555555555555555555555555",
|
|
|
452
|
+ "3333333333333333333333333333333333333333",
|
|
|
453
|
+ ],
|
|
|
454
|
+ confluxId: "cccccccccccccccccccccccccccccccc",
|
|
|
455
|
+ },
|
|
|
456
|
+ {
|
|
|
457
|
+ id: "6fF",
|
|
|
458
|
+ nodes: [
|
|
|
459
|
+ "1111111111111111111111111111aabbccddeeff",
|
|
|
460
|
+ "7777777777777777777777777777777777777777",
|
|
|
461
|
+ "8888888888888888888888888888888888888888",
|
|
|
462
|
+ ],
|
|
|
463
|
+ },
|
|
|
464
|
+ ]);
|
|
|
465
|
+ });
|
|
|
466
|
+});
|
|
|
467
|
+
|
|
|
468
|
+add_task(async function test_bridges() {
|
|
|
469
|
+ await runTest(async (_server, client) => {
|
|
|
470
|
+ const bridges = await client.getBridges();
|
|
|
471
|
+ Assert.deepEqual(bridges, [
|
|
|
472
|
+ {
|
|
|
473
|
+ transport: "obfs4",
|
|
|
474
|
+ addr: "1.2.3.4:443",
|
|
|
475
|
+ id: "1111111111111111111111111111111111111111",
|
|
|
476
|
+ args: "cert=IiE5kF0SGOWNDF2nN2RQA5iMszRJdvHA3/6JNr0vPZRO5ra2GslNPT46c1Hkj4O5O0a8/g iat-mode=0",
|
|
|
477
|
+ },
|
|
|
478
|
+ {
|
|
|
479
|
+ transport: "obfs4",
|
|
|
480
|
+ addr: "123.4.56.78:80",
|
|
|
481
|
+ id: "2222222222222222222222222222222222222222",
|
|
|
482
|
+ args: "cert=tTo5rWWGawTCMsEHM3DKVPzFni8d0BZib6xtcPVk6F2spWavYyZ5FXqlsaq8exih/6n+UD iat-mode=1",
|
|
|
483
|
+ },
|
|
|
484
|
+ {
|
|
|
485
|
+ transport: "snowflake",
|
|
|
486
|
+ addr: "5.6.7.8:443",
|
|
|
487
|
+ },
|
|
|
488
|
+ {
|
|
|
489
|
+ transport: "snowflake",
|
|
|
490
|
+ addr: "12.3.4.5:443",
|
|
|
491
|
+ args: "some=param",
|
|
|
492
|
+ },
|
|
|
493
|
+ {
|
|
|
494
|
+ transport: "vanilla",
|
|
|
495
|
+ addr: "123.45.6.78:9050",
|
|
|
496
|
+ },
|
|
|
497
|
+ ]);
|
|
|
498
|
+ });
|
|
|
499
|
+});
|
|
|
500
|
+
|
|
|
501
|
+add_task(async function test_pluggable_transports() {
|
|
|
502
|
+ await runTest(async (_server, client) => {
|
|
|
503
|
+ const pts = await client.getPluggableTransports();
|
|
|
504
|
+ Assert.deepEqual(pts, [
|
|
|
505
|
+ {
|
|
|
506
|
+ transports: [
|
|
|
507
|
+ "meek_lite",
|
|
|
508
|
+ "obfs2",
|
|
|
509
|
+ "obfs3",
|
|
|
510
|
+ "obfs4",
|
|
|
511
|
+ "scramblesuit",
|
|
|
512
|
+ "webtunnel",
|
|
|
513
|
+ ],
|
|
|
514
|
+ type: "exec",
|
|
|
515
|
+ pathToBinary: "./TorBrowser/Tor/PluggableTransports/lyrebird",
|
|
|
516
|
+ options: "",
|
|
|
517
|
+ },
|
|
|
518
|
+ {
|
|
|
519
|
+ transports: ["snowflake"],
|
|
|
520
|
+ type: "exec",
|
|
|
521
|
+ pathToBinary: ".\\TorBrowser\\Tor\\PluggableTransports\\lyrebird",
|
|
|
522
|
+ options: "",
|
|
|
523
|
+ },
|
|
|
524
|
+ {
|
|
|
525
|
+ transports: ["conjure"],
|
|
|
526
|
+ type: "exec",
|
|
|
527
|
+ pathToBinary: "./TorBrowser/Tor/PluggableTransports/conjure-client",
|
|
|
528
|
+ options: "-registerURL https://registration.refraction.network/api",
|
|
|
529
|
+ },
|
|
|
530
|
+ { transports: ["pt1"], type: "socks4", ip: "127.0.0.1", port: "9052" },
|
|
|
531
|
+ { transports: ["pt2"], type: "socks5", ip: "[::1]", port: "9053" },
|
|
|
532
|
+ ]);
|
|
|
533
|
+ });
|
|
|
534
|
+});
|
|
|
535
|
+
|
|
|
536
|
+add_task(async function test_set_conf() {
|
|
|
537
|
+ await runTest(async (server, client) => {
|
|
|
538
|
+ const entries = [
|
|
|
539
|
+ ["boolean", true],
|
|
|
540
|
+ ["integer", 3],
|
|
|
541
|
+ ["string", "value"],
|
|
|
542
|
+ ["array", ["val1", "val2", "val3"]],
|
|
|
543
|
+ ["null", null],
|
|
|
544
|
+ ];
|
|
|
545
|
+ Assert.equal(server.conf.size, 0, "Initially the conf map is empty.");
|
|
|
546
|
+ await client.setConf(entries);
|
|
|
547
|
+ // Booleans are converted to 0 and 1.
|
|
|
548
|
+ entries[0][1] = 1;
|
|
|
549
|
+ Assert.deepEqual(Array.from(server.conf.entries()), entries);
|
|
|
550
|
+ });
|
|
|
551
|
+});
|
|
|
552
|
+
|
|
|
553
|
+add_task(async function test_set_conf_bad() {
|
|
|
554
|
+ await runTest(async (_server, client) => {
|
|
|
555
|
+ let failed = false;
|
|
|
556
|
+ try {
|
|
|
557
|
+ await client.setConf([["INVALID", true]]);
|
|
|
558
|
+ } catch (e) {
|
|
|
559
|
+ failed = true;
|
|
|
560
|
+ Assert.equal(e.code, 552);
|
|
|
561
|
+ Assert.equal(
|
|
|
562
|
+ e.message,
|
|
|
563
|
+ "Unrecognized option: Unknown option 'INVALID'. Failing."
|
|
|
564
|
+ );
|
|
|
565
|
+ }
|
|
|
566
|
+ Assert.ok(failed, "We expected the SETCONF call to fail.");
|
|
|
567
|
+ });
|
|
|
568
|
+});
|
|
|
569
|
+
|
|
|
570
|
+add_task(async function test_set_network_enabled() {
|
|
|
571
|
+ await runTest(async (server, client) => {
|
|
|
572
|
+ await client.setNetworkEnabled(false);
|
|
|
573
|
+ Assert.equal(server.conf.get("DisableNetwork"), 1);
|
|
|
574
|
+ await client.setNetworkEnabled(true);
|
|
|
575
|
+ Assert.equal(server.conf.get("DisableNetwork"), 0);
|
|
|
576
|
+ });
|
|
|
577
|
+});
|
|
|
578
|
+
|
|
|
579
|
+add_task(async function test_onion_auth_flow() {
|
|
|
580
|
+ await runTest(async (server, client) => {
|
|
|
581
|
+ Assert.equal(server.onionAuth.size, 0);
|
|
|
582
|
+ await client.onionAuthAdd(
|
|
|
583
|
+ "pg6mmjiyjmcrsslvykfwnntlaru7p5svn6y2ymmju6nubxndf4pscryd",
|
|
|
584
|
+ "r9aD8uLN/kDI2Bmk633RvwgB/9uwAxNzhrHgJcs8I7wP",
|
|
|
585
|
+ false
|
|
|
586
|
+ );
|
|
|
587
|
+ Assert.equal(server.onionAuth.size, 1);
|
|
|
588
|
+ Assert.deepEqual(
|
|
|
589
|
+ server.onionAuth.get(
|
|
|
590
|
+ "PG6MMJIYJMCRSSLVYKFWNNTLARU7P5SVN6Y2YMMJU6NUBXNDF4PSCRYD"
|
|
|
591
|
+ ),
|
|
|
592
|
+ { key: "x25519:r9aD8uLN/kDI2Bmk633RvwgB/9uwAxNzhrHgJcs8I7wP" }
|
|
|
593
|
+ );
|
|
|
594
|
+ Assert.deepEqual(await client.onionAuthViewKeys(), [
|
|
|
595
|
+ {
|
|
|
596
|
+ address: "PG6MMJIYJMCRSSLVYKFWNNTLARU7P5SVN6Y2YMMJU6NUBXNDF4PSCRYD",
|
|
|
597
|
+ keyType: "x25519",
|
|
|
598
|
+ keyBlob: "r9aD8uLN/kDI2Bmk633RvwgB/9uwAxNzhrHgJcs8I7wP",
|
|
|
599
|
+ flags: [],
|
|
|
600
|
+ },
|
|
|
601
|
+ ]);
|
|
|
602
|
+
|
|
|
603
|
+ await client.onionAuthAdd(
|
|
|
604
|
+ "PG6MMJiyjmcrsslvykfwnntlaru7p5svn6y2ymmju6nubxndf4pscryd",
|
|
|
605
|
+ "r9aD8uLN/kDI2Bmk633RvwgB/9uwAxNzhrHgJcs8I7wP",
|
|
|
606
|
+ true
|
|
|
607
|
+ );
|
|
|
608
|
+ Assert.equal(server.onionAuth.size, 1);
|
|
|
609
|
+ Assert.deepEqual(
|
|
|
610
|
+ server.onionAuth.get(
|
|
|
611
|
+ "PG6MMJIYJMCRSSLVYKFWNNTLARU7P5SVN6Y2YMMJU6NUBXNDF4PSCRYD"
|
|
|
612
|
+ ),
|
|
|
613
|
+ {
|
|
|
614
|
+ key: "x25519:r9aD8uLN/kDI2Bmk633RvwgB/9uwAxNzhrHgJcs8I7wP",
|
|
|
615
|
+ flags: "Permanent",
|
|
56
|
616
|
}
|
|
|
617
|
+ );
|
|
|
618
|
+ Assert.deepEqual(await client.onionAuthViewKeys(), [
|
|
|
619
|
+ {
|
|
|
620
|
+ address: "PG6MMJIYJMCRSSLVYKFWNNTLARU7P5SVN6Y2YMMJU6NUBXNDF4PSCRYD",
|
|
|
621
|
+ keyType: "x25519",
|
|
|
622
|
+ keyBlob: "r9aD8uLN/kDI2Bmk633RvwgB/9uwAxNzhrHgJcs8I7wP",
|
|
|
623
|
+ flags: ["Permanent"],
|
|
|
624
|
+ },
|
|
|
625
|
+ ]);
|
|
|
626
|
+
|
|
|
627
|
+ await client.onionAuthRemove(
|
|
|
628
|
+ "PG6MMJIYJMcrSSLVykfwnnTlARu7P5sVN6y2yMmjU6NUBxndf4pscryD"
|
|
|
629
|
+ );
|
|
|
630
|
+ Assert.equal(server.onionAuth.size, 0);
|
|
|
631
|
+ Assert.deepEqual(await client.onionAuthViewKeys(), []);
|
|
|
632
|
+
|
|
|
633
|
+ // Removing again should not throw.
|
|
|
634
|
+ await client.onionAuthRemove(
|
|
|
635
|
+ "PG6MMJIYJMcrSSLVykfwnnTlARu7P5sVN6y2yMmjU6NUBxndf4pscryD"
|
|
|
636
|
+ );
|
|
|
637
|
+ });
|
|
|
638
|
+});
|
|
|
639
|
+
|
|
|
640
|
+add_task(async function test_onion_auth_add_bad() {
|
|
|
641
|
+ await runTest(async (_server, client) => {
|
|
|
642
|
+ let failed = false;
|
|
|
643
|
+ try {
|
|
|
644
|
+ await client.onionAuthAdd(
|
|
|
645
|
+ "invalidonionaddress",
|
|
|
646
|
+ "r9aD8uLN/kDI2Bmk633RvwgB/9uwAxNzhrHgJcs8I7wP",
|
|
|
647
|
+ true
|
|
|
648
|
+ );
|
|
|
649
|
+ } catch (e) {
|
|
|
650
|
+ Assert.ok(true, `The ONION_CLIENT_AUTH_ADD request failed: ${e.message}`);
|
|
|
651
|
+ Assert.equal(e.result, Cr.NS_ERROR_ILLEGAL_VALUE);
|
|
|
652
|
+ failed = true;
|
|
57
|
653
|
}
|
|
58
|
|
- Assert.ok(failed, "sendCommand threw when we expected it to.");
|
|
|
654
|
+ Assert.ok(
|
|
|
655
|
+ failed,
|
|
|
656
|
+ "This ONION_CLIENT_AUTH_ADD request was expected to fail."
|
|
|
657
|
+ );
|
|
|
658
|
+ });
|
|
59
|
659
|
|
|
60
|
|
- server.close();
|
|
|
660
|
+ await runTest(async (_server, client) => {
|
|
|
661
|
+ let failed = false;
|
|
|
662
|
+ try {
|
|
|
663
|
+ await client.onionAuthAdd(
|
|
|
664
|
+ "PG6MMJIYJMCRSSLVYKFWNNTLARU7P5SVN6Y2YMMJU6NUBXNDF4PSCRYD",
|
|
|
665
|
+ "not!base$64:(",
|
|
|
666
|
+ true
|
|
|
667
|
+ );
|
|
|
668
|
+ } catch (e) {
|
|
|
669
|
+ Assert.ok(true, `The ONION_CLIENT_AUTH_ADD request failed: ${e.message}`);
|
|
|
670
|
+ failed = true;
|
|
|
671
|
+ }
|
|
|
672
|
+ Assert.ok(
|
|
|
673
|
+ failed,
|
|
|
674
|
+ "This ONION_CLIENT_AUTH_ADD request was expected to fail."
|
|
|
675
|
+ );
|
|
|
676
|
+ });
|
|
|
677
|
+});
|
|
|
678
|
+
|
|
|
679
|
+add_task(async function test_onion_auth_remove_bad() {
|
|
|
680
|
+ await runTest(async (_server, client) => {
|
|
|
681
|
+ let failed = false;
|
|
|
682
|
+ try {
|
|
|
683
|
+ await client.onionAuthAdd("invalidonionaddress");
|
|
|
684
|
+ } catch (e) {
|
|
|
685
|
+ Assert.ok(
|
|
|
686
|
+ true,
|
|
|
687
|
+ `The ONION_CLIENT_AUTH_REMOVE request failed: ${e.message}`
|
|
|
688
|
+ );
|
|
|
689
|
+ Assert.equal(e.result, Cr.NS_ERROR_ILLEGAL_VALUE);
|
|
|
690
|
+ failed = true;
|
|
|
691
|
+ }
|
|
|
692
|
+ Assert.ok(
|
|
|
693
|
+ failed,
|
|
|
694
|
+ "This ONION_CLIENT_AUTH_REMOVE request was expected to fail."
|
|
|
695
|
+ );
|
|
|
696
|
+ });
|
|
|
697
|
+});
|
|
|
698
|
+
|
|
|
699
|
+add_task(async function test_onion_auth_view_bad() {
|
|
|
700
|
+ const runCommand = async client => {
|
|
|
701
|
+ let failed = false;
|
|
|
702
|
+ try {
|
|
|
703
|
+ await client.onionAuthView();
|
|
|
704
|
+ } catch (e) {
|
|
|
705
|
+ Assert.ok(
|
|
|
706
|
+ true,
|
|
|
707
|
+ `The ONION_CLIENT_AUTH_VIEW request failed: ${e.message}`
|
|
|
708
|
+ );
|
|
|
709
|
+ failed = true;
|
|
|
710
|
+ }
|
|
|
711
|
+ Assert.ok(
|
|
|
712
|
+ failed,
|
|
|
713
|
+ "This ONION_CLIENT_AUTH_VIEW request was expected to fail."
|
|
|
714
|
+ );
|
|
|
715
|
+ };
|
|
|
716
|
+
|
|
|
717
|
+ await runTest(async (server, client) => {
|
|
|
718
|
+ server.onionAuth.set("invalidoniondomain", {
|
|
|
719
|
+ key: "x25519:r9aD8uLN/kDI2Bmk633RvwgB/9uwAxNzhrHgJcs8I7wP",
|
|
|
720
|
+ flags: "Permanent",
|
|
|
721
|
+ });
|
|
|
722
|
+ await runCommand(client);
|
|
|
723
|
+ });
|
|
|
724
|
+
|
|
|
725
|
+ await runTest(async (server, client) => {
|
|
|
726
|
+ server.onionAuth.set(
|
|
|
727
|
+ "PG6MMJIYJMCRSSLVYKFWNNTLARU7P5SVN6Y2YMMJU6NUBXNDF4PSCRYD",
|
|
|
728
|
+ {
|
|
|
729
|
+ key: "x25519:not!base:(64$$$$",
|
|
|
730
|
+ flags: "",
|
|
|
731
|
+ }
|
|
|
732
|
+ );
|
|
|
733
|
+ await runCommand(client);
|
|
|
734
|
+ });
|
|
|
735
|
+});
|
|
|
736
|
+
|
|
|
737
|
+add_task(async function test_set_events() {
|
|
|
738
|
+ await runTest(async (server, client) => {
|
|
|
739
|
+ Assert.equal(server.events.length, 0);
|
|
|
740
|
+ const events = ["NOTICE", "INFO"];
|
|
|
741
|
+ await client.setEvents(events);
|
|
|
742
|
+ Assert.deepEqual(server.events, events);
|
|
|
743
|
+ });
|
|
|
744
|
+});
|
|
|
745
|
+
|
|
|
746
|
+add_task(async function test_simple_commands() {
|
|
|
747
|
+ await runTest(async (_server, client) => {
|
|
|
748
|
+ await client.flushSettings();
|
|
|
749
|
+ await client.takeOwnership();
|
|
|
750
|
+ await client.resetOwningControllerProcess();
|
|
|
751
|
+ await client.newnym();
|
|
61
|
752
|
});
|
|
62
|
753
|
});
|
|
63
|
754
|
|
|
64
|
755
|
/**
|
|
65
|
|
- * A specialized control port client for testing async messages.
|
|
|
756
|
+ * A notification listener that will be used for tests.
|
|
|
757
|
+ * It implements TorEventHandler as defined in TorControlPort.sys.mjs.
|
|
66
|
758
|
*/
|
|
67
|
|
-class ControlPortClientAsyncNotification extends ControlPortClient {
|
|
68
|
|
- notificationPromise;
|
|
|
759
|
+class NotificationListener {
|
|
|
760
|
+ #nextType;
|
|
69
|
761
|
#resolve;
|
|
70
|
|
- closedPromise;
|
|
71
|
|
- #closedResolve;
|
|
|
762
|
+ #reject;
|
|
72
|
763
|
|
|
73
|
|
- constructor(server) {
|
|
74
|
|
- super(server);
|
|
75
|
|
- this.notificationPromise = new Promise(
|
|
76
|
|
- resolve => (this.#resolve = resolve)
|
|
77
|
|
- );
|
|
78
|
|
- this.closedPromise = new Promise(
|
|
79
|
|
- resolve => (this.#closedResolve = resolve)
|
|
80
|
|
- );
|
|
|
764
|
+ #checkType(type) {
|
|
|
765
|
+ const next = this.#nextType;
|
|
|
766
|
+ this.#nextType = null;
|
|
|
767
|
+ if (type !== next) {
|
|
|
768
|
+ this.#reject(new Error(`Wrong type: got ${type}, expected ${next}`));
|
|
|
769
|
+ return false;
|
|
|
770
|
+ }
|
|
|
771
|
+ return true;
|
|
|
772
|
+ }
|
|
|
773
|
+
|
|
|
774
|
+ setup(type) {
|
|
|
775
|
+ this.#nextType = type;
|
|
|
776
|
+ return new Promise((resolve, reject) => {
|
|
|
777
|
+ this.#resolve = resolve;
|
|
|
778
|
+ this.#reject = reject;
|
|
|
779
|
+ });
|
|
|
780
|
+ }
|
|
|
781
|
+
|
|
|
782
|
+ onLogMessage(severity, message) {
|
|
|
783
|
+ if (this.#checkType("logMessage")) {
|
|
|
784
|
+ this.#resolve({ severity, message });
|
|
|
785
|
+ }
|
|
|
786
|
+ }
|
|
|
787
|
+
|
|
|
788
|
+ onBootstrapStatus(status) {
|
|
|
789
|
+ if (this.#checkType("bootstrapStatus")) {
|
|
|
790
|
+ this.#resolve(status);
|
|
|
791
|
+ }
|
|
81
|
792
|
}
|
|
82
|
793
|
|
|
83
|
|
- onAsyncMessage(message) {
|
|
84
|
|
- Assert.equal(message, "650-Test\r\n650 notification");
|
|
85
|
|
- this.#resolve();
|
|
|
794
|
+ onCircuitBuilt(circuit) {
|
|
|
795
|
+ if (this.#checkType("circuitBuilt")) {
|
|
|
796
|
+ this.#resolve(circuit);
|
|
|
797
|
+ }
|
|
|
798
|
+ }
|
|
|
799
|
+
|
|
|
800
|
+ onCircuitClosed(id) {
|
|
|
801
|
+ if (this.#checkType("circuitClosed")) {
|
|
|
802
|
+ this.#resolve(id);
|
|
|
803
|
+ }
|
|
|
804
|
+ }
|
|
|
805
|
+
|
|
|
806
|
+ onStreamSentConnect(streamId, circuitId, username, password) {
|
|
|
807
|
+ if (this.#checkType("streamSentConnect")) {
|
|
|
808
|
+ this.#resolve({
|
|
|
809
|
+ streamId,
|
|
|
810
|
+ circuitId,
|
|
|
811
|
+ username,
|
|
|
812
|
+ password,
|
|
|
813
|
+ });
|
|
|
814
|
+ }
|
|
86
|
815
|
}
|
|
87
|
816
|
|
|
88
|
817
|
onClosed() {
|
|
89
|
|
- this.#closedResolve();
|
|
|
818
|
+ if (this.#checkType("closed")) {
|
|
|
819
|
+ this.#resolve();
|
|
|
820
|
+ }
|
|
90
|
821
|
}
|
|
91
|
822
|
}
|
|
92
|
823
|
|
|
93
|
|
-add_task(async function test_asyncNotification() {
|
|
94
|
|
- await runTest(async function testAsyncNotification(protocol) {
|
|
95
|
|
- const server = new ControlPortServer(protocol, async transport => {
|
|
96
|
|
- await transport.write("650-Test\r\n650 notification\r\n");
|
|
97
|
|
- transport.close();
|
|
98
|
|
- });
|
|
99
|
|
- const cp = new ControlPortClientAsyncNotification(server);
|
|
100
|
|
- await cp.notificationPromise;
|
|
101
|
|
- cp.close();
|
|
102
|
|
- server.close();
|
|
103
|
|
- await cp.closedPromise;
|
|
|
824
|
+add_task(async function test_log_notifications() {
|
|
|
825
|
+ await runTest(async (server, client) => {
|
|
|
826
|
+ const listener = new NotificationListener();
|
|
|
827
|
+ client.setEventHandler(listener);
|
|
|
828
|
+ const testLog = async (severity, message) => {
|
|
|
829
|
+ const test = listener.setup("logMessage");
|
|
|
830
|
+ await server.write(`650 ${severity} ${message}\r\n`);
|
|
|
831
|
+ Assert.deepEqual(await test, {
|
|
|
832
|
+ severity,
|
|
|
833
|
+ message,
|
|
|
834
|
+ });
|
|
|
835
|
+ };
|
|
|
836
|
+ await testLog("DEBUG", "Some debug info");
|
|
|
837
|
+ await testLog("INFO", "An info message");
|
|
|
838
|
+ await testLog("NOTICE", "A notice");
|
|
|
839
|
+ await testLog("WARN", "An warning, so not too bad");
|
|
|
840
|
+ await testLog("ERR", "A bad error!!");
|
|
104
|
841
|
});
|
|
105
|
842
|
});
|
|
106
|
843
|
|
|
107
|
|
-add_task(async function test_failureAfterClosing() {
|
|
108
|
|
- await runTest(async function testFailureAfterClosing(protocol) {
|
|
|
844
|
+add_task(async function test_circuit_built_notifications() {
|
|
|
845
|
+ await runTest(async (server, client) => {
|
|
|
846
|
+ const listener = new NotificationListener();
|
|
|
847
|
+ client.setEventHandler(listener);
|
|
109
|
848
|
{
|
|
110
|
|
- let cp;
|
|
111
|
|
- const { promise, resolve, reject } = Promise.withResolvers();
|
|
112
|
|
- const server = new ControlPortServer(protocol, async transport => {
|
|
113
|
|
- transport.close();
|
|
114
|
|
- server.close();
|
|
115
|
|
-
|
|
116
|
|
- try {
|
|
117
|
|
- await cp.sendCommand("TEST");
|
|
118
|
|
- reject("We managed to send a command after closing the connection.");
|
|
119
|
|
- } catch (e) {
|
|
120
|
|
- Assert.ok(
|
|
121
|
|
- true,
|
|
122
|
|
- `We failed to send the command as expected (${e.message})`
|
|
123
|
|
- );
|
|
124
|
|
- } finally {
|
|
125
|
|
- try {
|
|
126
|
|
- cp?.close();
|
|
127
|
|
- } catch {}
|
|
128
|
|
- }
|
|
129
|
|
- resolve();
|
|
|
849
|
+ const test = listener.setup("circuitBuilt");
|
|
|
850
|
+ await server.write(
|
|
|
851
|
+ "650 CIRC abc123 BUILT $1111111111111111111111111111111111111111\r\n"
|
|
|
852
|
+ );
|
|
|
853
|
+ Assert.deepEqual(await test, {
|
|
|
854
|
+ id: "abc123",
|
|
|
855
|
+ nodes: ["1111111111111111111111111111111111111111"],
|
|
130
|
856
|
});
|
|
131
|
|
- try {
|
|
132
|
|
- cp = new ControlPortClient(server);
|
|
133
|
|
- } catch {
|
|
134
|
|
- server.close();
|
|
135
|
|
- }
|
|
136
|
|
- await promise;
|
|
137
|
857
|
}
|
|
138
|
|
-
|
|
139
|
858
|
{
|
|
140
|
|
- const server = new ControlPortServer(protocol, async transport => {
|
|
141
|
|
- try {
|
|
142
|
|
- const s = await transport.readLine();
|
|
143
|
|
- Assert.equal(s, "TEST");
|
|
144
|
|
- await transport.write("250 OK\r\n");
|
|
145
|
|
- } catch {
|
|
146
|
|
- // We do not really care if the client manages to close the socket
|
|
147
|
|
- // before we handle it.
|
|
148
|
|
- }
|
|
149
|
|
- transport.close();
|
|
|
859
|
+ const test = listener.setup("circuitBuilt");
|
|
|
860
|
+ await server.write(
|
|
|
861
|
+ "650 CIRC 456 BUILT $aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,$bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb,$cccccccccccccccccccccccccccccccccccccccc\r\n"
|
|
|
862
|
+ );
|
|
|
863
|
+ Assert.deepEqual(await test, {
|
|
|
864
|
+ id: "456",
|
|
|
865
|
+ nodes: [
|
|
|
866
|
+ "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
|
|
|
867
|
+ "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
|
|
|
868
|
+ "cccccccccccccccccccccccccccccccccccccccc",
|
|
|
869
|
+ ],
|
|
|
870
|
+ });
|
|
|
871
|
+ }
|
|
|
872
|
+ {
|
|
|
873
|
+ const test = listener.setup("circuitBuilt");
|
|
|
874
|
+ await server.write(
|
|
|
875
|
+ "650 CIRC conflux BUILT $1111111111111111111111111111111111111111~guard,$2222222222222222222222222222222222222222~mid,$3333333333333333333333333333333333333333~exit CONFLUX_ID=aabbccddeeff00112233445566778899\r\n"
|
|
|
876
|
+ );
|
|
|
877
|
+ Assert.deepEqual(await test, {
|
|
|
878
|
+ id: "conflux",
|
|
|
879
|
+ nodes: [
|
|
|
880
|
+ "1111111111111111111111111111111111111111",
|
|
|
881
|
+ "2222222222222222222222222222222222222222",
|
|
|
882
|
+ "3333333333333333333333333333333333333333",
|
|
|
883
|
+ ],
|
|
|
884
|
+ confluxId: "aabbccddeeff00112233445566778899",
|
|
150
|
885
|
});
|
|
|
886
|
+ }
|
|
|
887
|
+ });
|
|
|
888
|
+});
|
|
151
|
889
|
|
|
152
|
|
- const cp = new ControlPortClient(server);
|
|
153
|
|
- cp.close();
|
|
154
|
|
- let sentCommand = false;
|
|
155
|
|
- try {
|
|
156
|
|
- await cp.sendCommand("TEST");
|
|
157
|
|
- sentCommand = true;
|
|
158
|
|
- } catch (e) {
|
|
159
|
|
- Assert.ok(
|
|
160
|
|
- true,
|
|
161
|
|
- `We failed to send the command as expected (${e.message})`
|
|
162
|
|
- );
|
|
163
|
|
- } finally {
|
|
164
|
|
- server.close();
|
|
165
|
|
- }
|
|
166
|
|
- Assert.ok(
|
|
167
|
|
- !sentCommand,
|
|
168
|
|
- "We did not send the command as we had already closed the connection"
|
|
|
890
|
+add_task(async function test_circuit_closed_notification() {
|
|
|
891
|
+ await runTest(async (server, client) => {
|
|
|
892
|
+ const listener = new NotificationListener();
|
|
|
893
|
+ client.setEventHandler(listener);
|
|
|
894
|
+ const test = listener.setup("circuitClosed");
|
|
|
895
|
+ await server.write("650 CIRC qwerty CLOSED\r\n");
|
|
|
896
|
+ Assert.equal(await test, "qwerty");
|
|
|
897
|
+ });
|
|
|
898
|
+});
|
|
|
899
|
+
|
|
|
900
|
+add_task(async function test_sent_connect_notifications() {
|
|
|
901
|
+ await runTest(async (server, client) => {
|
|
|
902
|
+ const listener = new NotificationListener();
|
|
|
903
|
+ client.setEventHandler(listener);
|
|
|
904
|
+ {
|
|
|
905
|
+ const test = listener.setup("streamSentConnect");
|
|
|
906
|
+ await server.write("650 STREAM 1 SENTCONNECT 0 1.2.3.4:443\r\n");
|
|
|
907
|
+ Assert.deepEqual(await test, {
|
|
|
908
|
+ streamId: "1",
|
|
|
909
|
+ circuitId: "0",
|
|
|
910
|
+ username: null,
|
|
|
911
|
+ password: null,
|
|
|
912
|
+ });
|
|
|
913
|
+ }
|
|
|
914
|
+ {
|
|
|
915
|
+ const test = listener.setup("streamSentConnect");
|
|
|
916
|
+ await server.write(
|
|
|
917
|
+ '650 STREAM 1ab SENTCONNECT xyz 1.2.3.4:443 SOCKS_USERNAME="user" SOCKS_PASSWORD="pass"\r\n'
|
|
169
|
918
|
);
|
|
|
919
|
+ Assert.deepEqual(await test, {
|
|
|
920
|
+ streamId: "1ab",
|
|
|
921
|
+ circuitId: "xyz",
|
|
|
922
|
+ username: "user",
|
|
|
923
|
+ password: "pass",
|
|
|
924
|
+ });
|
|
170
|
925
|
}
|
|
171
|
926
|
});
|
|
172
|
927
|
});
|
|
|
928
|
+
|
|
|
929
|
+add_task(async function test_closed_notification() {
|
|
|
930
|
+ await runTest(async (server, client) => {
|
|
|
931
|
+ const listener = new NotificationListener();
|
|
|
932
|
+ client.setEventHandler(listener);
|
|
|
933
|
+ const test = listener.setup("closed");
|
|
|
934
|
+ server.close();
|
|
|
935
|
+ await test;
|
|
|
936
|
+ });
|
|
|
937
|
+}); |
toolkit/components/tor-integration/test/xpcshell/xpcshell.toml
|
1
|
1
|
[DEFAULT]
|
|
2
|
2
|
head = "head.js"
|
|
3
|
3
|
|
|
|
4
|
+["test_adapters.js"]
|
|
|
5
|
+
|
|
4
|
6
|
["test_control_port.js"] |
toolkit/components/tor-integration/torITorService.idl
| ... |
... |
@@ -17,11 +17,51 @@ interface torITorMessageHandler : nsISupports { |
|
17
|
17
|
void onError(in ACString error);
|
|
18
|
18
|
};
|
|
19
|
19
|
|
|
|
20
|
+[scriptable, uuid(8d817c29-e35c-4a4b-ad29-fb24b83ea8cd)]
|
|
|
21
|
+interface torITorReplyCallback : nsISupports {
|
|
|
22
|
+ void onReply([optional] in ACString reply);
|
|
|
23
|
+ void onTorError(in unsigned short code, in ACString message);
|
|
|
24
|
+ void onGenericError(in ACString message);
|
|
|
25
|
+};
|
|
|
26
|
+
|
|
|
27
|
+[scriptable, uuid(d555064e-811c-4e6d-b2d6-3ec88ae14a69)]
|
|
|
28
|
+interface torITorNotificationListener : nsISupports {
|
|
|
29
|
+ void logMessage(in ACString severity, in ACString message);
|
|
|
30
|
+ void bootstrapStatus(in ACString status);
|
|
|
31
|
+ void circuitBuilt(in ACString circuit);
|
|
|
32
|
+ void circuitClosed(in ACString id);
|
|
|
33
|
+ void streamSentConnect(in ACString stream);
|
|
|
34
|
+ void connectionClosed();
|
|
|
35
|
+};
|
|
|
36
|
+
|
|
20
|
37
|
// TODO: Remove once we have a provider.
|
|
21
|
38
|
[scriptable, uuid(f56d710e-5650-4b8c-8d31-279f360003ee)]
|
|
22
|
39
|
interface torITorControlPort : nsISupports {
|
|
23
|
40
|
void start(in torITorControlPortReceiver receiver);
|
|
24
|
41
|
void sendCommand(in ACString command, in torITorMessageHandler handler);
|
|
|
42
|
+
|
|
|
43
|
+ void authenticate(in Array<uint8_t> password,
|
|
|
44
|
+ in torITorReplyCallback callback);
|
|
|
45
|
+ void getBootstrapPhase(in torITorReplyCallback callback);
|
|
|
46
|
+ void getNodeAddresses(in ACString node, in torITorReplyCallback callback);
|
|
|
47
|
+ void getIpCountry(in ACString ip, in torITorReplyCallback callback);
|
|
|
48
|
+ void getSocksListeners(in torITorReplyCallback callback);
|
|
|
49
|
+ void getCircuits(in torITorReplyCallback callback);
|
|
|
50
|
+ void getBridges(in torITorReplyCallback callback);
|
|
|
51
|
+ void getPluggableTransports(in torITorReplyCallback callback);
|
|
|
52
|
+ void setConf(in ACString values, in torITorReplyCallback callback);
|
|
|
53
|
+ void setNetworkEnabled(in boolean enabled, in torITorReplyCallback callback);
|
|
|
54
|
+ void flushSettings(in torITorReplyCallback callback);
|
|
|
55
|
+ void onionAuthViewKeys(in torITorReplyCallback callback);
|
|
|
56
|
+ void onionAuthAdd(in ACString address, in ACString key, in boolean permanent,
|
|
|
57
|
+ in torITorReplyCallback callback);
|
|
|
58
|
+ void onionAuthRemove(in ACString address, in torITorReplyCallback callback);
|
|
|
59
|
+ void takeOwnership(in torITorReplyCallback callback);
|
|
|
60
|
+ void resetOwningControllerProcess(in torITorReplyCallback callback);
|
|
|
61
|
+ void newnym(in torITorReplyCallback callback);
|
|
|
62
|
+ void setEvents(in Array<ACString> events, in torITorReplyCallback callback);
|
|
|
63
|
+ void setNotificationListener(in torITorNotificationListener listener);
|
|
|
64
|
+
|
|
25
|
65
|
void close();
|
|
26
|
66
|
};
|
|
27
|
67
|
|
toolkit/components/tor-integration/tor_service/Cargo.toml
| ... |
... |
@@ -20,5 +20,8 @@ tor_provider = { path = "../tor_provider" } |
|
20
|
20
|
|
|
21
|
21
|
bytes = "1.4.0"
|
|
22
|
22
|
cstr = "0.2"
|
|
|
23
|
+hex = "0.4.3"
|
|
23
|
24
|
log = "0.4"
|
|
|
25
|
+serde = { version = "1.0", features = ["derive"] }
|
|
|
26
|
+serde_json = "1.0"
|
|
24
|
27
|
thin-vec = { version = "0.2.1", features = ["gecko-ffi"] } |
toolkit/components/tor-integration/tor_service/src/control_port.rs
| ... |
... |
@@ -2,18 +2,25 @@ |
|
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
|
+use bytes::Bytes;
|
|
5
|
6
|
use nserror::nsresult;
|
|
6
|
|
-use nserror::{NS_ERROR_NOT_CONNECTED, NS_ERROR_UNEXPECTED, NS_OK};
|
|
|
7
|
+use nserror::{NS_ERROR_INVALID_ARG, NS_ERROR_NOT_CONNECTED, NS_ERROR_UNEXPECTED, NS_OK};
|
|
7
|
8
|
use nsstring::{nsACString, nsCString};
|
|
8
|
|
-use tor_provider::ctor::{ControlPort, ControlSocketError, ControllerError, TorController};
|
|
9
|
|
-use xpcom::interfaces::{nsIFile, torITorControlPortReceiver, torITorMessageHandler};
|
|
|
9
|
+use serde_json::{json, Value as JsonValue};
|
|
|
10
|
+use std::rc::Rc;
|
|
|
11
|
+use thin_vec::ThinVec;
|
|
|
12
|
+use tor_provider::ctor::*;
|
|
|
13
|
+use xpcom::interfaces::{
|
|
|
14
|
+ nsIFile, torITorControlPortReceiver, torITorMessageHandler, torITorNotificationListener,
|
|
|
15
|
+ torITorReplyCallback,
|
|
|
16
|
+};
|
|
10
|
17
|
use xpcom::RefPtr;
|
|
11
|
18
|
|
|
12
|
19
|
// Actually used, but the compiler does not detect it.
|
|
13
|
20
|
#[allow(unused)]
|
|
14
|
21
|
use xpcom::interfaces::torITorControlPort;
|
|
15
|
22
|
|
|
16
|
|
-use super::control_socket::ControlSocketXpcom;
|
|
|
23
|
+use super::{control_socket::ControlSocketXpcom, plumbing::*};
|
|
17
|
24
|
|
|
18
|
25
|
#[xpcom(implement(torITorControlPort), atomic)]
|
|
19
|
26
|
pub struct ControlPortXpcom {
|
| ... |
... |
@@ -122,4 +129,311 @@ impl ControlPortXpcom { |
|
122
|
129
|
ControlSocketError::ConnectionClosed => NS_ERROR_NOT_CONNECTED,
|
|
123
|
130
|
}
|
|
124
|
131
|
}
|
|
|
132
|
+
|
|
|
133
|
+ xpcom_method!(authenticate => Authenticate(password: *const ThinVec<u8>, callback: *const torITorReplyCallback));
|
|
|
134
|
+ pub fn authenticate(
|
|
|
135
|
+ &self,
|
|
|
136
|
+ password: &ThinVec<u8>,
|
|
|
137
|
+ callback: *const torITorReplyCallback,
|
|
|
138
|
+ ) -> Result<(), nsresult> {
|
|
|
139
|
+ self.control_port
|
|
|
140
|
+ .authenticate(&password, make_xpcom_handler(callback));
|
|
|
141
|
+ Ok(())
|
|
|
142
|
+ }
|
|
|
143
|
+
|
|
|
144
|
+ xpcom_method!(get_bootstrap_phase => GetBootstrapPhase(callback: *const torITorReplyCallback));
|
|
|
145
|
+ fn get_bootstrap_phase(&self, callback: *const torITorReplyCallback) -> Result<(), nsresult> {
|
|
|
146
|
+ self.control_port
|
|
|
147
|
+ .get_bootstrap_phase(make_xpcom_handler(callback));
|
|
|
148
|
+ Ok(())
|
|
|
149
|
+ }
|
|
|
150
|
+
|
|
|
151
|
+ xpcom_method!(get_node_addresses => GetNodeAddresses(node: *const nsACString, callback: *const torITorReplyCallback));
|
|
|
152
|
+ fn get_node_addresses(
|
|
|
153
|
+ &self,
|
|
|
154
|
+ node: &nsACString,
|
|
|
155
|
+ callback: *const torITorReplyCallback,
|
|
|
156
|
+ ) -> Result<(), nsresult> {
|
|
|
157
|
+ let node_str = str::from_utf8(&node).map_err(|_| NS_ERROR_INVALID_ARG)?;
|
|
|
158
|
+ let mut node = [0; 20];
|
|
|
159
|
+ hex::decode_to_slice(node_str, &mut node).map_err(|_| NS_ERROR_INVALID_ARG)?;
|
|
|
160
|
+ self.control_port
|
|
|
161
|
+ .get_node_addresses(node, make_xpcom_handler(callback));
|
|
|
162
|
+ Ok(())
|
|
|
163
|
+ }
|
|
|
164
|
+
|
|
|
165
|
+ xpcom_method!(get_ip_country => GetIpCountry(ip: *const nsACString, callback: *const torITorReplyCallback));
|
|
|
166
|
+ fn get_ip_country(
|
|
|
167
|
+ &self,
|
|
|
168
|
+ ip: &nsACString,
|
|
|
169
|
+ callback: *const torITorReplyCallback,
|
|
|
170
|
+ ) -> Result<(), nsresult> {
|
|
|
171
|
+ let ip = str::from_utf8(&ip).map_err(|_| NS_ERROR_INVALID_ARG)?;
|
|
|
172
|
+ let ip = ip.parse().map_err(|_| NS_ERROR_INVALID_ARG)?;
|
|
|
173
|
+ self.control_port
|
|
|
174
|
+ .get_ip_country(ip, make_xpcom_handler(callback));
|
|
|
175
|
+ Ok(())
|
|
|
176
|
+ }
|
|
|
177
|
+
|
|
|
178
|
+ xpcom_method!(get_socks_listeners => GetSocksListeners(callback: *const torITorReplyCallback));
|
|
|
179
|
+ fn get_socks_listeners(&self, callback: *const torITorReplyCallback) -> Result<(), nsresult> {
|
|
|
180
|
+ let cb = make_xpcom_handler(callback);
|
|
|
181
|
+ self.control_port.get_socks_listeners(Box::new(|reply| {
|
|
|
182
|
+ (cb)(reply.map(|listeners| {
|
|
|
183
|
+ listeners
|
|
|
184
|
+ .iter()
|
|
|
185
|
+ .map(|l| match l {
|
|
|
186
|
+ SocksListener::Tcp(addr) => {
|
|
|
187
|
+ json!({ "host": addr.ip().to_string(), "port": addr.port() })
|
|
|
188
|
+ }
|
|
|
189
|
+ SocksListener::UnixSocket(path) => {
|
|
|
190
|
+ json!({ "ipcPath": path })
|
|
|
191
|
+ }
|
|
|
192
|
+ })
|
|
|
193
|
+ .collect::<Vec<_>>()
|
|
|
194
|
+ }))
|
|
|
195
|
+ }));
|
|
|
196
|
+ Ok(())
|
|
|
197
|
+ }
|
|
|
198
|
+
|
|
|
199
|
+ xpcom_method!(get_circuits => GetCircuits(callback: *const torITorReplyCallback));
|
|
|
200
|
+ fn get_circuits(&self, callback: *const torITorReplyCallback) -> Result<(), nsresult> {
|
|
|
201
|
+ self.control_port.get_circuits(make_xpcom_handler(callback));
|
|
|
202
|
+ Ok(())
|
|
|
203
|
+ }
|
|
|
204
|
+
|
|
|
205
|
+ xpcom_method!(get_bridges => GetBridges(callback: *const torITorReplyCallback));
|
|
|
206
|
+ pub fn get_bridges(&self, callback: *const torITorReplyCallback) -> Result<(), nsresult> {
|
|
|
207
|
+ self.control_port.get_bridges(make_xpcom_handler_mapped(
|
|
|
208
|
+ callback,
|
|
|
209
|
+ |bridges: Vec<Bridge>| {
|
|
|
210
|
+ bridges
|
|
|
211
|
+ .iter()
|
|
|
212
|
+ .map(|b| BridgeWithStrings::from(b))
|
|
|
213
|
+ .collect::<Vec<_>>()
|
|
|
214
|
+ },
|
|
|
215
|
+ ));
|
|
|
216
|
+ Ok(())
|
|
|
217
|
+ }
|
|
|
218
|
+
|
|
|
219
|
+ xpcom_method!(get_pluggable_transports => GetPluggableTransports(callback: *const torITorReplyCallback));
|
|
|
220
|
+ pub fn get_pluggable_transports(
|
|
|
221
|
+ &self,
|
|
|
222
|
+ callback: *const torITorReplyCallback,
|
|
|
223
|
+ ) -> Result<(), nsresult> {
|
|
|
224
|
+ self.control_port
|
|
|
225
|
+ .get_pluggable_transports(make_xpcom_handler_mapped(
|
|
|
226
|
+ callback,
|
|
|
227
|
+ |pts: Vec<PluggableTransport>| {
|
|
|
228
|
+ pts.iter()
|
|
|
229
|
+ .map(|pt| ExpandedPluggableTransport::from(pt))
|
|
|
230
|
+ .collect::<Vec<_>>()
|
|
|
231
|
+ },
|
|
|
232
|
+ ));
|
|
|
233
|
+ Ok(())
|
|
|
234
|
+ }
|
|
|
235
|
+
|
|
|
236
|
+ xpcom_method!(set_conf => SetConf(values: *const nsACString, callback: *const torITorReplyCallback));
|
|
|
237
|
+ fn set_conf(
|
|
|
238
|
+ &self,
|
|
|
239
|
+ values: &nsACString,
|
|
|
240
|
+ callback: *const torITorReplyCallback,
|
|
|
241
|
+ ) -> Result<(), nsresult> {
|
|
|
242
|
+ let values: Vec<(String, JsonValue)> =
|
|
|
243
|
+ serde_json::from_slice(&values).map_err(|_| NS_ERROR_INVALID_ARG)?;
|
|
|
244
|
+ let mut conf = Vec::with_capacity(values.len());
|
|
|
245
|
+ for (val, c) in values.iter() {
|
|
|
246
|
+ let cv = match c {
|
|
|
247
|
+ JsonValue::Bool(b) => ConfValue::Bool(*b),
|
|
|
248
|
+ JsonValue::Number(n) => {
|
|
|
249
|
+ if let Some(i) = n.as_i64().and_then(|i| i.try_into().ok()) {
|
|
|
250
|
+ ConfValue::Int(i)
|
|
|
251
|
+ } else {
|
|
|
252
|
+ return Err(NS_ERROR_INVALID_ARG);
|
|
|
253
|
+ }
|
|
|
254
|
+ }
|
|
|
255
|
+ JsonValue::String(s) => ConfValue::String(s.as_str()),
|
|
|
256
|
+ JsonValue::Array(arr) => {
|
|
|
257
|
+ let mut strings = Vec::with_capacity(arr.len());
|
|
|
258
|
+ for v in arr.iter() {
|
|
|
259
|
+ match v {
|
|
|
260
|
+ JsonValue::String(s) => strings.push(s.as_str()),
|
|
|
261
|
+ _ => {
|
|
|
262
|
+ return Err(NS_ERROR_INVALID_ARG);
|
|
|
263
|
+ }
|
|
|
264
|
+ }
|
|
|
265
|
+ }
|
|
|
266
|
+ ConfValue::Array(strings)
|
|
|
267
|
+ }
|
|
|
268
|
+ JsonValue::Null => ConfValue::Null,
|
|
|
269
|
+ _ => return Err(NS_ERROR_INVALID_ARG),
|
|
|
270
|
+ };
|
|
|
271
|
+ conf.push((val.as_str(), cv));
|
|
|
272
|
+ }
|
|
|
273
|
+ self.control_port
|
|
|
274
|
+ .set_conf(&conf, make_xpcom_handler(callback));
|
|
|
275
|
+ Ok(())
|
|
|
276
|
+ }
|
|
|
277
|
+
|
|
|
278
|
+ xpcom_method!(set_network_enabled => SetNetworkEnabled(enabled: bool, callback: *const torITorReplyCallback));
|
|
|
279
|
+ fn set_network_enabled(
|
|
|
280
|
+ &self,
|
|
|
281
|
+ enabled: bool,
|
|
|
282
|
+ callback: *const torITorReplyCallback,
|
|
|
283
|
+ ) -> Result<(), nsresult> {
|
|
|
284
|
+ self.control_port.set_conf(
|
|
|
285
|
+ &[("DisableNetwork", ConfValue::Bool(!enabled))],
|
|
|
286
|
+ make_xpcom_handler(callback),
|
|
|
287
|
+ );
|
|
|
288
|
+ Ok(())
|
|
|
289
|
+ }
|
|
|
290
|
+
|
|
|
291
|
+ xpcom_method!(flush_settings => FlushSettings(callback: *const torITorReplyCallback));
|
|
|
292
|
+ fn flush_settings(&self, callback: *const torITorReplyCallback) -> Result<(), nsresult> {
|
|
|
293
|
+ self.control_port.save_conf(make_xpcom_handler(callback));
|
|
|
294
|
+ Ok(())
|
|
|
295
|
+ }
|
|
|
296
|
+
|
|
|
297
|
+ xpcom_method!(onion_auth_view_keys => OnionAuthViewKeys(callback: *const torITorReplyCallback));
|
|
|
298
|
+ fn onion_auth_view_keys(&self, callback: *const torITorReplyCallback) -> Result<(), nsresult> {
|
|
|
299
|
+ self.control_port
|
|
|
300
|
+ .onion_auth_view_keys(make_xpcom_handler(callback));
|
|
|
301
|
+ Ok(())
|
|
|
302
|
+ }
|
|
|
303
|
+
|
|
|
304
|
+ xpcom_method!(onion_auth_add => OnionAuthAdd(address: *const nsACString, key: *const nsACString, permanent: bool, callback: *const torITorReplyCallback));
|
|
|
305
|
+ fn onion_auth_add(
|
|
|
306
|
+ &self,
|
|
|
307
|
+ address: &nsACString,
|
|
|
308
|
+ key: &nsACString,
|
|
|
309
|
+ permanent: bool,
|
|
|
310
|
+ callback: *const torITorReplyCallback,
|
|
|
311
|
+ ) -> Result<(), nsresult> {
|
|
|
312
|
+ let address = HSAddress::from_slice(&address).map_err(|_| NS_ERROR_INVALID_ARG)?;
|
|
|
313
|
+ self.control_port
|
|
|
314
|
+ .onion_auth_add(address, key, permanent, make_xpcom_handler(callback));
|
|
|
315
|
+ Ok(())
|
|
|
316
|
+ }
|
|
|
317
|
+
|
|
|
318
|
+ xpcom_method!(onion_auth_remove => OnionAuthRemove(address: *const nsACString, callback: *const torITorReplyCallback));
|
|
|
319
|
+ fn onion_auth_remove(
|
|
|
320
|
+ &self,
|
|
|
321
|
+ address: &nsACString,
|
|
|
322
|
+ callback: *const torITorReplyCallback,
|
|
|
323
|
+ ) -> Result<(), nsresult> {
|
|
|
324
|
+ let address = HSAddress::from_slice(&address).map_err(|_| NS_ERROR_INVALID_ARG)?;
|
|
|
325
|
+ self.control_port
|
|
|
326
|
+ .onion_auth_remove(address, make_xpcom_handler(callback));
|
|
|
327
|
+ Ok(())
|
|
|
328
|
+ }
|
|
|
329
|
+
|
|
|
330
|
+ xpcom_method!(take_ownership => TakeOwnership(callback: *const torITorReplyCallback));
|
|
|
331
|
+ fn take_ownership(&self, callback: *const torITorReplyCallback) -> Result<(), nsresult> {
|
|
|
332
|
+ self.control_port
|
|
|
333
|
+ .take_ownership(make_xpcom_handler(callback));
|
|
|
334
|
+ Ok(())
|
|
|
335
|
+ }
|
|
|
336
|
+
|
|
|
337
|
+ xpcom_method!(reset_owning_controller_process => ResetOwningControllerProcess(callback: *const torITorReplyCallback));
|
|
|
338
|
+ fn reset_owning_controller_process(
|
|
|
339
|
+ &self,
|
|
|
340
|
+ callback: *const torITorReplyCallback,
|
|
|
341
|
+ ) -> Result<(), nsresult> {
|
|
|
342
|
+ self.control_port
|
|
|
343
|
+ .reset_owning_controller_process(make_xpcom_handler(callback));
|
|
|
344
|
+ Ok(())
|
|
|
345
|
+ }
|
|
|
346
|
+
|
|
|
347
|
+ xpcom_method!(newnym => Newnym(callback: *const torITorReplyCallback));
|
|
|
348
|
+ fn newnym(&self, callback: *const torITorReplyCallback) -> Result<(), nsresult> {
|
|
|
349
|
+ self.control_port
|
|
|
350
|
+ .signal_newnym(make_xpcom_handler(callback));
|
|
|
351
|
+ Ok(())
|
|
|
352
|
+ }
|
|
|
353
|
+
|
|
|
354
|
+ xpcom_method!(set_events => SetEvents(events: *const ThinVec<nsCString>, callback: *const torITorReplyCallback));
|
|
|
355
|
+ fn set_events(
|
|
|
356
|
+ &self,
|
|
|
357
|
+ events: &ThinVec<nsCString>,
|
|
|
358
|
+ callback: *const torITorReplyCallback,
|
|
|
359
|
+ ) -> Result<(), nsresult> {
|
|
|
360
|
+ let events = events
|
|
|
361
|
+ .iter()
|
|
|
362
|
+ .map(|e| str::from_utf8(&e))
|
|
|
363
|
+ .collect::<Result<Vec<_>, _>>()
|
|
|
364
|
+ .map_err(|_| NS_ERROR_INVALID_ARG)?;
|
|
|
365
|
+ self.control_port
|
|
|
366
|
+ .set_events(&events, make_xpcom_handler(callback));
|
|
|
367
|
+ Ok(())
|
|
|
368
|
+ }
|
|
|
369
|
+
|
|
|
370
|
+ xpcom_method!(set_notification_listener => SetNotificationListener(listener: *const torITorNotificationListener));
|
|
|
371
|
+ fn set_notification_listener(
|
|
|
372
|
+ &self,
|
|
|
373
|
+ listener: &torITorNotificationListener,
|
|
|
374
|
+ ) -> Result<(), nsresult> {
|
|
|
375
|
+ self.control_port
|
|
|
376
|
+ .set_notification_listener(Some(Rc::new(XpcomNotificationListener::new(listener))));
|
|
|
377
|
+ let close_listener = RefPtr::new(listener);
|
|
|
378
|
+ // For consistency with the _javascript_ interface, we still keep the
|
|
|
379
|
+ // close handler with the notifications.
|
|
|
380
|
+ self.control_port.set_close_handler(Box::new(move || {
|
|
|
381
|
+ // Safety: method from our own interface that we created so that it
|
|
|
382
|
+ // was exposed to Rust.
|
|
|
383
|
+ unsafe { close_listener.ConnectionClosed() };
|
|
|
384
|
+ }));
|
|
|
385
|
+ Ok(())
|
|
|
386
|
+ }
|
|
|
387
|
+}
|
|
|
388
|
+
|
|
|
389
|
+struct XpcomNotificationListener(RefPtr<torITorNotificationListener>);
|
|
|
390
|
+
|
|
|
391
|
+impl XpcomNotificationListener {
|
|
|
392
|
+ fn new(listener: &torITorNotificationListener) -> Self {
|
|
|
393
|
+ Self(RefPtr::new(listener))
|
|
|
394
|
+ }
|
|
|
395
|
+}
|
|
|
396
|
+
|
|
|
397
|
+impl NotificationListener for XpcomNotificationListener {
|
|
|
398
|
+ fn log_message(&self, severity: String, message: Bytes) {
|
|
|
399
|
+ // Safety: method from our own interface that we created so that it was
|
|
|
400
|
+ // exposed to Rust.
|
|
|
401
|
+ unsafe {
|
|
|
402
|
+ self.0.LogMessage(
|
|
|
403
|
+ &*nsCString::from(severity),
|
|
|
404
|
+ &*nsCString::from(message.as_ref()),
|
|
|
405
|
+ )
|
|
|
406
|
+ };
|
|
|
407
|
+ }
|
|
|
408
|
+
|
|
|
409
|
+ fn bootstrap_status(&self, status: BootstrapStatus) {
|
|
|
410
|
+ if let Ok(status) = serde_json::to_vec(&status) {
|
|
|
411
|
+ // Safety: method from our own interface that we created so that it
|
|
|
412
|
+ // was exposed to Rust.
|
|
|
413
|
+ unsafe { self.0.BootstrapStatus(&*nsCString::from(status)) };
|
|
|
414
|
+ }
|
|
|
415
|
+ }
|
|
|
416
|
+
|
|
|
417
|
+ fn circuit_built(&self, circuit: Circuit) {
|
|
|
418
|
+ // Safety: method from our own interface that we created so that it was
|
|
|
419
|
+ // exposed to Rust.
|
|
|
420
|
+ if let Ok(circuit) = serde_json::to_vec(&circuit) {
|
|
|
421
|
+ unsafe { self.0.CircuitBuilt(&*nsCString::from(circuit)) };
|
|
|
422
|
+ }
|
|
|
423
|
+ }
|
|
|
424
|
+
|
|
|
425
|
+ fn circuit_closed(&self, id: CircuitID) {
|
|
|
426
|
+ // Safety: method from our own interface that we created so that it was
|
|
|
427
|
+ // exposed to Rust.
|
|
|
428
|
+ unsafe { self.0.CircuitClosed(&*nsCString::from(id.as_str())) };
|
|
|
429
|
+ }
|
|
|
430
|
+
|
|
|
431
|
+ fn stream_sent_connect(&self, stream: Stream) {
|
|
|
432
|
+ let stream = StreamWithStrings::from(stream);
|
|
|
433
|
+ if let Ok(stream) = serde_json::to_vec(&stream) {
|
|
|
434
|
+ // Safety: method from our own interface that we created so that it
|
|
|
435
|
+ // was exposed to Rust.
|
|
|
436
|
+ unsafe { self.0.StreamSentConnect(&*nsCString::from(stream)) };
|
|
|
437
|
+ }
|
|
|
438
|
+ }
|
|
125
|
439
|
} |
toolkit/components/tor-integration/tor_service/src/lib.rs
| ... |
... |
@@ -7,4 +7,5 @@ extern crate xpcom; |
|
7
|
7
|
|
|
8
|
8
|
mod control_port;
|
|
9
|
9
|
mod control_socket;
|
|
|
10
|
+mod plumbing;
|
|
10
|
11
|
mod service; |
toolkit/components/tor-integration/tor_service/src/plumbing.rs
|
|
1
|
+/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
2
|
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
3
|
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
4
|
+
|
|
|
5
|
+use nsstring::nsCString;
|
|
|
6
|
+use serde::Serialize;
|
|
|
7
|
+use std::net::SocketAddr;
|
|
|
8
|
+use tor_provider::ctor::*;
|
|
|
9
|
+use xpcom::{interfaces::torITorReplyCallback, RefPtr};
|
|
|
10
|
+
|
|
|
11
|
+fn call_xpcom_callback<T>(res: Result<T, ControllerError>, callback: RefPtr<torITorReplyCallback>)
|
|
|
12
|
+where
|
|
|
13
|
+ T: Serialize,
|
|
|
14
|
+{
|
|
|
15
|
+ // Safety: methods from our own interface that we created so that it was
|
|
|
16
|
+ // exposed to Rust.
|
|
|
17
|
+ match res {
|
|
|
18
|
+ Ok(value) => match serde_json::to_vec(&value) {
|
|
|
19
|
+ Ok(vec) => unsafe {
|
|
|
20
|
+ callback.OnReply(&*nsCString::from(vec));
|
|
|
21
|
+ },
|
|
|
22
|
+ Err(e) => unsafe {
|
|
|
23
|
+ callback.OnGenericError(&*nsCString::from(e.to_string()));
|
|
|
24
|
+ },
|
|
|
25
|
+ },
|
|
|
26
|
+ Err(ControllerError::TorError { code, message }) => unsafe {
|
|
|
27
|
+ callback.OnTorError(code, &*nsCString::from(message));
|
|
|
28
|
+ },
|
|
|
29
|
+ Err(e) => unsafe {
|
|
|
30
|
+ callback.OnGenericError(&*nsCString::from(e.to_string()));
|
|
|
31
|
+ },
|
|
|
32
|
+ }
|
|
|
33
|
+}
|
|
|
34
|
+
|
|
|
35
|
+pub fn make_xpcom_handler<T>(
|
|
|
36
|
+ callback: *const torITorReplyCallback,
|
|
|
37
|
+) -> Box<dyn FnOnce(Result<T, ControllerError>)>
|
|
|
38
|
+where
|
|
|
39
|
+ T: Serialize,
|
|
|
40
|
+{
|
|
|
41
|
+ // Safety: from_raw will handle the null pointer case for us.
|
|
|
42
|
+ // It will also increment the reference count, which is what we need, since
|
|
|
43
|
+ // the XPCOM convention is that pointers are borrowed.
|
|
|
44
|
+ let callback = unsafe { RefPtr::from_raw(callback) };
|
|
|
45
|
+ match callback {
|
|
|
46
|
+ Some(callback) => Box::new(move |r| {
|
|
|
47
|
+ call_xpcom_callback(r, callback);
|
|
|
48
|
+ }),
|
|
|
49
|
+ None => Box::new(move |_| {}),
|
|
|
50
|
+ }
|
|
|
51
|
+}
|
|
|
52
|
+
|
|
|
53
|
+pub fn make_xpcom_handler_mapped<F, T, R>(
|
|
|
54
|
+ callback: *const torITorReplyCallback,
|
|
|
55
|
+ map: F,
|
|
|
56
|
+) -> Box<dyn FnOnce(Result<T, ControllerError>)>
|
|
|
57
|
+where
|
|
|
58
|
+ F: FnOnce(T) -> R + 'static,
|
|
|
59
|
+ R: Serialize,
|
|
|
60
|
+{
|
|
|
61
|
+ // Safety: from_raw will handle the null pointer case for us.
|
|
|
62
|
+ // It will also increment the reference count, which is what we need, since
|
|
|
63
|
+ // the XPCOM convention is that pointers are borrowed.
|
|
|
64
|
+ let callback = unsafe { RefPtr::from_raw(callback) };
|
|
|
65
|
+ match callback {
|
|
|
66
|
+ Some(callback) => Box::new(move |r| {
|
|
|
67
|
+ call_xpcom_callback(r.map(map), callback);
|
|
|
68
|
+ }),
|
|
|
69
|
+ None => Box::new(move |_| {}),
|
|
|
70
|
+ }
|
|
|
71
|
+}
|
|
|
72
|
+
|
|
|
73
|
+/// A struct that looks like Stream, but uses strings for username and password,
|
|
|
74
|
+/// to avoid converting between bytes and strings in _javascript_.
|
|
|
75
|
+#[derive(Serialize)]
|
|
|
76
|
+pub(crate) struct StreamWithStrings {
|
|
|
77
|
+ stream_id: StreamID,
|
|
|
78
|
+ circuit_id: CircuitID,
|
|
|
79
|
+ socks_username: Option<String>,
|
|
|
80
|
+ socks_password: Option<String>,
|
|
|
81
|
+}
|
|
|
82
|
+
|
|
|
83
|
+impl From<Stream> for StreamWithStrings {
|
|
|
84
|
+ fn from(value: Stream) -> Self {
|
|
|
85
|
+ // The browser uses a limited set of ASCII characters, so even if we end
|
|
|
86
|
+ // up with the replacement character, those streams should be discarded
|
|
|
87
|
+ // for our purposes anyway.
|
|
|
88
|
+ let socks_username = value
|
|
|
89
|
+ .socks_username
|
|
|
90
|
+ .map(|s| String::from_utf8_lossy(&s).into_owned());
|
|
|
91
|
+ let socks_password = value
|
|
|
92
|
+ .socks_password
|
|
|
93
|
+ .map(|s| String::from_utf8_lossy(&s).into_owned());
|
|
|
94
|
+ Self {
|
|
|
95
|
+ stream_id: value.stream_id,
|
|
|
96
|
+ circuit_id: value.circuit_id,
|
|
|
97
|
+ socks_username,
|
|
|
98
|
+ socks_password,
|
|
|
99
|
+ }
|
|
|
100
|
+ }
|
|
|
101
|
+}
|
|
|
102
|
+
|
|
|
103
|
+#[derive(Serialize)]
|
|
|
104
|
+pub(crate) struct BridgeWithStrings {
|
|
|
105
|
+ pub transport: Option<String>,
|
|
|
106
|
+ pub address: String,
|
|
|
107
|
+ pub fingerprint: Option<String>,
|
|
|
108
|
+ pub args: Option<String>,
|
|
|
109
|
+}
|
|
|
110
|
+
|
|
|
111
|
+impl From<&Bridge> for BridgeWithStrings {
|
|
|
112
|
+ fn from(value: &Bridge) -> Self {
|
|
|
113
|
+ Self {
|
|
|
114
|
+ transport: value.transport.clone(),
|
|
|
115
|
+ address: value.address.to_string(),
|
|
|
116
|
+ fingerprint: value.fingerprint.map(|fp| hex::encode(fp)),
|
|
|
117
|
+ args: value
|
|
|
118
|
+ .args
|
|
|
119
|
+ .as_ref()
|
|
|
120
|
+ .map(|a| String::from_utf8_lossy(a).into_owned()),
|
|
|
121
|
+ }
|
|
|
122
|
+ }
|
|
|
123
|
+}
|
|
|
124
|
+
|
|
|
125
|
+/// A flattened version PluggableTransport that is friendlier to serialization.
|
|
|
126
|
+/// When pt_type is exec, path_to_binary and options are set and ip/port are
|
|
|
127
|
+/// None, opposite when it is another type.
|
|
|
128
|
+#[derive(Serialize)]
|
|
|
129
|
+pub(crate) struct ExpandedPluggableTransport {
|
|
|
130
|
+ transports: Vec<String>,
|
|
|
131
|
+ pt_type: String,
|
|
|
132
|
+ path_to_binary: Option<String>,
|
|
|
133
|
+ options: Option<String>,
|
|
|
134
|
+ ip: Option<String>,
|
|
|
135
|
+ port: Option<u16>,
|
|
|
136
|
+}
|
|
|
137
|
+
|
|
|
138
|
+impl ExpandedPluggableTransport {
|
|
|
139
|
+ fn new_exec(transports: &Vec<String>, path: &Vec<u8>, options: &Option<Vec<u8>>) -> Self {
|
|
|
140
|
+ Self {
|
|
|
141
|
+ transports: transports.clone(),
|
|
|
142
|
+ pt_type: String::from("exec"),
|
|
|
143
|
+ path_to_binary: Some(String::from_utf8_lossy(path).into_owned()),
|
|
|
144
|
+ options: options
|
|
|
145
|
+ .as_ref()
|
|
|
146
|
+ .map(|o| String::from_utf8_lossy(o).into_owned()),
|
|
|
147
|
+ ip: None,
|
|
|
148
|
+ port: None,
|
|
|
149
|
+ }
|
|
|
150
|
+ }
|
|
|
151
|
+
|
|
|
152
|
+ fn new_socks(transports: &Vec<String>, socks_type: &str, addr: &SocketAddr) -> Self {
|
|
|
153
|
+ let ip = if addr.is_ipv6() {
|
|
|
154
|
+ format!("[{}]", addr.ip())
|
|
|
155
|
+ } else {
|
|
|
156
|
+ addr.ip().to_string()
|
|
|
157
|
+ };
|
|
|
158
|
+ Self {
|
|
|
159
|
+ transports: transports.clone(),
|
|
|
160
|
+ pt_type: socks_type.to_string(),
|
|
|
161
|
+ path_to_binary: None,
|
|
|
162
|
+ options: None,
|
|
|
163
|
+ ip: Some(ip),
|
|
|
164
|
+ port: Some(addr.port()),
|
|
|
165
|
+ }
|
|
|
166
|
+ }
|
|
|
167
|
+}
|
|
|
168
|
+
|
|
|
169
|
+impl From<&PluggableTransport> for ExpandedPluggableTransport {
|
|
|
170
|
+ fn from(value: &PluggableTransport) -> Self {
|
|
|
171
|
+ match &value.plugin {
|
|
|
172
|
+ ClientTransportPlugin::Executable { path, options } => {
|
|
|
173
|
+ ExpandedPluggableTransport::new_exec(&value.transports, path, options)
|
|
|
174
|
+ }
|
|
|
175
|
+ ClientTransportPlugin::Socks4(addr) => {
|
|
|
176
|
+ ExpandedPluggableTransport::new_socks(&value.transports, "socks4", addr)
|
|
|
177
|
+ }
|
|
|
178
|
+ ClientTransportPlugin::Socks5(addr) => {
|
|
|
179
|
+ ExpandedPluggableTransport::new_socks(&value.transports, "socks5", addr)
|
|
|
180
|
+ }
|
|
|
181
|
+ }
|
|
|
182
|
+ }
|
|
|
183
|
+} |
toolkit/components/tor-launcher/TorControlPort.sys.mjs
| ... |
... |
@@ -396,15 +396,6 @@ export class TorController { |
|
396
|
396
|
* @returns {TorController}
|
|
397
|
397
|
*/
|
|
398
|
398
|
static fromIpcFile(ipcFile) {
|
|
399
|
|
- // Notice: this preference is temporary, only for testing!
|
|
400
|
|
- // Do not rely on it to exist forever.
|
|
401
|
|
- if (
|
|
402
|
|
- Services.tor &&
|
|
403
|
|
- Services.prefs.getBoolPref("browser.tor_provider.oxidize", false)
|
|
404
|
|
- ) {
|
|
405
|
|
- return new TorController(Services.tor.createControlPortIPC(ipcFile));
|
|
406
|
|
- }
|
|
407
|
|
-
|
|
408
|
399
|
return new TorController(AsyncSocket.fromIpcFile(ipcFile));
|
|
409
|
400
|
}
|
|
410
|
401
|
|
| ... |
... |
@@ -416,15 +407,6 @@ export class TorController { |
|
416
|
407
|
* @returns {TorController}
|
|
417
|
408
|
*/
|
|
418
|
409
|
static fromSocketAddress(host, port) {
|
|
419
|
|
- // Notice: this preference is temporary, only for testing!
|
|
420
|
|
- // Do not rely on it to exist forever.
|
|
421
|
|
- if (
|
|
422
|
|
- Services.tor &&
|
|
423
|
|
- Services.prefs.getBoolPref("browser.tor_provider.oxidize", false)
|
|
424
|
|
- ) {
|
|
425
|
|
- return new TorController(Services.tor.createControlPort(host, port));
|
|
426
|
|
- }
|
|
427
|
|
-
|
|
428
|
410
|
return new TorController(AsyncSocket.fromSocketAddress(host, port));
|
|
429
|
411
|
}
|
|
430
|
412
|
|
| ... |
... |
@@ -558,21 +540,6 @@ export class TorController { |
|
558
|
540
|
* closed).
|
|
559
|
541
|
*/
|
|
560
|
542
|
async #startMessagePump() {
|
|
561
|
|
- // Rust control port
|
|
562
|
|
- if (this.#socket.start) {
|
|
563
|
|
- const self = this;
|
|
564
|
|
- const receiver = {
|
|
565
|
|
- onAsyncMessage(message) {
|
|
566
|
|
- self.#handleNotification(message);
|
|
567
|
|
- },
|
|
568
|
|
- onClosed() {
|
|
569
|
|
- self.#eventHandler?.onClosed();
|
|
570
|
|
- },
|
|
571
|
|
- };
|
|
572
|
|
- this.#socket.start(receiver);
|
|
573
|
|
- return;
|
|
574
|
|
- }
|
|
575
|
|
-
|
|
576
|
543
|
try {
|
|
577
|
544
|
// This while is inside the try block because it is very likely that it
|
|
578
|
545
|
// will be broken by a NS_BASE_STREAM_CLOSED exception, rather than by its
|
| ... |
... |
@@ -631,21 +598,6 @@ export class TorController { |
|
631
|
598
|
throw new Error("ControlSocket not open");
|
|
632
|
599
|
}
|
|
633
|
600
|
|
|
634
|
|
- // Rust control port
|
|
635
|
|
- if (this.#socket.sendCommand) {
|
|
636
|
|
- const { promise, resolve, reject } = Promise.withResolvers();
|
|
637
|
|
- const handler = {
|
|
638
|
|
- onMessage(message) {
|
|
639
|
|
- resolve(message);
|
|
640
|
|
- },
|
|
641
|
|
- onError(error) {
|
|
642
|
|
- reject(new Error(error));
|
|
643
|
|
- },
|
|
644
|
|
- };
|
|
645
|
|
- this.#socket.sendCommand(commandString, handler);
|
|
646
|
|
- return promise;
|
|
647
|
|
- }
|
|
648
|
|
-
|
|
649
|
601
|
// this promise is resolved either in #handleCommandReply, or in
|
|
650
|
602
|
// #startMessagePump (on stream error)
|
|
651
|
603
|
return new Promise((resolve, reject) => {
|
toolkit/components/tor-launcher/TorProvider.sys.mjs
| ... |
... |
@@ -12,6 +12,8 @@ import { TorProviderTopics } from "moz-src:///toolkit/components/tor-launcher/To |
|
12
|
12
|
const lazy = {};
|
|
13
|
13
|
ChromeUtils.defineESModuleGetters(lazy, {
|
|
14
|
14
|
FileUtils: "resource://gre/modules/FileUtils.sys.mjs",
|
|
|
15
|
+ OxidizedControlPort:
|
|
|
16
|
+ "moz-src:///toolkit/components/tor-integration/OxidizedControlPort.sys.mjs",
|
|
15
|
17
|
TorController:
|
|
16
|
18
|
"moz-src:///toolkit/components/tor-launcher/TorControlPort.sys.mjs",
|
|
17
|
19
|
TorProcess: "moz-src:///toolkit/components/tor-launcher/TorProcess.sys.mjs",
|
| ... |
... |
@@ -799,12 +801,18 @@ export class TorProvider extends TorProviderBase { |
|
799
|
801
|
*/
|
|
800
|
802
|
async #openControlPort() {
|
|
801
|
803
|
let controlPort;
|
|
|
804
|
+ const controllerClass = Services.prefs.getBoolPref(
|
|
|
805
|
+ "browser.tor_provider.oxidize",
|
|
|
806
|
+ false
|
|
|
807
|
+ )
|
|
|
808
|
+ ? lazy.OxidizedControlPort
|
|
|
809
|
+ : lazy.TorController;
|
|
802
|
810
|
if (this.#controlPortSettings.ipcFile) {
|
|
803
|
|
- controlPort = lazy.TorController.fromIpcFile(
|
|
|
811
|
+ controlPort = controllerClass.fromIpcFile(
|
|
804
|
812
|
this.#controlPortSettings.ipcFile
|
|
805
|
813
|
);
|
|
806
|
814
|
} else {
|
|
807
|
|
- controlPort = lazy.TorController.fromSocketAddress(
|
|
|
815
|
+ controlPort = controllerClass.fromSocketAddress(
|
|
808
|
816
|
this.#controlPortSettings.host,
|
|
809
|
817
|
this.#controlPortSettings.port
|
|
810
|
818
|
);
|
|