Skip to content

Commit d7b0612

Browse files
author
Sean Karlage
committed
Add changes from PR tafia#28 for updates due to tokio-rustls bump
1 parent 72ef4ae commit d7b0612

File tree

2 files changed

+30
-9
lines changed

2 files changed

+30
-9
lines changed

Changelog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
- test: Adding missing tests
99
- chore: Changes to the build process or auxiliary tools/libraries/documentation
1010

11+
## 0.9.1
12+
- feat: upgrade rustls stack to tokio-rustls 0.23
13+
1114
## 0.9.0
1215
- feat: upgrade to tokio 1.0
1316
- feat: add tokio-openssl support

src/lib.rs

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ use openssl::ssl::{SslConnector as OpenSslConnector, SslMethod};
8585
#[cfg(feature = "openssl-tls")]
8686
use tokio_openssl::SslStream;
8787
#[cfg(feature = "rustls-base")]
88-
use webpki::DNSNameRef;
88+
use tokio_rustls::rustls::ServerName;
8989

9090
type BoxError = Box<dyn std::error::Error + Send + Sync>;
9191

@@ -288,19 +288,31 @@ impl<C> ProxyConnector<C> {
288288
/// Create a new secured Proxies
289289
#[cfg(feature = "rustls-base")]
290290
pub fn new(connector: C) -> Result<Self, io::Error> {
291-
let mut config = tokio_rustls::rustls::ClientConfig::new();
291+
let mut config = tokio_rustls::rustls::ClientConfig::builder();
292292

293293
#[cfg(feature = "rustls")]
294294
{
295-
config.root_store =
296-
rustls_native_certs::load_native_certs().map_err(|(_store, io)| io)?;
295+
let mut roots = tokio_rustls::rustls::RootCertStore::empty();
296+
for cert in rustls_native_certs::load_native_certs()? {
297+
let cert = rustls::Certificate(cert.0);
298+
roots.add(&cert).map_err(io_err)?;
299+
}
300+
config.with_root_certificates(roots).with_no_client_auth()
297301
}
298302

299303
#[cfg(feature = "rustls-webpki")]
300304
{
301-
config
302-
.root_store
303-
.add_server_trust_anchors(&webpki_roots::TLS_SERVER_ROOTS);
305+
let mut roots = tokio_rustls::rustls::RootCertStore::empty();
306+
roots.add_server_trust_anchors(webpki_roots::TLS_SERVER_ROOTS.0.into_iter().map(
307+
|trust_achor| {
308+
rustls::OwnedTrustAnchor::from_subject_spki_name_constraints(
309+
trust_anchor.subject,
310+
trust_anchor.spki,
311+
trust_anchor.name_constraints,
312+
)
313+
}
314+
));
315+
config.with_root_certificates(roots).with_no_client_auth()
304316
}
305317

306318
let cfg = Arc::new(config);
@@ -442,7 +454,13 @@ where
442454
if let (Some(p), Some(host)) = (self.match_proxy(&uri), uri.host()) {
443455
if uri.scheme() == Some(&http::uri::Scheme::HTTPS) || p.force_connect {
444456
let host = host.to_owned();
445-
let port = uri.port_u16().unwrap_or(if uri.scheme() == Some(&http::uri::Scheme::HTTP) { 80 } else { 443 });
457+
let port =
458+
uri.port_u16()
459+
.unwrap_or(if uri.scheme() == Some(&http::uri::Scheme::HTTP) {
460+
80
461+
} else {
462+
443
463+
});
446464
let tunnel = tunnel::new(&host, port, &p.headers);
447465
let connection =
448466
proxy_dst(&uri, &p.uri).map(|proxy_url| self.connector.call(proxy_url));
@@ -471,7 +489,7 @@ where
471489
#[cfg(feature = "rustls-base")]
472490
Some(tls) => {
473491
let dnsref =
474-
mtry!(DNSNameRef::try_from_ascii_str(&host).map_err(io_err));
492+
mtry!(ServerName::try_from(host.as_str()).map_err(io_err));
475493
let tls = TlsConnector::from(tls);
476494
let secure_stream =
477495
mtry!(tls.connect(dnsref, tunnel_stream).await.map_err(io_err));

0 commit comments

Comments
 (0)