Skip to content

Commit 97d6f1c

Browse files
committed
Upgrade to rustls-platform-verifier 0.6
1 parent e6a2371 commit 97d6f1c

File tree

4 files changed

+49
-14
lines changed

4 files changed

+49
-14
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "hyper-rustls"
3-
version = "0.27.6"
3+
version = "0.27.7"
44
edition = "2021"
55
rust-version = "1.71"
66
license = "Apache-2.0 OR ISC OR MIT"
@@ -29,7 +29,7 @@ hyper-util = { version = "0.1", default-features = false, features = ["client-le
2929
log = { version = "0.4.4", optional = true }
3030
pki-types = { package = "rustls-pki-types", version = "1" }
3131
rustls-native-certs = { version = "0.8", optional = true }
32-
rustls-platform-verifier = { version = "0.5", optional = true }
32+
rustls-platform-verifier = { version = "0.6", optional = true }
3333
rustls = { version = "0.23", default-features = false }
3434
tokio = "1.0"
3535
tokio-rustls = { version = "0.26", default-features = false }

src/config.rs

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#[cfg(feature = "rustls-native-certs")]
22
use std::io;
3-
#[cfg(feature = "rustls-platform-verifier")]
4-
use std::sync::Arc;
53

64
#[cfg(any(
75
feature = "rustls-platform-verifier",
@@ -12,6 +10,8 @@ use rustls::client::WantsClientCert;
1210
use rustls::{ClientConfig, ConfigBuilder, WantsVerifier};
1311
#[cfg(feature = "rustls-native-certs")]
1412
use rustls_native_certs::CertificateResult;
13+
#[cfg(feature = "rustls-platform-verifier")]
14+
use rustls_platform_verifier::BuilderVerifierExt;
1515

1616
/// Methods for configuring roots
1717
///
@@ -22,10 +22,26 @@ pub trait ConfigBuilderExt {
2222
///
2323
/// See the documentation for [rustls-platform-verifier] for more details.
2424
///
25+
/// # Panics
26+
///
27+
/// Since 0.27.7, this method will panic if the platform verifier cannot be initialized.
28+
/// Use `try_with_platform_verifier()` instead to handle errors gracefully.
29+
///
2530
/// [rustls-platform-verifier]: https://docs.rs/rustls-platform-verifier
31+
#[deprecated(since = "0.27.7", note = "use `try_with_platform_verifier` instead")]
2632
#[cfg(feature = "rustls-platform-verifier")]
2733
fn with_platform_verifier(self) -> ConfigBuilder<ClientConfig, WantsClientCert>;
2834

35+
/// Use the platform's native verifier to verify server certificates.
36+
///
37+
/// See the documentation for [rustls-platform-verifier] for more details.
38+
///
39+
/// [rustls-platform-verifier]: https://docs.rs/rustls-platform-verifier
40+
#[cfg(feature = "rustls-platform-verifier")]
41+
fn try_with_platform_verifier(
42+
self,
43+
) -> Result<ConfigBuilder<ClientConfig, WantsClientCert>, rustls::Error>;
44+
2945
/// This configures the platform's trusted certs, as implemented by
3046
/// rustls-native-certs
3147
///
@@ -43,11 +59,15 @@ pub trait ConfigBuilderExt {
4359
impl ConfigBuilderExt for ConfigBuilder<ClientConfig, WantsVerifier> {
4460
#[cfg(feature = "rustls-platform-verifier")]
4561
fn with_platform_verifier(self) -> ConfigBuilder<ClientConfig, WantsClientCert> {
46-
let provider = self.crypto_provider().clone();
47-
self.dangerous()
48-
.with_custom_certificate_verifier(Arc::new(
49-
rustls_platform_verifier::Verifier::new().with_provider(provider),
50-
))
62+
self.try_with_platform_verifier()
63+
.expect("failure to initialize platform verifier")
64+
}
65+
66+
#[cfg(feature = "rustls-platform-verifier")]
67+
fn try_with_platform_verifier(
68+
self,
69+
) -> Result<ConfigBuilder<ClientConfig, WantsClientCert>, rustls::Error> {
70+
BuilderVerifierExt::with_platform_verifier(self)
5171
}
5272

5373
#[cfg(feature = "rustls-native-certs")]

src/connector.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ mod tests {
258258
let config_builder = rustls::ClientConfig::builder();
259259
cfg_if::cfg_if! {
260260
if #[cfg(feature = "rustls-platform-verifier")] {
261-
let config_builder = config_builder.with_platform_verifier();
261+
let config_builder = config_builder.try_with_platform_verifier()?;
262262
} else if #[cfg(feature = "rustls-native-certs")] {
263263
let config_builder = config_builder.with_native_roots().unwrap();
264264
} else if #[cfg(feature = "webpki-roots")] {

src/connector/builder.rs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,26 @@ impl ConnectorBuilder<WantsTlsConfig> {
7474
feature = "rustls-platform-verifier"
7575
))]
7676
pub fn with_platform_verifier(self) -> ConnectorBuilder<WantsSchemes> {
77-
self.with_tls_config(
77+
self.try_with_platform_verifier()
78+
.expect("failure to initialize platform verifier")
79+
}
80+
81+
/// Shorthand for using rustls' default crypto provider and other defaults, and
82+
/// the platform verifier.
83+
///
84+
/// See [`ConfigBuilderExt::with_platform_verifier()`].
85+
#[cfg(all(
86+
any(feature = "ring", feature = "aws-lc-rs"),
87+
feature = "rustls-platform-verifier"
88+
))]
89+
pub fn try_with_platform_verifier(
90+
self,
91+
) -> Result<ConnectorBuilder<WantsSchemes>, rustls::Error> {
92+
Ok(self.with_tls_config(
7893
ClientConfig::builder()
79-
.with_platform_verifier()
94+
.try_with_platform_verifier()?
8095
.with_no_client_auth(),
81-
)
96+
))
8297
}
8398

8499
/// Shorthand for using a custom [`CryptoProvider`] and the platform verifier.
@@ -92,8 +107,8 @@ impl ConnectorBuilder<WantsTlsConfig> {
92107
Ok(self.with_tls_config(
93108
ClientConfig::builder_with_provider(provider.into())
94109
.with_safe_default_protocol_versions()
110+
.and_then(|builder| builder.try_with_platform_verifier())
95111
.map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e))?
96-
.with_platform_verifier()
97112
.with_no_client_auth(),
98113
))
99114
}

0 commit comments

Comments
 (0)