Skip to content

Commit 731d19e

Browse files
committed
Cargo: update Rustls & associated crates to 0.23
* updates rustls 0.22 to 0.23 * updates tokio-rustls 0.25 to 0.26 * updates rustls-platform-verifier 0.2 to 0.3 * addresses default crypto provider requirements for tests, examples * makes aws-lc-rs the default crypto provider, matching upstream. Ring remains available opt-in with the `ring` feature.
1 parent ccd5ec1 commit 731d19e

File tree

4 files changed

+42
-11
lines changed

4 files changed

+42
-11
lines changed

Cargo.toml

+6-6
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,23 @@ 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 }
21-
rustls = { version = "0.22", default-features = false }
20+
rustls-platform-verifier = { version = "0.3", optional = true }
21+
rustls = { version = "0.23", default-features = false }
2222
tokio = "1.0"
23-
tokio-rustls = { version = "0.25", default-features = false }
23+
tokio-rustls = { version = "0.26", default-features = false }
2424
tower-service = "0.3"
2525
webpki-roots = { version = "0.26", optional = true }
2626
futures-util = { version = "0.3", default-features = false }
2727

2828
[dev-dependencies]
2929
http-body-util = "0.1"
3030
hyper-util = { version = "0.1", default-features = false, features = ["server-auto"] }
31-
rustls = { version = "0.22", default-features = false, features = ["tls12"] }
31+
rustls = { version = "0.23", default-features = false, features = ["tls12"] }
3232
rustls-pemfile = "2"
3333
tokio = { version = "1.0", features = ["io-std", "macros", "net", "rt-multi-thread"] }
3434

3535
[features]
36-
default = ["native-tokio", "http1", "tls12", "logging", "ring"]
36+
default = ["native-tokio", "http1", "tls12", "logging", "aws-lc-rs"]
3737
aws-lc-rs = ["rustls/aws_lc_rs"]
3838
http1 = ["hyper-util/http1"]
3939
http2 = ["hyper-util/http2"]
@@ -51,7 +51,7 @@ required-features = ["native-tokio", "http1"]
5151
[[example]]
5252
name = "server"
5353
path = "examples/server.rs"
54-
required-features = ["ring"]
54+
required-features = ["aws-lc-rs"]
5555

5656
[package.metadata.docs.rs]
5757
all-features = true

examples/client.rs

