[vault] Two factors (format v2), machine store, key pairs and API keys (v0.4.0) #6

Manually merged
mnovak merged 5 commits from feature/two-factors into main 2026-11-02 16:24:45 +01:00
Owner

Core for two-factor vaults, the Claude Code store, and key generators. Version 0.4.0. Docs first: docs/FACTORS.md, docs/KEYS.md; then tests, then code.

What changed

  • Format version 2 (docs/FACTORS.md): a vault opens with any two of its factors, never one: password, device key, TOTP-released share, another device's approval, passkey PRF.
    • Each factor has a random factor key F (wrapped by the factor's material in a factor slot).
    • Each pair of factors wraps the vault key (pair slot, HKDF of both factor keys).
    • The factor keys are also in the encrypted body. An unlocked vault therefore adds a factor with only that factor's material, or drops one (never below two).
    • Changing the password rewraps the password factor's key only, so a forgotten password is replaced by unlocking with two other factors.
  • Upgrade: upgrade_to_two_factors turns a v1 vault into v2 with its password and a second factor; same vault key, same items. A v1 file still reads.
  • Machine store: a separate vault with one device factor and a single slot, for a program that must open it unattended (the Claude Code store). A store never opens as a user vault, nor the other way round.
  • Windows Hello device wrap (one secret) is refused for v2 vaults.
  • New item type key-pair, plus custos-keys (Ed25519, ECDSA P-256, RSA-3072/4096 as OpenSSH public/private, SPKI and PKCS#8 PEM, SHA256: fingerprint).
  • New generators in custos-gen: secret_key (16–128 bytes; hex, base64url, base64) and api_key (prefix_ + 190 bits of base62 + CRC-32 checksum).
  • Rule change (CLAUDE.md): ed25519-dalek is allowed as RustCrypto's Ed25519 backend for ssh-key.

Checked

  • cargo test --workspace --release: 71 green. New:
    • any two of three factors open and one never does;
    • wrong factors are named;
    • a factor is added and removed without the others;
    • a forgotten password is replaced via two other factors (same vault key);
    • v1 upgrades and its password alone stops working;
    • every header byte flipped fails;
    • machine store;
    • 8-factor limit with all 28 pairs;
    • no factor material in Debug;
    • key-pair round trip;
    • secret and API keys: length, encoding, entropy, checksum catches a typo;
    • every key algorithm parses back from each format; Ed25519 signs and verifies.
  • ssh-keygen (OpenSSH) reads the generated Ed25519, ECDSA and RSA private keys, derives the same public keys, and prints the same fingerprints.

Self-review

  • What a hostile file can do:
    • Slot counts and sizes are bounded (≤ 64 slots, ≤ 8 factors).
    • Pair ids must name existing factors, in order; a single slot only appears in a one-factor store.
    • Argon2 limits are checked before work.
    • Material outside 32–64 bytes is refused before work.
    • The header is the body's AAD, and every slot's head is its wrap's AAD.
  • The body cross-checks the header: the factor ids in the slots and in the body must match, or the vault is Corrupted.
  • Not verified: the wasm build (phase 4 adds the v2 calls to custos-wasm; it compiles here, the wasm32 target was not built).
Core for two-factor vaults, the Claude Code store, and key generators. Version 0.4.0. Docs first: `docs/FACTORS.md`, `docs/KEYS.md`; then tests, then code. ## What changed - **Format version 2** (`docs/FACTORS.md`): a vault opens with **any two of its factors**, never one: password, device key, TOTP-released share, another device's approval, passkey PRF. - Each factor has a random factor key `F` (wrapped by the factor's material in a *factor slot*). - Each pair of factors wraps the vault key (*pair slot*, HKDF of both factor keys). - The factor keys are also in the encrypted body. An unlocked vault therefore adds a factor with only that factor's material, or drops one (never below two). - Changing the password rewraps the password factor's key only, so a forgotten password is replaced by unlocking with two other factors. - **Upgrade:** `upgrade_to_two_factors` turns a v1 vault into v2 with its password and a second factor; same vault key, same items. A v1 file still reads. - **Machine store:** a separate vault with one device factor and a *single slot*, for a program that must open it unattended (the Claude Code store). A store never opens as a user vault, nor the other way round. - **Windows Hello device wrap** (one secret) is refused for v2 vaults. - **New item type `key-pair`**, plus `custos-keys` (Ed25519, ECDSA P-256, RSA-3072/4096 as OpenSSH public/private, SPKI and PKCS#8 PEM, `SHA256:` fingerprint). - **New generators in `custos-gen`:** `secret_key` (16–128 bytes; hex, base64url, base64) and `api_key` (`prefix_` + 190 bits of base62 + CRC-32 checksum). - **Rule change** (`CLAUDE.md`): `ed25519-dalek` is allowed as RustCrypto's Ed25519 backend for `ssh-key`. ## Checked - `cargo test --workspace --release`: **71 green**. New: - any two of three factors open and one never does; - wrong factors are named; - a factor is added and removed without the others; - a forgotten password is replaced via two other factors (same vault key); - v1 upgrades and its password alone stops working; - every header byte flipped fails; - machine store; - 8-factor limit with all 28 pairs; - no factor material in `Debug`; - key-pair round trip; - secret and API keys: length, encoding, entropy, checksum catches a typo; - every key algorithm parses back from each format; Ed25519 signs and verifies. - `ssh-keygen` (OpenSSH) reads the generated Ed25519, ECDSA and RSA private keys, derives the same public keys, and prints the same fingerprints. ## Self-review - **What a hostile file can do:** - Slot counts and sizes are bounded (≤ 64 slots, ≤ 8 factors). - Pair ids must name existing factors, in order; a single slot only appears in a one-factor store. - Argon2 limits are checked before work. - Material outside 32–64 bytes is refused before work. - The header is the body's AAD, and every slot's head is its wrap's AAD. - **The body cross-checks the header:** the factor ids in the slots and in the body must match, or the vault is `Corrupted`. - **Not verified:** the wasm build (phase 4 adds the v2 calls to `custos-wasm`; it compiles here, the wasm32 target was not built).
mnovak added 5 commits 2026-11-02 15:49:32 +01:00
mnovak manually merged commit 7893dd199c into main 2026-11-02 16:24:45 +01:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: mnovak/CustosPublic#6