From be1395e6fad0fe536e4cefdfa5a1553885e97775 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20L=C3=B6nnhager?= Date: Wed, 27 Nov 2024 15:44:55 +0100 Subject: [PATCH] Make SNI hostname implicit --- mullvad-api/src/https_client_with_sni.rs | 18 ++++++------------ mullvad-api/src/lib.rs | 5 ----- mullvad-api/src/rest.rs | 2 -- 3 files changed, 6 insertions(+), 19 deletions(-) diff --git a/mullvad-api/src/https_client_with_sni.rs b/mullvad-api/src/https_client_with_sni.rs index bc0070dd390f..416f3f21410d 100644 --- a/mullvad-api/src/https_client_with_sni.rs +++ b/mullvad-api/src/https_client_with_sni.rs @@ -285,7 +285,6 @@ impl TryFrom for InnerConnectionMode { #[derive(Clone)] pub struct HttpsConnectorWithSni { inner: Arc>, - sni_hostname: Option, abort_notify: Arc, dns_resolver: Arc, #[cfg(target_os = "android")] @@ -302,7 +301,6 @@ pub type SocketBypassRequest = (RawFd, oneshot::Sender<()>); impl HttpsConnectorWithSni { pub fn new( - sni_hostname: Option, dns_resolver: Arc, #[cfg(target_os = "android")] socket_bypass_tx: Option>, ) -> (Self, HttpsConnectorWithSniHandle) { @@ -349,7 +347,6 @@ impl HttpsConnectorWithSni { ( HttpsConnectorWithSni { inner, - sni_hostname, abort_notify, dns_resolver, #[cfg(target_os = "android")] @@ -431,13 +428,6 @@ impl Service for HttpsConnectorWithSni { } fn call(&mut self, uri: Uri) -> Self::Future { - let sni_hostname = self - .sni_hostname - .clone() - .or_else(|| uri.host().map(str::to_owned)) - .ok_or_else(|| { - io::Error::new(io::ErrorKind::InvalidInput, "invalid url, missing host") - }); let inner = self.inner.clone(); let abort_notify = self.abort_notify.clone(); #[cfg(target_os = "android")] @@ -451,8 +441,12 @@ impl Service for HttpsConnectorWithSni { "invalid url, not https", )); } - - let hostname = sni_hostname?; + let Some(hostname) = uri.host().map(str::to_owned) else { + return Err(io::Error::new( + io::ErrorKind::InvalidInput, + "invalid url, missing host", + )); + }; let addr = Self::resolve_address(&*dns_resolver, uri).await?; // Loop until we have established a connection. This starts over if a new endpoint diff --git a/mullvad-api/src/lib.rs b/mullvad-api/src/lib.rs index 7746765ce736..62e5b58e8fdb 100644 --- a/mullvad-api/src/lib.rs +++ b/mullvad-api/src/lib.rs @@ -451,7 +451,6 @@ impl Runtime { connection_mode_provider: T, ) -> rest::MullvadRestHandle { let service = self.new_request_service( - Some(API.host().to_string()), connection_mode_provider, Arc::new(self.address_cache.clone()), #[cfg(target_os = "android")] @@ -466,7 +465,6 @@ impl Runtime { /// This is only to be used in test code pub fn static_mullvad_rest_handle(&self, hostname: String) -> rest::MullvadRestHandle { let service = self.new_request_service( - Some(hostname.clone()), ApiConnectionMode::Direct.into_provider(), Arc::new(self.address_cache.clone()), #[cfg(target_os = "android")] @@ -481,7 +479,6 @@ impl Runtime { /// Returns a new request service handle pub fn rest_handle(&self, dns_resolver: impl DnsResolver) -> rest::RequestServiceHandle { self.new_request_service( - None, ApiConnectionMode::Direct.into_provider(), Arc::new(dns_resolver), #[cfg(target_os = "android")] @@ -492,13 +489,11 @@ impl Runtime { /// Creates a new request service and returns a handle to it. fn new_request_service( &self, - sni_hostname: Option, connection_mode_provider: T, dns_resolver: Arc, #[cfg(target_os = "android")] socket_bypass_tx: Option>, ) -> rest::RequestServiceHandle { rest::RequestService::spawn( - sni_hostname, self.api_availability.clone(), connection_mode_provider, dns_resolver, diff --git a/mullvad-api/src/rest.rs b/mullvad-api/src/rest.rs index 5c2870515820..5b93eea31142 100644 --- a/mullvad-api/src/rest.rs +++ b/mullvad-api/src/rest.rs @@ -150,14 +150,12 @@ pub(crate) struct RequestService { impl RequestService { /// Constructs a new request service. pub fn spawn( - sni_hostname: Option, api_availability: ApiAvailability, connection_mode_provider: T, dns_resolver: Arc, #[cfg(target_os = "android")] socket_bypass_tx: Option>, ) -> RequestServiceHandle { let (connector, connector_handle) = HttpsConnectorWithSni::new( - sni_hostname, dns_resolver, #[cfg(target_os = "android")] socket_bypass_tx.clone(),