+6
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ fn error(err: String) -> io::Error {
2626

2727
#[tokio::main]
2828
async fn run_client() -> io::Result<()> {
29+
// Set a process wide default crypto provider.
30+
#[cfg(feature = "ring")]
31+
let _ = rustls::crypto::ring::default_provider().install_default();
32+
#[cfg(feature = "aws-lc-rs")]
33+
let _ = rustls::crypto::aws_lc_rs::default_provider().install_default();
34+
2935
// First parameter is target URL (mandatory).
3036
let url = match env::args().nth(1) {
3137
Some(ref url) => Uri::from_str(url).map_err(|e| error(format!("{}", e)))?,

examples/server.rs

+6
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ fn error(err: String) -> io::Error {
3434

3535
#[tokio::main]
3636
async fn run_server() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
37+
// Set a process wide default crypto provider.
38+
#[cfg(feature = "ring")]
39+
let _ = rustls::crypto::ring::default_provider().install_default();
40+
#[cfg(feature = "aws-lc-rs")]
41+
let _ = rustls::crypto::aws_lc_rs::default_provider().install_default();
42+
3743
// First parameter is port number (optional, defaults to 1337)
3844
let port = match env::args().nth(1) {
3945
Some(ref p) => p.parse()?,

src/connector/builder.rs

+24-5
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,15 @@ use crate::config::ConfigBuilderExt;
1717
/// ```
1818
/// use hyper_rustls::HttpsConnectorBuilder;
1919
///
20-
/// # #[cfg(all(feature = "webpki-roots", feature = "http1"))]
21-
/// let https = HttpsConnectorBuilder::new()
20+
/// # #[cfg(all(feature = "webpki-roots", feature = "http1", feature="aws-lc-rs"))]
21+
/// # {
22+
/// # let _ = rustls::crypto::aws_lc_rs::default_provider().install_default();
23+
/// let https = HttpsConnectorBuilder::new()
2224
/// .with_webpki_roots()
2325
/// .https_only()
2426
/// .enable_http1()
2527
/// .build();
28+
/// # }
2629
/// ```
2730
pub struct ConnectorBuilder<State>(State);
2831

@@ -54,7 +57,10 @@ impl ConnectorBuilder<WantsTlsConfig> {
5457
/// Use rustls' default crypto provider and other defaults, and the platform verifier
5558
///
5659
/// See [`ConfigBuilderExt::with_platform_verifier()`].
57-
#[cfg(all(feature = "ring", feature = "rustls-platform-verifier"))]
60+
#[cfg(all(
61+
any(feature = "ring", feature = "aws-lc-rs"),
62+
feature = "rustls-platform-verifier"
63+
))]
5864
pub fn with_platform_verifier(self) -> ConnectorBuilder<WantsSchemes> {
5965
self.with_tls_config(
6066
ClientConfig::builder()
@@ -67,7 +73,10 @@ impl ConnectorBuilder<WantsTlsConfig> {
6773
/// native roots.
6874
///
6975
/// See [`ConfigBuilderExt::with_native_roots`]
70-
#[cfg(all(feature = "ring", feature = "rustls-native-certs"))]
76+
#[cfg(all(
77+
any(feature = "ring", feature = "aws-lc-rs"),
78+
feature = "rustls-native-certs"
79+
))]
7180
pub fn with_native_roots(self) -> std::io::Result<ConnectorBuilder<WantsSchemes>> {
7281
Ok(self.with_tls_config(
7382
ClientConfig::builder()
@@ -97,7 +106,7 @@ impl ConnectorBuilder<WantsTlsConfig> {
97106
/// safe defaults.
98107
///
99108
/// See [`ConfigBuilderExt::with_webpki_roots`]
100-
#[cfg(all(feature = "ring", feature = "webpki-roots"))]
109+
#[cfg(all(any(feature = "ring", feature = "aws-lc-rs"), feature = "webpki-roots"))]
101110
pub fn with_webpki_roots(self) -> ConnectorBuilder<WantsSchemes> {
102111
self.with_tls_config(
103112
ClientConfig::builder()
@@ -316,6 +325,7 @@ mod tests {
316325
#[test]
317326
#[cfg(all(feature = "webpki-roots", feature = "http1"))]
318327
fn test_builder() {
328+
ensure_global_state();
319329
let _connector = super::ConnectorBuilder::new()
320330
.with_webpki_roots()
321331
.https_only()
@@ -327,6 +337,7 @@ mod tests {
327337
#[cfg(feature = "http1")]
328338
#[should_panic(expected = "ALPN protocols should not be pre-defined")]
329339
fn test_reject_predefined_alpn() {
340+
ensure_global_state();
330341
let roots = rustls::RootCertStore::empty();
331342
let mut config_with_alpn = rustls::ClientConfig::builder()
332343
.with_root_certificates(roots)
@@ -342,6 +353,7 @@ mod tests {
342353
#[test]
343354
#[cfg(all(feature = "http1", feature = "http2"))]
344355
fn test_alpn() {
356+
ensure_global_state();
345357
let roots = rustls::RootCertStore::empty();
346358
let tls_config = rustls::ClientConfig::builder()
347359
.with_root_certificates(roots)
@@ -403,4 +415,11 @@ mod tests {
403415
.build();
404416
assert_eq!(&connector.tls_config.alpn_protocols, &[b"h2".to_vec()]);
405417
}
418+
419+
fn ensure_global_state() {
420+
#[cfg(feature = "ring")]
421+
let _ = rustls::crypto::ring::default_provider().install_default();
422+
#[cfg(feature = "aws-lc-rs")]
423+
let _ = rustls::crypto::aws_lc_rs::default_provider().install_default();
424+
}
406425
}

0 commit comments

Comments
 (0)