From f27056467c4c32c4d357aca2ae4fd5f1b4e0fc15 Mon Sep 17 00:00:00 2001 From: Carl Lerche Date: Thu, 11 Jan 2018 22:35:47 -0800 Subject: [PATCH] Track rustls / ring --- Cargo.toml | 8 ++--- examples/akamai.rs | 17 +++++---- examples/client.rs | 3 +- examples/server-tr.rs | 82 ------------------------------------------- 4 files changed, 13 insertions(+), 97 deletions(-) delete mode 100644 examples/server-tr.rs diff --git a/Cargo.toml b/Cargo.toml index ec72042..083578c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -53,7 +53,7 @@ serde_json = "1.0.0" # Akamai example tokio-core = "0.1" env_logger = "0.4.3" -io-dump = { git = "https://github.com/carllerche/io-dump" } -rustls = "0.11" -tokio-rustls = { git = "https://github.com/briansmith/tokio-rustls", tag = "b/p1" } -webpki-roots = "0.13" +rustls = "0.12" +tokio-rustls = "0.5.0" +webpki = "0.18.0-alpha" +webpki-roots = "0.14" diff --git a/examples/akamai.rs b/examples/akamai.rs index 1c391ee..e14cc39 100644 --- a/examples/akamai.rs +++ b/examples/akamai.rs @@ -2,10 +2,10 @@ extern crate env_logger; extern crate futures; extern crate h2; extern crate http; -extern crate io_dump; extern crate rustls; extern crate tokio_core; extern crate tokio_rustls; +extern crate webpki; extern crate webpki_roots; use h2::client; @@ -18,6 +18,7 @@ use tokio_core::reactor; use rustls::Session; use tokio_rustls::ClientConfigExt; +use webpki::DNSNameRef; use std::net::ToSocketAddrs; @@ -47,21 +48,19 @@ pub fn main() { let handle = core.handle(); let tcp = TcpStream::connect(&addr, &handle); + let dns_name = DNSNameRef::try_from_ascii_str("http2.akamai.com").unwrap(); let tcp = tcp.then(|res| { let tcp = res.unwrap(); tls_client_config - .connect_async("http2.akamai.com", tcp) + .connect_async(dns_name, tcp) .then(|res| { let tls = res.unwrap(); - let negotiated_protcol = { + { let (_, session) = tls.get_ref(); - session.get_alpn_protocol() - }; - assert_eq!(Some(ALPN_H2), negotiated_protcol.as_ref().map(|x| &**x)); - - // Dump output to stdout - let tls = io_dump::Dump::to_stdout(tls); + let negotiated_protocol = session.get_alpn_protocol(); + assert_eq!(Some(ALPN_H2), negotiated_protocol.as_ref().map(|x| &**x)); + } println!("Starting client handshake"); client::handshake(tls) diff --git a/examples/client.rs b/examples/client.rs index 547fe66..b7ad921 100644 --- a/examples/client.rs +++ b/examples/client.rs @@ -2,7 +2,6 @@ extern crate env_logger; extern crate futures; extern crate h2; extern crate http; -extern crate io_dump; extern crate tokio_core; use h2::client; @@ -54,7 +53,7 @@ pub fn main() { let tcp = TcpStream::connect(&"127.0.0.1:5928".parse().unwrap(), &handle); let tcp = tcp.then(|res| { - let tcp = io_dump::Dump::to_stdout(res.unwrap()); + let tcp = res.unwrap(); client::handshake(tcp) }).then(|res| { let (mut client, h2) = res.unwrap(); diff --git a/examples/server-tr.rs b/examples/server-tr.rs deleted file mode 100644 index f94d3cc..0000000 --- a/examples/server-tr.rs +++ /dev/null @@ -1,82 +0,0 @@ -extern crate bytes; -extern crate env_logger; -extern crate futures; -extern crate h2; -extern crate http; -extern crate tokio_core; - -use h2::server; - -use bytes::*; -use futures::*; -use http::*; - -use tokio_core::net::TcpListener; -use tokio_core::reactor; - -pub fn main() { - let _ = env_logger::init(); - - let mut core = reactor::Core::new().unwrap(); - let handle = core.handle(); - - let listener = TcpListener::bind(&"127.0.0.1:5928".parse().unwrap(), &handle).unwrap(); - - println!("listening on {:?}", listener.local_addr()); - - let server = listener.incoming().for_each(move |(socket, _)| { - // let socket = io_dump::Dump::to_stdout(socket); - - - let connection = server::handshake(socket) - .and_then(|conn| { - println!("H2 connection bound"); - - conn.for_each(|(request, mut respond)| { - println!("GOT request: {:?}", request); - - let response = Response::builder().status(StatusCode::OK).body(()).unwrap(); - - let mut send = match respond.send_response(response, false) { - Ok(send) => send, - Err(e) => { - println!(" error respond; err={:?}", e); - return Ok(()); - } - }; - - println!(">>>> sending data"); - if let Err(e) = send.send_data(Bytes::from_static(b"hello world"), false) { - println!(" -> err={:?}", e); - } - - let mut hdrs = HeaderMap::new(); - hdrs.insert("status", "ok".parse().unwrap()); - - println!(">>>> sending trailers"); - if let Err(e) = send.send_trailers(hdrs) { - println!(" -> err={:?}", e); - } - - Ok(()) - }).and_then(|_| { - println!( - "~~~~~~~~~~~~~~~~~~~~~~~~~~~ H2 connection CLOSE !!!!!! ~~~~~~~~~~~" - ); - Ok(()) - }) - }) - .then(|res| { - if let Err(e) = res { - println!(" -> err={:?}", e); - } - - Ok(()) - }); - - handle.spawn(connection); - Ok(()) - }); - - core.run(server).unwrap(); -}