pki.models.extensionΒΆ

Module that contains X.509 Extension Models.

Module ContentsΒΆ

class pki.models.extension.AttributeTypeAndValue(*args, **kwargs)[source]ΒΆ

Bases: django.db.models.Model

AttributeTypeAndValue Model.

Used for subject entries as well as the GeneralNameDirectoryName entries within the SubjectAlternativeName and IssuerAlternativeName.

See RFC5280 for more information.

oid[source]ΒΆ
value[source]ΒΆ
class Meta[source]ΒΆ
unique_together = ('oid', 'value')[source]ΒΆ
property abbreviation: str | None[source]ΒΆ

Returns the abbreviation of the attribute’s OID.

Return type:

str | None

property verbose_name: str[source]ΒΆ

Returns the verbose name of the attribute’s OID.

Return type:

str

class pki.models.extension.GeneralNameRFC822Name(*args, **kwargs)[source]ΒΆ

Bases: util.db.OrphanDeletionMixin, django.db.models.Model

GeneralNameRFC822Name Model.

Entries of either SubjectAlternativeNames or IssuerAlternativeNames.

See RFC5280 for more information.

value[source]ΒΆ
check_references_on_delete = ('general_names_set',)[source]ΒΆ
class pki.models.extension.GeneralNameDNSName(*args, **kwargs)[source]ΒΆ

Bases: util.db.OrphanDeletionMixin, django.db.models.Model

GeneralNameDNSName Model.

See RFC5280 for more information.

value[source]ΒΆ
check_references_on_delete = ('general_names_set',)[source]ΒΆ
class pki.models.extension.GeneralNameDirectoryName(*args, **kwargs)[source]ΒΆ

Bases: util.db.OrphanDeletionMixin, django.db.models.Model

GeneralNameDirectoryName Model.

Entries of either SubjectAlternativeNames or IssuerAlternativeNames.

See RFC5280 for more information.

names[source]ΒΆ
check_references_on_delete = ('general_names_set',)[source]ΒΆ
class pki.models.extension.GeneralNameUniformResourceIdentifier(*args, **kwargs)[source]ΒΆ

Bases: util.db.OrphanDeletionMixin, django.db.models.Model

GeneralNameUniformResourceIdentifier Model.

Entries of either SubjectAlternativeNames or IssuerAlternativeNames.

See RFC5280 for more information.

value[source]ΒΆ
check_references_on_delete = ('general_names_set',)[source]ΒΆ
class pki.models.extension.GeneralNameIpAddress(*args, **kwargs)[source]ΒΆ

Bases: util.db.OrphanDeletionMixin, django.db.models.Model

GeneralNameIpAddress Model.

Entries of either SubjectAlternativeNames or IssuerAlternativeNames.

See RFC5280 for more information.

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

Bases: django.db.models.TextChoices

Class for creating enumerated string choices.

IPV4_ADDRESS[source]ΒΆ
IPV6_ADDRESS[source]ΒΆ
IPV4_NETWORK[source]ΒΆ
IPV6_NETWORK[source]ΒΆ
ip_type[source]ΒΆ
value[source]ΒΆ
check_references_on_delete = ('general_names_set',)[source]ΒΆ
class Meta[source]ΒΆ
unique_together = ('ip_type', 'value')[source]ΒΆ
class pki.models.extension.GeneralNameRegisteredId(*args, **kwargs)[source]ΒΆ

Bases: util.db.OrphanDeletionMixin, django.db.models.Model

GeneralNameRegisteredId Model.

Entries of either SubjectAlternativeNames or IssuerAlternativeNames.

See RFC5280 for more information.

value[source]ΒΆ
check_references_on_delete = ('general_names_set',)[source]ΒΆ
class pki.models.extension.GeneralNameOtherName(*args, **kwargs)[source]ΒΆ

Bases: util.db.OrphanDeletionMixin, django.db.models.Model

GeneralNameOtherName Model.

Entries of either SubjectAlternativeNames or IssuerAlternativeNames.

See RFC5280 for more information.

type_id[source]ΒΆ
value[source]ΒΆ
check_references_on_delete = ('general_names_set',)[source]ΒΆ
class Meta[source]ΒΆ
unique_together = ('type_id', 'value')[source]ΒΆ
class pki.models.extension.CertificateExtension(*args, **kwargs)[source]ΒΆ

Bases: util.db.OrphanDeletionMixin

Abstract Base Class of Extension Models.

Due to a Metaclass conflict, this class is not derived from abc.ABC on purpose. # TODO: check if this can be rectified

property extension_oid: str[source]ΒΆ

Returns the OID of the extension.

Return type:

str

classmethod save_from_crypto_extensions(extension)[source]ΒΆ
Abstractmethod:

Parameters:

extension (cryptography.x509.Extension[T])

Return type:

CertificateExtension | None

Stores the extension in the database.

Meant to be called within an atomic transaction while storing a certificate.

Parameters:

extension (x509.Extension) – The X.509 extension object.

Returns:

The instance of the saved extension.

Return type:

CertificateExtension

classmethod delete_if_orphaned(instance)[source]ΒΆ

Removes the Extension instance if no longer referenced.

Since all extension classes are only referenced by the Certificate model with on_delete=models.PROTECT, we can rely on the database protection to remove the instance if it is no longer referenced. This saves an extra query to check if the β€˜certificates’ reverse relation still exists.

