diff options
| author | Linus Färnstrand <linus@mullvad.net> | 2019-04-24 16:23:14 +0200 |
|---|---|---|
| committer | Linus Färnstrand <linus@mullvad.net> | 2019-04-24 16:23:14 +0200 |
| commit | d07d62e752f55718dad05218504c208ea4c354bc (patch) | |
| tree | 9660b43d7c3faf28851497c43a56f2312293fa09 | |
| parent | 7fdc2f84a24ee25ab74dbfdfa000600034c78525 (diff) | |
| parent | cbad139a45bcd30d7fb84b2bc17e6898027c609d (diff) | |
| download | mullvadvpn-d07d62e752f55718dad05218504c208ea4c354bc.tar.xz mullvadvpn-d07d62e752f55718dad05218504c208ea4c354bc.zip | |
Merge branch 'misc-cleanup-before-bridges'
| -rw-r--r-- | mullvad-cli/src/cmds/tunnel.rs | 6 | ||||
| -rw-r--r-- | mullvad-daemon/src/relays.rs | 2 | ||||
| -rw-r--r-- | mullvad-types/src/relay_constraints.rs | 6 | ||||
| -rw-r--r-- | mullvad-types/src/settings.rs | 3 | ||||
| -rw-r--r-- | talpid-types/src/net/openvpn.rs | 90 |
5 files changed, 48 insertions, 59 deletions
diff --git a/mullvad-cli/src/cmds/tunnel.rs b/mullvad-cli/src/cmds/tunnel.rs index 2521a06838..592aef74df 100644 --- a/mullvad-cli/src/cmds/tunnel.rs +++ b/mullvad-cli/src/cmds/tunnel.rs @@ -392,7 +392,7 @@ impl Tunnel { let packed_proxy = openvpn::ProxySettings::Local(proxy); - if let Err(error) = openvpn::ProxySettingsValidation::validate(&packed_proxy) { + if let Err(error) = openvpn::validate_proxy_settings(&packed_proxy) { panic!(error); } @@ -421,7 +421,7 @@ impl Tunnel { let packed_proxy = openvpn::ProxySettings::Remote(proxy); - if let Err(error) = openvpn::ProxySettingsValidation::validate(&packed_proxy) { + if let Err(error) = openvpn::validate_proxy_settings(&packed_proxy) { panic!(error); } @@ -443,7 +443,7 @@ impl Tunnel { let packed_proxy = openvpn::ProxySettings::Shadowsocks(proxy); - if let Err(error) = openvpn::ProxySettingsValidation::validate(&packed_proxy) { + if let Err(error) = openvpn::validate_proxy_settings(&packed_proxy) { panic!(error); } diff --git a/mullvad-daemon/src/relays.rs b/mullvad-daemon/src/relays.rs index 2bc86ddc60..eac68588de 100644 --- a/mullvad-daemon/src/relays.rs +++ b/mullvad-daemon/src/relays.rs @@ -28,7 +28,7 @@ use log::{debug, error, info, warn}; use rand::{self, rngs::ThreadRng, seq::SliceRandom, Rng}; use tokio_timer::{TimeoutError, Timer}; -const DATE_TIME_FORMAT_STR: &str = "[%Y-%m-%d %H:%M:%S%.3f]"; +const DATE_TIME_FORMAT_STR: &str = "%Y-%m-%d %H:%M:%S%.3f"; const RELAYS_FILENAME: &str = "relays.json"; const DOWNLOAD_TIMEOUT: Duration = Duration::from_secs(15); /// How often the updater should wake up to check the cache of the in-memory cache of relays. diff --git a/mullvad-types/src/relay_constraints.rs b/mullvad-types/src/relay_constraints.rs index 23f0230c84..ba40243718 100644 --- a/mullvad-types/src/relay_constraints.rs +++ b/mullvad-types/src/relay_constraints.rs @@ -70,12 +70,6 @@ impl fmt::Display for RelaySettings { } } -impl Default for RelaySettings { - fn default() -> Self { - RelaySettings::Normal(RelayConstraints::default()) - } -} - impl RelaySettings { pub fn merge(&mut self, update: RelaySettingsUpdate) -> Self { match update { diff --git a/mullvad-types/src/settings.rs b/mullvad-types/src/settings.rs index 92b656bfa5..6a2d678db4 100644 --- a/mullvad-types/src/settings.rs +++ b/mullvad-types/src/settings.rs @@ -202,8 +202,7 @@ impl Settings { pub fn set_openvpn_proxy(&mut self, proxy: Option<openvpn::ProxySettings>) -> Result<bool> { if let Some(ref settings) = proxy { - openvpn::ProxySettingsValidation::validate(settings) - .map_err(Error::InvalidProxyData)?; + openvpn::validate_proxy_settings(settings).map_err(Error::InvalidProxyData)?; } if self.tunnel_options.openvpn.proxy != proxy { diff --git a/talpid-types/src/net/openvpn.rs b/talpid-types/src/net/openvpn.rs index 1bc774a8d6..4eaa2cb218 100644 --- a/talpid-types/src/net/openvpn.rs +++ b/talpid-types/src/net/openvpn.rs @@ -109,6 +109,15 @@ pub struct ShadowsocksProxySettings { pub cipher: String, } +impl ShadowsocksProxySettings { + pub fn get_endpoint(&self) -> Endpoint { + Endpoint { + address: self.peer, + protocol: TransportProtocol::Tcp, + } + } +} + pub static SHADOWSOCKS_CIPHERS: &[&str] = &[ // Stream ciphers. "aes-128-cfb", @@ -133,55 +142,42 @@ pub static SHADOWSOCKS_CIPHERS: &[&str] = &[ "aes-256-pmac-siv", ]; -impl ShadowsocksProxySettings { - pub fn get_endpoint(&self) -> Endpoint { - Endpoint { - address: self.peer, - protocol: TransportProtocol::Tcp, +pub fn validate_proxy_settings(proxy: &ProxySettings) -> Result<(), String> { + match proxy { + ProxySettings::Local(local) => { + if local.port == 0 { + return Err(String::from("Invalid local port number")); + } + if local.peer.ip().is_loopback() { + return Err(String::from( + "localhost is not a valid peer in this context", + )); + } + if local.peer.port() == 0 { + return Err(String::from("Invalid remote port number")); + } } - } -} - -pub struct ProxySettingsValidation; - -impl ProxySettingsValidation { - pub fn validate(proxy: &ProxySettings) -> Result<(), String> { - match proxy { - ProxySettings::Local(local) => { - if local.port == 0 { - return Err(String::from("Invalid local port number")); - } - if local.peer.ip().is_loopback() { - return Err(String::from( - "localhost is not a valid peer in this context", - )); - } - if local.peer.port() == 0 { - return Err(String::from("Invalid remote port number")); - } + ProxySettings::Remote(remote) => { + if remote.address.port() == 0 { + return Err(String::from("Invalid port number")); } - ProxySettings::Remote(remote) => { - if remote.address.port() == 0 { - return Err(String::from("Invalid port number")); - } - if remote.address.ip().is_loopback() { - return Err(String::from("localhost is not a valid remote server")); - } + if remote.address.ip().is_loopback() { + return Err(String::from("localhost is not a valid remote server")); } - ProxySettings::Shadowsocks(ss) => { - if ss.peer.ip().is_loopback() { - return Err(String::from( - "localhost is not a valid peer in this context", - )); - } - if ss.peer.port() == 0 { - return Err(String::from("Invalid remote port number")); - } - if !SHADOWSOCKS_CIPHERS.contains(&ss.cipher.as_str()) { - return Err(String::from("Invalid cipher")); - } + } + ProxySettings::Shadowsocks(ss) => { + if ss.peer.ip().is_loopback() { + return Err(String::from( + "localhost is not a valid peer in this context", + )); } - }; - Ok(()) - } + if ss.peer.port() == 0 { + return Err(String::from("Invalid remote port number")); + } + if !SHADOWSOCKS_CIPHERS.contains(&ss.cipher.as_str()) { + return Err(String::from("Invalid cipher")); + } + } + }; + Ok(()) } |
