aboutsummaryrefslogtreecommitdiff
path: root/openssl/src/ssl/mod.rs
diff options
context:
space:
mode:
authorSteven Fackler <[email protected]>2018-02-16 22:37:14 -0800
committerGitHub <[email protected]>2018-02-16 22:37:14 -0800
commitb1e7bf4d54365bd53a19992f4089153b0d3b76a8 (patch)
treefcc78f8952afb73d53450ae62ae3c5142428785b /openssl/src/ssl/mod.rs
parentMerge pull request #842 from nyradr/Documentation_fix_openssl_symm (diff)
parentFix libressl (diff)
downloadrust-openssl-b1e7bf4d54365bd53a19992f4089153b0d3b76a8.tar.xz
rust-openssl-b1e7bf4d54365bd53a19992f4089153b0d3b76a8.zip
Merge pull request #843 from sfackler/session-callback-2
Session callback 2
Diffstat (limited to 'openssl/src/ssl/mod.rs')
-rw-r--r--openssl/src/ssl/mod.rs55
1 files changed, 52 insertions, 3 deletions
diff --git a/openssl/src/ssl/mod.rs b/openssl/src/ssl/mod.rs
index a589d6a3..98d982bb 100644
--- a/openssl/src/ssl/mod.rs
+++ b/openssl/src/ssl/mod.rs
@@ -1177,12 +1177,9 @@ impl SslContextBuilder {
///
/// This corresponds to [`SSL_CTX_sess_set_new_cb`].
///
- /// Requires OpenSSL 1.1.0 or 1.1.1 and the corresponding Cargo feature.
- ///
/// [`SslRef::session`]: struct.SslRef.html#method.session
/// [`set_session_cache_mode`]: #method.set_session_cache_mode
/// [`SSL_CTX_sess_set_new_cb`]: https://www.openssl.org/docs/manmaster/man3/SSL_CTX_sess_set_new_cb.html
- #[cfg(any(all(feature = "v110", ossl110), all(feature = "v111", ossl111)))]
pub fn set_new_session_callback<F>(&mut self, callback: F)
where
F: Fn(&mut SslRef, SslSession) + 'static + Sync + Send,
@@ -1198,6 +1195,58 @@ impl SslContextBuilder {
}
}
+ /// Sets the callback which is called when sessions are removed from the context.
+ ///
+ /// Sessions can be removed because they have timed out or because they are considered faulty.
+ ///
+ /// This corresponds to [`SSL_CTX_sess_set_remove_cb`].
+ ///
+ /// [`SSL_CTX_sess_set_remove_cb`]: https://www.openssl.org/docs/manmaster/man3/SSL_CTX_sess_set_new_cb.html
+ pub fn set_remove_session_callback<F>(&mut self, callback: F)
+ where
+ F: Fn(&SslContextRef, &SslSessionRef) + '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_sess_set_remove_cb(
+ self.as_ptr(),
+ Some(callbacks::raw_remove_session::<F>),
+ );
+ }
+ }
+
+ /// Sets the callback which is called when a client proposed to resume a session but it was not
+ /// found in the internal cache.
+ ///
+ /// The callback is passed a reference to the session ID provided by the client. It should
+ /// return the session corresponding to that ID if available. This is only used for servers, not
+ /// clients.
+ ///
+ /// This corresponds to [`SSL_CTX_sess_set_get_cb`].
+ ///
+ /// # Safety
+ ///
+ /// The returned `SslSession` must not be associated with a different `SslContext`.
+ ///
+ /// [`SSL_CTX_sess_set_get_cb`]: https://www.openssl.org/docs/manmaster/man3/SSL_CTX_sess_set_new_cb.html
+ pub unsafe fn set_get_session_callback<F>(&mut self, callback: F)
+ where
+ F: Fn(&mut SslRef, &[u8]) -> Option<SslSession> + 'static + Sync + Send,
+ {
+ 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_sess_set_get_cb(self.as_ptr(), Some(callbacks::raw_get_session::<F>));
+ }
+
/// Sets the session caching mode use for connections made with the context.
///
/// Returns the previous session caching mode.