Module Challenge.Validator

Challenge validators.

A challenge validator ensures passkey challenges are used only once and within reasonable time limits. This is an in-memory abstraction, if your program crashes or restarts, all challenges become invalid.

In order to bound the amount of memory used by a validator it may arbitrarily drop challenges pending verification, see Validator.max.

Validators

type now_s = unit -> int

The type for an absolute notion of time in seconds. Calling the function must return the current time in seconds relative to an arbitrary epoch.

Warning. The function must be thread-safe.

type 'a t

The type for challenge validators. A value of this type holds the state to ensure unique and expirable challenge validation. Each challenge can have an associated stored payload of type 'a.

val make : ?max:int -> ?challenge_byte_size:int -> ?challenge_validity_s:int -> ?now_s:now_s -> ?crypto_random:Webs_crypto_random.t -> unit -> 'a t

make ~crypto_random () is a challenge validator with:

  • max is the maximum number of pending challenges. See max. Must be positive or Invalid_argument is raised.
  • challenge_byte_size is the number of random bytes in the challenges generated by the validator, defaults to 64. Must be at least 16 or Invalid_argument is raised.
  • challenge_validity_s is the default validity time in s of challenges. It defaults to 300 seconds (5 minutes) as recommended
  • now_s is a function returning the current time. Defaults uses Unix.gettimeofday.
  • crypto_random is a function returning random bytes of cryptographic quality for the challenges. Defaults to Webs_crypto_random.get
val max : 'a t -> int

max v is the maximal number of pending challenges in v. If this number is exceeded on a Challenge.make, an arbitrary existing challenge is dropped from the validator.

val challenge_byte_size : 'a t -> int

challenge_byte_size v is the number of random bytes in challenges generated by v.

val challenge_validity_s : 'a t -> int

challenge_validity_s v is the default challenge validitiy duration of challenges generated by v.

val pending : 'a t -> int

pending v is the number of challenges pending for validation in v.

val invalidate_pending : 'a t -> unit

invalidate_pending v invalidates all challenges pending for validation in v.