onionwire/docs/THREAT_MODEL.md
Sirius DevOps 3adfc24391
All checks were successful
ci / test (pull_request) Successful in 10m31s
feat(store): encrypt the whole sqlite store with SQLCipher
The db held the ed25519 identity secret, friend pubkeys, locators, profiles
and payment rows in the clear; only chat bodies were encrypted. Switch
rusqlite to `bundled-sqlcipher-vendored-openssl` and open every store with
`PRAGMA key = "x'<64 hex>'"` as the first statement after open, using the
existing Argon2id output as a raw key (no second KDF pass).

The per-install KDF salt moves out of the db into `store_salt` (0600) — a key
cannot be derived from a salt that lives inside the file it opens. The
per-message ChaCha20-Poly1305 + row-AAD layer is unchanged: whole-db
encryption does not defend against ciphertext swapped between rows, the AAD
does.

v0.2.1 installs are plaintext. The first open with the right passphrase
upgrades in place (WAL checkpoint, ATTACH ... KEY, sqlcipher_export) and only
swaps the file after the new one opens, passes integrity_check and unwraps
store_meta. A wrong passphrase leaves the plaintext file untouched; a
missing `store_salt` next to an encrypted db refuses to open rather than
guessing.

SQLCipher's internal "hmac check failed" ERROR on a rejected key is
suppressed (cipher_log_level = NONE) so a typo'd passphrase is not an error
dump.

docs/THREAT_MODEL.md: the store is now encrypted at rest; sqlcipher leaves
the "Out of v1" list.
2026-09-12 13:00:18 -04:00

6.4 KiB
Raw Blame History

OnionWire threat model (v1)

OnionWire is a two-party chat over Tor onion services. There is no chat server. Wire format: PROTOCOL.md. In-house review notes: SECURITY_AUDIT.md — not a public third-party audit.

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.

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 and payment rows 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 → send fails. Fingerprint mismatch vs the pinned key → hard fail, no send. Arti HS experimental: if it cannot publish, OnionWire stops; it does not fall back to C-tor.

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.

Monero sidecar is not a wallet

OnionWire never holds spend keys. Optional ONIONWIRE_WALLET_RPC talks HTTP Digest to a user-hosted monero-wallet-rpc on loopback (--rpc-login required; open RPC is refused). A Noise friend can sign any rcp; the signature proves who sent the claim, not that a payment happened. verified=1 only after a conjunctive RPC match: one get_transfers row with the same non-empty txid, amount, and address. Incoming rcp stays verified=0 if RPC is down, errors, or no exact row. Subaddress reuse is the user’s wallet policy.

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. The one intentional clearnet socket is optional monero-wallet-rpc on loopback TCP (numeric loopback preferred; localhost still does getaddrinfo).

Do not add STUN/ICE/WebRTC, a DHT, SOCKS/C-tor fallback, or “direct TCP when the onion is slow.” Those are the Tox-over-Tor leak 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, outbox, multi-device, DHT / name server, A/V.