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

@ -29,6 +29,9 @@ const C_TEXT: Color = Color::Rgb(196, 214, 176);
const C_DIM: Color = Color::Rgb(98, 110, 92);
const C_ALERT: Color = Color::Rgb(220, 80, 70);
const C_STALE: Color = Color::Rgb(210, 180, 80);
/// F8: the friend holds an invite with the pre-rotation prekey. Violet, not the
/// dial-stale amber — a stale invite is an exchange problem, not a dead peer.
const C_INVITE_STALE: Color = Color::Rgb(178, 128, 216);
const C_HL_BG: Color = Color::Rgb(48, 42, 28);
const C_BORDER: Color = Color::Rgb(72, 84, 64);
@ -403,6 +406,8 @@ pub struct TokenStyles {
pub alert: Style,
/// Stale data (unconfirmed, timed out).
pub stale: Style,
/// F8: the friend's copy of our invite predates the current prekey.
pub invite_stale: Style,
/// Border / chrome lines.
pub border: Style,
/// Highlight block (selected list row).
@ -438,6 +443,11 @@ pub fn tokens_for(mode: ColorMode) -> TokenStyles {
accent,
alert: rgb(C_ALERT, Color::Red),
stale: rgb(C_STALE, Color::Yellow),
invite_stale: match mode {
ColorMode::None => Style::default().add_modifier(Modifier::BOLD),
ColorMode::Ansi16 => Style::default().fg(Color::Magenta),
ColorMode::Rgb => Style::default().fg(C_INVITE_STALE),
},
border: rgb(C_BORDER, Color::DarkGray),
highlight,
}
@ -464,6 +474,10 @@ fn style_stale() -> Style {
tokens_for(color_mode()).stale
}
fn style_invite_stale() -> Style {
tokens_for(color_mode()).invite_stale
}
fn style_border() -> Style {
tokens_for(color_mode()).border
}
@ -493,6 +507,13 @@ pub fn fingerprint_mismatch_banner() -> &'static str {
"fingerprint mismatch"
}
/// The one-line hint for a friend whose invite predates our current prekey
/// (F8). Rendered in the same alert row as `fingerprint_mismatch_banner`, so the
/// user reads it where every other fail-closed sentence appears. Fits 80.
pub fn invite_stale_banner() -> &'static str {
"invite stale — F2 to share your new invite, they F3-paste it"
}
pub fn rotate_screen_text() -> &'static str {
"Rotate onion address?\n\
Your identity key stays the same.\n\
@ -1236,6 +1257,9 @@ struct App {
rt: tokio::runtime::Handle,
screen: Screen,
friends: Vec<Friend>,
/// Pubkeys whose invite predates our current prekey (F8), straight from
/// `Node::invite_stale_friends`. Refreshed with the roster, read on draw.
invite_stale: Vec<Vec<u8>>,
selected: usize,
me_fp: String,
me_onion: String,
@ -1823,6 +1847,7 @@ fn function_key_for(screen: &Screen, code: KeyCode) -> Option<FunctionKey> {
impl App {
fn new(node: Arc<Node>, rt: tokio::runtime::Handle) -> Result<Self, String> {
let friends = node.list_friends()?;
let invite_stale = node.invite_stale_friends();
// A fresh install has no wallet to pick and nothing to warn about yet,
// so it starts on the main view. The spend-authority warning is not
// weakened by this: every path where a user commits to creating or
@ -1847,6 +1872,7 @@ impl App {
rt,
screen,
friends,
invite_stale,
selected: 0,
alert: None,
status_note: None,
@ -2436,6 +2462,10 @@ impl App {
fn confirm_rotate_prekey(&mut self) -> Result<(), String> {
match self.node.rotate_prekey() {
Ok(_) => {
// Every friend on the roster just became "invite stale"; the
// markers have to be on the roster before the share screen
// opens, not after the next friend-list refresh.
self.reload_friends()?;
self.status_note =
Some("prekey rotated · friends must F3-paste your new invite".into());
self.open_share()
@ -3141,6 +3171,7 @@ impl App {
fn reload_friends(&mut self) -> Result<(), String> {
self.friends = self.node.list_friends()?;
self.invite_stale = self.node.invite_stale_friends();
if self.friends.is_empty() {
self.selected = 0;
} else {
@ -3409,7 +3440,12 @@ impl App {
fn draw_main(&self, f: &mut Frame) {
let phase = Some(TorPhase::of(self.node.tor_state()));
let (chat_lines, summary, chat_style) = self.chat_view(phase);
let rows: Vec<FriendRow> = self.friends.iter().map(friend_row).collect();
let invite_set = &self.invite_stale;
let rows: Vec<FriendRow> = self
.friends
.iter()
.map(|f| friend_row(f, invite_set.iter().any(|pk| pk == &f.pubkey)))
.collect();
let chat_name = self.friends.get(self.selected).map(|friend| {
friend
.petname
@ -3420,10 +3456,20 @@ impl App {
// The outbox is the source of truth while anything is outstanding; the
// transient note still covers "sending", "sent file x", "invoice sent".
let mut note = summary.note().or_else(|| self.status_note.clone());
// F8's cut is a standing fact about the selected friend, not a transient
// error: with nothing else failing, the alert row carries the sentence
// that turns it into an action. It clears with the marker (a re-pasted
// invite), so it is recomputed every draw rather than set once.
let invite_hint = self
.friends
.get(self.selected)
.filter(|f| self.invite_stale.iter().any(|pk| pk == &f.pubkey))
.map(|_| invite_stale_banner());
let alert = self.alert.as_deref().or(invite_hint);
// The alert row above the panes is the error channel. When it already
// carries the same sentence, drop it from the footer: one statement of a
// failure, in the place the eye goes for errors.
if note.as_deref() == self.alert.as_deref() {
if note.as_deref() == alert {
note = None;
}
let view = MainView {
@ -3438,7 +3484,7 @@ impl App {
chat_name: chat_name.as_deref(),
chat_scroll: self.chat_scroll,
composer: &self.composer,
alert: self.alert.as_deref(),
alert,
note: note.as_deref(),
};
draw_main_chrome(f, &view);
@ -3470,12 +3516,20 @@ impl App {
}
}
/// One roster row: the label, the fingerprint, and the word `stale` when the
/// last dial did not answer. Colour is what the row is (text vs stale), never a
/// decoration — the word carries the state on a monochrome terminal.
/// One roster row: the label, the fingerprint, and the state word — `stale`
/// when the last dial did not answer, `invite stale` when F8 replaced the prekey
/// the friend still holds. Colour is what the row is (text / dial stale / invite
/// stale), never a decoration — the word carries the state on a monochrome
/// terminal.
pub fn roster_line(row: &FriendRow, inner_width: u16) -> Line<'static> {
let text = roster_row_text(row, inner_width);
let style = if row.stale { style_stale() } else { style_text() };
let style = if row.invite_stale {
style_invite_stale()
} else if row.stale {
style_stale()
} else {
style_text()
};
Line::from(Span::raw(text).style(style))
}
@ -3750,6 +3804,9 @@ pub struct FriendRow {
pub fingerprint: String,
/// Last dial to this peer's onion did not answer.
pub stale: bool,
/// The friend's recorded invite predates our current prekey (F8): their
/// next inbound frame cannot be decrypted until they paste the new invite.
pub invite_stale: bool,
/// Friend row has an ML-KEM key (v2 invite). `false` means sessions to
/// this friend are the classical `onionwire-v1` transport, and the roster
/// says so in words — no pretending it is hybrid.
@ -3757,12 +3814,14 @@ pub struct FriendRow {
}
/// The roster row for one friend, fitted to the pane's inner width in cells.
pub fn friend_row(friend: &Friend) -> FriendRow {
/// `invite_stale` is `Node::invite_stale`'s answer for this pubkey.
pub fn friend_row(friend: &Friend, invite_stale: bool) -> FriendRow {
let raw = friend.petname.as_deref().unwrap_or(&friend.fingerprint);
FriendRow {
label: sanitize::display_text(raw.as_bytes()).to_string(),
fingerprint: friend.fingerprint.clone(),
stale: !friend.last_connect_ok,
invite_stale,
pq: friend.kem_pk.is_some(),
}
}
@ -5557,10 +5616,14 @@ fn truncate_fp(fp: &str) -> String {
fn roster_row_text(row: &FriendRow, inner_width: u16) -> String {
let budget = (inner_width as usize).saturating_sub(2);
let stale_s = if row.stale { " stale" } else { "" };
// F8's cut is not a failed dial: its own word, beside `stale` when both are
// true (the invite is old *and* the last dial timed out).
let invite_s = if row.invite_stale { " invite stale" } else { "" };
// A legacy v1 friend has no PQ transport; say the word rather than let the
// roster imply protection it does not have.
let pq_s = if row.pq { "" } else { " classical" };
let avail = budget.saturating_sub(cell_width(stale_s) + cell_width(pq_s));
let avail =
budget.saturating_sub(cell_width(stale_s) + cell_width(invite_s) + cell_width(pq_s));
// The name is what the reader is looking for. The fingerprint only
// disambiguates two friends with the same petname, so it gets what is left
// and is dropped entirely when the pane is too narrow to show a usable
@ -5576,7 +5639,7 @@ fn roster_row_text(row: &FriendRow, inner_width: u16) -> String {
} else {
(fit_cells(&row.label, avail), String::new())
};
fit_cells(&format!("{shown}{fp_part}{pq_s}{stale_s}"), budget)
fit_cells(&format!("{shown}{fp_part}{pq_s}{invite_s}{stale_s}"), budget)
}
fn to_hex(bytes: &[u8]) -> String {