pki.forms.truststores

Django forms for truststore configuration and management.

Module Contents

class pki.forms.truststores.TruststoreAddForm(data=None, files=None, auto_id='id_%s', prefix=None, initial=None, error_class=ErrorList, label_suffix=None, empty_permitted=False, field_order=None, use_required_attribute=None, renderer=None, bound_field_class=None)[source]

Bases: django.forms.Form

Form for adding a new truststore.

This form handles the creation of a truststore by validating the unique name, intended usage, and uploaded file. It ensures the unique name is not already used and validates the truststore file content before saving.

unique_name[source]

A unique name for the truststore.

Type:

CharField

intended_usage[source]

Specifies the intended usage of the truststore.

Type:

ChoiceField

trust_store_file[source]

The PEM or PKCS#7 file to be uploaded.

Type:

FileField

unique_name[source]
intended_usage[source]
trust_store_file[source]
clean_unique_name()[source]

Validates the uniqueness of the truststore name.

Raises:

ValidationError – If the name is already used by an existing truststore.

Return type:

str

clean()[source]

Cleans and validates the form data.

Ensures the uploaded file can be read and validates the unique name and intended usage fields. If validation passes, initializes and saves the truststore.

Raises:
  • ValidationError – If the truststore file cannot be read, the unique name

  • is not unique, or an unexpected error occurs during initialization.

Return type:

None

static save_trust_store(unique_name, intended_usage, certificates)[source]

Save all certificates of a truststore.

Parameters:
Return type:

pki.models.truststore.TruststoreModel

pki.forms.truststores.validate_and_create_ca_chain(certificates, intended_usage)[source]

Validate certificate chain and create keyless CA models for intermediates.

Parameters:
Returns:

The issuing CA (parent of the leaf certificate), or None if not ISSUING_CA_CHAIN

Raises:

ValidationError – If the chain is invalid or incomplete for ISSUING_CA_CHAIN usage

Return type:

pki.models.ca.CaModel | None

class pki.forms.truststores.TruststoreDownloadForm(data=None, files=None, auto_id='id_%s', prefix=None, initial=None, error_class=ErrorList, label_suffix=None, empty_permitted=False, field_order=None, use_required_attribute=None, renderer=None, bound_field_class=None)[source]

Bases: django.forms.Form

Form for downloading truststores in various formats.

This form provides options to customize the download of truststores, allowing users to specify the container type, inclusion of certificate chains, and the file format. It ensures flexibility in exporting truststores for various use cases and environments.

cert_file_container[source]

Specifies the container type for the truststore. - single_file: The entire truststore in a single file. - zip: Certificates as separate files in a .zip archive. - tar_gz: Certificates as separate files in a .tar.gz archive.

Type:

ChoiceField

cert_chain_incl[source]

Specifies whether to include certificate chains. - cert_only: Only the selected certificates. - chain_incl: Include certificate chains.

Type:

ChoiceField

cert_file_format[source]

Specifies the file format for the truststore. - pem: PEM format (.pem, .crt, .ca-bundle). - der: DER format (.der, .cer). - pkcs7_pem: PKCS#7 format in PEM encoding (.p7b, .p7c, .keystore). - pkcs7_der: PKCS#7 format in DER encoding (.p7b, .p7c, .keystore).

Type:

ChoiceField

cert_file_container[source]
cert_chain_incl[source]
cert_file_format[source]