diff --git a/openssl-sys/src/ssl.rs b/openssl-sys/src/ssl.rs index ca2fbb44..2a4d44a4 100644 --- a/openssl-sys/src/ssl.rs +++ b/openssl-sys/src/ssl.rs @@ -919,6 +919,11 @@ extern "C" { pub fn SSL_state_string(ssl: *const SSL) -> *const c_char; pub fn SSL_state_string_long(ssl: *const SSL) -> *const c_char; + pub fn SSL_SESSION_get_time(s: *const SSL_SESSION) -> c_long; + pub fn SSL_SESSION_get_timeout(s: *const SSL_SESSION) -> c_long; + #[cfg(ossl110)] + pub fn SSL_SESSION_get_protocol_version(s: *const SSL_SESSION) -> c_int; + #[cfg(ossl111)] pub fn SSL_SESSION_set_max_early_data(ctx: *mut SSL_SESSION, max_early_data: u32) -> c_int; #[cfg(ossl111)] diff --git a/openssl/src/ssl/mod.rs b/openssl/src/ssl/mod.rs index b67c333b..dfdc2cee 100644 --- a/openssl/src/ssl/mod.rs +++ b/openssl/src/ssl/mod.rs @@ -2129,6 +2129,41 @@ impl SslSessionRef { unsafe { ffi::SSL_SESSION_get_max_early_data(self.as_ptr()) } } + /// Returns the time at which the session was established, in seconds since the Unix epoch. + /// + /// This corresponds to [`SSL_SESSION_get_time`]. + /// + /// [`SSL_SESSION_get_time`]: https://www.openssl.org/docs/man1.1.1/man3/SSL_SESSION_get_time.html + pub fn time(&self) -> i64 { + unsafe { ffi::SSL_SESSION_get_time(self.as_ptr()) as i64 } + } + + /// Returns the sessions timeout, in seconds. + /// + /// A session older than this time should not be used for session resumption. + /// + /// This corresponds to [`SSL_SESSION_get_timeout`]. + /// + /// [`SSL_SESSION_get_timeout`]: https://www.openssl.org/docs/man1.1.1/man3/SSL_SESSION_get_time.html + pub fn timeout(&self) -> i64 { + unsafe { ffi::SSL_SESSION_get_timeout(self.as_ptr()) as i64 } + } + + /// Returns the session's TLS protocol version. + /// + /// Requires OpenSSL 1.1.0 or newer. + /// + /// This corresponds to [`SSL_SESSION_get_protocol_version`]. + /// + /// [`SSL_SESSION_get_protocol_version`]: https://www.openssl.org/docs/man1.1.1/man3/SSL_SESSION_get_time.html + #[cfg(ossl110)] + pub fn protocol_version(&self) -> SslVersion { + unsafe { + let version = ffi::SSL_SESSION_get_protocol_version(self.as_ptr()); + SslVersion(version) + } + } + to_der! { /// Serializes the session into a DER-encoded structure. ///