Source code for pki.forms.certificates


"""Django forms for certificate download and management."""


from __future__ import annotations

from django import forms
from django.utils.translation import gettext_lazy as _


[docs] class CertificateDownloadForm(forms.Form): """Form 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. Attributes: cert_file_container (ChoiceField): 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. cert_chain_incl (ChoiceField): Specifies whether to include certificate chains. - `cert_only`: Only the selected certificates. - `chain_incl`: Include certificate chains. cert_file_format (ChoiceField): 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). """
[docs] cert_file_container = forms.ChoiceField( label=_('Select Certificate Container Type'), choices=[ ('single_file', _('Single File')), ('zip', _('Separate Certificate Files (as .zip file)')), ('tar_gz', _('Separate Certificate Files (as .tar.gz file)')), ], initial='single_file', required=True, )
[docs] cert_chain_incl = forms.ChoiceField( label=_('Select Included Certificates'), choices=[('cert_only', _('Selected certificates only')), ('chain_incl', _('Include certificate chains'))], initial='selected_cert_only', required=True, )
[docs] cert_file_format = forms.ChoiceField( label=_('Select Certificate File Format'), choices=[ ('pem', _('PEM (.pem, .crt, .ca-bundle)')), ('der', _('DER (.der, .cer)')), ('pkcs7_pem', _('PKCS#7 (PEM) (.p7b, .p7c, .keystore)')), ('pkcs7_der', _('PKCS#7 (DER) (.p7b, .p7c, .keystore)')), ], initial='pem', required=True, )