[Added] danger feature

This commit is contained in:
quininer kel 2017-07-21 17:57:57 +08:00
parent c3961081ec
commit 36fabdadfd
2 changed files with 32 additions and 0 deletions

View File

@ -10,6 +10,9 @@ readme = "README.md"
description = "Asynchronous TLS/SSL streams for Tokio using Rustls."
categories = ["asynchronous", "cryptography", "network-programming"]
[features]
danger = [ "rustls/dangerous_configuration" ]
[dependencies]
futures = "0.1"
tokio-io = "0.1"

View File

@ -22,6 +22,11 @@ pub trait ClientConfigExt {
fn connect_async<S>(&self, domain: &str, stream: S)
-> ConnectAsync<S>
where S: AsyncRead + AsyncWrite;
#[cfg(feature = "danger")]
fn danger_connect_async_without_providing_domain_for_certificate_verification_and_server_name_indication<S>(&self, stream: S)
-> ConnectAsync<S>
where S: AsyncRead + AsyncWrite;
}
/// Extension trait for the `Arc<ServerConfig>` type in the `rustls` crate.
@ -48,6 +53,30 @@ impl ClientConfigExt for Arc<ClientConfig> {
{
connect_async_with_session(stream, ClientSession::new(self, domain))
}
#[cfg(feature = "danger")]
fn danger_connect_async_without_providing_domain_for_certificate_verification_and_server_name_indication<S>(&self, stream: S)
-> ConnectAsync<S>
where S: AsyncRead + AsyncWrite
{
use rustls::{ ServerCertVerifier, RootCertStore, Certificate, TLSError };
struct NoCertVerifier;
impl ServerCertVerifier for NoCertVerifier {
fn verify_server_cert(&self, _: &RootCertStore, _: &[Certificate], _: &str)
-> Result<(), TLSError>
{
Ok(())
}
}
let mut client_config = ClientConfig::new();
client_config.clone_from(self);
client_config.dangerous()
.set_certificate_verifier(Box::new(NoCertVerifier));
Arc::new(client_config).connect_async("", stream)
}
}
#[inline]