From 6f267a6aba52ee68f88e437abf2ce3253bd16e17 Mon Sep 17 00:00:00 2001 From: agent Date: Thu, 17 Sep 2026 20:41:48 -0400 Subject: [PATCH 1/4] tests: assert the DH ratchet step in lockstep on a bidirectional burst `round_trip_across_two_dh_ratchet_steps` only asserts that neither sending ratchet key stayed put; it would still pass if the two sides stepped onto unconnected epochs, and it never checks that either peer adopted the key the other advertised. The new test reads dh_pub out of the wire header and pins the adoption per step across an A->B / B->A burst: - round 1 rotates only the lower-key (establishing) peer, so one round cannot lockstep both sides -- the intermediate state is asserted, not assumed; - rounds 2 and 3 step each side in turn, asserting each receiver adopts exactly the key the frame advertised; - the three-frame burst each way asserts chain reads (not extra steps), zero skipped keys, and that the peer that received last is keyed to the other's current key. tests/ratchet.rs only; no src change, no new dependency. --- tests/ratchet.rs | 124 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 124 insertions(+) diff --git a/tests/ratchet.rs b/tests/ratchet.rs index 3407afa..67a4095 100644 --- a/tests/ratchet.rs +++ b/tests/ratchet.rs @@ -147,6 +147,130 @@ fn round_trip_across_two_dh_ratchet_steps() { assert_eq!(a.decrypt(&m4).expect("decrypt m4"), b"m4"); } +/// The ratchet key a frame advertises: `dh_pub[0..32]` of the header. +fn dh_pub(frame: &[u8]) -> [u8; 32] { + header_at(frame)[..32].try_into().expect("32") +} + +/// Lockstep on a bidirectional burst: every frame after a peer has stepped +/// carries the key that peer is now sending with, and the receiver *adopts +/// exactly that key* before its sending chain rekeys. +/// +/// `round_trip_across_two_dh_ratchet_steps` only asserts that neither sending +/// ratchet stayed put; it would still pass if the two sides stepped onto +/// unconnected epochs, and it never checks that either side adopted the key the +/// other advertised. This test reads the key out of the wire header and asserts +/// the adoption, per step, on a burst in both directions. +/// +/// The bootstrap tie-break means one A→B/B→A round cannot step both sides: only +/// the lower-key peer rotates its sending chain on establishment, and the other +/// peer has still only ever seen bootstrap keys. The burst therefore drives the +/// second and third rounds, and pins the intermediate state at each one. +#[test] +fn bidirectional_burst_keeps_the_dh_ratchet_in_lockstep() { + let (mut a, mut b) = peers(); + let (a0, b0) = (a.public(), b.public()); + assert_eq!(a.remote_pub(), b0, "a starts keyed to b's bootstrap key"); + assert_eq!(b.remote_pub(), a0, "b starts keyed to a's bootstrap key"); + + // Round 1 — A→B then B→A. Only a rotates here (it sorts lower). + let m1 = a.encrypt(b"a/1").expect("encrypt"); + assert_eq!( + dh_pub(&m1), + a0, + "a's first frame advertises its bootstrap key" + ); + assert_eq!(b.decrypt(&m1).expect("b decrypts a/1"), b"a/1"); + assert_eq!(b.public(), b0, "b has no new key to adopt yet"); + assert_eq!(b.remote_pub(), a0); + + let m2 = b.encrypt(b"b/1").expect("encrypt"); + assert_eq!( + dh_pub(&m2), + b0, + "b's first frame advertises its bootstrap key" + ); + assert_eq!(a.decrypt(&m2).expect("a decrypts b/1"), b"b/1"); + let a1 = a.public(); + assert_ne!(a1, a0, "round 1 must rotate a's sending ratchet key"); + assert_eq!(a.remote_pub(), b0, "a is keyed to the key b advertised"); + + // Round 2 — a's fresh key reaches b, which is the step the one-round + // exchange never takes. + let m3 = a.encrypt(b"a/2").expect("encrypt"); + assert_eq!(dh_pub(&m3), a1, "a advertises the key it just ratcheted to"); + assert_eq!(b.decrypt(&m3).expect("b decrypts a/2"), b"a/2"); + let b1 = b.public(); + assert_ne!(b1, b0, "b must DH-ratchet on a's new key"); + assert_eq!(b.remote_pub(), a1, "b adopted exactly the key a advertised"); + + // Round 3 — the mirror image: b's fresh key reaches a. + let m4 = b.encrypt(b"b/2").expect("encrypt"); + assert_eq!(dh_pub(&m4), b1, "b advertises the key it just ratcheted to"); + assert_eq!(a.decrypt(&m4).expect("a decrypts b/2"), b"b/2"); + let a2 = a.public(); + assert_ne!(a2, a1, "a stepped onto a fresh key of its own"); + assert_eq!(a.remote_pub(), b1, "a adopted exactly the key b advertised"); + + // The burst proper: three frames each way on the epoch both sides now hold. + let to_b: Vec> = (0..3) + .map(|i| { + a.encrypt(format!("a/burst{i}").as_bytes()) + .expect("encrypt") + }) + .collect(); + for frame in &to_b { + assert_eq!(dh_pub(frame), a2, "the burst stays on a's current key"); + } + for (i, frame) in to_b.iter().enumerate() { + assert_eq!( + b.decrypt(frame).expect("burst a→b"), + format!("a/burst{i}").as_bytes() + ); + } + let b2 = b.public(); + assert_ne!( + b2, b1, + "b's first burst frame is a full step, not a chain read" + ); + assert_eq!(b.remote_pub(), a2, "b adopted a's burst key"); + assert_eq!(b.recv_index(), 3, "all three burst frames were consumed"); + assert_eq!(b.skipped_len(), 0, "in-order burst skipped nothing"); + + let to_a: Vec> = (0..3) + .map(|i| { + b.encrypt(format!("b/burst{i}").as_bytes()) + .expect("encrypt") + }) + .collect(); + for frame in &to_a { + assert_eq!(dh_pub(frame), b2, "the burst stays on b's current key"); + } + for (i, frame) in to_a.iter().enumerate() { + assert_eq!( + a.decrypt(frame).expect("burst b→a"), + format!("b/burst{i}").as_bytes() + ); + } + + // Lockstep after the burst: the peer that received last is keyed to the + // other's *current* key, and the sender's own key is the one its burst + // advertised. (b's view of a is a2 — a's step generated a3, which has not + // been sent yet; that lag is the ratchet's normal one-header asymmetry.) + assert_eq!(a.remote_pub(), b2); + assert_eq!(a.remote_pub(), b.public(), "a is keyed to b's current key"); + assert_eq!(b.remote_pub(), a2, "b is keyed to a's last advertised key"); + assert_ne!(a.public(), a2, "a stepped again on b's burst"); + assert_ne!(a.public(), a0, "a never ratcheted across the whole burst"); + assert_ne!(b.public(), b0, "b never ratcheted across the whole burst"); + assert_eq!(a.skipped_len(), 0); + assert_eq!(a.recv_index(), 3); + + // And the conversation still flows on the epoch the burst left behind. + let after = a.encrypt(b"a/after").expect("encrypt"); + assert_eq!(b.decrypt(&after).expect("a/after"), b"a/after"); +} + #[test] fn out_of_order_within_one_chain() { let (mut a, mut b) = peers(); From 1aec007601e61ebe81a731a9c2ce81da0faaf080 Mon Sep 17 00:00:00 2001 From: agent Date: Thu, 17 Sep 2026 20:43:31 -0400 Subject: [PATCH 2/4] ratchet: freeze the v1 state/frame wire format with guard tests The persisted ratchet state had a version byte and typed errors but no test that a format change would actually be caught. Add two dedicated guards to tests/ratchet.rs that assert the frozen shape as literals (0x01, 210-byte prefix) rather than via STATE_VERSION, so a bump breaks them visibly, and pin that any foreign version byte is rejected with Error::UnsupportedStateVersion before any field is read. Document the frozen v1 state layout, the rat frame layout, and the migration path a v2 must follow in references/ratchet-wire-frozen.md. Verified by flipping STATE_VERSION to 2: both guards fail ("the frozen version byte changed"), then revert. --- references/ratchet-wire-frozen.md | 101 ++++++++++++++++++++++++++++++ tests/ratchet.rs | 75 ++++++++++++++++++++++ 2 files changed, 176 insertions(+) create mode 100644 references/ratchet-wire-frozen.md diff --git a/references/ratchet-wire-frozen.md b/references/ratchet-wire-frozen.md new file mode 100644 index 0000000..89204f1 --- /dev/null +++ b/references/ratchet-wire-frozen.md @@ -0,0 +1,101 @@ +# Ratchet wire format — frozen at v1 + +Status: **frozen**. A change to the persisted ratchet state layout, or to the +`rat ` frame layout, is a wire-format break and needs a migration path (see +"Changing the format" below). The guard tests that enforce this live in +`tests/ratchet.rs`: + +- `ratchet_state_blob_is_frozen_at_version_v1` +- `ratchet_state_foreign_version_is_rejected_not_misread` + +Both are written to fail visibly on a version bump or a field insertion: +they assert the literal byte `0x01` and the literal 210-byte prefix length, +not the `STATE_VERSION` constant, so a bump cannot quietly follow them. + +## Persisted state (`ratchet_sessions.state`) + +Written by `RatchetState::to_bytes`, read by `RatchetState::from_bytes` +(`src/ratchet.rs`). The store treats the blob as opaque +(`Store::load_ratchet` / `Store::save_ratchet`, `src/store.rs`; the row is +`ratchet_sessions(state BLOB NOT NULL)` keyed by `friend_id`). There is no +public `decode_state` function in the crate: the persisted blob is decoded by +`RatchetState::from_bytes`, reached from `ratchet_for` in `src/node.rs`, and +the resulting version error is reported as `Error::UnsupportedStateVersion`. + +Layout — version `0x01`: + +``` +0 version byte 0x01 (STATE_VERSION) +1..33 root_key +33..65 local ratchet secret +65..97 local ratchet public +97..129 remote ratchet public +129..161 sending chain key +161..165 send_n u32 BE +165..197 receiving chain key +197..201 recv_n u32 BE +201..205 prev_send_len u32 BE +205 established (0 or 1) +206..210 skipped-key count u32 BE +210.. per skipped key, in insertion order: dh_pub[32] || n u32 BE || key[32] +``` + +The fixed prefix is **210 bytes** (pinned as `STATE_PREFIX_LEN` in the test); +the skipped-key tail is `68` bytes per key, capped at `MAX_SKIPPED_KEYS` +(2000). The blob contains secret key material — the caller owns wiping it. + +`from_bytes` is fail-closed on every malformed input it can see: a foreign +version byte returns `Error::UnsupportedStateVersion(byte)` *before* any field +is read, so a blob from another version is never decoded under the v1 layout; +empty, truncated, trailing-byte, bad-`established`-flag, bad skipped-count and +secret-does-not-match-its-public-key inputs return `Error::BadState(&str)`. +None of them panic or partially apply. + +## Frames (`rat ` chat frames) + +Written by `RatchetState::encrypt`, parsed by `Frame::parse` +(`src/ratchet.rs`). Framing constants: `FRAME_PREFIX = b"rat "`, +`FRAME_VERSION = 0x01`, `HEADER_LEN = 40`, `HEADER_OFFSET = 5`. + +``` +0..4 b"rat " +4 version byte 0x01 (FRAME_VERSION) +5..45 header: dh_pub[32] || N u32 BE || PN u32 BE +45..57 nonce[12] +57.. ciphertext || Poly1305 tag[16] (ChaCha20-Poly1305) +``` + +The 40-byte header is also the AEAD associated data, so any header edit fails +authentication rather than being silently ignored. `Frame::parse` checks the +prefix, then the minimum length (`HEADER_OFFSET + HEADER_LEN + 12 + 16 = 73`), +then the version byte; a sub-73-byte frame is a length error whatever its +version byte says, and a frame of 73 bytes or more with a foreign version is a +version error. Rejected frames leave the state byte-identical. + +## Changing the format + +There is **no migration code today**, and a version bump must not silently +re-bootstrap a session: replacing an unreadable stored session with a fresh +bootstrap produces traffic the peer cannot decrypt and loses the established +epoch. The required shape for a v2 is: + +1. Bump `STATE_VERSION` and make `from_bytes` keep the v1 decoder reachable + (match on the version byte, decode old blobs with the old layout, then + re-serialize as v2). +2. Do **not** let an older build read a newer blob: it must keep rejecting + anything that is not its own version with `UnsupportedStateVersion`, never + decode it under the old layout. That is what the current code does, and it + is why only the *newer* build may convert a blob in place. +3. Surface the refusal to the user. Today the message only reaches a log: + an outbound `Node::send` fails closed with `Err(String)` + (`ratchet state: unsupported ratchet state version N`, from + `ratchet_for`), and an inbound frame is dropped with + `eprintln!("rat dropped ({e})")` in `Node::handle_incoming`'s + `Kind::Ratchet` arm. There is no dialog and no automatic recovery; a v2 + must add the user-visible message rather than rely on stderr. +4. Keep the freeze tests green only by updating the pinned literals in + `tests/ratchet.rs` *and* the layout docs in this file in the same change. + +An additive change with no version bump is not an option: the skipped-key tail +is read by count, so appending a field changes what the tail means for every +stored blob. diff --git a/tests/ratchet.rs b/tests/ratchet.rs index 3407afa..138f431 100644 --- a/tests/ratchet.rs +++ b/tests/ratchet.rs @@ -372,6 +372,81 @@ fn state_round_trips_and_rejects_garbage() { assert!(RatchetState::from_bytes(&huge_count).is_err()); } +/// Fixed size of a v1 state blob's prefix: the version byte, the root key, the +/// local secret and public, the remote public, both chain keys, both counters, +/// `prev_send_len`, the established flag and the skipped-key count. +/// Documented in `src/ratchet.rs`'s `to_bytes` layout. +const STATE_PREFIX_LEN: usize = 1 + 32 + 32 + 32 + 32 + 32 + 4 + 32 + 4 + 4 + 1 + 4; + +/// Freeze guard for the persisted wire format. A stored session is only +/// meaningful if both sides agree byte for byte on the layout, so a version +/// bump or a field insertion must break this test on purpose. +/// +/// `0x01` is asserted as a literal: asserting `STATE_VERSION` would silently +/// follow a bump instead of catching it, which is the whole point of the +/// guard. +#[test] +fn ratchet_state_blob_is_frozen_at_version_v1() { + let local = RatchetKeyPair::from_secret([0x11u8; 32]); + let remote = RatchetKeyPair::from_secret([0x22u8; 32]); + let state = RatchetState::bootstrap(ROOT, local, remote.public()); + let bytes = state.to_bytes(); + + assert_eq!( + STATE_VERSION, 1, + "the frozen version byte changed: this is a wire-format break, not a refactor" + ); + assert_eq!( + bytes[0], 0x01, + "a state blob must start with the v1 version byte" + ); + assert_eq!( + bytes.len(), + STATE_PREFIX_LEN, + "the fixed part of the v1 layout changed (a field was added, removed or resized)" + ); + assert_eq!( + bytes.len(), + 210, + "the documented v1 prefix is 210 bytes; a different number means the \ + format moved and stored sessions need a migration path" + ); +} + +/// A blob written by another version must come back as a typed +/// `UnsupportedStateVersion`, never as a panic and never as a state decoded +/// under the wrong layout. The guard must also not be over-eager: the +/// untouched v1 blob still loads. +#[test] +fn ratchet_state_foreign_version_is_rejected_not_misread() { + let (mut a, mut b) = peers(); + // Decrypting m2 first leaves m0/m1 in the skipped store, so the blob is + // longer than the fixed prefix and the check cannot pass by luck. + let frames: Vec> = (0..3) + .map(|i| a.encrypt(format!("m{i}").as_bytes()).expect("encrypt")) + .collect(); + assert_eq!(b.decrypt(&frames[2]).expect("m2"), b"m2"); + let bytes = b.to_bytes(); + assert!( + bytes.len() > STATE_PREFIX_LEN, + "expected skipped keys in the blob, got {} bytes", + bytes.len() + ); + + for version in [0x00u8, 0x02, 0x7f, 0xff] { + let mut foreign = bytes.clone(); + foreign[0] = version; + assert_eq!( + RatchetState::from_bytes(&foreign).expect_err("a foreign version must be rejected"), + Error::UnsupportedStateVersion(version), + "version {version:#04x} must be rejected under its own code, not misread or panicked on" + ); + } + + let reloaded = RatchetState::from_bytes(&bytes).expect("the untouched v1 blob still loads"); + assert_eq!(reloaded.to_bytes(), bytes, "v1 round trip is not stable"); +} + /// Mirrors the private `MIN_FRAME_LEN` in `src/ratchet.rs` /// (`HEADER_OFFSET + HEADER_LEN + NONCE_LEN + TAG_LEN`), which the crate does /// not export. From dff37fe00e09b256b113ef96d2efd8c3a324c5b8 Mon Sep 17 00:00:00 2001 From: agent Date: Thu, 17 Sep 2026 20:44:28 -0400 Subject: [PATCH 3/4] docs+tui: reachability stance (no sealed mailbox) and peer-unreachable queued footer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add a Reachability section to docs/THREAT_MODEL.md: no sealed mailbox or server-side message store, the chat outbox is local-device retry only, and there is no mutual-online indicator — a send is a one-shot Noise IK session and an unanswered dial queues locally with the retry clock shown. OutboxSummary now carries the outstanding row's attempt count and soonest retry, so the footer reads 'peer unreachable, queued (n/8, retry 45s)' instead of a bare 'n queued'. Tests updated to the real outbox wording; the Android KDoc note stops claiming the footer copy is mirrored (Android shows per-row 'queued (try n/8, retry …)' via OutboxDetail). --- .../onionwire/ui/MessageDelivery.kt | 9 +++-- docs/THREAT_MODEL.md | 17 ++++++++-- src/tui.rs | 34 +++++++++++++++++-- tests/tui_spec.rs | 33 ++++++++++++++---- 4 files changed, 79 insertions(+), 14 deletions(-) diff --git a/android/app/src/main/java/com/siriusdevops/onionwire/ui/MessageDelivery.kt b/android/app/src/main/java/com/siriusdevops/onionwire/ui/MessageDelivery.kt index fcf3117..e82bb37 100644 --- a/android/app/src/main/java/com/siriusdevops/onionwire/ui/MessageDelivery.kt +++ b/android/app/src/main/java/com/siriusdevops/onionwire/ui/MessageDelivery.kt @@ -130,8 +130,13 @@ fun parseDelivery(direction: String, delivery: String?): Delivery? { /** * Chat-level delivery summary derived from the rendered rows. * - * Mirrors `src/tui.rs::OutboxSummary`: `Queued` + `Sending` are "still coming", - * `Failed` is terminal and keeps a fail-closed statement on screen. + * The *counting* rule mirrors `src/tui.rs::OutboxSummary`: `Queued` + `Sending` + * are "still coming", `Failed` is terminal and keeps a fail-closed statement on + * screen. The TUI's footer wording for an outstanding row also carries the + * reachability statement and retry clock (`peer unreachable, queued (n/8, retry + * 45s)`); on Android that per-row detail already lives in the row's own + * `queued (try n/8, retry …)` marker (`OutboxDetail.kt`), so the summary stays + * the short count form instead of repeating it. */ data class OutboxSummary( val queued: Int = 0, diff --git a/docs/THREAT_MODEL.md b/docs/THREAT_MODEL.md index 21ddb15..f4dea4e 100644 --- a/docs/THREAT_MODEL.md +++ b/docs/THREAT_MODEL.md @@ -66,6 +66,16 @@ A chat send to an unreachable onion is written to an `outbox` row next to its `m The queue is bounded in scope: chat only. File transfer and `rcp` frames are one-shot, so a failed payment claim does not sit in the store being retried forever. +## Reachability: there is no sealed mailbox, and no mutual-online indicator + +**No sealed mailbox.** OnionWire does not implement a server-side message store, a sealed mailbox, or any store-and-forward drop. There is no address a peer can write a message to when you are offline, and nothing that holds a message on your behalf after your device is gone. A mailbox of that kind needs a persistent process that accepts and later replays ciphertext for an absent recipient — exactly the hosted store-and-forward server this threat model rules out (“Tor relays are not a chat server”, “Out of v1”). A sealed box whose key never leaves the user's device is still a server holding the traffic pattern and the ciphertext, and it is still a third party that can be compelled, logged, or silently serve a stale box. That is the design decision, and it is not planned as a follow-up. + +**The chat outbox is local-device retry only.** A message to an unreachable peer is written to the local `outbox` row and re-dialed from this device. It dies with the device: no relay, no friend, no other install ever holds it. Nothing in the outbox is a delivery guarantee. + +**No mutual-online indicator.** OnionWire has no presence, no "peer is online" dot, and no shared online state. Every send is a one-shot Noise IK session to the peer's onion and is closed after one application frame; the peer's availability is only learned from whether *this* dial succeeded. A roster row we have not reached is marked `stale` (from the last connect attempt, `last_connect_ok`) and the footer states the consequence instead of implying presence: `peer unreachable, queued (n/8, retry …)` while an outbox row is outstanding. "They are offline right now" and "they have never been online since my last attempt" are indistinguishable to OnionWire, and the UI does not pretend otherwise. + +**What this costs, stated plainly.** Two devices that are never online at the same time cannot talk, and there is no queue that changes that — the sender's own device is the only queue. Anyone who needs offline delivery must run their own always-on OnionWire install (their own identity, their own onion) to hold the messages, which is a hosted server *they* own and operate, not a service OnionWire provides. + ## Chat is ratcheted on top of the one-shot Noise session The Noise IK session is still the transport: handshake, **one** application @@ -234,7 +244,8 @@ the peer already knows the plaintext they sent. ## Out of v1 -Prosody, XMPP, s2s, MAM, carbons, a **server-side** outbox / store-and-forward -relay, multi-device, DHT / name server, A/V. The local retry queue of the -previous section is not an outbox in the XMPP sense: it never leaves the device. +Prosody, XMPP, s2s, MAM, carbons, a **sealed mailbox**, a **server-side** +outbox / store-and-forward relay, multi-device, DHT / name server, A/V. The +local retry queue of the previous section is not an outbox in the XMPP sense: it +never leaves the device, and it is not a mailbox either — see “Reachability”. diff --git a/src/tui.rs b/src/tui.rs index d07b88c..3e27638 100644 --- a/src/tui.rs +++ b/src/tui.rs @@ -204,11 +204,22 @@ pub struct OutboxSummary { pub failed: usize, /// First terminal failure, for the fail-closed footer copy. pub first_error: Option, + /// Highest attempt count across outstanding rows (0 when nothing is + /// outstanding). With `DEFAULT_MAX_ATTEMPTS` this is the `n` in `(n/8)`. + pub attempts: u32, + /// Seconds until the earliest scheduled retry, relative to the render + /// `now`. `None` while nothing is outstanding. + pub next_in_secs: Option, } impl OutboxSummary { /// Footer note, or `None` when nothing is outstanding. Any terminal failure /// keeps a `send failed` statement so the fail-closed copy stays visible. + /// + /// An outstanding row is a reachability statement, not just a count: the + /// peer's onion did not answer *this* dial, so the note names that and the + /// retry it is waiting on (`peer unreachable, queued (n/8, retry 45s)`). + /// There is no mutual-online indicator to fall back on. pub fn note(&self) -> Option { let reason = || { short_send_reason( @@ -216,12 +227,19 @@ impl OutboxSummary { FAIL_REASON_BUDGET, ) }; + let queued = || { + format!( + "peer unreachable, queued ({}/{DEFAULT_MAX_ATTEMPTS}, {})", + self.attempts, + retry_in_text(self.next_in_secs.unwrap_or(0)) + ) + }; match (self.queued, self.failed) { (0, 0) => None, - (queued, 0) => Some(format!("{queued} queued")), (0, 1) => Some(format!("send failed: {}", reason())), (0, failed) => Some(format!("send failed: {} ({failed} failed)", reason())), - (queued, _) => Some(format!("{queued} queued, send failed: {}", reason())), + (_, 0) => Some(queued()), + (_, _) => Some(format!("{}, send failed: {}", queued(), reason())), } } } @@ -244,7 +262,17 @@ pub fn chat_with_delivery( summary.failed += 1; summary.first_error.get_or_insert_with(|| why.clone()); } - _ => summary.queued += 1, + _ => { + summary.queued += 1; + // The note is the reachability statement for the selected + // friend: highest attempt count, soonest scheduled retry. + summary.attempts = summary.attempts.max(entry.attempts); + let secs = entry.next_attempt_at - now; + summary.next_in_secs = Some(match summary.next_in_secs { + Some(prev) => prev.min(secs), + None => secs, + }); + } } } if msgs.is_empty() { diff --git a/tests/tui_spec.rs b/tests/tui_spec.rs index d81dd41..1718619 100644 --- a/tests/tui_spec.rs +++ b/tests/tui_spec.rs @@ -531,7 +531,10 @@ fn identical_bodies_join_by_message_id_not_body() { "delivered row (id 8) must keep its mark: {:?}", lines[1] ); - assert_eq!(summary.note().as_deref(), Some("1 queued")); + assert_eq!( + summary.note().as_deref(), + Some("peer unreachable, queued (1/8, retry 30s)") + ); } #[test] @@ -621,13 +624,19 @@ fn footer_summary_counts_queued_and_keeps_fail_closed() { queued: 2, failed: 0, first_error: None, + attempts: 3, + next_in_secs: Some(45), }; - assert_eq!(queued.note().as_deref(), Some("2 queued")); + assert_eq!( + queued.note().as_deref(), + Some("peer unreachable, queued (3/8, retry 45s)") + ); let failed = OutboxSummary { queued: 0, failed: 1, first_error: Some("connect peer.onion:80: connection timed out".into()), + ..OutboxSummary::default() }; let note = failed.note().expect("failed rows must produce a note"); assert!(note.starts_with("send failed:"), "{note:?}"); @@ -637,9 +646,15 @@ fn footer_summary_counts_queued_and_keeps_fail_closed() { queued: 3, failed: 1, first_error: Some("connect peer.onion:80: connection timed out".into()), + attempts: 2, + next_in_secs: Some(60), }; let mixed_note = mixed.note().expect("mixed rows must produce a note"); - assert!(mixed_note.contains("3 queued"), "{mixed_note:?}"); + assert!( + mixed_note.contains("queued (2/8, retry 1m)"), + "{mixed_note:?}" + ); + assert!(mixed_note.starts_with("peer unreachable"), "{mixed_note:?}"); assert!(mixed_note.contains("send failed"), "{mixed_note:?}"); // Fail-closed copy stays visible in the real footer at the 80-col floor. @@ -653,7 +668,10 @@ fn footer_summary_counts_queued_and_keeps_fail_closed() { assert!(line.contains("TOR") && line.contains("? help"), "{line:?}"); let queued_line = status_footer(80, FP, ONION, queued.note().as_deref(), main_footer_hints()); - assert!(queued_line.contains("2 queued"), "{queued_line:?}"); + assert!( + queued_line.contains("queued (3/8, retry 45s)"), + "{queued_line:?}" + ); assert!(queued_line.chars().count() <= 80); // `! ` ornament (colour off) still lands on the derived failing note. @@ -731,7 +749,7 @@ fn chat_and_footer_rows_fit_80x24_and_wrap_instead_of_clipping() { "long row was clipped, not wrapped:\n{screen}" ); assert!( - screen.contains("1 queued"), + screen.contains("peer unreachable, queued (3/8, retry 45s)"), "footer summary missing:\n{screen}" ); println!("===== AFTER outbox 80x24 (real draw_chat + status_footer) =====\n{screen}"); @@ -789,7 +807,10 @@ async fn renders_a_queued_row_from_a_real_outbox_send() { "real outbox row did not render: {:?}", lines[0] ); - assert_eq!(summary.note().as_deref(), Some("1 queued")); + assert_eq!( + summary.note().as_deref(), + Some("peer unreachable, queued (1/8, retry 45s)") + ); // And once a send crosses the circuit the row is gone, so the same message // renders as delivered. From bfbbdbf14f38a434899ad112f4a8e203296c9165 Mon Sep 17 00:00:00 2001 From: agent Date: Thu, 17 Sep 2026 20:57:50 -0400 Subject: [PATCH 4/4] ci: nightly cargo-fuzz job for fuzz/ (PR #103 harness) Add a job to .forgejo/workflows/ci.yml that builds the four libFuzzer targets on nightly (ratchet_frame, qr_decode, dispatch_classify, file_decode) and runs each for 15s. Own registry and target volumes (onionwire-cargo-registry-fuzz / onionwire-target-ci-fuzz), TMPDIR=/target/tmp, own concurrency group (onionwire-ci-pi-fuzz) so the ~12min cold build does not serialize the test/sdk jobs. Path allowlist extended with fuzz/** and scripts/run-fuzz.sh so fuzz-only PRs actually trigger it. Job is a no-op until PR #103 lands on main; the fuzz/ crate is a detached workspace that root cargo test/clippy never sees. --- .forgejo/workflows/ci.yml | 93 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) diff --git a/.forgejo/workflows/ci.yml b/.forgejo/workflows/ci.yml index d922dfe..a7176f0 100644 --- a/.forgejo/workflows/ci.yml +++ b/.forgejo/workflows/ci.yml @@ -17,6 +17,8 @@ on: - "Cargo.toml" - "Cargo.lock" - ".forgejo/workflows/ci.yml" + - "fuzz/**" + - "scripts/run-fuzz.sh" pull_request: paths: - "src/**" @@ -25,6 +27,8 @@ on: - "Cargo.toml" - "Cargo.lock" - ".forgejo/workflows/ci.yml" + - "fuzz/**" + - "scripts/run-fuzz.sh" workflow_dispatch: # One cargo job on the Pi at a time. Overlapping PR+main runs shared the @@ -44,6 +48,14 @@ env: # jobs' feature-unified artifacts. SDK_CARGO_TARGET_VOLUME: onionwire-target-ci-sdk SDK_BUILD_CONTAINER: onionwire-ci-sdk-${{ github.run_id }} + # The fuzz job builds on nightly with a release profile + debug=line-tables-only; + # it must not thrash the test/sdk target volumes and needs its own registry cache. + FUZZ_REGISTRY_VOLUME: onionwire-cargo-registry-fuzz + FUZZ_TARGET_VOLUME: onionwire-target-ci-fuzz + FUZZ_BUILD_CONTAINER: onionwire-ci-fuzz-${{ github.run_id }} + # libFuzzer writes its -fork dir into TMPDIR; point it at the target volume so + # a host tmpfs quota can't OOM-kill the builder. + FUZZ_TMP_DIR: /target/tmp jobs: test: @@ -65,6 +77,7 @@ jobs: -e CARGO_TARGET_DIR=/target \ -e CARGO_BUILD_JOBS=2 \ -e CARGO_TERM_COLOR=never \ + -e TMPDIR=/target/tmp \ -v "$CARGO_REGISTRY_VOLUME":/usr/local/cargo/registry \ -v "$CARGO_TARGET_VOLUME":/target \ -w /src \ @@ -105,6 +118,7 @@ jobs: -e CARGO_TARGET_DIR=/target \ -e CARGO_BUILD_JOBS=2 \ -e CARGO_TERM_COLOR=never \ + -e TMPDIR=/target/tmp \ -v "$CARGO_REGISTRY_VOLUME":/usr/local/cargo/registry \ -v "$SDK_CARGO_TARGET_VOLUME":/target \ -w /src \ @@ -119,3 +133,82 @@ jobs: --exclude=./crates/onionwire-sdk/target . \ | docker start -a -i "$SDK_BUILD_CONTAINER" docker rm -f "$SDK_BUILD_CONTAINER" > /dev/null + + # Nightly cargo-fuzz harness. The `fuzz/` crate (PR #103) is a detached + # workspace with four libFuzzer targets over the untrusted-input parsers — + # RatchetState::from_bytes/decrypt, qr::decode, dispatch::classify, file::decode. + # Nothing in CI ever compiles this crate, so the targets bit-rot silently: this + # job catches it. It only does something useful after PR #103 merges to main. + fuzz: + runs-on: docker + timeout-minutes: 120 + # The cold fuzz build (~12 min locally for the full Arti + SQLCipher + + # vendored-OpenSSL graph) can SERIALIZE other PRs with the same concurrency + # group. Give it its own group so a long fuzz build does not block the test/sdk + # jobs and the PRs that trigger them. + concurrency: + group: onionwire-ci-pi-fuzz + cancel-in-progress: false + steps: + - name: Checkout + uses: https://code.forgejo.org/actions/checkout@v4 + + - name: nightly toolchain + cargo-fuzz + run: | + set -euo pipefail + cd "${GITHUB_WORKSPACE}" + echo "workspace: $GITHUB_WORKSPACE" + docker volume create "$FUZZ_REGISTRY_VOLUME" > /dev/null + docker volume create "$FUZZ_TARGET_VOLUME" > /dev/null + docker rm -f "$FUZZ_BUILD_CONTAINER" > /dev/null 2>&1 || true + docker create --name "$FUZZ_BUILD_CONTAINER" -i \ + -e CARGO_TARGET_DIR=/target \ + -e CARGO_BUILD_JOBS=2 \ + -e CARGO_TERM_COLOR=never \ + -e TMPDIR=/target/tmp \ + -e RUSTUP_HOME=/usr/local/rustup \ + -e CARGO_HOME=/usr/local/cargo \ + -v "$FUZZ_REGISTRY_VOLUME":/usr/local/cargo/registry \ + -v "$FUZZ_TARGET_VOLUME":/target \ + -w /src \ + "$RUST_IMAGE" \ + sh -euxc 'mkdir -p /src && tar xzf - -C /src && cd /src \ + && apt-get update \ + && apt-get install -y --no-install-recommends pkg-config libssl-dev \ + && rustup toolchain install nightly --profile minimal \ + && rustup default nightly \ + && cargo install cargo-fuzz --locked \ + && export PATH="/usr/local/cargo/bin:$PATH" \ + && cd /src/fuzz \ + && cargo +nightly fuzz build \ + && cargo +nightly fuzz list' + tar czf - --exclude=./target --exclude=./.git --exclude=./.worktrees . \ + | docker start -a -i "$FUZZ_BUILD_CONTAINER" + + - name: run each fuzz target for 15s + run: | + set -euo pipefail + cd "${GITHUB_WORKSPACE}" + docker volume create "$FUZZ_REGISTRY_VOLUME" > /dev/null + docker volume create "$FUZZ_TARGET_VOLUME" > /dev/null + docker rm -f "$FUZZ_BUILD_CONTAINER" > /dev/null 2>&1 || true + docker create --name "$FUZZ_BUILD_CONTAINER" -i \ + -e CARGO_TARGET_DIR=/target \ + -e CARGO_BUILD_JOBS=2 \ + -e CARGO_TERM_COLOR=never \ + -e TMPDIR=/target/tmp \ + -e RUSTUP_HOME=/usr/local/rustup \ + -e CARGO_HOME=/usr/local/cargo \ + -e FUZZ_SECS=15 \ + -e FUZZ_JOBS=2 \ + -v "$FUZZ_REGISTRY_VOLUME":/usr/local/cargo/registry \ + -v "$FUZZ_TARGET_VOLUME":/target \ + -w /src \ + "$RUST_IMAGE" \ + sh -euxc 'mkdir -p /src && tar xzf - -C /src && cd /src \ + && export PATH="/usr/local/cargo/bin:$PATH" \ + && cd /src/fuzz \ + && bash /src/scripts/run-fuzz.sh' + tar czf - --exclude=./target --exclude=./.git --exclude=./.worktrees . \ + | docker start -a -i "$FUZZ_BUILD_CONTAINER" + docker rm -f "$FUZZ_BUILD_CONTAINER" > /dev/null