pki.util.cert_profileΒΆ

JSON Certificate Profile implementation.

This module provides functionality to verify certificate requests against JSON-based profiles.

Profiles define allowed fields, prohibited fields, and other constraints for certificate requests. They can also specify default values for fields and validate the request against these rules.

Module ContentsΒΆ

pki.util.cert_profile.logger[source]ΒΆ
exception pki.util.cert_profile.ProfileValidationError[source]ΒΆ

Bases: Exception

Raised when the request is well-formed but does not match the profile constraints.

pki.util.cert_profile.ALIASES: dict[str, pydantic.AliasChoices][source]ΒΆ
pki.util.cert_profile.CERT_PROFILE_KEYWORDS[source]ΒΆ
pki.util.cert_profile.build_alias_map_name_oids(alias_map, enum_cls)[source]ΒΆ

Build a mapping of all known OID strings from trustpoint_core to their canonical field names.

Parameters:
  • alias_map (dict[str, str])

  • enum_cls (type[enum.Enum])

Return type:

dict[str, str]

pki.util.cert_profile.alias_map[source]ΒΆ
pki.util.cert_profile.alias_map[source]ΒΆ
class pki.util.cert_profile.ProfileValuePropertyModel(/, **data)[source]ΒΆ

Bases: pydantic.BaseModel

Model for a profile value property.

Parameters:

data (Any)

value: Any | None = None[source]ΒΆ
default: Any | None = None[source]ΒΆ
required: bool = False[source]ΒΆ
mutable: bool = True[source]ΒΆ
class pki.util.cert_profile.SubjectModel(/, **data)[source]ΒΆ

Bases: pydantic.BaseModel

Model for the subject DN of a certificate profile.

Parameters:

data (Any)

common_name: str | ProfileValuePropertyModel | None = None[source]ΒΆ
surname: str | ProfileValuePropertyModel | None = None[source]ΒΆ
serial_number: str | ProfileValuePropertyModel | None = None[source]ΒΆ
country_name: str | ProfileValuePropertyModel | None = None[source]ΒΆ
locality_name: str | ProfileValuePropertyModel | None = None[source]ΒΆ
state_or_province_name: str | ProfileValuePropertyModel | None = None[source]ΒΆ
street_address: str | ProfileValuePropertyModel | None = None[source]ΒΆ
organization_name: str | ProfileValuePropertyModel | None = None[source]ΒΆ
organizational_unit_name: str | ProfileValuePropertyModel | None = None[source]ΒΆ
title: str | ProfileValuePropertyModel | None = None[source]ΒΆ
description: str | ProfileValuePropertyModel | None = None[source]ΒΆ
postal_code: str | ProfileValuePropertyModel | None = None[source]ΒΆ
email_address: str | ProfileValuePropertyModel | None = None[source]ΒΆ
name: str | ProfileValuePropertyModel | None = None[source]ΒΆ
given_name: str | ProfileValuePropertyModel | None = None[source]ΒΆ
initials: str | ProfileValuePropertyModel | None = None[source]ΒΆ
pseudonym: str | ProfileValuePropertyModel | None = None[source]ΒΆ
uid: str | ProfileValuePropertyModel | None = None[source]ΒΆ
domain_component: str | ProfileValuePropertyModel | None = None[source]ΒΆ
model_config[source]ΒΆ

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class pki.util.cert_profile.BaseExtensionModel(/, **data)[source]ΒΆ

Bases: pydantic.BaseModel

Base model for certificate extensions.

Parameters:

data (Any)

critical: bool | None = None[source]ΒΆ
model_config[source]ΒΆ

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class pki.util.cert_profile.BasicConstraintsExtensionModel(/, **data)[source]ΒΆ

Bases: BaseExtensionModel

Model for the Basic Constraints extension of a certificate profile.

Parameters:

data (Any)

ca: bool | None = None[source]ΒΆ
path_length: int | None = None[source]ΒΆ
model_config[source]ΒΆ

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class pki.util.cert_profile.SanExtensionModel(/, **data)[source]ΒΆ

Bases: BaseExtensionModel, ProfileValuePropertyModel

