Merge pull request #1248 from coolreader18/ssl-functions

Add functions for SSL{_CTX}_get_verify_mode and SSL_is_init_finished
This commit is contained in:
Steven Fackler 2020-03-26 20:52:42 -04:00 committed by GitHub
commit 2cbc436b8b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 46 additions and 0 deletions

View File

@ -672,6 +672,21 @@ extern "C" {
pub fn SSL_get_finished(s: *const SSL, buf: *mut c_void, count: size_t) -> size_t;
pub fn SSL_get_peer_finished(s: *const SSL, buf: *mut c_void, count: size_t) -> size_t;
pub fn SSL_CTX_get_verify_mode(ctx: *const SSL_CTX) -> c_int;
pub fn SSL_get_verify_mode(s: *const SSL) -> c_int;
}
cfg_if! {
if #[cfg(ossl111)] {
extern "C" {
pub fn SSL_is_init_finished(s: *const SSL) -> c_int;
}
} else if #[cfg(ossl110)] {
extern "C" {
pub fn SSL_is_init_finished(s: *mut SSL) -> c_int;
}
}
}
pub const SSL_AD_ILLEGAL_PARAMETER: c_int = SSL3_AD_ILLEGAL_PARAMETER;

View File

@ -1960,6 +1960,17 @@ impl SslContextRef {
pub fn session_cache_size(&self) -> i64 {
unsafe { ffi::SSL_CTX_sess_get_cache_size(self.as_ptr()).into() }
}
/// Returns the verify mode that was set on this context from [`SslContextBuilder::set_verify`].
///
/// This corresponds to [`SSL_CTX_get_verify_mode`].
///
/// [`SslContextBuilder::set_verify`]: struct.SslContextBuilder.html#method.set_verify
/// [`SSL_CTX_get_verify_mode`]: https://www.openssl.org/docs/man1.1.1/man3/SSL_CTX_get_verify_mode.html
pub fn verify_mode(&self) -> SslVerifyMode {
let mode = unsafe { ffi::SSL_CTX_get_verify_mode(self.as_ptr()) };
SslVerifyMode::from_bits(mode).expect("SSL_CTX_get_verify_mode returned invalid mode")
}
}
/// Information about the state of a cipher.
@ -2410,6 +2421,16 @@ impl SslRef {
unsafe { ffi::SSL_set_verify(self.as_ptr(), mode.bits as c_int, None) }
}
/// Returns the verify mode that was set using `set_verify`.
///
/// This corresponds to [`SSL_get_verify_mode`].
///
/// [`SSL_get_verify_mode`]: https://www.openssl.org/docs/man1.1.1/man3/SSL_get_verify_mode.html
pub fn verify_mode(&self) -> SslVerifyMode {
let mode = unsafe { ffi::SSL_get_verify_mode(self.as_ptr()) };
SslVerifyMode::from_bits(mode).expect("SSL_get_verify_mode returned invalid mode")
}
/// Like [`SslContextBuilder::set_verify_callback`].
///
/// This corresponds to [`SSL_set_verify`].
@ -3188,6 +3209,16 @@ impl SslRef {
}
}
/// Determines if the initial handshake has been completed.
///
/// This corresponds to [`SSL_is_init_finished`].
///
/// [`SSL_is_init_finished`]: https://www.openssl.org/docs/man1.1.1/man3/SSL_is_init_finished.html
#[cfg(ossl110)]
pub fn is_init_finished(&self) -> bool {
unsafe { ffi::SSL_is_init_finished(self.as_ptr()) != 0 }
}
/// Determines if the client's hello message is in the SSLv2 format.
///
/// This can only be used inside of the client hello callback. Otherwise, `false` is returned.