[repo] Provisio core: a kept seal recipient, the provision audit (v0.11.0) #13

Manually merged
mnovak merged 3 commits from feature/provisio-core into main 2026-11-04 14:02:01 +01:00
Owner

The two core pieces Provisio needs (the app's docs/10_provisio.md, "The seal" and "Audit"). v0.11.0.

custos-seal: a kept recipient

impl Recipient {
    pub fn from_secret(secret: Zeroizing<[u8; 32]>) -> Result<Recipient, SealError>;
    pub fn secret_bytes(&self) -> Zeroizing<[u8; 32]>;
}
  • The PC's Provisio sealing key (what the server seals offers to) is made once with generate, kept DPAPI-sealed
    via secret_bytes, and restored with from_secret. One-time keys stay the default (docs/SEAL.md, "A kept key").
  • from_secret refuses (BadKey) a secret that X25519 clamps to zero (all zeros, a wiped or never-filled buffer,
    and anything that differs from it only in clamped bits) and, as seal does for public keys, one whose shared
    secrets would not be contributory.
  • Debug of Recipient now prints secret: [redacted] (it already printed only the match code).
  • No new crypto: x25519-dalek's StaticSecret::from / to_bytes.

custos-vault: the provision audit

A new optional body member provision: {"audit": [...]}, beside signing (docs/FORMAT.md, "The provision audit").

pub mod provision {
    pub const AUDIT_LIMIT: usize = 5_000;
    pub enum Direction { Ask, Offer }                  // "ask" | "offer"
    pub enum Store { Vault, Claude, Cloud }            // "vault" | "claude" | "cloud"
    pub enum Outcome { Approved, Generated, Accepted, Refused, OutOfScope, Invalid, Expired } // kebab-case
    pub struct ProvisionEntry {
        pub at: i64, pub direction: Direction, pub host: String, pub item: String, pub store: Store,
        pub run: Option<String>, pub kind: Option<String>, pub code: String, pub outcome: Outcome, pub replaced: bool,
    }
    impl ProvisionEntry { pub fn check(&self) -> Result<(), Error>; }
}
impl Vault {
    pub fn provision_record(&mut self, entry: ProvisionEntry) -> Result<(), Error>; // check, append, keep newest 5 000
    pub fn provision_audit(&self) -> &[ProvisionEntry];                            // oldest first
}
Error::Provision(&'static str)  // names the member, never its value
  • at is i64 Unix ms, as signing::AuditEntry::at and now_ms().
  • Absent while empty, so a vault without entries is written byte-for-byte as before.

Tests (153 total, all green with cargo test --workspace --release; 8 new)

Each new test was run red before the code existed, then once more against a skeleton to see it fail for its own
reason:

Test Red against the skeleton because
seal a_kept_recipient_comes_back_from_its_secret did not compile (no from_secret / secret_bytes)
seal a_known_secret_is_refused all-zero secret accepted (unwrap_err on Ok)
seal a_kept_recipient_prints_redacted Debug had no [redacted]
vault the_provision_audit_records_every_outcome_and_survives_a_reopen audit empty after reopen (not persisted)
vault entries_that_do_not_fit_are_refused_and_not_stored a 5-digit code was accepted
vault the_audit_is_append_only_and_keeps_the_newest_entries 5 003 entries kept, not 5 000
vault an_entry_has_no_member_that_could_hold_a_secret did not compile (no types); a shape guard after that
vault (unit) provision::tests::an_older_reader_opens_a_vault_with_the_provision_audit member not written to the body

Besides the unit test (which parses the decrypted body with core 0.10.0's Body shape), a one-off check linked the
real v0.10.0 custos-vault next to this one: v0.10.0 opens a file with a provision audit (items intact), and its
save drops the member, as FORMAT.md documents for identity and signing.

rustfmt --edition 2024 ran on the changed files only (it rewrapped one pre-existing line in custos-seal's lib.rs).
Clippy is clean on the new code (one pre-existing collapsible-if in signing.rs is untouched).

Self-review (adversarial)

What could misuse from_secret / secret_bytes?

  • secret_bytes is the first function in custos-seal that hands a recipient secret out. Anyone holding a
    Recipient can now export it. Mitigation is by contract and review, not by type: the doc comments and
    SEAL.md say it goes only to the caller's sealed storage; one-time paths (approvals, pairing, Provisio asks)
    never call it. The returned Zeroizing<[u8; 32]> wipes on drop, but its Debug prints the bytes: a caller
    that {:?}s it leaks it. The app must not, and its own redaction tests should cover the DPAPI path.
  • A kept key opens every box ever sealed to it, so a stolen provision.key (DPAPI, this Windows account) opens
    offers recorded in transit later or earlier. The mailbox holds boxes for 5 minutes only and keeps none after
    hand-out; the context binds each box to provision-offer:<store>:<item>; the PC checks the plaintext's item,
    store, kind and code key; the mailbox refuses a replayed ephemeral key. Rotating the key (generate a new one,
    re-register) is the app's lever after a suspected leak.
  • from_secret with attacker-chosen bytes: it only builds a key the caller already holds; the refusal of
    clamped-zero catches the realistic bug (a zeroed buffer after a failed unseal), which would otherwise give a
    key the whole world knows. Other weak-but-valid scalars cannot be told from random ones; the key must come from
    generate.
  • *secret copies the array to the stack while building the StaticSecret, exactly as generate already does;
    that copy is not wiped (same as before this change).

Why the audit cannot hold a secret

  • There is no value member: an_entry_has_no_member_that_could_hold_a_secret pins the exact member list and that
    none is nested. A later member would have to change that test and FORMAT.md.
  • Every member is something the server sends in the clear through the mailbox (host, item, store, run, kind) or
    the match code of a public key. None of it is secret by construction.
  • The free-text members are checked before an entry is stored: item and run by the factor service's own
    patterns, host as a host name, kind at most 200 characters without control characters, code exactly six digits.
    The only member that could carry arbitrary text is kind (200 characters); it is the label the server already
    printed on the card and sent in the clear. The app must fill it from the offer's kind / the ask's --generate
    recipe and nothing else.
  • A refused entry's error names the member, never its value (tested with a token-like string).
  • Append-only: the API has provision_record (append) and provision_audit (a shared slice); nothing edits or
    removes an entry except the oldest dropping off past 5 000.

Format risks

  • As for signing, an older Custos drops provision when it saves: every Custos that saves the vault must be
    0.11.0 or later (FORMAT.md, and the app's docs/10_provisio.md risk table).
  • A future outcome/direction/store value would make this core refuse the vault (Corrupted), as with signing.
    Adding one needs the same "must be 0.x or later" note.
The two core pieces Provisio needs (the app's docs/10_provisio.md, "The seal" and "Audit"). v0.11.0. ## custos-seal: a kept recipient ```rust impl Recipient { pub fn from_secret(secret: Zeroizing<[u8; 32]>) -> Result<Recipient, SealError>; pub fn secret_bytes(&self) -> Zeroizing<[u8; 32]>; } ``` - The PC's Provisio sealing key (what the server seals offers to) is made once with `generate`, kept DPAPI-sealed via `secret_bytes`, and restored with `from_secret`. One-time keys stay the default (docs/SEAL.md, "A kept key"). - `from_secret` refuses (`BadKey`) a secret that X25519 clamps to zero (all zeros, a wiped or never-filled buffer, and anything that differs from it only in clamped bits) and, as `seal` does for public keys, one whose shared secrets would not be contributory. - `Debug` of `Recipient` now prints `secret: [redacted]` (it already printed only the match code). - No new crypto: x25519-dalek's `StaticSecret::from` / `to_bytes`. ## custos-vault: the provision audit A new optional body member `provision: {"audit": [...]}`, beside `signing` (docs/FORMAT.md, "The provision audit"). ```rust pub mod provision { pub const AUDIT_LIMIT: usize = 5_000; pub enum Direction { Ask, Offer } // "ask" | "offer" pub enum Store { Vault, Claude, Cloud } // "vault" | "claude" | "cloud" pub enum Outcome { Approved, Generated, Accepted, Refused, OutOfScope, Invalid, Expired } // kebab-case pub struct ProvisionEntry { pub at: i64, pub direction: Direction, pub host: String, pub item: String, pub store: Store, pub run: Option<String>, pub kind: Option<String>, pub code: String, pub outcome: Outcome, pub replaced: bool, } impl ProvisionEntry { pub fn check(&self) -> Result<(), Error>; } } impl Vault { pub fn provision_record(&mut self, entry: ProvisionEntry) -> Result<(), Error>; // check, append, keep newest 5 000 pub fn provision_audit(&self) -> &[ProvisionEntry]; // oldest first } Error::Provision(&'static str) // names the member, never its value ``` - `at` is `i64` Unix ms, as `signing::AuditEntry::at` and `now_ms()`. - Absent while empty, so a vault without entries is written byte-for-byte as before. ## Tests (153 total, all green with `cargo test --workspace --release`; 8 new) Each new test was run red before the code existed, then once more against a skeleton to see it fail for its own reason: | Test | Red against the skeleton because | | :-- | :-- | | seal `a_kept_recipient_comes_back_from_its_secret` | did not compile (no `from_secret` / `secret_bytes`) | | seal `a_known_secret_is_refused` | all-zero secret accepted (`unwrap_err` on `Ok`) | | seal `a_kept_recipient_prints_redacted` | Debug had no `[redacted]` | | vault `the_provision_audit_records_every_outcome_and_survives_a_reopen` | audit empty after reopen (not persisted) | | vault `entries_that_do_not_fit_are_refused_and_not_stored` | a 5-digit code was accepted | | vault `the_audit_is_append_only_and_keeps_the_newest_entries` | 5 003 entries kept, not 5 000 | | vault `an_entry_has_no_member_that_could_hold_a_secret` | did not compile (no types); a shape guard after that | | vault (unit) `provision::tests::an_older_reader_opens_a_vault_with_the_provision_audit` | member not written to the body | Besides the unit test (which parses the decrypted body with core 0.10.0's `Body` shape), a one-off check linked the real v0.10.0 `custos-vault` next to this one: v0.10.0 opens a file with a provision audit (items intact), and its save drops the member, as FORMAT.md documents for `identity` and `signing`. `rustfmt --edition 2024` ran on the changed files only (it rewrapped one pre-existing line in custos-seal's lib.rs). Clippy is clean on the new code (one pre-existing collapsible-if in signing.rs is untouched). ## Self-review (adversarial) **What could misuse `from_secret` / `secret_bytes`?** - `secret_bytes` is the first function in custos-seal that hands a recipient secret out. Anyone holding a `Recipient` can now export it. Mitigation is by contract and review, not by type: the doc comments and SEAL.md say it goes only to the caller's sealed storage; one-time paths (approvals, pairing, Provisio asks) never call it. The returned `Zeroizing<[u8; 32]>` wipes on drop, but its `Debug` prints the bytes: a caller that `{:?}`s it leaks it. The app must not, and its own redaction tests should cover the DPAPI path. - A kept key opens every box ever sealed to it, so a stolen `provision.key` (DPAPI, this Windows account) opens offers recorded in transit later or earlier. The mailbox holds boxes for 5 minutes only and keeps none after hand-out; the context binds each box to `provision-offer:<store>:<item>`; the PC checks the plaintext's item, store, kind and code key; the mailbox refuses a replayed ephemeral key. Rotating the key (generate a new one, re-register) is the app's lever after a suspected leak. - `from_secret` with attacker-chosen bytes: it only builds a key the caller already holds; the refusal of clamped-zero catches the realistic bug (a zeroed buffer after a failed unseal), which would otherwise give a key the whole world knows. Other weak-but-valid scalars cannot be told from random ones; the key must come from `generate`. - `*secret` copies the array to the stack while building the `StaticSecret`, exactly as `generate` already does; that copy is not wiped (same as before this change). **Why the audit cannot hold a secret** - There is no value member: `an_entry_has_no_member_that_could_hold_a_secret` pins the exact member list and that none is nested. A later member would have to change that test and FORMAT.md. - Every member is something the server sends in the clear through the mailbox (host, item, store, run, kind) or the match code of a public key. None of it is secret by construction. - The free-text members are checked before an entry is stored: item and run by the factor service's own patterns, host as a host name, kind at most 200 characters without control characters, code exactly six digits. The only member that could carry arbitrary text is `kind` (200 characters); it is the label the server already printed on the card and sent in the clear. The app must fill it from the offer's `kind` / the ask's `--generate` recipe and nothing else. - A refused entry's error names the member, never its value (tested with a token-like string). - Append-only: the API has `provision_record` (append) and `provision_audit` (a shared slice); nothing edits or removes an entry except the oldest dropping off past 5 000. **Format risks** - As for `signing`, an older Custos drops `provision` when it saves: every Custos that saves the vault must be 0.11.0 or later (FORMAT.md, and the app's docs/10_provisio.md risk table). - A future outcome/direction/store value would make this core refuse the vault (`Corrupted`), as with `signing`. Adding one needs the same "must be 0.x or later" note.
mnovak added 3 commits 2026-11-04 14:01:41 +01:00
mnovak manually merged commit 8660b887c1 into main 2026-11-04 14:02:01 +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#13