Skip to content

Commit

Permalink
Uniformize new_with_extra_roots
Browse files Browse the repository at this point in the history
  • Loading branch information
stormshield-gt committed Sep 2, 2024
1 parent 61ca4cc commit 36cc3f5
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 14 deletions.
6 changes: 3 additions & 3 deletions rustls-platform-verifier/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ webpki = { package = "rustls-webpki", version = "0.102", default-features = fals
android_logger = { version = "0.13", optional = true } # Only used during testing.

[target.'cfg(target_arch = "wasm32")'.dependencies]
webpki-roots = "0.26"
webpki = { package = "rustls-webpki", version = "0.102", default-features = false }
webpki-root-certs = "0.26"

# BSD targets require webpki-roots for the real-world verification tests.
# BSD targets require webpki-roots-certs for the real-world verification tests.
[target.'cfg(target_os = "freebsd")'.dev-dependencies]
webpki-roots = "0.26"
webpki-root-certs = "0.26"

[target.'cfg(any(target_os = "macos", target_os = "ios", target_os = "tvos"))'.dependencies]
core-foundation = "0.9"
Expand Down
5 changes: 3 additions & 2 deletions rustls-platform-verifier/src/tests/verification_mock/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,11 @@ pub(super) fn verification_without_mock_root() {
ensure_global_state();
// Since Rustls 0.22 constructing a webpki verifier (like the one backing Verifier on unix
// systems) without any roots produces `OtherError(NoRootAnchors)` - since our FreeBSD CI
// runner fails to find any roots with openssl-probe we need to provide webpki-roots here
// runner fails to find any roots with openssl-probe we need to provide webpki-root-certs here
// or the test will fail with the `OtherError` instead of the expected `CertificateError`.
#[cfg(target_os = "freebsd")]
let verifier = Verifier::new_with_extra_roots(webpki_roots::TLS_SERVER_ROOTS.iter().cloned());
let verifier =
Verifier::new_with_extra_roots(webpki_root_certs::TLS_SERVER_ROOT_CERTS.iter().cloned());

#[cfg(not(target_os = "freebsd"))]
let verifier = Verifier::new();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,10 @@ fn real_world_test<E: std::error::Error>(test_case: &TestCase<E>) {
);

// On BSD systems openssl-probe fails to find the system CA bundle,
// so we must provide extra roots from webpki-roots.
// so we must provide extra roots from webpki-root-cert.
#[cfg(target_os = "freebsd")]
let verifier = Verifier::new_with_extra_roots(webpki_roots::TLS_SERVER_ROOTS.iter().cloned());
let verifier =
Verifier::new_with_extra_roots(webpki_root_certs::TLS_SERVER_ROOT_CERTS.iter().cloned());

#[cfg(not(target_os = "freebsd"))]
let verifier = Verifier::new();
Expand Down
18 changes: 11 additions & 7 deletions rustls-platform-verifier/src/verification/others.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,16 @@ impl Verifier {
/// Creates a new verifier whose certificate validation is provided by
/// WebPKI, using root certificates provided by the platform and augmented by
/// the provided extra root certificates.
pub fn new_with_extra_roots(
roots: impl IntoIterator<Item = pki_types::TrustAnchor<'static>>,
) -> Self {
pub fn new_with_extra_roots(roots: Vec<pki_types::CertificateDer<'static>>) -> Self {
Self {
inner: OnceCell::new(),
extra_roots: roots.into_iter().collect::<Vec<_>>().into(),
extra_roots: roots
.into_iter()
.flat_map(|root| {
webpki::anchor_from_trusted_cert(&root).map(|anchor| anchor.to_owned())
})
.collect::<Vec<_>>()
.into(),
#[cfg(any(test, feature = "ffi-testing", feature = "dbg"))]
test_only_root_ca_override: None,
crypto_provider: OnceCell::new(),
Expand Down Expand Up @@ -154,9 +158,9 @@ impl Verifier {

#[cfg(target_arch = "wasm32")]
{
root_store
.roots
.extend_from_slice(webpki_roots::TLS_SERVER_ROOTS);
root_store.add_parsable_certificates(
webpki_root_certs::TLS_SERVER_ROOT_CERTS.iter().cloned(),
);
};

WebPkiServerVerifier::builder_with_provider(
Expand Down

0 comments on commit 36cc3f5

Please sign in to comment.