Skip to content

Commit

Permalink
Provide into_ssl() for ConnectConfiguration
Browse files Browse the repository at this point in the history
Port from openssl-rs.
  • Loading branch information
eaufavor committed Sep 19, 2023
1 parent 4749c52 commit d905fd3
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions boring/src/ssl/connector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use crate::ssl::{
SslOptions, SslRef, SslStream, SslVerifyMode,
};
use crate::version;
use std::net::IpAddr;

const FFDHE_2048: &str = "
-----BEGIN DH PARAMETERS-----
Expand Down Expand Up @@ -189,14 +190,11 @@ impl ConnectConfiguration {
self.verify_hostname = verify_hostname;
}

/// Initiates a client-side TLS session on a stream.
/// Returns an `Ssl` configured to connect to the provided domain.
///
/// The domain is used for SNI and hostname verification if enabled.
pub fn connect<S>(mut self, domain: &str, stream: S) -> Result<SslStream<S>, HandshakeError<S>>
where
S: Read + Write,
{
if self.sni {
/// The domain is used for SNI (if it is not an IP address) and hostname verification if enabled.
pub fn into_ssl(mut self, domain: &str) -> Result<Ssl, ErrorStack> {
if self.sni && domain.parse::<IpAddr>().is_err() {
self.ssl.set_hostname(domain)?;
}

Expand All @@ -210,7 +208,17 @@ impl ConnectConfiguration {
setup_verify_hostname(&mut self.ssl, domain)?;
}

self.ssl.connect(stream)
Ok(self.ssl)
}

/// Initiates a client-side TLS session on a stream.
///
/// The domain is used for SNI (if it is not an IP address) and hostname verification if enabled.
pub fn connect<S>(self, domain: &str, stream: S) -> Result<SslStream<S>, HandshakeError<S>>
where
S: Read + Write,
{
self.into_ssl(domain)?.connect(stream)
}
}

Expand Down

0 comments on commit d905fd3

Please sign in to comment.