diff --git a/Cargo.toml b/Cargo.toml index ecc2d98..6ba4cea 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,6 +18,7 @@ default = ["tls", "cookies"] json = ["serde_json"] charset = ["encoding"] tls = ["rustls", "webpki", "webpki-roots"] +native-certs = ["rustls-native-certs"] cookies = ["cookie"] [dependencies] @@ -30,5 +31,6 @@ url = "2" rustls = { version = "0.17", optional = true, features = [] } webpki = { version = "0.21", optional = true } webpki-roots = { version = "0.19", optional = true } +rustls-native-certs = { version = "0.3", optional = true } serde_json = { version = "1", optional = true } encoding = { version = "0.2", optional = true } diff --git a/src/stream.rs b/src/stream.rs index d6ca2be..a6b0d45 100644 --- a/src/stream.rs +++ b/src/stream.rs @@ -129,6 +129,17 @@ pub(crate) fn connect_http(unit: &Unit) -> Result { connect_host(unit, hostname, port).map(Stream::Http) } +#[cfg(all(feature = "tls", feature = "native-certs"))] +fn configure_certs(config: &mut rustls::ClientConfig) { + config.root_store = rustls_native_certs::load_native_certs() + .expect("Could not load patform certs"); +} + +#[cfg(all(feature = "tls", not(feature = "native-certs")))] +fn configure_certs(config: &mut rustls::ClientConfig) { + config.root_store.add_server_trust_anchors(&webpki_roots::TLS_SERVER_ROOTS); +} + #[cfg(feature = "tls")] pub(crate) fn connect_https(unit: &Unit) -> Result { use lazy_static::lazy_static; @@ -137,9 +148,7 @@ pub(crate) fn connect_https(unit: &Unit) -> Result { lazy_static! { static ref TLS_CONF: Arc = { let mut config = rustls::ClientConfig::new(); - config - .root_store - .add_server_trust_anchors(&webpki_roots::TLS_SERVER_ROOTS); + configure_certs(&mut config); Arc::new(config) }; }