1
0
mirror of https://github.com/moepman/acertmgr.git synced 2024-11-10 18:30:32 +01:00

tools: update the get_cert_domain function

Add all domains for SAN certificates and convert IDNA values to the
correct representation
This commit is contained in:
Kishi85 2019-04-04 13:21:15 +02:00
parent b63a0bc424
commit 79791c53bc

View File

@ -189,15 +189,14 @@ def download_issuer_ca(cert):
# @brief determine all san domains on a given certificate # @brief determine all san domains on a given certificate
def get_cert_domains(cert): def get_cert_domains(cert):
if cert is None:
log("None-certificate has no domains. You have found a bug. Congratulations!", warning=True)
return []
san_cert = cert.extensions.get_extension_for_oid(ExtensionOID.SUBJECT_ALTERNATIVE_NAME) san_cert = cert.extensions.get_extension_for_oid(ExtensionOID.SUBJECT_ALTERNATIVE_NAME)
domains = set()
domains.add(cert.subject.get_attributes_for_oid(NameOID.COMMON_NAME)[0].value)
if san_cert: if san_cert:
return [d.value for d in san_cert.value] for d in san_cert.value:
else: domains.add(d.value)
return [cert.subject.rfc4514_string()[3:], ] # strip CN= from the result and return as 1 item list # Convert IDNA domain to correct representation and return the list
return [x.encode('idna').decode('ascii') if any(ord(c) >= 128 for c in x) else x for x in domains]
# @brief determine certificate cn # @brief determine certificate cn