Secure storage

A secret the operating system protects, as opposed to one a file protects. Registered on macOS, Windows and Linux under keychain, so a page can call it.

await window.crust.invoke("keychain", "set", {
	service: "land.jyz.notes",
	account: "sync-token",
	secret: "…",
});

const { found, secret } = await window.crust.invoke("keychain", "get", {
	service: "land.jyz.notes",
	account: "sync-token",
});

stronghold is the other half of this story: one AES-256-GCM file under a password the app supplies. That protects a file, and a lost password loses the data — a leaked one leaks it. A keychain entry is unlocked by the login session, has no app-held password to lose, and appears in Keychain Access or Credential Manager, where a user can revoke it. Reach for keychain when the OS owns the machine, and stronghold when the secret must travel with a data file.

Upgrading stronghold: its vault moved from the machine-wide ~/Library/Application Support/crust/stronghold.json to one file per app under that app's data directory. The legacy shared file is not migrated because its entries carry no app identity, so they cannot be attributed to one app without preserving the leak. Any secret stored before this version must be set again. When the first launch creates a fresh per-app vault while the legacy file still exists, crust writes one warn line naming both paths.

Commands

commandargumentsanswer
setservice, account, secret{ ok: true, stored: true }
getservice, account{ ok: true, found: true, secret } or { ok: true, found: false }
deleteservice, account{ ok: true, deleted: boolean }
listservice{ ok: true, accounts: string[] }

The list answer above is what a platform that binds enumeration returns. macOS binds SecItemCopyMatching and Windows binds CredEnumerateW, so list works on both. Linux binds no enumerator, so list refuses with not-implemented naming secret_service_search_sync; set, get and delete work on all three platforms.

A missing credential is { found: false }, never an error. "You have not stored this" is a normal answer, and a refusal a caller must catch would make a first launch look broken.

delete answers deleted: false when nothing was stored, which is the same success: the entry the caller named is gone. An empty secret is a real secret, so only a non-string is refused.

Both service and account must be non-empty and may not contain a NUL — a NUL would truncate the name inside the C string the OS is handed, which is how two credentials could collapse onto one entry. On Windows neither may contain a backslash either: CredWriteW keys a generic credential on one service\account target, so ("a", "b\c") and ("a\b", "c") would otherwise be the same entry. A secret may be empty but may not contain a NUL on any platform — libsecret takes a C string on Linux, so a NUL-bearing secret would come back as only its prefix there. Refuse it uniformly.

Ad-hoc builds cannot use the keychain

crust build ad-hoc signs a macOS app; that signature carries no application-identifier entitlement, so the Keychain driver refuses the write. keychain.set then answers { ok: false, code: "handler-error", message: … } naming the OS refusal, and nothing is stored. A later keychain.get answers { found: false } — do not read that as "nothing stored yet". Check the answer of set: found: false after a refused write means the credential store is unavailable, not that a first launch simply has no entry.

There is no framework-level plaintext fallback. crust never writes a 0600 file and calls it a keychain. If a secret must work in an ad-hoc build, stronghold is the right tool — an AES-256-GCM file under a password the app supplies, which is a different contract from an OS-managed credential. To use the macOS keychain, ship a bundle signed with a Developer ID and the entitlement. Windows and Linux have no application-identifier entitlement; both work from an ad-hoc build.

What each platform uses

Failure codes

codewhen
bad-requestservice or account empty or NUL-bearing, a backslash in either on Windows, a NUL in secret, or a non-string secret
not-implementedno adapter on this platform, or list on Linux; requires names what is missing
handler-errorthe OS refused the read, write or delete — a locked keychain, a denied prompt, or Linux's missing libsecret/provider

On macOS and Windows a secret is read into a caller-sized buffer and re-read at its exact length when the first buffer was too small; if it keeps growing across three reads the command refuses rather than decoding a clamped prefix. Linux uses a fixed 64 KiB static buffer in the C shim and refuses a larger secret with handler-error, and a NUL-bearing secret is refused on every platform; no platform silently truncates a credential.