Artifact 51f5b8c2c188dc977ec23b7d97d57800ea2d5f168fff3af77e65470351f0ef68:
- File
docs/design/key-sources.md
— part of check-in
[bcb82b941e]
at
2026-11-23 11:55:36
on branch keysource
— Keep the credential store's key in the Keychain or a key file, not behind a passphrase
A new store gets a random 32-byte master key kept in the login Keychain (macOS, /usr/bin/security run as a child with the command on stdin) or the keyring (secret-tool), else ~/.pic/master.key at 0600. The source is recorded in picu_credential_key.source; a passphrase store keeps working as before. pic auth rekey keychain|file|passphrase reseals every sealed row in one transaction, and a typed passphrase is followed once by the offer to stop asking. --passphrase-fd and PIC_PASSPHRASE_COMMAND (setting passphraseCommand) give a passphrase with no terminal. pic remote opens a keychain or file store with no prompt. Every OS service stays in platform.c behind secret_key, secret_keep and secret_drop. (user: dmestas, size: 2286) [annotate] [blame] [check-ins using]
Where the credential store's key comes from
Status: built 2026-11-23 (owner's choice: options A and C, with E's sources that need no terminal).
Tier: core (cred.c: the recorded source, pic_cred_quiet, pic_cred_rekey, the offer) over the
platform seam (platform.h: secret_key, secret_keep, secret_drop); the host's sources live in
platform.c alone. Clock: os (the security and secret-tool command lines, tmutil). Record:
picu_credential_key.source (keychain, file or passphrase; a raw key's kdf is none), the
setting cred.offer. Default: a new store's random key in the login Keychain (or keyring), else
~/.pic/master.key; a passphrase only when chosen.
The threat model
A copied pic.sqlite, a backup or an exported journal on its own reveals nothing. Malware or a
person acting in the user's unlocked session can read the key, as with the keys other tools keep.
So a passphrase stops being the default: it guarded against the second case at the cost of a prompt
in every process, and against the first case no better than a key kept apart from the database.
Decisions
- The sealing (ChaCha20-Poly1305 under a 32-byte master key, the verifier) is unchanged; only where the master key comes from changes, with no stretching for a raw key.
- The keystore runs as a child process (
/usr/bin/security -i, the command on its stdin;secret-tool store, the secret on its stdin), so the key is never in argv and pic links no framework. A keep is read back before it counts, since a locked Keychain can seem to take one. - The keystore is used only for the store under the account's own home directory; any other
HOMEgets the key file. Tests run under a privateHOME, so a test that forgets the stand-in (PIC_TEST_KEYCHAIN) still cannot reach the real Keychain. - A rekey reseals every sealed row (credentials, remote control's keys and devices) in one transaction; the old source is cleared only after the commit, and a new source that the commit did not take is cleared again. A row that did not open under the old key is left as it was.
- An OS-free build supplies its own
secret_key(andsecret_keepwhen it can keep a key; when it keeps a fixed boot key,secret_keepnames that source and keeps nothing).