onionwire/docs/THREAT_MODEL.md
agent f95c1e7ca7
docs: rewrite README and living docs to match the tree
Audit the operator docs against the source: pin downloads to v0.14.0,
document the real CLI/flags/env/F-keys (including F9, no F7), keep 18081
as the app-owned daemon port, describe the local chat outbox vs a
server-side one, and stop implying SECURITY_AUDIT.md is a third-party
audit. Spike reports stay; they get a status header only.
2026-09-20 00:31:07 -04:00

22 KiB
Raw Permalink Blame History

OnionWire threat model (v1)

OnionWire is a two-party chat over Tor onion services. There is no chat server. Identity is an ed25519 pubkey; the onion is a locator only (F4 rotates the locator, nothing else). Wire format: PROTOCOL.md. Wallet: WALLET.md. In-house review notes: SECURITY_AUDIT.md — not a public third-party audit. Do not cite that file as “audited.”

Tor relays are not a chat server

Each install hosts its own v3 onion and dials friends’ onions through in-process Arti. Relays move cells; they never see plaintext, never store messages, and never hold a roster. Compromising a relay is not compromising OnionWire’s message store. The store is the sqlite file on the endpoint.

Location updates are not a missing-person finder

A signed loc frame (onion, ts, sig) rewrites a friend’s locator only if that friend is already in the roster, the signature verifies against the pinned pubkey, and ts is newer. There is no directory, DHT, or introduction server. If you rotated while they were offline, they cannot find you until they F3-paste your new invite. OnionWire will not hunt for a missing person.

Rotating the onion does not revoke a friend

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

The sqlite store is SQLCipher (rusqlite feature bundled-sqlcipher-vendored-openssl). A 32-byte key is derived from the store passphrase with Argon2id (same params as identity backup) over a per-install 16-byte salt in store_salt, and handed to SQLCipher as a raw key (PRAGMA key = "x'…'") — no second KDF pass over it. The key is the first statement after open, so the file header, schema, identity secret key, friend public keys, locators, profiles, payment rows and the per-friend ratchet session blobs (ratchet_sessions) are all ciphertext on disk. There is no identity_sk-on-disk problem to work around because identity_sk is inside the encrypted file. A wrong or empty passphrase fails closed before any write; an encrypted store whose store_salt is missing refuses to open instead of guessing.

v0.2.1 installs have a plaintext db. The first open with the right passphrase upgrades it in place (ATTACH … KEY + sqlcipher_export after a WAL checkpoint), and swaps the file in only after the new file opens, passes integrity_check and unwraps store_meta. A wrong passphrase leaves the plaintext file untouched. The store_salt file is not secret (a salt never is).

Chat bodies carry a second, row-bound layer: ChaCha20-Poly1305 (nonce || ciphertext in messages.plaintext) with AAD owmsg1 || friend_id_le64 || dir || 0x00 || row_id_le64, plus a random 32-byte data key wrapped with Argon2id from the same passphrase (store_meta). Whole-db encryption does not stop someone who can write the file from moving one row's ciphertext into another row; the AAD does, and it stays. Unlock is fail-closed: wrong or empty passphrase does not open chat. Empty-AAD v0.2 blobs are rewrapped once on unlock; list_messages never falls back to empty AAD.

At-rest encryption is not a defense against a live compromise: while OnionWire runs, the passphrase, the db key and decrypted bodies are in process memory, and SQLCipher's page cache holds decrypted pages. It also does not stop an attacker who has your passphrase. /wipe deletes chat and payments history (overwrite message bodies, VACUUM, WAL checkpoint); roster and identity stay. It is not a forensic erase — SSD wear-leveling can keep copies. /wipe-all deletes the data dir (new identity); same disk caveat.

Fail closed

Peer onion down → a chat send is queued locally and retried (see “Local outbox (chat retry queue)”); file transfer and payment frames still fail immediately. Fingerprint mismatch vs the pinned key → hard fail, no send, never queued. Arti HS experimental: if it cannot publish, OnionWire stops; it does not fall back to C-tor.

Local outbox (chat retry queue) is local, and it re-dials on a schedule

