Skip to main content

Module apikeys

Module apikeys 

Source
Expand description

API keys: Authorization: Bearer dm_<random>.

The keys file (mode 0600) holds one line per key: the SHA-256 of the whole key text (dm_...) as 64 lowercase hex digits, the principal id, and optionally the key’s own limit in requests per minute; # starts a comment. The plaintext of a key is never stored by the mesh: create_key writes it to a file of its own (mode 0600) and nowhere else.

Structs§

ApiKeys
The API keys a mesh accepts, by hash.
Principal
A principal: the owner of an API key.

Constants§

KEY_PREFIX
The prefix of every key.

Functions§

create_key
Creates a key for principal: appends its hash line to keys_file (created with mode 0600 if missing; refused if it exists with a wider mode) and writes the key itself, with a final newline, to out (created new, mode 0600; refused if it exists). Nothing is printed.
new_key
A new key: dm_ and 64 hex digits of 256 bits from the operating system’s CSPRNG.