Skip to content

Commit a7cb726

Browse files
committed
Upgrade to rustls-native-certs 0.8
1 parent a6a5687 commit a7cb726

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ hyper = { version = "1", default-features = false }
1616
hyper-util = { version = "0.1", default-features = false, features = ["client-legacy", "tokio"] }
1717
log = { version = "0.4.4", optional = true }
1818
pki-types = { package = "rustls-pki-types", version = "1" }
19-
rustls-native-certs = { version = "0.7", optional = true }
19+
rustls-native-certs = { version = "0.8", optional = true }
2020
rustls-platform-verifier = { version = "0.3", optional = true }
2121
rustls = { version = "0.23", default-features = false }
2222
tokio = "1.0"

src/config.rs

+16-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ use std::sync::Arc;
88
))]
99
use rustls::client::WantsClientCert;
1010
use rustls::{ClientConfig, ConfigBuilder, WantsVerifier};
11+
#[cfg(feature = "rustls-native-certs")]
12+
use rustls_native_certs::CertificateResult;
1113

1214
/// Methods for configuring roots
1315
///
@@ -52,8 +54,19 @@ impl ConfigBuilderExt for ConfigBuilder<ClientConfig, WantsVerifier> {
5254
let mut valid_count = 0;
5355
let mut invalid_count = 0;
5456

55-
for cert in rustls_native_certs::load_native_certs().expect("could not load platform certs")
56-
{
57+
let CertificateResult { certs, errors, .. } = rustls_native_certs::load_native_certs();
58+
if !errors.is_empty() {
59+
crate::log::warn!("native root CA certificate loading errors: {errors:?}");
60+
}
61+
62+
if certs.is_empty() {
63+
return Err(std::io::Error::new(
64+
std::io::ErrorKind::NotFound,
65+
"no native root CA certificates found (errors: {errors})",
66+
));
67+
}
68+
69+
for cert in certs {
5770
match roots.add(cert) {
5871
Ok(_) => valid_count += 1,
5972
Err(err) => {
@@ -62,6 +75,7 @@ impl ConfigBuilderExt for ConfigBuilder<ClientConfig, WantsVerifier> {
6275
}
6376
}
6477
}
78+
6579
crate::log::debug!(
6680
"with_native_roots processed {} valid and {} invalid certs",
6781
valid_count,

src/lib.rs

+6
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ mod stream;
4343
mod log {
4444
#[cfg(any(feature = "rustls-native-certs", feature = "webpki-roots"))]
4545
pub(crate) use log::debug;
46+
#[cfg(any(feature = "rustls-native-certs"))]
47+
pub(crate) use log::warn;
4648
}
4749

4850
#[cfg(not(feature = "logging"))]
@@ -51,6 +53,10 @@ mod log {
5153
macro_rules! debug ( ($($tt:tt)*) => {{}} );
5254
#[cfg(any(feature = "rustls-native-certs", feature = "webpki-roots"))]
5355
pub(crate) use debug;
56+
#[cfg(any(feature = "rustls-native-certs"))]
57+
macro_rules! warn ( ($($tt:tt)*) => {{}} );
58+
#[cfg(any(feature = "rustls-native-certs"))]
59+
pub(crate) use warn;
5460
}
5561

5662
pub use crate::config::ConfigBuilderExt;

0 commit comments

Comments
 (0)