aboutsummaryrefslogtreecommitdiff
path: root/src/ssl/mod.rs
diff options
context:
space:
mode:
authorAndrew Dunham <[email protected]>2014-09-04 18:21:43 -0700
committerAndrew Dunham <[email protected]>2014-09-04 18:21:43 -0700
commitfc79815faf28b347f6f0b8dd6d7c4f6b83fc4e53 (patch)
tree7e53c8274042fb333b374cf2051954e7c3b75ead /src/ssl/mod.rs
parentMerge pull request #35 from Kroisse/master (diff)
downloadrust-openssl-fc79815faf28b347f6f0b8dd6d7c4f6b83fc4e53.tar.xz
rust-openssl-fc79815faf28b347f6f0b8dd6d7c4f6b83fc4e53.zip
Allow setting hostname to support TLS-SNI
Diffstat (limited to 'src/ssl/mod.rs')
-rw-r--r--src/ssl/mod.rs23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/ssl/mod.rs b/src/ssl/mod.rs
index 7c9b2d60..82301086 100644
--- a/src/ssl/mod.rs
+++ b/src/ssl/mod.rs
@@ -362,6 +362,29 @@ impl Ssl {
None => unreachable!()
}
}
+
+ /// Set the host name to be used with SNI (Server Name Indication).
+ pub fn set_hostname(&self, hostname: &str) -> Result<(), SslError> {
+ let ret = hostname.with_c_str(|hostname| {
+ unsafe {
+ // This is defined as a macro:
+ // #define SSL_set_tlsext_host_name(s,name) \
+ // SSL_ctrl(s,SSL_CTRL_SET_TLSEXT_HOSTNAME,TLSEXT_NAMETYPE_host_name,(char *)name)
+
+ ffi::SSL_ctrl(self.ssl, ffi::SSL_CTRL_SET_TLSEXT_HOSTNAME,
+ ffi::TLSEXT_NAMETYPE_host_name,
+ hostname as *const c_void as *mut c_void)
+ }
+ });
+
+ // For this case, 0 indicates failure.
+ if ret == 0 {
+ Err(SslError::get())
+ } else {
+ Ok(())
+ }
+ }
+
}
#[deriving(FromPrimitive)]