ratchet verify: end-to-end + adversarial tests on the wired chat path #88

Merged
sirius merged 1 commit from wt/t_95ff7563 into main 2026-09-16 23:31:23 +00:00
Owner

Verification card for the chat Double Ratchet, stacked on the merged PR #87 (base main). Offline: real SQLCipher stores, real identity keys, the real encode_chat_frame / ingest_chat_frame pair that Node::send and Node::handle_incoming call, and a capture-and-release Deliverer so the test decides what arrives, when, and how often. No live Tor on the offline paths.

Why the harness looks like this

Node::start / start_with_passphrase are the only public constructors and both bootstrap Tor and publish an onion service, so tests/*.rs cannot build a Node. The wire-level files drive the exact functions those two call sites use; the Node struct itself (its send body and its dispatch arm, over a real Noise IK handshake on an in-memory stream) is driven in src/node.rs's test module. The live Tor case stays #[ignore]d in tests/two_node.rs, unchanged.

Scenarios

# Scenario Where The assertion that proves it
1 Out-of-order delivery (send 0,1,2; deliver 2,0,1) tests/ratchet_e2e.rs three chat rows, arrival order 2,0,1, each with its own plaintext, no duplicates
2 A dropped frame does not stall the conversation tests/ratchet_e2e.rs 0, then 2 and 3 decrypt with 1 never sent; and the lost frame still decrypts later from the skipped-key store
3 Replay, including the real retry path tests/ratchet_e2e.rs a queued row is re-sent byte-identically, received once, and the second delivery errors already used with exactly one chat row
4 Skip bound tests/ratchet_adversarial.rs a well-formed frame claiming N = next + 2001 is rejected with MAX_SKIP (not an AEAD failure), no chat row, persisted blob byte-identical; N = next + 2000 passes the bound and is rejected only by its tag
5 Restart persistence tests/ratchet_e2e.rs both peers' stores are dropped and reopened from the same home dirs; identity is unchanged and both directions continue
6 Post-compromise security smoke tests/ratchet_adversarial.rs a snapshot taken at message k reads the skipped key it held, then reads the epoch built on its own ratchet key (the documented Double Ratchet hop), and cannot read the epoch that needs a key minted after the compromise; the live peer reads all of it
7 Prefix safety / desync tests/ratchet_adversarial.rs unknown friend errors unknown friend and writes no session row; a frame from an epoch derived from a prekey Bob no longer holds is rejected, writes no session row, and the re-scanned invite resumes both directions
8 Corruption tests/ratchet_adversarial.rs truncated, header-only, bad version, flipped dh_pub, flipped N, flipped ciphertext: each dropped, no chat row, persisted blob byte-identical, and the good frame after them still lands

Node-level (src/node.rs test module, cargo test --lib): Node::send queues exactly one rat frame on the outbox row with the plaintext only in local history; an inbound frame goes through a real Noise IK handshake into handle_incoming and is dispatched to the ratchet; out-of-order, replay and corruption behave the same through the real receive path.

Scope deviation

src/node.rs gains a #[cfg(test)] mod tests (no production code, no public API change) because a Node cannot be constructed from tests/ without Tor. It builds the struct literal with an unbootstrapped TorClient and a NoDial deliverer, and bridges tokio::io::duplex to futures::io with a 30-line adapter instead of adding a dev-dependency. Everything else is inside the two allowed new test files; no existing test was weakened or deleted.

One test repair, not a product bug

The first version of the retired-epoch case only called clear_ratchet and relied on the prekeys being unchanged; that is not deterministic, because a peer that re-derives the same bootstrap epoch can still follow the lineage by public-key order, and the test passed or failed depending on the random tie-break. It now changes the friend's recorded prekey (what a refreshed invite does, and what makes Node::add_friend_payload clear the session), which is deterministic. The product code was not changed: 20 consecutive runs of the Node-level tests and 15 consecutive runs of both new files pass.

Evidence

  • cargo test --locked --target x86_64-unknown-linux-gnu: 288 passed, 0 failed, 4 ignored across 32 test targets (baseline on main was 275 passed, 3 ignored — the delta is the 13 new tests; the 4 ignored are the pre-existing live-Tor cases).
  • cargo clippy --locked --all-targets --target x86_64-unknown-linux-gnu -- -D warnings: clean.

Not verified

  • The live Tor path: tests/two_node.rs stays #[ignore]d; nothing here exercises a real onion, a real publish, or Arti's HS client against a remote service.
  • The Android SDK / Compose client and crates/onionwire-sdk: not touched, not built here.
  • The TUI: not exercised; these tests drive Node, not the widgets.
  • The wallet / payment frames: not exercised by this card.
  • Real radio: no packet loss, no reordering, no clock skew, no adversarial network. Frames are captured and released by hand.
  • The Double Ratchet's long-run behaviour beyond two DH steps: the PCS case walks exactly two round trips.
Verification card for the chat Double Ratchet, stacked on the merged PR #87 (base `main`). Offline: real SQLCipher stores, real identity keys, the real `encode_chat_frame` / `ingest_chat_frame` pair that `Node::send` and `Node::handle_incoming` call, and a capture-and-release `Deliverer` so the test decides what arrives, when, and how often. No live Tor on the offline paths. ## Why the harness looks like this `Node::start` / `start_with_passphrase` are the only public constructors and both bootstrap Tor and publish an onion service, so `tests/*.rs` cannot build a `Node`. The wire-level files drive the exact functions those two call sites use; the `Node` struct itself (its send body and its dispatch arm, over a real Noise IK handshake on an in-memory stream) is driven in `src/node.rs`'s test module. The live Tor case stays `#[ignore]`d in `tests/two_node.rs`, unchanged. ## Scenarios | # | Scenario | Where | The assertion that proves it | |---|---|---|---| | 1 | Out-of-order delivery (send 0,1,2; deliver 2,0,1) | `tests/ratchet_e2e.rs` | three chat rows, arrival order 2,0,1, each with its own plaintext, no duplicates | | 2 | A dropped frame does not stall the conversation | `tests/ratchet_e2e.rs` | 0, then 2 and 3 decrypt with 1 never sent; and the lost frame still decrypts later from the skipped-key store | | 3 | Replay, including the real retry path | `tests/ratchet_e2e.rs` | a queued row is re-sent byte-identically, received once, and the second delivery errors `already used` with exactly one chat row | | 4 | Skip bound | `tests/ratchet_adversarial.rs` | a well-formed frame claiming N = next + 2001 is rejected with `MAX_SKIP` (not an AEAD failure), no chat row, persisted blob byte-identical; N = next + 2000 passes the bound and is rejected only by its tag | | 5 | Restart persistence | `tests/ratchet_e2e.rs` | both peers' stores are dropped and reopened from the same home dirs; identity is unchanged and both directions continue | | 6 | Post-compromise security smoke | `tests/ratchet_adversarial.rs` | a snapshot taken at message k reads the skipped key it held, then reads the epoch built on its own ratchet key (the documented Double Ratchet hop), and cannot read the epoch that needs a key minted after the compromise; the live peer reads all of it | | 7 | Prefix safety / desync | `tests/ratchet_adversarial.rs` | unknown friend errors `unknown friend` and writes no session row; a frame from an epoch derived from a prekey Bob no longer holds is rejected, writes no session row, and the re-scanned invite resumes both directions | | 8 | Corruption | `tests/ratchet_adversarial.rs` | truncated, header-only, bad version, flipped dh_pub, flipped N, flipped ciphertext: each dropped, no chat row, persisted blob byte-identical, and the good frame after them still lands | `Node`-level (`src/node.rs` test module, `cargo test --lib`): `Node::send` queues exactly one `rat ` frame on the outbox row with the plaintext only in local history; an inbound frame goes through a real Noise IK handshake into `handle_incoming` and is dispatched to the ratchet; out-of-order, replay and corruption behave the same through the real receive path. ## Scope deviation `src/node.rs` gains a `#[cfg(test)] mod tests` (no production code, no public API change) because a `Node` cannot be constructed from `tests/` without Tor. It builds the struct literal with an unbootstrapped `TorClient` and a `NoDial` deliverer, and bridges `tokio::io::duplex` to `futures::io` with a 30-line adapter instead of adding a dev-dependency. Everything else is inside the two allowed new test files; no existing test was weakened or deleted. ## One test repair, not a product bug The first version of the retired-epoch case only called `clear_ratchet` and relied on the prekeys being unchanged; that is not deterministic, because a peer that re-derives the same bootstrap epoch can still follow the lineage by public-key order, and the test passed or failed depending on the random tie-break. It now changes the friend's recorded prekey (what a refreshed invite does, and what makes `Node::add_friend_payload` clear the session), which is deterministic. The product code was not changed: 20 consecutive runs of the Node-level tests and 15 consecutive runs of both new files pass. ## Evidence - `cargo test --locked --target x86_64-unknown-linux-gnu`: **288 passed, 0 failed, 4 ignored** across 32 test targets (baseline on `main` was 275 passed, 3 ignored — the delta is the 13 new tests; the 4 ignored are the pre-existing live-Tor cases). - `cargo clippy --locked --all-targets --target x86_64-unknown-linux-gnu -- -D warnings`: clean. ## Not verified - The live Tor path: `tests/two_node.rs` stays `#[ignore]`d; nothing here exercises a real onion, a real publish, or Arti's HS client against a remote service. - The Android SDK / Compose client and `crates/onionwire-sdk`: not touched, not built here. - The TUI: not exercised; these tests drive `Node`, not the widgets. - The wallet / payment frames: not exercised by this card. - Real radio: no packet loss, no reordering, no clock skew, no adversarial network. Frames are captured and released by hand. - The Double Ratchet's long-run behaviour beyond two DH steps: the PCS case walks exactly two round trips.
ratchet: end-to-end and adversarial tests on the wired send/receive path
All checks were successful
ci / test (pull_request) Successful in 4m54s
ci / sdk (pull_request) Successful in 1m0s
android-ci / android (pull_request) Successful in 9m26s
3620e4f38f
Drives the shipped chat ratchet offline against real SQLCipher stores and
the real encode/decode pair Node::send and Node::handle_incoming call, with
a capture-and-release Deliverer so arrival order and drops are controlled.

tests/ratchet_e2e.rs: full exchange, out-of-order arrival, a dropped frame,
a retried frame re-sent byte-identically, and a restart of both peers.

tests/ratchet_adversarial.rs: a frame claiming a jump past MAX_SKIP, a
post-compromise snapshot across a DH step, an unknown friend, a retired
epoch after an invite refresh, and five corruption shapes. Every rejected
frame is asserted to leave the persisted ratchet blob byte-identical.

src/node.rs gains a test-only module that builds a Node with an
unbootstrapped Tor client and drives Node::send plus the real receive path
(Noise IK handshake over an in-memory stream into handle_incoming).
sirius merged commit 1c998e9472 into main 2026-09-16 23:31:23 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
sirius/onionwire!88
No description provided.