feat(store): encrypt chat bodies at rest; Ctrl-Q CLEAR/QUIT
All checks were successful
ci / test (pull_request) Successful in 3m13s

Wrap a random 32-byte message key with Argon2id+ChaCha20-Poly1305.
sqlite messages.plaintext is nonce||ciphertext; identity keys stay
plaintext. Empty/wrong passphrase fails closed. Ctrl-Q types CLEAR or
QUIT then Enter (Esc cancels).
This commit is contained in:
Sirius DevOps 2026-09-10 17:19:50 -04:00
commit 6323619d80
No known key found for this signature in database
16 changed files with 461 additions and 35 deletions

View file

@ -31,6 +31,15 @@ Offline friends CANNOT find you until they F3-paste your new invite.\n\
Type ROTATE to confirm Esc to cancel"
}
pub fn quit_screen_text() -> &'static str {
"Quit OnionWire?\n\
Message history can be cleared; identity and friends stay.\n\
This is not /wipe-all.\n\
Type CLEAR then Enter to clear history and quit.\n\
Type QUIT then Enter to quit without clearing.\n\
Esc to cancel"
}
/// Full Main-screen wordmark. Every line is <= 80 ASCII characters.
pub fn wordmark_banner() -> &'static str {
"\
@ -71,7 +80,7 @@ OnionWire keys\n\
/backup /path encrypted identity export\n\
/restore /path overwrite self keys\n\
? this help\n\
Ctrl-Q quit\n\
Ctrl-Q quit; type CLEAR or QUIT\n\
\n\
Esc closes this overlay"
}
@ -415,6 +424,52 @@ impl RotatePrompt {
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum QuitDecision {
Pending,
ClearAndQuit,
Quit,
Cancel,
}
#[derive(Debug, Default)]
pub struct QuitPrompt {
buf: String,
}
impl QuitPrompt {
pub fn new() -> Self {
Self::default()
}
pub fn on_esc(&self) -> QuitDecision {
QuitDecision::Cancel
}
pub fn on_char(&mut self, c: char) -> QuitDecision {
if c == '\n' {
return match self.buf.as_str() {
"CLEAR" => QuitDecision::ClearAndQuit,
"QUIT" => QuitDecision::Quit,
_ => QuitDecision::Pending,
};
}
if c == '\u{8}' {
self.buf.pop();
return QuitDecision::Pending;
}
if !c.is_ascii_alphabetic() {
return QuitDecision::Pending;
}
self.buf.push(c);
QuitDecision::Pending
}
pub fn typed(&self) -> &str {
&self.buf
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum BackupKind {
Backup,
@ -558,6 +613,9 @@ enum Screen {
first: Option<String>,
buf: String,
},
Quit {
prompt: QuitPrompt,
},
}
impl App {
@ -591,7 +649,12 @@ impl App {
continue;
}
if key.code == KeyCode::Char('q') && key.modifiers.contains(KeyModifiers::CONTROL) {
return Ok(AppExit::Quit);
if !matches!(self.screen, Screen::Quit { .. }) {
self.screen = Screen::Quit {
prompt: QuitPrompt::new(),
};
}
continue;
}
if let Some(exit) = self.handle_key(key)? {
return Ok(exit);
@ -624,6 +687,7 @@ impl App {
}
let mut wipe_confirm = None;
let mut quit_clear = None;
let mut profile_save = None;
let mut open_profile = false;
let mut pay_cmd = None;
@ -810,10 +874,31 @@ impl App {
}
_ => {}
},
Screen::Quit { prompt } => match key.code {
KeyCode::Esc => self.screen = Screen::Main,
KeyCode::Enter => match prompt.on_char('\n') {
QuitDecision::ClearAndQuit => quit_clear = Some(true),
QuitDecision::Quit => quit_clear = Some(false),
_ => {}
},
KeyCode::Backspace => {
prompt.on_char('\u{8}');
}
KeyCode::Char(c) if !key.modifiers.contains(KeyModifiers::CONTROL) => {
prompt.on_char(c);
}
_ => {}
},
}
if let Some(kind) = wipe_confirm {
return self.confirm_wipe(kind);
}
if let Some(clear) = quit_clear {
if clear {
self.node.wipe_messages()?;
}
return Ok(Some(AppExit::Quit));
}
if open_profile {
self.open_profile()?;
}
@ -1098,6 +1183,7 @@ impl App {
Screen::Passphrase {
kind, first, buf, ..
} => draw_passphrase(f, *kind, first.is_some(), buf),
Screen::Quit { prompt } => draw_quit(f, prompt.typed()),
}
if self.help_open {
draw_text_overlay(f, "? help", help_overlay_text());
@ -1242,7 +1328,10 @@ impl App {
fn chat_lines(&self) -> Vec<String> {
let Some(friend) = self.friends.get(self.selected) else {
return vec!["no friends yet".into(), "F3 paste an invite to add one".into()];
return vec![
"no friends yet".into(),
"F3 paste an invite to add one".into(),
];
};
match self.node.list_messages(&friend.pubkey) {
Ok(msgs) if msgs.is_empty() => vec!["no messages".into()],
@ -1342,6 +1431,7 @@ fn footer_hints(screen: &Screen) -> &'static str {
BackupKind::Restore => "type RESTORE Esc cancel ? help",
},
Screen::Passphrase { .. } => "Enter submit Esc cancel ? help",
Screen::Quit { .. } => "CLEAR or QUIT then Enter Esc cancel ? help",
}
}
@ -1428,6 +1518,17 @@ fn draw_wipe(f: &mut Frame, kind: WipeKind, typed: &str) {
);
}
fn draw_quit(f: &mut Frame, typed: &str) {
let body = format!("{}\n\n{typed}", quit_screen_text());
f.render_widget(
Paragraph::new(body)
.style(Style::default().fg(C_TEXT))
.wrap(Wrap { trim: false })
.block(themed_block("(o) quit")),
f.area(),
);
}
fn draw_profile(f: &mut Frame, editor: &ProfileEditor) {
let labels = ["name", "bio", "xmr"];
let values = [editor.display_name(), editor.bio(), editor.xmr_addr()];