Skip to content

Commit 3582863

Browse files
committed
Add built-in support for rustls-platform-verifier
1 parent 9bb9d59 commit 3582863

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ hyper-util = { version = "0.1", default-features = false, features = ["client-le
1717
log = { version = "0.4.4", optional = true }
1818
pki-types = { package = "rustls-pki-types", version = "1" }
1919
rustls-native-certs = { version = "0.7", optional = true }
20+
rustls-platform-verifier = { version = "0.2", optional = true }
2021
rustls = { version = "0.22", default-features = false }
2122
tokio = "1.0"
2223
tokio-rustls = { version = "0.25", default-features = false }

src/config.rs

+24-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
#[cfg(any(feature = "rustls-native-certs", feature = "webpki-roots"))]
1+
#[cfg(feature = "rustls-platform-verifier")]
2+
use std::sync::Arc;
3+
4+
#[cfg(any(
5+
feature = "rustls-platform-verifier",
6+
feature = "rustls-native-certs",
7+
feature = "webpki-roots"
8+
))]
29
use rustls::client::WantsClientCert;
310
use rustls::{ClientConfig, ConfigBuilder, WantsVerifier};
411

@@ -7,6 +14,14 @@ use rustls::{ClientConfig, ConfigBuilder, WantsVerifier};
714
/// This adds methods (gated by crate features) for easily configuring
815
/// TLS server roots a rustls ClientConfig will trust.
916
pub trait ConfigBuilderExt {
17+
/// Use the platform's native verifier to verify server certificates.
18+
///
19+
/// See the documentation for [rustls-platform-verifier] for more details.
20+
///
21+
/// [rustls-platform-verifier]: https://docs.rs/rustls-platform-verifier
22+
#[cfg(feature = "rustls-platform-verifier")]
23+
fn with_platform_verifier(self) -> ConfigBuilder<ClientConfig, WantsClientCert>;
24+
1025
/// This configures the platform's trusted certs, as implemented by
1126
/// rustls-native-certs
1227
///
@@ -22,6 +37,14 @@ pub trait ConfigBuilderExt {
2237
}
2338

2439
impl ConfigBuilderExt for ConfigBuilder<ClientConfig, WantsVerifier> {
40+
#[cfg(feature = "rustls-platform-verifier")]
41+
fn with_platform_verifier(self) -> ConfigBuilder<ClientConfig, WantsClientCert> {
42+
self.dangerous()
43+
.with_custom_certificate_verifier(Arc::new(
44+
rustls_platform_verifier::Verifier::default(),
45+
))
46+
}
47+
2548
#[cfg(feature = "rustls-native-certs")]
2649
#[cfg_attr(not(feature = "logging"), allow(unused_variables))]
2750
fn with_native_roots(self) -> std::io::Result<ConfigBuilder<ClientConfig, WantsClientCert>> {

src/connector/builder.rs

+12
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,18 @@ impl ConnectorBuilder<WantsTlsConfig> {
5151
ConnectorBuilder(WantsSchemes { tls_config: config })
5252
}
5353

54+
/// Use rustls' default crypto provider and other defaults, and the platform verifier
55+
///
56+
/// See [`ConfigBuilderExt::with_platform_verifier()`].
57+
#[cfg(all(feature = "ring", feature = "rustls-platform-verifier"))]
58+
pub fn with_platform_verifier(self) -> ConnectorBuilder<WantsSchemes> {
59+
self.with_tls_config(
60+
ClientConfig::builder()
61+
.with_platform_verifier()
62+
.with_no_client_auth(),
63+
)
64+
}
65+
5466
/// Shorthand for using rustls' default crypto provider and safe defaults, with
5567
/// native roots.
5668
///

0 commit comments

Comments
 (0)