diff options
author | Joern Heissler <joern@fishpond.co.nz> | 2016-01-13 22:51:37 +0100 |
---|---|---|
committer | Joern Heissler <joern@fishpond.co.nz> | 2016-01-13 22:51:37 +0100 |
commit | 1bd77e2f4ee2fcdd9233ea36ed74edeee02817c5 (patch) | |
tree | 9af6b663011b1d0cee65d5581818b2f0961159a0 /src | |
parent | 4b88c2d091f844c03f083ab2d6964f3980982419 (diff) | |
download | cryptography-1bd77e2f4ee2fcdd9233ea36ed74edeee02817c5.tar.gz cryptography-1bd77e2f4ee2fcdd9233ea36ed74edeee02817c5.tar.bz2 cryptography-1bd77e2f4ee2fcdd9233ea36ed74edeee02817c5.zip |
Add verify method on CertificateSigningRequest
Diffstat (limited to 'src')
-rw-r--r-- | src/cryptography/hazmat/backends/openssl/x509.py | 12 | ||||
-rw-r--r-- | src/cryptography/x509/base.py | 6 |
2 files changed, 17 insertions, 1 deletions
diff --git a/src/cryptography/hazmat/backends/openssl/x509.py b/src/cryptography/hazmat/backends/openssl/x509.py index a6f7d69e..18274aa1 100644 --- a/src/cryptography/hazmat/backends/openssl/x509.py +++ b/src/cryptography/hazmat/backends/openssl/x509.py @@ -7,7 +7,7 @@ from __future__ import absolute_import, division, print_function import operator from cryptography import utils, x509 -from cryptography.exceptions import UnsupportedAlgorithm +from cryptography.exceptions import UnsupportedAlgorithm, InvalidSignature from cryptography.hazmat.backends.openssl.decode_asn1 import ( _CERTIFICATE_EXTENSION_PARSER, _CRL_EXTENSION_PARSER, _CSR_EXTENSION_PARSER, _REVOKED_CERTIFICATE_EXTENSION_PARSER, @@ -362,3 +362,13 @@ class _CertificateSigningRequest(object): @property def signature(self): return _asn1_string_to_bytes(self._backend, self._x509_req.signature) + + def verify(self): + pkey = self._backend._lib.X509_REQ_get_pubkey(self._x509_req) + self._backend.openssl_assert(pkey != self._backend._ffi.NULL) + pkey = self._backend._ffi.gc(pkey, self._backend._lib.EVP_PKEY_free) + res = self._backend._lib.X509_REQ_verify(self._x509_req, pkey) + + if res != 1: + self._backend._consume_errors() + raise InvalidSignature diff --git a/src/cryptography/x509/base.py b/src/cryptography/x509/base.py index 55e965f7..d24070d5 100644 --- a/src/cryptography/x509/base.py +++ b/src/cryptography/x509/base.py @@ -288,6 +288,12 @@ class CertificateSigningRequest(object): 2986. """ + @abc.abstractmethod + def verify(self): + """ + Verifies signature of signing request. + """ + @six.add_metaclass(abc.ABCMeta) class RevokedCertificate(object): |