Commits:
-
9e9506e9
by Elena at 2026-12-03T08:42:52+01:00
fixup! TB 40933: Add tor-launcher functionality
TB 45469: Created an XPCOM interface for TorProvider.
Do not rely on the provider to log its initialization exception, log it
also from TorProviderBuilder.settled.
-
dd5c868f
by Elena at 2026-12-03T08:42:53+01:00
fixup! TB 44806: Implement the tor integration in Rust.
TB 45469: Created an XPCOM interface for TorProvider.
Create an XPCOM interface that mimics TorProviderBase and the JS
wrapper to actually use it as a provider.
Also, stub the C-tor provider creation function.
8 changed files:
Changes:
Cargo.lock
| ... |
... |
@@ -8471,6 +8471,7 @@ name = "tor_service" |
|
8471
|
8471
|
version = "0.1.0"
|
|
8472
|
8472
|
dependencies = [
|
|
8473
|
8473
|
"bytes",
|
|
|
8474
|
+ "chrono",
|
|
8474
|
8475
|
"cstr",
|
|
8475
|
8476
|
"hex",
|
|
8476
|
8477
|
"log",
|
toolkit/components/tor-integration/OxidizedTorProvider.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
|
+import { TorProviderBase } from "moz-src:///toolkit/components/tor-launcher/TorProviderBase.sys.mjs";
|
|
|
10
|
+
|
|
|
11
|
+const lazy = {};
|
|
|
12
|
+
|
|
|
13
|
+ChromeUtils.defineLazyGetter(lazy, "logger", () => {
|
|
|
14
|
+ return console.createInstance({
|
|
|
15
|
+ // Share preference with TorProvider.
|
|
|
16
|
+ maxLogLevelPref: "browser.tor_provider.log_level",
|
|
|
17
|
+ prefix: "OxidizedTorProvider",
|
|
|
18
|
+ });
|
|
|
19
|
+});
|
|
|
20
|
+
|
|
|
21
|
+ChromeUtils.defineESModuleGetters(lazy, {
|
|
|
22
|
+ TorProxyType: "moz-src:///toolkit/modules/TorSettings.sys.mjs",
|
|
|
23
|
+ TorSettings: "moz-src:///toolkit/modules/TorSettings.sys.mjs",
|
|
|
24
|
+});
|
|
|
25
|
+
|
|
|
26
|
+/**
|
|
|
27
|
+ * The base class for oxidized providers.
|
|
|
28
|
+ *
|
|
|
29
|
+ * We expect all oxidized providers to return the same data structures,
|
|
|
30
|
+ * therefore we have this common class that handles the plumbing between Rust
|
|
|
31
|
+ * and _javascript_.
|
|
|
32
|
+ *
|
|
|
33
|
+ * Every provider is expected to have a corresponding class that must implement
|
|
|
34
|
+ * only one method (_makeNative) to create an instance of torITorProvider.
|
|
|
35
|
+ */
|
|
|
36
|
+class OxidizedTorProvider extends TorProviderBase {
|
|
|
37
|
+ #native;
|
|
|
38
|
+ #initCanceled = null;
|
|
|
39
|
+
|
|
|
40
|
+ _makeNative(_callback) {
|
|
|
41
|
+ throw new Error("Not implemented for the base class.");
|
|
|
42
|
+ }
|
|
|
43
|
+
|
|
|
44
|
+ // TorProvider implementation
|
|
|
45
|
+
|
|
|
46
|
+ async _initInternal() {
|
|
|
47
|
+ const { promise, resolve, reject } = Promise.withResolvers();
|
|
|
48
|
+ // This function is used to cancel the initialization.
|
|
|
49
|
+ // We rely on the fact that we expect to use this wrapper only for native
|
|
|
50
|
+ // providers. Therefore, if we try to resolve the promise after it has
|
|
|
51
|
+ // already been rejected, the provider will be as a matter of fact deleted,
|
|
|
52
|
+ // and this should call the native destructor.
|
|
|
53
|
+ this.#initCanceled = () => reject(new Error("initialization canceled"));
|
|
|
54
|
+ try {
|
|
|
55
|
+ this._makeNative({
|
|
|
56
|
+ onSuccess: provider => {
|
|
|
57
|
+ resolve(provider);
|
|
|
58
|
+ },
|
|
|
59
|
+ onError(message) {
|
|
|
60
|
+ lazy.logger.error(
|
|
|
61
|
+ `Creation of the native torITorProvider object failed: ${message}`
|
|
|
62
|
+ );
|
|
|
63
|
+ reject(new Error(message));
|
|
|
64
|
+ },
|
|
|
65
|
+ });
|
|
|
66
|
+ } catch (e) {
|
|
|
67
|
+ lazy.logger.error("_makeNative failed on the JS side", e);
|
|
|
68
|
+ reject(e);
|
|
|
69
|
+ }
|
|
|
70
|
+
|
|
|
71
|
+ try {
|
|
|
72
|
+ this.#native = await promise;
|
|
|
73
|
+ } finally {
|
|
|
74
|
+ this.#initCanceled = null;
|
|
|
75
|
+ }
|
|
|
76
|
+ this.#native.setCloseHandler(() => this._stoppedInternal());
|
|
|
77
|
+
|
|
|
78
|
+ try {
|
|
|
79
|
+ await lazy.TorSettings.initializedPromise;
|
|
|
80
|
+ await lazy.TorSettings.setTorProvider(this);
|
|
|
81
|
+ } catch (e) {
|
|
|
82
|
+ lazy.logger.warn(
|
|
|
83
|
+ "Failed to initialize TorSettings or to write our initial settings. Continuing the initialization anyway.",
|
|
|
84
|
+ e
|
|
|
85
|
+ );
|
|
|
86
|
+ }
|
|
|
87
|
+ }
|
|
|
88
|
+
|
|
|
89
|
+ _uninitInternal() {
|
|
|
90
|
+ if (this.#initCanceled) {
|
|
|
91
|
+ this.#initCanceled();
|
|
|
92
|
+ } else if (this.#native) {
|
|
|
93
|
+ this.#native.close();
|
|
|
94
|
+ } else {
|
|
|
95
|
+ lazy.logger.warn("Tried to close the native provider before it was set.");
|
|
|
96
|
+ }
|
|
|
97
|
+ this._stoppedInternal();
|
|
|
98
|
+ }
|
|
|
99
|
+
|
|
|
100
|
+ async writeBridgeSettings(bridges) {
|
|
|
101
|
+ const lines = bridges?.enabled ? bridges.bridge_strings : [];
|
|
|
102
|
+ await promisifyMethod(this.#native, "writeBridgeSettings", lines);
|
|
|
103
|
+ }
|
|
|
104
|
+
|
|
|
105
|
+ async writeProxySettings(proxy) {
|
|
|
106
|
+ let settings = {
|
|
|
107
|
+ type: Ci.torITorProxySettings.DIRECT,
|
|
|
108
|
+ host: "",
|
|
|
109
|
+ port: 0,
|
|
|
110
|
+ username: "",
|
|
|
111
|
+ password: "",
|
|
|
112
|
+ };
|
|
|
113
|
+
|
|
|
114
|
+ if (proxy.enabled) {
|
|
|
115
|
+ let { type, address: host, port, username, password } = proxy;
|
|
|
116
|
+ switch (type) {
|
|
|
117
|
+ case lazy.TorProxyType.Socks4:
|
|
|
118
|
+ type = Ci.torITorProxySettings.SOCKS4;
|
|
|
119
|
+ break;
|
|
|
120
|
+ case lazy.TorProxyType.Socks5:
|
|
|
121
|
+ type = Ci.torITorProxySettings.SOCKS5;
|
|
|
122
|
+ break;
|
|
|
123
|
+ case lazy.TorProxyType.HTTPS:
|
|
|
124
|
+ type = Ci.torITorProxySettings.HTTPS;
|
|
|
125
|
+ break;
|
|
|
126
|
+ default:
|
|
|
127
|
+ throw new Error(`Invalid proxy type ${type}`);
|
|
|
128
|
+ }
|
|
|
129
|
+ if (
|
|
|
130
|
+ type !== lazy.TorProxyType.Socks5 &&
|
|
|
131
|
+ type !== lazy.TorProxyType.HTTPS
|
|
|
132
|
+ ) {
|
|
|
133
|
+ username = "";
|
|
|
134
|
+ password = "";
|
|
|
135
|
+ }
|
|
|
136
|
+ settings = {
|
|
|
137
|
+ type,
|
|
|
138
|
+ host,
|
|
|
139
|
+ port,
|
|
|
140
|
+ username,
|
|
|
141
|
+ password,
|
|
|
142
|
+ };
|
|
|
143
|
+ }
|
|
|
144
|
+
|
|
|
145
|
+ await promisifyMethod(this.#native, "writeProxySettings", settings);
|
|
|
146
|
+ }
|
|
|
147
|
+
|
|
|
148
|
+ async writeFirewallSettings(firewall) {
|
|
|
149
|
+ const ports = firewall.enabled ? firewall.allowed_ports : [];
|
|
|
150
|
+ await promisifyMethod(this.#native, "writeFirewallSettings", ports);
|
|
|
151
|
+ }
|
|
|
152
|
+
|
|
|
153
|
+ async flushSettings() {
|
|
|
154
|
+ await promisifyMethod(this.#native, "flushSettings");
|
|
|
155
|
+ }
|
|
|
156
|
+
|
|
|
157
|
+ async connect() {
|
|
|
158
|
+ await promisifyMethod(this.#native, "connect");
|
|
|
159
|
+ }
|
|
|
160
|
+
|
|
|
161
|
+ async stopBootstrap() {
|
|
|
162
|
+ await promisifyMethod(this.#native, "stopBootstrap");
|
|
|
163
|
+ }
|
|
|
164
|
+
|
|
|
165
|
+ async newnym() {
|
|
|
166
|
+ await promisifyMethod(this.#native, "newnym");
|
|
|
167
|
+ }
|
|
|
168
|
+
|
|
|
169
|
+ async getPluggableTransports() {
|
|
|
170
|
+ return OxidationAdapters.convertPluggableTransports(
|
|
|
171
|
+ await promisifyMethod(this.#native, "getPluggableTransports")
|
|
|
172
|
+ );
|
|
|
173
|
+ }
|
|
|
174
|
+
|
|
|
175
|
+ async onionAuthAdd(address, b64PrivateKey, isPermanent) {
|
|
|
176
|
+ await promisifyMethod(
|
|
|
177
|
+ this.#native,
|
|
|
178
|
+ "onionAuthAdd",
|
|
|
179
|
+ address,
|
|
|
180
|
+ b64PrivateKey,
|
|
|
181
|
+ isPermanent
|
|
|
182
|
+ );
|
|
|
183
|
+ }
|
|
|
184
|
+
|
|
|
185
|
+ async onionAuthRemove(address) {
|
|
|
186
|
+ await promisifyMethod(this.#native, "onionAuthRemove", address);
|
|
|
187
|
+ }
|
|
|
188
|
+
|
|
|
189
|
+ async onionAuthViewKeys() {
|
|
|
190
|
+ return OxidationAdapters.convertOnionKeys(
|
|
|
191
|
+ await promisifyMethod(this.#native, "onionAuthViewKeys")
|
|
|
192
|
+ );
|
|
|
193
|
+ }
|
|
|
194
|
+
|
|
|
195
|
+ get currentBridge() {
|
|
|
196
|
+ // TODO: Adapt the values.
|
|
|
197
|
+ return JSON.parse(this.#native.currentBridge);
|
|
|
198
|
+ }
|
|
|
199
|
+}
|
|
|
200
|
+
|
|
|
201
|
+/**
|
|
|
202
|
+ * A C-tor TorProvider implemented in Rust.
|
|
|
203
|
+ */
|
|
|
204
|
+export class OxidizedCtorProvider extends OxidizedTorProvider {
|
|
|
205
|
+ async _makeNative(callback) {
|
|
|
206
|
+ if (!Services.tor) {
|
|
|
207
|
+ throw new Error("The Tor service is not available!");
|
|
|
208
|
+ }
|
|
|
209
|
+ Services.tor.createProvider(callback);
|
|
|
210
|
+ }
|
|
|
211
|
+} |
toolkit/components/tor-integration/moz.build
| ... |
... |
@@ -14,4 +14,8 @@ TEST_DIRS += ["test/gtest"] |
|
14
|
14
|
|
|
15
|
15
|
XPCSHELL_TESTS_MANIFESTS += ["test/xpcshell/xpcshell.toml"]
|
|
16
|
16
|
|
|
17
|
|
-MOZ_SRC_FILES += ["OxidationAdapters.sys.mjs", "OxidizedControlPort.sys.mjs"] |
|
|
17
|
+MOZ_SRC_FILES += [
|
|
|
18
|
+ "OxidationAdapters.sys.mjs",
|
|
|
19
|
+ "OxidizedControlPort.sys.mjs",
|
|
|
20
|
+ "OxidizedTorProvider.sys.mjs",
|
|
|
21
|
+] |
toolkit/components/tor-integration/torITorService.idl
| ... |
... |
@@ -4,6 +4,7 @@ |
|
4
|
4
|
|
|
5
|
5
|
#include "nsISupports.idl"
|
|
6
|
6
|
#include "nsIFile.idl"
|
|
|
7
|
+interface nsIRunnable;
|
|
7
|
8
|
|
|
8
|
9
|
[scriptable, uuid(8d817c29-e35c-4a4b-ad29-fb24b83ea8cd)]
|
|
9
|
10
|
interface torITorReplyCallback : nsISupports {
|
| ... |
... |
@@ -50,9 +51,104 @@ interface torITorControlPort : nsISupports { |
|
50
|
51
|
void close();
|
|
51
|
52
|
};
|
|
52
|
53
|
|
|
|
54
|
+/**
|
|
|
55
|
+ * An interface to send the proxy settings to a provider.
|
|
|
56
|
+ */
|
|
|
57
|
+[scriptable, uuid(07db8e9c-27c0-4457-8097-f0a436d2607c)]
|
|
|
58
|
+interface torITorProxySettings : nsISupports {
|
|
|
59
|
+ const unsigned short DIRECT = 0;
|
|
|
60
|
+ const unsigned short SOCKS4 = 1;
|
|
|
61
|
+ const unsigned short SOCKS5 = 2;
|
|
|
62
|
+ const unsigned short HTTPS = 3;
|
|
|
63
|
+
|
|
|
64
|
+ readonly attribute unsigned short type;
|
|
|
65
|
+ readonly attribute ACString host;
|
|
|
66
|
+ readonly attribute unsigned short port;
|
|
|
67
|
+ readonly attribute ACString username;
|
|
|
68
|
+ readonly attribute ACString password;
|
|
|
69
|
+};
|
|
|
70
|
+
|
|
|
71
|
+/**
|
|
|
72
|
+ * An XPCOM interface equivalent to TorProviderBase.
|
|
|
73
|
+ *
|
|
|
74
|
+ * This class allows providers to be implemented in Rust (or any other language
|
|
|
75
|
+ * that allows to implement XPCOM interfaces).
|
|
|
76
|
+ * All provider methods are expected to be async, but Rust does not support
|
|
|
77
|
+ * promises. Therefore, every method takes a torITorReplyCallback instead.
|
|
|
78
|
+ * The methods will not return any data (they will pass an empty string to
|
|
|
79
|
+ * onReply) unless documented. In that case, the argument will be a valid JSON
|
|
|
80
|
+ * string.
|
|
|
81
|
+ * Error messages are not machine-parseable.
|
|
|
82
|
+ *
|
|
|
83
|
+ * Providers also use the observer service for logs, the bootstrap status, for
|
|
|
84
|
+ * the data for the circuit display, and to notify a bridge change.
|
|
|
85
|
+ *
|
|
|
86
|
+ * This interface should not be used directly.
|
|
|
87
|
+ * Instead, it should use the OxidizedTorProvider _javascript_ class, that
|
|
|
88
|
+ * converts callbacks to promises, as well as arguments and returned values to
|
|
|
89
|
+ * types as documented in TorProvider.
|
|
|
90
|
+ */
|
|
|
91
|
+[scriptable, uuid(c01293cc-6eb8-4dcc-b45a-020b7ccf9563)]
|
|
|
92
|
+interface torITorProvider : nsISupports {
|
|
|
93
|
+ void close();
|
|
|
94
|
+ void setCloseHandler(in nsIRunnable handler);
|
|
|
95
|
+
|
|
|
96
|
+ /**
|
|
|
97
|
+ * Ask the provider to apply some bridge settings.
|
|
|
98
|
+ * If lines is an empty array, bridges will be disabled.
|
|
|
99
|
+ */
|
|
|
100
|
+ void writeBridgeSettings(in Array<ACString> lines,
|
|
|
101
|
+ in torITorReplyCallback callback);
|
|
|
102
|
+ void writeProxySettings(in torITorProxySettings settings,
|
|
|
103
|
+ in torITorReplyCallback callback);
|
|
|
104
|
+ /**
|
|
|
105
|
+ * Tell the provider that only some ports are reachable.
|
|
|
106
|
+ * If the array is empty, all ports will be considered reachable.
|
|
|
107
|
+ */
|
|
|
108
|
+ void writeFirewallSettings(in Array<unsigned short> ports,
|
|
|
109
|
+ in torITorReplyCallback callback);
|
|
|
110
|
+ void flushSettings(in torITorReplyCallback callback);
|
|
|
111
|
+ void connect(in torITorReplyCallback callback);
|
|
|
112
|
+ void stopBootstrap(in torITorReplyCallback callback);
|
|
|
113
|
+ void newnym(in torITorReplyCallback callback);
|
|
|
114
|
+ /**
|
|
|
115
|
+ * Return the available pluggable transports.
|
|
|
116
|
+ * It returns a JSON array of objects that can be converted to PTInfo with
|
|
|
117
|
+ * OxidationAdapters.convertPluggableTransports.
|
|
|
118
|
+ */
|
|
|
119
|
+ void getPluggableTransports(in torITorReplyCallback callback);
|
|
|
120
|
+ void onionAuthAdd(
|
|
|
121
|
+ in ACString address,
|
|
|
122
|
+ in ACString b64PrivateKey,
|
|
|
123
|
+ in boolean isPermanent,
|
|
|
124
|
+ in torITorReplyCallback callback
|
|
|
125
|
+ );
|
|
|
126
|
+ void onionAuthRemove(in ACString address, in torITorReplyCallback callback);
|
|
|
127
|
+ /**
|
|
|
128
|
+ * Return the private keys for authenticated Onion services.
|
|
|
129
|
+ * It returns a JSON array of objects that can be converted to
|
|
|
130
|
+ * OnionAuthKeyInfo with OxidationAdapters.convertOnionKeys.
|
|
|
131
|
+ */
|
|
|
132
|
+ void onionAuthViewKeys(in torITorReplyCallback callback);
|
|
|
133
|
+ /**
|
|
|
134
|
+ * The bridge currently in use.
|
|
|
135
|
+ * TODO: The format for this string has not been decided yet, and we might
|
|
|
136
|
+ * even define an XPCOM interface for it.
|
|
|
137
|
+ */
|
|
|
138
|
+ readonly attribute ACString currentBridge;
|
|
|
139
|
+};
|
|
|
140
|
+
|
|
|
141
|
+[scriptable, uuid(362cf37a-ba6c-4cff-b654-5ffaeb4d4a0c)]
|
|
|
142
|
+interface torITorProviderInitializationCallback : nsISupports {
|
|
|
143
|
+ void onSuccess(in torITorProvider provider);
|
|
|
144
|
+ void onError(in ACString message);
|
|
|
145
|
+};
|
|
|
146
|
+
|
|
53
|
147
|
[builtinclass, scriptable, uuid(2537313c-e120-408c-a2f6-86e6e1bdf899)]
|
|
54
|
148
|
interface torITorService : nsISupports {
|
|
55
|
149
|
// For development purposes...
|
|
56
|
150
|
torITorControlPort createControlPort(in ACString host, in long port);
|
|
57
|
151
|
torITorControlPort createControlPortIPC(in nsIFile socket);
|
|
|
152
|
+
|
|
|
153
|
+ void createProvider(in torITorProviderInitializationCallback callback);
|
|
58
|
154
|
}; |
toolkit/components/tor-integration/tor_service/Cargo.toml
| ... |
... |
@@ -19,6 +19,7 @@ xpcom = { path = "../../../../xpcom/rust/xpcom" } |
|
19
|
19
|
tor_provider = { path = "../tor_provider" }
|
|
20
|
20
|
|
|
21
|
21
|
bytes = "1.4.0"
|
|
|
22
|
+chrono = "0.4"
|
|
22
|
23
|
cstr = "0.2"
|
|
23
|
24
|
hex = "0.4.3"
|
|
24
|
25
|
log = "0.4"
|
toolkit/components/tor-integration/tor_service/src/plumbing.rs
| ... |
... |
@@ -2,12 +2,19 @@ |
|
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 nsstring::nsCString;
|
|
|
5
|
+use bytes::Bytes;
|
|
|
6
|
+use chrono::Utc;
|
|
|
7
|
+use nserror::{nsresult, NS_OK};
|
|
|
8
|
+use nsstring::{nsACString, nsCString};
|
|
6
|
9
|
use serde::Serialize;
|
|
7
|
10
|
use std::net::SocketAddr;
|
|
8
|
11
|
use tor_provider::ctor::*;
|
|
9
|
12
|
use xpcom::{interfaces::torITorReplyCallback, RefPtr};
|
|
10
|
13
|
|
|
|
14
|
+// These are used in implement() below, so they are actually used.
|
|
|
15
|
+#[allow(unused)]
|
|
|
16
|
+use xpcom::interfaces::{torITorBootstrapStatus, torITorLogEntry};
|
|
|
17
|
+
|
|
11
|
18
|
fn call_xpcom_callback<T>(res: Result<T, ControllerError>, callback: RefPtr<torITorReplyCallback>)
|
|
12
|
19
|
where
|
|
13
|
20
|
T: Serialize,
|
| ... |
... |
@@ -181,3 +188,89 @@ impl From<&PluggableTransport> for ExpandedPluggableTransport { |
|
181
|
188
|
}
|
|
182
|
189
|
}
|
|
183
|
190
|
}
|
|
|
191
|
+
|
|
|
192
|
+#[xpcom(implement(torITorLogEntry), atomic)]
|
|
|
193
|
+pub(crate) struct LogEntry {
|
|
|
194
|
+ severity: nsCString,
|
|
|
195
|
+ message: nsCString,
|
|
|
196
|
+ timestamp: nsCString,
|
|
|
197
|
+}
|
|
|
198
|
+
|
|
|
199
|
+impl LogEntry {
|
|
|
200
|
+ pub fn new(severity: String, message: Bytes) -> RefPtr<Self> {
|
|
|
201
|
+ let timestamp = Utc::now().format("%Y-%m-%d %H:%M:%S%.3f UTC").to_string();
|
|
|
202
|
+ Self::allocate(InitLogEntry {
|
|
|
203
|
+ severity: nsCString::from(severity),
|
|
|
204
|
+ message: nsCString::from(message.as_ref()),
|
|
|
205
|
+ timestamp: nsCString::from(timestamp),
|
|
|
206
|
+ })
|
|
|
207
|
+ }
|
|
|
208
|
+
|
|
|
209
|
+ xpcom_method!(get_severity => GetSeverity() -> nsACString);
|
|
|
210
|
+ fn get_severity(&self) -> Result<nsCString, nsresult> {
|
|
|
211
|
+ Ok(self.severity.clone())
|
|
|
212
|
+ }
|
|
|
213
|
+
|
|
|
214
|
+ xpcom_method!(get_message => GetMessage() -> nsACString);
|
|
|
215
|
+ fn get_message(&self) -> Result<nsCString, nsresult> {
|
|
|
216
|
+ Ok(self.message.clone())
|
|
|
217
|
+ }
|
|
|
218
|
+
|
|
|
219
|
+ xpcom_method!(get_timestamp => GetTimestamp() -> nsACString);
|
|
|
220
|
+ fn get_timestamp(&self) -> Result<nsCString, nsresult> {
|
|
|
221
|
+ Ok(self.timestamp.clone())
|
|
|
222
|
+ }
|
|
|
223
|
+}
|
|
|
224
|
+
|
|
|
225
|
+#[xpcom(implement(torITorBootstrapStatus), atomic)]
|
|
|
226
|
+pub(crate) struct BootstrapStatusXpcom {
|
|
|
227
|
+ progress: u8,
|
|
|
228
|
+ severity: nsCString,
|
|
|
229
|
+ tag: nsCString,
|
|
|
230
|
+ summary: nsCString,
|
|
|
231
|
+ reason: nsCString,
|
|
|
232
|
+ should_warn: bool,
|
|
|
233
|
+}
|
|
|
234
|
+
|
|
|
235
|
+impl BootstrapStatusXpcom {
|
|
|
236
|
+ pub fn new(status: &BootstrapStatus) -> RefPtr<Self> {
|
|
|
237
|
+ Self::allocate(InitBootstrapStatusXpcom {
|
|
|
238
|
+ progress: status.progress,
|
|
|
239
|
+ severity: nsCString::from(status.severity.to_string()),
|
|
|
240
|
+ tag: nsCString::from(status.tag.clone()),
|
|
|
241
|
+ summary: nsCString::from(status.summary.clone()),
|
|
|
242
|
+ reason: nsCString::from(status.reason.clone().unwrap_or_default()),
|
|
|
243
|
+ should_warn: status.should_warn,
|
|
|
244
|
+ })
|
|
|
245
|
+ }
|
|
|
246
|
+
|
|
|
247
|
+ xpcom_method!(get_progress => GetProgress() -> u8);
|
|
|
248
|
+ fn get_progress(&self) -> Result<u8, nsresult> {
|
|
|
249
|
+ Ok(self.progress)
|
|
|
250
|
+ }
|
|
|
251
|
+
|
|
|
252
|
+ xpcom_method!(get_severity => GetSeverity() -> nsACString);
|
|
|
253
|
+ fn get_severity(&self) -> Result<nsCString, nsresult> {
|
|
|
254
|
+ Ok(self.severity.clone())
|
|
|
255
|
+ }
|
|
|
256
|
+
|
|
|
257
|
+ xpcom_method!(get_tag => GetTag() -> nsACString);
|
|
|
258
|
+ fn get_tag(&self) -> Result<nsCString, nsresult> {
|
|
|
259
|
+ Ok(self.tag.clone())
|
|
|
260
|
+ }
|
|
|
261
|
+
|
|
|
262
|
+ xpcom_method!(get_summary => GetSummary() -> nsACString);
|
|
|
263
|
+ fn get_summary(&self) -> Result<nsCString, nsresult> {
|
|
|
264
|
+ Ok(self.summary.clone())
|
|
|
265
|
+ }
|
|
|
266
|
+
|
|
|
267
|
+ xpcom_method!(get_reason => GetReason() -> nsACString);
|
|
|
268
|
+ fn get_reason(&self) -> Result<nsCString, nsresult> {
|
|
|
269
|
+ Ok(self.reason.clone())
|
|
|
270
|
+ }
|
|
|
271
|
+
|
|
|
272
|
+ xpcom_method!(get_should_warn => GetShouldWarn() -> bool);
|
|
|
273
|
+ fn get_should_warn(&self) -> Result<bool, nsresult> {
|
|
|
274
|
+ Ok(self.should_warn)
|
|
|
275
|
+ }
|
|
|
276
|
+} |
toolkit/components/tor-integration/tor_service/src/service.rs
| ... |
... |
@@ -2,9 +2,9 @@ |
|
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 nserror::{nsresult, NS_ERROR_NULL_POINTER, NS_OK};
|
|
|
5
|
+use nserror::{nsresult, NS_ERROR_NOT_IMPLEMENTED, NS_ERROR_NULL_POINTER, NS_OK};
|
|
6
|
6
|
use nsstring::nsACString;
|
|
7
|
|
-use xpcom::interfaces::{nsIFile, torITorControlPort};
|
|
|
7
|
+use xpcom::interfaces::{nsIFile, torITorControlPort, torITorProviderInitializationCallback};
|
|
8
|
8
|
use xpcom::RefPtr;
|
|
9
|
9
|
|
|
10
|
10
|
use super::control_port::ControlPortXpcom;
|
| ... |
... |
@@ -49,6 +49,14 @@ impl TorService { |
|
49
|
49
|
cp.forget(unsafe { &mut *out });
|
|
50
|
50
|
Ok(())
|
|
51
|
51
|
}
|
|
|
52
|
+
|
|
|
53
|
+ xpcom_method!(create_provider => CreateProvider(callback: *const torITorProviderInitializationCallback));
|
|
|
54
|
+ fn create_provider(
|
|
|
55
|
+ &self,
|
|
|
56
|
+ _callback: &torITorProviderInitializationCallback,
|
|
|
57
|
+ ) -> Result<(), nsresult> {
|
|
|
58
|
+ Err(NS_ERROR_NOT_IMPLEMENTED)
|
|
|
59
|
+ }
|
|
52
|
60
|
}
|
|
53
|
61
|
|
|
54
|
62
|
// See toolkit/components/extensions/storage/webext_storage_bridge/src/lib.rs.
|
toolkit/components/tor-launcher/TorProviderBuilder.sys.mjs
| ... |
... |
@@ -4,6 +4,8 @@ |
|
4
|
4
|
|
|
5
|
5
|
const lazy = {};
|
|
6
|
6
|
ChromeUtils.defineESModuleGetters(lazy, {
|
|
|
7
|
+ OxidizedCtorProvider:
|
|
|
8
|
+ "moz-src:///toolkit/components/tor-integration/OxidizedTorProvider.sys.mjs",
|
|
7
|
9
|
TorProvider: "moz-src:///toolkit/components/tor-launcher/TorProvider.sys.mjs",
|
|
8
|
10
|
TorProviderMock:
|
|
9
|
11
|
"moz-src:///toolkit/components/tor-launcher/TorProviderMock.sys.mjs",
|
| ... |
... |
@@ -77,6 +79,7 @@ export const TorProviders = Object.freeze({ |
|
77
|
79
|
mock: "mock",
|
|
78
|
80
|
none: "none",
|
|
79
|
81
|
tor: "tor",
|
|
|
82
|
+ oxidizedctor: "oxidizedctor",
|
|
80
|
83
|
});
|
|
81
|
84
|
|
|
82
|
85
|
/**
|
| ... |
... |
@@ -236,6 +239,9 @@ export class TorProviderBuilder { |
|
236
|
239
|
case TorProviders.tor:
|
|
237
|
240
|
providerClass = lazy.TorProvider;
|
|
238
|
241
|
break;
|
|
|
242
|
+ case TorProviders.oxidizedctor:
|
|
|
243
|
+ providerClass = lazy.OxidizedCtorProvider;
|
|
|
244
|
+ break;
|
|
239
|
245
|
case TorProviders.none:
|
|
240
|
246
|
providerClass = lazy.TorProviderNone;
|
|
241
|
247
|
break;
|
| ... |
... |
@@ -396,7 +402,9 @@ export class TorProviderBuilder { |
|
396
|
402
|
this.#checkActive();
|
|
397
|
403
|
try {
|
|
398
|
404
|
await this.#providerData.initPromise;
|
|
399
|
|
- } catch {}
|
|
|
405
|
+ } catch (e) {
|
|
|
406
|
+ lazy.logger.error("The provider failed to initialize", e);
|
|
|
407
|
+ }
|
|
400
|
408
|
}
|
|
401
|
409
|
|
|
402
|
410
|
/**
|
|