tui: mark friends invite-stale after an F8 prekey rotation
All checks were successful
ci / test (pull_request) Successful in 21m19s
ci / sdk (pull_request) Successful in 2m7s

F8 replaces the Noise static prekey and the ML-KEM key together and clears
every stored ratchet, but nothing recorded the cut: a friend on the roster
still held an invite with the old prekey, the next inbound frame could not be
decrypted, our own outbound re-bootstrapped an epoch they did not have, and the
send looked delivered. The only fix -- ask them to paste the new invite -- was
never said.

- `rotate_prekey` snapshots the roster into `$ONIONWIRE_HOME/invite-stale`
  (derived local state; no store schema change, no wire field, no new crate).
  `Node::invite_stale(pk)` / `invite_stale_friends()` answer the question, and
  an install that never rotated has no file and nothing marked.
- `Node::send` and `Node::send_once` fail closed with `invite stale` for a
  pre-rotation friend instead of silently re-bootstrapping past the cut.
- The roster gains its own `invite stale` word and colour token (violet; `stale`
  keeps meaning "the last dial did not answer"), and the alert row above the
  panes carries `invite stale -- F2 to share your new invite, they F3-paste it`,
  recomputed every draw so F3-pasting an invite for that friend clears it.
- `add_friend_payload` removes the pubkey from the set, which is the test the
  card asks for; docs/TUI.md documents the marker.

This makes the existing hard cut legible. It does not add in-band revocation or
a soft rotation; the threat model's hard-cut wording stays as it is.
This commit is contained in:
rust-dev 2026-10-22 23:38:30 -04:00
commit 9b53632859
No known key found for this signature in database
4 changed files with 436 additions and 20 deletions

View file

@ -16,11 +16,11 @@ use onionwire::outbox::{OutboxEntry, OutboxStatus};
use onionwire::qr;
use onionwire::tui::{
ChatRowStyle, FriendRow, MainView, Pane, TorPhase, backup_screen_text, banner_for_width,
cell_width, chat_no_friends_lines, chat_with_delivery, compact_banner, draw_main_chrome,
draw_share, draw_text_overlay, fingerprint_mismatch_banner, help_overlay_text,
main_footer_hints, onion_glyph, quit_screen_text, restore_screen_text, rotate_screen_text,
roster_line, status_footer, who_overlay_text, wipe_screen_text, wordmark_banner, ProfileEditor,
WipeKind,
cell_width, chat_no_friends_lines, chat_with_delivery, color_mode, compact_banner,
draw_main_chrome, draw_share, draw_text_overlay, fingerprint_mismatch_banner,
help_overlay_text, invite_stale_banner, main_footer_hints, onion_glyph, quit_screen_text,
restore_screen_text, rotate_screen_text, roster_line, status_footer, tokens_for,
who_overlay_text, wipe_screen_text, wordmark_banner, ProfileEditor, WipeKind,
};
use onionwire::{FriendProfile, Message};
use ratatui::Frame;
@ -91,12 +91,14 @@ fn friend_rows() -> Vec<FriendRow> {
label: "alice".into(),
fingerprint: "aaaaaaaaaaaaaaaa".into(),
stale: false,
invite_stale: false,
pq: true,
},
FriendRow {
label: "bob-the-stale-peer".into(),
fingerprint: "bbbbbbbbbbbbbbbb".into(),
stale: true,
invite_stale: false,
pq: true,
},
]
@ -108,6 +110,7 @@ fn a_legacy_friend_row_says_classical_in_the_roster() {
label: "alice".into(),
fingerprint: "aaaaaaaaaaaaaaaa".into(),
stale: false,
invite_stale: false,
pq: true,
};
let legacy = FriendRow {
@ -131,6 +134,129 @@ fn a_legacy_friend_row_says_classical_in_the_roster() {
);
}
/// F8 invalidates every friend's stored copy of our invite. That is a different
/// fact from "the last dial did not answer": the roster needs its own word, its
/// own colour token, and it must not borrow `stale` for it.
#[test]
fn an_invite_stale_friend_is_marked_apart_from_a_dial_stale_one() {
let row = FriendRow {
label: "alice".into(),
fingerprint: "aaaaaaaaaaaaaaaa".into(),
stale: false,
invite_stale: false,
pq: true,
};
let invite = FriendRow {
invite_stale: true,
..row.clone()
};
let dial = FriendRow {
stale: true,
..row.clone()
};
let text = |r: &FriendRow| -> String {
roster_line(r, 40)
.spans
.iter()
.map(|s| s.content.clone())
.collect()
};
let invite_text = text(&invite);
assert!(
invite_text.contains("invite stale"),
"a pre-rotation friend must say so in words: {invite_text:?}"
);
let dial_text = text(&dial);
assert!(
!dial_text.contains("invite stale"),
"a failed dial keeps the old marker and only that: {dial_text:?}"
);
assert!(dial_text.contains("stale"), "{dial_text:?}");
let invite_style = roster_line(&invite, 40).spans[0].style;
let tokens = tokens_for(color_mode());
assert_eq!(
invite_style, tokens.invite_stale,
"invite staleness owns a colour token, not the dial-stale one"
);
assert_ne!(tokens.invite_stale, tokens.stale);
}
/// The hint has to render in the same place as the fingerprint mismatch banner
/// (the fail-closed alert row above the panes) and fit 80 columns.
#[test]
fn the_invite_stale_hint_renders_above_the_panes_at_80_columns() {
let hint = invite_stale_banner();
assert!(
cell_width(hint) <= 80,
"the hint must fit 80 columns: {hint:?} is {}",
cell_width(hint)
);
assert!(hint.contains("invite stale"), "{hint:?}");
assert!(
hint.contains("F2") && hint.contains("F3"),
"the hint must point at sharing and re-pasting an invite: {hint:?}"
);
let friends = vec![
FriendRow {
label: "alice".into(),
fingerprint: "aaaaaaaaaaaaaaaa".into(),
stale: false,
invite_stale: true,
pq: true,
},
FriendRow {
label: "bob".into(),
fingerprint: "bbbbbbbbbbbbbbbb".into(),
stale: false,
invite_stale: false,
pq: true,
},
];
let chat = vec!["hi".to_string()];
let draw = |w: u16, h: u16| {
draw_frame(w, h, |f| {
draw_main_chrome(
f,
&MainView {
me_fp: FP,
me_onion: ONION,
phase: Some(TorPhase::Ready),
friends: &friends,
selected: 1,
focus: Pane::Chat,
chat_lines: &chat,
chat_style: ChatRowStyle::Text,
chat_name: Some("alice"),
chat_scroll: 0,
composer: "",
alert: Some(hint),
note: None,
},
)
})
};
// 80x24 is the audit size every rendered row must survive.
let narrow = draw(80, 24);
let narrow_screen = screen_of(&narrow, 80, 24);
for line in narrow_screen.lines().filter(|l| l.contains("invite")) {
println!("80-col line ({} cells): {line:?}", cell_width(line));
}
assert!(
narrow_screen.lines().nth(1).unwrap_or_default().contains("invite stale"),
"the hint belongs in the alert row: {narrow_screen}"
);
let wide = draw(120, 40);
let wide_screen = screen_of(&wide, 120, 40);
assert!(
wide_screen.contains("alice invite stale"),
"the row itself must carry the marker: {wide_screen}"
);
}
fn out_msg(id: i64, body: &str) -> Message {
Message {
id,