Skip to content

Commit bf4fc6d

Browse files
Merge branch 'add-api-access-method-daemon-tests-des-607'
2 parents 110e037 + 6980530 commit bf4fc6d

File tree

29 files changed

+368
-100
lines changed

29 files changed

+368
-100
lines changed

.github/workflows/cargo-audit.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,5 @@ jobs:
3737
# Ignored audit issues. This list should be kept short, and effort should be
3838
# put into removing items from the list.
3939
# RUSTSEC-2023-0057,RUSTSEC-2023-0058 - Unsoundness in `inventory`.
40-
ignore: RUSTSEC-2023-0057,RUSTSEC-2023-0058
40+
# RUSTSEC-2023-0079 - KyberSlash in `pqc_kyber`.
41+
ignore: RUSTSEC-2023-0057,RUSTSEC-2023-0058,RUSTSEC-2023-0079

Cargo.lock

+13-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+9-8
Original file line numberDiff line numberDiff line change
@@ -11,31 +11,32 @@ members = [
1111
"android/translations-converter",
1212
"ios/MullvadREST/Transport/Shadowsocks/shadowsocks-proxy",
1313
"ios/TunnelObfuscation/tunnel-obfuscator-proxy",
14-
"mullvad-daemon",
14+
"mullvad-api",
1515
"mullvad-cli",
16+
"mullvad-daemon",
17+
"mullvad-exclude",
1618
"mullvad-fs",
17-
"mullvad-setup",
18-
"mullvad-problem-report",
1919
"mullvad-jni",
20+
"mullvad-management-interface",
21+
"mullvad-nsis",
2022
"mullvad-paths",
23+
"mullvad-problem-report",
2124
"mullvad-relay-selector",
25+
"mullvad-setup",
2226
"mullvad-types",
23-
"mullvad-api",
24-
"mullvad-exclude",
2527
"mullvad-version",
26-
"mullvad-nsis",
27-
"talpid-openvpn-plugin",
2828
"talpid-core",
2929
"talpid-dbus",
30+
"talpid-future",
3031
"talpid-openvpn",
32+
"talpid-openvpn-plugin",
3133
"talpid-platform-metadata",
3234
"talpid-routing",
3335
"talpid-time",
3436
"talpid-tunnel",
3537
"talpid-tunnel-config-client",
3638
"talpid-windows",
3739
"talpid-wireguard",
38-
"mullvad-management-interface",
3940
"tunnel-obfuscation",
4041
]
4142

