Add /wipe, /wipe-all, and threat model docs.

/wipe overwrites the message log and VACUUMs; identity and friends stay.
/wipe-all deletes the data dir after confirm so the next open is a new person.
Neither runs without a typed confirm screen.
This commit is contained in:
Sirius DevOps 2026-09-10 02:49:42 -04:00
commit 5412e020bb
No known key found for this signature in database
7 changed files with 415 additions and 18 deletions

View file

@ -23,6 +23,97 @@ Offline friends CANNOT find you until they rescan your QR.\n\
Type ROTATE to confirm Esc to cancel"
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum WipeKind {
Messages,
All,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum WipeDecision {
Pending,
Confirm,
Cancel,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum AppExit {
Quit,
WipeAll,
}
pub fn parse_slash(raw: &str) -> Option<WipeKind> {
match raw.trim() {
"/wipe" => Some(WipeKind::Messages),
"/wipe-all" => Some(WipeKind::All),
_ => None,
}
}
pub fn wipe_screen_text(kind: WipeKind) -> &'static str {
match kind {
WipeKind::Messages => {
"Wipe message log?\n\
Identity key and friends stay.\n\
Type WIPE to confirm Esc to cancel"
}
WipeKind::All => {
"Wipe ALL local data?\n\
This deletes your identity key. You become a new person.\n\
Type WIPEALL to confirm Esc to cancel"
}
}
}
#[derive(Debug)]
pub struct WipePrompt {
expected: &'static str,
buf: String,
}
impl WipePrompt {
pub fn messages() -> Self {
Self {
expected: "WIPE",
buf: String::new(),
}
}
pub fn all() -> Self {
Self {
expected: "WIPEALL",
buf: String::new(),
}
}
pub fn on_esc(&self) -> WipeDecision {
WipeDecision::Cancel
}
pub fn on_char(&mut self, c: char) -> WipeDecision {
if c == '\n' {
return WipeDecision::Pending;
}
if c == '\u{8}' {
self.buf.pop();
return WipeDecision::Pending;
}
if !c.is_ascii_alphabetic() {
return WipeDecision::Pending;
}
self.buf.push(c);
if self.buf == self.expected {
WipeDecision::Confirm
} else {
WipeDecision::Pending
}
}
pub fn typed(&self) -> &str {
&self.buf
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum RotateDecision {
Pending,
@ -68,7 +159,7 @@ impl RotatePrompt {
}
}
pub fn run(node: Arc<Node>, rt: tokio::runtime::Handle) -> Result<(), String> {
pub fn run(node: Arc<Node>, rt: tokio::runtime::Handle) -> Result<AppExit, String> {
let mut app = App::new(node, rt)?;
let mut terminal = ratatui::init();
let result = app.run(&mut terminal);
@ -86,6 +177,7 @@ struct App {
me_onion: String,
alert: Option<String>,
status_note: Option<String>,
composer: String,
}
enum Screen {
@ -94,6 +186,7 @@ enum Screen {
Paste { buf: String, err: Option<String> },
Approve { payload: QrPayload },
Rotate { prompt: RotatePrompt },
Wipe { kind: WipeKind, prompt: WipePrompt },
}
impl App {
@ -109,10 +202,11 @@ impl App {
selected: 0,
alert: None,
status_note: None,
composer: String::new(),
})
}
fn run(&mut self, terminal: &mut DefaultTerminal) -> Result<(), String> {
fn run(&mut self, terminal: &mut DefaultTerminal) -> Result<AppExit, String> {
loop {
terminal.draw(|f| self.draw(f)).map_err(|e| e.to_string())?;
let Event::Key(key) = event::read().map_err(io_err)? else {
@ -122,13 +216,16 @@ impl App {
continue;
}
if key.code == KeyCode::Char('q') && key.modifiers.contains(KeyModifiers::CONTROL) {
return Ok(());
return Ok(AppExit::Quit);
}
if let Some(exit) = self.handle_key(key)? {
return Ok(exit);
}
self.handle_key(key)?;
}
}
fn handle_key(&mut self, key: KeyEvent) -> Result<(), String> {
fn handle_key(&mut self, key: KeyEvent) -> Result<Option<AppExit>, String> {
let mut wipe_confirm = None;
match &mut self.screen {
Screen::Main => match key.code {
KeyCode::Up => {
@ -151,6 +248,23 @@ impl App {
prompt: RotatePrompt::new(),
};
}
KeyCode::Esc => self.composer.clear(),
KeyCode::Backspace => {
self.composer.pop();
}
KeyCode::Enter => {
if let Some(kind) = parse_slash(&self.composer) {
self.composer.clear();
let prompt = match kind {
WipeKind::Messages => WipePrompt::messages(),
WipeKind::All => WipePrompt::all(),
};
self.screen = Screen::Wipe { kind, prompt };
}
}
KeyCode::Char(c) if !key.modifiers.contains(KeyModifiers::CONTROL) => {
self.composer.push(c);
}
_ => {}
},
Screen::Share { .. } => {
@ -194,8 +308,38 @@ impl App {
}
_ => {}
},
Screen::Wipe { kind, prompt } => {
let kind = *kind;
match key.code {
KeyCode::Esc => self.screen = Screen::Main,
KeyCode::Char(c) if !key.modifiers.contains(KeyModifiers::CONTROL) => {
if prompt.on_char(c) == WipeDecision::Confirm {
wipe_confirm = Some(kind);
}
}
KeyCode::Backspace => {
prompt.on_char('\u{8}');
}
_ => {}
}
}
}
if let Some(kind) = wipe_confirm {
return self.confirm_wipe(kind);
}
Ok(None)
}
fn confirm_wipe(&mut self, kind: WipeKind) -> Result<Option<AppExit>, String> {
match kind {
WipeKind::Messages => {
self.node.wipe_messages()?;
self.status_note = Some("wiped messages".into());
self.screen = Screen::Main;
Ok(None)
}
WipeKind::All => Ok(Some(AppExit::WipeAll)),
}
Ok(())
}
fn confirm_rotate(&mut self) -> Result<(), String> {
@ -268,12 +412,18 @@ impl App {
Screen::Paste { buf, err } => draw_paste(f, buf, err.as_deref()),
Screen::Approve { payload } => draw_approve(f, payload),
Screen::Rotate { prompt } => draw_rotate(f, prompt.typed()),
Screen::Wipe { kind, prompt } => draw_wipe(f, *kind, prompt.typed()),
}
}
fn draw_main(&self, f: &mut Frame) {
let area = f.area();
let cols = Layout::vertical([Constraint::Min(1), Constraint::Length(1)]).split(area);
let cols = Layout::vertical([
Constraint::Min(1),
Constraint::Length(1),
Constraint::Length(1),
])
.split(area);
let body = if self.alert.is_some() {
Layout::vertical([Constraint::Length(1), Constraint::Min(1)]).split(cols[0])
} else {
@ -329,7 +479,13 @@ impl App {
truncate_fp(&self.me_fp),
onion
);
f.render_widget(Paragraph::new(status), cols[1]);
let cmd = if self.composer.is_empty() {
"/wipe /wipe-all".to_string()
} else {
self.composer.clone()
};
f.render_widget(Paragraph::new(cmd), cols[1]);
f.render_widget(Paragraph::new(status), cols[2]);
}
}
@ -377,6 +533,20 @@ fn draw_rotate(f: &mut Frame, typed: &str) {
);
}
fn draw_wipe(f: &mut Frame, kind: WipeKind, typed: &str) {
let title = match kind {
WipeKind::Messages => "/wipe",
WipeKind::All => "/wipe-all",
};
let body = format!("{}\n\n{typed}", wipe_screen_text(kind));
f.render_widget(
Paragraph::new(body)
.wrap(Wrap { trim: false })
.block(Block::default().borders(Borders::ALL).title(title)),
f.area(),
);
}
fn truncate_fp(fp: &str) -> String {
let s: String = fp.chars().take(8).collect();
format!("{s}…")