feat(store): encrypt chat bodies at rest; Ctrl-Q CLEAR/QUIT
All checks were successful
ci / test (pull_request) Successful in 3m13s
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:
parent
1d7f8e1f35
commit
6323619d80
16 changed files with 461 additions and 35 deletions
|
|
@ -1,7 +1,10 @@
|
|||
//! M5: wipe messages (keep identity + friends); wipe-all is a new person.
|
||||
|
||||
use onionwire::Store;
|
||||
use onionwire::tui::{WipeDecision, WipeKind, WipePrompt, parse_slash, wipe_screen_text};
|
||||
use onionwire::tui::{
|
||||
QuitDecision, QuitPrompt, WipeDecision, WipeKind, WipePrompt, parse_slash, quit_screen_text,
|
||||
wipe_screen_text,
|
||||
};
|
||||
|
||||
fn pk(tag: u8) -> [u8; 32] {
|
||||
let mut k = [0u8; 32];
|
||||
|
|
@ -19,7 +22,7 @@ fn db_contains(home: &std::path::Path, needle: &[u8]) -> bool {
|
|||
#[test]
|
||||
fn wipe_clears_messages_keeps_self_and_friends() {
|
||||
let dir = tempfile::tempdir().expect("tempdir");
|
||||
let store = Store::open_at(dir.path()).expect("open");
|
||||
let store = Store::open_at_with_passphrase(dir.path(), "onionwire-test").expect("open");
|
||||
let me = store.self_identity().unwrap();
|
||||
store
|
||||
.upsert_friend(&pk(1), "a.onion", Some("alice"))
|
||||
|
|
@ -51,7 +54,7 @@ fn wipe_clears_messages_keeps_self_and_friends() {
|
|||
fn wipe_all_removes_dir_so_next_open_is_new_identity() {
|
||||
let dir = tempfile::tempdir().expect("tempdir");
|
||||
let home = dir.path().join("ow");
|
||||
let store = Store::open_at(&home).expect("open");
|
||||
let store = Store::open_at_with_passphrase(&home, "onionwire-test").expect("open");
|
||||
let old_pk = store.self_identity().unwrap().identity_pk;
|
||||
store.upsert_friend(&pk(1), "a.onion", None).unwrap();
|
||||
store.append_message(&pk(1), "out", b"gone").unwrap();
|
||||
|
|
@ -61,7 +64,7 @@ fn wipe_all_removes_dir_so_next_open_is_new_identity() {
|
|||
Store::wipe_all(&home).expect("wipe-all");
|
||||
assert!(!home.exists(), "data dir gone");
|
||||
|
||||
let store2 = Store::open_at(&home).expect("reopen");
|
||||
let store2 = Store::open_at_with_passphrase(&home, "onionwire-test").expect("reopen");
|
||||
let new_pk = store2.self_identity().unwrap().identity_pk;
|
||||
assert_ne!(old_pk, new_pk, "new identity key = new person");
|
||||
assert_eq!(store2.friend_count().unwrap(), 0);
|
||||
|
|
@ -115,3 +118,39 @@ fn wipe_prompt_text_matches_spec() {
|
|||
assert!(a.contains("Type WIPEALL to confirm"));
|
||||
assert!(a.contains("Esc to cancel"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn quit_requires_clear_or_quit_then_enter() {
|
||||
let mut p = QuitPrompt::new();
|
||||
assert_eq!(p.on_esc(), QuitDecision::Cancel);
|
||||
assert_eq!(
|
||||
p.on_char('\n'),
|
||||
QuitDecision::Pending,
|
||||
"Enter alone must not quit"
|
||||
);
|
||||
for c in "CLEA".chars() {
|
||||
assert_eq!(p.on_char(c), QuitDecision::Pending);
|
||||
}
|
||||
assert_eq!(p.on_char('R'), QuitDecision::Pending, "CLEAR without Enter");
|
||||
assert_eq!(p.on_char('\n'), QuitDecision::ClearAndQuit);
|
||||
|
||||
let mut q = QuitPrompt::new();
|
||||
for c in "QUIT".chars() {
|
||||
assert_eq!(q.on_char(c), QuitDecision::Pending);
|
||||
}
|
||||
assert_eq!(q.on_char('\n'), QuitDecision::Quit);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn quit_prompt_text_matches_spec() {
|
||||
let t = quit_screen_text();
|
||||
assert!(
|
||||
t.contains("message history can be cleared")
|
||||
|| t.contains("Message history can be cleared")
|
||||
);
|
||||
assert!(t.contains("identity") && t.contains("friends"));
|
||||
assert!(t.contains("not") && t.contains("/wipe-all"));
|
||||
assert!(t.contains("CLEAR"));
|
||||
assert!(t.contains("QUIT"));
|
||||
assert!(t.contains("Esc"));
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue