DeviceAuthenticator

Verifies device-authenticated requests (docs/server-authentication.md).

A request is accepted if, in this order: it carries authentication; the device has a registered key (only registration itself names its key in the body); its timestamp lies within WINDOW of clock's time, bounds included; the signature over the canonical request verifies with that key; and its nonce was not accepted for the device before. The nonce is claimed last, in one atomic step of nonces, so of concurrent identical requests at most one is accepted. A claimed nonce stays claimed even if the operation fails afterwards; clients use a fresh nonce for every attempt.

Nonces are kept per device until their timestamp leaves the window: such a request is rejected by the window check anyway.

Constructors

Link copied to clipboard
constructor(devices: DeviceRegistrationRepository, nonces: AuthenticationNonceRepository, clock: Clock = Clock.System)

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard
suspend fun authenticate(address: DeviceAddress, endpoint: ProtectedEndpoint, body: ByteArray, authentication: RequestAuthentication?): AuthenticatedDevice

Authenticates a request of the registered device address for endpoint whose HTTP body was exactly body. Throws DeviceAuthenticationException.