request.authentication.cmpΒΆ

Provides the β€˜CmpAuthentication’ class using the Composite pattern for modular CMP authentication.

ClassesΒΆ

CmpAuthenticationBase

Base class for CMP authentication components with common functionality.

CmpSharedSecretAuthentication

Handles CMP authentication using shared secrets with HMAC-based protection.

CmpSignatureBasedInitializationAuthentication

Handles CMP signature-based authentication for initialization requests using IDevID certificates.

CmpSignatureBasedCertificationAuthentication

Handles CMP signature-based authentication for certification requests using domain credentials.

CmpAuthentication

Composite authenticator specifically for CMP requests, combining various authentication methods.

Module ContentsΒΆ

class request.authentication.cmp.CmpAuthenticationBase[source]ΒΆ

Bases: request.authentication.base.AuthenticationComponent, trustpoint.logger.LoggerMixin

Base class for CMP authentication components with common functionality.

_is_aoki_request(context)[source]ΒΆ

Determine if this is an AOKI request based on domain name and URL path.

Parameters:

context (request.request_context.CmpBaseRequestContext)

Return type:

bool

class request.authentication.cmp.CmpSharedSecretAuthentication[source]ΒΆ

Bases: CmpAuthenticationBase

Handles CMP authentication using shared secrets with HMAC-based protection.

authenticate(context)[source]ΒΆ

Authenticate using CMP shared secret HMAC protection.

Parameters:

context (request.request_context.BaseRequestContext)

Return type:

None

_validate_context(context)[source]ΒΆ

Validate the context for CMP shared secret authentication.

Parameters:

context (request.request_context.CmpBaseRequestContext)

Return type:

bool

_raise_value_error(message)[source]ΒΆ

Raise a ValueError with the given message.

Parameters:

message (str)

Return type:

Never

_extract_sender_kid(context)[source]ΒΆ

Extract sender KID from CMP message header.

Parameters:

context (request.request_context.CmpBaseRequestContext)

Return type:

int

_get_device(sender_kid)[source]ΒΆ

Get device by sender KID.

Parameters:

sender_kid (int)

Return type:

devices.models.DeviceModel

_validate_device_configuration(device, sender_kid)[source]ΒΆ

Validate device has required shared secret configuration.

Parameters:
Return type:

onboarding.models.OnboardingConfigModel | onboarding.models.NoOnboardingConfigModel

_verify_hmac_protection(context, shared_secret)[source]ΒΆ

Verify HMAC-based protection and store shared secret for response.

Parameters:
Return type:

None

_finalize_authentication(context, device, sender_kid)[source]ΒΆ

Finalize authentication by setting device in context and logging success.

Parameters:
Return type:

None

_handle_authentication_error(error)[source]ΒΆ

Handle known authentication errors.

Parameters:

error (Exception)

Return type:

None

_handle_unexpected_error(error)[source]ΒΆ

Handle unexpected errors during authentication.

Parameters:

error (Exception)

Return type:

None

_raise_cmp_error(message)[source]ΒΆ

Raise CMP authentication error.

Parameters:

message (str)

Return type:

Never

static _verify_protection_shared_secret(parsed_message, shared_secret)[source]ΒΆ

Verifies the HMAC-based protection of a CMP message using a shared secret.

Returns a new HMAC object that can be used to sign the response message.

Parameters:
  • parsed_message (pyasn1_modules.rfc4210.PKIMessage)

  • shared_secret (str)

Return type:

cryptography.hazmat.primitives.hmac.HMAC

class request.authentication.cmp.CmpSignatureBasedInitializationAuthentication[source]ΒΆ

Bases: CmpAuthenticationBase

Handles CMP signature-based authentication for initialization requests using IDevID certificates.

authenticate(context)[source]ΒΆ

Authenticate using CMP signature-based protection for initialization requests.

Parameters:

context (request.request_context.BaseRequestContext)

Return type:

None

_authenticate_and_verify_device(context, cmp_signer_cert, intermediate_certs)[source]ΒΆ

Authenticate and verify the device.

Parameters:
Return type:

devices.models.DeviceModel

