Expand description
Local API token: generation, reading, and atomic 0600 writes.
Token format: <issued-at unix seconds>.<64 lowercase hex chars>. The
issue timestamp is embedded in the token itself — file mtime is NOT
trusted, because copies, backup restores, and sync tools all rewrite it.
The daemon owns generation and rotation; local clients (beam CLI) only
read the file and send the token verbatim as an Authorization: Bearer
credential. Validity is an exact string match against daemon state, so a
tampered timestamp never authenticates.
Constants§
- SIG_
HEADER - Header carrying the hex HMAC-SHA256 signature.
- SIG_
NONCE_ HEADER - Header carrying the per-request nonce.
- SIG_
TIMESTAMP_ HEADER - Header carrying the signature timestamp (unix seconds).
- SIG_
WINDOW_ SECS - Maximum accepted clock skew between signer and verifier, in seconds.
Functions§
- generate_
api_ token - Generate a new local API token issued at the current time.
- generate_
api_ token_ at - Generate a token for an explicit issue time (tests, clock control).
- generate_
sig_ nonce - Generate a random per-request signature nonce.
- now_
unix_ secs - Current wall-clock time as unix seconds.
- parse_
api_ token - Parse a token into (issued_at_unix, secret). Returns
Nonefor malformed tokens — including legacy plain-hex tokens without a timestamp, which the daemon then treats as stale and rotates out. - read_
api_ token - Read the current token from disk. Returns
Nonewhen the file is missing, unreadable, or empty. - sign_
request - Compute the hex HMAC-SHA256 signature for one request.
- signature_
payload - Canonical string that gets HMAC-signed for one request.
path_queryis the request path with query string (e.g./sessions/abc/input?x=1). - verify_
request_ signature - Constant-time verification of a presented hex signature.
- write_
api_ token - Atomically write the token (tmp + rename) with 0600 permissions on Unix.