A chat send to an unreachable onion is written to an outbox row next to its messages row and retried in the background. There is no server-side queue: a queued message is never handed to a third party, and it dies with the device. Two consequences are real and are accepted:

  • Device seizure. A pending (never-delivered) message sits in the same SQLCipher store as the rest of the history, under the same per-row AEAD and the same passphrase-derived key — no weaker, but also no shorter-lived. Seizure with the passphrase reveals messages that were never actually sent, including ones the sender may have moved on from; seizure without it reveals nothing in this store. /wipe clears outbox rows with the rest of chat history; /wipe-all removes them with the data dir. Neither is a forensic erase.
  • Retry cadence is a local traffic-analysis surface. A queued send re-dials the peer's onion on a backoff schedule while the app runs. An observer of your Tor client (or the network in front of it) sees a repeating connection attempt to one onion on a predictable cadence — it does not learn the plaintext or the recipient identity, but it can infer that you have an undelivered message for someone, and roughly when you composed it. The backoff is per-row, capped at one attempt per 30 min per message, and stops after 8 attempts or on a terminal failure.

The queue is bounded in scope: chat only. File transfer and rcp frames are one-shot, so a failed payment claim does not sit in the store being retried forever.

Reachability: there is no sealed mailbox, and no mutual-online indicator

No sealed mailbox. OnionWire does not implement a server-side message store, a sealed mailbox, or any store-and-forward drop. There is no address a peer can write a message to when you are offline, and nothing that holds a message on your behalf after your device is gone. A mailbox of that kind needs a persistent process that accepts and later replays ciphertext for an absent recipient — exactly the hosted store-and-forward server this threat model rules out (“Tor relays are not a chat server”, “Out of v1”). A sealed box whose key never leaves the user's device is still a server holding the traffic pattern and the ciphertext, and it is still a third party that can be compelled, logged, or silently serve a stale box. That is the design decision, and it is not planned as a follow-up.

The chat outbox is local-device retry only. A message to an unreachable peer is written to the local outbox row and re-dialed from this device. It dies with the device: no relay, no friend, no other install ever holds it. Nothing in the outbox is a delivery guarantee.

No mutual-online indicator. OnionWire has no presence, no "peer is online" dot, and no shared online state. Every send is a one-shot Noise IK session to the peer's onion and is closed after one application frame; the peer's availability is only learned from whether this dial succeeded. A roster row we have not reached is marked stale (from the last connect attempt, last_connect_ok) and the footer states the consequence instead of implying presence: peer unreachable, queued (n/8, retry …) while an outbox row is outstanding. "They are offline right now" and "they have never been online since my last attempt" are indistinguishable to OnionWire, and the UI does not pretend otherwise.

What this costs, stated plainly. Two devices that are never online at the same time cannot talk, and there is no queue that changes that — the sender's own device is the only queue. Anyone who needs offline delivery must run their own always-on OnionWire install (their own identity, their own onion) to hold the messages, which is a hosted server they own and operate, not a service OnionWire provides.

Chat is ratcheted on top of the one-shot Noise session

The Noise IK session is still the transport: handshake, one application frame, close, one circuit per message. Chat stacks a Double Ratchet inside that frame (rat , PROTOCOL.md), with per-friend state persisted in the encrypted store (ratchet_sessions). The ratchet changes what a stolen chat line is worth; it does not re-open any lock: no relay, no server-side queue, one frame per Noise session, and the ratchet state never leaves the device.

Gains.

  • Per-chain forward secrecy. Every message key is HMAC-SHA256(chain_key, 0x01) over a chain key that is replaced by HMAC-SHA256(chain_key, 0x02) after each message, so state recovered after a chain has moved on does not decrypt the messages already sent on it — outside the skipped-key window below.
  • Post-compromise security after a DH ratchet step. An attacker holding a snapshot of one side's state cannot read the conversation past the next DH ratchet step: that step feeds a fresh X25519 output into the root, and the snapshot stops producing chain keys. The window is not zero — it lasts until the next step — but no attacker can prevent it closing.
  • The ratchet header is not on the wire. dh_pub, N and PN ride inside the Noise ciphertext (authenticated as AEAD associated data), so message counts and ratchet-key changes are not observable, and a tampered header fails closed.

