diff options
| -rw-r--r-- | mullvad-cli/src/cmds/tunnel.rs | 249 |
1 files changed, 1 insertions, 248 deletions
diff --git a/mullvad-cli/src/cmds/tunnel.rs b/mullvad-cli/src/cmds/tunnel.rs index 6b4d02e605..136290d5bb 100644 --- a/mullvad-cli/src/cmds/tunnel.rs +++ b/mullvad-cli/src/cmds/tunnel.rs @@ -1,10 +1,7 @@ use crate::{new_rpc_client, Command, Result}; use clap::value_t; -use mullvad_types::{relay_constraints::BridgeSettings, settings::TunnelOptions}; -use talpid_types::net::openvpn::{self, SHADOWSOCKS_CIPHERS}; - -use std::net::{IpAddr, SocketAddr}; +use mullvad_types::settings::TunnelOptions; pub struct Tunnel; @@ -67,7 +64,6 @@ fn create_openvpn_subcommand() -> clap::App<'static, 'static> { .about("Manage options for OpenVPN tunnels") .setting(clap::AppSettings::SubcommandRequiredElseHelp) .subcommand(create_openvpn_mssfix_subcommand()) - .subcommand(create_openvpn_proxy_subcommand()) } fn create_openvpn_mssfix_subcommand() -> clap::App<'static, 'static> { @@ -81,97 +77,6 @@ fn create_openvpn_mssfix_subcommand() -> clap::App<'static, 'static> { ) } -fn create_openvpn_proxy_subcommand() -> clap::App<'static, 'static> { - clap::SubCommand::with_name("proxy") - .about("Configure a SOCKS5 proxy") - .setting(clap::AppSettings::SubcommandRequiredElseHelp) - .subcommand(clap::SubCommand::with_name("get")) - .subcommand(clap::SubCommand::with_name("unset")) - .subcommand( - clap::SubCommand::with_name("set") - .setting(clap::AppSettings::SubcommandRequiredElseHelp) - .subcommand( - clap::SubCommand::with_name("local") - .about("Registers a local SOCKS5 proxy") - .arg( - clap::Arg::with_name("local-port") - .help("Specifies the port the local proxy server is listening on") - .required(true) - .index(1), - ) - .arg( - clap::Arg::with_name("remote-ip") - .help("Specifies the IP of the proxy server peer") - .required(true) - .index(2), - ) - .arg( - clap::Arg::with_name("remote-port") - .help("Specifies the port of the proxy server peer") - .required(true) - .index(3), - ), - ) - .subcommand( - clap::SubCommand::with_name("remote") - .about("Registers a remote SOCKS5 proxy") - .arg( - clap::Arg::with_name("remote-ip") - .help("Specifies the IP of the remote proxy server") - .required(true) - .index(1), - ) - .arg( - clap::Arg::with_name("remote-port") - .help("Specifies the port the remote proxy server is listening on") - .required(true) - .index(2), - ) - .arg( - clap::Arg::with_name("username") - .help("Specifies the username for remote authentication") - .required(true) - .index(3), - ) - .arg( - clap::Arg::with_name("password") - .help("Specifies the password for remote authentication") - .required(true) - .index(4), - ), - ) - .subcommand( - clap::SubCommand::with_name("shadowsocks") - .about("Configure bundled Shadowsocks proxy") - .arg( - clap::Arg::with_name("remote-ip") - .help("Specifies the IP of the remote Shadowsocks server") - .required(true) - .index(1), - ) - .arg( - clap::Arg::with_name("remote-port") - .help("Specifies the port of the remote Shadowsocks server") - .default_value("443") - .index(2), - ) - .arg( - clap::Arg::with_name("password") - .help("Specifies the password on the remote Shadowsocks server") - .default_value("23#dfsbbb") - .index(3), - ) - .arg( - clap::Arg::with_name("cipher") - .help("Specifies the cipher to use") - .default_value("chacha20") - .possible_values(SHADOWSOCKS_CIPHERS) - .index(4), - ), - ), - ) -} - fn create_ipv6_subcommand() -> clap::App<'static, 'static> { clap::SubCommand::with_name("ipv6") .setting(clap::AppSettings::SubcommandRequiredElseHelp) @@ -190,7 +95,6 @@ impl Tunnel { fn handle_openvpn_cmd(matches: &clap::ArgMatches<'_>) -> Result<()> { match matches.subcommand() { ("mssfix", Some(mssfix_matches)) => Self::handle_openvpn_mssfix_cmd(mssfix_matches), - ("proxy", Some(proxy_matches)) => Self::handle_openvpn_proxy_cmd(proxy_matches), _ => unreachable!("unhandled command"), } } @@ -204,15 +108,6 @@ impl Tunnel { } } - fn handle_openvpn_proxy_cmd(matches: &clap::ArgMatches<'_>) -> Result<()> { - match matches.subcommand() { - ("get", Some(_)) => Self::process_openvpn_proxy_get(), - ("unset", Some(_)) => Self::process_openvpn_proxy_unset(), - ("set", Some(set_matches)) => Self::process_openvpn_proxy_set(set_matches), - _ => unreachable!("unhandled command"), - } - } - fn handle_wireguard_cmd(matches: &clap::ArgMatches<'_>) -> Result<()> { match matches.subcommand() { ("mtu", Some(matches)) => match matches.subcommand() { @@ -323,148 +218,6 @@ impl Tunnel { Ok(()) } - fn process_openvpn_proxy_get() -> Result<()> { - let mut rpc = new_rpc_client()?; - let settings = rpc.get_settings()?; - println!("Bridge state - {}", settings.get_bridge_state()); - match settings.get_bridge_settings() { - BridgeSettings::Custom(proxy) => { - match proxy { - openvpn::ProxySettings::Local(local_proxy) => { - Self::print_local_proxy(&local_proxy) - } - openvpn::ProxySettings::Remote(remote_proxy) => { - Self::print_remote_proxy(&remote_proxy) - } - openvpn::ProxySettings::Shadowsocks(shadowsocks_proxy) => { - Self::print_shadowsocks_proxy(&shadowsocks_proxy) - } - }; - } - BridgeSettings::Normal(constraints) => { - println!("Bridge constraitns: {}", constraints); - } - }; - Ok(()) - } - - fn print_local_proxy(proxy: &openvpn::LocalProxySettings) { - println!("proxy: local"); - println!(" local port: {}", proxy.port); - println!(" peer IP: {}", proxy.peer.ip()); - println!(" peer port: {}", proxy.peer.port()); - } - - fn print_remote_proxy(proxy: &openvpn::RemoteProxySettings) { - println!("proxy: remote"); - println!(" server IP: {}", proxy.address.ip()); - println!(" server port: {}", proxy.address.port()); - - if let Some(ref auth) = proxy.auth { - println!(" auth username: {}", auth.username); - println!(" auth password: {}", auth.password); - } else { - println!(" auth: none"); - } - } - - fn print_shadowsocks_proxy(proxy: &openvpn::ShadowsocksProxySettings) { - println!("proxy: Shadowsocks"); - println!(" peer IP: {}", proxy.peer.ip()); - println!(" peer port: {}", proxy.peer.port()); - println!(" password: {}", proxy.password); - println!(" cipher: {}", proxy.cipher); - } - - fn process_openvpn_proxy_unset() -> Result<()> { - let mut rpc = new_rpc_client()?; - rpc.set_bridge_settings(BridgeSettings::default())?; - println!("proxy details have been unset"); - Ok(()) - } - - fn process_openvpn_proxy_set(matches: &clap::ArgMatches<'_>) -> Result<()> { - if let Some(args) = matches.subcommand_matches("local") { - let local_port = - value_t!(args.value_of("local-port"), u16).unwrap_or_else(|e| e.exit()); - let remote_ip = - value_t!(args.value_of("remote-ip"), IpAddr).unwrap_or_else(|e| e.exit()); - let remote_port = - value_t!(args.value_of("remote-port"), u16).unwrap_or_else(|e| e.exit()); - - let proxy = openvpn::LocalProxySettings { - port: local_port, - peer: SocketAddr::new(remote_ip, remote_port), - }; - - let packed_proxy = openvpn::ProxySettings::Local(proxy); - - if let Err(error) = openvpn::validate_proxy_settings(&packed_proxy) { - panic!(error); - } - - let mut rpc = new_rpc_client()?; - rpc.set_bridge_settings(BridgeSettings::Custom(packed_proxy))?; - } else if let Some(args) = matches.subcommand_matches("remote") { - let remote_ip = - value_t!(args.value_of("remote-ip"), IpAddr).unwrap_or_else(|e| e.exit()); - let remote_port = - value_t!(args.value_of("remote-port"), u16).unwrap_or_else(|e| e.exit()); - let username = args.value_of("username"); - let password = args.value_of("password"); - - let auth = match (username, password) { - (Some(username), Some(password)) => Some(openvpn::ProxyAuth { - username: username.to_string(), - password: password.to_string(), - }), - _ => None, - }; - - let proxy = openvpn::RemoteProxySettings { - address: SocketAddr::new(remote_ip, remote_port), - auth, - }; - - let packed_proxy = openvpn::ProxySettings::Remote(proxy); - - if let Err(error) = openvpn::validate_proxy_settings(&packed_proxy) { - panic!(error); - } - - let mut rpc = new_rpc_client()?; - rpc.set_bridge_settings(BridgeSettings::Custom(packed_proxy))?; - } else if let Some(args) = matches.subcommand_matches("shadowsocks") { - let remote_ip = - value_t!(args.value_of("remote-ip"), IpAddr).unwrap_or_else(|e| e.exit()); - let remote_port = - value_t!(args.value_of("remote-port"), u16).unwrap_or_else(|e| e.exit()); - let password = args.value_of("password").unwrap().to_string(); - let cipher = args.value_of("cipher").unwrap().to_string(); - - let proxy = openvpn::ShadowsocksProxySettings { - peer: SocketAddr::new(remote_ip, remote_port), - password, - cipher, - }; - - let packed_proxy = openvpn::ProxySettings::Shadowsocks(proxy); - - if let Err(error) = openvpn::validate_proxy_settings(&packed_proxy) { - panic!(error); - } - - let mut rpc = new_rpc_client()?; - rpc.set_bridge_settings(BridgeSettings::Custom(packed_proxy))?; - } else { - unreachable!("unhandled proxy type"); - } - - println!("proxy details have been updated"); - println!("note: The OpenVPN tunnel constraints have been updated to use TCP"); - Ok(()) - } - fn process_ipv6_get() -> Result<()> { let tunnel_options = Self::get_tunnel_options()?; println!( |
