1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
|
use super::{
Error, TestContext, helpers,
helpers::{connect_and_wait, send_guest_probes},
};
use anyhow::{Context, ensure};
use mullvad_management_interface::MullvadProxyClient;
use mullvad_types::settings::{DefaultDnsOptions, DnsOptions, Settings};
use std::net::SocketAddr;
use test_macro::test_function;
use test_rpc::ServiceClient;
/// Verify that traffic to private IPs is blocked when
/// "local network sharing" is disabled, but not blocked
/// when it is enabled.
/// It only checks whether outgoing UDP, TCP, and ICMP is
/// blocked for a single arbitrary private IP and port.
#[test_function]
pub async fn test_lan(
_: TestContext,
rpc: ServiceClient,
mut mullvad_client: MullvadProxyClient,
) -> Result<(), Error> {
// Take care not to use some bogus IP in the guest's subnet, lest we just send ARP requests
// These will fail if there's no actual host present
let lan_destination = "10.1.2.3:1234".parse().unwrap();
// Disable LAN sharing
//
log::info!("LAN sharing: disabled");
mullvad_client
.set_allow_lan(false)
.await
.expect("failed to disable LAN sharing");
// Connect
//
connect_and_wait(&mut mullvad_client).await?;
// Ensure LAN is not reachable
//
log::info!("Test whether outgoing LAN traffic is blocked");
let default_interface = rpc.get_default_interface().await?;
let detected_probes =
send_guest_probes(rpc.clone(), default_interface.clone(), lan_destination).await;
assert!(
detected_probes.none(),
"observed unexpected outgoing LAN packets: {detected_probes:?}"
);
// Enable LAN sharing
//
log::info!("LAN sharing: enabled");
mullvad_client
.set_allow_lan(true)
.await
.expect("failed to enable LAN sharing");
// Ensure LAN is reachable
//
log::info!("Test whether outgoing LAN traffic is blocked");
let detected_probes = send_guest_probes(rpc.clone(), default_interface, lan_destination).await;
assert!(
detected_probes.all(),
"did not observe all outgoing LAN packets: {detected_probes:?}"
);
Ok(())
}
/// Enable lockdown mode. This test succeeds if:
///
/// * Disconnected state: Outgoing traffic leaks (UDP/TCP/ICMP) cannot be produced.
/// * Disconnected state: Outgoing traffic to a single private IP can be produced, if and only if
/// LAN sharing is enabled.
/// * Connected state: Outgoing traffic leaks (UDP/TCP/ICMP) cannot be produced.
///
/// # Limitations
///
/// These tests are performed on one single public IP address
/// and one private IP address. They detect basic leaks but
/// do not guarantee close conformity with the security
/// document.
#[test_function]
pub async fn test_lockdown(
_: TestContext,
rpc: ServiceClient,
mut mullvad_client: MullvadProxyClient,
) -> Result<(), Error> {
// Take care not to use some bogus IP in the guest's subnet, lest we just send ARP requests
// These will fail if there's no actual host present
let lan_destination = "10.1.2.3:1234".parse().unwrap();
let inet_destination: SocketAddr = "1.1.1.1:1337".parse().unwrap();
// Disable LAN sharing
//
log::info!("LAN sharing: disabled");
mullvad_client
.set_allow_lan(false)
.await
.expect("failed to disable LAN sharing");
// Enable lockdown mode
//
mullvad_client
.set_lockdown_mode(true)
.await
.expect("failed to enable lockdown mode");
// Ensure all destinations are unreachable
//
let default_interface = rpc.get_default_interface().await?;
let detected_probes =
send_guest_probes(rpc.clone(), default_interface.clone(), lan_destination).await;
assert!(
detected_probes.none(),
"observed outgoing packets to LAN: {detected_probes:?}"
);
let detected_probes =
send_guest_probes(rpc.clone(), default_interface.clone(), inet_destination).await;
assert!(
detected_probes.none(),
"observed outgoing packets to internet: {detected_probes:?}"
);
// Enable LAN sharing
//
log::info!("LAN sharing: enabled");
mullvad_client
.set_allow_lan(true)
.await
.expect("failed to enable LAN sharing");
// Ensure private IPs are reachable, but not others
//
let detected_probes =
send_guest_probes(rpc.clone(), default_interface.clone(), lan_destination).await;
assert!(
detected_probes.all(),
"did not observe some outgoing packets: {detected_probes:?}"
);
let detected_probes =
send_guest_probes(rpc.clone(), default_interface.clone(), inet_destination).await;
assert!(
detected_probes.none(),
"observed outgoing packets to internet: {detected_probes:?}"
);
// Connect
//
connect_and_wait(&mut mullvad_client).await?;
// Leak test
//
assert!(
helpers::using_mullvad_exit(&rpc).await,
"expected Mullvad exit IP"
);
// Send traffic outside the tunnel to sanity check that the internet is *not* reachable via non-
// tunnel interfaces.
let detected_probes = send_guest_probes(rpc.clone(), default_interface, inet_destination).await;
assert!(
detected_probes.none(),
"observed outgoing packets to internet: {detected_probes:?}"
);
Ok(())
}
/// Reset settings to their default values.
///
/// The account should still be logged in after resetting settings.
#[test_function]
pub async fn test_reset_settings(
_: TestContext,
_: ServiceClient,
mut mullvad_client: MullvadProxyClient,
) -> anyhow::Result<()> {
// Change some settings to non-default values.
{
let err = "Failed to generate random settings";
mullvad_client.set_allow_lan(true).await.context(err)?;
mullvad_client
.set_dns_options(DnsOptions {
default_options: DefaultDnsOptions::new().block_ads().block_malware(),
..Default::default()
})
.await
.context(err)?;
mullvad_client.set_lockdown_mode(true).await.context(err)?;
}
// Note: We do not double-check that the daemon reports these settings changes. We trust other
// E2E tests to cover this.
// Soft-reset settings by invoking the `reset-settings` rpc.
mullvad_client
.reset_settings()
.await
.context("Failed to reset settings")?;
// Check that all changed settings have indeed been reset.
let daemon = mullvad_client
.get_settings()
.await
.context("Failed to get settings")?;
let default = Settings::default();
// Santiy-check that data that shouldn't have been touched have indeed been kept intact.
// Are we still logged in?
// Are the custom lists intact?
ensure!(
mullvad_client.get_account_history().await?.is_some(),
"Logged out after reset settings RPC"
);
// Note: We can not compare `daemon` with `default` directly because Settings::default is
// non-deterministic ..
ensure!(
daemon.lockdown_mode == default.lockdown_mode,
"Lockdown mode was not reset"
);
ensure!(
daemon.allow_lan == default.allow_lan,
"Lockdown mode was not reset"
);
ensure!(
daemon.tunnel_options == default.tunnel_options,
"Lockdown mode was not reset"
);
// TODO: check other data as well, such as log files. Do this after having written such a test
// first.
Ok(())
}
|