Skip to content

Commit b3085bc

Browse files
authored
Merge pull request #38 from crawford/ring
Update to rustls 0.12
2 parents 4848802 + 8b2e758 commit b3085bc

File tree

4 files changed

+41
-27
lines changed

4 files changed

+41
-27
lines changed

Cargo.toml

+5-4
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@ repository = "https://github.com/ctz/hyper-rustls"
1111
[dependencies]
1212
futures = "0.1.13"
1313
hyper = "0.11"
14-
rustls = "0.11.0"
14+
rustls = "0.12"
1515
tokio-core = "0.1.7"
1616
tokio-io = "0.1.1"
1717
tokio-proto = "0.1"
18-
tokio-rustls = { version = "0.4.0", features = [ "tokio-proto" ] }
18+
tokio-rustls = { version = "0.5", features = [ "tokio-proto" ] }
1919
tokio-service = "0.1.0"
20-
webpki-roots = "0.13.0"
21-
ct-logs = "0.2.0"
20+
webpki = "0.18.0-alpha"
21+
webpki-roots = "0.14"
22+
ct-logs = "0.3"

examples/server.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ fn main() {
6565
let addr = format!("127.0.0.1:{}", port).parse().unwrap();
6666
let certs = load_certs("examples/sample.pem");
6767
let key = load_private_key("examples/sample.rsa");
68-
let mut cfg = rustls::ServerConfig::new();
68+
let mut cfg = rustls::ServerConfig::new(rustls::NoClientAuth::new());
6969
cfg.set_single_cert(certs, key);
7070
let tls = proto::Server::new(Http::new(), std::sync::Arc::new(cfg));
7171
let tcp = tokio_proto::TcpServer::new(tls, addr);

src/connector.rs

+33-21
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use stream::MaybeHttpsStream;
88
use tokio_core::reactor::Handle;
99
use tokio_rustls::ClientConfigExt;
1010
use tokio_service::Service;
11+
use webpki::{DNSName, DNSNameRef};
1112
use webpki_roots;
1213
use ct_logs;
1314

@@ -26,9 +27,14 @@ impl HttpsConnector {
2627
let mut http = HttpConnector::new(threads, handle);
2728
http.enforce_http(false);
2829
let mut config = ClientConfig::new();
29-
config.root_store.add_server_trust_anchors(&webpki_roots::TLS_SERVER_ROOTS);
30+
config
31+
.root_store
32+
.add_server_trust_anchors(&webpki_roots::TLS_SERVER_ROOTS);
3033
config.ct_logs = Some(&ct_logs::LOGS);
31-
HttpsConnector { http: http, tls_config: Arc::new(config) }
34+
HttpsConnector {
35+
http: http,
36+
tls_config: Arc::new(config),
37+
}
3238
}
3339
}
3440

@@ -55,36 +61,42 @@ impl Service for HttpsConnector {
5561

5662
fn call(&self, uri: Uri) -> Self::Future {
5763
let is_https = uri.scheme() == Some("https");
58-
let host = match uri.host() {
59-
Some(host) => host.to_owned(),
60-
None => return HttpsConnecting(
61-
Box::new(
62-
::futures::future::err(
63-
io::Error::new(
64-
io::ErrorKind::InvalidInput,
65-
"invalid url, missing host"
66-
)
67-
)
68-
)
69-
),
64+
let host: DNSName = match uri.host() {
65+
Some(host) => match DNSNameRef::try_from_ascii_str(host) {
66+
Ok(host) => host.into(),
67+
Err(err) => {
68+
return HttpsConnecting(Box::new(::futures::future::err(io::Error::new(
69+
io::ErrorKind::InvalidInput,
70+
format!("invalid url: {:?}", err),
71+
))))
72+
}
73+
},
74+
None => {
75+
return HttpsConnecting(Box::new(::futures::future::err(io::Error::new(
76+
io::ErrorKind::InvalidInput,
77+
"invalid url, missing host",
78+
))))
79+
}
7080
};
7181
let connecting = self.http.call(uri);
7282

7383
HttpsConnecting(if is_https {
7484
let tls = self.tls_config.clone();
75-
Box::new(connecting.and_then(move |tcp| {
76-
tls
77-
.connect_async(&host, tcp)
78-
.map_err(|e| io::Error::new(io::ErrorKind::Other, e))
79-
}).map(|tls| MaybeHttpsStream::Https(tls))
80-
.map_err(|e| io::Error::new(io::ErrorKind::Other, e)))
85+
Box::new(
86+
connecting
87+
.and_then(move |tcp| {
88+
tls.connect_async(host.as_ref(), tcp)
89+
.map_err(|e| io::Error::new(io::ErrorKind::Other, e))
90+
})
91+
.map(|tls| MaybeHttpsStream::Https(tls))
92+
.map_err(|e| io::Error::new(io::ErrorKind::Other, e)),
93+
)
8194
} else {
8295
Box::new(connecting.map(|tcp| MaybeHttpsStream::Http(tcp)))
8396
})
8497
}
8598
}
8699

87-
88100
pub struct HttpsConnecting(Box<Future<Item = MaybeHttpsStream, Error = io::Error>>);
89101

90102
impl Future for HttpsConnecting {

src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,16 @@
2525
//! }
2626
//! ```
2727
28+
extern crate ct_logs;
2829
extern crate futures;
2930
extern crate hyper;
3031
extern crate rustls;
3132
extern crate tokio_core;
3233
extern crate tokio_io;
3334
extern crate tokio_rustls;
3435
extern crate tokio_service;
36+
extern crate webpki;
3537
extern crate webpki_roots;
36-
extern crate ct_logs;
3738

3839
mod connector;
3940
mod stream;

0 commit comments

Comments
 (0)