Skip to content

Commit 129b0a0

Browse files
g2pdjc
authored andcommitted
Update to take advantage of rustls 0.21.1
The extensions to rustls::ClientConfig in ClientConfigExt that set root certificates now do just that, they don't go on to configure / disable client auth. The builder traits are unchanged, they set convenient defaults (no client auth) but allow passing a custom rustls::ClientConfig.
1 parent 2f37ed5 commit 129b0a0

File tree

4 files changed

+17
-12
lines changed

4 files changed

+17
-12
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ http = "0.2"
1414
hyper = { version = "0.14", default-features = false, features = ["client"] }
1515
log = { version = "0.4.4", optional = true }
1616
rustls-native-certs = { version = "0.6", optional = true }
17-
rustls = { version = "0.20", default-features = false }
17+
rustls = { version = "0.20.1", default-features = false }
1818
tokio = "1.0"
1919
tokio-rustls = { version = "0.23", default-features = false }
2020
webpki-roots = { version = "0.22", optional = true }
@@ -23,7 +23,7 @@ webpki-roots = { version = "0.22", optional = true }
2323
async-stream = "0.3.0"
2424
futures-util = { version = "0.3.1", default-features = false }
2525
hyper = { version = "0.14", features = ["full"] }
26-
rustls = { version = "0.20", default-features = false, features = ["tls12"] }
26+
rustls = { version = "0.20.1", default-features = false, features = ["tls12"] }
2727
rustls-pemfile = "0.2.1"
2828
tokio = { version = "1.0", features = ["io-std", "macros", "net", "rt-multi-thread"] }
2929

examples/client.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ async fn run_client() -> io::Result<()> {
6060
// Default TLS client config with native roots
6161
None => rustls::ClientConfig::builder()
6262
.with_safe_defaults()
63-
.with_native_roots(),
63+
.with_native_roots()
64+
.with_no_client_auth(),
6465
};
6566
// Prepare the HTTPS connector
6667
let https = hyper_rustls::HttpsConnectorBuilder::new()

src/config.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use rustls::client::WantsTransparencyPolicyOrClientCert;
12
use rustls::{ClientConfig, ConfigBuilder, WantsVerifier};
23

34
/// Methods for configuring roots
@@ -9,20 +10,20 @@ pub trait ConfigBuilderExt {
910
/// rustls-native-certs
1011
#[cfg(feature = "rustls-native-certs")]
1112
#[cfg_attr(docsrs, doc(cfg(feature = "rustls-native-certs")))]
12-
fn with_native_roots(self) -> ClientConfig;
13+
fn with_native_roots(self) -> ConfigBuilder<ClientConfig, WantsTransparencyPolicyOrClientCert>;
1314

1415
/// This configures the webpki roots, which are Mozilla's set of
1516
/// trusted roots as packaged by webpki-roots.
1617
#[cfg(feature = "webpki-roots")]
1718
#[cfg_attr(docsrs, doc(cfg(feature = "webpki-roots")))]
18-
fn with_webpki_roots(self) -> ClientConfig;
19+
fn with_webpki_roots(self) -> ConfigBuilder<ClientConfig, WantsTransparencyPolicyOrClientCert>;
1920
}
2021

2122
impl ConfigBuilderExt for ConfigBuilder<ClientConfig, WantsVerifier> {
2223
#[cfg(feature = "rustls-native-certs")]
2324
#[cfg_attr(docsrs, doc(cfg(feature = "rustls-native-certs")))]
2425
#[cfg_attr(not(feature = "logging"), allow(unused_variables))]
25-
fn with_native_roots(self) -> ClientConfig {
26+
fn with_native_roots(self) -> ConfigBuilder<ClientConfig, WantsTransparencyPolicyOrClientCert> {
2627
let mut roots = rustls::RootCertStore::empty();
2728
let mut valid_count = 0;
2829
let mut invalid_count = 0;
@@ -41,16 +42,17 @@ impl ConfigBuilderExt for ConfigBuilder<ClientConfig, WantsVerifier> {
4142
}
4243
crate::log::debug!(
4344
"with_native_roots processed {} valid and {} invalid certs",
44-
valid_count, invalid_count
45+
valid_count,
46+
invalid_count
4547
);
4648
assert!(!roots.is_empty(), "no CA certificates found");
4749

48-
self.with_root_certificates(roots).with_no_client_auth()
50+
self.with_root_certificates(roots)
4951
}
5052

5153
#[cfg(feature = "webpki-roots")]
5254
#[cfg_attr(docsrs, doc(cfg(feature = "webpki-roots")))]
53-
fn with_webpki_roots(self) -> ClientConfig {
55+
fn with_webpki_roots(self) -> ConfigBuilder<ClientConfig, WantsTransparencyPolicyOrClientCert> {
5456
let mut roots = rustls::RootCertStore::empty();
5557
roots.add_server_trust_anchors(webpki_roots::TLS_SERVER_ROOTS.0.iter().map(|ta| {
5658
rustls::OwnedTrustAnchor::from_subject_spki_name_constraints(
@@ -59,6 +61,6 @@ impl ConfigBuilderExt for ConfigBuilder<ClientConfig, WantsVerifier> {
5961
ta.name_constraints,
6062
)
6163
}));
62-
self.with_root_certificates(roots).with_no_client_auth()
64+
self.with_root_certificates(roots)
6365
}
6466
}

src/connector/builder.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ impl ConnectorBuilder<WantsTlsConfig> {
5858
self.with_tls_config(
5959
ClientConfig::builder()
6060
.with_safe_defaults()
61-
.with_native_roots(),
61+
.with_native_roots()
62+
.with_no_client_auth(),
6263
)
6364
}
6465

@@ -74,7 +75,8 @@ impl ConnectorBuilder<WantsTlsConfig> {
7475
self.with_tls_config(
7576
ClientConfig::builder()
7677
.with_safe_defaults()
77-
.with_webpki_roots(),
78+
.with_webpki_roots()
79+
.with_no_client_auth(),
7880
)
7981
}
8082
}

0 commit comments

Comments
 (0)