Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0.27.0 preparation, Rustls 0.23 update #266

Merged
merged 4 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ jobs:
env:
RUST_BACKTRACE: 1

- name: cargo test (debug; defaults+ring)
run: cargo test --no-default-features --features ring,native-tokio,http1,tls12,logging
env:
RUST_BACKTRACE: 1

- name: cargo test (debug; all features)
run: cargo test --all-features
env:
Expand Down
14 changes: 7 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "hyper-rustls"
version = "0.26.0"
version = "0.27.0"
edition = "2021"
rust-version = "1.64"
license = "Apache-2.0 OR ISC OR MIT"
Expand All @@ -17,23 +17,23 @@ hyper-util = { version = "0.1", default-features = false, features = ["client-le
log = { version = "0.4.4", optional = true }
pki-types = { package = "rustls-pki-types", version = "1" }
rustls-native-certs = { version = "0.7", optional = true }
rustls-platform-verifier = { version = "0.2", optional = true }
rustls = { version = "0.22", default-features = false }
rustls-platform-verifier = { version = "0.3", optional = true }
cpu marked this conversation as resolved.
Show resolved Hide resolved
rustls = { version = "0.23", default-features = false }
tokio = "1.0"
tokio-rustls = { version = "0.25", default-features = false }
tokio-rustls = { version = "0.26", default-features = false }
tower-service = "0.3"
webpki-roots = { version = "0.26", optional = true }
futures-util = { version = "0.3", default-features = false }

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

[features]
default = ["native-tokio", "http1", "tls12", "logging", "ring"]
default = ["native-tokio", "http1", "tls12", "logging", "aws-lc-rs"]
aws-lc-rs = ["rustls/aws_lc_rs"]
http1 = ["hyper-util/http1"]
http2 = ["hyper-util/http2"]
Expand All @@ -51,7 +51,7 @@ required-features = ["native-tokio", "http1"]
[[example]]
name = "server"
path = "examples/server.rs"
required-features = ["ring"]
required-features = ["aws-lc-rs"]

[package.metadata.docs.rs]
all-features = true
Expand Down
6 changes: 6 additions & 0 deletions examples/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ fn error(err: String) -> io::Error {

#[tokio::main]
async fn run_client() -> io::Result<()> {
// Set a process wide default crypto provider.
#[cfg(feature = "ring")]
let _ = rustls::crypto::ring::default_provider().install_default();
#[cfg(feature = "aws-lc-rs")]
let _ = rustls::crypto::aws_lc_rs::default_provider().install_default();

// First parameter is target URL (mandatory).
let url = match env::args().nth(1) {
Some(ref url) => Uri::from_str(url).map_err(|e| error(format!("{}", e)))?,
Expand Down
7 changes: 6 additions & 1 deletion examples/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

use std::net::{Ipv4Addr, SocketAddr};
use std::sync::Arc;
use std::vec::Vec;
use std::{env, fs, io};

use http::{Method, Request, Response, StatusCode};
Expand Down Expand Up @@ -35,6 +34,12 @@ fn error(err: String) -> io::Error {

#[tokio::main]
async fn run_server() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
// Set a process wide default crypto provider.
#[cfg(feature = "ring")]
let _ = rustls::crypto::ring::default_provider().install_default();
#[cfg(feature = "aws-lc-rs")]
let _ = rustls::crypto::aws_lc_rs::default_provider().install_default();

// First parameter is port number (optional, defaults to 1337)
let port = match env::args().nth(1) {
Some(ref p) => p.parse()?,
Expand Down
29 changes: 24 additions & 5 deletions src/connector/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@ use crate::config::ConfigBuilderExt;
/// ```
/// use hyper_rustls::HttpsConnectorBuilder;
///
/// # #[cfg(all(feature = "webpki-roots", feature = "http1"))]
/// let https = HttpsConnectorBuilder::new()
/// # #[cfg(all(feature = "webpki-roots", feature = "http1", feature="aws-lc-rs"))]
/// # {
/// # let _ = rustls::crypto::aws_lc_rs::default_provider().install_default();
/// let https = HttpsConnectorBuilder::new()
/// .with_webpki_roots()
/// .https_only()
/// .enable_http1()
/// .build();
/// # }
/// ```
pub struct ConnectorBuilder<State>(State);

Expand Down Expand Up @@ -54,7 +57,10 @@ impl ConnectorBuilder<WantsTlsConfig> {
/// Use rustls' default crypto provider and other defaults, and the platform verifier
///
/// See [`ConfigBuilderExt::with_platform_verifier()`].
#[cfg(all(feature = "ring", feature = "rustls-platform-verifier"))]
#[cfg(all(
any(feature = "ring", feature = "aws-lc-rs"),
feature = "rustls-platform-verifier"
))]
pub fn with_platform_verifier(self) -> ConnectorBuilder<WantsSchemes> {
self.with_tls_config(
ClientConfig::builder()
Expand All @@ -67,7 +73,10 @@ impl ConnectorBuilder<WantsTlsConfig> {
/// native roots.
///
/// See [`ConfigBuilderExt::with_native_roots`]
#[cfg(all(feature = "ring", feature = "rustls-native-certs"))]
#[cfg(all(
any(feature = "ring", feature = "aws-lc-rs"),
feature = "rustls-native-certs"
))]
pub fn with_native_roots(self) -> std::io::Result<ConnectorBuilder<WantsSchemes>> {
Ok(self.with_tls_config(
ClientConfig::builder()
Expand Down Expand Up @@ -97,7 +106,7 @@ impl ConnectorBuilder<WantsTlsConfig> {
/// safe defaults.
///
/// See [`ConfigBuilderExt::with_webpki_roots`]
#[cfg(all(feature = "ring", feature = "webpki-roots"))]
#[cfg(all(any(feature = "ring", feature = "aws-lc-rs"), feature = "webpki-roots"))]
pub fn with_webpki_roots(self) -> ConnectorBuilder<WantsSchemes> {
self.with_tls_config(
ClientConfig::builder()
Expand Down Expand Up @@ -316,6 +325,7 @@ mod tests {
#[test]
#[cfg(all(feature = "webpki-roots", feature = "http1"))]
fn test_builder() {
ensure_global_state();
let _connector = super::ConnectorBuilder::new()
.with_webpki_roots()
.https_only()
Expand All @@ -327,6 +337,7 @@ mod tests {
#[cfg(feature = "http1")]
#[should_panic(expected = "ALPN protocols should not be pre-defined")]
fn test_reject_predefined_alpn() {
ensure_global_state();
let roots = rustls::RootCertStore::empty();
let mut config_with_alpn = rustls::ClientConfig::builder()
.with_root_certificates(roots)
Expand All @@ -342,6 +353,7 @@ mod tests {
#[test]
#[cfg(all(feature = "http1", feature = "http2"))]
fn test_alpn() {
ensure_global_state();
let roots = rustls::RootCertStore::empty();
let tls_config = rustls::ClientConfig::builder()
.with_root_certificates(roots)
Expand Down Expand Up @@ -403,4 +415,11 @@ mod tests {
.build();
assert_eq!(&connector.tls_config.alpn_protocols, &[b"h2".to_vec()]);
}

fn ensure_global_state() {
#[cfg(feature = "ring")]
let _ = rustls::crypto::ring::default_provider().install_default();
#[cfg(feature = "aws-lc-rs")]
let _ = rustls::crypto::aws_lc_rs::default_provider().install_default();
}
}
Loading