Skip to content

Commit

Permalink
Add mullvad debug block-connection command
Browse files Browse the repository at this point in the history
  • Loading branch information
Serock3 committed Nov 23, 2023
1 parent 81f6d9c commit 7c0ef49
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 3 deletions.
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
9 changes: 8 additions & 1 deletion mullvad-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ enum Cli {
#[clap(subcommand)]
LockdownMode(lockdown::LockdownMode),

/// Debug commands used for internal testing of the app.
///
/// These commands will likely set the app in an invalid state, which is
/// used to test security under various edge cases.
#[clap(subcommand, hide = true)]
Debug(debug::DebugCommands),

/// Configure DNS servers to use when connected
#[clap(subcommand)]
Dns(dns::Dns),
Expand Down Expand Up @@ -70,7 +77,6 @@ enum Cli {
/// Manage relay and tunnel constraints
#[clap(subcommand)]
Relay(relay::Relay),

/// Manage Mullvad API access methods.
///
/// Access methods are used to connect to the the Mullvad API via one of
Expand Down Expand Up @@ -148,6 +154,7 @@ async fn main() -> Result<()> {
Cli::Bridge(cmd) => cmd.handle().await,
Cli::Connect { wait } => tunnel_state::connect(wait).await,
Cli::Reconnect { wait } => tunnel_state::reconnect(wait).await,
Cli::Debug(cmd) => cmd.handle().await,
Cli::Disconnect { wait } => tunnel_state::disconnect(wait).await,
Cli::AutoConnect(cmd) => cmd.handle().await,
Cli::BetaProgram(cmd) => cmd.handle().await,
Expand Down

0 comments on commit 7c0ef49

Please sign in to comment.