aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteven Fackler <[email protected]>2017-12-29 10:50:10 -0800
committerSteven Fackler <[email protected]>2017-12-29 10:50:49 -0800
commit89dd50b3cec8d9c9dea33b3b461c9ecaaeaf3b9d (patch)
tree799daffccd7111cabdb24cbdb424b5547b2abcb9
parentMerge pull request #807 from sfackler/no-compression (diff)
downloadrust-openssl-89dd50b3cec8d9c9dea33b3b461c9ecaaeaf3b9d.tar.xz
rust-openssl-89dd50b3cec8d9c9dea33b3b461c9ecaaeaf3b9d.zip
Add issuer name access.
Closes #808
-rw-r--r--openssl-sys/src/libressl/mod.rs1
-rw-r--r--openssl-sys/src/ossl10x.rs1
-rw-r--r--openssl-sys/src/ossl110.rs1
-rw-r--r--openssl/src/x509/mod.rs50
4 files changed, 50 insertions, 3 deletions
diff --git a/openssl-sys/src/libressl/mod.rs b/openssl-sys/src/libressl/mod.rs
index 7eb119c2..ffa37bb0 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 8bf5e35b..8a9a0389 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 8b862443..f8d944f0 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 d1297a69..52becf10 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<Stack<GeneralName>> {
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<Stack<GeneralName>> {
+ 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 _))
+ }
}
}