Skip to content

Commit 978894a

Browse files
feat(ddcommon): Replace rustls-native-certs by rustls-platform-verifier
1 parent a303dc1 commit 978894a

File tree

3 files changed

+113
-49
lines changed

3 files changed

+113
-49
lines changed

Cargo.lock

Lines changed: 109 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ddcommon/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ regex = "1.5"
3636
rmp = "0.8.14"
3737
rmp-serde = "1.3.0"
3838
rustls = { version = "0.23", default-features = false, optional = true }
39-
rustls-native-certs = { version = "0.8.1", optional = true }
39+
rustls-platform-verifier = { version = "0.5", optional = true }
4040
tokio = { version = "1.23", features = ["rt", "macros"] }
4141
tokio-rustls = { version = "0.26", default-features = false, optional = true }
4242
serde = { version = "1.0", features = ["derive"] }
@@ -71,7 +71,7 @@ maplit = "1.0"
7171

7272
[features]
7373
default = ["https"]
74-
https = ["tokio-rustls", "rustls", "hyper-rustls", "rustls-native-certs"]
74+
https = ["tokio-rustls", "rustls", "hyper-rustls", "rustls-platform-verifier"]
7575
use_webpki_roots = ["hyper-rustls/webpki-roots"]
7676
# Enable this feature to enable stubbing of cgroup
7777
# php directly import this crate and uses functions gated by this feature for their test

ddcommon/src/connector/mod.rs

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -128,42 +128,18 @@ mod https {
128128
pub(super) fn build_https_connector() -> anyhow::Result<
129129
hyper_rustls::HttpsConnector<hyper_util::client::legacy::connect::HttpConnector>,
130130
> {
131+
use rustls_platform_verifier::BuilderVerifierExt;
131132
ensure_crypto_provider_initialized(); // One-time initialization of a crypto provider if needed
132133

133-
let certs = load_root_certs()?;
134134
let client_config = ClientConfig::builder()
135-
.with_root_certificates(certs)
135+
.with_platform_verifier()
136136
.with_no_client_auth();
137137
Ok(hyper_rustls::HttpsConnectorBuilder::new()
138138
.with_tls_config(client_config)
139139
.https_or_http()
140140
.enable_http1()
141141
.build())
142142
}
143-
144-
#[cfg(not(feature = "use_webpki_roots"))]
145-
fn load_root_certs() -> anyhow::Result<rustls::RootCertStore> {
146-
use super::errors;
147-
148-
let mut roots = rustls::RootCertStore::empty();
149-
150-
let cert_result = rustls_native_certs::load_native_certs();
151-
if cert_result.certs.is_empty() {
152-
if let Some(err) = cert_result.errors.into_iter().next() {
153-
return Err(err.into());
154-
}
155-
}
156-
// TODO(paullgdfc): log errors even if there are valid certs, instead of ignoring them
157-
158-
for cert in cert_result.certs {
159-
//TODO: log when invalid cert is loaded
160-
roots.add(cert).ok();
161-
}
162-
if roots.is_empty() {
163-
return Err(errors::Error::NoValidCertifacteRootsFound.into());
164-
}
165-
Ok(roots)
166-
}
167143
}
168144

169145
impl tower_service::Service<hyper::Uri> for Connector {

0 commit comments

Comments
 (0)