Gracefully handle importing certificates with missing data (#674)
* fixing index out of range issue * catching exceptions is common values aren't set * fixing lint errors * fixing unrelated lint/import error
This commit is contained in:
parent
b1723b4985
commit
162d5ccb62
@ -7,6 +7,7 @@
|
|||||||
"""
|
"""
|
||||||
import requests
|
import requests
|
||||||
import subprocess
|
import subprocess
|
||||||
|
from requests.exceptions import ConnectionError
|
||||||
from cryptography import x509
|
from cryptography import x509
|
||||||
from cryptography.hazmat.backends import default_backend
|
from cryptography.hazmat.backends import default_backend
|
||||||
|
|
||||||
|
@ -53,9 +53,12 @@ def common_name(cert):
|
|||||||
:param cert:
|
:param cert:
|
||||||
:return: Common name or None
|
:return: Common name or None
|
||||||
"""
|
"""
|
||||||
return cert.subject.get_attributes_for_oid(
|
try:
|
||||||
x509.OID_COMMON_NAME
|
return cert.subject.get_attributes_for_oid(
|
||||||
)[0].value.strip()
|
x509.OID_COMMON_NAME
|
||||||
|
)[0].value.strip()
|
||||||
|
except Exception as e:
|
||||||
|
current_app.logger.error("Unable to get common name! {0}".format(e))
|
||||||
|
|
||||||
|
|
||||||
def organization(cert):
|
def organization(cert):
|
||||||
@ -64,9 +67,12 @@ def organization(cert):
|
|||||||
:param cert:
|
:param cert:
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
return cert.subject.get_attributes_for_oid(
|
try:
|
||||||
x509.OID_ORGANIZATION_NAME
|
return cert.subject.get_attributes_for_oid(
|
||||||
)[0].value.strip()
|
x509.OID_ORGANIZATION_NAME
|
||||||
|
)[0].value.strip()
|
||||||
|
except Exception as e:
|
||||||
|
current_app.logger.error("Unable to get organization! {0}".format(e))
|
||||||
|
|
||||||
|
|
||||||
def organizational_unit(cert):
|
def organizational_unit(cert):
|
||||||
@ -75,9 +81,12 @@ def organizational_unit(cert):
|
|||||||
:param cert:
|
:param cert:
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
return cert.subject.get_attributes_for_oid(
|
try:
|
||||||
x509.OID_ORGANIZATIONAL_UNIT_NAME
|
return cert.subject.get_attributes_for_oid(
|
||||||
)[0].value.strip()
|
x509.OID_ORGANIZATIONAL_UNIT_NAME
|
||||||
|
)[0].value.strip()
|
||||||
|
except Exception as e:
|
||||||
|
current_app.logger.error("Unable to get organizational unit! {0}".format(e))
|
||||||
|
|
||||||
|
|
||||||
def country(cert):
|
def country(cert):
|
||||||
@ -86,9 +95,12 @@ def country(cert):
|
|||||||
:param cert:
|
:param cert:
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
return cert.subject.get_attributes_for_oid(
|
try:
|
||||||
x509.OID_COUNTRY_NAME
|
return cert.subject.get_attributes_for_oid(
|
||||||
)[0].value.strip()
|
x509.OID_COUNTRY_NAME
|
||||||
|
)[0].value.strip()
|
||||||
|
except Exception as e:
|
||||||
|
current_app.logger.error("Unable to get country! {0}".format(e))
|
||||||
|
|
||||||
|
|
||||||
def state(cert):
|
def state(cert):
|
||||||
@ -97,9 +109,12 @@ def state(cert):
|
|||||||
:param cert:
|
:param cert:
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
return cert.subject.get_attributes_for_oid(
|
try:
|
||||||
x509.OID_STATE_OR_PROVINCE_NAME
|
return cert.subject.get_attributes_for_oid(
|
||||||
)[0].value.strip()
|
x509.OID_STATE_OR_PROVINCE_NAME
|
||||||
|
)[0].value.strip()
|
||||||
|
except Exception as e:
|
||||||
|
current_app.logger.error("Unable to get state! {0}".format(e))
|
||||||
|
|
||||||
|
|
||||||
def location(cert):
|
def location(cert):
|
||||||
@ -108,9 +123,12 @@ def location(cert):
|
|||||||
:param cert:
|
:param cert:
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
return cert.subject.get_attributes_for_oid(
|
try:
|
||||||
x509.OID_LOCALITY_NAME
|
return cert.subject.get_attributes_for_oid(
|
||||||
)[0].value.strip()
|
x509.OID_LOCALITY_NAME
|
||||||
|
)[0].value.strip()
|
||||||
|
except Exception as e:
|
||||||
|
current_app.logger.error("Unable to get location! {0}".format(e))
|
||||||
|
|
||||||
|
|
||||||
def domains(cert):
|
def domains(cert):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user