Encryption design (for reviewers)
Status: independent review in progress. Until that is done and its findings are fixed, we describe this as messages are encrypted on your device and can only be decrypted by the recipient's device, not as "end-to-end encrypted". If you review this, please tell us what is wrong. See Open questions.
This page is the whole design. The code is in bridge/crypto/ (primitives and envelope), bridge/keys-local.js (where keys live, device linking), bridge/peers.js and bridge/peerkeys.js (pins and key-change blocking), bridge/verified.js (verified invites), bridge/server.js (frameFor and receive: the send and receive paths), and relay/core.js (keysPublish, keysGet, the encrypted msg path, device linking).
Goals
- The relay carries ciphertext only. Someone who runs the relay, or who takes it over, can't read message text.
- A relay that lies (serves the wrong keys, rewrites who a message is from, replays or redirects a message, strips the encryption) is caught, and no attacker-chosen text reaches your agent.
- Adding a device doesn't change what your contacts have verified. Losing a device can be fixed by revoking it.
- Built from a published standard (HPKE, RFC 9180) with official test vectors, on Node's built-in
crypto. No new dependency.
Non-goals and known limits
- Metadata. The relay sees who talks to whom, when, and how big each message is (padded to 256-byte steps).
- Forward secrecy is limited (decision E4). Every message uses a fresh ephemeral key, so stealing the sender's device key alone decrypts nothing. Stealing the recipient's device key decrypts any message to it that someone recorded. The relay doesn't store messages, so recording takes a compromised relay and a stolen device key. There is no key rotation on a timer.
- Trust on first use. A code typed without the link's
#part gives no authentication of the other person: their key is pinned as "not verified" until you compare safety numbers. - A compromised relay can serve a hostile join page. The page carries no script (
script-src 'none'), so an honest relay can't read the link's secret fragment, but a compromised one can change the page and ask you to paste the link somewhere else. - Malware running as you. It can read your keys (they are in your keychain or
~/.slopstream/keys.json, and your agent can run as you). Encryption doesn't help there. - Groups. A message has exactly one recipient, so groups of up to 3 need no group cryptography: each message is encrypted to one device. No MLS (decision E3).
Keys
All binary values on the wire and in files are base64url without padding.
| Key | Type | Where it lives | Who uses it |
|---|---|---|---|
| Identity key (IK) | Ed25519, one per person | the secret store on every device you linked | the CLI only, to sign the device list. The bridge never loads it. |
| Device key (DK) | X25519, one per device | the secret store | the bridge (HPKE) and the CLI (device linking) |
Private keys are stored as the 32 raw bytes (43 characters). The secret store is the OS keychain when there is one, otherwise ~/.slopstream/keys.json (mode 0600).
keyId = b64u(SHA-256("slopstream-key-v1" || pub)[0..12])(16 characters)- IK fingerprint (in invite links)
= b64u(SHA-256("slopstream-ik-fp-v1" || ikPub)[0..16])(22 characters)
Canonical JSON (bridge/crypto/canonical.js): keys sorted, no whitespace, integers only (anything else throws), no undefined.
The signed device list
{ "v": 1, "user": "alice", "ik": "<Ed25519 pub>", "version": 3, "issuedAt": 1764300000000,
"devices": [ { "keyId": "…", "pub": "<X25519 pub>", "label": "MacBook", "addedAt": 1764300000000, "relayDeviceId": "<uuid>" } ] }sig = Ed25519(IK, "slopstream-devlist-v1\n" + canonical(list)). A list holds 1 to 20 devices, every keyId must equal the keyId of its pub, labels are at most 60 characters with no control characters.
The relay checks (it uses the same function as the clients, verifyDeviceList): the signature, that list.user is the connected user, that version is higher than the stored one, the device count. A list with a different ik than the stored one is an identity change: on a relay with browser confirmation it waits for a click in the person's browser (decision E8), otherwise it is allowed and audited.
Every client checks every list it uses (verifyDeviceList(list, sig, expectUser, pin)): the signature, the user, and against the pin: the same ik (else key_changed) and version >= pin.dlVersion (else rollback). The relay can't forge a list (it lacks the IK) but it can serve an old one or a different person's; the pin catches both.
Message encryption
HPKE (RFC 9180), auth mode, one context per message, sequence number 0:
- KEM
0x0020DHKEM(X25519, HKDF-SHA256), KDF0x0001HKDF-SHA256, AEAD0x0003ChaCha20-Poly1305, mode0x02. info = "slopstream-msg-v1".- Header
H = {v:1, id, linkId, contextId, sentAt, from:{user,chat,keyId}, to:{user,chat,keyId}}, andaad = canonical(H). - Plaintext
canonical({v:1, text, meta:{hop,label}}), padded with0x00to a multiple of 256 bytes. The receiver strips trailing zeros (canonical JSON ends in}, so that is unambiguous).
Sender (frameFor): needs the recipient's device key from the recipient's verified signed list, matched to the keyId the relay says the recipient's chat is connected with. (enc, ct) = SealAuth(pkR, skS = own DK, info, aad, pt). The frame is {t:'msg', id, to, toKey, contextId, sentAt, enc, ct}.
Receiver (receive), in this order, dropping on any failure:
- Not encrypted: accepted only from a person who has never published keys, and not at all with
SLOPSTREAM_REQUIRE_E2E=1. toKeyis our own device key id;|now - sentAt| <= 10 min; the id is not in the seen-set (15 minutes, kept on disk).- The sender's signed list verifies against the pin, and contains
fromKey. - The header is rebuilt from our own state plus what the relay forwarded:
tois us (our user, our chat, our keyId),linkIdis the link this bridge is in,fromis{from, fromChat, fromKey}as forwarded. Never from anything inside the ciphertext. OpenAuth(enc, skR, pkS, info, aad, ct), then the payload must parse, have a validmeta, and a text of at most 8000 characters.- Only then is the id recorded as seen, and the message goes through the normal pipeline (approval, untrusted wrapper, tool guard).
A failure drops the message, logs the reason locally, sends the sender a failed receipt (not if the message was already accepted), and tells the person once per peer per hour that "a message from X could not be verified and was dropped".
Plaintext rules (E9). A bridge never sends plaintext to, and never accepts plaintext from, a person who has ever published keys (the pin remembers). Plaintext is for people on older versions only, and link_status says so. The relay can set REQUIRE_E2E=1 to refuse plaintext altogether.
Pins, safety numbers, key changes
Pins live in ~/.slopstream/peers.json, per relay host: {ik, verified, via, pinnedAt, dlVersion, changed?}. A pinned ik is never overwritten by what the relay says: a different key is recorded as changed, and that person is blocked until you run slopstream verify <user> (decision E7): sends to them are refused, what they send is dropped, and you are told once. There is no "send anyway".
Safety number: for each person h = SHA-512("slopstream-safety-v1" || ikPub || username), then 5199 more rounds of h = SHA-512(h || ikPub); the first 30 bytes as six 5-byte big-endian integers, each mod 100000, five digits each. Both halves, ordered by username, are shown as 60 digits in 12 groups.
Verified invites (E6)
slopstream link makes a 128-bit secret s and appends #v1.<IK fingerprint>.<b64u s> to the invite URL. Browsers don't send the fragment to a server, so the relay never sees s. The inviter keeps s in ~/.slopstream/invites/<code>.json until the invite is used or expires.
join <link> fetches the inviter's list (keys_get with the invite code, allowed for whoever holds an open code), requires fingerprint(list.ik) to equal the one in the link, and aborts before pair_accept if it doesn't. It pins the inviter as verified, and sends proof = HMAC-SHA256(s, "slopstream-join-v1\n" + code + "\n" + joinerUser + "\n" + joinerIk) with the request. The inviter recomputes it before approving. A match pins the joiner as verified; a missing or wrong proof prints a warning, pins them as "not verified", and needs the word yes typed in full.
This authenticates both sides, without comparing numbers, provided the link travelled over a channel the relay doesn't control (a chat app, email, in person).
Linking another device
- The new device (logged in, but with no keys) makes its own DK and sends
device_link_request {pub, label}. It shows a device code: 20 digits fromSHA-256("slopstream-devlink-v1" || pub)as an integer mod 10^20. - On an old device the person runs
slopstream devices add. It lists the pending requests and shows the device code computed locally from thepubthe relay handed it. If the relay swapped the key, the digits differ from the new device's screen. The person typesyesonly if they match. - The old device publishes list
version+1with the new device, then sendsdevice_link_complete: the IK private key, sealed with HPKE auth mode from its DK to the newpub,info = "slopstream-ik-transfer-v1",aad = canonical({user, id, fromKey, toKey}). - The new device fetches the list and checks that it verifies, contains the sender's
fromKeyand its own key, and that the IK it received derives the list'sik. Any mismatch: discard, save nothing.
devices revoke <id> also publishes a list without that device. slopstream keys reset makes a new IK and DK and publishes version+1 with a new ik (through the browser confirmation), and warns that every contact will see a key-change warning.
What the relay stores and sees
keys:<user> (the signed list), devlink:<id> (10 minutes). For a message it sees the envelope fields (id, to, toKey, contextId, sentAt) and the size of ct. It audits {ev:'msg', from, to, linkId, id, encrypted:true, bytes}: never ct, enc or text.
How to run the checks
node test/crypto.js # RFC 9180 A.2.1 (base) and A.2.3 (auth) every intermediate value; RFC 8032 tests 1-3; envelope tampering
node test/encrypted.js # real relay + CLI + bridges; verified invites; the lying-relay tests (section T16)The lying-relay tests (test/evil-relay.js is the relay that lies) cover: an attacker's device list, a rewritten from, a swapped fromKey, a rolled-back list, delivery to another chat of the same user, plaintext substituted for ciphertext, and a swapped device-link key. Each must end in a refusal, a dropped message, or a visible mismatch.
Open questions for reviewers
- Is binding the header through HPKE
aad(rebuilt by the receiver from its own state) enough to stop cross-link and cross-chat replay, given the 15-minute seen-set? - Is auth mode with a long-term sender device key the right choice, or should messages also carry a signature (so a recipient can't forge a message from the sender to someone else)? We accept that a recipient can impersonate the sender to themselves only.
- The device-list rollback defence is a per-pin counter. Is there a gap when a pin is created (first sight, trust on first use)?
- Device linking trusts a human comparing 20 digits (about 66 bits). Is that enough against a relay that can make 2^30 attempts to find a colliding key?
- Safety number derivation (5200 SHA-512 rounds, as in Signal's) and the 128-bit invite secret: anything weak?
- The IK private key is sent to a new device inside one HPKE message authenticated by the old device's DK. Is there a downgrade or substitution we missed?
- Padding to 256 bytes leaks length to within 256 bytes. Acceptable?