[Added] danger feature
This commit is contained in:
parent
c3961081ec
commit
36fabdadfd
@ -10,6 +10,9 @@ readme = "README.md"
|
|||||||
description = "Asynchronous TLS/SSL streams for Tokio using Rustls."
|
description = "Asynchronous TLS/SSL streams for Tokio using Rustls."
|
||||||
categories = ["asynchronous", "cryptography", "network-programming"]
|
categories = ["asynchronous", "cryptography", "network-programming"]
|
||||||
|
|
||||||
|
[features]
|
||||||
|
danger = [ "rustls/dangerous_configuration" ]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
futures = "0.1"
|
futures = "0.1"
|
||||||
tokio-io = "0.1"
|
tokio-io = "0.1"
|
||||||
|
29
src/lib.rs
29
src/lib.rs
@ -22,6 +22,11 @@ pub trait ClientConfigExt {
|
|||||||
fn connect_async<S>(&self, domain: &str, stream: S)
|
fn connect_async<S>(&self, domain: &str, stream: S)
|
||||||
-> ConnectAsync<S>
|
-> ConnectAsync<S>
|
||||||
where S: AsyncRead + AsyncWrite;
|
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.
|
/// 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))
|
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]
|
#[inline]
|
||||||
|
Loading…
Reference in New Issue
Block a user