Files

8.2 KiB

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:

{
  "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 urls). 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). 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.

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.

Shares are not vault files; their blob and link format is in docs/SHARE.md.