summaryrefslogtreecommitdiffhomepage
path: root/mullvad-cli/src/cmds/obfuscation.rs
blob: b2aaaa1f6e62e4e3fa89a3ffa31b3528a3fd500b (plain)
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
use anyhow::Result;
use clap::Subcommand;
use mullvad_management_interface::MullvadProxyClient;
use mullvad_types::relay_constraints::{
    Constraint, ObfuscationSettings, SelectedObfuscation, Udp2TcpObfuscationSettings,
};

#[derive(Subcommand, Debug)]
pub enum Obfuscation {
    /// Get current obfuscation settings
    Get,

    /// Set obfuscation settings
    #[clap(subcommand)]
    Set(SetCommands),
}

#[derive(Subcommand, Debug, Clone)]
pub enum SetCommands {
    /// Specifies if obfuscation should be used with WireGuard connections.
    /// And if so, what obfuscation protocol it should use.
    Mode { mode: SelectedObfuscation },

    /// Specifies the config for the udp2tcp obfuscator.
    Udp2tcp {
        /// Port to use, or 'any'
        #[arg(long, short = 'p')]
        port: Constraint<u16>,
    },
}

impl Obfuscation {
    pub async fn handle(self) -> Result<()> {
        match self {
            Obfuscation::Get => {
                let mut rpc = MullvadProxyClient::new().await?;
                let obfuscation_settings = rpc.get_settings().await?.obfuscation_settings;
                println!(
                    "Obfuscation mode: {}",
                    obfuscation_settings.selected_obfuscation
                );
                println!("udp2tcp settings: {}", obfuscation_settings.udp2tcp);
                Ok(())
            }
            Obfuscation::Set(subcmd) => Self::set(subcmd).await,
        }
    }

    async fn set(subcmd: SetCommands) -> Result<()> {
        let mut rpc = MullvadProxyClient::new().await?;
        let current_settings = rpc.get_settings().await?.obfuscation_settings;

        match subcmd {
            SetCommands::Mode { mode } => {
                rpc.set_obfuscation_settings(ObfuscationSettings {
                    selected_obfuscation: mode,
                    ..current_settings
                })
                .await?;
            }
            SetCommands::Udp2tcp { port } => {
                rpc.set_obfuscation_settings(ObfuscationSettings {
                    udp2tcp: Udp2TcpObfuscationSettings { port },
                    ..current_settings
                })
                .await?;
            }
        }

        println!("Updated obfuscation settings");

        Ok(())
    }
}