diff options
| author | Benjamin Saunders <[email protected]> | 2018-03-26 18:49:03 -0700 |
|---|---|---|
| committer | Benjamin Saunders <[email protected]> | 2018-03-28 18:14:44 -0700 |
| commit | bbb1cb61f6fe7ec697f0667807dbc175ac623d07 (patch) | |
| tree | 5575920851613cce8ff8962fdccde1ad98f99860 /openssl/src/ssl/mod.rs | |
| parent | Merge pull request #884 from sfackler/libressl-27 (diff) | |
| download | rust-openssl-bbb1cb61f6fe7ec697f0667807dbc175ac623d07.tar.xz rust-openssl-bbb1cb61f6fe7ec697f0667807dbc175ac623d07.zip | |
Update to OpenSSL 1.1.1-pre3
Diffstat (limited to 'openssl/src/ssl/mod.rs')
| -rw-r--r-- | openssl/src/ssl/mod.rs | 54 |
1 files changed, 49 insertions, 5 deletions
diff --git a/openssl/src/ssl/mod.rs b/openssl/src/ssl/mod.rs index f3c4ed3a..024e4ca5 100644 --- a/openssl/src/ssl/mod.rs +++ b/openssl/src/ssl/mod.rs @@ -1437,8 +1437,9 @@ impl SslContextBuilder { /// The callback will be called with the SSL context and a slice into which the cookie /// should be written. The callback should return the number of bytes written. /// - /// This corresponds to `SSL_CTX_set_cookie_generate_cb`. - pub fn set_cookie_generate_cb<F>(&mut self, callback: F) + /// This corresponds to `SSL_CTX_set_stateless_cookie_generate_cb`. + #[cfg(ossl111)] + pub fn set_stateless_cookie_generate_cb<F>(&mut self, callback: F) where F: Fn(&mut SslRef, &mut [u8]) -> Result<usize, ErrorStack> + 'static + Sync + Send, { @@ -1447,9 +1448,9 @@ impl SslContextBuilder { ffi::SSL_CTX_set_ex_data( self.as_ptr(), get_callback_idx::<F>(), - mem::transmute(callback), + Box::into_raw(callback) as *mut _, ); - ffi::SSL_CTX_set_cookie_generate_cb(self.as_ptr(), Some(raw_cookie_generate::<F>)) + ffi::SSL_CTX_set_stateless_cookie_generate_cb(self.as_ptr(), Some(raw_stateless_cookie_generate::<F>)) } } @@ -1461,6 +1462,49 @@ impl SslContextBuilder { /// Note that the OpenSSL implementation independently verifies the integrity of /// application cookies using an HMAC before invoking the supplied callback. /// + /// This corresponds to `SSL_CTX_set_stateless_cookie_verify_cb`. + #[cfg(ossl111)] + pub fn set_stateless_cookie_verify_cb<F>(&mut self, callback: F) + where + F: Fn(&mut SslRef, &[u8]) -> bool + 'static + Sync + Send, + { + unsafe { + let callback = Box::new(callback); + ffi::SSL_CTX_set_ex_data( + self.as_ptr(), + get_callback_idx::<F>(), + Box::into_raw(callback) as *mut _, + ); + ffi::SSL_CTX_set_stateless_cookie_verify_cb(self.as_ptr(), Some(raw_stateless_cookie_verify::<F>)) + } + } + + /// Sets the callback for generating a DTLSv1 cookie + /// + /// The callback will be called with the SSL context and a slice into which the cookie + /// should be written. The callback should return the number of bytes written. + /// + /// This corresponds to `SSL_CTX_set_cookie_generate_cb`. + pub fn set_cookie_generate_cb<F>(&mut self, callback: F) + where + F: Fn(&mut SslRef, &mut [u8]) -> Result<usize, ErrorStack> + 'static + Sync + Send, + { + unsafe { + let callback = Box::new(callback); + ffi::SSL_CTX_set_ex_data( + self.as_ptr(), + get_callback_idx::<F>(), + Box::into_raw(callback) as *mut _, + ); + ffi::SSL_CTX_set_cookie_generate_cb(self.as_ptr(), Some(raw_cookie_generate::<F>)) + } + } + + /// Sets the callback for verifying a DTLSv1 cookie + /// + /// The callback will be called with the SSL context and the cookie supplied by the + /// client. It should return true if and only if the cookie is valid. + /// /// This corresponds to `SSL_CTX_set_cookie_verify_cb`. pub fn set_cookie_verify_cb<F>(&mut self, callback: F) where @@ -1471,7 +1515,7 @@ impl SslContextBuilder { ffi::SSL_CTX_set_ex_data( self.as_ptr(), get_callback_idx::<F>(), - mem::transmute(callback), + Box::into_raw(callback) as *mut _, ); ffi::SSL_CTX_set_cookie_verify_cb(self.as_ptr(), Some(raw_cookie_verify::<F>)) } |