_process_device_authentication(context, cmp_signer_cert, intermediate_certs)[source]ΒΆ

Process device authentication using certificates.

Parameters:
Return type:

devices.models.DeviceModel

_handle_authentication_error(error)[source]ΒΆ

Handle authentication errors by logging and raising a ValueError.

Parameters:

error (Exception)

Return type:

Never

_validate_context(context)[source]ΒΆ

Validate the context for CMP authentication.

Parameters:

context (request.request_context.CmpCertificateRequestContext)

Return type:

bool

_extract_certificates(context)[source]ΒΆ

Extract and validate certificates from the CMP message.

Parameters:

context (request.request_context.CmpCertificateRequestContext)

Return type:

tuple[cryptography.x509.Certificate, list[cryptography.x509.Certificate]]

_authenticate_device(context, cmp_signer_cert, intermediate_certs)[source]ΒΆ

Authenticate the device using IDevID.

Parameters:
Return type:

devices.models.DeviceModel

_verify_device_configuration(device)[source]ΒΆ

Verify the device’s configuration and protocols.

Parameters:

device (devices.models.DeviceModel)

Return type:

None

_raise_value_error(message)[source]ΒΆ

Helper method to log and raise a ValueError.

Parameters:

message (str)

Return type:

Never

_verify_protection_signature(parsed_message, cmp_signer_cert)[source]ΒΆ

Verifies the message signature of a CMP message using signature-based protection.

Parameters:
  • parsed_message (pyasn1_modules.rfc4210.PKIMessage)

  • cmp_signer_cert (cryptography.x509.Certificate)

Return type:

None

class request.authentication.cmp.CmpSignatureBasedCertificationAuthentication[source]ΒΆ

Bases: request.authentication.base.AuthenticationComponent, trustpoint.logger.LoggerMixin

Handles CMP signature-based authentication for certification requests using domain credentials.

authenticate(context)[source]ΒΆ

Authenticate using CMP signature-based protection for certification requests.

Parameters:

context (request.request_context.BaseRequestContext)

Return type:

None

_should_authenticate(context)[source]ΒΆ

Check if this authentication method should be applied.

Parameters:

context (request.request_context.CmpCertificateRequestContext)

Return type:

bool

_extract_and_validate_certificate(context)[source]ΒΆ

Extract and validate the CMP signer certificate from the message.

Parameters:

context (request.request_context.CmpCertificateRequestContext)

Return type:

cryptography.x509.Certificate

_authenticate_device(context)[source]ΒΆ

Authenticate the device using the CMP signer certificate.

Parameters:

context (request.request_context.CmpCertificateRequestContext)

Return type:

devices.models.DeviceModel

_extract_device_info(cmp_signer_cert)[source]ΒΆ

Extract device information from certificate subject.

Parameters:

cmp_signer_cert (cryptography.x509.Certificate)

Return type:

dict[str, str | int | None]

_lookup_device(device_info)[source]ΒΆ

Look up the device by ID.

Parameters:

device_info (dict[str, str | int | None])

Return type:

devices.models.DeviceModel

_validate_device(device, device_info, cmp_signer_cert)[source]ΒΆ

Validate device properties and certificate.

Parameters:
Return type:

None

_verify_protection_and_finalize(context, cmp_signer_cert, device)[source]ΒΆ

Verify protection signature and finalize authentication.

Parameters:
Return type:

None

_raise_value_error(message)[source]ΒΆ

Helper method to log and raise a ValueError.

Parameters:

message (str)

Return type:

Never

_raise_type_error(message)[source]ΒΆ

Helper method to log and raise a TypeError.

Parameters:

message (str)

Return type:

Never

_verify_protection_signature(parsed_message, cmp_signer_cert)[source]ΒΆ

Verifies the message signature of a CMP message using signature-based protection.

Parameters:
  • parsed_message (pyasn1_modules.rfc4210.PKIMessage)

  • cmp_signer_cert (cryptography.x509.Certificate)

Return type:

None

class request.authentication.cmp.CmpAuthentication[source]ΒΆ

Bases: request.authentication.base.CompositeAuthentication

Composite authenticator specifically for CMP requests, combining various authentication methods.