Model for the SAN extension of a certificate profile.

Parameters:

data (Any)

dns_names: list[str] | ProfileValuePropertyModel | None = None[source]ΒΆ
ip_addresses: list[str] | ProfileValuePropertyModel | None = None[source]ΒΆ
rfc822_names: list[str] | ProfileValuePropertyModel | None = None[source]ΒΆ
uris: list[str] | ProfileValuePropertyModel | None = None[source]ΒΆ
other_names: list[str] | ProfileValuePropertyModel | None = None[source]ΒΆ
model_config[source]ΒΆ

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class pki.util.cert_profile.CRLDistributionPointsExtensionModel(/, **data)[source]ΒΆ

Bases: BaseExtensionModel, ProfileValuePropertyModel

Model for the CRL Distribution Points extension of a certificate profile.

Note: Only URIs in full_name are supported.

Parameters:

data (Any)

uris: list[str] | ProfileValuePropertyModel | None = None[source]ΒΆ
model_config[source]ΒΆ

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class pki.util.cert_profile.KeyUsageExtensionModel(/, **data)[source]ΒΆ

Bases: BaseExtensionModel

Model for the Key Usage extension of a certificate profile.

Parameters:

data (Any)

digital_signature: bool | None = None[source]ΒΆ
content_commitment: bool | None = None[source]ΒΆ
key_encipherment: bool | None = None[source]ΒΆ
data_encipherment: bool | None = None[source]ΒΆ
key_agreement: bool | None = None[source]ΒΆ
key_cert_sign: bool | None = None[source]ΒΆ
crl_sign: bool | None = None[source]ΒΆ
encipher_only: bool | None = None[source]ΒΆ
decipher_only: bool | None = None[source]ΒΆ
model_config[source]ΒΆ

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class pki.util.cert_profile.ExtendedKeyUsageExtensionModel(/, **data)[source]ΒΆ

Bases: BaseExtensionModel

Model for the Extended Key Usage extension of a certificate profile.

Parameters:

data (Any)

usages: list[str] | ProfileValuePropertyModel | None = None[source]ΒΆ
model_config[source]ΒΆ

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class pki.util.cert_profile.ExtensionsModel(/, **data)[source]ΒΆ

Bases: pydantic.BaseModel

Model for the extensions of a certificate request.

Parameters:

data (Any)

basic_constraints: BasicConstraintsExtensionModel | None = None[source]ΒΆ
key_usage: KeyUsageExtensionModel | None = None[source]ΒΆ
extended_key_usage: ExtendedKeyUsageExtensionModel | None = None[source]ΒΆ
subject_alternative_name: SanExtensionModel | None = None[source]ΒΆ
crl_distribution_points: CRLDistributionPointsExtensionModel | None = None[source]ΒΆ
class pki.util.cert_profile.ValidityModel(/, **data)[source]ΒΆ

Bases: pydantic.BaseModel

Model for the validity period of a certificate profile.

Parameters:

data (Any)

not_before: pydantic.AwareDatetime | None = None[source]ΒΆ
not_after: pydantic.AwareDatetime | None = None[source]ΒΆ
days: float | None = None[source]ΒΆ
hours: float | None = None[source]ΒΆ
minutes: float | None = None[source]ΒΆ
seconds: int | None = None[source]ΒΆ
duration: datetime.timedelta | None = None[source]ΒΆ
offset_s: int | None = None[source]ΒΆ
validity_max: datetime.timedelta | None = None[source]ΒΆ
validity_min: datetime.timedelta | None = None[source]ΒΆ
model_config[source]ΒΆ

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class pki.util.cert_profile.CertProfileBaseModel(/, **data)[source]ΒΆ

Bases: pydantic.BaseModel

Base model for each nesting level of certificate profiles.

This allows for granular control over allowed fields and constraints at each level.

Parameters:

data (Any)

allow: list[str] | Literal['*'] | None = None[source]ΒΆ
reject_mods: bool = None[source]ΒΆ
classmethod normalize_allow(value)[source]ΒΆ

Normalize the allow list by replacing aliases with their canonical names.

