aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/cryptography/hazmat/backends/openssl/ec.py2
-rw-r--r--src/cryptography/hazmat/backends/openssl/rsa.py4
-rw-r--r--src/cryptography/hazmat/backends/openssl/x509.py78
3 files changed, 42 insertions, 42 deletions
diff --git a/src/cryptography/hazmat/backends/openssl/ec.py b/src/cryptography/hazmat/backends/openssl/ec.py
index 393a991f..c2af2be9 100644
--- a/src/cryptography/hazmat/backends/openssl/ec.py
+++ b/src/cryptography/hazmat/backends/openssl/ec.py
@@ -217,7 +217,7 @@ class _EllipticCurvePrivateKey(object):
)
-@utils.register_interface(ec.EllipticCurvePublicKeyWithNumbers)
+@utils.register_interface(ec.EllipticCurvePublicKeyWithSerialization)
class _EllipticCurvePublicKey(object):
def __init__(self, backend, ec_key_cdata):
self._backend = backend
diff --git a/src/cryptography/hazmat/backends/openssl/rsa.py b/src/cryptography/hazmat/backends/openssl/rsa.py
index 30f79912..1dbbb844 100644
--- a/src/cryptography/hazmat/backends/openssl/rsa.py
+++ b/src/cryptography/hazmat/backends/openssl/rsa.py
@@ -18,8 +18,7 @@ from cryptography.hazmat.primitives.asymmetric.padding import (
AsymmetricPadding, MGF1, OAEP, PKCS1v15, PSS
)
from cryptography.hazmat.primitives.asymmetric.rsa import (
- RSAPrivateKeyWithNumbers, RSAPrivateKeyWithSerialization,
- RSAPublicKeyWithSerialization
+ RSAPrivateKeyWithSerialization, RSAPublicKeyWithSerialization
)
@@ -507,7 +506,6 @@ class _RSAVerificationContext(object):
raise InvalidSignature
-@utils.register_interface(RSAPrivateKeyWithNumbers)
@utils.register_interface(RSAPrivateKeyWithSerialization)
class _RSAPrivateKey(object):
def __init__(self, backend, rsa_cdata):
diff --git a/src/cryptography/hazmat/backends/openssl/x509.py b/src/cryptography/hazmat/backends/openssl/x509.py
index b712f1f9..89db016b 100644
--- a/src/cryptography/hazmat/backends/openssl/x509.py
+++ b/src/cryptography/hazmat/backends/openssl/x509.py
@@ -20,6 +20,43 @@ from cryptography.exceptions import UnsupportedAlgorithm
from cryptography.hazmat.primitives import hashes
+def _obj2txt(backend, obj):
+ # Set to 80 on the recommendation of
+ # https://www.openssl.org/docs/crypto/OBJ_nid2ln.html#return_values
+ buf_len = 80
+ buf = backend._ffi.new("char[]", buf_len)
+ res = backend._lib.OBJ_obj2txt(buf, buf_len, obj, 1)
+ assert res > 0
+ return backend._ffi.buffer(buf, res)[:].decode()
+
+
+def _build_x509_name(backend, x509_name):
+ count = backend._lib.X509_NAME_entry_count(x509_name)
+ attributes = []
+ for x in range(count):
+ entry = backend._lib.X509_NAME_get_entry(x509_name, x)
+ obj = backend._lib.X509_NAME_ENTRY_get_object(entry)
+ assert obj != backend._ffi.NULL
+ data = backend._lib.X509_NAME_ENTRY_get_data(entry)
+ assert data != backend._ffi.NULL
+ buf = backend._ffi.new("unsigned char **")
+ res = backend._lib.ASN1_STRING_to_UTF8(buf, data)
+ assert res >= 0
+ assert buf[0] != backend._ffi.NULL
+ buf = backend._ffi.gc(
+ buf, lambda buf: backend._lib.OPENSSL_free(buf[0])
+ )
+ value = backend._ffi.buffer(buf[0], res)[:].decode('utf8')
+ oid = _obj2txt(backend, obj)
+ attributes.append(
+ x509.NameAttribute(
+ x509.ObjectIdentifier(oid), value
+ )
+ )
+
+ return x509.Name(attributes)
+
+
@utils.register_interface(x509.Certificate)
class _Certificate(object):
def __init__(self, backend, x509):
@@ -97,52 +134,17 @@ class _Certificate(object):
def issuer(self):
issuer = self._backend._lib.X509_get_issuer_name(self._x509)
assert issuer != self._backend._ffi.NULL
- return self._build_x509_name(issuer)
+ return _build_x509_name(self._backend, issuer)
@property
def subject(self):
subject = self._backend._lib.X509_get_subject_name(self._x509)
assert subject != self._backend._ffi.NULL
- return self._build_x509_name(subject)
-
- def _build_x509_name(self, x509_name):
- count = self._backend._lib.X509_NAME_entry_count(x509_name)
- attributes = []
- for x in range(count):
- entry = self._backend._lib.X509_NAME_get_entry(x509_name, x)
- obj = self._backend._lib.X509_NAME_ENTRY_get_object(entry)
- assert obj != self._backend._ffi.NULL
- data = self._backend._lib.X509_NAME_ENTRY_get_data(entry)
- assert data != self._backend._ffi.NULL
- buf = self._backend._ffi.new("unsigned char **")
- res = self._backend._lib.ASN1_STRING_to_UTF8(buf, data)
- assert res >= 0
- assert buf[0] != self._backend._ffi.NULL
- buf = self._backend._ffi.gc(
- buf, lambda buf: self._backend._lib.OPENSSL_free(buf[0])
- )
- value = self._backend._ffi.buffer(buf[0], res)[:].decode('utf8')
- oid = self._obj2txt(obj)
- attributes.append(
- x509.NameAttribute(
- x509.ObjectIdentifier(oid), value
- )
- )
-
- return x509.Name(attributes)
-
- def _obj2txt(self, obj):
- # Set to 80 on the recommendation of
- # https://www.openssl.org/docs/crypto/OBJ_nid2ln.html#return_values
- buf_len = 80
- buf = self._backend._ffi.new("char[]", buf_len)
- res = self._backend._lib.OBJ_obj2txt(buf, buf_len, obj, 1)
- assert res > 0
- return self._backend._ffi.buffer(buf, res)[:].decode()
+ return _build_x509_name(self._backend, subject)
@property
def signature_hash_algorithm(self):
- oid = self._obj2txt(self._x509.sig_alg.algorithm)
+ oid = _obj2txt(self._backend, self._x509.sig_alg.algorithm)
try:
return x509._SIG_OIDS_TO_HASH[oid]
except KeyError: