Skip to content

Commit

Permalink
Merge branch 'error-handling-wrong-hostname-435'
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkusPettersson98 committed Nov 23, 2023
2 parents 8f39758 + efdef80 commit ef8c2cf
Show file tree
Hide file tree
Showing 11 changed files with 264 additions and 152 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ Line wrap the file at 100 chars. Th

## [Unreleased]
### Added
- Add customizable relay lists to the CLI on desktop. Custom lists can be managed through
`mullvad custom-lists` and can be selected through `mullvad relay set` and `mullvad bridge set`.
- Add customizable relay lists to the CLI on desktop. Custom lists can be managed through `mullvad custom-lists` and can be selected through `mullvad relay set` and `mullvad bridge set`.
- Add custom lists to location selector in desktop app.
- Add custom API access methods to the CLI on desktop. Custom API access methods allow the user to
proxy API traffic through a peer before connecting to a tunnel. They are managed through
Expand All @@ -36,6 +35,7 @@ Line wrap the file at 100 chars. Th

### Changed
- Update Electron from 25.2.0 to 26.3.0.
- CLI command `mullvad relay set tunnel wireguard entry-location` changed to `mullvad relay set tunnel wireguard entry location`, as the `location` subcommand can now be swapped for `custom-list` to select entry relays using a custom list.

#### Android
- Migrate welcome view to compose.
Expand All @@ -59,6 +59,7 @@ Line wrap the file at 100 chars. Th
- Remove wireguard-go (userspace WireGuard) support.