Honest limits.

  • Skipped-key window. Up to MAX_SKIP (2000) message keys of one chain, or up to MAX_SKIPPED_KEYS (2000) entries across a friend, stay decryptable to whoever holds the state until they are used (deleted on use) or evicted oldest-first. A snapshot also carries the current sending and receiving chain keys, which read the current chain until it advances. This is the price of out-of-order delivery, and it is per friend.
  • The bootstrap epoch is prekey-bound. The initial root and both initial ratchet secrets are HKDF outputs of the X25519 DH between the two long-lived signed prekeys, and the identity pubkeys that separate them are public. An attacker who has both peers' prekey statics can therefore reconstruct the first epoch. What that does not buy is a recorded message: every rat frame travels inside a one-shot Noise session whose ephemerals are not derived from the prekeys, so the prekeys alone do not open stored traffic. From the first DH ratchet step on, fresh X25519 secrets enter and the prekeys derive nothing — the bootstrap epoch is the exception, not the rule, and it is the reason the state is dropped when a peer's prekey changes.
  • No deniability and no non-repudiation claim. Chat frames are not signed and both parties derive the same chain keys, so nothing here would let a third party decide which of the two authored a chat line. Identity is proven per Noise session (the 96-byte proof), not per message.
  • 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 drops the state locally and the next chat frame re-bootstraps; there is no 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 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 history. /wipe clears chat, payments and outbox rows but keeps the ratchet state (roster and identity stay), so chat resumes on the same epoch; /wipe-all removes the data dir with it.
  • No metadata protection beyond Noise. One Noise session per message, no padding: sizes and timing are what they were before the ratchet.
  • The ratchet does not re-open the "no server-side outbox" lock. The state is device-local, one row per friend in the encrypted store, and nothing about it is transmitted. The local retry queue's two accepted consequences (device seizure, retry cadence) are unchanged.

Profile is friend-visible, not a directory

A signed prf frame is shown to people who already have a session with you. Apply only for existing friends. There is still no name lookup, DHT, or public profile server. Anyone who already has a Noise session can see the profile you send them; that is not confidentiality against that friend.

Payments are opt-in; spend is a local authority

Chat does not need a wallet. Payment frames (inv, rcp, tip) are signed claims over Noise: a signature proves which friend sent the claim, not that money moved. verified=1 only after a conjunctive match — one get_transfers row with the same non-empty txid, amount, and address. RPC down, error, or no exact row → stay verified=0. Subaddress reuse is the user’s wallet policy.

Default: no spend. No seed and no spend key on the device. Receive can use the profile xmr_addr, or a view-only wallet (create_address / get_transfers only). /tip is off (ONIONWIRE_WALLET_NO_SPEND, or a watch-only wallet detected over RPC via query_key spend_key → -29).

Spend is opt-in, at wallet create or restore, not a hidden default. A seed-backed spend-capable wallet makes OnionWire a local spend authority for that file: anyone with the wallet passphrase or the wallet-RPC credentials can move the balance, and /tip is a supported way for a chat peer to get paid. The spend-authority warning is unavoidable at that create/restore step. Loopback binding is not an authorization boundary. Back up the seed; do not leave a spend-capable wallet on a device you do not trust; a separate hot wallet with a small balance is the sane spend shape, not savings.

The app talks to monero-wallet-rpc over loopback HTTP Digest only (--rpc-login required; open RPC refused). That process may be one the user already runs, or one the app spawns. Wallet RPC is never dialed over clearnet or over .onion — a remote wallet RPC would move spend authority off the box through a channel the messenger’s --password gate does not cover.

Chain source is the user’s choice

