diff --git a/test-server/Cargo.toml b/test-server/Cargo.toml index 512f65e1c..73278f165 100644 --- a/test-server/Cargo.toml +++ b/test-server/Cargo.toml @@ -28,6 +28,7 @@ default = [] # openssl ssl = ["openssl", "actix-server/ssl", "awc/ssl"] +rust-tls = ["rustls", "webpki", "actix-server/rust-tls", "awc/rust-tls"] [dependencies] actix-codec = "0.1.2" @@ -53,7 +54,5 @@ time = "0.1" tokio-tcp = "0.1" tokio-timer = "0.2" openssl = { version="0.10", optional = true } - -[dev-dependencies] -actix-web = "1.0.0" -actix-http = "0.2.4" +rustls = { version = "0.15.2", optional = true, features = ["dangerous_configuration"] } +webpki = { version = "0.19", optional = true } diff --git a/test-server/src/lib.rs b/test-server/src/lib.rs index ce73e181b..950a4f850 100644 --- a/test-server/src/lib.rs +++ b/test-server/src/lib.rs @@ -67,6 +67,21 @@ where R: IntoFuture, { RT.with(move |rt| rt.borrow_mut().get_mut().block_on(lazy(f))) +} pub struct NoCertificateVerification {} + +#[cfg(feature = "rust-tls")] +mod danger { + pub struct NoCertificateVerification {} + + impl rustls::ServerCertVerifier for NoCertificateVerification { + fn verify_server_cert(&self, + _roots: &rustls::RootCertStore, + _presented_certs: &[rustls::Certificate], + _dns_name: webpki::DNSNameRef<'_>, + _ocsp: &[u8]) -> Result { + Ok(rustls::ServerCertVerified::assertion()) + } + } } /// The `TestServer` type. @@ -151,7 +166,23 @@ impl TestServer { .ssl(builder.build()) .finish() } - #[cfg(not(feature = "ssl"))] + #[cfg(feature = "rust-tls")] + { + use rustls::ClientConfig; + use std::sync::Arc; + + let mut config = ClientConfig::new(); + let protos = vec![b"h2".to_vec(), b"http/1.1".to_vec()]; + config.set_protocols(&protos); + config.dangerous().set_certificate_verifier(Arc::new(danger::NoCertificateVerification{})); + + Connector::new() + .conn_lifetime(time::Duration::from_secs(0)) + .timeout(time::Duration::from_millis(500)) + .ssl(Arc::new(config)) + .finish() + } + #[cfg(not(any(feature = "ssl", feature = "rust-tls")))] { Connector::new() .conn_lifetime(time::Duration::from_secs(0))