Files
mnovak 0eee7632ae [vault] Signing: a key the Android grant makes is standing-granted, a value older cores read; v0.19.1
0.19.0 wrote a new security action, android-key-made, which every older core refuses. The phone app and the
web vault open the same vault with their own pinned core, so a vault in which the grant made a key would stop
opening there. The key's creation is now standing-granted with 'Android grant made <id> for <repo> pipeline
release'; the grant itself is a member older cores ignore.
2026-11-21 09:06:35 +01:00

303 lines
17 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# The `.custos` vault file, format version 1
Version 2 (two factors, the machine store) is in `docs/FACTORS.md`; it reuses this layout.
One file holds one vault. Everything after the header is one XChaCha20-Poly1305 ciphertext.
The header is not secret, but it is authenticated: changing any byte of it makes the body fail to open.
All integers are little-endian. The code is `crates/custos-vault/src/format.rs`.
## Keys
```
master password ──Argon2id(salt, m, t, p)──► KEK (32 bytes) ──unwraps──► vault key (32 random bytes)
│
body = XChaCha20-Poly1305(vault key, body nonce,
JSON, aad = whole header)
```
- The **vault key** is 32 bytes from the OS CSPRNG, made once when the vault is created.
- A **key slot** wraps the vault key. Version 1 has one kind: a password slot (Argon2id → KEK →
XChaCha20-Poly1305). Changing the password writes a new slot (new salt, new nonce) and leaves the vault
key alone. Windows Hello (desktop app) wraps the same vault key outside this file, on the one machine.
- **Nonces** are 24 random bytes, fresh for every slot write and every save. With 192-bit nonces random
generation is safe for any realistic number of saves.
## Layout
```
offset size field
0 6 magic "CUSTOS" (43 55 53 54 4F 53)
6 2 version u16 = 1
8 1 slot count u8, 1..=8
9 … slots repeated `slot count` times, see below
… 24 body nonce
──────── end of header ─────────────────────────────────────────────
… n+16 body ciphertext of n bytes of JSON + 16-byte Poly1305 tag, to end of file
```
Each slot:
```
size field
1 kind 1 = password; other values are skipped by readers that do not know them
2 length u16, bytes of payload that follow
len payload
```
Password slot payload (117 bytes):
```
size field
1 kdf 1 = Argon2id, version 0x13
4 m_cost u32, memory in KiB
4 t_cost u32, iterations
4 p_cost u32, lanes
32 salt
24 wrap nonce
48 wrapped key 32-byte vault key encrypted with the KEK + 16-byte tag
```
- **Slot AAD**: `magic ‖ version ‖ kind ‖ payload[0..69]` (everything in the slot before the wrapped key).
So the KDF parameters and salt cannot be swapped without the unwrap failing.
- **Body AAD**: the whole header, from offset 0 to the end of the body nonce.
### Limits a reader enforces before running Argon2
A tampered header must not make the reader allocate 16 GiB. Outside these ranges the file is refused
with "unsupported KDF parameters", before any work:
| Parameter | Allowed | Default written by Custos |
|:--|:--|:--|
| m_cost | 8·p ..= 2 097 152 KiB (2 GiB) | 65 536 KiB (64 MiB) |
| t_cost | 1 ..= 64 | 20 (≈ 0.75 s per unlock on the dev machine; `examples/kdf_timing.rs` measures it) |
| p_cost | 1 ..= 16 | 1 |
The parameters are stored per file, so a later version can raise the defaults; a vault keeps its
parameters until its password is changed.
### Errors
| Situation | Error |
|:--|:--|
| Wrong magic, or the file is shorter than a header | `NotAVault` |
| Version other than 1 | `UnsupportedVersion(n)` |
| No password slot, or a slot runs past the end | `Malformed` |
| KDF parameters outside the limits | `UnsupportedKdf` |
| No slot unwraps with the password | `WrongPassword` (a wrong password and a tampered slot look the same) |
| Slot unwraps but the body tag fails | `Corrupted` (header or body changed after it was written) |
No error carries any part of the password, the key or the plaintext.
## Body (the JSON inside)
UTF-8 JSON, held in zeroizing buffers while being encrypted or parsed:
```json
{
"format": 1,
"items": [
{
"id": "6f1c…(32 hex)",
"type": "web-login",
"title": "GitHub",
"fields": [
{ "name": "username", "value": "GitHub.Lantern.47", "secret": false },
{ "name": "password", "value": "Fable7-Orbit3-…", "secret": true },
{ "name": "url", "value": "https://github.com", "secret": false }
],
"tags": ["dev"],
"notes": "",
"created": 1793000000000,
"modified": 1793000000000,
"history": [ { "field": "password", "value": "old…", "changed": 1792000000000 } ]
}
]
}
```
- Times are Unix milliseconds (UTC).
- `fields` is an ordered list; a name may repeat (several `url`s). Unknown names are kept as custom fields.
- `history` keeps the previous value of a secret field each time it changes (newest last, at most 20 per item).
- Readers ignore JSON members they do not know, so later versions can add them.
- `identity` (optional, core 0.7.0): the Domi identity's root key and the certs it issued (docs/IDENTITY.md);
since core 0.10.0 a cert may carry `revoked_at` and `revocation`.
An older Custos drops it when it saves, so every Custos that saves the vault must be 0.7.0 or later.
- `folder` (optional item member, core 0.8.0): a list of folder names, outermost first (a KeePass group path,
docs/KDBX.md). Absent or empty = no folder.
- `attachments` (optional item member, core 0.8.0): `[{"name": "id_rsa", "data": "<base64>"}]`, files kept with
the item (imported from KeePass). The data counts as secret: it is never logged or printed.
An older Custos drops `folder` and `attachments` when it saves.
- `signing` (optional, core 0.9.0): signing keys for releases and the audit log of every signing request
(docs/SIGNING.md). An older Custos drops it when it saves, so every Custos that saves the vault must be 0.9.0 or later.
- `provision` (optional, core 0.11.0): the Provisio audit, every outcome of a server's *ask* or *offer* (the app's
docs/10_provisio.md). An older Custos ignores it when it reads and drops it when it saves, so every Custos that
saves the vault must be 0.11.0 or later. See "The provision audit" below.
- `kind`, `team` (core 0.18.0): a team vault's body is `"kind": "team"` with the `team` member (docs/TEAM.md); no
other vault has either, and a team vault has no `factors`, `identity` or `member`.
- `member` (optional, core 0.18.0): a person's member key and the teams it opened (docs/TEAM.md). An older Custos
drops it when it saves, so every Custos that saves a member's vault must be 0.18.0 or later.
- `security` (optional, core 0.12.0): the security level, the hardening checklist and their audit (the app's
docs/11_runs_and_levels.md). An older Custos ignores it when it reads and drops it when it saves (the level falls
back to Standard, the checklist to unticked), so every Custos that saves the vault must be 0.12.0 or later. See
"The security member" below.
**Values older cores refuse.** A reader refuses a file whose closed lists hold a value it does not know (see each
member), so these values, new in core 0.12.0, make a vault unreadable for a core before 0.12.0 once they are
written: a `signing` audit entry of kind `approval` (docs/SIGNING.md), a `provision` entry with store `display` or
outcome `confirmed`. A vault without them still opens in core 0.11.0. Core 0.14.0 adds two more: a `signing` key
of kind `android` and an audit entry of kind `apk` (docs/SIGNING.md); a vault that holds either does not open in a
core before 0.14.0. Core 0.16.0 adds the `signing` audit outcome `standing` and the `security` actions
`standing-granted` and `standing-revoked` (docs/SIGNING.md, "Standing approvals"): a vault in which a standing
approval was ever granted does not open in a core before 0.16.0. The rules themselves (`signing.standing`) are a
member older cores ignore and drop. Core 0.19.0 adds the member `signing.android` (the Android grant, docs/SIGNING.md "The Android
grant"), which older cores ignore and drop (the grant is lost, never widened). It adds no closed-list value:
a key the grant makes is `standing-granted` in the security audit (core 0.19.1), so a vault with the grant still
opens in every core since 0.16.0, as the phone app and the web vault may be.
### The provision audit (core 0.11.0)
```json
"provision": {
"audit": [
{ "at": 1793750100000, "direction": "offer", "host": "nixos-vm", "item": "fabrica/gitea-read-token",
"store": "vault", "run": "deploy-7", "kind": "Gitea token, read:repository", "code": "684361",
"outcome": "accepted", "replaced": true }
]
}
```
| Member | |
| :-- | :-- |
| `at` | Unix milliseconds |
| `direction` | `ask` (the server asked for a secret) or `offer` (the server offered one) |
| `host` | the name the factor service gave, 1–253 characters `[A-Za-z0-9.-]` |
| `item` | `^[a-z0-9][a-z0-9._-]{0,63}(/[a-z0-9][a-z0-9._-]{0,63}){0,3}$`, as the factor service checks it |
| `store` | `vault`, `claude`, `cloud` or (core 0.12.0) `display`: shown once on the card, stored nowhere |
| `run` | optional, `[A-Za-z0-9._-]{1,64}` |
| `kind` | optional, at most 200 characters, no control characters (an offer's label; an ask's `--generate` recipe) |
| `code` | the match code: six ASCII digits |
| `outcome` | `approved`, `generated`, `accepted`, `refused`, `out-of-scope`, `invalid`, `expired` or (core 0.12.0) `confirmed` |
| `replaced` | `true` when an accepted offer replaced an existing item |
A **display offer** (core 0.12.0; a TOTP seed moved to a phone) is an `offer` with store `display`. Its outcome is
`confirmed` (Mark typed the phone's current code, Custos checked it and sent it to the server), `refused`, `expired`,
`invalid` or `out-of-scope`; never `accepted`, `approved` or `generated`, and never `replaced`, because nothing is
stored. `confirmed` belongs to display offers only. A code Custos's own check refuses stays on the card and is not
an outcome; a code the server then refuses (its exit 10) is not seen by Custos, so there is no `confirmed-wrong`.
- **No value, ever.** There is no member that holds a secret: every member is something the server sent in the
clear through the mailbox (host, item, store, run, kind) or derives from a public key (`code`). A recorded
entry is checked against the table above; an entry that does not fit is refused, not stored.
- **Append-only.** The API records an entry and lists them (oldest first); nothing edits or removes one, except
that the log keeps the newest 5 000 entries and drops the oldest beyond that.
- Readers ignore members of an entry they do not know. A file whose `provision` has an `outcome`, `direction` or
`store` this core does not know does not open (`Corrupted`), as for `signing`.
### The security member (core 0.12.0; hands-off values 0.13.0)
```json
"security": {
"setup": { "started": 1793750000000, "until": 1793757200000 },
"finished": 1793751000000,
"ticked": ["hello-approvals", "no-ssh"],
"keptScope": { "ask": ["arca/"], "offer": ["arca/", "fabrica/"] },
"audit": [
{ "at": 1793750000000, "action": "setup-started" },
{ "at": 1793751000000, "action": "setup-finished" },
{ "at": 1793752000000, "action": "ticked", "item": "no-ssh" },
{ "at": 1793753000000, "action": "unticked", "item": "no-ssh", "auth": "hello" }
]
}
```
| Member | |
| :-- | :-- |
| `setup` | optional: the last Setup window, Unix milliseconds; `until` is 2 hours after `started` |
| `finished` | optional: when that window ended, by *Finish setup*, or `until` once its expiry was noticed |
| `ticked` | the checklist items that are ticked: `totp-on-phone`, `hello-approvals`, `narrow-scope`, `rotate-setup`, `no-ssh`, `phone-approves`, and (core 0.13.0) `no-auto-connect`, `no-unattended`, `card-signing` |
| `keptScope` | optional: the server scope prefixes *Narrow the server scope* replaced (`ask`, `offer`: at most 64 each, 1–200 characters, no control characters), kept for its undo |
| `audit` | `{at, action, item?, auth?, detail?}`; `action` is `setup-started`, `setup-finished`, `setup-expired`, `ticked`, `unticked`, `ssh-connected`, `totp-moved`, or (core 0.13.0) `auto-connected`, `unattended-stored`, `setup-item-removed`, `unattended-signed`, `taken-over`, or (core 0.16.0) `standing-granted`, `standing-revoked` (also for the Android grant and the keys it makes), or (core 0.17.0) `recovery-created`, `recovery-removed`, `recovered` (docs/FACTORS.md, "The recovery key"; their `detail` is the key's id); `item` a checklist item (with `ticked`, `unticked`); `auth` is `hello` or `password` (with `unticked`); `detail` (core 0.13.0, the four notes; core 0.16.0, the two standing actions) names what happened, never a value: 1–500 characters, no control characters |
The **level** is computed, never stored:
- **Setup** while there is a `setup` window, it has not `finished`, and `started` ≤ now < `until`;
- otherwise **Hardened** when at least one item is ticked;
- otherwise **Standard** (also every vault without the member).
Ticked items hold during Setup too: Setup never undoes hardening. Starting Setup while in Setup changes nothing;
after a window ended a new one starts at now. Its expiry is written (`setup-expired`, and `finished` = `until`) by
the first change after it, not by reading.
- **Append-only** like `provision`: the API adds entries and lists them; the log keeps the newest 5 000.
- Absent while nothing was ever set, so a vault without it is written exactly as before.
- The values new in core 0.13.0 make a vault unreadable for a core before 0.13.0 once one is written, as the
0.12.0 values did before.
- **Hands-off rules** (core 0.13.0, `security`): `is_setup_run` (`setup-` and 1–58 of `[A-Za-z0-9._-]`),
`auto_connect_allowed` (not Hardened, neither `no-auto-connect` nor `no-ssh`), `setup_on_connect` (neither
`no-unattended` nor `no-ssh`), `unattended_provision` (in Setup, a setup run, `no-unattended` not ticked, never an
existing item: an `ask --generate` or an `offer` into `arca/`, `custos/`, `fabrica/`, `aula/`, `gitea/`, an offer
into the Claude Code store, a TOTP offer unless `totp-on-phone`; never `display`) and `unattended_sign` (a
machine-key vault, a request with a run, not Hardened, `card-signing` not ticked, the kinds `minisign`,
`manifest`, `authenticode`, `approval`; never `apk`, core 0.14.0). The app enforces them; the server never decides.
- Readers ignore members they do not know. A file whose `security` has an item, action or auth this core does not
know, a window whose `until` is not after `started`, `finished` without `setup`, or a kept scope that breaks the
rules above does not open (`Corrupted`).
### Item types and their fields (v1)
`*` = secret (`"secret": true`: hidden until revealed, copied with clipboard protection).
| `type` | Fields, in order |
|:--|:--|
| `web-login` | `username`, `password`*, `url` (repeatable), `totp`* (otpauth URI or base32 secret), `autotype-match`, `autotype-sequence` |
| `api-credential` | `service`, `key-id`, `secret`*, `endpoint`, `expires` (YYYY-MM-DD) |
| `local-app` | `target` (app or Credential Manager target), `username`, `password`* |
| `wifi` | `ssid`, `password`*, `security` (`WPA` / `WEP` / `nopass`), `hidden` (`true` / `false`) |
| `secure-note` | none: the text is `notes` |
| `card` | `cardholder`, `number`*, `expiry` (MM/YY), `cvv`*, `pin`* |
`notes` is secret for every type (it is shown only on reveal).
## KDBX 4 (KeePass)
Import and export, with the full field mapping and what does not survive: docs/KDBX.md.
## Device key wrap (not part of the file)
Quick unlock on one machine (the desktop app uses Windows Hello) keeps a separate 108-byte blob **on that
machine**, never in the vault file:
```
"CDW1" (4) ‖ salt (32) ‖ nonce (24) ‖ XChaCha20-Poly1305(KEK, vault key, aad = "CDW1" ‖ salt ‖ nonce) (48)
KEK = HKDF-SHA256(ikm = device material, salt, info = "custos device wrap v1")
```
The device material is something only that device can produce on request (for Windows Hello: the RSA
signature of a fixed challenge by a TPM-held key, which only Hello can unlock). A wrong material or a
changed blob gives `DeviceKeyRejected`; a blob from another vault unwraps a key that fails the body tag
(`Corrupted`). Changing the master password does not change the vault key, so the app deletes the blob
itself when the password changes.
## Saving
`custos-vault::save_atomic` never leaves a half-written vault in place of the old one:
1. The new bytes go to `<name>.custos.tmp` in the same folder; the file is flushed with `fsync`.
2. If `<name>.custos` exists, it is copied to `<name>.custos.bak.tmp`, flushed, and renamed over
`<name>.custos.bak`.
3. `<name>.custos.tmp` is renamed over `<name>.custos` (`std::fs::rename`, which replaces the target; on
Unix the folder is flushed afterwards). A rename refused because a sync client or virus scanner holds
the file open is retried for about two seconds.
A crash in step 1 or 2 leaves the old vault untouched; a crash between 2 and 3 leaves both the old vault
and an identical `.bak`. Leftover `.tmp` files are ignored and overwritten by the next save.
## Versioning
A change that old readers would misread bumps `version`. Readers refuse versions they do not know rather
than guess. Adding JSON members or new slot kinds does not need a bump.
## Share links
Shares are not vault files; their blob and link format is in `docs/SHARE.md`.