ExSwan.Validator (exswan v0.1.0)

View Source

Validation functions for WebAuthn data structures and security requirements.

This module provides comprehensive validation for WebAuthn operations, ensuring compliance with the WebAuthn specification and security best practices.

Summary

Functions

Validates a challenge value meets WebAuthn requirements.

Validates attestation creation options structure.

Validates credential ID format and length.

Validates origin against allowed origins list.

Validates public key credential parameters list.

Validates assertion request options structure.

Validates relying party identifier format.

Validates timeout value is within acceptable range.

Validates user handle requirements.

Functions

validate_challenge(challenge)

@spec validate_challenge(binary()) :: :ok | {:error, atom()}

Validates a challenge value meets WebAuthn requirements.

Challenges must be at least 16 bytes (128 bits) of random data.

Examples

iex> ExSwan.Validator.validate_challenge(<<1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16>>)
:ok

iex> ExSwan.Validator.validate_challenge(<<1, 2, 3>>)
{:error, :challenge_too_short}

validate_creation_options(options)

@spec validate_creation_options(ExSwan.Attestation.CreationOptions.t()) ::
  :ok | {:error, atom()}

Validates attestation creation options structure.

validate_credential_id(credential_id)

@spec validate_credential_id(binary()) :: :ok | {:error, atom()}

Validates credential ID format and length.

validate_origin(origin, allowed_origins)

@spec validate_origin(String.t(), [String.t()]) :: :ok | {:error, atom()}

Validates origin against allowed origins list.

validate_pub_key_cred_params(params)

@spec validate_pub_key_cred_params([ExSwan.Credential.Parameters.t()]) ::
  :ok | {:error, atom()}

Validates public key credential parameters list.

validate_request_options(options)

@spec validate_request_options(ExSwan.Assertion.RequestOptions.t()) ::
  :ok | {:error, atom()}

Validates assertion request options structure.

validate_rp_id(rp_id)

@spec validate_rp_id(String.t()) :: :ok | {:error, atom()}

Validates relying party identifier format.

The RP ID must be a valid domain name.

validate_timeout(timeout)

@spec validate_timeout(pos_integer() | nil) :: :ok | {:error, atom()}

Validates timeout value is within acceptable range.

validate_user_handle(user_handle)

@spec validate_user_handle(binary()) :: :ok | {:error, atom()}

Validates user handle requirements.

User handles should be unique, random identifiers of at most 64 bytes.