### Fixed
- Validate that hostname matches correct server type for CLI commands `mullvad relay set location`, `mullvad bridge set location` and `mullvad relay set tunnel wireguard entry location`
- Show correct endpoint in CLI for custom relays.
- Lower risk of being rate limited.
- Fix error dialog when failing to write to console by handling the thrown error.
Expand Down
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion mullvad-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ path = "src/main.rs"
anyhow = "1.0"
chrono = { workspace = true }
clap = { workspace = true }
env_logger = { workspace = true }
futures = "0.3"
natord = "1.0.9"
itertools = "0.10"
Expand Down
21 changes: 10 additions & 11 deletions mullvad-cli/src/cmds/bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use mullvad_types::{
use std::net::{IpAddr, SocketAddr};
use talpid_types::net::openvpn::{self, SHADOWSOCKS_CIPHERS};

use super::{relay::find_relay_by_hostname, relay_constraints::LocationArgs};
use super::{relay::resolve_location_constraint, relay_constraints::LocationArgs};

#[derive(Subcommand, Debug)]
pub enum Bridge {
Expand Down Expand Up @@ -160,16 +160,15 @@ impl Bridge {
println!("Updated bridge state");
Ok(())
}
SetCommands::Location(location) => {
let countries = rpc.get_relay_locations().await?.countries;
let location =
if let Some(relay) = find_relay_by_hostname(&countries, &location.country) {
Constraint::Only(relay)
} else {
Constraint::from(location)
};
let location = location.map(LocationConstraint::Location);
Self::update_bridge_settings(&mut rpc, Some(location), None, None).await
SetCommands::Location(location_constraint_args) => {
let relay_filter = |relay: &mullvad_types::relay_list::Relay| {
relay.active && relay.endpoint_data == RelayEndpointData::Bridge
};
let location_constraint =
resolve_location_constraint(&mut rpc, location_constraint_args, relay_filter)
.await?
.map(LocationConstraint::from);
Self::update_bridge_settings(&mut rpc, Some(location_constraint), None, None).await
}
SetCommands::CustomList { custom_list_name } => {
let list =
Expand Down
57 changes: 36 additions & 21 deletions mullvad-cli/src/cmds/custom_list.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
use super::{
relay::{find_relay_by_hostname, get_filtered_relays},
relay_constraints::LocationArgs,
};
use anyhow::{anyhow, Result};
use super::{relay::resolve_location_constraint, relay_constraints::LocationArgs};
use anyhow::{anyhow, bail, Result};
use clap::Subcommand;
use mullvad_management_interface::MullvadProxyClient;
use mullvad_types::{
Expand Down Expand Up @@ -108,31 +105,49 @@ impl CustomList {
}

async fn add_location(name: String, location_args: LocationArgs) -> Result<()> {
let countries = get_filtered_relays().await?;
let location = find_relay_by_hostname(&countries, &location_args.country)
.map_or(Constraint::from(location_args), Constraint::Only)
.option()
.ok_or(anyhow!("\"any\" is not a valid location"))?;

let mut rpc = MullvadProxyClient::new().await?;

let mut list = find_list_by_name(&mut rpc, &name).await?;
list.locations.insert(location);
rpc.update_custom_list(list).await?;
// Don't filter out any hosts, i.e. allow adding even inactive ones
let relay_filter = |_: &_| true;
let location_constraint =
resolve_location_constraint(&mut rpc, location_args, relay_filter).await?;

match location_constraint {
Constraint::Any => bail!("\"any\" is not a valid location"),
Constraint::Only(location) => {
let mut list = find_list_by_name(&mut rpc, &name).await?;
if list.locations.insert(location) {
rpc.update_custom_list(list).await?;
println!("Location added to custom-list")
} else {
bail!("Provided location is already present in custom-list")
};
}
}

Ok(())
}

async fn remove_location(name: String, location_args: LocationArgs) -> Result<()> {
let location = Constraint::<GeographicLocationConstraint>::from(location_args)
.option()
.ok_or(anyhow!("\"any\" is not a valid location"))?;

let mut rpc = MullvadProxyClient::new().await?;

let mut list = find_list_by_name(&mut rpc, &name).await?;
list.locations.remove(&location);
rpc.update_custom_list(list).await?;
// Don't filter out any hosts, i.e. allow adding even inactive ones
let relay_filter = |_: &_| true;
let location_constraint =
resolve_location_constraint(&mut rpc, location_args, relay_filter).await?;

match location_constraint {
Constraint::Any => bail!("\"any\" is not a valid location"),
Constraint::Only(location) => {
let mut list = find_list_by_name(&mut rpc, &name).await?;
if list.locations.remove(&location) {
rpc.update_custom_list(list).await?;
println!("Location removed from custom-list")
} else {
bail!("Provided location was not present in custom-list")
};
}
}

Ok(())
}
Expand Down
40 changes: 40 additions & 0 deletions mullvad-cli/src/cmds/debug.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
use anyhow::Result;
use mullvad_management_interface::MullvadProxyClient;
use mullvad_types::relay_constraints::{Constraint, RelayConstraints, RelaySettings};

#[derive(clap::Subcommand, Debug)]
pub enum DebugCommands {
/// Block all internet connection by setting an invalid relay constraint.
BlockConnection,
}

impl DebugCommands {
pub async fn handle(self) -> Result<()> {
match self {
DebugCommands::BlockConnection => {
let mut rpc = MullvadProxyClient::new().await?;
let settings = rpc.get_settings().await?;

let relay_settings = settings.get_relay_settings();
let mut constraints = match relay_settings {
RelaySettings::Normal(normal) => normal,
RelaySettings::CustomTunnelEndpoint(_custom) => {
println!("Removing custom relay settings");
RelayConstraints::default()
}
};
constraints.location = Constraint::Only(
mullvad_types::relay_constraints::LocationConstraint::Location(
mullvad_types::relay_constraints::GeographicLocationConstraint::Country(
"xx".into(),
),
),
);
rpc.set_relay_settings(RelaySettings::Normal(constraints))
.await?;
eprintln!("WARNING: ENTERED BLOCKED MODE");
Ok(())
}
}
}
}
4 changes: 2 additions & 2 deletions mullvad-cli/src/cmds/mod.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use clap::builder::{PossibleValuesParser, TypedValueParser, ValueParser};
use std::io::stdin;
use std::ops::Deref;
use std::{io::stdin, ops::Deref};

pub mod account;
pub mod api_access;
pub mod auto_connect;
pub mod beta_program;
pub mod bridge;
pub mod custom_list;
pub mod debug;
pub mod dns;
pub mod import_settings;
pub mod lan;
Expand Down
Loading

0 comments on commit ef8c2cf

Please sign in to comment.