Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ native-tls-crate = { version = "0.2.10", optional = true, package = "native-tls"
tokio-native-tls = { version = "0.3.0", optional = true }

# rustls-tls
hyper-rustls = { version = "0.27.0", default-features = false, optional = true, features = ["http1", "tls12"] }
hyper-rustls = { git = "https://github.com/rustls/hyper-rustls.git", rev = "5e9b69b4128abfc147e8b6fa55977eac4c3f575c", default-features = false, optional = true, features = ["http1", "tls12"] }
rustls = { version = "0.23.4", optional = true, default-features = false, features = ["std", "tls12"] }
tokio-rustls = { version = "0.26", optional = true, default-features = false, features = ["tls12"] }
webpki-roots = { version = "1", optional = true }
Expand Down
16 changes: 16 additions & 0 deletions src/async_impl/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ struct Config {
tls_built_in_certs_native: bool,
#[cfg(feature = "__rustls")]
crls: Vec<CertificateRevocationList>,
#[cfg(feature = "__rustls")]
server_name_resolver: Arc<dyn hyper_rustls::ResolveServerName + Send + Sync>,
#[cfg(feature = "__tls")]
min_tls_version: Option<tls::Version>,
#[cfg(feature = "__tls")]
Expand Down Expand Up @@ -314,6 +316,8 @@ impl ClientBuilder {
identity: None,
#[cfg(feature = "__rustls")]
crls: vec![],
#[cfg(feature = "__rustls")]
server_name_resolver: Arc::new(hyper_rustls::DefaultServerNameResolver::default()),
#[cfg(feature = "__tls")]
min_tls_version: None,
#[cfg(feature = "__tls")]
Expand Down Expand Up @@ -665,6 +669,7 @@ impl ClientBuilder {
config.interface.as_deref(),
config.nodelay,
config.tls_info,
config.server_name_resolver,
)
}
#[cfg(feature = "__rustls")]
Expand Down Expand Up @@ -870,6 +875,7 @@ impl ClientBuilder {
config.interface.as_deref(),
config.nodelay,
config.tls_info,
config.server_name_resolver,
)
}
#[cfg(any(feature = "native-tls", feature = "__rustls",))]
Expand Down Expand Up @@ -1723,6 +1729,16 @@ impl ClientBuilder {
self
}

/// Sets the server name resolver. Defaults to `hyper_rustls::DefaultServerNameResolver`
///
/// This requires the `rustls-tls(-...)` Cargo feature enabled.
#[cfg(feature = "__rustls")]
#[cfg_attr(docsrs, doc(cfg(feature = "rustls-tls")))]
pub fn with_server_name_resolver(mut self, server_name_resolver: Arc<dyn hyper_rustls::ResolveServerName + Send + Sync>) -> ClientBuilder {
self.config.server_name_resolver = server_name_resolver;
self
}

/// Set that all sockets have `TCP_USER_TIMEOUT` set with the supplied duration.
///
/// This option controls how long transmitted data may remain unacknowledged before
Expand Down
15 changes: 8 additions & 7 deletions src/connect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ where {
interface: Option<&str>,
nodelay: bool,
tls_info: bool,
server_name_resolver: Arc<dyn hyper_rustls::ResolveServerName + Send + Sync>,
) -> ConnectorBuilder
where
T: Into<Option<IpAddr>>,
Expand Down Expand Up @@ -381,6 +382,7 @@ where {
http,
tls,
tls_proxy,
server_name_resolver,
},
proxies,
verbose: verbose::OFF,
Expand Down Expand Up @@ -494,6 +496,7 @@ enum Inner {
http: HttpConnector,
tls: Arc<rustls::ClientConfig>,
tls_proxy: Arc<rustls::ClientConfig>,
server_name_resolver: Arc<dyn hyper_rustls::ResolveServerName + Send + Sync>,
},
}

Expand Down Expand Up @@ -639,7 +642,7 @@ impl ConnectorService {
}
}
#[cfg(feature = "__rustls")]
Inner::RustlsTls { http, tls, .. } => {
Inner::RustlsTls { http, tls, server_name_resolver, .. } => {
let mut http = http.clone();

// Disable Nagle's algorithm for TLS handshake
Expand All @@ -649,7 +652,7 @@ impl ConnectorService {
http.set_nodelay(true);
}

let mut http = hyper_rustls::HttpsConnector::from((http, tls.clone()));
let mut http = hyper_rustls::HttpsConnector::new(http, tls.clone(), false, server_name_resolver);
let io = http.call(dst).await?;

if let hyper_rustls::MaybeHttpsStream::Https(stream) = io {
Expand Down Expand Up @@ -804,10 +807,9 @@ impl ConnectorService {
http,
tls,
tls_proxy,
server_name_resolver: name_resolver,
} => {
if dst.scheme() == Some(&Scheme::HTTPS) {
use rustls_pki_types::ServerName;
use std::convert::TryFrom;
use tokio_rustls::TlsConnector as RustlsConnector;

log::trace!("tunneling HTTPS over proxy");
Expand All @@ -830,9 +832,8 @@ impl ConnectorService {
// We don't wrap this again in an HttpsConnector since that uses Maybe,
// and we know this is definitely HTTPS.
let tunneled = tunnel.call(dst.clone()).await?;
let host = dst.host().ok_or("no host in url")?.to_string();
let server_name = ServerName::try_from(host.as_str().to_owned())
.map_err(|_| "Invalid Server Name")?;

let server_name = name_resolver.resolve(&dst)?;
let io = RustlsConnector::from(tls.clone())
.connect(server_name, TokioIo::new(tunneled))
.await?;
Expand Down
4 changes: 4 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,10 @@ pub use self::error::{Error, Result};
pub use self::into_url::IntoUrl;
pub use self::response::ResponseBuilderExt;

#[cfg(feature = "__rustls")]
#[cfg_attr(docsrs, doc(cfg(feature = "rustls-tls")))]
pub use hyper_rustls::ResolveServerName;

/// Shortcut method to quickly make a `GET` request.
///
/// See also the methods on the [`reqwest::Response`](./struct.Response.html)
Expand Down