Skip to main content

Module signing

Module signing 

Source
Expand description

Minimal HMAC-SHA256 used across the CMS for short signed tokens (view-restriction grants, signed rendition URLs).

The framework’s CSRF module has an hmac_sha256 but it’s pub(crate); rather than pull the hmac + sha2 crates twice, we implement HMAC over the sha2 crate the workspace already depends on. One shared impl so the two call sites can’t drift.

Constants§

GENERATED_KEY_PATH
Where the CMS keeps the key it generates when RCMS_SECRET_KEY is not set, relative to the working directory. Several replicas need either the env var or this file on shared storage, so they sign alike.

Functions§

constant_time_eq
Constant-time comparison of two byte slices — use when checking a supplied MAC against the expected one so timing doesn’t leak how many leading bytes matched.
derived_key
A key for one purpose, derived from secret, so a value signed for one feature never verifies in another.
hmac_sha256_hex
HMAC-SHA256(key, msg) as lowercase hex (64 chars). Callers that want a shorter token truncate the result (a prefix of a hex HMAC is itself a valid MAC at reduced bit-strength).
secret
The CMS signing secret: set_secret’s key, else RCMS_SECRET_KEY, else a 32-byte key generated once and kept at GENERATED_KEY_PATH, so every signed feature works without configuration.
set_secret
Set the CMS signing secret. Call once at startup, before anything is served; the key must be stable across restarts. Sourced from the RCMS_SECRET_KEY env var, then GENERATED_KEY_PATH, when this isn’t called.