|
|
def reset_certificate(record):
record.pem_certificate = False
record.subject_common_name = False
record.content_format = False
record.date_start = False
record.date_end = False
record.serial_number = False
record.loading_error = False
for certificate in self:
content = certificate.with_context(bin_size=False).content
if not content:
reset_certificate(certificate)
continue
pkcs12_password = certificate.pkcs12_password.encode('utf-8') if certificate.pkcs12_password else None
leaf_pem, _additional_pems, certificate.content_format = self._parse_certificate_content(content, pkcs12_password)
if not leaf_pem:
reset_certificate(certificate)
if certificate.pkcs12_password:
certificate.loading_error = _(
"This certificate could not be loaded. Either the content or the password is erroneous."
)
continue
cert = x509.load_pem_x509_certificate(leaf_pem)
certificate.loading_error = ""
# Extract certificate data
certificate.pem_certificate = base64.b64encode(leaf_pem)
certificate.serial_number = cert.serial_number
certificate.subject_common_name = self._get_common_name(cert) or cert.serial_number
if parse_version(metadata.version('cryptography')) < parse_version('42.0.0'):
certificate.date_start = cert.not_valid_before
certificate.date_end = cert.not_valid_after
else:
certificate.date_start = cert.not_valid_before_utc.replace(tzinfo=None)
certificate.date_end = cert.not_valid_after_utc.replace(tzinfo=None)
|
|