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

update main dependencies #38

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
16 changes: 8 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,18 @@ hyper = { version = "0.14", features = ["client"] }
tower-service = "0.3"
http = "0.2"
futures-util = { version = "0.3", default-features = false }
bytes = "1.0"
hyper-tls = { version = "0.5.0", optional = true }
tokio-native-tls = { version = "0.3.0", optional = true }
bytes = "1"
hyper-tls = { version = "0.5", optional = true }
tokio-native-tls = { version = "0.3", optional = true }
native-tls = { version = "0.2", optional = true }
openssl = { version = "0.10", optional = true }
tokio-openssl = { version = "0.6", optional = true }
tokio-rustls = { version = "0.22", optional = true }
hyper-rustls = { version = "0.22", optional = true }
tokio-rustls = { version = "0.24", optional = true }
hyper-rustls = { version = "0.24", optional = true }

webpki = { version = "0.21", optional = true }
rustls-native-certs = { version = "0.5.0", optional = true }
webpki-roots = { version = "0.21.0", optional = true }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hope to see this MR merged soon. Currently facing https://rustsec.org/advisories/RUSTSEC-2023-0052 from this.

webpki = { version = "0.22", optional = true }
rustls-native-certs = { version = "0.6", optional = true }
webpki-roots = { version = "0.24", optional = true }
headers = "0.3"

[dev-dependencies]
Expand Down
51 changes: 33 additions & 18 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ use http::header::{HeaderMap, HeaderName, HeaderValue};
use hyper::{service::Service, Uri};

use futures_util::future::TryFutureExt;
#[cfg(feature = "rustls-base")]
use std::convert::TryFrom;
use std::{fmt, io, sync::Arc};
use std::{
future::Future,
Expand All @@ -77,15 +79,13 @@ use native_tls::TlsConnector as NativeTlsConnector;
#[cfg(feature = "tls")]
use tokio_native_tls::TlsConnector;
#[cfg(feature = "rustls-base")]
use tokio_rustls::TlsConnector;
use tokio_rustls::{rustls::ServerName, TlsConnector};

use headers::{authorization::Credentials, Authorization, HeaderMapExt, ProxyAuthorization};
#[cfg(feature = "openssl-tls")]
use openssl::ssl::{SslConnector as OpenSslConnector, SslMethod};
#[cfg(feature = "openssl-tls")]
use tokio_openssl::SslStream;
#[cfg(feature = "rustls-base")]
use webpki::DNSNameRef;

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

Expand Down Expand Up @@ -288,20 +288,27 @@ impl<C> ProxyConnector<C> {
/// Create a new secured Proxies
#[cfg(feature = "rustls-base")]
pub fn new(connector: C) -> Result<Self, io::Error> {
let mut config = tokio_rustls::rustls::ClientConfig::new();

let mut roots = tokio_rustls::rustls::RootCertStore::empty();
#[cfg(feature = "rustls")]
{
config.root_store =
rustls_native_certs::load_native_certs().map_err(|(_store, io)| io)?;
for cert in rustls_native_certs::load_native_certs()? {
roots
.add(&tokio_rustls::rustls::Certificate(cert.0))
.map_err(io_err)?;
}

#[cfg(feature = "rustls-webpki")]
{
config
.root_store
.add_server_trust_anchors(&webpki_roots::TLS_SERVER_ROOTS);
}
roots.add_server_trust_anchors(webpki_roots::TLS_SERVER_ROOTS.0.iter().map(|ta| {
tokio_rustls::rustls::OwnedTrustAnchor::from_subject_spki_name_constraints(
ta.subject,
ta.spki,
ta.name_constraints,
)
}));

let config = tokio_rustls::rustls::ClientConfig::builder()
.with_safe_defaults()
.with_root_certificates(roots)
.with_no_client_auth();

let cfg = Arc::new(config);
let tls = TlsConnector::from(cfg);
Expand Down Expand Up @@ -442,7 +449,13 @@ where
if let (Some(p), Some(host)) = (self.match_proxy(&uri), uri.host()) {
if uri.scheme() == Some(&http::uri::Scheme::HTTPS) || p.force_connect {
let host = host.to_owned();
let port = uri.port_u16().unwrap_or(if uri.scheme() == Some(&http::uri::Scheme::HTTP) { 80 } else { 443 });
let port =
uri.port_u16()
.unwrap_or(if uri.scheme() == Some(&http::uri::Scheme::HTTP) {
80
} else {
443
});
let tunnel = tunnel::new(&host, port, &p.headers);
let connection =
proxy_dst(&uri, &p.uri).map(|proxy_url| self.connector.call(proxy_url));
Expand Down Expand Up @@ -470,11 +483,13 @@ where

#[cfg(feature = "rustls-base")]
Some(tls) => {
let dnsref =
mtry!(DNSNameRef::try_from_ascii_str(&host).map_err(io_err));
let server_name =
mtry!(ServerName::try_from(host.as_str()).map_err(io_err));
let tls = TlsConnector::from(tls);
let secure_stream =
mtry!(tls.connect(dnsref, tunnel_stream).await.map_err(io_err));
let secure_stream = mtry!(tls
.connect(server_name, tunnel_stream)
.await
.map_err(io_err));

Ok(ProxyStream::Secured(secure_stream))
}
Expand Down