aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/cryptography/hazmat/backends/openssl/x509.py16
-rw-r--r--src/cryptography/x509.py26
2 files changed, 19 insertions, 23 deletions
diff --git a/src/cryptography/hazmat/backends/openssl/x509.py b/src/cryptography/hazmat/backends/openssl/x509.py
index 989a9dd7..c69e9148 100644
--- a/src/cryptography/hazmat/backends/openssl/x509.py
+++ b/src/cryptography/hazmat/backends/openssl/x509.py
@@ -140,15 +140,6 @@ class _Certificate(object):
@property
def signature_hash_algorithm(self):
- oid = self._signature_algorithm()
- try:
- return x509._SIG_OIDS_TO_HASH[oid.dotted_string]
- except KeyError:
- raise UnsupportedAlgorithm(
- "Signature algorithm {0} not recognized".format(oid)
- )
-
- def _signature_algorithm(self):
buf_len = 50
buf = self._backend._ffi.new("char[]", buf_len)
res = self._backend._lib.OBJ_obj2txt(
@@ -156,4 +147,9 @@ class _Certificate(object):
)
assert res <= 50 and res > 0
oid = self._backend._ffi.buffer(buf, res)[:].decode()
- return x509.ObjectIdentifier(oid)
+ try:
+ return x509._SIG_OIDS_TO_HASH[oid]
+ except KeyError:
+ raise UnsupportedAlgorithm(
+ "Signature algorithm OID:{0} not recognized".format(oid)
+ )
diff --git a/src/cryptography/x509.py b/src/cryptography/x509.py
index c6ce61d1..0273ca86 100644
--- a/src/cryptography/x509.py
+++ b/src/cryptography/x509.py
@@ -172,19 +172,19 @@ OID_DSA_WITH_SHA224 = ObjectIdentifier("2.16.840.1.101.3.4.3.1")
OID_DSA_WITH_SHA256 = ObjectIdentifier("2.16.840.1.101.3.4.3.2")
_SIG_OIDS_TO_HASH = {
- "1.2.840.113549.1.1.4": hashes.MD5(),
- "1.2.840.113549.1.1.5": hashes.SHA1(),
- "1.2.840.113549.1.1.14": hashes.SHA224(),
- "1.2.840.113549.1.1.11": hashes.SHA256(),
- "1.2.840.113549.1.1.12": hashes.SHA384(),
- "1.2.840.113549.1.1.13": hashes.SHA512(),
- "1.2.840.10045.4.3.1": hashes.SHA224(),
- "1.2.840.10045.4.3.2": hashes.SHA256(),
- "1.2.840.10045.4.3.3": hashes.SHA384(),
- "1.2.840.10045.4.3.4": hashes.SHA512(),
- "1.2.840.10040.4.3": hashes.SHA1(),
- "2.16.840.1.101.3.4.3.1": hashes.SHA224(),
- "2.16.840.1.101.3.4.3.2": hashes.SHA256()
+ OID_MD5_WITH_RSA.dotted_string: hashes.MD5(),
+ OID_SHA1_WITH_RSA.dotted_string: hashes.SHA1(),
+ OID_SHA224_WITH_RSA.dotted_string: hashes.SHA224(),
+ OID_SHA256_WITH_RSA.dotted_string: hashes.SHA256(),
+ OID_SHA384_WITH_RSA.dotted_string: hashes.SHA384(),
+ OID_SHA512_WITH_RSA.dotted_string: hashes.SHA512(),
+ OID_ECDSA_WITH_SHA224.dotted_string: hashes.SHA224(),
+ OID_ECDSA_WITH_SHA256.dotted_string: hashes.SHA256(),
+ OID_ECDSA_WITH_SHA384.dotted_string: hashes.SHA384(),
+ OID_ECDSA_WITH_SHA512.dotted_string: hashes.SHA512(),
+ OID_DSA_WITH_SHA1.dotted_string: hashes.SHA1(),
+ OID_DSA_WITH_SHA224.dotted_string: hashes.SHA224(),
+ OID_DSA_WITH_SHA256.dotted_string: hashes.SHA256()
}