pki.models.certificateΒΆ

Module that contains the CertificateModel.

ClassesΒΆ

CertificateModel

X509 Certificate Model.

RevokedCertificateModel

Model to store revoked certificates.

Module ContentsΒΆ

class pki.models.certificate.CertificateModel(*args, **kwargs)[source]ΒΆ

Bases: trustpoint.logger.LoggerMixin, util.db.CustomDeleteActionModel

X509 Certificate Model.

See RFC5280 for more information.

class CertificateStatus(*args, **kwds)[source]ΒΆ

Bases: django.db.models.TextChoices

CertificateModel status.

OK[source]ΒΆ
REVOKED[source]ΒΆ
EXPIRED[source]ΒΆ
NOT_YET_VALID[source]ΒΆ
class Version(*args, **kwds)[source]ΒΆ

Bases: django.db.models.IntegerChoices

X509 RFC 5280 - Certificate Version.

V3[source]ΒΆ
class SignatureAlgorithmOidChoices(*args, **kwds)[source]ΒΆ

Bases: django.db.models.TextChoices

Signature Algorithm OIDs.

RSA_MD5[source]ΒΆ
RSA_SHA1[source]ΒΆ
RSA_SHA1_ALT[source]ΒΆ
RSA_SHA224[source]ΒΆ
RSA_SHA256[source]ΒΆ
RSA_SHA384[source]ΒΆ
RSA_SHA512[source]ΒΆ
RSA_SHA3_224[source]ΒΆ
RSA_SHA3_256[source]ΒΆ
RSA_SHA3_384[source]ΒΆ
RSA_SHA3_512[source]ΒΆ
ECDSA_SHA1[source]ΒΆ
ECDSA_SHA224[source]ΒΆ
ECDSA_SHA256[source]ΒΆ
ECDSA_SHA384[source]ΒΆ
ECDSA_SHA512[source]ΒΆ
ECDSA_SHA3_224[source]ΒΆ
ECDSA_SHA3_256[source]ΒΆ
ECDSA_SHA3_384[source]ΒΆ
ECDSA_SHA3_512[source]ΒΆ
PASSWORD_BASED_MAC[source]ΒΆ
class PublicKeyAlgorithmOidChoices(*args, **kwds)[source]ΒΆ

Bases: django.db.models.TextChoices

Public Key Algorithm OIDs.

ECC[source]ΒΆ
RSA[source]ΒΆ
class PublicKeyEcCurveOidChoices(*args, **kwds)[source]ΒΆ

Bases: django.db.models.TextChoices

Public Key EC Curve OIDs.

NONE = ''[source]ΒΆ
SECP192R1[source]ΒΆ
SECP224R1[source]ΒΆ
SECP256K1[source]ΒΆ
SECP256R1[source]ΒΆ
SECP384R1[source]ΒΆ
SECP521R1[source]ΒΆ
BRAINPOOLP256R1[source]ΒΆ
BRAINPOOLP384R1[source]ΒΆ
BRAINPOOLP512R1[source]ΒΆ
SECT163K1[source]ΒΆ
SECT163R2[source]ΒΆ
SECT233K1[source]ΒΆ
SECT233R1[source]ΒΆ
SECT283K1[source]ΒΆ
SECT283R1[source]ΒΆ
SECT409K1[source]ΒΆ
SECT409R1[source]ΒΆ
SECT571K1[source]ΒΆ
SECT571R1[source]ΒΆ
is_self_signed[source]ΒΆ
common_name[source]ΒΆ
sha256_fingerprint[source]ΒΆ
signature_algorithm_oid[source]ΒΆ
signature_value[source]ΒΆ
version[source]ΒΆ
serial_number[source]ΒΆ
issuer[source]ΒΆ
issuer_public_bytes[source]ΒΆ
issuer_id[source]ΒΆ
not_valid_before[source]ΒΆ
not_valid_after[source]ΒΆ
subject[source]ΒΆ
subject_public_bytes[source]ΒΆ
spki_algorithm_oid[source]ΒΆ
spki_algorithm[source]ΒΆ
spki_key_size[source]ΒΆ
spki_ec_curve_oid[source]ΒΆ
spki_ec_curve[source]ΒΆ
cert_pem[source]ΒΆ
public_key_pem[source]ΒΆ
created_at[source]ΒΆ
key_usage_extension[source]ΒΆ
subject_alternative_name_extension[source]ΒΆ
issuer_alternative_name_extension[source]ΒΆ
basic_constraints_extension[source]ΒΆ
authority_key_identifier_extension[source]ΒΆ
subject_key_identifier_extension[source]ΒΆ
certificate_policies_extension[source]ΒΆ
extended_key_usage_extension[source]ΒΆ
name_constraints_extension[source]ΒΆ
crl_distribution_points_extension[source]ΒΆ
authority_information_access_extension[source]ΒΆ
subject_information_access_extension[source]ΒΆ
inhibit_any_policy_extension[source]ΒΆ
policy_constraints_extension[source]ΒΆ
subject_directory_attributes_extension[source]ΒΆ
freshest_crl_extension[source]ΒΆ
class Meta[source]ΒΆ

Bases: django_stubs_ext.db.models.TypedModelMeta

Meta class configuration.

__repr__()[source]ΒΆ

Representation of the CertificateModel instance.

Return type:

str

__str__()[source]ΒΆ

Human-readable representation of the CertificateModel instance.

Return type:

str

save(*_args, **_kwargs)[source]ΒΆ

Save method must not be called directly to protect the integrity.

This method makes sure save() is not called by mistake.

Raises:

NotImplementedError –

