diff options
| author | Markus Pettersson <markus.pettersson@mullvad.net> | 2023-09-11 15:52:15 +0200 |
|---|---|---|
| committer | David Lönnhager <david.l@mullvad.net> | 2023-10-09 14:40:03 +0200 |
| commit | 2db6e2ecc64c0ddb9dba0b0947a31b0fbefe9f53 (patch) | |
| tree | 943d1a981f74d9fbe792eb5932532e247bcd668c /mullvad-api/src | |
| parent | c899c1b63858c12c9367318c19120fe899b31394 (diff) | |
| download | mullvadvpn-2db6e2ecc64c0ddb9dba0b0947a31b0fbefe9f53.tar.xz mullvadvpn-2db6e2ecc64c0ddb9dba0b0947a31b0fbefe9f53.zip | |
Code cleanup
- Add a new datastructures for distinguishing between built-in & custom
api access methods
- Implement `TryFrom` instead of `From` for fallible conversions
- Do not panic if a protobuf-message is ill-formatted
- Do not allow removal of built-in api access methods
- Refactor notification logic in `access_methods.rs`
- Rename `mullvad proxy api` to simply `mullvad proxy`
- Since there are no other kinds of proxies at the moment, the
subcommand `proxy api` does not make much sense.
- Remove left-over comments
Diffstat (limited to 'mullvad-api/src')
| -rw-r--r-- | mullvad-api/src/https_client_with_sni.rs | 13 | ||||
| -rw-r--r-- | mullvad-api/src/proxy.rs | 23 |
2 files changed, 22 insertions, 14 deletions
diff --git a/mullvad-api/src/https_client_with_sni.rs b/mullvad-api/src/https_client_with_sni.rs index 940bb249d4..5bffa3d32b 100644 --- a/mullvad-api/src/https_client_with_sni.rs +++ b/mullvad-api/src/https_client_with_sni.rs @@ -146,8 +146,6 @@ impl InnerConnectionMode { } /// Set up a SOCKS5-socket connection. - /// - /// TODO: Handle case where the proxy-address is `localhost`. async fn handle_socks_connection( proxy_config: SocksConfig, addr: &SocketAddr, @@ -223,9 +221,14 @@ impl TryFrom<ApiConnectionMode> for InnerConnectionMode { proxy_context: SsContext::new_shared(ServerType::Local), }) } - ProxyConfig::Socks(config) => { - InnerConnectionMode::Socks5(SocksConfig { peer: config.peer }) - } + ProxyConfig::Socks(config) => match config { + mullvad_types::api_access_method::Socks5::Local(config) => { + InnerConnectionMode::Socks5(SocksConfig { peer: config.peer }) + } + mullvad_types::api_access_method::Socks5::Remote(config) => { + InnerConnectionMode::Socks5(SocksConfig { peer: config.peer }) + } + }, }, }) } diff --git a/mullvad-api/src/proxy.rs b/mullvad-api/src/proxy.rs index c5c2426933..112a747f04 100644 --- a/mullvad-api/src/proxy.rs +++ b/mullvad-api/src/proxy.rs @@ -1,5 +1,6 @@ use futures::Stream; use hyper::client::connect::Connected; +use mullvad_types::api_access_method; use serde::{Deserialize, Serialize}; use std::{ fmt, io, @@ -8,9 +9,7 @@ use std::{ pin::Pin, task::{self, Poll}, }; -use talpid_types::{ - net::openvpn::ShadowsocksProxySettings, net::openvpn::SocksProxySettings, ErrorExt, -}; +use talpid_types::ErrorExt; use tokio::{ fs, io::{AsyncRead, AsyncWrite, AsyncWriteExt, ReadBuf}, @@ -18,7 +17,7 @@ use tokio::{ const CURRENT_CONFIG_FILENAME: &str = "api-endpoint.json"; -#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)] +#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)] pub enum ApiConnectionMode { /// Connect directly to the target. Direct, @@ -35,10 +34,10 @@ impl fmt::Display for ApiConnectionMode { } } -#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)] +#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)] pub enum ProxyConfig { - Shadowsocks(ShadowsocksProxySettings), - Socks(SocksProxySettings), + Shadowsocks(api_access_method::Shadowsocks), + Socks(api_access_method::Socks5), } impl fmt::Display for ProxyConfig { @@ -46,7 +45,10 @@ impl fmt::Display for ProxyConfig { match self { // TODO: Do not hardcode TCP ProxyConfig::Shadowsocks(ss) => write!(f, "Shadowsocks {}/TCP", ss.peer), - ProxyConfig::Socks(s) => write!(f, "Socks5 {}/TCP", s.peer), + ProxyConfig::Socks(socks) => match socks { + api_access_method::Socks5::Local(s) => write!(f, "Socks5 {}/TCP", s.peer), + api_access_method::Socks5::Remote(s) => write!(f, "Socks5 {}/TCP", s.peer), + }, } } } @@ -117,7 +119,10 @@ impl ApiConnectionMode { ApiConnectionMode::Direct => None, ApiConnectionMode::Proxied(proxy_config) => match proxy_config { ProxyConfig::Shadowsocks(ss) => Some(ss.peer), - ProxyConfig::Socks(s) => Some(s.peer), + ProxyConfig::Socks(socks) => match socks { + api_access_method::Socks5::Local(s) => Some(s.peer), + api_access_method::Socks5::Remote(s) => Some(s.peer), + }, }, } } |
