pki.formsΒΆ
Module for managing PKI-related forms in the Trustpoint application.
ClassesΒΆ
Form for selecting the method to add an DevID Onboarding Pattern. |
|
Form to create a new DevIdRegistration. |
|
Form for adding a new truststore. |
|
Form for downloading truststores in various formats. |
|
Form for downloading certificates in various formats. |
|
Form for selecting the method to add an Issuing Certificate Authority (CA). |
|
Form for selecting the file type when importing an Issuing CA. |
|
Form for importing an Issuing CA using a PKCS#12 file. |
|
Form for importing an Issuing CA using separate files. |
|
Form for importing an DevOwnerID using separate files. |
Module ContentsΒΆ
- class pki.forms.DevIdAddMethodSelectForm(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.FormForm for selecting the method to add an DevID Onboarding Pattern.
- class pki.forms.DevIdRegistrationForm[source]ΒΆ
Bases:
django.forms.ModelForm[pki.models.DevIdRegistration]Form to create a new DevIdRegistration.
- class pki.forms.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.FormForm 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.
- 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]ΒΆ
- Parameters:
unique_name (str)
intended_usage (pki.models.truststore.TruststoreModel.IntendedUsage)
certificates (list[cryptography.x509.Certificate])
- Return type:
- class pki.forms.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.FormForm 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
- class pki.forms.CertificateDownloadForm(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.FormForm for downloading certificates in various formats.
This form allows users to customize the download options for certificates, including the container type, inclusion of certificate chains, and the file format. It provides flexibility to download certificates in the desired structure and format for different use cases.
- cert_file_container[source]ΒΆ
Specifies the container type for the downloaded certificates. - single_file: All certificates 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 certificates. - 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
- class pki.forms.IssuingCaAddMethodSelectForm(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.FormForm for selecting the method to add an Issuing Certificate Authority (CA).
This form provides options to choose the method for adding a new Issuing CA. Users can select between importing from a file, generating a key pair and requesting an Issuing CA certificate, or configuring a remote Issuing CA.
- class pki.forms.IssuingCaFileTypeSelectForm(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.FormForm for selecting the file type when importing an Issuing CA.
This form allows users to choose the type of file to use for importing an Issuing Certificate Authority (CA). Supported formats include PKCS#12 and other common certificate formats such as PEM, PKCS#1, PKCS#7, and PKCS#8.
- class pki.forms.IssuingCaAddFileImportPkcs12Form(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:
trustpoint.logger.LoggerMixin,django.forms.FormForm for importing an Issuing CA using a PKCS#12 file.
This form allows the user to upload a PKCS#12 file containing the private key and certificate chain, along with an optional password. It validates the uploaded file and its contents and ensures the unique name is not already used by another Issuing CA.
- clean()[source]ΒΆ
Cleans and validates the entire form.
This method performs additional validation on the cleaned data to ensure all required fields are valid and consistent. It checks the uploaded PKCS#12 file and its password (if provided) and validates that the unique name does not conflict with existing entries. Any issues during validation raise appropriate errors.
- Raises:
ValidationError β If the data is invalid, such as when the unique name
is already taken or the PKCS#12 file cannot be read or parsed. β
- Return type:
None
- class pki.forms.IssuingCaAddFileImportSeparateFilesForm(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:
trustpoint.logger.LoggerMixin,django.forms.FormForm for importing an Issuing CA using separate files.
This form allows the user to upload a private key file, its password (optional), an Issuing CA certificate file, and an optional certificate chain. The form validates the uploaded files, ensuring they are correctly formatted, within size limits, and not already associated with an existing Issuing CA.
- ca_certificate[source]ΒΆ
The Issuing CA certificate file (.cer, .der, .pem, .p7b, .p7c).
- Type:
FileField
- clean_private_key_file()[source]ΒΆ
Validates and parses the uploaded private key file.
This method checks if the private key file is provided, ensures it meets size constraints, and validates its contents. If a password is provided, it is used to decrypt the private key. Raises validation errors for missing, oversized, or corrupted private key files.
- Returns:
A serializer containing the parsed private key.
- Return type:
PrivateKeySerializer
- Raises:
ValidationError β If the private key file is missing, too large, or
corrupted, or if the password is invalid or incompatible. β
- clean_ca_certificate()[source]ΒΆ
Validates and parses the uploaded Issuing CA certificate file.
This method ensures the provided Issuing CA certificate file is valid and not already associated with an existing Issuing CA in the database. If the file is too large, corrupted, or already in use, a validation error is raised.
- Returns:
A serializer containing the parsed certificate.
- Return type:
CertificateSerializer
- Raises:
ValidationError β If the file is missing, too large, corrupted, or already
associated with an existing Issuing CA. β
- clean_ca_certificate_chain()[source]ΒΆ
Validates and parses the uploaded Issuing CA certificate chain file.
This method checks if the optional certificate chain file is provided. If present, it validates and attempts to parse the file into a collection of certificates. Raises a validation error if parsing fails or the file appears corrupted.
- Returns:
A serializer containing the parsed certificate chain if provided.
- Return type:
CertificateCollectionSerializer
- Raises:
ValidationError β If the certificate chain cannot be parsed.
- clean()[source]ΒΆ
Cleans and validates the form data.
This method performs additional validation on the provided data, such as ensuring the unique name, private key file, and certificates are valid. It also initializes and saves the issuing CA configuration if all checks pass.
- Raises:
ValidationError β If the form data is invalid or there is an error during processing.
- Return type:
None
- class pki.forms.OwnerCredentialFileImportForm(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:
trustpoint.logger.LoggerMixin,django.forms.FormForm for importing an DevOwnerID using separate files.
This form allows the user to upload a private key file, its password (optional), an DevOwnerID certificate file, and an optional certificate chain. The form validates the uploaded files, ensuring they are correctly formatted and within size limits.
- owner_certificateΒΆ
The DevOwnerID certificate file (.cer, .der, .pem, .p7b, .p7c).
- Type:
FileField
- owner_certificate_chainΒΆ
An optional certificate chain file.
- Type:
FileField
- clean_private_key_file()[source]ΒΆ
Validates and parses the uploaded private key file.
This method checks if the private key file is provided, ensures it meets size constraints, and validates its contents. If a password is provided, it is used to decrypt the private key. Raises validation errors for missing, oversized, or corrupted private key files.
- Returns:
A serializer containing the parsed private key.
- Return type:
PrivateKeySerializer
- Raises:
ValidationError β If the private key file is missing, too large, or
corrupted, or if the password is invalid or incompatible. β
- clean_certificate()[source]ΒΆ
Validates and parses the uploaded certificate file.
This method ensures the provided certificate file is valid and not already associated with an existing DevOwnerID in the database. If the file is too large, corrupted, or already in use, a validation error is raised.
- Returns:
A serializer containing the parsed certificate.
- Return type:
CertificateSerializer
- Raises:
ValidationError β If the file is missing, too large, corrupted, or already
associated with an existing Issuing CA. β
- clean_certificate_chain()[source]ΒΆ
Validates and parses the uploaded certificate chain file.
This method checks if the optional certificate chain file is provided. If present, it validates and attempts to parse the file into a collection of certificates. Raises a validation error if parsing fails or the file appears corrupted.
- Returns:
A serializer containing the parsed certificate chain if provided.
- Return type:
CertificateCollectionSerializer
- Raises:
ValidationError β If the certificate chain cannot be parsed.
- clean()[source]ΒΆ
Cleans and validates the form data.
This method performs additional validation on the provided data, such as ensuring the unique name, private key file, and certificates are valid. It also initializes and saves the OwnerCredential configuration if all checks pass.
- Raises:
ValidationError β If the form data is invalid or there is an error during processing.
- Return type:
None