From bcb7b3f5dc58de1fa88a65f5b6ea0bda089c2aee Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Sun, 6 Nov 2016 10:46:38 -0800 Subject: Add accessors for cert and private key Closes #340 --- openssl/src/ssl/mod.rs | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) (limited to 'openssl/src') diff --git a/openssl/src/ssl/mod.rs b/openssl/src/ssl/mod.rs index 9a477993..16bc386b 100644 --- a/openssl/src/ssl/mod.rs +++ b/openssl/src/ssl/mod.rs @@ -762,6 +762,31 @@ impl SslContext { } } +impl SslContextRef { + /// Returns the certificate associated with this `SslContext`, if present. + pub fn certificate(&self) -> Option<&X509Ref> { + unsafe { + let ptr = ffi::SSL_CTX_get0_certificate(self.as_ptr()); + if ptr.is_null() { + None + } else { + Some(X509Ref::from_ptr(ptr)) + } + } + } + + /// Returns the private key associated with this `SslContext`, if present. + pub fn private_key(&self) -> Option<&PKeyRef> { + unsafe { + let ptr = ffi::SSL_CTX_get0_privatekey(self.as_ptr()); + if ptr.is_null() { + None + } else { + Some(PKeyRef::from_ptr(ptr)) + } + } + } +} pub struct CipherBits { /// The number of secret bits used for the cipher. @@ -955,6 +980,30 @@ impl SslRef { } } + /// Returns the certificate associated with this `Ssl`, if present. + pub fn certificate(&self) -> Option<&X509Ref> { + unsafe { + let ptr = ffi::SSL_get_certificate(self.as_ptr()); + if ptr.is_null() { + None + } else { + Some(X509Ref::from_ptr(ptr)) + } + } + } + + /// Returns the private key associated with this `Ssl`, if present. + pub fn private_key(&self) -> Option<&PKeyRef> { + unsafe { + let ptr = ffi::SSL_get_privatekey(self.as_ptr()); + if ptr.is_null() { + None + } else { + Some(PKeyRef::from_ptr(ptr)) + } + } + } + /// Returns the name of the protocol used for the connection, e.g. "TLSv1.2", "SSLv3", etc. pub fn version(&self) -> &'static str { let version = unsafe { -- cgit v1.2.3