[seal] Sealed boxes and key import (v0.5.0) #7

Manually merged
mnovak merged 1 commits from feature/seal-import into main 2026-11-03 11:57:08 +01:00
Owner

Core for Custos phase 3: sealed boxes for the factor service, key import, and the header's factor ids. Version 0.5.0.

What

  • custos-seal (new crate, docs/SEAL.md):
    • A box sealed to a one-time X25519 key: X25519 → HKDF-SHA256 → XChaCha20-Poly1305. A context binds each
      box to one request.
    • A six-digit match code, shown on both screens.
    • At-rest sealing for the TOTP shares the factor service keeps.
    • Low-order public keys are refused. The plaintext limit is 32 KiB.
  • custos_keys::import (docs/KEYS.md "Importing"):
    • OpenSSH, PKCS#8, PKCS#1 and SEC1 private keys (Ed25519, ECDSA P-256, RSA 2048–4096).
    • The public parts and the fingerprint are derived from the private key, never copied from the input.
    • Passphrase-protected keys are refused, and errors never repeat the input.
    • Works around an ssh-key 0.6.7 bug: its TryFrom<&RsaKeypair> passes p twice.
  • Vault::factor_ids: each factor's id and type from the header alone, so the app can ask the TOTP
    service or a paired device for a factor.
  • Docs: THREAT_MODEL (the factor service holds one factor; match codes) and CLAUDE.md.

Tests (79, all pass)

  • custos-seal, 5 tests:
    • only the recipient opens, and only for its context;
    • every changed byte is refused;
    • bad and low-order keys are refused;
    • the match-code vector (07×32 → 684361, checked independently with Python);
    • at-rest sealing opens only with the same key and context.
  • custos-keys, 3 new tests:
    • an ssh-keygen fixture imports with the fingerprint ssh-keygen -l printed;
    • every format, with CRLF and surrounding whitespace, imports to the same key;
    • passphrase-protected and unknown inputs are refused without echoing them.
      The fixtures are throwaway test keys made for this test only.
  • custos-vault: factor_ids matches the unlocked vault's factor list; a v1 file has none.

Self-review

  • No new primitives. The crates are x25519-dalek 2 (same family as ed25519-dalek), chacha20poly1305,
    hkdf and sha2, with randomness from SysRng.
  • The recipient's secret half is a StaticSecret with zeroize. It is never serialised, and Debug
    shows only the match code.
  • Algorithm is unchanged. Imported RSA-2048 is only a string in the item's algorithm field, so
    dependents' exhaustive matches still compile.
Core for Custos phase 3: sealed boxes for the factor service, key import, and the header's factor ids. Version 0.5.0. ## What - **`custos-seal`** (new crate, `docs/SEAL.md`): - A box sealed to a one-time X25519 key: X25519 → HKDF-SHA256 → XChaCha20-Poly1305. A `context` binds each box to one request. - A six-digit match code, shown on both screens. - At-rest sealing for the TOTP shares the factor service keeps. - Low-order public keys are refused. The plaintext limit is 32 KiB. - **`custos_keys::import`** (`docs/KEYS.md` "Importing"): - OpenSSH, PKCS#8, PKCS#1 and SEC1 private keys (Ed25519, ECDSA P-256, RSA 2048–4096). - The public parts and the fingerprint are derived from the private key, never copied from the input. - Passphrase-protected keys are refused, and errors never repeat the input. - Works around an ssh-key 0.6.7 bug: its `TryFrom<&RsaKeypair>` passes `p` twice. - **`Vault::factor_ids`**: each factor's id and type from the header alone, so the app can ask the TOTP service or a paired device for a factor. - Docs: THREAT_MODEL (the factor service holds one factor; match codes) and CLAUDE.md. ## Tests (79, all pass) - **custos-seal, 5 tests:** - only the recipient opens, and only for its context; - every changed byte is refused; - bad and low-order keys are refused; - the match-code vector (`07`×32 → `684361`, checked independently with Python); - at-rest sealing opens only with the same key and context. - **custos-keys, 3 new tests:** - an `ssh-keygen` fixture imports with the fingerprint `ssh-keygen -l` printed; - every format, with CRLF and surrounding whitespace, imports to the same key; - passphrase-protected and unknown inputs are refused without echoing them. The fixtures are throwaway test keys made for this test only. - **custos-vault:** `factor_ids` matches the unlocked vault's factor list; a v1 file has none. ## Self-review - No new primitives. The crates are `x25519-dalek` 2 (same family as `ed25519-dalek`), `chacha20poly1305`, `hkdf` and `sha2`, with randomness from `SysRng`. - The recipient's secret half is a `StaticSecret` with `zeroize`. It is never serialised, and `Debug` shows only the match code. - `Algorithm` is unchanged. Imported RSA-2048 is only a string in the item's `algorithm` field, so dependents' exhaustive matches still compile.
mnovak added 1 commit 2026-11-02 18:30:28 +01:00
mnovak manually merged commit df7c149b25 into main 2026-11-03 11:57:08 +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#7