Parameters:
  • _args (Any)

  • _kwargs (Any)

Return type:

None

property signature_algorithm: str[source]ΒΆ

Name of the signature algorithm.

Return type:

str

property signature_algorithm_padding_scheme: str[source]ΒΆ

Padding scheme if RSA is used, otherwise None.

Return type:

str

property signature_suite: trustpoint_core.oid.SignatureSuite[source]ΒΆ

Signature Suite of the certificate.

Return type:

trustpoint_core.oid.SignatureSuite

property public_key_info: trustpoint_core.oid.PublicKeyInfo[source]ΒΆ

Public Key Info of the certificate.

Return type:

trustpoint_core.oid.PublicKeyInfo

property certificate_status: CertificateStatus[source]ΒΆ

Status of the certificate.

Return type:

CertificateStatus

property days_left: int[source]ΒΆ

Returns number of days from now until not_valid_after. If expired, returns 0.

Return type:

int

property is_ca: bool[source]ΒΆ

Check if the certificate is a CA certificate.

Return type:

bool

property is_root_ca: bool[source]ΒΆ

Check if the certificate is a root CA certificate.

Return type:

bool

property is_end_entity: bool[source]ΒΆ

Check if the certificate is an end entity certificate.

Return type:

bool

classmethod get_cert_by_sha256_fingerprint(sha256_fingerprint)[source]ΒΆ

Get a CertificateModel instance by its SHA256 fingerprint.

Parameters:

sha256_fingerprint (str)

Return type:

None | CertificateModel

static _get_subject(cert)[source]ΒΆ
Parameters:

cert (cryptography.x509.Certificate)

Return type:

list[tuple[str, str]]

static _get_issuer_name(cert)[source]ΒΆ
Parameters:

cert (cryptography.x509.Certificate)

Return type:

list[tuple[str, str]]

static _get_spki_info(cert)[source]ΒΆ
Parameters:

cert (cryptography.x509.Certificate)

Return type:

tuple[trustpoint_core.oid.PublicKeyAlgorithmOid, int, trustpoint_core.oid.NamedCurve]

get_certificate_serializer()[source]ΒΆ

Get the serializer for the certificate.

Return type:

trustpoint_core.serializer.CertificateSerializer

get_public_key_serializer()[source]ΒΆ

Get the serializer for the certificate’s public key.

Return type:

trustpoint_core.serializer.PublicKeySerializer

get_certificate_chain()[source]ΒΆ

Get the certificate chain from this certificate up to the root CA.

Return type:

list[CertificateModel]

_save(**kwargs)[source]ΒΆ
Parameters:

kwargs (Any)

Return type:

None

classmethod _save_certificate(certificate)[source]ΒΆ
Parameters:

certificate (cryptography.x509.Certificate | trustpoint_core.serializer.CertificateSerializer)

Return type:

CertificateModel

static _save_attribute_and_value_pairs(oid, value)[source]ΒΆ
Parameters:
  • oid (str)

  • value (str)

Return type:

pki.models.extension.AttributeTypeAndValue

classmethod _save_subject(cert_model, subject)[source]ΒΆ
Parameters:
Return type:

None

classmethod _save_issuer(cert_model, issuer)[source]ΒΆ
Parameters:
Return type:

None

EXTENSION_MAP[source]ΒΆ
static _save_extensions(cert_model, cert)[source]ΒΆ
Parameters:
Return type:

None

classmethod _atomic_save(cert_model, certificate, subject, issuer)[source]ΒΆ
Parameters:
  • cert_model (CertificateModel)

  • certificate (cryptography.x509.Certificate)

  • subject (list[tuple[str, str]])

  • issuer (list[tuple[str, str]])

Return type:

CertificateModel

classmethod save_certificate(certificate)[source]ΒΆ

Store the certificate in the database.

Returns:

The certificate object that has just been saved.

Return type:

trustpoint.pki.models.Certificate

Parameters:

certificate (cryptography.x509.Certificate | trustpoint_core.serializer.CertificateSerializer)

pre_delete()[source]ΒΆ

Store the related objects before deletion.

Return type:

None

post_delete()[source]ΒΆ

Clean up related orphaned extension models.

Return type:

None

subjects_match(other_subject)[source]ΒΆ

Check if the provided subject is identical to the one of this certificate.

Parameters:

other_subject (x509.Name) – The subject to compare to.

Returns:

True if the subjects match, False otherwise.

Return type:

bool

class pki.models.certificate.RevokedCertificateModel(*args, **kwargs)[source]ΒΆ

Bases: django.db.models.Model

Model to store revoked certificates.

class ReasonCode(*args, **kwds)[source]ΒΆ

Bases: django.db.models.TextChoices

Revocation reasons per RFC 5280.

UNSPECIFIED[source]ΒΆ
KEY_COMPROMISE[source]ΒΆ
CA_COMPROMISE[source]ΒΆ
AFFILIATION_CHANGED[source]ΒΆ
SUPERSEDED[source]ΒΆ
CESSATION[source]ΒΆ
CERTIFICATE_HOLD[source]ΒΆ
PRIVILEGE_WITHDRAWN[source]ΒΆ
AA_COMPROMISE[source]ΒΆ
REMOVE_FROM_CRL[source]ΒΆ
certificate[source]ΒΆ
revoked_at[source]ΒΆ
revocation_reason[source]ΒΆ
ca[source]ΒΆ
class Meta[source]ΒΆ

Bases: django_stubs_ext.db.models.TypedModelMeta

Meta class configuration.

__str__()[source]ΒΆ

String representation of the RevokedCertificateModel instance.

Return type:

str