aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPaul Kehrer <paul.l.kehrer@gmail.com>2015-07-11 12:32:27 -0500
committerPaul Kehrer <paul.l.kehrer@gmail.com>2015-07-11 12:33:44 -0500
commit065b7b81984b8dbb24910d438b9ea0128db0b0bf (patch)
tree2237d3a9dd1d8e96ac8777e6ab91e53a8520887a /src
parent9ce25a9e624a43e47f677a764d4eedcdc7f6c86e (diff)
downloadcryptography-065b7b81984b8dbb24910d438b9ea0128db0b0bf.tar.gz
cryptography-065b7b81984b8dbb24910d438b9ea0128db0b0bf.tar.bz2
cryptography-065b7b81984b8dbb24910d438b9ea0128db0b0bf.zip
modify _encode_name, add _encode_name_gc
Diffstat (limited to 'src')
-rw-r--r--src/cryptography/hazmat/backends/openssl/backend.py15
1 files changed, 10 insertions, 5 deletions
diff --git a/src/cryptography/hazmat/backends/openssl/backend.py b/src/cryptography/hazmat/backends/openssl/backend.py
index 194f295c..af675116 100644
--- a/src/cryptography/hazmat/backends/openssl/backend.py
+++ b/src/cryptography/hazmat/backends/openssl/backend.py
@@ -89,8 +89,10 @@ def _encode_asn1_str(backend, data, length):
def _encode_name(backend, attributes):
+ """
+ The X509_NAME created will not be gc'd. Use _encode_name_gc if needed.
+ """
subject = backend._lib.X509_NAME_new()
- subject = backend._ffi.gc(subject, backend._lib.X509_NAME_free)
for attribute in attributes:
value = attribute.value.encode('utf8')
obj = _txt2obj(backend, attribute.oid.dotted_string)
@@ -105,6 +107,12 @@ def _encode_name(backend, attributes):
return subject
+def _encode_name_gc(backend, attributes):
+ subject = _encode_name(backend, attributes)
+ subject = backend._ffi.gc(subject, backend._lib.X509_NAME_free)
+ return subject
+
+
def _txt2obj(backend, name):
"""
Converts a Python string with an ASN.1 object ID in dotted form to a
@@ -175,9 +183,6 @@ def _encode_subject_alt_name(backend, san):
gn = backend._lib.GENERAL_NAME_new()
assert gn != backend._ffi.NULL
name = _encode_name(backend, alt_name.value)
- # _encode_name registers the X509_NAME for gc so we'll duplicate
- # a new one that is not gc'd for the struct
- name = backend._lib.X509_NAME_dup(name)
gn.type = backend._lib.GEN_DIRNAME
gn.d.directoryName = name
else:
@@ -883,7 +888,7 @@ class Backend(object):
# Set subject name.
res = self._lib.X509_REQ_set_subject_name(
- x509_req, _encode_name(self, builder._subject_name)
+ x509_req, _encode_name_gc(self, builder._subject_name)
)
assert res == 1