Add session info accessors

This commit is contained in:
Steven Fackler 2019-02-28 22:08:48 -08:00
parent 913267e68a
commit a16482f972
2 changed files with 40 additions and 0 deletions

View File

@ -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)]

View File

@ -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.
///