Odoo Mindscape. Understand Odoo faster. Explore modules, fields, dependencies and version differences in one place instead of digging through the source code.

Module: Certificate

Entity: certificate.certificate

Compute Method: _compute_pem_certificate

View 18.0
Inputs Method Outputs
  • pkcs12_password
+ 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)
  • content_format
  • loading_error
  • pem_certificate
  • serial_number
  • subject_common_name
  • date_start
  • date_end

Back to entity