Parameters:

value (list[str] | Literal['*'] | None)

Return type:

list[str] | Literal[β€˜*’] | None

class pki.util.cert_profile.ProfileSubjectModel(/, **data)[source]ΒΆ

Bases: SubjectModel, CertProfileBaseModel

Model for the subject DN of a certificate profile, with profile constraints.

Parameters:

data (Any)

class pki.util.cert_profile.ProfileSanExtensionModel(/, **data)[source]ΒΆ

Bases: SanExtensionModel, CertProfileBaseModel

Model for the SAN extension of a certificate profile, with profile constraints.

Parameters:

data (Any)

class pki.util.cert_profile.ProfileCrlDistributionPointsExtensionModel(/, **data)[source]ΒΆ

Bases: CRLDistributionPointsExtensionModel, CertProfileBaseModel

Model for the CRL Distribution Points extension of a certificate profile, with profile constraints.

Parameters:

data (Any)

class pki.util.cert_profile.ProfileExtensionsModel(/, **data)[source]ΒΆ

Bases: CertProfileBaseModel

Model for the extensions of a certificate profile, with profile constraints.

Parameters:

data (Any)

basic_constraints: BasicConstraintsExtensionModel | ProfileValuePropertyModel | None = None[source]ΒΆ
key_usage: KeyUsageExtensionModel | ProfileValuePropertyModel | None = None[source]ΒΆ
extended_key_usage: ExtendedKeyUsageExtensionModel | ProfileValuePropertyModel | None = None[source]ΒΆ
subject_alternative_name: ProfileSanExtensionModel | ProfileValuePropertyModel | None = None[source]ΒΆ
crl_distribution_points: ProfileCrlDistributionPointsExtensionModel | ProfileValuePropertyModel | None = None[source]ΒΆ
class pki.util.cert_profile.CertProfileModel(/, **data)[source]ΒΆ

Bases: CertProfileBaseModel

Model for a certificate profile.

Parameters:

data (Any)

type: Literal['cert_profile'][source]ΒΆ
display_name: str | None = None[source]ΒΆ
subject: ProfileSubjectModel = None[source]ΒΆ
extensions: ProfileExtensionsModel = None[source]ΒΆ
validity: ValidityModel = None[source]ΒΆ
class pki.util.cert_profile.CertRequestModel(/, **data)[source]ΒΆ

Bases: pydantic.BaseModel

Model for a certificate request.

Parameters:

data (Any)

type: Literal['cert_request'] | None = 'cert_request'[source]ΒΆ
subject: SubjectModel = None[source]ΒΆ
extensions: ExtensionsModel = None[source]ΒΆ
validity: ValidityModel = None[source]ΒΆ
model_config[source]ΒΆ

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class pki.util.cert_profile.InheritedProfileConfig(*, allow_implicit=False, reject_mods=False, mutable=False)[source]ΒΆ

Constraints set in the profile that are inherited by deeper nesting levels.

Parameters:
  • allow_implicit (bool)

  • reject_mods (bool)

  • mutable (bool)

allow_implicit: bool = False[source]ΒΆ
reject_mods: bool = False[source]ΒΆ
mutable: bool = False[source]ΒΆ
class pki.util.cert_profile.JSONProfileVerifier(profile)[source]ΒΆ

Class to verify certificate requests against JSON-based profiles.

Parameters:

profile (dict[str, Any])

profile[source]ΒΆ
profile_dict[source]ΒΆ
static validate_request(request)[source]ΒΆ

Validates and normalizes a certificate request.

This just checks its structure, it does not validate against a profile.

Parameters:

request (dict[str, Any])

Return type:

dict[str, Any]

apply_profile_to_request(request)[source]ΒΆ

Apply the profile to a certificate request and return the modified request.

Parameters:

request (dict[str, Any])

Return type:

dict[str, Any]

get_sample_request()[source]ΒΆ

Generate a sample certificate request that conforms to the profile.

Return type:

dict[str, Any]

get_profile()[source]ΒΆ

Get the profile as a dictionary.

Return type:

dict[str, Any]