diff --git a/openssl-sys/src/libressl/mod.rs b/openssl-sys/src/libressl/mod.rs index 7eb119c23dd3edf247199348646b53067bfc6919..ffa37bb09cc0c555dbe65f56c107e374eb6461b6 100644 --- a/openssl-sys/src/libressl/mod.rs +++ b/openssl-sys/src/libressl/mod.rs @@ -542,6 +542,7 @@ extern "C" { -> *mut ::EC_KEY, ); pub fn X509_get_subject_name(x: *mut ::X509) -> *mut ::X509_NAME; + pub fn X509_get_issuer_name(x: *mut ::X509) -> *mut ::X509_NAME; pub fn X509_set_notAfter(x: *mut ::X509, tm: *const ::ASN1_TIME) -> c_int; pub fn X509_set_notBefore(x: *mut ::X509, tm: *const ::ASN1_TIME) -> c_int; pub fn X509_get_ext_d2i( diff --git a/openssl-sys/src/ossl10x.rs b/openssl-sys/src/ossl10x.rs index 8bf5e35b0908465a143067615b3820cec73cc143..8a9a038939131c80e21ee4e9f490e9e04324baff 100644 --- a/openssl-sys/src/ossl10x.rs +++ b/openssl-sys/src/ossl10x.rs @@ -830,6 +830,7 @@ extern "C" { -> *mut ::EC_KEY, ); pub fn X509_get_subject_name(x: *mut ::X509) -> *mut ::X509_NAME; + pub fn X509_get_issuer_name(x: *mut ::X509) -> *mut ::X509_NAME; pub fn X509_set_notAfter(x: *mut ::X509, tm: *const ::ASN1_TIME) -> c_int; pub fn X509_set_notBefore(x: *mut ::X509, tm: *const ::ASN1_TIME) -> c_int; pub fn X509_get_ext_d2i( diff --git a/openssl-sys/src/ossl110.rs b/openssl-sys/src/ossl110.rs index 8b862443239f94ad6b3f0b3aafb898b3bf33605e..f8d944f02c680c742f903c8a2bc18e80e29fec43 100644 --- a/openssl-sys/src/ossl110.rs +++ b/openssl-sys/src/ossl110.rs @@ -107,6 +107,7 @@ extern "C" { pub fn DTLS_method() -> *const ::SSL_METHOD; pub fn SSL_CIPHER_get_version(cipher: *const ::SSL_CIPHER) -> *const c_char; pub fn X509_get_subject_name(x: *const ::X509) -> *mut ::X509_NAME; + pub fn X509_get_issuer_name(x: *const ::X509) -> *mut ::X509_NAME; pub fn X509_set1_notAfter(x: *mut ::X509, tm: *const ::ASN1_TIME) -> c_int; pub fn X509_set1_notBefore(x: *mut ::X509, tm: *const ::ASN1_TIME) -> c_int; pub fn X509_get_ext_d2i( diff --git a/openssl/src/x509/mod.rs b/openssl/src/x509/mod.rs index d1297a6978eb9e9a036962af77775fe5f6dbc53d..52becf103888ce7d338101208fcab12c1970a381 100644 --- a/openssl/src/x509/mod.rs +++ b/openssl/src/x509/mod.rs @@ -263,14 +263,37 @@ foreign_type_and_impl_send_sync! { } impl X509Ref { + /// Returns this certificate's subject name. + /// + /// This corresponds to [`X509_get_subject_name`]. + /// + /// [`X509_get_subject_name`]: https://www.openssl.org/docs/man1.1.0/crypto/X509_get_subject_name.html pub fn subject_name(&self) -> &X509NameRef { unsafe { let name = ffi::X509_get_subject_name(self.as_ptr()); + assert!(!name.is_null()); X509NameRef::from_ptr(name) } } - /// Returns this certificate's SAN entries, if they exist. + /// Returns this certificate's issuer name. + /// + /// This corresponds to [`X509_get_issuer_name`]. + /// + /// [`X509_get_issuer_name`]: https://www.openssl.org/docs/man1.1.0/crypto/X509_get_subject_name.html + pub fn issuer_name(&self) -> &X509NameRef { + unsafe { + let name = ffi::X509_get_issuer_name(self.as_ptr()); + assert!(!name.is_null()); + X509NameRef::from_ptr(name) + } + } + + /// Returns this certificate's subject alternative name entries, if they exist. + /// + /// This corresponds to [`X509_get_ext_d2i`] called with `NID_subject_alt_name`. + /// + /// [`X509_get_ext_d2i`]: https://www.openssl.org/docs/man1.1.0/crypto/X509_get_ext_d2i.html pub fn subject_alt_names(&self) -> Option> { unsafe { let stack = ffi::X509_get_ext_d2i( @@ -280,10 +303,31 @@ impl X509Ref { ptr::null_mut(), ); if stack.is_null() { - return None; + None + } else { + Some(Stack::from_ptr(stack as *mut _)) } + } + } - Some(Stack::from_ptr(stack as *mut _)) + /// Returns this certificate's issuer alternative name entries, if they exist. + /// + /// This corresponds to [`X509_get_ext_d2i`] called with `NID_issuer_alt_name`. + /// + /// [`X509_get_ext_d2i`]: https://www.openssl.org/docs/man1.1.0/crypto/X509_get_ext_d2i.html + pub fn issuer_alt_names(&self) -> Option> { + unsafe { + let stack = ffi::X509_get_ext_d2i( + self.as_ptr(), + ffi::NID_issuer_alt_name, + ptr::null_mut(), + ptr::null_mut(), + ); + if stack.is_null() { + None + } else { + Some(Stack::from_ptr(stack as *mut _)) + } } }