@@ -21,7 +21,10 @@ impl TlsStream for SslStream<Stream> {
21
21
/// A `TlsHandshake` implementation that uses OpenSSL.
22
22
///
23
23
/// Requires the `with-openssl` feature.
24
- pub struct OpenSsl ( SslConnector ) ;
24
+ pub struct OpenSsl {
25
+ connector : SslConnector ,
26
+ disable_verification : bool ,
27
+ }
25
28
26
29
impl fmt:: Debug for OpenSsl {
27
30
fn fmt ( & self , fmt : & mut fmt:: Formatter ) -> fmt:: Result {
@@ -33,23 +36,36 @@ impl OpenSsl {
33
36
/// Creates a `OpenSsl` with `SslConnector`'s default configuration.
34
37
pub fn new ( ) -> Result < OpenSsl , ErrorStack > {
35
38
let connector = try!( SslConnectorBuilder :: new ( SslMethod :: tls ( ) ) ) . build ( ) ;
36
- Ok ( OpenSsl ( connector) )
39
+ Ok ( OpenSsl :: from ( connector) )
37
40
}
38
41
39
42
/// Returns a reference to the inner `SslConnector`.
40
43
pub fn connector ( & self ) -> & SslConnector {
41
- & self . 0
44
+ & self . connector
42
45
}
43
46
44
47
/// Returns a mutable reference to the inner `SslConnector`.
45
48
pub fn connector_mut ( & mut self ) -> & mut SslConnector {
46
- & mut self . 0
49
+ & mut self . connector
50
+ }
51
+
52
+ /// If set, the
53
+ /// `SslConnector::danger_connect_without_providing_domain_for_certificate_verification_and_server_name_indication`
54
+ /// method will be used to connect.
55
+ ///
56
+ /// If certificate verification has been disabled in the `SslConnector`, verification must be
57
+ /// additionally disabled here for that setting to take effect.
58
+ pub fn danger_disable_hostname_verification ( & mut self , disable_verification : bool ) {
59
+ self . disable_verification = disable_verification;
47
60
}
48
61
}
49
62
50
63
impl From < SslConnector > for OpenSsl {
51
64
fn from ( connector : SslConnector ) -> OpenSsl {
52
- OpenSsl ( connector)
65
+ OpenSsl {
66
+ connector : connector,
67
+ disable_verification : false ,
68
+ }
53
69
}
54
70
}
55
71
@@ -58,7 +74,11 @@ impl TlsHandshake for OpenSsl {
58
74
domain : & str ,
59
75
stream : Stream )
60
76
-> Result < Box < TlsStream > , Box < Error + Send + Sync > > {
61
- let stream = try!( self . 0 . connect ( domain, stream) ) ;
77
+ let stream = if self . disable_verification {
78
+ try!( self . connector . danger_connect_without_providing_domain_for_certificate_verification_and_server_name_indication ( stream) )
79
+ } else {
80
+ try!( self . connector . connect ( domain, stream) )
81
+ } ;
62
82
Ok ( Box :: new ( stream) )
63
83
}
64
84
}
0 commit comments