diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0dd8924..ae0a7b4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -152,6 +152,29 @@ jobs: if: matrix.os == 'ubuntu-latest' run: cargo test --manifest-path android-release-support/Cargo.toml --test codegen -- --ignored + test_upki: + name: "Test (upki)" + runs-on: ubuntu-latest + # upki is packaged from Ubuntu 26.10, for which there is no GitHub-hosted runner. + container: ubuntu:26.10 + steps: + - name: Install dependencies + run: | + apt-get update + apt-get install -y --no-install-recommends build-essential ca-certificates curl git upki + + - uses: actions/checkout@v4 + with: + persist-credentials: false + + - uses: dtolnay/rust-toolchain@stable + + - name: Fetch upki revocation data + run: runuser -u upki -g upki -- upki fetch + + - name: Test + run: cargo test -p rustls-platform-verifier --features upki + test_android: name: "Test (Android)" runs-on: ubuntu-latest diff --git a/Cargo.lock b/Cargo.lock index 9bb6dcb..845dc95 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -114,6 +114,15 @@ version = "0.23.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac07cdecf99051d9a5238b80f35af32cdeba5b336e55d957b318b50137e18da5" +[[package]] +name = "bincode" +version = "1.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad" +dependencies = [ + "serde", +] + [[package]] name = "bitflags" version = "1.3.2" @@ -184,6 +193,27 @@ dependencies = [ "rand_core", ] +[[package]] +name = "clubcard" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f8c5e5335283f9165377506b6b99cdc34fa9634927b201cca7d79fa4d0c8259" +dependencies = [ + "serde", +] + +[[package]] +name = "clubcard-crlite" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "345a8de7ab744a39098db70ae604c87dc3e709594c9cf1d6efd164c17305e4bd" +dependencies = [ + "base64 0.23.1", + "bincode", + "clubcard", + "serde", +] + [[package]] name = "cmake" version = "0.1.58" @@ -317,6 +347,27 @@ version = "0.5.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9e9de72ce2ad1f90dc62fa25f0f430ef85eb4b0d8fa0be4f30373bc40a21d28e" +[[package]] +name = "directories" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16f5094c54661b38d03bd7e50df373292118db60b585c08a411c6d840017fe7d" +dependencies = [ + "dirs-sys", +] + +[[package]] +name = "dirs-sys" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e01a3366d27ee9890022452ee61b2b63a67e6f13f58900b651ff5665f0bb1fab" +dependencies = [ + "libc", + "option-ext", + "redox_users", + "windows-sys 0.61.2", +] + [[package]] name = "displaydoc" version = "0.2.7" @@ -350,6 +401,12 @@ dependencies = [ "regex", ] +[[package]] +name = "equivalent" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00d174d5400e5e8fd687ad1049e2f578285fa914201b1af7e8b112a4546bd826" + [[package]] name = "find-msvc-tools" version = "0.1.15" @@ -431,11 +488,20 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "hashbrown" +version = "0.17.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a" + [[package]] name = "hex" version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" +dependencies = [ + "serde", +] [[package]] name = "http" @@ -638,6 +704,16 @@ dependencies = [ "icu_properties", ] +[[package]] +name = "indexmap" +version = "2.14.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc4e190f5d26ca7051642629da2c52fc03bde85a03197c99408dcd291734c855" +dependencies = [ + "equivalent", + "hashbrown", +] + [[package]] name = "ipnet" version = "2.12.2" @@ -769,6 +845,15 @@ version = "0.2.191" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "65cd87c9a6d60536580b316ad985726104730a5151c99845f2490428ef91240a" +[[package]] +name = "libredox" +version = "0.1.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61ff90caf6077a803a240f62fdbe88645a890bbca49ef8174c3cb0404362171d" +dependencies = [ + "libc", +] + [[package]] name = "litemap" version = "0.8.3" @@ -885,6 +970,12 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7c87def4c32ab89d880effc9e097653c8da5d6ef28e6b539d313baaacfbafcbe" +[[package]] +name = "option-ext" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d" + [[package]] name = "percent-encoding" version = "2.3.2" @@ -1040,6 +1131,16 @@ dependencies = [ "rand_core", ] +[[package]] +name = "redox_users" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60dc65c0ff1a7ae1294b0c67b9f14baf70b644404010370171787bfac1038fc0" +dependencies = [ + "libredox", + "thiserror", +] + [[package]] name = "regex" version = "1.13.1" @@ -1153,7 +1254,7 @@ dependencies = [ "aws-lc-rs", "once_cell", "rustls-pki-types", - "rustls-webpki", + "rustls-webpki 0.103.16", "subtle", "zeroize", ] @@ -1193,7 +1294,8 @@ dependencies = [ "rustls", "rustls-native-certs", "rustls-platform-verifier-android 0.2.0", - "rustls-webpki", + "rustls-upki", + "rustls-webpki 0.103.16", "security-framework", "security-framework-sys", "webpki-root-certs", @@ -1214,7 +1316,7 @@ dependencies = [ "rustls", "rustls-native-certs", "rustls-platform-verifier-android 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rustls-webpki", + "rustls-webpki 0.103.16", "security-framework", "security-framework-sys", "webpki-root-certs", @@ -1237,6 +1339,17 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eec689c0bc40ff2458a5977b6619cb718087084a18e02a131c599b62d05e1a5f" +[[package]] +name = "rustls-upki" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f58dc8eb633bf4b92c97192c72abe593c1421904fbb4c357e9ffd465015eb73c" +dependencies = [ + "rustls", + "rustls-webpki 0.104.0-alpha.7", + "upki", +] + [[package]] name = "rustls-webpki" version = "0.103.16" @@ -1249,6 +1362,16 @@ dependencies = [ "untrusted", ] +[[package]] +name = "rustls-webpki" +version = "0.104.0-alpha.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bea702cca24d344fc70973022bf7eb920c224e318466eb49784272337dd24b1a" +dependencies = [ + "rustls-pki-types", + "untrusted", +] + [[package]] name = "rustversion" version = "1.0.23" @@ -1351,6 +1474,15 @@ dependencies = [ "zmij", ] +[[package]] +name = "serde_spanned" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c187e0a369471c550af028cba56d4f4fa2a489ad28151ae95a4d340a2a8b782" +dependencies = [ + "serde_core", +] + [[package]] name = "shlex" version = "2.0.1" @@ -1582,6 +1714,45 @@ dependencies = [ "tokio", ] +[[package]] +name = "toml" +version = "1.2.1+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d5755c51863cdac711f1956baf8eb9588e060755f7d3c4c979e70ea1e1f32cd7" +dependencies = [ + "indexmap", + "serde_core", + "serde_spanned", + "toml_datetime", + "toml_parser", + "toml_writer", + "winnow", +] + +[[package]] +name = "toml_datetime" +version = "1.1.3+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "173f25c883cd2176a2d8212155638c0a60d484a9d84546d270866f40f56b6e49" +dependencies = [ + "serde_core", +] + +[[package]] +name = "toml_parser" +version = "1.1.5+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baa693a8032d7e1cada7d0041e96126df243179ff061456783ac7f12bda4744c" +dependencies = [ + "winnow", +] + +[[package]] +name = "toml_writer" +version = "1.2.0+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "009dbb7700f11c55ef83aebbe4c0e9cf1f1ac0844bd8d6f00dc38f302026e13a" + [[package]] name = "tower" version = "0.5.3" @@ -1634,9 +1805,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "63e71662fa4b2a2c3a26f570f037eb95bb1f85397f3cd8076caed2f026a6d100" dependencies = [ "pin-project-lite", + "tracing-attributes", "tracing-core", ] +[[package]] +name = "tracing-attributes" +version = "0.1.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7490cfa5ec963746568740651ac6781f701c9c5ea257c58e057f3ba8cf69e8da" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + [[package]] name = "tracing-core" version = "0.1.36" @@ -1670,6 +1853,23 @@ version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" +[[package]] +name = "upki" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a95bcd73832f17c1b515f3ce0af94ea78e7fff79a453c5eade38c9c4e70c1d6e" +dependencies = [ + "base64 0.23.1", + "clubcard-crlite", + "directories", + "hex", + "rustls-pki-types", + "rustls-webpki 0.104.0-alpha.7", + "serde", + "toml", + "tracing", +] + [[package]] name = "url" version = "2.5.8" @@ -1801,7 +2001,7 @@ dependencies = [ "num-bigint 0.5.1", "reqwest", "rustls-pki-types", - "rustls-webpki", + "rustls-webpki 0.103.16", "serde", "serde_json", "url", @@ -1915,6 +2115,12 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" +[[package]] +name = "winnow" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c3b93199df0ab874cdf0c6a94f0a0dc3423fe41f1cafb62b8bd7b1deb277aef" + [[package]] name = "writeable" version = "0.6.4" diff --git a/README.md b/README.md index f77c9ba..6250bea 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ This library supports the following platforms and flows: | macOS (10.14+) | macOS platform roots and keychain certificate | macOS `Security.framework` | Yes | | iOS | iOS platform roots and keychain certificates | iOS `Security.framework` | Yes | | Android | Android System Trust Store | Android Trust Manager | Sometimes[^1] | -| Linux | System CA bundle, or user-provided certs[^3] | webpki | No[^2] | +| Linux | System CA bundle, or user-provided certs[^3] | webpki | No[^2] / Yes[^4] | | WASM | webpki roots | webpki | No[^2] | [^1]: On Android, revocation checking requires API version >= 24 (e.g. at least Android 7.0, August 2016). @@ -40,11 +40,15 @@ information. Users may wish to augment these certificates with [webpki-roots] using [`Verifier::new_with_extra_roots`] in case a system CA bundle is unavailable. +[^4]: Enable the `upki` crate feature to use [upki] to do revocation checking of end-entity certificates. The +`upki` system component needs to be installed (it is available, for example, on Ubuntu 26.10). + [`ServerCertVerifierBuilder`]: https://docs.rs/rustls/latest/rustls/client/struct.ServerCertVerifierBuilder.html [`Verifier::new_with_extra_roots`]: https://docs.rs/rustls-platform-verifier/latest/rustls_platform_verifier/struct.Verifier.html#method.new_with_extra_roots [rustls-native-certs]: https://github.com/rustls/rustls-native-certs [openssl-probe]: https://github.com/alexcrichton/openssl-probe [webpki-roots]: https://github.com/rustls/webpki-roots +[upki]: https://github.com/rustls/upki ## Deployment Considerations diff --git a/rustls-platform-verifier/Cargo.toml b/rustls-platform-verifier/Cargo.toml index 989cc2b..7f5b0a5 100644 --- a/rustls-platform-verifier/Cargo.toml +++ b/rustls-platform-verifier/Cargo.toml @@ -24,9 +24,13 @@ dbg = [] cert-logging = ["base64"] # Used for nicely documenting the Android-specific APIs. This feature is not stable. docsrs = ["jni"] +# Use upki for revocation checking on Linux. This requires the upki service to be installed +# on the target machine, which synchronizes revocation data. +upki = ["dep:rustls-upki"] [dependencies] rustls = { version = "0.23.27", default-features = false, features = ["std"] } +rustls-upki = { version = "1", optional = true } log = { version = "0.4" } base64 = { version = "0.22", optional = true } # Only used when the `cert-logging` feature is enabled. jni = { version = "0.22.4", default-features = false, optional = true } # Only used during doc generation diff --git a/rustls-platform-verifier/src/verification/others.rs b/rustls-platform-verifier/src/verification/others.rs index 6e4796f..06114af 100644 --- a/rustls-platform-verifier/src/verification/others.rs +++ b/rustls-platform-verifier/src/verification/others.rs @@ -2,11 +2,10 @@ use std::fmt::Debug; use std::sync::Arc; use rustls::client::danger::{HandshakeSignatureValid, ServerCertVerified, ServerCertVerifier}; -use rustls::client::WebPkiServerVerifier; use rustls::pki_types; use rustls::{ crypto::CryptoProvider, CertificateError, DigitallySignedStruct, Error as TlsError, OtherError, - SignatureScheme, + RootCertStore, SignatureScheme, }; use super::log_server_cert; @@ -17,7 +16,7 @@ pub struct Verifier { // We currently keep one set of certificates per-verifier so that // recreating the verifier will pull fresh root certificates from disk, // picking up on any changes that might have been made since. - inner: Arc, + inner: Arc, } impl Verifier { @@ -58,7 +57,7 @@ impl Verifier { test_root: Option>, crypto_provider: Arc, ) -> Result { - let mut root_store = rustls::RootCertStore::empty(); + let mut root_store = RootCertStore::empty(); // For testing only: load fake root cert, instead of native/WebPKI roots #[cfg(any(test, feature = "ffi-testing", feature = "dbg"))] @@ -66,7 +65,7 @@ impl Verifier { if let Some(test_root) = test_root { root_store.add(test_root)?; return Ok(Self { - inner: WebPkiServerVerifier::builder_with_provider( + inner: rustls::client::WebPkiServerVerifier::builder_with_provider( root_store.into(), crypto_provider.clone(), ) @@ -118,11 +117,33 @@ impl Verifier { }; Ok(Self { - inner: WebPkiServerVerifier::builder_with_provider(root_store.into(), crypto_provider) - .build() - .map_err(|e| TlsError::Other(OtherError(Arc::new(e))))?, + inner: Self::create_verifier(root_store.into(), crypto_provider)?, }) } + + #[cfg(feature = "upki")] + fn create_verifier( + root_store: Arc, + crypto_provider: Arc, + ) -> Result, TlsError> { + rustls_upki::ServerVerifier::new( + rustls_upki::Policy::default(), + None, + root_store, + crypto_provider, + ) + .map(Arc::new) + } + + #[cfg(not(feature = "upki"))] + fn create_verifier( + root_store: Arc, + crypto_provider: Arc, + ) -> Result, TlsError> { + rustls::client::WebPkiServerVerifier::builder_with_provider(root_store, crypto_provider) + .build() + .map_err(|e| TlsError::Other(OtherError(Arc::new(e)))) + } } #[cfg_attr(docsrs, doc(cfg(all())))]