Skip to content

Commit c18a7e2

Browse files
committed
Cargo: update to rustls 0.22, associated updates
For the time being, this branch continues to unconditionally use *ring* as the crypto provider. Follow-up work to expose this as a choice (e.g allowing aws-lc-rs as a provider) may be interesting. Deps: * updated rustls 0.21 -> 0.22.1 Linux deps: * rustls-native-certs 0.6 -> 0.7 * webpki 0.101 -> 0.102 Android deps: * webpki 0.101 -> 0.102 WASM32 deps: * webpki-roots 0.25 -> 0.26 Summary of breaking change updates: * We use rustls 0.22.1 in specific to benefit from the `pki_types` re-export, removing the need to add that as our own dep with matching version. * `ServerName`, `Certificate`, and `OwnedTrustAnchor` types are now sourced from `pki_types`, with an associated generic lifetime. The `OwnedTrustAnchor` type is now just `TrustAnchor`. * The 'dangerous' rustls crate feature was removed, and associated items moved into new locations with the import path emphasizing danger. * "Other error" types changed to use a specific `rustls::OtherError` inner variant. * `SystemTime` for verifiers replaced with `pki_types::UnixTime`. * Default fns on `ServerCertVerifier` trait were removed, must be reconstituted with `rustls::verify_tls12_signature`, `rustls::verify_tls13_signature` and `WebPkiSupportedAlgorithms.supported_schemes` using a `CryptoProvider`. * `ServerName` now supports a `to_str` operation, avoiding the need to `match` and handle unsupported name types. * `WebPkiVerifier` was renamed to `WebPkiServerVerifier`, handled as an `Arc` and constructed with a builder.
1 parent b51d933 commit c18a7e2

File tree

11 files changed

+385
-318
lines changed

11 files changed

+385
-318
lines changed

Cargo.lock

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

rustls-platform-verifier/Cargo.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,31 +29,31 @@ cert-logging = ["base64"]
2929
docsrs = ["jni", "once_cell"]
3030

3131
[dependencies]
32-
rustls = { version = "0.21", features = ["dangerous_configuration", "tls12", "logging"] }
32+
rustls = { version = "0.22.1", features = ["tls12", "logging"] }
3333
log = { version = "0.4" }
3434
base64 = { version = "0.21", optional = true } # Only used when the `cert-logging` feature is enabled.
3535
jni = { version = "0.19", default-features = false, optional = true } # Only used during doc generation
3636
once_cell = { version = "1.9", optional = true } # Only used during doc generation.
3737

3838
[target.'cfg(all(unix, not(target_os = "android"), not(target_os = "macos"), not(target_os = "ios")))'.dependencies]
39-
rustls-native-certs = "0.6"
39+
rustls-native-certs = "0.7"
4040
once_cell = "1.9"
41-
webpki = { package = "rustls-webpki", version = "0.101", features = ["alloc", "std"] }
41+
webpki = { package = "rustls-webpki", version = "0.102", features = ["ring", "alloc", "std"] }
4242

4343
[target.'cfg(target_os = "android")'.dependencies]
4444
rustls-platform-verifier-android = { path = "../android-release-support", version = "0.1.0" }
4545
jni = { version = "0.19", default-features = false }
46-
webpki = { package = "rustls-webpki", version = "0.101", features = ["alloc", "std"] }
46+
webpki = { package = "rustls-webpki", version = "0.102", features = ["ring", "alloc", "std"] }
4747
once_cell = "1.9"
4848
android_logger = { version = "0.13", optional = true } # Only used during testing.
4949

5050
[target.'cfg(target_arch = "wasm32")'.dependencies]
5151
once_cell = "1.9"
52-
webpki-roots = "0.25"
52+
webpki-roots = "0.26"
5353

5454
# BSD targets require webpki-roots for the real-world verification tests.
5555
[target.'cfg(target_os = "freebsd")'.dev-dependencies]
56-
webpki-roots = "0.25"
56+
webpki-roots = "0.26"
5757

5858
[target.'cfg(any(target_os = "macos", target_os = "ios"))'.dependencies]
5959
core-foundation = "0.9"

rustls-platform-verifier/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,13 @@ pub use tests::ffi::*;
5454
///
5555
/// If you require more control over the rustls `ClientConfig`, you can
5656
/// instantiate a [Verifier] with [Verifier::default] and then use it
57-
/// with [rustls::ConfigBuilder::with_custom_certificate_verifier].
57+
/// with [rustls::ConfigBuilder::dangerous::with_custom_certificate_verifier].
5858
///
5959
/// Refer to the crate level documentation to see what platforms
6060
/// are currently supported.
6161
pub fn tls_config() -> ClientConfig {
62-
rustls::ClientConfig::builder()
63-
.with_safe_defaults()
62+
ClientConfig::builder()
63+
.dangerous()
6464
.with_custom_certificate_verifier(Arc::new(Verifier::new()))
6565
.with_no_client_auth()
6666
}
@@ -69,6 +69,6 @@ pub fn tls_config() -> ClientConfig {
6969
///
7070
/// This is not intended for production use, you should use [tls_config] instead.
7171
#[cfg(feature = "dbg")]
72-
pub fn verifier_for_dbg(root: &[u8]) -> Arc<dyn rustls::client::ServerCertVerifier> {
72+
pub fn verifier_for_dbg(root: &[u8]) -> Arc<dyn rustls::client::danger::ServerCertVerifier> {
7373
Arc::new(Verifier::new_with_fake_root(root))
7474
}

rustls-platform-verifier/src/tests/mod.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
pub mod ffi;
33

44
use std::error::Error as StdError;
5-
use std::time::{Duration, SystemTime};
5+
use std::time::Duration;
66

77
mod verification_real_world;
88

99
mod verification_mock;
1010

11-
use rustls::{CertificateError, Error as TlsError, Error::InvalidCertificate};
11+
use rustls::{pki_types, CertificateError, Error as TlsError, Error::InvalidCertificate};
1212

1313
struct TestCase<'a, E: StdError> {
1414
/// The name of the server we're connecting to.
@@ -21,7 +21,7 @@ struct TestCase<'a, E: StdError> {
2121
pub stapled_ocsp: Option<&'a [u8]>,
2222

2323
/// The time to use as the current time for verification.
24-
pub verification_time: SystemTime,
24+
pub verification_time: pki_types::UnixTime,
2525

2626
pub expected_result: Result<(), TlsError>,
2727

@@ -43,6 +43,7 @@ pub fn assert_cert_error_eq<E: StdError + PartialEq + 'static>(
4343
if let Err(InvalidCertificate(CertificateError::Other(err))) = &expected {
4444
let expected_err = expected_err.expect("error not provided for `Other` case handling");
4545
let err: &E = err
46+
.0
4647
.downcast_ref()
4748
.expect("incorrect `Other` inner error kind");
4849
assert_eq!(err, expected_err);
@@ -56,7 +57,7 @@ pub fn assert_cert_error_eq<E: StdError + PartialEq + 'static>(
5657
/// We fix the "now" value used for certificate validation to a fixed point in time at which
5758
/// we know the test certificates are valid. This must be updated if the mock certificates
5859
/// are regenerated.
59-
pub(crate) fn verification_time() -> SystemTime {
60+
pub(crate) fn verification_time() -> pki_types::UnixTime {
6061
// Wednesday, January 3, 2024 6:03:08 PM UTC
61-
SystemTime::UNIX_EPOCH + Duration::from_secs(1_704_304_988)
62+
pki_types::UnixTime::since_unix_epoch(Duration::from_secs(1_704_304_988))
6263
}

0 commit comments

Comments
 (0)