[relay] Files: a file route for same-size encrypted chunks with its own quotas; the client seals chunks in STREAM and sends a file payload inside MLS
ci / check (pull_request) Has been cancelled
ci / check (pull_request) Has been cancelled
The relay stores files (id, upload and fetch token hashes, chunk count, uploaded hour) and chunks (file id, index, ciphertext): every chunk is 256 000 bytes, so it learns the size rounded up to 250 KiB and nothing finer, and it keeps no fetch count. Only the uploader's token puts or deletes, only the fetch token gets, a chunk never changes; per-file and relay-wide quotas answer 507; files go after 30 days, incomplete ones after 24 hours. The client pads a file to whole chunks and seals each with ChaCha20-Poly1305 in the aead crate's STREAM, under a key made for that file; the key, name, type, size and thumbnail travel only in the new `file` payload, which shares `seq` with text. Also: every route now answers a bare 413 (axum's own carried a text). PROTOCOL.md §1, §4, §5, §7, §8.
This commit is contained in:
+31
-4
@@ -7,7 +7,7 @@ is a protocol version bump: documented here with its date and reason, and review
|
||||
## 1. Threat model
|
||||
| Adversary | Protected | Not protected |
|
||||
|:--|:--|:--|
|
||||
| **Relay operator** (honest but curious, including us) | message content, names, contact lists, which mailboxes belong to the same person *by content* | IP addresses at connection time and timing — an operator who logs at the network layer can correlate. Reduced by not logging (§5), not prevented. |
|
||||
| **Relay operator** (honest but curious, including us) | message content, names, contact lists, which mailboxes belong to the same person *by content*; a file's name, type, exact size and content | IP addresses at connection time and timing — an operator who logs at the network layer can correlate. Reduced by not logging (§5), not prevented. A file's size rounded up to 250 KiB, when it was uploaded, and each fetch of its chunks as it serves them (§8, files) |
|
||||
| **Network observer** | content (TLS + MLS) | that a device talks to a relay, and when |
|
||||
| **Stranger** | cannot post: no capability token | — |
|
||||
| **Contact who turns hostile** | block = rotate the token; their posts are refused | what they already received |
|
||||
@@ -56,6 +56,7 @@ Every MLS application message carries one JSON object. The relay sees none of it
|
||||
| `poll` *(2026-11-22)* | `seq`, `question`, `options`, `multiple` | a message (it shares `seq` with `text`): a question of 1–300 characters and 2–10 different options of 1–100, none blank, no control characters; `multiple` allows several choices in a vote |
|
||||
| `vote` *(2026-11-22)* | `poll`, `choices` | the sender's choices in the poll `poll` names, replacing their earlier ones: indexes into `options`, ascending, each once, at most one unless `multiple`; `[]` takes the vote back. Refused once the poll is closed. No `seq` |
|
||||
| `pollClose` *(2026-11-22)* | `poll`, `ballots` | sent by the poll's author only: the poll is closed, and `ballots` (`{author, choices}`, one per member with a non-empty vote) are **the final votes**, as the author's client had accepted them, so a vote that crossed the close counts nowhere. No `seq` |
|
||||
| `file` *(2026-11-22)* | `seq`, `file`, `fetchToken`, `key`, `name`, `mime`, `size`, `thumb`? | a message (it shares `seq` with `text`): a file on the relay (§8, files). `file` its id, `fetchToken` the capability to get its chunks, `key` its 32-byte key; `name` 1–255 characters without control characters, `/` or `\`; `mime` `type/subtype`, 3–127 printable ASCII bytes; `size` 1 byte to 100 MiB; `thumb`, when there, a JPEG of at most 32 KiB (a receiver drops a thumbnail that is not, and keeps the file). The key, the name, the type and the exact size travel **only here** |
|
||||
| `receipt` | `upto` | the receiver has saved the sender's texts up to `upto`. Sent only by a client with receipts on; a client with them off also ignores them |
|
||||
| `inbox` | `postToken` | a new post token for the mailbox the receiver already knows (after an unblock). It cannot name another mailbox |
|
||||
|
||||
@@ -71,6 +72,14 @@ the app to see this message* and counts for receipts; one without is dropped. A
|
||||
unknown field is dropped: **new fields go into new kinds**, so that older clients say so instead of
|
||||
dropping a message without a trace.
|
||||
|
||||
**A file's chunks** *(added 2026-11-22, Amicitia F29; `.agents/features/files.md`)*: the file is
|
||||
padded with zeros to whole chunks of 255 984 bytes and each is sealed with ChaCha20-Poly1305 under
|
||||
the file's key in the STREAM construction (the `aead` crate's `StreamBE32`: a zero 7-byte nonce
|
||||
prefix, the chunk's index as a 32-bit big-endian counter, and a last-chunk flag), so every chunk is
|
||||
256 000 bytes and opens only at its own index, and only the last opens as last. A key is made for
|
||||
one file and never reused. A receiver refuses a chunk that does not open, and padding that is not
|
||||
zeros.
|
||||
|
||||
**Block** (§3) is a rotate of the post token to the hash of a token nobody gets. Nothing is sent to
|
||||
the blocked person: their posts get §8's ordinary 404. What they posted before is fetched and
|
||||
dropped. **Unblock** rotates again and sends the new token in an `inbox` payload.
|
||||
@@ -82,8 +91,12 @@ dropped. **Unblock** rotates again and sends the new token in an `inbox` payload
|
||||
| `blobs` | mailbox id, ciphertext, size, received hour (rounded) |
|
||||
| `invites` | invite id, hash(fetch secret), KeyPackage, expiry |
|
||||
| `push` *(only if the user opts in, G03; made concrete 2026-11-20)* | mailbox id, push endpoint |
|
||||
| `files` *(2026-11-22, F29)* | file id, hash(upload token), hash(fetch token), chunk count, uploaded hour (rounded) |
|
||||
| `chunks` *(2026-11-22, F29)* | file id, index, ciphertext (always 256 000 bytes) |
|
||||
|
||||
Nothing else. No IP, no user agent, no request log beyond counts. *(2026-11-20:)* the relay also
|
||||
Nothing else. *(2026-11-22:)* a file has no mailbox, no sender and no recipient, and the relay
|
||||
keeps **no count of fetches**: it sees each one as it serves it. A file is deleted when its
|
||||
uploader deletes it, after **30 days**, or after **24 hours** if not all its chunks have arrived. No IP, no user agent, no request log beyond counts. *(2026-11-20:)* the relay also
|
||||
remembers **in memory only**, never on disk, when it last woke each mailbox (§6), to wake it at most
|
||||
once a minute. A blob is deleted on acknowledged
|
||||
delivery and after **30 days** at the latest *(decided 2026-11-08)*. The reverse proxy in front must also not
|
||||
@@ -115,6 +128,7 @@ The platform facts above are Claude's understanding, to be verified in `.agents/
|
||||
- A canary string sent in a message never appears anywhere in the relay's database or logs.
|
||||
- A reaction's emoji and a reply's text never appear in the relay's database (`client/tests/real_relay.rs`, `client/tests/reactions.rs`); a reaction or reply to a message that does not exist in the conversation is refused (`client/tests/reactions.rs`, the client's unit tests).
|
||||
- A poll's question and options never appear in the relay's database (`client/tests/real_relay.rs`); a vote or close that does not fit its poll, a close by anyone but the poll's author, and anything after the close are refused and dropped (`client/tests/polls.rs`, the client's unit tests).
|
||||
- A file's name, type, thumbnail and content never appear in the relay's database, and every chunk it holds is 256 000 bytes (`client/tests/real_relay.rs`, `client/tests/files.rs`); a chunk tampered with, swapped, repeated, cut or from another file is refused (`client/tests/files.rs`, the client's unit tests); only the upload token puts or deletes and only the fetch token gets, a chunk never changes, the quotas answer 507, and files go after 30 days or 24 hours incomplete (`relay/tests/files.rs`).
|
||||
- A post without a valid token is refused; after rotation the old token is refused.
|
||||
- A delivered blob is gone; an undelivered blob is gone after the TTL (clock injected).
|
||||
- A wake carries the constant body and nothing of the mailbox, its tokens or the blob; a mailbox is
|
||||
@@ -122,7 +136,7 @@ The platform facts above are Claude's understanding, to be verified in `.agents/
|
||||
- Parsers are fuzzed (`cargo fuzz`) for every message type.
|
||||
- Every check in `VERIFY.md` §1 has a CI job or a documented manual procedure.
|
||||
|
||||
## 8. The wire (v0) — approved 2026-11-08, routes added 2026-11-14, quotas 2026-11-16, join page 2026-11-18, push 2026-11-20
|
||||
## 8. The wire (v0) — approved 2026-11-08, routes added 2026-11-14, quotas 2026-11-16, join page 2026-11-18, push 2026-11-20, files 2026-11-22
|
||||
HTTP/1.1 behind TLS (the reverse proxy, F23). Ids and tokens are unpadded base64url of a fixed length
|
||||
with one canonical spelling: ids are 16 bytes, and tokens and hashes are 32. JSON bodies refuse
|
||||
unknown fields. A blob is at most 256 KiB, and a KeyPackage at most 16 KiB.
|
||||
@@ -138,6 +152,10 @@ unknown fields. A blob is at most 256 KiB, and a KeyPackage at most 16 KiB.
|
||||
| `DELETE /v0/mailboxes/{id}/push` *(2026-11-20)* | fetch token | no more wakes for this mailbox. 204, also when none was set |
|
||||
| `POST /v0/invites` `{id, secretHash, keyPackage}` | none | stores an invite. It expires after 7 days, rounded up to the hour |
|
||||
| `GET /v0/invites/{id}` | invite secret | returns the KeyPackage once, then deletes the invite |
|
||||
| `POST /v0/files` `{id, uploadTokenHash, fetchTokenHash, chunks}` *(2026-11-22)* | none | creates a file of `chunks` (1–410) chunks. The uploader sends **hashes** of two tokens it made. 201; 409 if the id is taken; 400 if `chunks` is out of range |
|
||||
| `PUT /v0/files/{id}/chunks/{index}` (exactly 256 000 bytes) *(2026-11-22)* | upload token | stores chunk `index` (decimal, from 0). The same bytes again: 201; other bytes: 409, a chunk never changes; another size: 413 |
|
||||
| `GET /v0/files/{id}/chunks/{index}` *(2026-11-22)* | fetch token | the chunk's bytes; a chunk not there (yet) is 404 |
|
||||
| `DELETE /v0/files/{id}` *(2026-11-22)* | upload token | deletes the file and its chunks. 204 |
|
||||
| `GET /version` | none | the protocol and relay versions |
|
||||
| `GET /join` | none | a static page for an invite link opened in a browser *(added 2026-11-18)* |
|
||||
|
||||
@@ -149,6 +167,14 @@ unknown fields. A blob is at most 256 KiB, and a KeyPackage at most 16 KiB.
|
||||
limit the answer is a bare **507**. The per-mailbox caps are checked only after the post token,
|
||||
so a 507 tells a stranger nothing about a mailbox. Nothing new is stored to count: the counts
|
||||
come from §5's own rows and `size`. A client treats 507 like any failure and tries again later.
|
||||
- **Files** *(added 2026-11-22, Amicitia F29, so a chat can carry photos, videos and documents;
|
||||
`.agents/features/files.md`)*: a file holds at most its declared chunks (an index at or past them
|
||||
is 507, checked after the upload token), at most 410 (100 MiB of plaintext). A relay holds at most
|
||||
`--max-files` files (default 10 000) and `--max-file-bytes` (default 4 GiB), each file counted at
|
||||
its full size from its creation so an upload under way is never cut off; over either, `POST` is
|
||||
507. Files have their own quota, apart from blobs, so they cannot starve messages. Only the token
|
||||
whose hash came with `POST` can add, or delete; a stranger who learns a file id can do neither.
|
||||
A relay from before this answers 404 to `POST /v0/files`.
|
||||
- **The join page** *(added 2026-11-18; `.agents/features/join-page.md`)*: an invite can travel as
|
||||
`https://<relay>/join#<invite id>.<secret>`, which messengers make tappable. The browser sends
|
||||
only `GET /join`: the fragment, and so the secret, never reaches the relay, a link preview or a
|
||||
@@ -161,4 +187,5 @@ unknown fields. A blob is at most 256 KiB, and a KeyPackage at most 16 KiB.
|
||||
- **Push** *(added 2026-11-20, Amicitia F25b, so a closed Android app hears that something arrived)*:
|
||||
a wrong token or unknown mailbox is §8's bare 404; an endpoint that breaks the rules is 400, and so
|
||||
is `http://` to a loopback host, which only a relay started with `--push-loopback` (tests) accepts.
|
||||
- Tests: `crates/relay/tests/relay.rs`, `crates/relay/tests/wake.rs`, `crates/protocol/tests/wire.rs`.
|
||||
- Tests: `crates/relay/tests/relay.rs`, `crates/relay/tests/wake.rs`, `crates/relay/tests/files.rs`,
|
||||
`crates/protocol/tests/wire.rs`.
|
||||
|
||||
Reference in New Issue
Block a user