Parameters:

instance (util.db.OrphanDeletionMixin | None)

Return type:

None

class pki.models.extension.BasicConstraintsExtension(*args, **kwargs)[source]ΒΆ

Bases: CertificateExtension, django.db.models.Model

Represents the BasicConstraints extension in X.509 certificates.

This extension indicates whether a certificate is a CA and its path length.

critical[source]ΒΆ
ca[source]ΒΆ
path_length_constraint[source]ΒΆ
class Meta[source]ΒΆ
unique_together = ('critical', 'ca', 'path_length_constraint')[source]ΒΆ
classmethod save_from_crypto_extensions(crypto_basic_constraints_extension)[source]ΒΆ

Stores the BasicConstraintsExtension in the database.

Parameters:

crypto_basic_constraints_extension (x509.Extension) – The X.509 extension containing BasicConstraints.

Returns:

The instance of the saved extension.

Return type:

BasicConstraintsExtension

class pki.models.extension.KeyUsageExtension(*args, **kwargs)[source]ΒΆ

Bases: CertificateExtension, django.db.models.Model

Represents the KeyUsage extension in X.509 certificates.

Specifies the permitted usage of the certificate’s public key.

critical[source]ΒΆ
digital_signature[source]ΒΆ
content_commitment[source]ΒΆ
key_encipherment[source]ΒΆ
data_encipherment[source]ΒΆ
key_agreement[source]ΒΆ
key_cert_sign[source]ΒΆ
crl_sign[source]ΒΆ
encipher_only[source]ΒΆ
decipher_only[source]ΒΆ
class Meta[source]ΒΆ
unique_together = ('digital_signature', 'content_commitment', 'key_encipherment', 'data_encipherment',...[source]ΒΆ
classmethod save_from_crypto_extensions(crypto_basic_constraints_extension)[source]ΒΆ

Stores the KeyUsage extension in the database.

Parameters:

crypto_basic_constraints_extension (x509.Extension) – The X.509 extension containing KeyUsage.

Returns:

The instance of the saved extension.

Return type:

KeyUsageExtension

class pki.models.extension.GeneralNamesModel(*args, **kwargs)[source]ΒΆ

Bases: util.db.OrphanDeletionMixin, util.db.CustomDeleteActionModel

Represents a collection of general names as per RFC5280.

Used for both SubjectAlternativeName and IssuerAlternativeName extensions.

rfc822_names[source]ΒΆ
dns_names[source]ΒΆ
directory_names[source]ΒΆ
uniform_resource_identifiers[source]ΒΆ
ip_addresses[source]ΒΆ
registered_ids[source]ΒΆ
other_names[source]ΒΆ
save_general_names(general_names)[source]ΒΆ

Stores general names in the database.

Parameters:

general_names (x509.Extension | list[x509.GeneralName]) – The X.509 general names extension or a list of general names.

Returns:

The instance of the saved general names.

Return type:

GeneralNamesModel

class pki.models.extension.IssuerAlternativeNameExtension(*args, **kwargs)[source]ΒΆ

Bases: CertificateExtension, util.db.CustomDeleteActionModel

IssuerAlternativeNameExtension Model.

See RFC5280 for more information.

critical[source]ΒΆ
issuer_alt_name[source]ΒΆ
post_delete()[source]ΒΆ

Clean up related orphaned extension field models.

Return type:

None

classmethod save_from_crypto_extensions(extension)[source]ΒΆ

Stores the IssuerAlternativeNameExtension in the database.

Meant to be called within an atomic transaction while storing a certificate.

Parameters:

extension (x509.Extension) – The x509.Extension object that contains all extensions of the certificate.

Returns:

The instance of the saved IssuerAlternativeNameExtension.

Return type:

trustpoint.pki.models.IssuerAlternativeNameExtension

class pki.models.extension.SubjectAlternativeNameExtension(*args, **kwargs)[source]ΒΆ

Bases: CertificateExtension, util.db.CustomDeleteActionModel

Represents the SubjectAlternativeName extension in X.509 certificates.

Stores alternative names for the certificate’s subject.

critical[source]ΒΆ
subject_alt_name[source]ΒΆ
post_delete()[source]ΒΆ

Clean up related orphaned extension field models.

Return type:

None

classmethod save_from_crypto_extensions(extension)[source]ΒΆ

Stores the SubjectAlternativeName extension in the database.

Parameters:

extension (x509.Extension) – The X.509 extension containing SubjectAlternativeName.

Returns:

The instance of the saved extension.

Return type:

SubjectAlternativeNameExtension

class pki.models.extension.PolicyConstraintsExtension(*args, **kwargs)[source]ΒΆ

Bases: CertificateExtension, django.db.models.Model

Represents the PolicyConstraints extension in X.509 certificates.

This extension specifies whether an explicit policy is required and whether policy mapping is inhibited.

critical[source]ΒΆ
require_explicit_policy[source]ΒΆ
inhibit_policy_mapping[source]ΒΆ
objects: django.db.models.Manager[PolicyConstraintsExtension][source]ΒΆ
classmethod save_from_crypto_extensions(extension)[source]ΒΆ

Stores the PolicyMappingsExtension in the database.

Parameters:

extension (x509.Extension) – The x509.Extension object containing PolicyConstraints.

Returns:

The saved instance of PolicyConstraintsExtension or None.

Return type:

PolicyConstraintsExtension