Skip to content

Commit 99cab46

Browse files
committed
Allow verification to be disabled in OpenSsl
1 parent b673d8a commit 99cab46

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

postgres/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ hex = "0.2"
4343
log = "0.3"
4444
postgres-protocol = "0.2"
4545

46-
openssl = { version = "0.9", optional = true }
46+
openssl = { version = "0.9.2", optional = true }
4747
native-tls = { version = "0.1", optional = true }
4848
rustc-serialize = { version = "0.3", optional = true }
4949
schannel = { version = "0.1", optional = true }

postgres/src/tls/openssl.rs

+26-6
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ impl TlsStream for SslStream<Stream> {
2121
/// A `TlsHandshake` implementation that uses OpenSSL.
2222
///
2323
/// Requires the `with-openssl` feature.
24-
pub struct OpenSsl(SslConnector);
24+
pub struct OpenSsl {
25+
connector: SslConnector,
26+
disable_verification: bool,
27+
}
2528

2629
impl fmt::Debug for OpenSsl {
2730
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
@@ -33,23 +36,36 @@ impl OpenSsl {
3336
/// Creates a `OpenSsl` with `SslConnector`'s default configuration.
3437
pub fn new() -> Result<OpenSsl, ErrorStack> {
3538
let connector = try!(SslConnectorBuilder::new(SslMethod::tls())).build();
36-
Ok(OpenSsl(connector))
39+
Ok(OpenSsl::from(connector))
3740
}
3841

3942
/// Returns a reference to the inner `SslConnector`.
4043
pub fn connector(&self) -> &SslConnector {
41-
&self.0
44+
&self.connector
4245
}
4346

4447
/// Returns a mutable reference to the inner `SslConnector`.
4548
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;
4760
}
4861
}
4962

5063
impl From<SslConnector> for OpenSsl {
5164
fn from(connector: SslConnector) -> OpenSsl {
52-
OpenSsl(connector)
65+
OpenSsl {
66+
connector: connector,
67+
disable_verification: false,
68+
}
5369
}
5470
}
5571

@@ -58,7 +74,11 @@ impl TlsHandshake for OpenSsl {
5874
domain: &str,
5975
stream: Stream)
6076
-> 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+
};
6282
Ok(Box::new(stream))
6383
}
6484
}

0 commit comments

Comments
 (0)