pki.forms.cert_profilesΒΆ

Django forms for certificate profile configuration.

Module ContentsΒΆ

pki.forms.cert_profiles.check_validity_days_against_security_config(total_days)[source]ΒΆ

Raise ValidationError if total_days exceeds the policy limit.

Parameters:

total_days (float)

Return type:

None

class pki.forms.cert_profiles.CertProfileConfigForm[source]ΒΆ

Bases: trustpoint.logger.LoggerMixin, django.forms.ModelForm[pki.models.cert_profile.CertificateProfileModel]

Form for creating or updating Certificate Profiles.

This form is based on the CertificateProfileModel and allows users to create or update certificate profiles by specifying a unique name and profile JSON configuration.

unique_nameΒΆ

A unique name for the certificate profile.

Type:

CharField

profile_jsonΒΆ

The JSON configuration for the certificate profile.

Type:

JSONField

class Meta[source]ΒΆ

Meta information for the CertProfileConfigForm.

model[source]ΒΆ
fields: ClassVar[list[str]] = ['unique_name', 'profile_json', 'is_default'][source]ΒΆ
clean_unique_name()[source]ΒΆ

Validates the unique name to ensure it is not already in use.

Raises:

ValidationError – If the unique name is already associated with an existing certificate profile.

Return type:

str

clean_profile_json()[source]ΒΆ

Validates the profile JSON to ensure it is a valid certificate profile.

Raises:

ValidationError – If the profile JSON is not a valid certificate profile, or if the configured validity exceeds the security policy limit.

Return type:

str

class pki.forms.cert_profiles.ProfileBasedFormFieldBuilder(profile)[source]ΒΆ

Bases: trustpoint.logger.LoggerMixin

Django form field builder that leverages JSONProfileVerifier.

This builder uses JSONProfileVerifier.get_sample_request() to understand the profile structure, eliminating the need for manual profile parsing logic.

Parameters:

profile (dict[str, Any])

profile[source]ΒΆ

The certificate profile definition

verifier[source]ΒΆ

JSONProfileVerifier instance for profile interpretation

fields[source]ΒΆ

Dictionary of generated Django form fields

SUBJECT_LABELS: ClassVar[dict[str, str]][source]ΒΆ
SAN_LABELS: ClassVar[dict[str, str]][source]ΒΆ
VALIDITY_LABELS: ClassVar[dict[str, str]][source]ΒΆ
profile[source]ΒΆ
verifier[source]ΒΆ
fields: dict[str, django.forms.Field][source]ΒΆ
build_all_fields()[source]ΒΆ

Build all fields from the profile by analyzing a sample request.

This leverages JSONProfileVerifier.get_sample_request() to understand the profile structure, eliminating manual parsing.

Return type:

dict[str, django.forms.Field]

class pki.forms.cert_profiles.CertificateIssuanceForm(profile, *args, **kwargs)[source]ΒΆ

Bases: trustpoint.logger.LoggerMixin, django.forms.Form

Form for certificate issuance based on a certificate profile.

This form dynamically generates fields based on a certificate profile and leverages existing infrastructure for profile interpretation and certificate building:

  • Uses JSONProfileVerifier.get_sample_request() to understand what fields to show

  • Validates user input with JSONProfileVerifier.apply_profile_to_request()

  • Delegates certificate building to JSONCertRequestConverter.from_json()

This eliminates code duplication and ensures consistent profile interpretation across the application (55% code reduction from original implementation).

Parameters:
  • profile (dict[str, Any])

  • args (Any)

  • kwargs (Any)

profile[source]ΒΆ

The certificate profile definition

verifier[source]ΒΆ

JSONProfileVerifier instance for validation

fields[source]ΒΆ

Dynamically generated Django form fields

profile[source]ΒΆ
verifier[source]ΒΆ
fields[source]ΒΆ
get_certificate_builder()[source]ΒΆ

Build a CertificateBuilder from the form data.

This method converts the form data to JSON format and delegates to JSONCertRequestConverter.from_json() to create the CertificateBuilder.

Returns:

CertificateBuilder ready for signing

Return type:

cryptography.x509.base.CertificateBuilder

clean()[source]ΒΆ

Validate the requested certificate validity against the active security policy.

Return type:

dict[str, Any]