gui/test/e2e/installed/state-dependent/api-access-methods.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ test('App should edit access method', async () => {
125125
await inputs.nth(3).fill(process.env.SHADOWSOCKS_SERVER_PASSWORD!);
126126

127127
await page.getByTestId('ciphers').click();
128-
await page.getByRole('option', { name: process.env.SHADOWSOCKS_SERVER_CIPHER! }).click();
128+
await page.getByRole('option', { name: process.env.SHADOWSOCKS_SERVER_CIPHER!, exact: true }).click();
129129

130130
expect(
131131
await util.waitForNavigation(async () => await saveButton.click())

mullvad-api/src/lib.rs

+47-22
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,13 @@ impl<T> Deref for LazyManual<T> {
104104
}
105105
}
106106

107+
pub mod env {
108+
pub const API_HOST_VAR: &str = "MULLVAD_API_HOST";
109+
pub const API_ADDR_VAR: &str = "MULLVAD_API_ADDR";
110+
pub const API_FORCE_DIRECT_VAR: &str = "MULLVAD_API_FORCE_DIRECT";
111+
pub const DISABLE_TLS_VAR: &str = "MULLVAD_API_DISABLE_TLS";
112+
}
113+
107114
/// A hostname and socketaddr to reach the Mullvad REST API over.
108115
#[derive(Debug)]
109116
pub struct ApiEndpoint {
@@ -128,17 +135,30 @@ pub struct ApiEndpoint {
128135
pub disable_address_cache: bool,
129136
#[cfg(feature = "api-override")]
130137
pub disable_tls: bool,
138+
#[cfg(feature = "api-override")]
139+
/// Whether bridges/proxies can be used to access the API or not. This is
140+
/// useful primarily for testing purposes.
141+
///
142+
/// * If `force_direct` is `true`, bridges and proxies will not be used to
143+
/// reach the API.
144+
/// * If `force_direct` is `false`, bridges and proxies can be used to reach the API.
145+
///
146+
/// # Note
147+
///
148+
/// By default, `force_direct` will be `true` if the `api-override` feature
149+
/// is enabled. This is supposedely less error prone, as common targets such
150+
/// as Devmole might be unreachable from behind a bridge server.
151+
///
152+
/// To disable `force_direct`, set the environment variable
153+
/// `MULLVAD_API_FORCE_DIRECT=0` before starting the daemon.
154+
pub force_direct: bool,
131155
}
132156

133157
impl ApiEndpoint {
134158
const API_HOST_DEFAULT: &'static str = "api.mullvad.net";
135159
const API_IP_DEFAULT: IpAddr = IpAddr::V4(Ipv4Addr::new(45, 83, 223, 196));
136160
const API_PORT_DEFAULT: u16 = 443;
137161

138-
const API_HOST_VAR: &'static str = "MULLVAD_API_HOST";
139-
const API_ADDR_VAR: &'static str = "MULLVAD_API_ADDR";
140-
const DISABLE_TLS_VAR: &'static str = "MULLVAD_API_DISABLE_TLS";
141-
142162
/// Returns the endpoint to connect to the API over.
143163
///
144164
/// # Panics
@@ -147,15 +167,19 @@ impl ApiEndpoint {
147167
/// `MULLVAD_API_DISABLE_TLS` has invalid contents.
148168
#[cfg(feature = "api-override")]
149169
pub fn from_env_vars() -> ApiEndpoint {
150-
let host_var = Self::read_var(ApiEndpoint::API_HOST_VAR);
151-
let address_var = Self::read_var(ApiEndpoint::API_ADDR_VAR);
152-
let disable_tls_var = Self::read_var(ApiEndpoint::DISABLE_TLS_VAR);
170+
let host_var = Self::read_var(env::API_HOST_VAR);
171+
let address_var = Self::read_var(env::API_ADDR_VAR);
172+
let disable_tls_var = Self::read_var(env::DISABLE_TLS_VAR);
173+
let force_direct = Self::read_var(env::API_FORCE_DIRECT_VAR);
153174

154175
let mut api = ApiEndpoint {
155176
host: None,
156177
address: None,
157178
disable_address_cache: true,
158179
disable_tls: false,
180+
force_direct: force_direct
181+
.map(|force_direct_env| force_direct_env.to_lowercase() != "0")
182+
.unwrap_or(true),
159183
};
160184

161185
match (host_var, address_var) {
@@ -164,8 +188,8 @@ impl ApiEndpoint {
164188
use std::net::ToSocketAddrs;
165189
log::debug!(
166190
"{api_addr} not found. Resolving API IP address from {api_host}={host}",
167-
api_addr = ApiEndpoint::API_ADDR_VAR,
168-
api_host = ApiEndpoint::API_HOST_VAR
191+
api_addr = env::API_ADDR_VAR,
192+
api_host = env::API_HOST_VAR
169193
);
170194
api.address = format!("{}:{}", host, ApiEndpoint::API_PORT_DEFAULT)
171195
.to_socket_addrs()
@@ -181,7 +205,7 @@ impl ApiEndpoint {
181205
let addr = address.parse().unwrap_or_else(|_| {
182206
panic!(
183207
"{api_addr}={address} is not a valid socketaddr",
184-
api_addr = ApiEndpoint::API_ADDR_VAR,
208+
api_addr = env::API_ADDR_VAR,
185209
)
186210
});
187211
api.address = Some(addr);
@@ -193,9 +217,9 @@ impl ApiEndpoint {
193217
if disable_tls_var.is_some() {
194218
log::warn!(
195219
"{disable_tls} is ignored since {api_host} and {api_addr} are not set",
196-
disable_tls = ApiEndpoint::DISABLE_TLS_VAR,
197-
api_host = ApiEndpoint::API_HOST_VAR,
198-
api_addr = ApiEndpoint::API_ADDR_VAR,
220+
disable_tls = env::DISABLE_TLS_VAR,
221+
api_host = env::API_HOST_VAR,
222+
api_addr = env::API_ADDR_VAR,
199223
);
200224
}
201225
} else {
@@ -226,16 +250,17 @@ impl ApiEndpoint {
226250
/// `MULLVAD_API_DISABLE_TLS` has invalid contents.
227251
#[cfg(not(feature = "api-override"))]
228252
pub fn from_env_vars() -> ApiEndpoint {
229-
let host_var = Self::read_var(ApiEndpoint::API_HOST_VAR);
230-
let address_var = Self::read_var(ApiEndpoint::API_ADDR_VAR);
231-
let disable_tls_var = Self::read_var(ApiEndpoint::DISABLE_TLS_VAR);
232-
233-
if host_var.is_some() || address_var.is_some() || disable_tls_var.is_some() {
253+
let env_vars = [
254+
env::API_HOST_VAR,
255+
env::API_ADDR_VAR,
256+
env::DISABLE_TLS_VAR,
257+
env::API_FORCE_DIRECT_VAR,
258+
];
259+
260+
if env_vars.map(Self::read_var).iter().any(Option::is_some) {
234261
log::warn!(
235-
"These variables are ignored in production builds: {api_host}, {api_addr}, {disable_tls}",
236-
api_host = ApiEndpoint::API_HOST_VAR,
237-
api_addr = ApiEndpoint::API_ADDR_VAR,
238-
disable_tls = ApiEndpoint::DISABLE_TLS_VAR
262+
"These variables are ignored in production builds: {env_vars_pretty}",
263+
env_vars_pretty = env_vars.join(", ")
239264
);
240265
}
241266

mullvad-daemon/Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,10 @@ mullvad-api = { path = "../mullvad-api" }
3434
mullvad-fs = { path = "../mullvad-fs" }
3535
mullvad-version = { path = "../mullvad-version" }
3636
talpid-core = { path = "../talpid-core" }
37-
talpid-types = { path = "../talpid-types" }
37+
talpid-future = { path = "../talpid-future" }
3838
talpid-platform-metadata = { path = "../talpid-platform-metadata" }
3939
talpid-time = { path = "../talpid-time" }
40+
talpid-types = { path = "../talpid-types" }
4041

4142
[target.'cfg(not(target_os="android"))'.dependencies]
4243
clap = { workspace = true }

mullvad-daemon/src/api.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -328,10 +328,7 @@ impl AccessModeSelector {
328328
#[cfg(feature = "api-override")]
329329
{
330330
use mullvad_api::API;
331-
// If the API address has been explicitly overridden, it should
332-
// always be used. This implies that a direct API connection mode is
333-
// used.
334-
if API.address.is_some() {
331+
if API.force_direct {
335332
log::debug!("API proxies are disabled");
336333
let endpoint = resolve_allowed_endpoint(
337334
&ApiConnectionMode::Direct,
@@ -350,8 +347,8 @@ impl AccessModeSelector {
350347
}
351348

352349
log::debug!(
353-
"The `api-override` feature is enabled, but the API address \
354-
was not overridden. Selecting API access methods as normal"
350+
"The `api-override` feature is enabled, but a direct connection \
351+
is not enforced. Selecting API access methods as normal"
355352
);
356353
}
357354

mullvad-daemon/src/device/service.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use mullvad_api::{
1717
rest::{self, MullvadRestHandle},
1818
AccountsProxy, DevicesProxy,
1919
};
20-
use talpid_core::future_retry::{retry_future, ConstantInterval, ExponentialBackoff, Jittered};
20+
use talpid_future::retry::{retry_future, ConstantInterval, ExponentialBackoff, Jittered};
2121
/// Retry strategy used for user-initiated actions that require immediate feedback
2222
const RETRY_ACTION_STRATEGY: ConstantInterval = ConstantInterval::new(Duration::ZERO, Some(3));
2323
/// Retry strategy used for background tasks

mullvad-daemon/src/geoip.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@ use mullvad_api::{
77
};
88
use mullvad_types::location::{AmIMullvad, GeoIpLocation, LocationEventData};
99
use once_cell::sync::Lazy;
10-
use talpid_core::{
11-
future_retry::{retry_future, ExponentialBackoff, Jittered},
12-
mpsc::Sender,
13-
};
10+
use talpid_core::mpsc::Sender;
11+
use talpid_future::retry::{retry_future, ExponentialBackoff, Jittered};
1412
use talpid_types::ErrorExt;
1513

1614
use crate::{DaemonEventSender, InternalDaemonEvent};

mullvad-daemon/src/version_check.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ use std::{
1515
str::FromStr,
1616
time::Duration,
1717
};
18-
use talpid_core::{future_retry::ConstantInterval, mpsc::Sender};
18+
use talpid_core::mpsc::Sender;
19+
use talpid_future::retry::{retry_future, ConstantInterval};
1920
use talpid_types::ErrorExt;
2021
use tokio::fs::{self, File};
2122

@@ -193,7 +194,7 @@ impl VersionUpdater {
193194
.map_err(Error::Download)
194195
};
195196

196-
Box::pin(talpid_core::future_retry::retry_future(
197+
Box::pin(retry_future(
197198
download_future_factory,
198199
move |result| Self::should_retry_immediate(result, &api_handle),
199200
IMMEDIATE_RETRY_STRATEGY,
@@ -233,7 +234,7 @@ impl VersionUpdater {
233234
}
234235
};
235236

236-
Box::pin(talpid_core::future_retry::retry_future(
237+
Box::pin(retry_future(
237238
download_future_factory,
238239
|result| result.is_err(),
239240
std::iter::repeat(UPDATE_INTERVAL_ERROR),

mullvad-relay-selector/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ rand = "0.8.5"
2121
serde_json = "1.0"
2222
tokio = { workspace = true, features = ["fs", "io-util", "time"] }
2323

24-
talpid-core = { path = "../talpid-core" }
24+
talpid-future = { path = "../talpid-future" }
2525
talpid-types = { path = "../talpid-types" }
2626
mullvad-api = { path = "../mullvad-api" }
2727
mullvad-types = { path = "../mullvad-types" }

mullvad-relay-selector/src/updater.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use std::{
1212
sync::Arc,
1313
time::{Duration, SystemTime, UNIX_EPOCH},
1414
};
15-
use talpid_core::future_retry::{retry_future, ExponentialBackoff, Jittered};
15+
use talpid_future::retry::{retry_future, ExponentialBackoff, Jittered};
1616
use talpid_types::ErrorExt;
1717
use tokio::fs::File;
1818

mullvad-setup/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,5 @@ mullvad-api = { path = "../mullvad-api" }
3030
mullvad-types = { path = "../mullvad-types" }
3131
mullvad-version = { path = "../mullvad-version" }
3232
talpid-core = { path = "../talpid-core" }
33+
talpid-future = { path = "../talpid-future" }
3334
talpid-types = { path = "../talpid-types" }

mullvad-setup/src/main.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
use clap::Parser;
2+
use once_cell::sync::Lazy;
3+
use std::{path::PathBuf, process, str::FromStr, time::Duration};
4+
25
use mullvad_api::{self, proxy::ApiConnectionMode, DEVICE_NOT_FOUND};
36
use mullvad_management_interface::MullvadProxyClient;
47
use mullvad_types::version::ParsedAppVersion;
5-
use once_cell::sync::Lazy;
6-
use std::{path::PathBuf, process, str::FromStr, time::Duration};
7-
use talpid_core::{
8-
firewall::{self, Firewall},
9-
future_retry::{retry_future, ConstantInterval},
10-
};
8+
use talpid_core::firewall::{self, Firewall};
9+
use talpid_future::retry::{retry_future, ConstantInterval};
1110
use talpid_types::ErrorExt;
1211

1312
static APP_VERSION: Lazy<ParsedAppVersion> =

0 commit comments

Comments
 (0)