est.views¶
Views for EST (Enrollment over Secure Transport) handling authentication and certificate issuance.
Attributes¶
Exceptions¶
Exception raised for username and password authentication failures. |
Classes¶
Custom HttpResponse that logs and prints error messages automatically. |
|
Protocol defining a dispatch method for handling HTTP requests. |
|
Encapsulates the details extracted from a CSR. |
|
Checks for HTTP Basic Authentication before processing the request. |
|
Mixin for processing HTTP requests for EST endpoints. |
|
Mixin to extract the requested domain. |
|
Mixin to extract and validate the certificate template from request parameters. |
|
Mixin to handle serialization and deserialization of PKCS#10 certificate signing requests. |
|
Extract the serial number from an X.509 CSR and retrieve or create a DeviceModel instance. |
|
Mixin to handle issuing credentials based on a given certificate template input. |
|
A mixin that provides onboarding validation logic for issuing credentials. |
|
Handles simple EST (Enrollment over Secure Transport) enrollment requests. |
|
Handles simple EST (Enrollment over Secure Transport) reenrollment requests. |
|
View to handle the EST /cacerts endpoint. |
|
View to handle the EST /csrattrs endpoint. |
Module Contents¶
- exception est.views.UsernamePasswordAuthenticationError[source]¶
Bases:
ExceptionException raised for username and password authentication failures.
- class est.views.LoggedHttpResponse(content=b'', status=None, *args, **kwargs)[source]¶
Bases:
django.http.HttpResponse,trustpoint.logger.LoggerMixinCustom HttpResponse that logs and prints error messages automatically.
- Parameters:
content (str | bytes)
status (int | None)
args (Any)
kwargs (Any)
- class est.views.Dispatchable[source]¶
Bases:
ProtocolProtocol defining a dispatch method for handling HTTP requests.
- class est.views.CredentialRequest[source]¶
Encapsulates the details extracted from a CSR.
- class est.views.EstAuthenticationMixin[source]¶
Bases:
trustpoint.logger.LoggerMixinChecks for HTTP Basic Authentication before processing the request.
- static authenticate_username_password(request)[source]¶
Authenticate a user using HTTP Basic credentials and return associated DeviceModel.
- Parameters:
request (django.http.HttpRequest) â Django HttpRequest containing the headers.
- Returns:
Authenticated DeviceModel instance.
- Raises:
UsernamePasswordAuthenticationError â if authentication fails.
- Return type:
- authenticate_domain_credential(request)[source]¶
Authenticate client using a Domain Credential TLS cert (Mutual TLS), return the associated DeviceModel.
- Parameters:
request (django.http.HttpRequest)
- Return type:
- authenticate_reenrollment_application_credential(request, csr)[source]¶
Authenticate client using an Application Credential. This is only allowed for reenrolling.
Only authenticates if subject and SAN in both client cert and CSR match the existing issued credential.
- Parameters:
request (django.http.HttpRequest)
csr (cryptography.x509.CertificateSigningRequest)
- Return type:
- authenticate_request(request, domain, cert_template_str, csr=None)[source]¶
Authenticate the request and return a DeviceModel if authentication succeeds.
- Parameters:
request (django.http.HttpRequest)
domain (pki.models.domain.DomainModel)
cert_template_str (str)
csr (cryptography.x509.CertificateSigningRequest | None)
- Return type:
tuple[devices.models.DeviceModel | None, LoggedHttpResponse | None]
- _authenticate_domain_credential_request(request, domain)[source]¶
Authenticate requests for âdomaincredentialâ certificates and return the associated DeviceModel.
- Parameters:
request (django.http.HttpRequest)
domain (pki.models.domain.DomainModel)
- Return type:
tuple[devices.models.DeviceModel | None, LoggedHttpResponse | None]
- _authenticate_application_certificate_request(request, domain, csr)[source]¶
Authenticate requests for application certificate templates and return the associated DeviceModel.
- Parameters:
request (django.http.HttpRequest)
domain (pki.models.domain.DomainModel)
csr (cryptography.x509.CertificateSigningRequest | None)
- Return type:
tuple[devices.models.DeviceModel | None, LoggedHttpResponse | None]
- class est.views.EstHttpMixin[source]¶
Mixin for processing HTTP requests for EST endpoints.
- This mixin reads the raw message from the request, verifies that the payload:
Does not exceed the maximum allowed size.
Contains the expected content type.
Is optionally decoded from base64 if required.
Upon successful validation, the mixin delegates the request handling to the parent dispatch method.
- process_http_request(request)[source]¶
Process the incoming HTTP request for EST enrollment.
- The method performs the following checks in order:
Reads the raw request message and ensures it does not exceed the maximum allowed size.
Verifies that the request contains a Content-Type header matching the expected type.
If the request includes a âContent-Transfer-Encodingâ header set to âbase64â, decodes the raw message from base64.
Delegates the remaining request processing to the parent classâs dispatch method.
- Parameters:
request (django.http.HttpRequest) â The incoming HttpRequest.
- Returns:
An LoggedHttpResponse, either an error response or the result of the parent dispatch.
- Return type:
tuple[bytes | None, LoggedHttpResponse | None]
- class est.views.EstRequestedDomainExtractorMixin[source]¶
Mixin to extract the requested domain.
- This mixin sets:
self.requested_domain: The DomainModel instance based on the âdomainâ parameter.
self.issuing_ca_certificate: The CA certificate for the requested domain.
self.signature_suite: The signature suite derived from the CA certificate.
- requested_domain: pki.models.domain.DomainModel | None[source]¶
- extract_requested_domain(domain_name)[source]¶
Extracts the requested domain and sets the relevant certificate and signature suite.
- Returns:
The response from the parent classâs dispatch method.
- Parameters:
domain_name (str)
- Return type:
tuple[pki.models.domain.DomainModel | None, LoggedHttpResponse | None]
- class est.views.EstRequestedCertTemplateExtractorMixin[source]¶
Mixin to extract and validate the certificate template from request parameters.
- allowed_cert_templates: ClassVar[list[str]] = ['tls-server', 'tls-client', 'opc-ua-client', 'opc-ua-server', 'domaincredential'][source]¶
- extract_cert_template(cert_template)[source]¶
Extract and validate the âcerttemplateâ parameter, then delegate request processing.
- Parameters:
cert_template (str)
- Return type:
tuple[str | None, LoggedHttpResponse | None]
- class est.views.EstPkiMessageSerializerMixin[source]¶
Bases:
trustpoint.logger.LoggerMixinMixin to handle serialization and deserialization of PKCS#10 certificate signing requests.
- extract_details_from_csr(csr, request_format)[source]¶
Loads the CSR (x509.CertificateSigningRequest) and extracts subject and SAN.
- Parameters:
csr (cryptography.x509.CertificateSigningRequest)
request_format (str)
- Return type:
- _extract_serial_number(subject_attributes)[source]¶
- Parameters:
subject_attributes (list[cryptography.x509.NameAttribute[Any]])
- Return type:
str | None
- _extract_common_name(subject_attributes)[source]¶
Extracts the common name from the subject attributes.
- Parameters:
subject_attributes (list[cryptography.x509.NameAttribute[Any]])
- Return type:
str
- _extract_san(csr)[source]¶
Extract SAN (Subject Alternative Name) extension values.
- Parameters:
csr (cryptography.x509.CertificateSigningRequest)
- Return type:
tuple[list[str], list[ipaddress.IPv4Address], list[ipaddress.IPv6Address], list[str]]
- deserialize_pki_message(data)[source]¶
Deserializes a DER-encoded PKCS#10 certificate signing request.
- Parameters:
data (bytes) â DER-encoded PKCS#10 request bytes.
requested_cert_template â Certificate template string.
- Returns:
An CredentialRequest object.
- Raises:
ValueError â If deserialization fails.
- Return type:
tuple[CredentialRequest | None, cryptography.x509.CertificateSigningRequest | None, LoggedHttpResponse | None]
- class est.views.DeviceHandlerMixin[source]¶
Extract the serial number from an X.509 CSR and retrieve or create a DeviceModel instance.
This mixin assumes the CSR is already deserialized into a cryptography.x509.CertificateSigningRequest object.
- create_device_idevid(credential_request, domain, cert_template)[source]¶
Retrieves a DeviceModel instance using the serial number extracted from the provided CSR.
If a device with that serial number does not exist, a new one is created.
- Parameters:
csr â A cryptography.x509.CertificateSigningRequest instance.
domain (pki.models.domain.DomainModel) â The DomainModel instance associated with this device.
cert_template (str) â The X509 Certificate Template to use for this device.
credential_request (CredentialRequest)
- Returns:
A DeviceModel instance corresponding to the extracted serial number.
- Return type:
- class est.views.CredentialIssuanceMixin[source]¶
Mixin to handle issuing credentials based on a given certificate template input.
- Required inputs for the issue_credential method:
- cert_template_str: A string indicating the certificate template type.
Supported values: âtls-serverâ, âtls-clientâ, or âdomaincredentialâ.
cert_template_class: The class responsible for issuing the credential.
device: The device instance for which the credential is issued.
domain: The domain instance used during credential issuance.
csr: The certificate signing request (used only for âdomaincredentialâ).
- Additional parameters are used by the specific issuance methods:
common_name: Used for âtls-clientâ and âtls-serverâ credentials.
validity_days: Used for âtls-clientâ and âtls-serverâ credentials.
ipv4_addresses, ipv6_addresses, domain_names: Used for âtls-serverâ credentials.
- _validate_subject_attributes(subject_attributes, allowed_subject_oids)[source]¶
Helper method to validate subject attributes.
- Parameters:
subject_attributes (list[cryptography.x509.NameAttribute[Any]])
allowed_subject_oids (set[pyasn1.type.univ.ObjectIdentifier])
- Return type:
None
- issue_credential(cert_template_str, device, domain, credential_request)[source]¶
Issues a credential based on the specified certificate template and CSR.
This method handles the credential issuance process, which includes extracting the necessary details from the CSR and domain, and then issuing the requested certificate. The method supports both new certificate issuance and reenrollment.
- Parameters:
cert_template_str (str) â The certificate template string indicating the type of certificate to issue (e.g., âtls-serverâ, âtls-clientâ, etc.).
device (DeviceModel) â The device for which the certificate is being issued.
domain (DomainModel) â The domain associated with the certificate issuance.
credential_request (CredentialRequest) â A CredentialRequest object containing processed information about the CSR
- Returns:
The issued credential model that contains the issued certificate and related data.
- Return type:
- Raises:
ValueError â If the certificate template is invalid or any other error occurs during issuance.
- _issue_simpleenroll(device, domain, requested_cert_template_str, credential_request)[source]¶
Handles the credential issuance and raises an error if issuance fails.
- Parameters:
device (devices.models.DeviceModel)
domain (pki.models.domain.DomainModel)
requested_cert_template_str (str)
credential_request (CredentialRequest)
- Return type:
- _issue_based_on_template(cert_template_str, credential_request, device, domain)[source]¶
Issues the credential based on the selected template.
- Parameters:
cert_template_str (str)
credential_request (CredentialRequest)
device (devices.models.DeviceModel)
domain (pki.models.domain.DomainModel)
- Return type:
- class est.views.OnboardingMixin(content=b'', status=None, *args, **kwargs)[source]¶
Bases:
LoggedHttpResponseA mixin that provides onboarding validation logic for issuing credentials.
- Parameters:
content (str | bytes)
status (int | None)
args (Any)
kwargs (Any)
- _validate_onboarding(device, credential_request, requested_cert_template_str)[source]¶
Validates if the deviceâs onboarding status is appropriate for credential issuance.
- Parameters:
device (devices.models.DeviceModel)
credential_request (CredentialRequest)
requested_cert_template_str (str)
- Return type:
LoggedHttpResponse | None
- class est.views.EstSimpleEnrollmentView(content=b'', status=None, *args, **kwargs)[source]¶
Bases:
EstAuthenticationMixin,EstHttpMixin,EstRequestedDomainExtractorMixin,EstRequestedCertTemplateExtractorMixin,EstPkiMessageSerializerMixin,DeviceHandlerMixin,CredentialIssuanceMixin,OnboardingMixin,trustpoint.logger.LoggerMixin,django.views.ViewHandles simple EST (Enrollment over Secure Transport) enrollment requests.
This view processes certificate signing requests (CSRs), authenticates the client using either Mutual TLS or username/password, validates the device, and issues the requested certificate based on the certificate template specified in the request.
- Parameters:
content (str | bytes)
status (int | None)
args (Any)
kwargs (Any)
- class est.views.EstSimpleReEnrollmentView(content=b'', status=None, *args, **kwargs)[source]¶
Bases:
EstAuthenticationMixin,EstHttpMixin,EstRequestedDomainExtractorMixin,EstRequestedCertTemplateExtractorMixin,EstPkiMessageSerializerMixin,DeviceHandlerMixin,CredentialIssuanceMixin,OnboardingMixin,trustpoint.logger.LoggerMixin,django.views.ViewHandles simple EST (Enrollment over Secure Transport) reenrollment requests.
This view processes certificate signing requests (CSRs), authenticates the client using either Mutual TLS or username/password, validates the device, and issues the requested certificate based on the certificate template specified in the request.
- Parameters:
content (str | bytes)
status (int | None)
args (Any)
kwargs (Any)
- class est.views.EstCACertsView(**kwargs)[source]¶
Bases:
EstAuthenticationMixin,EstRequestedDomainExtractorMixin,django.views.View,trustpoint.logger.LoggerMixinView to handle the EST /cacerts endpoint.
Returns the CA certificate chain in a (simplified) PKCS#7 MIME format.
URL pattern should supply the âdomainâ parameter (e.g., /cacerts/<domain>/)
- class est.views.EstCsrAttrsView(**kwargs)[source]¶
Bases:
django.views.View,trustpoint.logger.LoggerMixinView to handle the EST /csrattrs endpoint.
This endpoint is not supported and returns 404 Not Found.