Merge pull request 't_2fb507c6: F8 rotate prekey (Node::rotate_prekey + invite re-encode)' (#101) from wt/t_2fb507c6 into main
Reviewed-on: #101
This commit is contained in:
commit
24b5c93c43
7 changed files with 177 additions and 2 deletions
|
|
@ -136,6 +136,7 @@ Focus starts on the composer so typing works immediately. `Tab` cycles panes; `j
|
||||||
| `F4` | Rotate **onion** (locator only) |
|
| `F4` | Rotate **onion** (locator only) |
|
||||||
| `F5` | Selected friend's profile (`/who`) |
|
| `F5` | Selected friend's profile (`/who`) |
|
||||||
| `F6` | Wallet screen (receive QR, balance, transfers) |
|
| `F6` | Wallet screen (receive QR, balance, transfers) |
|
||||||
|
| `F8` | Rotate **prekey** (hard cut: every friend re-pastes the invite) |
|
||||||
| Enter | Send chat to the selected friend, or run a `/command` |
|
| Enter | Send chat to the selected friend, or run a `/command` |
|
||||||
| `Esc` | Close overlay / back to Main / clear composer |
|
| `Esc` | Close overlay / back to Main / clear composer |
|
||||||
| `Ctrl-Q` | Quit: type `CLEAR`+Enter to wipe history, `QUIT`+Enter to leave it, Esc to stay |
|
| `Ctrl-Q` | Quit: type `CLEAR`+Enter to wipe history, `QUIT`+Enter to leave it, Esc to stay |
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,8 @@ Each install holds:
|
||||||
- **Identity** — ed25519 keypair. The 32-byte public key **is** the person.
|
- **Identity** — ed25519 keypair. The 32-byte public key **is** the person.
|
||||||
Roster primary key. Displayed as 64 lowercase hex chars (the fingerprint).
|
Roster primary key. Displayed as 64 lowercase hex chars (the fingerprint).
|
||||||
- **Prekey** — x25519 keypair. This is the Noise IK *static*. It is long-lived
|
- **Prekey** — x25519 keypair. This is the Noise IK *static*. It is long-lived
|
||||||
in v1. Rotating the onion (`F4`) does **not** rotate it.
|
in v1 — rotate it with `F8`, which hard-cuts every stored session. Rotating
|
||||||
|
the onion (`F4`) does **not** rotate it.
|
||||||
- **Onion** — Tor v3 address. Locator only. Disposable.
|
- **Onion** — Tor v3 address. Locator only. Disposable.
|
||||||
|
|
||||||
A friend is `{identity_pk, current_onion, current_prekey_pk}`. Pasting the same
|
A friend is `{identity_pk, current_onion, current_prekey_pk}`. Pasting the same
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,10 @@ A signed `loc` frame (`onion`, `ts`, `sig`) rewrites a friend’s locator **only
|
||||||
|
|
||||||
`F4` changes the locator only. The identity key is unchanged. Anyone who already has your pubkey can still prove they are talking to you, and a later invite paste with the same `k` updates their row. To become a new person, `/wipe-all` (new identity key). There is no in-band unfriend/revoke in v1.
|
`F4` changes the locator only. The identity key is unchanged. Anyone who already has your pubkey can still prove they are talking to you, and a later invite paste with the same `k` updates their row. To become a new person, `/wipe-all` (new identity key). There is no in-band unfriend/revoke in v1.
|
||||||
|
|
||||||
|
## Rotating the prekey is a hard cut, and it is wider than F4
|
||||||
|
|
||||||
|
`F8` rotates the long-lived signed prekey. The identity key and the onion are unchanged, but the prekey is our Noise static **and** the seed of the bootstrap ratchet epoch, so once it moves nothing is reachable any more: a friend's dial uses the prekey they pinned from your invite, and their stored epoch is derived from the old one. There is no push path for a prekey — it only travels inside a signed invite — so every friend, online or offline, has to F3-paste the new invite before chat works in either direction again. F8 therefore also drops the local ratchet state for every friend, exactly as a peer's own prekey change does. Rotating the prekey shrinks the forward-secrecy window of the long-lived static; it is not a revocation (the old invite holder still learns nothing new, but they also cannot talk to you).
|
||||||
|
|
||||||
## Your store is encrypted
|
## Your store is encrypted
|
||||||
|
|
||||||
The sqlite store is SQLCipher (`rusqlite` feature `bundled-sqlcipher-vendored-openssl`).
|
The sqlite store is SQLCipher (`rusqlite` feature `bundled-sqlcipher-vendored-openssl`).
|
||||||
|
|
@ -128,7 +132,9 @@ device.
|
||||||
- *No one-time prekeys.* The bootstrap epoch uses the long-lived signed prekey
|
- *No one-time prekeys.* The bootstrap epoch uses the long-lived signed prekey
|
||||||
only, so there is no per-session prekey consumption. A peer prekey change
|
only, so there is no per-session prekey consumption. A peer prekey change
|
||||||
drops the state locally and the next chat frame re-bootstraps; there is no
|
drops the state locally and the next chat frame re-bootstraps; there is no
|
||||||
in-band reset and no key confirmation.
|
in-band reset and no key confirmation. The same is true of your **own**
|
||||||
|
prekey: `F8` rotates it, drops every stored state, and each friend has to
|
||||||
|
re-paste your invite, because a new prekey is never pushed.
|
||||||
- *A compromised endpoint is out of scope.* The ratchet state lives in the same
|
- *A compromised endpoint is out of scope.* The ratchet state lives in the same
|
||||||
SQLCipher file as the chat log, under the same passphrase. Anyone who opens
|
SQLCipher file as the chat log, under the same passphrase. Anyone who opens
|
||||||
the store holds the roots, both chain keys, the skipped keys and the plaintext
|
the store holds the roots, both chain keys, the skipped keys and the plaintext
|
||||||
|
|
|
||||||
79
src/node.rs
79
src/node.rs
|
|
@ -8,6 +8,7 @@ use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH};
|
||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
use futures::io::{AsyncRead, AsyncWrite};
|
use futures::io::{AsyncRead, AsyncWrite};
|
||||||
use hkdf::Hkdf;
|
use hkdf::Hkdf;
|
||||||
|
use rand::rngs::OsRng;
|
||||||
use sha2::Sha256;
|
use sha2::Sha256;
|
||||||
use tor_cell::relaycell::msg::Connected;
|
use tor_cell::relaycell::msg::Connected;
|
||||||
use tor_hsservice::{RunningOnionService, handle_rend_requests};
|
use tor_hsservice::{RunningOnionService, handle_rend_requests};
|
||||||
|
|
@ -877,6 +878,34 @@ impl Node {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Rotate the long-lived signed prekey (F8). Hard cut, like the locator
|
||||||
|
/// rotate: the prekey is our Noise static and the bootstrap ratchet epoch is
|
||||||
|
/// derived from the prekey DH, so every stored session is dead the moment
|
||||||
|
/// this returns and every friend has to F3-paste the new invite. Nothing is
|
||||||
|
/// pushed to peers — a new prekey only travels inside a signed invite. The
|
||||||
|
/// identity key (and therefore the fingerprint) does not move; the caller
|
||||||
|
/// re-encodes the F2 invite around the returned pubkey.
|
||||||
|
pub fn rotate_prekey(&self) -> Result<[u8; 32], String> {
|
||||||
|
let mut k = self.keys()?;
|
||||||
|
let sk = StaticSecret::random_from_rng(OsRng);
|
||||||
|
let pk = X25519Public::from(&sk).to_bytes();
|
||||||
|
{
|
||||||
|
let store = self.store.lock().map_err(|e| e.to_string())?;
|
||||||
|
// `replace_identity_keys` rewrites the prekey columns too; the
|
||||||
|
// identity values passed back are the ones already stored.
|
||||||
|
store
|
||||||
|
.replace_identity_keys(&k.identity_sk, &k.identity_pk, &sk.to_bytes(), &pk)
|
||||||
|
.map_err(|e| e.to_string())?;
|
||||||
|
for f in store.list_friends().map_err(|e| e.to_string())? {
|
||||||
|
store.clear_ratchet(&f.pubkey).map_err(|e| e.to_string())?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
k.prekey_sk = sk.to_bytes();
|
||||||
|
k.prekey_pk = pk;
|
||||||
|
*self.keys.lock().map_err(|e| e.to_string())? = k;
|
||||||
|
Ok(pk)
|
||||||
|
}
|
||||||
|
|
||||||
/// One-shot file to a friend. Fail closed; no outbox, no resume.
|
/// One-shot file to a friend. Fail closed; no outbox, no resume.
|
||||||
/// Chunks are paced (`file::CHUNK_PACE`) with bounded per-chunk retry so
|
/// Chunks are paced (`file::CHUNK_PACE`) with bounded per-chunk retry so
|
||||||
/// a 1 MiB transfer fits the receiver's rendezvous token bucket.
|
/// a 1 MiB transfer fits the receiver's rendezvous token bucket.
|
||||||
|
|
@ -1823,5 +1852,55 @@ mod tests {
|
||||||
"the sender's chat must show the tip they just paid"
|
"the sender's chat must show the tip they just paid"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// F8: rotate the long-lived signed prekey. The identity must not move, the
|
||||||
|
/// stored/dialed prekey must, every prekey-bound ratchet epoch must be
|
||||||
|
/// dropped, and the F2 invite must be re-encodable around the new prekey.
|
||||||
|
#[tokio::test]
|
||||||
|
async fn rotating_the_prekey_keeps_identity_and_drops_stale_ratchet_state() {
|
||||||
|
let dir = tempfile::tempdir().unwrap();
|
||||||
|
let node = offline_node(&dir.path().join("bob"), Arc::new(NoDial));
|
||||||
|
let peer = Keys::generate();
|
||||||
|
let old_identity = node.identity_pk();
|
||||||
|
let old_prekey = node_prekey(&node);
|
||||||
|
*node.onion.lock().unwrap() = format!("{}.onion", "a".repeat(56));
|
||||||
|
{
|
||||||
|
let store = node.store.lock().unwrap();
|
||||||
|
befriend(&store, &peer.identity_pk, &peer.prekey_pk, "peer.onion");
|
||||||
|
store
|
||||||
|
.save_ratchet(&peer.identity_pk, b"epoch-bound-to-the-old-prekey")
|
||||||
|
.expect("seed ratchet state");
|
||||||
|
}
|
||||||
|
|
||||||
|
let new_prekey = node.rotate_prekey().expect("rotate prekey");
|
||||||
|
|
||||||
|
assert_ne!(new_prekey, old_prekey, "the prekey must actually change");
|
||||||
|
assert_eq!(node_prekey(&node), new_prekey, "the live keys follow");
|
||||||
|
assert_eq!(
|
||||||
|
node.identity_pk(),
|
||||||
|
old_identity,
|
||||||
|
"identity = pubkey, it stays"
|
||||||
|
);
|
||||||
|
{
|
||||||
|
let store = node.store.lock().unwrap();
|
||||||
|
assert_eq!(
|
||||||
|
store.self_identity().unwrap().prekey_pk,
|
||||||
|
new_prekey.to_vec(),
|
||||||
|
"the self row carries the new prekey"
|
||||||
|
);
|
||||||
|
assert!(
|
||||||
|
store.load_ratchet(&peer.identity_pk).unwrap().is_none(),
|
||||||
|
"the bootstrap epoch is prekey-bound, so the stored state is stale"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
let payload = qr::decode(&node.qr_payload().expect("re-encode the invite"))
|
||||||
|
.expect("the re-encoded invite decodes");
|
||||||
|
assert_eq!(payload.signed_prekey, new_prekey.to_vec());
|
||||||
|
assert_eq!(
|
||||||
|
payload.pubkey,
|
||||||
|
old_identity.to_vec(),
|
||||||
|
"the new invite still names the same identity"
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
63
src/tui.rs
63
src/tui.rs
|
|
@ -491,6 +491,17 @@ Offline friends CANNOT find you until they F3-paste your new invite.\n\
|
||||||
Type ROTATE to confirm Esc to cancel"
|
Type ROTATE to confirm Esc to cancel"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// F8. Hard cut like the locator rotate: the prekey is our Noise static and the
|
||||||
|
/// ratchet bootstrap is derived from the prekey DH, so nothing short of a fresh
|
||||||
|
/// invite re-syncs a friend.
|
||||||
|
pub fn prekey_screen_text() -> &'static str {
|
||||||
|
"Rotate prekey?\n\
|
||||||
|
Your identity and onion stay the same.\n\
|
||||||
|
Every friend must F3-paste your new invite to pick up the new prekey,\n\
|
||||||
|
or you cannot reach them and they cannot reach you.\n\
|
||||||
|
Type ROTATE to confirm Esc to cancel"
|
||||||
|
}
|
||||||
|
|
||||||
pub fn quit_screen_text() -> &'static str {
|
pub fn quit_screen_text() -> &'static str {
|
||||||
"Quit OnionWire?\n\
|
"Quit OnionWire?\n\
|
||||||
Message history can be cleared; identity and friends stay.\n\
|
Message history can be cleared; identity and friends stay.\n\
|
||||||
|
|
@ -535,6 +546,7 @@ OnionWire keys\n\
|
||||||
F4 rotate onion locator\n\
|
F4 rotate onion locator\n\
|
||||||
F5 selected friend's profile (/who)\n\
|
F5 selected friend's profile (/who)\n\
|
||||||
F6 wallet (receive QR, create/import)\n\
|
F6 wallet (receive QR, create/import)\n\
|
||||||
|
F8 rotate prekey\n\
|
||||||
/profile edit name, bio, Monero address\n\
|
/profile edit name, bio, Monero address\n\
|
||||||
/pay <xmr> [memo] invoice to receive\n\
|
/pay <xmr> [memo] invoice to receive\n\
|
||||||
/tip <xmr> [memo] pay selected friend\n\
|
/tip <xmr> [memo] pay selected friend\n\
|
||||||
|
|
@ -1185,6 +1197,9 @@ enum Screen {
|
||||||
Rotate {
|
Rotate {
|
||||||
prompt: RotatePrompt,
|
prompt: RotatePrompt,
|
||||||
},
|
},
|
||||||
|
RotatePrekey {
|
||||||
|
prompt: RotatePrompt,
|
||||||
|
},
|
||||||
Wipe {
|
Wipe {
|
||||||
kind: WipeKind,
|
kind: WipeKind,
|
||||||
prompt: WipePrompt,
|
prompt: WipePrompt,
|
||||||
|
|
@ -1324,6 +1339,11 @@ impl App {
|
||||||
}
|
}
|
||||||
KeyCode::F(5) => self.who_open = true,
|
KeyCode::F(5) => self.who_open = true,
|
||||||
KeyCode::F(6) => self.open_wallet()?,
|
KeyCode::F(6) => self.open_wallet()?,
|
||||||
|
KeyCode::F(8) => {
|
||||||
|
self.screen = Screen::RotatePrekey {
|
||||||
|
prompt: RotatePrompt::new(),
|
||||||
|
};
|
||||||
|
}
|
||||||
KeyCode::Esc => self.composer.clear(),
|
KeyCode::Esc => self.composer.clear(),
|
||||||
KeyCode::Backspace => {
|
KeyCode::Backspace => {
|
||||||
if self.focus == Pane::Composer {
|
if self.focus == Pane::Composer {
|
||||||
|
|
@ -1443,6 +1463,18 @@ impl App {
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
},
|
},
|
||||||
|
Screen::RotatePrekey { prompt } => match key.code {
|
||||||
|
KeyCode::Esc => self.screen = Screen::Main,
|
||||||
|
KeyCode::Char(c) if !key.modifiers.contains(KeyModifiers::CONTROL) => {
|
||||||
|
if prompt.on_char(c) == RotateDecision::Confirm {
|
||||||
|
self.confirm_rotate_prekey()?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
KeyCode::Backspace => {
|
||||||
|
prompt.on_char('\u{8}');
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
},
|
||||||
Screen::Wipe { kind, prompt } => {
|
Screen::Wipe { kind, prompt } => {
|
||||||
let kind = *kind;
|
let kind = *kind;
|
||||||
match key.code {
|
match key.code {
|
||||||
|
|
@ -1715,6 +1747,24 @@ impl App {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// F8. Local and synchronous: nothing is pushed to peers — the new prekey
|
||||||
|
/// only travels inside a fresh signed invite — so the screen goes straight
|
||||||
|
/// to that invite (the F2 share path) for the user to hand out.
|
||||||
|
fn confirm_rotate_prekey(&mut self) -> Result<(), String> {
|
||||||
|
match self.node.rotate_prekey() {
|
||||||
|
Ok(_) => {
|
||||||
|
self.status_note =
|
||||||
|
Some("prekey rotated · friends must F3-paste your new invite".into());
|
||||||
|
self.open_share()
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
self.alert = Some(e);
|
||||||
|
self.screen = Screen::Main;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn open_share(&mut self) -> Result<(), String> {
|
fn open_share(&mut self) -> Result<(), String> {
|
||||||
let payload = self.node.qr_payload()?;
|
let payload = self.node.qr_payload()?;
|
||||||
self.screen = Screen::Share { payload };
|
self.screen = Screen::Share { payload };
|
||||||
|
|
@ -2092,6 +2142,7 @@ impl App {
|
||||||
Screen::Paste { buf, err } => draw_paste(f, buf, err.as_deref()),
|
Screen::Paste { buf, err } => draw_paste(f, buf, err.as_deref()),
|
||||||
Screen::Approve { payload } => draw_approve(f, payload),
|
Screen::Approve { payload } => draw_approve(f, payload),
|
||||||
Screen::Rotate { prompt } => draw_rotate(f, prompt.typed()),
|
Screen::Rotate { prompt } => draw_rotate(f, prompt.typed()),
|
||||||
|
Screen::RotatePrekey { prompt } => draw_rotate_prekey(f, prompt.typed()),
|
||||||
Screen::Wipe { kind, prompt } => draw_wipe(f, *kind, prompt.typed()),
|
Screen::Wipe { kind, prompt } => draw_wipe(f, *kind, prompt.typed()),
|
||||||
Screen::Profile { editor } => draw_profile(f, editor),
|
Screen::Profile { editor } => draw_profile(f, editor),
|
||||||
Screen::ConfirmKeys { kind, prompt, .. } => draw_confirm_keys(f, *kind, prompt.typed()),
|
Screen::ConfirmKeys { kind, prompt, .. } => draw_confirm_keys(f, *kind, prompt.typed()),
|
||||||
|
|
@ -2410,6 +2461,7 @@ match screen {
|
||||||
Screen::Paste { .. } => "Enter submit Esc back ? help",
|
Screen::Paste { .. } => "Enter submit Esc back ? help",
|
||||||
Screen::Approve { .. } => "y accept n reject ? help",
|
Screen::Approve { .. } => "y accept n reject ? help",
|
||||||
Screen::Rotate { .. } => "type ROTATE Esc cancel ? help",
|
Screen::Rotate { .. } => "type ROTATE Esc cancel ? help",
|
||||||
|
Screen::RotatePrekey { .. } => "type ROTATE Esc cancel ? help",
|
||||||
Screen::Wipe { kind, .. } => match kind {
|
Screen::Wipe { kind, .. } => match kind {
|
||||||
WipeKind::Messages => "type WIPE Esc cancel ? help",
|
WipeKind::Messages => "type WIPE Esc cancel ? help",
|
||||||
WipeKind::All => "type WIPEALL Esc cancel ? help",
|
WipeKind::All => "type WIPEALL Esc cancel ? help",
|
||||||
|
|
@ -2510,6 +2562,17 @@ fn draw_rotate(f: &mut Frame, typed: &str) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn draw_rotate_prekey(f: &mut Frame, typed: &str) {
|
||||||
|
let body = format!("{}\n\n{typed}", prekey_screen_text());
|
||||||
|
f.render_widget(
|
||||||
|
Paragraph::new(body)
|
||||||
|
.style(style_text())
|
||||||
|
.wrap(Wrap { trim: false })
|
||||||
|
.block(themed_block("(o) rotate prekey")),
|
||||||
|
f.area(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
fn draw_wipe(f: &mut Frame, kind: WipeKind, typed: &str) {
|
fn draw_wipe(f: &mut Frame, kind: WipeKind, typed: &str) {
|
||||||
let title = match kind {
|
let title = match kind {
|
||||||
WipeKind::Messages => "(o) wipe",
|
WipeKind::Messages => "(o) wipe",
|
||||||
|
|
|
||||||
|
|
@ -130,3 +130,27 @@ fn rotate_prompt_text_matches_spec() {
|
||||||
assert!(t.contains("Type ROTATE to confirm"));
|
assert!(t.contains("Type ROTATE to confirm"));
|
||||||
assert!(t.contains("Esc to cancel"));
|
assert!(t.contains("Esc to cancel"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn f8_prekey_rotation_screen_text_matches_spec() {
|
||||||
|
let t = onionwire::tui::prekey_screen_text();
|
||||||
|
assert!(t.contains("Rotate prekey?"));
|
||||||
|
assert!(t.contains("Your identity and onion stay the same."));
|
||||||
|
assert!(
|
||||||
|
t.contains("F3-paste"),
|
||||||
|
"the re-paste requirement is the whole point of the screen"
|
||||||
|
);
|
||||||
|
assert!(t.contains("Type ROTATE to confirm"));
|
||||||
|
assert!(t.contains("Esc to cancel"));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn f8_reuses_the_type_rotate_confirm_prompt() {
|
||||||
|
let mut p = RotatePrompt::new();
|
||||||
|
assert_eq!(p.on_esc(), RotateDecision::Cancel);
|
||||||
|
for c in "ROTA".chars() {
|
||||||
|
assert_eq!(p.on_char(c), RotateDecision::Pending);
|
||||||
|
}
|
||||||
|
assert_eq!(p.on_char('T'), RotateDecision::Pending);
|
||||||
|
assert_eq!(p.on_char('E'), RotateDecision::Confirm);
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -46,6 +46,7 @@ fn help_overlay_lists_core_bindings() {
|
||||||
"F4",
|
"F4",
|
||||||
"F5",
|
"F5",
|
||||||
"F6",
|
"F6",
|
||||||
|
"F8",
|
||||||
"send chat",
|
"send chat",
|
||||||
"/profile",
|
"/profile",
|
||||||
"/pay",
|
"/pay",
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue