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.
Attributes¶
Exceptions¶
Raised when the request is well-formed but does not match the profile constraints. |
Classes¶
Model for a profile value property. |
|
Model for the subject DN of a certificate profile. |
|
Base model for certificate extensions. |
|
Model for the Basic Constraints extension of a certificate profile. |
|
Model for the SAN extension of a certificate profile. |
|
Model for the CRL Distribution Points extension of a certificate profile. |
|
Model for the Key Usage extension of a certificate profile. |
|
Model for the Extended Key Usage extension of a certificate profile. |
|
Model for the extensions of a certificate request. |
|
Model for the validity period of a certificate profile. |
|
Base model for each nesting level of certificate profiles. |
|
Model for the subject DN of a certificate profile, with profile constraints. |
|
Model for the SAN extension of a certificate profile, with profile constraints. |
|
Model for the CRL Distribution Points extension of a certificate profile, with profile constraints. |
|
Model for the extensions of a certificate profile, with profile constraints. |
|
Model for a certificate profile. |
|
Model for a certificate request. |
|
Constraints set in the profile that are inherited by deeper nesting levels. |
|
Class to verify certificate requests against JSON-based profiles. |
Functions¶
|
Build a mapping of all known OID strings from trustpoint_core to their canonical field names. |
Module Contents¶
- exception pki.util.cert_profile.ProfileValidationError[source]¶
Bases:
ExceptionRaised when the request is well-formed but does not match the profile constraints.
- 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]
- class pki.util.cert_profile.ProfileValuePropertyModel(/, **data)[source]¶
Bases:
pydantic.BaseModelModel for a profile value property.
- Parameters:
data (Any)
- class pki.util.cert_profile.SubjectModel(/, **data)[source]¶
Bases:
pydantic.BaseModelModel 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]¶
- class pki.util.cert_profile.BaseExtensionModel(/, **data)[source]¶
Bases:
pydantic.BaseModelBase model for certificate extensions.
- Parameters:
data (Any)
- class pki.util.cert_profile.BasicConstraintsExtensionModel(/, **data)[source]¶
Bases:
BaseExtensionModelModel for the Basic Constraints extension of a certificate profile.
- Parameters:
data (Any)
- class pki.util.cert_profile.SanExtensionModel(/, **data)[source]¶
Bases:
BaseExtensionModel,ProfileValuePropertyModelModel 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]¶
- class pki.util.cert_profile.CRLDistributionPointsExtensionModel(/, **data)[source]¶
Bases:
BaseExtensionModel,ProfileValuePropertyModelModel 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]¶
- class pki.util.cert_profile.KeyUsageExtensionModel(/, **data)[source]¶
Bases:
BaseExtensionModelModel for the Key Usage extension of a certificate profile.
- Parameters:
data (Any)
- class pki.util.cert_profile.ExtendedKeyUsageExtensionModel(/, **data)[source]¶
Bases:
BaseExtensionModelModel for the Extended Key Usage extension of a certificate profile.
- Parameters:
data (Any)
- usages: list[str] | ProfileValuePropertyModel | None = None[source]¶
- class pki.util.cert_profile.ExtensionsModel(/, **data)[source]¶
Bases:
pydantic.BaseModelModel 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.BaseModelModel for the validity period of a certificate profile.
- Parameters:
data (Any)
- class pki.util.cert_profile.CertProfileBaseModel(/, **data)[source]¶
Bases:
pydantic.BaseModelBase model for each nesting level of certificate profiles.
This allows for granular control over allowed fields and constraints at each level.
- Parameters:
data (Any)
- class pki.util.cert_profile.ProfileSubjectModel(/, **data)[source]¶
Bases:
SubjectModel,CertProfileBaseModelModel for the subject DN of a certificate profile, with profile constraints.
- Parameters:
data (Any)
- class pki.util.cert_profile.ProfileSanExtensionModel(/, **data)[source]¶
Bases:
SanExtensionModel,CertProfileBaseModelModel for the SAN extension of a certificate profile, with profile constraints.
- Parameters:
data (Any)
- class pki.util.cert_profile.ProfileCrlDistributionPointsExtensionModel(/, **data)[source]¶
Bases:
CRLDistributionPointsExtensionModel,CertProfileBaseModelModel 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:
CertProfileBaseModelModel 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:
CertProfileBaseModelModel for a certificate profile.
- Parameters:
data (Any)
- subject: ProfileSubjectModel = None[source]¶
- extensions: ProfileExtensionsModel = None[source]¶
- validity: ValidityModel = None[source]¶
- class pki.util.cert_profile.CertRequestModel(/, **data)[source]¶
Bases:
pydantic.BaseModelModel for a certificate request.
- Parameters:
data (Any)
- subject: SubjectModel = None[source]¶
- extensions: ExtensionsModel = None[source]¶
- validity: ValidityModel = None[source]¶
- 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)
- class pki.util.cert_profile.JSONProfileVerifier(profile)[source]¶
Class to verify certificate requests against JSON-based profiles.
- Parameters:
profile (dict[str, Any])
- 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]
- static _is_simple_type(value)[source]¶
Check if the value is a simple type (not a dict, class).
Excludes None, since we check it separately.
List is considered a simple type here (e.g. for SAN dns_names).
- Parameters:
value (Any)
- Return type:
bool
- _handle_request_only_fields(request, profile, profile_config, allow_list=None)[source]¶
Consider the fields that are only in the request, but not in the profile.
Don’t need to do any nested stuff here, since if the key is not in the profile, it will also not constrain sub-keys.
Request fields are deleted in-place if they are not allowed by the profile.
- Parameters:
request (dict[str, Any])
profile (dict[str, Any])
profile_config (InheritedProfileConfig)
allow_list (list[str] | None)
- Return type:
None
- _handle_profile_only_field(profile_value, field, request, profile_config)[source]¶
- Parameters:
profile_value (Any)
field (str)
request (dict[str, Any])
profile_config (InheritedProfileConfig)
- Return type:
None
- _handle_profile_and_req_field(profile_value, field, request, profile_config)[source]¶
- Parameters:
profile_value (Any)
field (str)
request (dict[str, Any])
profile_config (InheritedProfileConfig)
- Return type:
None
- _apply_profile_rules(request, profile, parent_profile_config=None)[source]¶
Apply the actual profile rules to one level of the request dict.
It needs them both request and profile to be in the same structure and hierarchy, e.g. both in the “subject” sub-dict.
- Parameters:
request (dict[str, Any])
profile (dict[str, Any])
parent_profile_config (InheritedProfileConfig | None)
- 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]
- _apply_profile_rules_sample(request, profile, parent_profile_config=None)[source]¶
Apply the actual profile rules to one level of the request dict.
It needs them both request and profile to be in the same structure and hierarchy, e.g. both in the “subject” sub-dict.
- Parameters:
request (dict[str, Any])
profile (dict[str, Any])
parent_profile_config (InheritedProfileConfig | None)
- Return type:
dict[str, Any]