[docs] Format and threat model: vault file v1, KDBX mapping, what is not protected
This commit is contained in:
+181
@@ -0,0 +1,181 @@
|
||||
# The `.custos` vault file, format version 1
|
||||
|
||||
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 | 3 (measured ≈ 0.5–1 s on the dev machine, see `custos-vault` `KdfParams::DEFAULT`) |
|
||||
| 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.
|
||||
|
||||
### 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).
|
||||
|
||||
## Planned KDBX 4 mapping (export comes in v1.2)
|
||||
|
||||
KeePassXC-compatible: standard strings where KeePass has them, custom strings otherwise. Secret fields
|
||||
become *protected* strings.
|
||||
|
||||
| Custos | KDBX 4 entry |
|
||||
|:--|:--|
|
||||
| `title` | `Title` |
|
||||
| `username` (web-login, local-app) | `UserName` |
|
||||
| `password`* (web-login, local-app, wifi) | `Password` (protected) |
|
||||
| first `url` | `URL` |
|
||||
| 2nd, 3rd … `url` | `KP2A_URL_1`, `KP2A_URL_2`, … (KeePassXC reads these) |
|
||||
| `notes` | `Notes` |
|
||||
| `totp` | `otp` (protected), as an `otpauth://` URI (KeePassXC's format) |
|
||||
| `autotype-sequence` | `AutoType/DefaultSequence` |
|
||||
| `autotype-match` | `AutoType/Association/Window` |
|
||||
| `type` | custom string `custos-type` |
|
||||
| `api-credential`: `service`, `key-id`, `endpoint`, `expires` | custom strings `service`, `key-id`, `endpoint`; `expires` → entry `Times/Expires` + `ExpiryTime` |
|
||||
| `api-credential`: `secret`* | `Password` (protected) |
|
||||
| `local-app`: `target` | custom string `target` |
|
||||
| `wifi`: `ssid`, `security`, `hidden` | `UserName` = ssid, custom strings `security`, `hidden` |
|
||||
| `card`: `number`* | `Password` (protected) |
|
||||
| `card`: `cardholder`, `expiry` | `UserName` = cardholder, custom string `expiry` |
|
||||
| `card`: `cvv`*, `pin`* | protected custom strings `cvv`, `pin` |
|
||||
| other custom fields | custom strings of the same name, protected when secret |
|
||||
| `tags` | `Tags` (`;`-separated) |
|
||||
| `created`, `modified` | `Times/CreationTime`, `Times/LastModificationTime` |
|
||||
| `history` entries | `History` entries (one per change, with that old password) |
|
||||
|
||||
## 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` (`MoveFileEx` with `REPLACE_EXISTING` on Windows,
|
||||
`rename` on Unix, then the folder is flushed on Unix).
|
||||
|
||||
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.
|
||||
@@ -0,0 +1,50 @@
|
||||
# Threat model
|
||||
|
||||
Custos keeps one person's (or one household's) secrets in one encrypted file on their own disk, synced
|
||||
as a plain file (e.g. by Arca to their own Nextcloud). This page says what that protects against and,
|
||||
just as plainly, what it does not.
|
||||
|
||||
## Assets
|
||||
|
||||
- The secrets in the vault: passwords, API keys, TOTP seeds, Wi-Fi keys, card numbers, notes.
|
||||
- The master password and the 256-bit vault key it unwraps.
|
||||
|
||||
## What is protected
|
||||
|
||||
| Attacker | Has | Gets | Why |
|
||||
|:--|:--|:--|:--|
|
||||
| Thief or sync server | The `.custos` file (any number of old versions) | Item count and sizes roughly (the ciphertext length), the KDF parameters. Nothing else. | XChaCha20-Poly1305 over the whole body; titles, URLs and usernames are inside it too. |
|
||||
| Offline guesser | The file and a GPU farm | One Argon2id evaluation (64 MiB, 3 passes by default) per guess | A 4-word memorable password with digits (~65 bits) is out of reach; a weak master password is not. **The master password is the whole defence here.** |
|
||||
| Tamperer | Write access to the file | Can destroy it, or roll it back to an older version they saw. Cannot change, reorder, add or remove items unnoticed. | The header is the body's AAD; each slot's parameters are its wrap's AAD. |
|
||||
| Someone who crashes the machine mid-save | — | Nothing | Atomic save: temp file, fsync, rename; the previous version is kept as `.bak`. |
|
||||
|
||||
## What is NOT protected
|
||||
|
||||
- **A compromised OS or a malicious process running as you.** While the vault is unlocked, the key and
|
||||
the decrypted items are in the app's memory. Malware with your privileges can read that memory, log your
|
||||
keystrokes as you type the master password, or read the screen. No password manager defends against this.
|
||||
- **A memory dump while unlocked** (crash dump, hibernation file, swap). Secrets are held in zeroizing types
|
||||
and wiped when dropped, which shrinks the window; it does not close it. Copies may remain where the
|
||||
standard library or the JSON parser moved a buffer, in the webview (the desktop app shows a revealed
|
||||
value there), and in OS buffers. Use full-disk encryption (BitLocker) for the hibernation file and swap.
|
||||
- **The clipboard.** A copied secret is readable by every process until it is cleared (30 s in the
|
||||
desktop app), and by any clipboard manager that ignores the "exclude from history" marker.
|
||||
- **Auto-type** sends keystrokes to whatever window has focus. The app re-checks the target window before
|
||||
typing, but a window that steals focus at the wrong moment can receive them.
|
||||
- **Rollback.** Someone with write access to the synced file can replace it with an older version.
|
||||
Custos does not detect that (there is no trusted counter to compare against).
|
||||
- **Shoulder surfing and QR codes.** A revealed password or a shown QR code is readable by anyone who
|
||||
can see the screen.
|
||||
- **Metadata.** File size and modification times reveal roughly how much is stored and when it changed.
|
||||
- **Side channels.** No effort beyond what the RustCrypto crates provide (constant-time tag comparison).
|
||||
|
||||
## Design rules that follow from this
|
||||
|
||||
- No custom cryptography: Argon2id (`argon2`), XChaCha20-Poly1305 (`chacha20poly1305`), the OS CSPRNG
|
||||
(`rand`'s `SysRng`/`getrandom`), `zeroize`. All RustCrypto / rust-random.
|
||||
- Secret-holding types never print their contents: `Debug` and `Display` give `[redacted]` (tested).
|
||||
- Errors never contain secret material; a wrong password and a tampered slot give the same error.
|
||||
- The reader checks KDF parameters against fixed limits before running Argon2, so a crafted file cannot
|
||||
make it allocate unbounded memory.
|
||||
- Generated passwords take their randomness only from the OS CSPRNG, and their reported entropy counts only
|
||||
the random choices (a fixed pattern like capitalisation adds nothing).
|
||||
Reference in New Issue
Block a user