diff options
author | Dominic Chen <d.c.ddcc@gmail.com> | 2015-10-09 00:23:07 -0400 |
---|---|---|
committer | Dominic Chen <d.c.ddcc@gmail.com> | 2015-10-10 05:15:46 +0000 |
commit | 87bb9579202ba94df593ae197fd85c22ac1a023c (patch) | |
tree | 8b51772757633cc31528d7187277124146291f2c /src | |
parent | 450d9797a2320f85aff317e5cab39cc2339eabec (diff) | |
download | cryptography-87bb9579202ba94df593ae197fd85c22ac1a023c.tar.gz cryptography-87bb9579202ba94df593ae197fd85c22ac1a023c.tar.bz2 cryptography-87bb9579202ba94df593ae197fd85c22ac1a023c.zip |
fix to handle malformed certificates without hostname
Diffstat (limited to 'src')
-rw-r--r-- | src/cryptography/hazmat/backends/openssl/x509.py | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/src/cryptography/hazmat/backends/openssl/x509.py b/src/cryptography/hazmat/backends/openssl/x509.py index 80f32e29..fd32bd02 100644 --- a/src/cryptography/hazmat/backends/openssl/x509.py +++ b/src/cryptography/hazmat/backends/openssl/x509.py @@ -64,7 +64,9 @@ def _decode_general_names(backend, gns): def _decode_general_name(backend, gn): if gn.type == backend._lib.GEN_DNS: data = backend._asn1_string_to_bytes(gn.d.dNSName) - if data.startswith(b"*."): + if not data: + decoded = u"" + elif data.startswith(b"*."): # This is a wildcard name. We need to remove the leading wildcard, # IDNA decode, then re-add the wildcard. Wildcard characters should # always be left-most (RFC 2595 section 2.4). @@ -82,7 +84,10 @@ def _decode_general_name(backend, gn): elif gn.type == backend._lib.GEN_URI: data = backend._asn1_string_to_ascii(gn.d.uniformResourceIdentifier) parsed = urllib_parse.urlparse(data) - hostname = idna.decode(parsed.hostname) + if parsed.hostname: + hostname = idna.decode(parsed.hostname) + else: + hostname = "" if parsed.port: netloc = hostname + u":" + six.text_type(parsed.port) else: |