aboutsummaryrefslogtreecommitdiff
path: root/openssl/src/x509/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'openssl/src/x509/mod.rs')
-rw-r--r--openssl/src/x509/mod.rs79
1 files changed, 67 insertions, 12 deletions
diff --git a/openssl/src/x509/mod.rs b/openssl/src/x509/mod.rs
index a0b76fef..de7aece7 100644
--- a/openssl/src/x509/mod.rs
+++ b/openssl/src/x509/mod.rs
@@ -13,7 +13,7 @@ use std::slice;
use std::str;
use {cvt, cvt_p};
-use asn1::{Asn1StringRef, Asn1Time, Asn1TimeRef};
+use asn1::{Asn1StringRef, Asn1Time, Asn1TimeRef, Asn1BitStringRef, Asn1ObjectRef};
use bio::MemBioSlice;
use hash::MessageDigest;
use pkey::{PKey, PKeyRef};
@@ -410,8 +410,8 @@ impl X509Ref {
}
}
- /// Returns certificate Not After validity period.
- pub fn not_after<'a>(&'a self) -> &'a Asn1TimeRef {
+ /// Returns the certificate's Not After validity period.
+ pub fn not_after(&self) -> &Asn1TimeRef {
unsafe {
let date = compat::X509_get_notAfter(self.as_ptr());
assert!(!date.is_null());
@@ -419,8 +419,8 @@ impl X509Ref {
}
}
- /// Returns certificate Not Before validity period.
- pub fn not_before<'a>(&'a self) -> &'a Asn1TimeRef {
+ /// Returns the certificate's Not Before validity period.
+ pub fn not_before(&self) -> &Asn1TimeRef {
unsafe {
let date = compat::X509_get_notBefore(self.as_ptr());
assert!(!date.is_null());
@@ -428,6 +428,26 @@ impl X509Ref {
}
}
+ /// Returns the certificate's signature
+ pub fn signature(&self) -> &Asn1BitStringRef {
+ unsafe {
+ let mut signature = ptr::null();
+ compat::X509_get0_signature(&mut signature, ptr::null_mut(), self.as_ptr());
+ assert!(!signature.is_null());
+ Asn1BitStringRef::from_ptr(signature as *mut _)
+ }
+ }
+
+ /// Returns the certificate's signature algorithm.
+ pub fn signature_algorithm(&self) -> &X509AlgorithmRef {
+ unsafe {
+ let mut algor = ptr::null();
+ compat::X509_get0_signature(ptr::null_mut(), &mut algor, self.as_ptr());
+ assert!(!algor.is_null());
+ X509AlgorithmRef::from_ptr(algor as *mut _)
+ }
+ }
+
/// Returns the list of OCSP responder URLs specified in the certificate's Authority Information
/// Access field.
pub fn ocsp_responders(&self) -> Result<Stack<OpensslString>, ErrorStack> {
@@ -800,12 +820,23 @@ impl Stackable for GeneralName {
type StackType = ffi::stack_st_GENERAL_NAME;
}
-#[test]
-fn test_negative_serial() {
- // I guess that's enough to get a random negative number
- for _ in 0..1000 {
- assert!(X509Generator::random_serial().unwrap() > 0,
- "All serials should be positive");
+foreign_type! {
+ type CType = ffi::X509_ALGOR;
+ fn drop = ffi::X509_ALGOR_free;
+
+ pub struct X509Algorithm;
+ pub struct X509AlgorithmRef;
+}
+
+impl X509AlgorithmRef {
+ /// Returns the ASN.1 OID of this algorithm.
+ pub fn object(&self) -> &Asn1ObjectRef {
+ unsafe {
+ let mut oid = ptr::null();
+ compat::X509_ALGOR_get0(&mut oid, ptr::null_mut(), ptr::null_mut(), self.as_ptr());
+ assert!(!oid.is_null());
+ Asn1ObjectRef::from_ptr(oid as *mut _)
+ }
}
}
@@ -815,12 +846,14 @@ mod compat {
pub use ffi::X509_getm_notBefore as X509_get_notBefore;
pub use ffi::X509_up_ref;
pub use ffi::X509_get0_extensions;
+ pub use ffi::X509_get0_signature;
+ pub use ffi::X509_ALGOR_get0;
}
#[cfg(ossl10x)]
#[allow(bad_style)]
mod compat {
- use libc::c_int;
+ use libc::{c_int, c_void};
use ffi;
pub unsafe fn X509_get_notAfter(x: *mut ffi::X509) -> *mut ffi::ASN1_TIME {
@@ -848,4 +881,26 @@ mod compat {
(*info).extensions
}
}
+
+ pub unsafe fn X509_get0_signature(psig: *mut *const ffi::ASN1_BIT_STRING,
+ palg: *mut *const ffi::X509_ALGOR,
+ x: *const ffi::X509) {
+ if !psig.is_null() {
+ *psig = (*x).signature;
+ }
+ if !palg.is_null() {
+ *palg = (*x).sig_alg;
+ }
+ }
+
+ pub unsafe fn X509_ALGOR_get0(paobj: *mut *const ffi::ASN1_OBJECT,
+ pptype: *mut c_int,
+ pval: *mut *mut c_void,
+ alg: *const ffi::X509_ALGOR) {
+ if !paobj.is_null() {
+ *paobj = (*alg).algorithm;
+ }
+ assert!(pptype.is_null());
+ assert!(pval.is_null());
+ }
}