ipalib.x509: Handle missing SAN gracefully

When extension is not present None is returned instead of empty iterable
or exception thrown.

Reviewed-By: Martin Basti <mbasti@redhat.com>
This commit is contained in:
David Kupka
2017-01-23 10:38:34 +01:00
committed by Martin Basti
parent 7e2d185ba0
commit 308c790ee9

View File

@@ -435,8 +435,12 @@ def get_san_general_names(cert):
asn1Spec=rfc2459.TBSCertificate()
)[0]
OID_SAN = univ.ObjectIdentifier('2.5.29.17')
# One would expect KeyError or empty iterable when the key ('extensions'
# in this particular case) is not pressent in the certificate but pyasn1
# returns None here
extensions = tbs['extensions'] or []
gns = []
for ext in tbs['extensions']:
for ext in extensions:
if ext['extnID'] == OID_SAN:
der = decoder.decode(
ext['extnValue'], asn1Spec=univ.OctetString())[0]