Scan, receipt verification, and spend need a Monero daemon. The user picks one; the app does not pick a public remote node for them.

  1. Spawn a local monerod (pruned is the on-device target). Chain traffic stays on the device. The user accepts disk (tens of GB for a pruned mainnet node), first-sync time, and — on Android — process kills: the daemon is not always running. A pruned node is not an archive. Seed restore of deep history can degrade; once the wallet has scanned, its own cache is the history. Unsynced or not running is an honest “not ready” / unverified state, not a fake success.

  2. An in-process daemon (Cuprate, behind the cuprate-daemon feature, off by default). P2P, consensus and RandomX run in the OnionWire process; nothing is spawned and nothing leaves the device except the chain P2P traffic itself. What that changes: there is no daemon operator to trust — your own process is the daemon, so the "operator sees your addresses" question does not exist. The spend key, the chain, and the messenger are then all on one device. What it does not change: the device is now the trust root for chain data. Chain state is only as trustworthy as the binary running it, and a compromised device corrupts the chain view along with everything else. Honest limits, stated here rather than in a footnote:

    • Cuprate is pre-production. Its own user book says "do NOT use cuprated for any serious purposes", and its monerod RPC parity is incomplete (Cuprate issue #278). This is why the source is an opt-in build feature and a stored user choice, never a default.
    • Mainnet is unvalidated. The TUI can store a mainnet choice (F6 1/2); every in-process surface still says testnet only — mainnet is unvalidated. Cross-compiled is not device-proven.
    • Cuprate's own arti feature is off (its Tor stack is arti-client 0.44, which cannot unify with this crate's 0.46), so the in-process daemon's P2P traffic is clearnet: your ISP sees that this device talks to Monero peers. No Tor is on the chain path — Tor is the messenger's transport here, not the chain's.
    • Inbound P2P is off and the restricted RPC listener is disabled; the unrestricted RPC binds loopback only, and it is the address the wallet child dials. --trusted-daemon is still never passed.
    • The chain database is a separate embedded store (fjall) under the chain data directory, not the SQLCipher store the messenger writes — different file, different exposure: it is not encrypted by that store's key.
  3. A daemon address they supply. The wallet child points --daemon-address at that host. Trust follows the address:

    • Loopback — same privacy as (1); the user owns monerod.
    • .onion — chain traffic over Tor through a localhost SOCKS5 listener the app provides for the wallet child (not the messenger’s Arti connect(), and not a C-tor fallback for chat). That listener is the bundled arti binary run as a child (arti proxy -p <port>) — a second, separate Tor client with its own state and cache dirs, because arti-client 0.46 exposes no SOCKS listener API. It is TCP loopback only (arti proxy -p binds 127.0.0.1/::1; arti 2.6.0 / tor-config 0.46 have no Unix-socket listen target — arti#1965), and the port is usable by any local process at the user's privilege level: it is an app-private port, not an access-controlled one. The app gates the spawn on the unlocked store and waits ≤20s for the listener to accept before starting the wallet child, so a dead proxy fails visibly instead of hanging. The SOCKS child stops with the wallet child. Tor hides the transport. The daemon operator still sees the wallet’s addresses during sync. The host is the trust boundary.
    • Clearnet — only if the user typed it. Not a default, not implied. The ISP sees Monero-node traffic; the daemon operator sees addresses. Show that trust shift before using the address.

Remote daemons are untrusted (--trusted-daemon off). Setup, view-only vs spend, and RPC credentials: WALLET.md.

Backup file is the identity

/backup writes the identity and Noise static secrets. Treat the file like onionwire.db. Restore overwrites self keys and does not rewrite the friends table.

Rate limit is availability, not anonymity

Incoming rendezvous accepts are token-bucket limited (30/60s, burst 10). Excess is dropped without handshake. That is a DoS/availability control. It does not hide that you run an onion, and it is not a traffic-analysis defense. The constants are unchanged. Clients absorb the cost: file senders pace and retry chunks to fit this budget. The accept loop does not distinguish a friend from a flood.

Network (UDP / clearnet)

The application does not open UDP sockets and does not resolve friends via system DNS. Peer dials are Arti connect((onion, 80)) only.

Wallet RPC (HTTP Digest to monero-wallet-rpc) is loopback TCP only (numeric 127.0.0.1 / ::1 preferred; localhost still does getaddrinfo). That socket is the app talking to the wallet process, not to the chain.

Chain traffic is the wallet child’s connection to a Monero daemon. It is off unless the user opted into a wallet and chose a chain source: spawned local monerod (loopback), or a daemon address they entered. A .onion daemon is reached through a localhost SOCKS5 proxy used only by that wallet child: the bundled arti binary run as arti proxy -p <port>, whose --proxy target is 127.0.0.1 and whose .onion name travels inside the SOCKS request (Monero's SOCKS5 client sends the domain-name form, so no local DNS runs on it). The messenger's in-process Arti client is never handed to the wallet child. A clearnet daemon address is an explicit user choice — a clearnet socket they asked for — not the messenger path and not a hidden default.

Do not add STUN/ICE/WebRTC, a DHT, SOCKS/C-tor fallback for peer dials, or “direct TCP when the onion is slow.” Those are the Tox-over-Tor leak class. A SOCKS listener used only by the wallet child to reach a user-chosen .onion daemon is not that class.

Peer text is untrusted display data

Chat bodies and fil names come from a Noise peer, not from the local user. They are display data, not terminal commands. A friend (or anyone who stole that session) can put ESC/CSI/OSC, C1 controls, or bidi overrides in a payload. OnionWire strips those at ingest (so sqlite history is clean) and again at TUI render (so rows written before this rule stay inert). Filenames that contain the same characters are rejected, not rewritten. This is a UI-redressing / terminal-injection boundary, not a confidentiality control: the peer already knows the plaintext they sent.

Out of v1

Prosody, XMPP, s2s, MAM, carbons, a sealed mailbox, a server-side outbox / store-and-forward relay, multi-device, DHT / name server, A/V. The local retry queue of the previous section is not an outbox in the XMPP sense: it never leaves the device, and it is not a mailbox either — see “Reachability”.