Skip to content
Draft
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
116 changes: 71 additions & 45 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 11 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ include = ["Cargo.toml", "LICENSE-MIT", "LICENSE-APACHE", "LICENSE-ISC", "README

[features]
default = ["native-tokio", "http1", "tls12", "logging", "aws-lc-rs"]
aws-lc-rs = ["rustls/aws_lc_rs"]
fips = ["aws-lc-rs", "rustls/fips"]
aws-lc-rs = ["dep:rustls-aws-lc-rs", "tokio-rustls/aws-lc-rs"]
fips = ["aws-lc-rs", "rustls-aws-lc-rs/fips", "tokio-rustls/fips"]
http1 = ["hyper-util/http1"]
http2 = ["hyper-util/http2"]
logging = ["log", "tokio-rustls/logging", "rustls/logging"]
logging = ["log", "tokio-rustls/logging", "rustls/log"]
native-tokio = ["rustls-native-certs"]
ring = ["rustls/ring"]
tls12 = ["tokio-rustls/tls12", "rustls/tls12"]
ring = ["dep:rustls-ring", "tokio-rustls/ring"]
tls12 = ["tokio-rustls/tls12"]
webpki-tokio = ["webpki-roots"]

[dependencies]
Expand All @@ -29,18 +29,20 @@ hyper = { version = "1", default-features = false }
hyper-util = { version = "0.1", default-features = false, features = ["client-legacy", "tokio"] }
log = { version = "0.4.4", optional = true }
rustls-native-certs = { version = "0.8", optional = true }
rustls-platform-verifier = { version = "0.7", optional = true }
rustls = { version = "0.23", default-features = false }
rustls-platform-verifier = { git = "https://github.com/rustls/rustls-platform-verifier.git", rev = "733494d8ade721f249dc1b4e93196adf409ae8c0", version = "0.7", optional = true }
rustls = { git = "https://github.com/rustls/rustls.git", branch = "main", version = "0.24.0-dev.0", default-features = false, features = ["webpki"] }
rustls-aws-lc-rs = { git = "https://github.com/rustls/rustls.git", branch = "main", version = "0.1.0-dev.0", default-features = false, features = ["aws-lc-sys", "std"], optional = true }
rustls-ring = { git = "https://github.com/rustls/rustls.git", branch = "main", version = "0.1.0-dev.0", default-features = false, features = ["std"], optional = true }
tokio = "1.0"
tokio-rustls = { version = "0.26", default-features = false }
tokio-rustls = { git = "https://github.com/rustls/tokio-rustls.git", rev = "be34e90bfe59f124363d725ceb739a435bfafa1e", version = "0.26.4", default-features = false }
tower-service = "0.3"
webpki-roots = { version = "1", optional = true }

[dev-dependencies]
cfg-if = "1"
http-body-util = "0.1"
hyper-util = { version = "0.1", default-features = false, features = ["server-auto"] }
rustls = { version = "0.23", default-features = false, features = ["tls12"] }
rustls = { git = "https://github.com/rustls/rustls.git", branch = "main", version = "0.24.0-dev.0", default-features = false, features = ["webpki"] }
tokio = { version = "1.0", features = ["io-std", "macros", "net", "rt-multi-thread"] }

[[example]]
Expand Down
27 changes: 18 additions & 9 deletions examples/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use rustls::pki_types::CertificateDer;
use rustls::RootCertStore;

use std::str::FromStr;
use std::sync::Arc;
use std::{env, io};

fn main() {
Expand All @@ -28,12 +29,6 @@ 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 All @@ -54,14 +49,16 @@ async fn run_client() -> io::Result<()> {
let mut roots = RootCertStore::empty();
roots.add_parsable_certificates(certs);
// TLS client config using the custom CA store for lookups
rustls::ClientConfig::builder()
rustls::ClientConfig::builder(provider())
.with_root_certificates(roots)
.with_no_client_auth()
.map_err(|e| error(e.to_string()))?
}
// Default TLS client config with native roots
None => rustls::ClientConfig::builder()
None => rustls::ClientConfig::builder(provider())
.with_native_roots()?
.with_no_client_auth(),
.with_no_client_auth()
.map_err(|e| error(e.to_string()))?,
};
// Prepare the HTTPS connector
let https = hyper_rustls::HttpsConnectorBuilder::new()
Expand Down Expand Up @@ -97,3 +94,15 @@ async fn run_client() -> io::Result<()> {

fut.await
}

fn provider() -> Arc<rustls::crypto::CryptoProvider> {
#[cfg(feature = "aws-lc-rs")]
{
return Arc::new(rustls_aws_lc_rs::DEFAULT_PROVIDER.clone());
}

#[cfg(all(not(feature = "aws-lc-rs"), feature = "ring"))]
{
return Arc::new(rustls_ring::DEFAULT_PROVIDER.clone());
}
}
Loading
Loading