Expand description
Secure credential storage module
Provides secure storage for access tokens using:
- Primary: System keyring (Secret Service on Linux, Keychain on macOS)
- Fallback: AES-256-GCM encrypted file when keyring unavailable
The fallback is obfuscation at rest, not a secret: its key sits in a file beside the ciphertext, so anyone who can read one can read the other. It exists so headless systems keep working, and the keyring remains the only place a token is actually protected.
The key used to be derived from the hostname, $USER and a hardcoded salt.
That was no more secret — those are readable by anyone who can read the file
— and it was unstable: renaming the machine, or launching from a context
where $USER is unset, changed the key and made every stored token
undecryptable. load_credentials_file treats a failed decrypt as “no stored
credentials”, so that surfaced as being silently signed out rather than as an
error. The key is now random and persisted, and the old derivation is kept
only to migrate a file written before this change.
TRACES: UR-012 | IR-014
Structs§
- Credential
Store - Credential storage manager
Enums§
- Credential
Error - Error types for credential operations
- Credential
Result - Result of a credential storage operation
Constants§
- CREDENTIALS_
FILENAME 🔒 - KEY_
FILENAME 🔒 - Key file for the encrypted-file fallback, beside the credentials it opens.
- SERVICE_
NAME 🔒
Functions§
- decrypt_
with 🔒 - Decrypt
encryptedwithkey. - encrypt_
with 🔒 - Encrypt
plaintextwithkey, prepending a fresh random nonce. - load_
or_ 🔒create_ key - Load the fallback encryption key, creating it on first use.
- restrict_
to_ 🔒owner - Make a key file owner-readable only. Best effort — a filesystem without Unix permissions is not a reason to fail.