aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAlex Gaynor <alex.gaynor@gmail.com>2015-10-27 07:31:25 -0400
committerAlex Gaynor <alex.gaynor@gmail.com>2015-10-27 07:31:25 -0400
commitd9849599346dd245c175221114b8d559d9d2124f (patch)
tree5dcdc3a3c1c5544f6aeae054eb2a07d73b96a6ce /src
parent9c72a6bb3868979cf9416cfa526ea2fc066f854d (diff)
parent8fdd1d3a00ea2c1de04a214314e20a39009c7c29 (diff)
downloadcryptography-d9849599346dd245c175221114b8d559d9d2124f.tar.gz
cryptography-d9849599346dd245c175221114b8d559d9d2124f.tar.bz2
cryptography-d9849599346dd245c175221114b8d559d9d2124f.zip
Merge pull request #2435 from reaperhulk/fix-2407
encode countryName with PrintableString
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 6471da6e..8e302a99 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"])
@@ -133,12 +133,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 Appendix A.1 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