Skip to main content

Module api_keys

Module api_keys 

Source
Expand description

Hashed product API-key store (G-039) for the operator server.

Mirrors the rusqlite pattern in crate::stel::ledger_store: enum ApiKeyStore { Sqlite(..), Disabled }, idempotent migrate(), an in-memory constructor for tests, and a poisoned-mutex-recovering lock so a prior panic degrades instead of crashing the serve loop (FR-011 discipline).

§Security model (GATE-2 / FR-004 / SC-003)

  • The raw secret is shown exactly once, at ApiKeyStore::mint time, and is never persisted or returned again. Only a SHA-256 hash of the raw secret is stored.
  • ApiKeyStore::verify hashes the presented secret and compares (in constant time over the hex digest) against the stored hash of every active (non-revoked) key. A revoked key never verifies.
  • ApiKeyStore::list returns label / fingerprint / timestamps only — never the raw secret and never the full hash.

The raw secret is a high-entropy 256-bit random bearer token rendered as sf_<64 hex>. Because it is random (not a human-chosen password) a plain SHA-256 is appropriate; a slow password-KDF would add a dependency for no security gain on a 256-bit random token (see research.md D3/D4).

Structs§

ApiKeyRecord
A persisted API-key record (never carries the raw secret).
MintedKey
The outcome of a successful ApiKeyStore::mint: the record plus the raw secret shown exactly once.
SqliteApiKeyStore
SQLite-backed implementation.

Enums§

ApiKeyStore
Hashed API-key store. Disabled when the DB could not open.