transport: ML-KEM-768 hybrid prelude and onionwire:v2 invites
Adds an ML-KEM-768 install key beside the ed25519 identity and x25519 prekey. A friend added from a v2 invite always gets a version-2 PQ prelude before Noise msg 1, and both sides bind (ct, ss_kem) into the Noise prologue (onionwire-v2 \0 ct \0 ss_kem). The row decides: a kem_pk friend without a prelude is rejected with 'prelude required', a prelude for a classical row with 'unexpected prelude'. Invites are now onionwire:v2 with kem=<base64url pk>; decode still accepts v1 (no kem) and yields a classical friend. F8 rotates the KEM key with the prekey and hard-cuts stored ratchet state. The TUI labels a legacy friend 'classical'. Docs: PROTOCOL (keys, framing, prologues, no-downgrade, invite v2), THREAT_MODEL (what PQ transport does and does not buy; epoch 0 stays classical), README (invite size, F8, legacy caveat). SDK exposes pq on InviteInfo/FriendInfo and gains a v2 decode round-trip test.
This commit is contained in:
parent
00bb95675f
commit
c741b660e4
26 changed files with 1637 additions and 177 deletions
120
docs/PROTOCOL.md
120
docs/PROTOCOL.md
|
|
@ -4,8 +4,9 @@ This is the wire protocol. A second implementation should be able to
|
|||
interoperate from this document without reading the Rust.
|
||||
|
||||
It is **not** an IETF RFC. It describes what this repository speaks today
|
||||
(frame version 1, invite scheme `onionwire:v1`). There has been no public
|
||||
third-party audit. Arti onion services are experimental upstream.
|
||||
(frame versions 1 and 2, invite schemes `onionwire:v2` (emit) and
|
||||
`onionwire:v1` (decode only)). There has been no public third-party audit.
|
||||
Arti onion services are experimental upstream.
|
||||
|
||||
Related: [threat model](THREAT_MODEL.md), [audit notes](SECURITY_AUDIT.md).
|
||||
|
||||
|
|
@ -32,13 +33,20 @@ Each install holds:
|
|||
- **Identity** — ed25519 keypair. The 32-byte public key **is** the person.
|
||||
Roster primary key. Displayed as 64 lowercase hex chars (the fingerprint).
|
||||
- **Prekey** — x25519 keypair. This is the Noise IK *static*. It is long-lived
|
||||
in v1 — rotate it with `F8`, which hard-cuts every stored session. Rotating
|
||||
the onion (`F4`) does **not** rotate it.
|
||||
— rotate it with `F8`, which hard-cuts every stored session. Rotating the
|
||||
onion (`F4`) does **not** rotate it.
|
||||
- **KEM key** — ML-KEM-768 (FIPS 203) keypair. The 1184-byte encapsulation key
|
||||
travels in a v2 invite as `kem=`; the 64-byte decapsulation seed lives in the
|
||||
SQLCipher store beside `identity_sk`. `F8` rotates it together with the
|
||||
prekey, with the same hard cut (stored ratchet state is dropped and every
|
||||
friend re-pastes the invite).
|
||||
- **Onion** — Tor v3 address. Locator only. Disposable.
|
||||
|
||||
A friend is `{identity_pk, current_onion, current_prekey_pk}`. Pasting the same
|
||||
identity `k` updates the locator (and prekey) on that row. It never creates a
|
||||
second person.
|
||||
A friend is `{identity_pk, current_onion, current_prekey_pk, kem_pk?}`. Pasting
|
||||
the same identity `k` updates the locator, prekey and KEM key on that row. It
|
||||
never creates a second person. `kem_pk` is absent only for a friend added from
|
||||
a legacy `onionwire:v1` invite; such a friend is **classical** (see
|
||||
[No downgrade](#no-downgrade)).
|
||||
|
||||
Petnames, chat history, and the optional Monero wallet RPC are local. They are
|
||||
not on the wire.
|
||||
|
|
@ -72,11 +80,18 @@ Excess is dropped before handshake. That is availability, not anonymity.
|
|||
Every Noise handshake message and every ciphertext is wrapped:
|
||||
|
||||
```
|
||||
uint8 version = 1
|
||||
uint8 version = 1 (normal) | 2 (PQ handshake prelude)
|
||||
uint32 length = big-endian body length
|
||||
uint8 body[length]
|
||||
```
|
||||
|
||||
- `version = 1` is Noise msg 1, msg 2, an identity proof, or one application
|
||||
ciphertext. It is unchanged from v1 of this document.
|
||||
- `version = 2` is the **PQ handshake prelude**. Its body is `uint16 ct_len`
|
||||
(big-endian) followed by exactly `ct_len` bytes of ML-KEM-768 ciphertext.
|
||||
`ct_len` MUST be 1088. The prelude may only be the first frame of a session;
|
||||
the initiator sends exactly one, then Noise msg 1 with `version = 1`.
|
||||
`read_frame` (used after the opening frame) rejects `version = 2`.
|
||||
- `length` MUST be ≤ 65535. Check the length **before** allocating the body.
|
||||
- Other `version` values are a hard fail (close the stream).
|
||||
- Length that does not match the bytes on the wire is a hard fail.
|
||||
|
|
@ -85,21 +100,42 @@ uint8 body[length]
|
|||
|
||||
Noise pattern: `Noise_IK_25519_ChaChaPoly_BLAKE2s`
|
||||
|
||||
Prologue (both sides, before the first handshake message): `onionwire-v1`
|
||||
(13 ASCII bytes, no NUL).
|
||||
Prologue (both sides, before the first Noise handshake message):
|
||||
|
||||
- **Classical** (no PQ prelude, friend row has no `kem_pk`): `onionwire-v1`
|
||||
(12 ASCII bytes, no NUL).
|
||||
- **Hybrid** (a PQ prelude was sent/received): the exact byte layout
|
||||
|
||||
```
|
||||
"onionwire-v2" || 0x00 || ct || 0x00 || ss_kem
|
||||
```
|
||||
|
||||
where `onionwire-v2` is 12 ASCII bytes, `ct` is the 1088-byte ML-KEM-768
|
||||
ciphertext from the prelude, and `ss_kem` is the 32-byte shared secret.
|
||||
Initiator: `(ct, ss_kem) = ML-KEM-768.Encapsulate(friend.kem_pk)`.
|
||||
Responder: `ss_kem = ML-KEM-768.Decapsulate(own_dk, ct)`. Both therefore
|
||||
commit to the ciphertext and to the PQ secret: a modified `ct` changes the
|
||||
prologue (and decapsulates to implicit-rejection garbage), so the Noise
|
||||
handshake fails before msg 2.
|
||||
|
||||
Handshake payloads are empty. A non-empty decrypted handshake payload is a
|
||||
hard fail.
|
||||
|
||||
### Sequence
|
||||
|
||||
Initiator knows the responder’s identity pubkey (pinned) and x25519 prekey
|
||||
from the invite (or roster).
|
||||
Initiator knows the responder’s identity pubkey (pinned), x25519 prekey and
|
||||
(if `kem_pk` is present) ML-KEM key from the invite (or roster).
|
||||
|
||||
1. **IK msg 1** — initiator → responder (framed). Responder’s Noise static is
|
||||
the invite `spk`.
|
||||
0. **PQ prelude** — only when the responder’s roster row has `kem_pk`:
|
||||
initiator → responder, one `version = 2` frame carrying the ML-KEM
|
||||
ciphertext. If the row has no `kem_pk`, no prelude is sent and the prologue
|
||||
is `onionwire-v1`.
|
||||
1. **IK msg 1** — initiator → responder (framed, `version = 1`). Responder’s
|
||||
Noise static is the invite `spk`.
|
||||
2. Responder looks up the remote static in the roster **by prekey**.
|
||||
Unknown prekey → close. This is how the answerer learns who is calling.
|
||||
It then compares the friend row with how the session opened (see
|
||||
[No downgrade](#no-downgrade)) and only then sends msg 2.
|
||||
3. **IK msg 2** — responder → initiator (framed).
|
||||
4. Both sides enter transport mode. Handshake hash `h` is 32 bytes (BLAKE2s).
|
||||
5. **Identity proof, initiator first** — transport-encrypt a 96-byte proof,
|
||||
|
|
@ -129,6 +165,27 @@ ciphertext and closes. The responder decrypts that one frame and closes.
|
|||
Compromise of the long-term x25519 prekey does not decrypt past transport
|
||||
(IK + ephemeral). It does allow future impersonation at the Noise layer until
|
||||
the peer notices the identity proof failing — so the proof is not optional.
|
||||
With a PQ prelude, the transport secrets also mix `ss_kem`; a later
|
||||
cryptographically relevant quantum adversary that recorded the session still
|
||||
needs ML-KEM-768 broken to recover the Noise transport keys.
|
||||
|
||||
### No downgrade
|
||||
|
||||
The rule comes from the roster row, never from what arrives on the wire:
|
||||
|
||||
- friend row has `kem_pk` → **always** send the prelude; the responder requires
|
||||
one. A `version = 1` opening from that peer is rejected with `prelude
|
||||
required` before msg 2, the identity proofs, and any application frame.
|
||||
- friend row has no `kem_pk` (added from a legacy v1 invite) → classical
|
||||
session with the `onionwire-v1` prologue. The UI labels the friend as lacking
|
||||
PQ protection.
|
||||
- A prelude is not accepted for a friend row with no `kem_pk`: the responder
|
||||
rejects it with `unexpected prelude` before msg 2, so the wire cannot upgrade
|
||||
a classical row. `kem_pk` only enters a row from a signed v2 invite.
|
||||
|
||||
A v1-only build dialling a v2 install cannot parse `version = 2` as an opening
|
||||
frame and hard-fails, and a v2 build will not send a prelude to a v1 peer.
|
||||
That mixed-fleet break is accepted; there is no fallback path.
|
||||
|
||||
## Application plaintext
|
||||
|
||||
|
|
@ -566,28 +623,39 @@ the new invite is the signal.
|
|||
Not a QR graphic. A single ASCII string, max 4096 characters:
|
||||
|
||||
```
|
||||
onionwire:v1:k=<64 hex>:o=<v3 onion>:spk=<64 hex>:sig=<128 hex>
|
||||
onionwire:v2:k=<64 hex>:o=<v3 onion>:spk=<64 hex>:kem=<base64url pk>:sig=<128 hex>
|
||||
```
|
||||
|
||||
Field order in the string is not significant; duplicate or unknown fields are
|
||||
rejected. `k` is the identity pubkey, `spk` the x25519 prekey, `o` the current
|
||||
locator.
|
||||
locator, and `kem` the ML-KEM-768 encapsulation key (1184 bytes) encoded as
|
||||
unpadded base64url (1579 characters). A v2 invite is about 1.9 KB, still well
|
||||
under the 4096-character cap.
|
||||
|
||||
**Current signature (encode this):**
|
||||
|
||||
```
|
||||
ed25519_sign(identity_sk,
|
||||
"onionwire-invite-v1" || 0x00 || k_ascii || 0x00 || o_ascii || 0x00 || spk_ascii)
|
||||
"onionwire-invite-v2" || 0x00 || k_ascii || 0x00 || o_ascii || 0x00 ||
|
||||
spk_ascii || 0x00 || kem_ascii)
|
||||
```
|
||||
|
||||
`k_ascii` / `spk_ascii` are the hex strings as they appear in the invite
|
||||
(lowercase).
|
||||
(lowercase); `kem_ascii` is the base64url field value after `kem=`. Because the
|
||||
signature covers `kem_ascii`, removing the field or substituting a different
|
||||
key fails verification — that is the anti-strip/anti-substitution property.
|
||||
|
||||
**Legacy accept:** a signature over the raw concatenation `k || o || spk`
|
||||
(no domain tag, no separators) is still accepted on decode so old invites
|
||||
verify. New invites MUST use the domain-separated form. Do not emit legacy.
|
||||
**Legacy accept (`onionwire:v1`):** a v1 invite has no `kem` field. Decode
|
||||
accepts it and yields a friend with no `kem_pk`, i.e. a classical peer. A v1
|
||||
signature is accepted in either historical form: the tagged
|
||||
`"onionwire-invite-v1" || 0x00 || k || 0x00 || o || 0x00 || spk` or the raw
|
||||
concatenation `k || o || spk` (no tag, no separators), so old invites keep
|
||||
verifying. `onionwire:v2` MUST have `kem=` and MUST verify over the v2 domain;
|
||||
a v2 body relabelled v1 does not verify.
|
||||
|
||||
Unknown `k`: prompt. Same `k`: update onion and prekey only.
|
||||
Encode MUST emit `onionwire:v2` only. Unknown `k`: prompt. Same `k`: update
|
||||
locator, prekey and KEM key on that row (never a second friend), and drop the
|
||||
stored ratchet state if either key changed.
|
||||
|
||||
## What v1 will not grow into
|
||||
|
||||
|
|
@ -604,8 +672,12 @@ path”). They are out of scope, not postponed.
|
|||
|
||||
## Versioning
|
||||
|
||||
- Frame `version` 1 and invite `onionwire:v1` are this document.
|
||||
- A new handshake prologue or a new invite scheme is a breaking change.
|
||||
- Frame `version` 1 (normal), frame `version` 2 (PQ prelude), invite
|
||||
`onionwire:v2` (emit) and invite `onionwire:v1` (decode only) are this
|
||||
document.
|
||||
- A new handshake prologue or a new invite scheme is a breaking change. The
|
||||
hybrid prologue and the prelude are exactly that: v1 peers cannot talk to a
|
||||
friend that has a `kem_pk`.
|
||||
- New typed prefixes (`xyz `) are backward compatible if old peers drop them.
|
||||
- The `rat ` frame has its own version byte (`0x01`). A different ratchet frame
|
||||
layout or a different KDF is a breaking change for chat only: peers that
|
||||
|
|
|
|||
|
|
@ -20,7 +20,41 @@ A signed `loc` frame (`onion`, `ts`, `sig`) rewrites a friend’s locator **only
|
|||
|
||||
## 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).
|
||||
`F8` rotates the long-lived signed prekey **and the ML-KEM-768 install key**. The identity key and the onion are unchanged, but the prekey is our Noise static **and** the seed of the bootstrap ratchet epoch, and the KEM key is what peers encapsulate to, so once either moves nothing is reachable any more: a friend's dial uses the prekey and `kem=` they pinned from your invite, and their stored epoch is derived from the old prekey. There is no push path for either key — they only travel 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).
|
||||
|
||||
## Post-quantum transport does not make messaging post-quantum
|
||||
|
||||
Every Noise session to a v2 friend carries an ML-KEM-768 secret. The
|
||||
initiator sends a `version = 2` prelude with `ct = Encapsulate(friend.kem_pk)`
|
||||
before Noise msg 1, and both sides mix `(ct, ss_kem)` into the Noise prologue
|
||||
(`"onionwire-v2" || 0x00 || ct || 0x00 || ss_kem`). A recorded handshake
|
||||
therefore exposes an X25519 DH and an ML-KEM-768 encapsulation; a future
|
||||
cryptographically relevant quantum adversary has to break ML-KEM-768 as well as
|
||||
X25519 to recover the Noise transport keys. That removes the
|
||||
harvest-now-decrypt-later exposure of the **one-shot transport**.
|
||||
|
||||
What this does **not** buy:
|
||||
|
||||
- **The chat ratchet stays classical.** Chat messages are `rat ` frames
|
||||
(Double Ratchet, `docs/PROTOCOL.md`). The **bootstrap epoch is derived only
|
||||
from the two long-lived X25519 prekeys** (HKDF over their DH, with the
|
||||
identity pubkeys mixed in), so an adversary who records a `rat ` chain and
|
||||
later obtains both prekeys can reconstruct epoch 0 even though the Noise
|
||||
session that carried it was hybrid. Later epoch chains use fresh X25519 DH
|
||||
steps, which are equally quantum-vulnerable. PQ ratchet steps are a separate
|
||||
follow-up, not part of this transport work.
|
||||
- **Identity and invite signatures are ed25519**, still classical. The KEM key
|
||||
is authenticated by a v1-style ed25519 invite signature; an adversary who can
|
||||
forge it can also swap `kem=`. Hybrid transport protects confidentiality, not
|
||||
the long-term authentication root.
|
||||
- **Legacy friends get nothing.** A friend added from an `onionwire:v1` invite
|
||||
has no `kem_pk`; sessions to them are the old classical `onionwire-v1`
|
||||
prologue, and the UI labels that friend as lacking PQ protection. The choice
|
||||
is derived from the roster row, never from the wire: a `kem_pk` friend
|
||||
rejects a prelude-less session with `prelude required` before any application
|
||||
frame, so an active attacker cannot downgrade it.
|
||||
- **Mixed-version fleets break.** A v1-only build cannot open a session with a
|
||||
v2 friend; that is accepted rather than adding a fallback path.
|
||||
|
||||
## Your store is encrypted
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue