aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPaul Kehrer <paul.l.kehrer@gmail.com>2015-10-19 23:45:59 -0500
committerPaul Kehrer <paul.l.kehrer@gmail.com>2015-10-20 11:13:07 -0500
commit5a2bb54bbb7b68a7407ab5d62c828c329166bd81 (patch)
treec2de009d37d9f1603dd66914bf9f6f3a4f12aa4a /src
parent08801cd1bacf08aa4d4a833ff235574f4da15a20 (diff)
downloadcryptography-5a2bb54bbb7b68a7407ab5d62c828c329166bd81.tar.gz
cryptography-5a2bb54bbb7b68a7407ab5d62c828c329166bd81.tar.bz2
cryptography-5a2bb54bbb7b68a7407ab5d62c828c329166bd81.zip
encode countryName with PrintableString
This commit adds a dependency on asn1crypto for testing purposes to parse the certificate and confirm that countryName is encoded with PrintableString while other fields are UTF8String. This is a test only dep.
Diffstat (limited to 'src')
-rw-r--r--src/cryptography/hazmat/backends/openssl/backend.py14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/cryptography/hazmat/backends/openssl/backend.py b/src/cryptography/hazmat/backends/openssl/backend.py
index f86c3aa1..db7022e5 100644
--- a/src/cryptography/hazmat/backends/openssl/backend.py
+++ b/src/cryptography/hazmat/backends/openssl/backend.py
@@ -52,7 +52,7 @@ from cryptography.hazmat.primitives.ciphers.algorithms import (
from cryptography.hazmat.primitives.ciphers.modes import (
CBC, CFB, CFB8, CTR, ECB, GCM, OFB
)
-from cryptography.x509.oid import ExtensionOID
+from cryptography.x509.oid import ExtensionOID, NameOID
_MemoryBIO = collections.namedtuple("_MemoryBIO", ["bio", "char_ptr"])
@@ -119,12 +119,14 @@ def _encode_name(backend, attributes):
for attribute in attributes:
value = attribute.value.encode('utf8')
obj = _txt2obj_gc(backend, attribute.oid.dotted_string)
+ if attribute.oid == NameOID.COUNTRY_NAME:
+ # Per RFC5280 countryName should be encoded as PrintableString,
+ # not UTF8String
+ type = backend._lib.MBSTRING_ASC
+ else:
+ type = backend._lib.MBSTRING_UTF8
res = backend._lib.X509_NAME_add_entry_by_OBJ(
- subject,
- obj,
- backend._lib.MBSTRING_UTF8,
- value,
- -1, -1, 0,
+ subject, obj, type, value, -1, -1, 0,
)
backend.openssl_assert(res == 1)
return subject