aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPaul Kehrer <paul.l.kehrer@gmail.com>2018-07-10 04:55:02 +0530
committerAlex Gaynor <alex.gaynor@gmail.com>2018-07-09 19:25:02 -0400
commit20ae2c8084812bd218d2b1d2972774963c4d2041 (patch)
treeb8d38879064f3cc0856b9771a08524d15925d15c /src
parent01c9dac7c0ac33fb3dd73ab32322f7fc1699c059 (diff)
downloadcryptography-20ae2c8084812bd218d2b1d2972774963c4d2041.tar.gz
cryptography-20ae2c8084812bd218d2b1d2972774963c4d2041.tar.bz2
cryptography-20ae2c8084812bd218d2b1d2972774963c4d2041.zip
fix encoding BMPString in x509 name entries (#4321)
Previously we encoded them as UTF-8, but as best I can tell in reality a BMPString is fixed-width basic multilingual plane big endian encoding. This is basically UCS-2 (aka original Unicode). However, Python doesn't support UCS-2 encoding so we need to use utf_16_be. This means you can encode surrogate code points that are invalid in the context of what a BMPString is supposed to be, but in reality I strongly suspect the sane encoding ship has sailed and dozens if not hundreds of implementations both do this and expect other systems to handle their nonsense.
Diffstat (limited to 'src')
-rw-r--r--src/cryptography/hazmat/backends/openssl/encode_asn1.py9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/cryptography/hazmat/backends/openssl/encode_asn1.py b/src/cryptography/hazmat/backends/openssl/encode_asn1.py
index 4bea03e6..a2c7ed73 100644
--- a/src/cryptography/hazmat/backends/openssl/encode_asn1.py
+++ b/src/cryptography/hazmat/backends/openssl/encode_asn1.py
@@ -14,6 +14,7 @@ from cryptography.hazmat.backends.openssl.decode_asn1 import (
_CRL_ENTRY_REASON_ENUM_TO_CODE, _DISTPOINT_TYPE_FULLNAME,
_DISTPOINT_TYPE_RELATIVENAME
)
+from cryptography.x509.name import _ASN1Type
from cryptography.x509.oid import CRLEntryExtensionOID, ExtensionOID
@@ -116,11 +117,15 @@ def _encode_sk_name_entry(backend, attributes):
def _encode_name_entry(backend, attribute):
- value = attribute.value.encode('utf8')
+ if attribute._type is _ASN1Type.BMPString:
+ value = attribute.value.encode('utf_16_be')
+ else:
+ value = attribute.value.encode('utf8')
+
obj = _txt2obj_gc(backend, attribute.oid.dotted_string)
name_entry = backend._lib.X509_NAME_ENTRY_create_by_OBJ(
- backend._ffi.NULL, obj, attribute._type.value, value, -1
+ backend._ffi.NULL, obj, attribute._type.value, value, len(value)
)
return name_entry