aboutsummaryrefslogtreecommitdiff
path: root/openssl/src
diff options
context:
space:
mode:
authorRenĂ© Richter <[email protected]>2018-04-21 09:44:49 +0200
committerRenĂ© Richter <[email protected]>2018-04-21 23:14:48 +0200
commit5bb89d7552fd5fd14749769da8e848ee67ef7582 (patch)
tree84effaebac73582a6634d49d6c6294d962d10413 /openssl/src
parentMerge pull request #899 from rohit-lshift/master (diff)
downloadrust-openssl-5bb89d7552fd5fd14749769da8e848ee67ef7582.tar.xz
rust-openssl-5bb89d7552fd5fd14749769da8e848ee67ef7582.zip
Add functions to X509Req to obtain public key and extensions
This allows for basic CSR signing.
Diffstat (limited to 'openssl/src')
-rw-r--r--openssl/src/x509/mod.rs22
-rw-r--r--openssl/src/x509/tests.rs4
2 files changed, 26 insertions, 0 deletions
diff --git a/openssl/src/x509/mod.rs b/openssl/src/x509/mod.rs
index 011a2d96..c1ae3b16 100644
--- a/openssl/src/x509/mod.rs
+++ b/openssl/src/x509/mod.rs
@@ -1069,6 +1069,28 @@ impl X509ReqRef {
X509NameRef::from_ptr(name)
}
}
+
+ /// Returns the public key of the certificate request.
+ ///
+ /// This corresponds to [`X509_REQ_get_pubkey"]
+ ///
+ /// [`X509_REQ_get_pubkey`]: https://www.openssl.org/docs/man1.1.0/crypto/X509_REQ_get_pubkey.html
+ pub fn public_key(&self) -> Result<PKey<Public>, ErrorStack> {
+ unsafe {
+ let key = cvt_p(ffi::X509_REQ_get_pubkey(self.as_ptr()))?;
+ Ok(PKey::from_ptr(key))
+ }
+ }
+
+ /// Returns the extensions of the certificate request.
+ ///
+ /// This corresponds to [`X509_REQ_get_extensions"]
+ pub fn extensions(&self) -> Result<Stack<X509Extension>, ErrorStack> {
+ unsafe {
+ let extensions = cvt_p(ffi::X509_REQ_get_extensions(self.as_ptr()))?;
+ Ok(Stack::from_ptr(extensions))
+ }
+ }
}
/// The result of peer certificate verification.
diff --git a/openssl/src/x509/tests.rs b/openssl/src/x509/tests.rs
index fa8056ad..7ef4d160 100644
--- a/openssl/src/x509/tests.rs
+++ b/openssl/src/x509/tests.rs
@@ -234,6 +234,10 @@ fn x509_req_builder() {
builder.add_extensions(&extensions).unwrap();
builder.sign(&pkey, MessageDigest::sha256()).unwrap();
+
+ let req = builder.build();
+ assert!(req.public_key().unwrap().public_eq(&pkey));
+ assert_eq!(req.extensions().unwrap().len(), extensions.len());
}
#[test]