Skip to content
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
156 changes: 92 additions & 64 deletions Cargo.lock

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

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,16 @@ with_axum = ["axum-core", "http", "async-trait"]

[dev-dependencies]
tokio = { version = "1.25.0", features = ["full", "macros"] }
tokio-rustls = "0.24.0"
rustls-pemfile = "1.0"
tokio-rustls = "0.26.0"
rustls-pemfile = "2.2"
hyper-util = { version = "0.1.0", features = ["tokio"] }
http-body-util = { version = "0.1.0" }
hyper = { version = "1", features = ["http1", "server", "client"] }
assert2 = "0.3.4"
trybuild = "1.0.80"
criterion = "0.4.0"
anyhow = "1.0.71"
webpki-roots = "0.23.0"
webpki-roots = "1.0"
bytes = "1.4.0"
axum = "0.8.1"

Expand Down
25 changes: 8 additions & 17 deletions examples/tls_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ use hyper::upgrade::Upgraded;
use hyper::Request;
use hyper_util::rt::TokioIo;
use tokio::net::TcpStream;
use tokio_rustls::rustls::pki_types::ServerName;
use tokio_rustls::rustls::ClientConfig;
use tokio_rustls::rustls::OwnedTrustAnchor;
use tokio_rustls::rustls::RootCertStore;
use tokio_rustls::TlsConnector;

struct SpawnExecutor;
Expand All @@ -30,20 +31,11 @@ where
}

fn tls_connector() -> Result<TlsConnector> {
let mut root_store = tokio_rustls::rustls::RootCertStore::empty();

root_store.add_trust_anchors(webpki_roots::TLS_SERVER_ROOTS.0.iter().map(
|ta| {
OwnedTrustAnchor::from_subject_spki_name_constraints(
ta.subject,
ta.spki,
ta.name_constraints,
)
},
));
let root_store = RootCertStore {
roots: webpki_roots::TLS_SERVER_ROOTS.to_vec(),
};

let config = ClientConfig::builder()
.with_safe_defaults()
.with_root_certificates(root_store)
.with_no_client_auth();

Expand All @@ -56,10 +48,9 @@ async fn connect(domain: &str) -> Result<FragmentCollector<TokioIo<Upgraded>>> {

let tcp_stream = TcpStream::connect(&addr).await?;
let tls_connector = tls_connector().unwrap();
let domain =
tokio_rustls::rustls::ServerName::try_from(domain).map_err(|_| {
std::io::Error::new(std::io::ErrorKind::InvalidInput, "invalid dnsname")
})?;
let domain = ServerName::try_from(domain.to_string()).map_err(|_| {
std::io::Error::new(std::io::ErrorKind::InvalidInput, "invalid dnsname")
})?;

let tls_stream = tls_connector.connect(domain, tcp_stream).await?;

Expand Down
Loading
Loading