Skip to content

Commit 351b03c

Browse files
authored
Merge pull request #139 from adamreichold/bump-rustls
Bump rustls and webpki to enable connecting to IP addresses over TLS.
2 parents 3fe9967 + 2198089 commit 351b03c

4 files changed

Lines changed: 21 additions & 30 deletions

File tree

Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ mime = {version = "0.3.16", optional = true}
2424
multipart = {version = "0.18.0", default-features = false, features = ["client"], optional = true}
2525
native-tls = {version = "0.2.10", optional = true}
2626
rustls-native-certs = { version = "0.6", optional = true}
27-
rustls-opt-dep = {package = "rustls", version = "0.20.6", features = ["dangerous_configuration"], optional = true}
27+
rustls-opt-dep = {package = "rustls", version = "0.21.0", features = ["dangerous_configuration"], optional = true}
2828
serde = {version = "1.0.143", optional = true}
2929
serde_json = {version = "1.0.83", optional = true}
3030
serde_urlencoded = {version = "0.7.1", optional = true}
3131
url = "2.2.2"
3232
webpki = {version = "0.22.0", optional = true}
33-
webpki-roots = {version = "0.22.4", optional = true}
33+
webpki-roots = {version = "0.23.0", optional = true}
3434

3535
[dev-dependencies]
3636
anyhow = "1.0.61"
@@ -39,6 +39,7 @@ futures = "0.3.23"
3939
futures-util = "0.3.23"
4040
hyper = "0.14.20"
4141
lazy_static = "1.4.0"
42+
multipart = {version = "0.18.0", default-features = false, features = ["server"]}
4243
tokio = {version = "1.20.1", features = ["full"]}
4344
tokio-rustls = "0.22.0"
4445
tokio-stream = {version = "0.1.9", features = ["net"]}

src/error.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,6 @@ pub enum ErrorKind {
8989
InvalidMimeType(String),
9090
/// TLS was not enabled by features.
9191
TlsDisabled,
92-
/// WebPKI error.
93-
#[cfg(feature = "__rustls")]
94-
WebPKI(webpki::Error),
9592
}
9693

9794
/// A type that contains all the errors that can possibly occur while accessing an HTTP server.
@@ -135,8 +132,6 @@ impl Display for Error {
135132
InvalidDNSName(ref e) => write!(w, "Invalid DNS name: {e}"),
136133
InvalidMimeType(ref e) => write!(w, "Invalid mime type: {e}"),
137134
TlsDisabled => write!(w, "TLS is disabled, activate one of the tls- features"),
138-
#[cfg(feature = "__rustls")]
139-
WebPKI(ref e) => write!(w, "WebPKI error: {e}"),
140135
}
141136
}
142137
}
@@ -152,8 +147,6 @@ impl StdError for Error {
152147
Json(ref e) => Some(e),
153148
#[cfg(any(feature = "tls-native", feature = "__rustls"))]
154149
Tls(ref e) => Some(e),
155-
#[cfg(feature = "__rustls")]
156-
WebPKI(ref e) => Some(e),
157150
_ => None,
158151
}
159152
}
@@ -235,12 +228,5 @@ impl From<InvalidResponseKind> for io::Error {
235228
}
236229
}
237230

238-
#[cfg(feature = "__rustls")]
239-
impl From<webpki::Error> for Error {
240-
fn from(err: webpki::Error) -> Error {
241-
Error(Box::new(ErrorKind::WebPKI(err)))
242-
}
243-
}
244-
245231
/// Wrapper for the `Result` type with an `Error`.
246232
pub type Result<T = ()> = result::Result<T, Error>;

src/request/proxy.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,11 @@ impl ProxySettings {
7878

7979
if !disable_proxies {
8080
if let Some(no_proxy) = no_proxy {
81-
no_proxy_hosts.extend(no_proxy.split(',').map(|s|
82-
s.trim().trim_start_matches('.').to_lowercase()));
81+
no_proxy_hosts.extend(
82+
no_proxy
83+
.split(',')
84+
.map(|s| s.trim().trim_start_matches('.').to_lowercase()),
85+
);
8386
}
8487
}
8588

@@ -101,7 +104,11 @@ impl ProxySettings {
101104
}
102105

103106
if let Some(host) = url.host_str() {
104-
if !self.no_proxy_hosts.iter().any(|x| host.ends_with(x.to_lowercase().as_str())) {
107+
if !self
108+
.no_proxy_hosts
109+
.iter()
110+
.any(|x| host.ends_with(x.to_lowercase().as_str()))
111+
{
105112
return match url.scheme() {
106113
"http" => self.http_proxy.as_ref(),
107114
"https" => self.https_proxy.as_ref(),

src/tls/rustls_impl.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -198,17 +198,14 @@ impl ServerCertVerifier for CustomCertVerifier {
198198
.upstream
199199
.verify_server_cert(end_entity, intermediates, server_name, scts, ocsp_response, now)
200200
{
201-
Err(
202-
rustls::Error::NoCertificatesPresented
203-
| rustls::Error::InvalidCertificateEncoding
204-
| rustls::Error::InvalidCertificateSignatureType
205-
| rustls::Error::InvalidCertificateSignature
206-
| rustls::Error::InvalidCertificateData(_),
207-
) if self.accept_invalid_certs => Ok(ServerCertVerified::assertion()),
208-
209-
// c.f. https://github.com/rustls/rustls/blob/2f90c1bf7339e7862dfc850f2b23e2010c795ddb/rustls/tests/api.rs#L801
210-
Err(rustls::Error::InvalidCertificateData(msg))
211-
if self.accept_invalid_hostnames && msg.contains("CertNotValidForName") =>
201+
Err(rustls::Error::NoCertificatesPresented | rustls::Error::InvalidCertificate(_))
202+
if self.accept_invalid_certs =>
203+
{
204+
Ok(ServerCertVerified::assertion())
205+
}
206+
207+
Err(rustls::Error::InvalidCertificate(rustls::CertificateError::NotValidForName))
208+
if self.accept_invalid_hostnames =>
212209
{
213210
Ok(ServerCertVerified::assertion())
214211
}

0 commit comments

Comments
 (0)