Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b62317d552 | |||
| 6c66cabb69 | |||
| 580b8d50e3 | |||
| 4a4e82e0e9 | |||
| 8517b0bbd9 | |||
| b502e57d93 | |||
| 80a27d9181 | |||
| 841236dc87 | |||
| 710e1f87fb |
@@ -0,0 +1,99 @@
|
|||||||
|
# F21 — The client: MLS 1:1, a mailbox per contact, invites
|
||||||
|
|
||||||
|
Analysis, 2026-11-14. Issues #3 (OpenMLS check) and #6 (client). It builds on F20: the relay and
|
||||||
|
`PROTOCOL.md` §8.
|
||||||
|
|
||||||
|
## 1. Why and what
|
||||||
|
Chat must be end-to-end encrypted with MLS, and the relay must learn nothing readable. The client
|
||||||
|
library is the one place where that happens. Amicitia embeds it in F22, and any other app could too.
|
||||||
|
|
||||||
|
After F21, two clients in one test can:
|
||||||
|
1. pair through an invite;
|
||||||
|
2. learn each other's mailbox and post token *inside* MLS;
|
||||||
|
3. exchange text both ways through a real relay.
|
||||||
|
|
||||||
|
A canary string in a message, and both display names, never appear in the relay's database.
|
||||||
|
|
||||||
|
### The OpenMLS check (#3), measured 2026-11-14
|
||||||
|
| Question | Answer |
|
||||||
|
|:--|:--|
|
||||||
|
| Version | `openmls` 0.9.2, `openmls_rust_crypto` / `_basic_credential` / `_traits` 0.6.0; MSRV 1.91 (we pin 1.99) |
|
||||||
|
| Licence | OpenMLS crates **MIT**. The whole tree is MIT, Apache-2.0 or BSD, except **`hpke-rs` 0.7 (MPL-2.0)**, OpenMLS's HPKE. MPL-2.0 is file-level copyleft: an app that ships it unmodified must say where its source is. That goes into Amicitia's licence notices (F22) |
|
||||||
|
| C code | none: no `cc`, `cmake` or `-sys` crate in the tree. The crypto is RustCrypto (pure Rust) |
|
||||||
|
| Android | `cargo build -p tabellarius-client` passes for `aarch64-linux-android`, `x86_64-linux-android` and `armv7-linux-androideabi`. The client's tests also *run* on the x86_64 emulator (§5) |
|
||||||
|
|
||||||
|
## 2. Architecture
|
||||||
|
```mermaid
|
||||||
|
sequenceDiagram
|
||||||
|
participant A as Inviter A
|
||||||
|
participant R as Relay
|
||||||
|
participant B as Invitee B
|
||||||
|
A->>R: POST /v0/mailboxes Mw (id and post token derived from the secret)
|
||||||
|
A->>R: POST /v0/invites {id, hash(secret), KeyPackage(A)}
|
||||||
|
A-->>B: link: relay, invite id, secret (QR or link, outside the relay)
|
||||||
|
B->>R: GET /v0/invites/{id} (secret) → KeyPackage(A), invite deleted
|
||||||
|
B->>B: create group G, add A → Welcome
|
||||||
|
B->>R: POST Mw: Welcome; then an MLS message {hello: mailbox M_B, post token P_B, name}
|
||||||
|
A->>R: GET Mw → join G, read hello
|
||||||
|
A->>R: POST M_B: MLS {hello: mailbox M_A, post token P_A, name}
|
||||||
|
B->>R: GET M_B → read hello
|
||||||
|
Note over A,B: A posts to M_B, B posts to M_A. One MLS group per pair.
|
||||||
|
```
|
||||||
|
- **Identity:** an Ed25519 key made on the device, behind a `BasicCredential` that carries 16
|
||||||
|
random bytes, not a name. The display name travels only inside MLS (`PROTOCOL.md` §2).
|
||||||
|
- **Ciphersuite:** `MLS_128_DHKEMX25519_AES128GCM_SHA256_Ed25519`, RFC 9420's mandatory one.
|
||||||
|
- **The welcome mailbox, Mw.** The link carries three things (§4): the relay, the invite id and the
|
||||||
|
secret. The invitee's first reply needs somewhere to go, so its id and post token are **derived
|
||||||
|
from the invite secret** with HKDF-SHA256 (crate `hkdf`, labels `tabellarius v0 welcome mailbox`
|
||||||
|
and `… post`). The inviter creates Mw and keeps a random fetch token for it. To the relay it is an
|
||||||
|
ordinary mailbox, so §5 and §8 are unchanged.
|
||||||
|
- **The invitee creates the group.** It holds the inviter's KeyPackage, so it can add the inviter at
|
||||||
|
once and send the Welcome. §4 says the invitee *replies with their own* KeyPackage. That is not
|
||||||
|
needed when the invitee creates the group, so §4's text changes (§4 below).
|
||||||
|
- **Payloads inside MLS** are JSON: `{"kind":"hello","mailbox","postToken","name"}` and
|
||||||
|
`{"kind":"text","body"}`. The relay sees only MLS ciphertext.
|
||||||
|
- **Blob framing:** each blob is one TLS-serialised `MlsMessageOut` (a Welcome, or a private
|
||||||
|
message).
|
||||||
|
- **Transport is a trait.** `Transport` covers create mailbox, post, fetch, acknowledge, create
|
||||||
|
invite and claim invite. The library makes no network calls itself. F22 gives it an HTTP
|
||||||
|
implementation. The tests use the real relay over loopback, plus an in-memory double for the run
|
||||||
|
on Android.
|
||||||
|
- **Poll:** fetch every own mailbox, process blobs in order, and acknowledge each one processed
|
||||||
|
(or refused as not MLS). Each call returns events: `Joined {contact, name}`,
|
||||||
|
`Message {contact, text}`.
|
||||||
|
|
||||||
|
## 3. Risks
|
||||||
|
- **Privacy:**
|
||||||
|
- The relay sees: mailbox ids, token hashes, ciphertext sizes and hours, and the KeyPackage (A's
|
||||||
|
public key and the random credential id).
|
||||||
|
- It does not see: names, text, or which two mailboxes belong to one pair.
|
||||||
|
- The welcome mailbox's id is derived from the secret. Whoever has the link can post there, which
|
||||||
|
is exactly the invite's capability. Mw is used once, but a mailbox cannot be deleted in v0 (F20
|
||||||
|
§4), so it stays empty.
|
||||||
|
- **Crypto:** none written here. MLS, HKDF and SHA-256 come from OpenMLS, `hkdf` and `sha2`.
|
||||||
|
- **State:** in memory in F21. Keeping MLS state across restarts, in Amicitia's encrypted `mls`
|
||||||
|
table, is F22.
|
||||||
|
- **A stolen link:** whoever opens it first becomes the contact. The inviter sees the joiner's name
|
||||||
|
and can block. Safety footprints (F26) are the real answer, and the link is meant to be shared in
|
||||||
|
person or privately.
|
||||||
|
|
||||||
|
## 4. Gaps and designed solutions
|
||||||
|
| Gap | Solution |
|
||||||
|
|:--|:--|
|
||||||
|
| §4 says the invitee *replies with their own KeyPackage*, and the reply channel (Mw) is not described | Change §4 to this flow: the invitee creates the group; the first reply goes to a mailbox derived from the secret. **Needs Mark's approval** before merging (CLAUDE.md §3) |
|
||||||
|
| RFC 9420 test vectors | OpenMLS runs them in its own CI. Here, interop is tested between two of our clients, plus OpenMLS's validation of every message |
|
||||||
|
| State across restarts | F22 (an `mls` table, an SQLite storage provider) |
|
||||||
|
| Deleting the used welcome mailbox | protocol v1 (F20 §4) |
|
||||||
|
| Block, delivery state | F24 |
|
||||||
|
| Several devices per person | Phase 5 (G04) |
|
||||||
|
|
||||||
|
## 5. Verification matrix
|
||||||
|
| Case | Kind | Test |
|
||||||
|
|:--|:--|:--|
|
||||||
|
| Two clients pair through an invite and exchange text both ways, through the real relay over loopback | integration | `client` `pair_and_talk_through_a_real_relay` |
|
||||||
|
| A canary in a message, and both names, never appear in the relay's database file | integration | `client` `the_relay_never_sees_a_name_or_a_word` |
|
||||||
|
| A link opened twice: the second claim fails, and nobody else joins | integration | `client` |
|
||||||
|
| A blob that is not MLS, or not for this group, is acknowledged and skipped, never shown | integration | `client` |
|
||||||
|
| The welcome mailbox derivation is fixed (a test vector) | unit | `client` |
|
||||||
|
| Pairing and talking run **on the Android emulator** (an in-memory transport) | device | `cargo test --target x86_64-linux-android` binary run with `adb` |
|
||||||
|
| The client does not depend on the relay (except in its tests) | CI | `scripts/check-deps.sh` (normal edges only) |
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
# Review — `feature/protocol-http` (PROTOCOL.md §8, the v0 routes)
|
||||||
|
|
||||||
|
2026-11-14. Documents only. Mark approved adding the routes on 2026-11-14.
|
||||||
|
|
||||||
|
**F1 — the routes match the code.** The table repeats `.agents/features/relay.md` §2 as built and
|
||||||
|
tested in F20 (`crates/relay/tests/relay.rs`, 17 tests). No route, limit or status is new here.
|
||||||
|
|
||||||
|
**F2 — privacy.** §8 adds no stored field (§5 is unchanged) and loosens no promise. Two choices are
|
||||||
|
written down as protocol commitments:
|
||||||
|
- the uniform bare 404;
|
||||||
|
- acknowledging by SHA-256 instead of an id.
|
||||||
|
|
||||||
|
**F3 — what is not here.** No quotas yet (`relay.md` §4). A future change to §8 is a version bump,
|
||||||
|
like any change to this file.
|
||||||
@@ -28,9 +28,13 @@ deploy/container/ # container image
|
|||||||
|
|
||||||
## 3. Workflow
|
## 3. Workflow
|
||||||
Same as Amicitia: analysis document in `.agents/features/` before code ((D)TDD), branch per feature,
|
Same as Amicitia: analysis document in `.agents/features/` before code ((D)TDD), branch per feature,
|
||||||
adversarial self-review in `.agents/reviews/`, merge `--no-ff`, push and verify the remote hash. The
|
PR. **The adversarial self-review is posted in the PR** as a Gitea review: the evidence (test counts
|
||||||
agent merges its own PR once local checks pass and the review is written, and reports afterwards
|
per crate, planted bugs) in its body and a comment on each line a finding is about. The PR is the
|
||||||
(Mark, 2026-11-08); a change to `docs/PROTOCOL.md` still needs Mark's approval first.
|
record; `.agents/reviews/` holds the reviews from before 2026-11-14 only.
|
||||||
|
**The agent merges every PR itself**, a change to `docs/PROTOCOL.md` included, once local checks pass
|
||||||
|
and the review is posted: merge `--no-ff`, push, verify the remote hash, say in the merge commit which
|
||||||
|
PR holds the review, and report to Mark afterwards (Mark, 2026-11-14). A protocol change still says in
|
||||||
|
`docs/PROTOCOL.md` what changed, when and why.
|
||||||
**No AI attribution in commits, ever.** Quote test counts per crate; an exit code is not a count.
|
**No AI attribution in commits, ever.** Quote test counts per crate; an exit code is not a count.
|
||||||
|
|
||||||
## 4. Known traps
|
## 4. Known traps
|
||||||
|
|||||||
Generated
+1631
-14
File diff suppressed because it is too large
Load Diff
@@ -8,6 +8,24 @@ publish.workspace = true
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
tabellarius-protocol = { path = "../protocol" }
|
tabellarius-protocol = { path = "../protocol" }
|
||||||
|
# MLS (RFC 9420). Pure-Rust crypto provider (RustCrypto), so Android and iOS need no C toolchain.
|
||||||
|
openmls = "0.9"
|
||||||
|
openmls_rust_crypto = "0.6"
|
||||||
|
openmls_basic_credential = "0.6"
|
||||||
|
openmls_traits = "0.6"
|
||||||
|
# Derives the welcome mailbox from an invite secret (client.md §2).
|
||||||
|
hkdf = "0.12"
|
||||||
|
sha2 = "0.10"
|
||||||
|
serde = { version = "1", features = ["derive"] }
|
||||||
|
serde_json = "1"
|
||||||
|
|
||||||
|
[dev-dependencies]
|
||||||
|
# The real relay, for the end-to-end test only. `check-deps.sh` checks normal edges: the client
|
||||||
|
# library itself never depends on the relay.
|
||||||
|
tabellarius-relay = { path = "../relay" }
|
||||||
|
axum = { version = "0.8", default-features = false, features = ["http1", "tokio"] }
|
||||||
|
tokio = { version = "1", features = ["rt", "net"] }
|
||||||
|
tempfile = "3"
|
||||||
|
|
||||||
[lints]
|
[lints]
|
||||||
workspace = true
|
workspace = true
|
||||||
|
|||||||
+470
-2
@@ -1,2 +1,470 @@
|
|||||||
//! Client library: MLS (via OpenMLS) and the mailbox client.
|
//! The Tabellarius client: MLS 1:1 conversations (OpenMLS), a mailbox per contact, invites.
|
||||||
//! Empty until the protocol review is approved. No cryptography is ever written here by hand.
|
//! No cryptography is written here by hand: MLS is OpenMLS, HKDF and SHA-256 are RustCrypto.
|
||||||
|
//!
|
||||||
|
//! Pairing (`.agents/features/client.md` §2):
|
||||||
|
//! 1. The inviter makes a KeyPackage and a link (invite id + secret). It also makes a *welcome
|
||||||
|
//! mailbox*, whose id and post token are derived from the secret.
|
||||||
|
//! 2. The invitee claims the KeyPackage, creates the MLS group, and posts the Welcome and an MLS
|
||||||
|
//! `hello` (its own mailbox and post token, and its name) to the welcome mailbox.
|
||||||
|
//! 3. The inviter joins, and answers with its own `hello` to the invitee's mailbox.
|
||||||
|
//!
|
||||||
|
//! The relay only ever holds MLS ciphertext, KeyPackages, ids and token hashes.
|
||||||
|
|
||||||
|
pub mod transport;
|
||||||
|
|
||||||
|
use hkdf::Hkdf;
|
||||||
|
use openmls::prelude::tls_codec::{Deserialize as _, Serialize as _};
|
||||||
|
use openmls::prelude::*;
|
||||||
|
use openmls_basic_credential::SignatureKeyPair;
|
||||||
|
use openmls_rust_crypto::OpenMlsRustCrypto;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use sha2::Sha256;
|
||||||
|
use tabellarius_protocol::{
|
||||||
|
blob_hash, CreateInvite, CreateMailbox, InviteId, KeyPackageBytes, MailboxId, Token,
|
||||||
|
MAX_BLOB_BYTES,
|
||||||
|
};
|
||||||
|
pub use transport::{MemoryTransport, Transport, TransportError};
|
||||||
|
|
||||||
|
/// RFC 9420's mandatory ciphersuite.
|
||||||
|
pub const CIPHERSUITE: Ciphersuite = Ciphersuite::MLS_128_DHKEMX25519_AES128GCM_SHA256_Ed25519;
|
||||||
|
/// The longest display name sent in a `hello`.
|
||||||
|
pub const MAX_NAME_CHARS: usize = 64;
|
||||||
|
/// The longest text message, in bytes; well under a blob's limit once encrypted.
|
||||||
|
pub const MAX_TEXT_BYTES: usize = 64 * 1024;
|
||||||
|
|
||||||
|
const WELCOME_ID_LABEL: &[u8] = b"tabellarius v0 welcome mailbox";
|
||||||
|
const WELCOME_POST_LABEL: &[u8] = b"tabellarius v0 welcome mailbox post";
|
||||||
|
|
||||||
|
/// Why something failed. Never carries a message's text, a name, or a token.
|
||||||
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
|
pub enum ClientError {
|
||||||
|
Transport(TransportError),
|
||||||
|
/// MLS refused: a bad KeyPackage, a Welcome that is not for us, a message that does not verify.
|
||||||
|
Mls,
|
||||||
|
/// No randomness from the system.
|
||||||
|
Random,
|
||||||
|
/// A name or text over its limit.
|
||||||
|
TooLong,
|
||||||
|
/// No such contact, or a contact whose mailbox is not known yet.
|
||||||
|
UnknownContact,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<TransportError> for ClientError {
|
||||||
|
fn from(e: TransportError) -> Self {
|
||||||
|
ClientError::Transport(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// What the link to share carries, besides the relay's address.
|
||||||
|
#[derive(Clone, PartialEq, Eq, Debug)]
|
||||||
|
pub struct Invite {
|
||||||
|
pub id: InviteId,
|
||||||
|
pub secret: Token,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The welcome mailbox's id and post token, derived from an invite secret with HKDF-SHA256.
|
||||||
|
pub fn welcome_mailbox(secret: &Token) -> (MailboxId, Token) {
|
||||||
|
let hk = Hkdf::<Sha256>::new(None, secret.as_bytes());
|
||||||
|
let mut id = [0u8; 16];
|
||||||
|
let mut post = [0u8; 32];
|
||||||
|
// Lengths within HKDF's limit (255 × 32 bytes): expand cannot fail here.
|
||||||
|
let _ = hk.expand(WELCOME_ID_LABEL, &mut id);
|
||||||
|
let _ = hk.expand(WELCOME_POST_LABEL, &mut post);
|
||||||
|
(MailboxId::from_bytes(id), Token::from_bytes(post))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A local handle for a contact. Means nothing outside this client.
|
||||||
|
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
|
||||||
|
pub struct ContactId(pub u32);
|
||||||
|
|
||||||
|
/// What [`Client::poll`] found.
|
||||||
|
#[derive(Clone, PartialEq, Eq, Debug)]
|
||||||
|
pub enum Event {
|
||||||
|
/// The other side's `hello` arrived: the conversation can be used both ways.
|
||||||
|
Joined {
|
||||||
|
contact: ContactId,
|
||||||
|
name: String,
|
||||||
|
},
|
||||||
|
Message {
|
||||||
|
contact: ContactId,
|
||||||
|
text: String,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The JSON inside an MLS application message. The relay never sees it.
|
||||||
|
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq)]
|
||||||
|
#[serde(tag = "kind", rename_all = "camelCase", deny_unknown_fields)]
|
||||||
|
enum Payload {
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
Hello {
|
||||||
|
mailbox: MailboxId,
|
||||||
|
post_token: Token,
|
||||||
|
name: String,
|
||||||
|
},
|
||||||
|
Text {
|
||||||
|
body: String,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Mailbox {
|
||||||
|
id: MailboxId,
|
||||||
|
fetch: Token,
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Contact {
|
||||||
|
id: ContactId,
|
||||||
|
group: MlsGroup,
|
||||||
|
name: Option<String>,
|
||||||
|
/// Where the other side posts to us.
|
||||||
|
inbox: Option<Mailbox>,
|
||||||
|
/// Where we post to the other side: their mailbox and its post token.
|
||||||
|
outbox: Option<(MailboxId, Token)>,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct Client<T: Transport> {
|
||||||
|
provider: OpenMlsRustCrypto,
|
||||||
|
signer: SignatureKeyPair,
|
||||||
|
credential: CredentialWithKey,
|
||||||
|
name: String,
|
||||||
|
transport: T,
|
||||||
|
contacts: Vec<Contact>,
|
||||||
|
welcome_boxes: Vec<Mailbox>,
|
||||||
|
next_contact: u32,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T: Transport> Client<T> {
|
||||||
|
/// A new identity: an Ed25519 key and a credential holding 16 random bytes, never a name.
|
||||||
|
pub fn new(name: &str, transport: T) -> Result<Self, ClientError> {
|
||||||
|
if name.chars().count() > MAX_NAME_CHARS {
|
||||||
|
return Err(ClientError::TooLong);
|
||||||
|
}
|
||||||
|
let provider = OpenMlsRustCrypto::default();
|
||||||
|
let signer = SignatureKeyPair::new(CIPHERSUITE.signature_algorithm())
|
||||||
|
.map_err(|_| ClientError::Mls)?;
|
||||||
|
signer
|
||||||
|
.store(provider.storage())
|
||||||
|
.map_err(|_| ClientError::Mls)?;
|
||||||
|
let identity: [u8; 16] = provider
|
||||||
|
.rand()
|
||||||
|
.random_array()
|
||||||
|
.map_err(|_| ClientError::Random)?;
|
||||||
|
let credential = CredentialWithKey {
|
||||||
|
credential: BasicCredential::new(identity.to_vec()).into(),
|
||||||
|
signature_key: signer.public().into(),
|
||||||
|
};
|
||||||
|
Ok(Self {
|
||||||
|
provider,
|
||||||
|
signer,
|
||||||
|
credential,
|
||||||
|
name: name.to_string(),
|
||||||
|
transport,
|
||||||
|
contacts: Vec::new(),
|
||||||
|
welcome_boxes: Vec::new(),
|
||||||
|
next_contact: 0,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
fn random<const N: usize>(&self) -> Result<[u8; N], ClientError> {
|
||||||
|
self.provider
|
||||||
|
.rand()
|
||||||
|
.random_array()
|
||||||
|
.map_err(|_| ClientError::Random)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A fresh mailbox on the relay: we keep the fetch token, the post token goes to the contact.
|
||||||
|
fn new_mailbox(&self) -> Result<(Mailbox, Token), ClientError> {
|
||||||
|
let id = MailboxId::from_bytes(self.random()?);
|
||||||
|
let post = Token::from_bytes(self.random()?);
|
||||||
|
let fetch = Token::from_bytes(self.random()?);
|
||||||
|
self.transport.create_mailbox(&CreateMailbox {
|
||||||
|
id,
|
||||||
|
post_token_hash: post.hash(),
|
||||||
|
fetch_token_hash: fetch.hash(),
|
||||||
|
})?;
|
||||||
|
Ok((Mailbox { id, fetch }, post))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Step 1: a KeyPackage on the relay and a welcome mailbox. Share the result as a link.
|
||||||
|
pub fn create_invite(&mut self) -> Result<Invite, ClientError> {
|
||||||
|
let bundle = KeyPackage::builder()
|
||||||
|
.build(
|
||||||
|
CIPHERSUITE,
|
||||||
|
&self.provider,
|
||||||
|
&self.signer,
|
||||||
|
self.credential.clone(),
|
||||||
|
)
|
||||||
|
.map_err(|_| ClientError::Mls)?;
|
||||||
|
let kp = bundle
|
||||||
|
.key_package()
|
||||||
|
.tls_serialize_detached()
|
||||||
|
.map_err(|_| ClientError::Mls)?;
|
||||||
|
let invite = Invite {
|
||||||
|
id: InviteId::from_bytes(self.random()?),
|
||||||
|
secret: Token::from_bytes(self.random()?),
|
||||||
|
};
|
||||||
|
let (welcome_id, welcome_post) = welcome_mailbox(&invite.secret);
|
||||||
|
let fetch = Token::from_bytes(self.random()?);
|
||||||
|
self.transport.create_mailbox(&CreateMailbox {
|
||||||
|
id: welcome_id,
|
||||||
|
post_token_hash: welcome_post.hash(),
|
||||||
|
fetch_token_hash: fetch.hash(),
|
||||||
|
})?;
|
||||||
|
self.transport.create_invite(&CreateInvite {
|
||||||
|
id: invite.id,
|
||||||
|
secret_hash: invite.secret.hash(),
|
||||||
|
key_package: KeyPackageBytes::new(kp).map_err(|_| ClientError::Mls)?,
|
||||||
|
})?;
|
||||||
|
self.welcome_boxes.push(Mailbox {
|
||||||
|
id: welcome_id,
|
||||||
|
fetch,
|
||||||
|
});
|
||||||
|
Ok(invite)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Step 2, on the other device: claim the KeyPackage, make the group, send Welcome and hello.
|
||||||
|
pub fn accept_invite(&mut self, invite: &Invite) -> Result<ContactId, ClientError> {
|
||||||
|
let kp_bytes = self.transport.claim_invite(&invite.id, &invite.secret)?;
|
||||||
|
let key_package = KeyPackageIn::tls_deserialize_exact(&kp_bytes)
|
||||||
|
.map_err(|_| ClientError::Mls)?
|
||||||
|
.validate(self.provider.crypto(), ProtocolVersion::Mls10)
|
||||||
|
.map_err(|_| ClientError::Mls)?;
|
||||||
|
let config = MlsGroupCreateConfig::builder()
|
||||||
|
.ciphersuite(CIPHERSUITE)
|
||||||
|
.use_ratchet_tree_extension(true)
|
||||||
|
.build();
|
||||||
|
let mut group = MlsGroup::new(
|
||||||
|
&self.provider,
|
||||||
|
&self.signer,
|
||||||
|
&config,
|
||||||
|
self.credential.clone(),
|
||||||
|
)
|
||||||
|
.map_err(|_| ClientError::Mls)?;
|
||||||
|
let (_commit, welcome, _info) = group
|
||||||
|
.add_members(&self.provider, &self.signer, &[key_package])
|
||||||
|
.map_err(|_| ClientError::Mls)?;
|
||||||
|
group
|
||||||
|
.merge_pending_commit(&self.provider)
|
||||||
|
.map_err(|_| ClientError::Mls)?;
|
||||||
|
|
||||||
|
let (inbox, inbox_post) = self.new_mailbox()?;
|
||||||
|
let hello = Payload::Hello {
|
||||||
|
mailbox: inbox.id,
|
||||||
|
post_token: inbox_post,
|
||||||
|
name: self.name.clone(),
|
||||||
|
};
|
||||||
|
let (welcome_id, welcome_post) = welcome_mailbox(&invite.secret);
|
||||||
|
let welcome = welcome
|
||||||
|
.tls_serialize_detached()
|
||||||
|
.map_err(|_| ClientError::Mls)?;
|
||||||
|
let hello = Self::seal(&self.provider, &self.signer, &mut group, &hello)?;
|
||||||
|
self.transport.post(&welcome_id, &welcome_post, &welcome)?;
|
||||||
|
self.transport.post(&welcome_id, &welcome_post, &hello)?;
|
||||||
|
|
||||||
|
let id = self.add_contact(group, Some(inbox), None);
|
||||||
|
Ok(id)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn add_contact(
|
||||||
|
&mut self,
|
||||||
|
group: MlsGroup,
|
||||||
|
inbox: Option<Mailbox>,
|
||||||
|
outbox: Option<(MailboxId, Token)>,
|
||||||
|
) -> ContactId {
|
||||||
|
let id = ContactId(self.next_contact);
|
||||||
|
self.next_contact += 1;
|
||||||
|
self.contacts.push(Contact {
|
||||||
|
id,
|
||||||
|
group,
|
||||||
|
name: None,
|
||||||
|
inbox,
|
||||||
|
outbox,
|
||||||
|
});
|
||||||
|
id
|
||||||
|
}
|
||||||
|
|
||||||
|
fn seal(
|
||||||
|
provider: &OpenMlsRustCrypto,
|
||||||
|
signer: &SignatureKeyPair,
|
||||||
|
group: &mut MlsGroup,
|
||||||
|
payload: &Payload,
|
||||||
|
) -> Result<Vec<u8>, ClientError> {
|
||||||
|
let json = serde_json::to_vec(payload).map_err(|_| ClientError::Mls)?;
|
||||||
|
let blob = group
|
||||||
|
.create_message(provider, signer, &json)
|
||||||
|
.map_err(|_| ClientError::Mls)?
|
||||||
|
.tls_serialize_detached()
|
||||||
|
.map_err(|_| ClientError::Mls)?;
|
||||||
|
if blob.len() > MAX_BLOB_BYTES {
|
||||||
|
return Err(ClientError::TooLong);
|
||||||
|
}
|
||||||
|
Ok(blob)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Sends text to a contact whose `hello` has arrived.
|
||||||
|
pub fn send(&mut self, contact: ContactId, text: &str) -> Result<(), ClientError> {
|
||||||
|
if text.len() > MAX_TEXT_BYTES {
|
||||||
|
return Err(ClientError::TooLong);
|
||||||
|
}
|
||||||
|
let c = self
|
||||||
|
.contacts
|
||||||
|
.iter_mut()
|
||||||
|
.find(|c| c.id == contact)
|
||||||
|
.ok_or(ClientError::UnknownContact)?;
|
||||||
|
let (to, post) = c.outbox.ok_or(ClientError::UnknownContact)?;
|
||||||
|
let blob = Self::seal(
|
||||||
|
&self.provider,
|
||||||
|
&self.signer,
|
||||||
|
&mut c.group,
|
||||||
|
&Payload::Text {
|
||||||
|
body: text.to_string(),
|
||||||
|
},
|
||||||
|
)?;
|
||||||
|
self.transport.post(&to, &post, &blob)?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The contact's name, once its `hello` has arrived.
|
||||||
|
pub fn contact_name(&self, contact: ContactId) -> Option<&str> {
|
||||||
|
self.contacts
|
||||||
|
.iter()
|
||||||
|
.find(|c| c.id == contact)
|
||||||
|
.and_then(|c| c.name.as_deref())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Fetches every own mailbox, processes each blob in order, and acknowledges it, whether it
|
||||||
|
/// was understood or refused. A blob that is not valid MLS for one of our groups is dropped
|
||||||
|
/// without a trace: nothing from it is shown.
|
||||||
|
pub fn poll(&mut self) -> Result<Vec<Event>, ClientError> {
|
||||||
|
let mut events = Vec::new();
|
||||||
|
let mut sources: Vec<(MailboxId, Token)> =
|
||||||
|
self.welcome_boxes.iter().map(|m| (m.id, m.fetch)).collect();
|
||||||
|
sources.extend(
|
||||||
|
self.contacts
|
||||||
|
.iter()
|
||||||
|
.filter_map(|c| c.inbox.as_ref().map(|m| (m.id, m.fetch))),
|
||||||
|
);
|
||||||
|
for (id, fetch) in sources {
|
||||||
|
for blob in self.transport.fetch(&id, &fetch)? {
|
||||||
|
// A failure to understand one blob must not stop the rest, nor be shown.
|
||||||
|
if let Ok(Some(event)) = self.process(&blob) {
|
||||||
|
events.push(event);
|
||||||
|
}
|
||||||
|
self.transport.acknowledge(&id, &fetch, &blob_hash(&blob))?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(events)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn process(&mut self, blob: &[u8]) -> Result<Option<Event>, ClientError> {
|
||||||
|
let message = MlsMessageIn::tls_deserialize_exact(blob).map_err(|_| ClientError::Mls)?;
|
||||||
|
match message.extract() {
|
||||||
|
MlsMessageBodyIn::Welcome(welcome) => {
|
||||||
|
let config = MlsGroupJoinConfig::builder()
|
||||||
|
.use_ratchet_tree_extension(true)
|
||||||
|
.build();
|
||||||
|
let group = StagedWelcome::new_from_welcome(&self.provider, &config, welcome, None)
|
||||||
|
.map_err(|_| ClientError::Mls)?
|
||||||
|
.into_group(&self.provider)
|
||||||
|
.map_err(|_| ClientError::Mls)?;
|
||||||
|
// Not a contact to show yet: the hello right behind the Welcome makes it one.
|
||||||
|
self.add_contact(group, None, None);
|
||||||
|
Ok(None)
|
||||||
|
}
|
||||||
|
MlsMessageBodyIn::PrivateMessage(private) => {
|
||||||
|
let protocol: ProtocolMessage = private.into();
|
||||||
|
let group_id = protocol.group_id().clone();
|
||||||
|
let index = self
|
||||||
|
.contacts
|
||||||
|
.iter()
|
||||||
|
.position(|c| c.group.group_id() == &group_id)
|
||||||
|
.ok_or(ClientError::UnknownContact)?;
|
||||||
|
let processed = self.contacts[index]
|
||||||
|
.group
|
||||||
|
.process_message(&self.provider, protocol)
|
||||||
|
.map_err(|_| ClientError::Mls)?;
|
||||||
|
let ProcessedMessageContent::ApplicationMessage(app) = processed.into_content()
|
||||||
|
else {
|
||||||
|
return Ok(None);
|
||||||
|
};
|
||||||
|
let payload: Payload =
|
||||||
|
serde_json::from_slice(&app.into_bytes()).map_err(|_| ClientError::Mls)?;
|
||||||
|
self.receive(index, payload)
|
||||||
|
}
|
||||||
|
_ => Err(ClientError::Mls),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn receive(&mut self, index: usize, payload: Payload) -> Result<Option<Event>, ClientError> {
|
||||||
|
match payload {
|
||||||
|
Payload::Hello {
|
||||||
|
mailbox,
|
||||||
|
post_token,
|
||||||
|
name,
|
||||||
|
} => {
|
||||||
|
if name.chars().count() > MAX_NAME_CHARS || self.contacts[index].name.is_some() {
|
||||||
|
return Err(ClientError::Mls);
|
||||||
|
}
|
||||||
|
self.contacts[index].outbox = Some((mailbox, post_token));
|
||||||
|
self.contacts[index].name = Some(name.clone());
|
||||||
|
// The inviter's side: answer with our own mailbox, inside MLS.
|
||||||
|
if self.contacts[index].inbox.is_none() {
|
||||||
|
let (inbox, inbox_post) = self.new_mailbox()?;
|
||||||
|
let hello = Payload::Hello {
|
||||||
|
mailbox: inbox.id,
|
||||||
|
post_token: inbox_post,
|
||||||
|
name: self.name.clone(),
|
||||||
|
};
|
||||||
|
let c = &mut self.contacts[index];
|
||||||
|
let blob = Self::seal(&self.provider, &self.signer, &mut c.group, &hello)?;
|
||||||
|
c.inbox = Some(inbox);
|
||||||
|
self.transport.post(&mailbox, &post_token, &blob)?;
|
||||||
|
}
|
||||||
|
Ok(Some(Event::Joined {
|
||||||
|
contact: self.contacts[index].id,
|
||||||
|
name,
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
Payload::Text { body } => {
|
||||||
|
let c = &self.contacts[index];
|
||||||
|
if c.name.is_none() {
|
||||||
|
// Text before hello: not from a conversation that has been set up.
|
||||||
|
return Err(ClientError::Mls);
|
||||||
|
}
|
||||||
|
Ok(Some(Event::Message {
|
||||||
|
contact: c.id,
|
||||||
|
text: body,
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
/// A contact who sends a second `hello` must not redirect our messages to another mailbox,
|
||||||
|
/// nor rename themselves. Only the contact can send one (MLS authenticates it), so this guards
|
||||||
|
/// against a misbehaving contact or a replayed message.
|
||||||
|
#[test]
|
||||||
|
fn a_second_hello_changes_nothing() {
|
||||||
|
let relay = MemoryTransport::default();
|
||||||
|
let mut eva = Client::new("Eva", relay.clone()).expect("eva");
|
||||||
|
let mut jan = Client::new("Jan", relay.clone()).expect("jan");
|
||||||
|
let invite = eva.create_invite().expect("invite");
|
||||||
|
jan.accept_invite(&invite).expect("accept");
|
||||||
|
let joined = eva.poll().expect("poll");
|
||||||
|
assert_eq!(joined.len(), 1);
|
||||||
|
let before = eva.contacts[0].outbox.map(|(m, _)| m);
|
||||||
|
|
||||||
|
let other = MailboxId::from_bytes([9; 16]);
|
||||||
|
let again = Payload::Hello {
|
||||||
|
mailbox: other,
|
||||||
|
post_token: Token::from_bytes([9; 32]),
|
||||||
|
name: "Mallory".into(),
|
||||||
|
};
|
||||||
|
assert_eq!(eva.receive(0, again), Err(ClientError::Mls));
|
||||||
|
assert_eq!(eva.contacts[0].outbox.map(|(m, _)| m), before);
|
||||||
|
assert_eq!(eva.contacts[0].name.as_deref(), Some("Jan"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,153 @@
|
|||||||
|
//! How the client reaches a relay. The library makes no network calls itself: an app gives it a
|
||||||
|
//! [`Transport`] (HTTP in Amicitia, F22). [`MemoryTransport`] is a stand-in with the relay's rules,
|
||||||
|
//! for tests and for running the client on a device without a relay.
|
||||||
|
|
||||||
|
use std::collections::HashMap;
|
||||||
|
use std::sync::{Arc, Mutex};
|
||||||
|
use tabellarius_protocol::{
|
||||||
|
blob_hash, CreateInvite, CreateMailbox, InviteId, MailboxId, Sha256Hash, Token,
|
||||||
|
};
|
||||||
|
|
||||||
|
/// Why the relay said no. Carries nothing of the request.
|
||||||
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
|
pub enum TransportError {
|
||||||
|
/// 404: unknown, wrong token, expired, or already claimed.
|
||||||
|
NotFound,
|
||||||
|
/// 409: the id is taken.
|
||||||
|
Conflict,
|
||||||
|
/// Anything else: the network, a 5xx, a body that did not parse.
|
||||||
|
Failed,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The relay's operations (`PROTOCOL.md` §8), one method each.
|
||||||
|
pub trait Transport {
|
||||||
|
fn create_mailbox(&self, req: &CreateMailbox) -> Result<(), TransportError>;
|
||||||
|
fn post(&self, id: &MailboxId, post: &Token, blob: &[u8]) -> Result<(), TransportError>;
|
||||||
|
/// The waiting blobs, oldest first.
|
||||||
|
fn fetch(&self, id: &MailboxId, fetch: &Token) -> Result<Vec<Vec<u8>>, TransportError>;
|
||||||
|
fn acknowledge(
|
||||||
|
&self,
|
||||||
|
id: &MailboxId,
|
||||||
|
fetch: &Token,
|
||||||
|
hash: &Sha256Hash,
|
||||||
|
) -> Result<(), TransportError>;
|
||||||
|
fn create_invite(&self, req: &CreateInvite) -> Result<(), TransportError>;
|
||||||
|
/// The KeyPackage, once.
|
||||||
|
fn claim_invite(&self, id: &InviteId, secret: &Token) -> Result<Vec<u8>, TransportError>;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Default)]
|
||||||
|
struct Boxes {
|
||||||
|
mailboxes: HashMap<MailboxId, (Sha256Hash, Sha256Hash, Vec<Vec<u8>>)>,
|
||||||
|
invites: HashMap<InviteId, (Sha256Hash, Vec<u8>)>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// An in-memory relay with the same rules as the real one (no expiry: there is no clock here).
|
||||||
|
/// Clone it to give two clients the same relay.
|
||||||
|
#[derive(Clone, Default)]
|
||||||
|
pub struct MemoryTransport(Arc<Mutex<Boxes>>);
|
||||||
|
|
||||||
|
impl MemoryTransport {
|
||||||
|
fn boxes(&self) -> std::sync::MutexGuard<'_, Boxes> {
|
||||||
|
self.0.lock().unwrap_or_else(|p| p.into_inner())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// How many blobs wait on the relay, in all mailboxes: what was not acknowledged.
|
||||||
|
pub fn waiting_blobs(&self) -> usize {
|
||||||
|
self.boxes()
|
||||||
|
.mailboxes
|
||||||
|
.values()
|
||||||
|
.map(|(_, _, b)| b.len())
|
||||||
|
.sum()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Every byte the relay holds, for privacy tests: ids, hashes, blobs and KeyPackages.
|
||||||
|
pub fn everything_stored(&self) -> Vec<u8> {
|
||||||
|
let b = self.boxes();
|
||||||
|
let mut out = Vec::new();
|
||||||
|
for (id, (post, fetch, blobs)) in &b.mailboxes {
|
||||||
|
out.extend_from_slice(id.as_bytes());
|
||||||
|
out.extend_from_slice(post.as_bytes());
|
||||||
|
out.extend_from_slice(fetch.as_bytes());
|
||||||
|
blobs.iter().for_each(|blob| out.extend_from_slice(blob));
|
||||||
|
}
|
||||||
|
for (id, (hash, kp)) in &b.invites {
|
||||||
|
out.extend_from_slice(id.as_bytes());
|
||||||
|
out.extend_from_slice(hash.as_bytes());
|
||||||
|
out.extend_from_slice(kp);
|
||||||
|
}
|
||||||
|
out
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Transport for MemoryTransport {
|
||||||
|
fn create_mailbox(&self, req: &CreateMailbox) -> Result<(), TransportError> {
|
||||||
|
let mut b = self.boxes();
|
||||||
|
if b.mailboxes.contains_key(&req.id) {
|
||||||
|
return Err(TransportError::Conflict);
|
||||||
|
}
|
||||||
|
b.mailboxes.insert(
|
||||||
|
req.id,
|
||||||
|
(req.post_token_hash, req.fetch_token_hash, Vec::new()),
|
||||||
|
);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn post(&self, id: &MailboxId, post: &Token, blob: &[u8]) -> Result<(), TransportError> {
|
||||||
|
match self.boxes().mailboxes.get_mut(id) {
|
||||||
|
Some((hash, _, blobs)) if *hash == post.hash() => {
|
||||||
|
blobs.push(blob.to_vec());
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
_ => Err(TransportError::NotFound),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn fetch(&self, id: &MailboxId, fetch: &Token) -> Result<Vec<Vec<u8>>, TransportError> {
|
||||||
|
match self.boxes().mailboxes.get(id) {
|
||||||
|
Some((_, hash, blobs)) if *hash == fetch.hash() => Ok(blobs.clone()),
|
||||||
|
_ => Err(TransportError::NotFound),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn acknowledge(
|
||||||
|
&self,
|
||||||
|
id: &MailboxId,
|
||||||
|
fetch: &Token,
|
||||||
|
hash: &Sha256Hash,
|
||||||
|
) -> Result<(), TransportError> {
|
||||||
|
match self.boxes().mailboxes.get_mut(id) {
|
||||||
|
Some((_, f, blobs)) if *f == fetch.hash() => {
|
||||||
|
let at = blobs
|
||||||
|
.iter()
|
||||||
|
.position(|b| blob_hash(b) == *hash)
|
||||||
|
.ok_or(TransportError::NotFound)?;
|
||||||
|
blobs.remove(at);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
_ => Err(TransportError::NotFound),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn create_invite(&self, req: &CreateInvite) -> Result<(), TransportError> {
|
||||||
|
let mut b = self.boxes();
|
||||||
|
if b.invites.contains_key(&req.id) {
|
||||||
|
return Err(TransportError::Conflict);
|
||||||
|
}
|
||||||
|
b.invites
|
||||||
|
.insert(req.id, (req.secret_hash, req.key_package.bytes().to_vec()));
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn claim_invite(&self, id: &InviteId, secret: &Token) -> Result<Vec<u8>, TransportError> {
|
||||||
|
let mut b = self.boxes();
|
||||||
|
match b.invites.get(id) {
|
||||||
|
Some((hash, _)) if *hash == secret.hash() => b
|
||||||
|
.invites
|
||||||
|
.remove(id)
|
||||||
|
.map(|(_, kp)| kp)
|
||||||
|
.ok_or(TransportError::NotFound),
|
||||||
|
_ => Err(TransportError::NotFound),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,218 @@
|
|||||||
|
//! Pairing and talking through an in-memory relay. These tests have no I/O, so the same binary runs
|
||||||
|
//! on an Android emulator (`.agents/features/client.md` §5).
|
||||||
|
|
||||||
|
use tabellarius_client::*;
|
||||||
|
use tabellarius_protocol::Token;
|
||||||
|
|
||||||
|
fn contains(haystack: &[u8], needle: &[u8]) -> bool {
|
||||||
|
!needle.is_empty() && haystack.windows(needle.len()).any(|w| w == needle)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Eva invites, Jan accepts; both polls exchange the hellos.
|
||||||
|
fn pair(
|
||||||
|
relay: &MemoryTransport,
|
||||||
|
) -> (
|
||||||
|
Client<MemoryTransport>,
|
||||||
|
ContactId,
|
||||||
|
Client<MemoryTransport>,
|
||||||
|
ContactId,
|
||||||
|
) {
|
||||||
|
let mut eva = Client::new("Eva Nováková", relay.clone()).expect("eva");
|
||||||
|
let mut jan = Client::new("Jan", relay.clone()).expect("jan");
|
||||||
|
let invite = eva.create_invite().expect("invite");
|
||||||
|
let jan_side = jan.accept_invite(&invite).expect("accept");
|
||||||
|
let eva_events = eva.poll().expect("eva polls");
|
||||||
|
let Some(Event::Joined {
|
||||||
|
contact: eva_side,
|
||||||
|
name,
|
||||||
|
}) = eva_events.first().cloned()
|
||||||
|
else {
|
||||||
|
panic!("Eva did not see Jan join: {eva_events:?}");
|
||||||
|
};
|
||||||
|
assert_eq!(name, "Jan");
|
||||||
|
let jan_events = jan.poll().expect("jan polls");
|
||||||
|
assert_eq!(
|
||||||
|
jan_events,
|
||||||
|
vec![Event::Joined {
|
||||||
|
contact: jan_side,
|
||||||
|
name: "Eva Nováková".into()
|
||||||
|
}]
|
||||||
|
);
|
||||||
|
(eva, eva_side, jan, jan_side)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn two_people_pair_through_an_invite_and_talk_both_ways() {
|
||||||
|
let relay = MemoryTransport::default();
|
||||||
|
let (mut eva, eva_side, mut jan, jan_side) = pair(&relay);
|
||||||
|
|
||||||
|
eva.send(eva_side, "Ahoj Jane, pivo ve čtvrtek?")
|
||||||
|
.expect("send");
|
||||||
|
eva.send(eva_side, "V sedm.").expect("send");
|
||||||
|
assert_eq!(
|
||||||
|
jan.poll().expect("poll"),
|
||||||
|
vec![
|
||||||
|
Event::Message {
|
||||||
|
contact: jan_side,
|
||||||
|
text: "Ahoj Jane, pivo ve čtvrtek?".into()
|
||||||
|
},
|
||||||
|
Event::Message {
|
||||||
|
contact: jan_side,
|
||||||
|
text: "V sedm.".into()
|
||||||
|
},
|
||||||
|
]
|
||||||
|
);
|
||||||
|
jan.send(jan_side, "Platí 🍺").expect("send");
|
||||||
|
assert_eq!(
|
||||||
|
eva.poll().expect("poll"),
|
||||||
|
vec![Event::Message {
|
||||||
|
contact: eva_side,
|
||||||
|
text: "Platí 🍺".into()
|
||||||
|
}]
|
||||||
|
);
|
||||||
|
// Everything delivered was acknowledged: nothing waits on the relay, and a second poll is
|
||||||
|
// empty on both sides.
|
||||||
|
assert_eq!(relay.waiting_blobs(), 0);
|
||||||
|
assert!(eva.poll().expect("poll").is_empty());
|
||||||
|
assert!(jan.poll().expect("poll").is_empty());
|
||||||
|
assert_eq!(eva.contact_name(eva_side), Some("Jan"));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn the_relay_holds_no_name_and_no_word() {
|
||||||
|
let relay = MemoryTransport::default();
|
||||||
|
let (mut eva, eva_side, mut jan, jan_side) = pair(&relay);
|
||||||
|
let canary = "CANARY-7f3a91-the-relay-must-never-see-this";
|
||||||
|
eva.send(eva_side, canary).expect("send");
|
||||||
|
jan.send(jan_side, canary).expect("send");
|
||||||
|
// Before anyone fetches: the canaries are waiting on the relay, encrypted.
|
||||||
|
let stored = relay.everything_stored();
|
||||||
|
assert!(!stored.is_empty());
|
||||||
|
for (what, needle) in [
|
||||||
|
("canary", canary.as_bytes()),
|
||||||
|
("inviter's name", "Eva Nováková".as_bytes()),
|
||||||
|
("invitee's name", b"Jan".as_slice()),
|
||||||
|
] {
|
||||||
|
assert!(
|
||||||
|
!contains(&stored, needle),
|
||||||
|
"{what} is readable on the relay"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn a_link_works_once() {
|
||||||
|
let relay = MemoryTransport::default();
|
||||||
|
let mut eva = Client::new("Eva", relay.clone()).expect("eva");
|
||||||
|
let mut jan = Client::new("Jan", relay.clone()).expect("jan");
|
||||||
|
let mut mallory = Client::new("Mallory", relay.clone()).expect("mallory");
|
||||||
|
let invite = eva.create_invite().expect("invite");
|
||||||
|
jan.accept_invite(&invite).expect("first");
|
||||||
|
assert_eq!(
|
||||||
|
mallory.accept_invite(&invite),
|
||||||
|
Err(ClientError::Transport(TransportError::NotFound))
|
||||||
|
);
|
||||||
|
let joined: Vec<_> = eva.poll().expect("poll");
|
||||||
|
assert_eq!(joined.len(), 1, "exactly one person joined: {joined:?}");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn a_wrong_secret_claims_nothing() {
|
||||||
|
let relay = MemoryTransport::default();
|
||||||
|
let mut eva = Client::new("Eva", relay.clone()).expect("eva");
|
||||||
|
let mut jan = Client::new("Jan", relay.clone()).expect("jan");
|
||||||
|
let mut invite = eva.create_invite().expect("invite");
|
||||||
|
invite.secret = Token::from_bytes([7; 32]);
|
||||||
|
assert!(jan.accept_invite(&invite).is_err());
|
||||||
|
assert!(eva.poll().expect("poll").is_empty());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn junk_in_a_mailbox_is_dropped_and_never_shown() {
|
||||||
|
let relay = MemoryTransport::default();
|
||||||
|
let mut eva = Client::new("Eva", relay.clone()).expect("eva");
|
||||||
|
let mut jan = Client::new("Jan", relay.clone()).expect("jan");
|
||||||
|
let invite = eva.create_invite().expect("invite");
|
||||||
|
// Whoever holds the link can post to Eva's welcome mailbox: before, between and after the
|
||||||
|
// real Welcome and hello, bytes that are not MLS.
|
||||||
|
let (welcome_box, welcome_post) = welcome_mailbox(&invite.secret);
|
||||||
|
relay
|
||||||
|
.post(&welcome_box, &welcome_post, b"not MLS at all")
|
||||||
|
.expect("post");
|
||||||
|
let jan_side = jan.accept_invite(&invite).expect("accept");
|
||||||
|
relay
|
||||||
|
.post(&welcome_box, &welcome_post, &[0x00, 0x01, 0x00, 0x05])
|
||||||
|
.expect("post");
|
||||||
|
let events = eva.poll().expect("poll");
|
||||||
|
assert_eq!(events.len(), 1, "only the join is shown: {events:?}");
|
||||||
|
assert!(matches!(events[0], Event::Joined { .. }));
|
||||||
|
assert_eq!(
|
||||||
|
relay.waiting_blobs(),
|
||||||
|
1,
|
||||||
|
"junk acknowledged too; only Eva's hello to Jan waits"
|
||||||
|
);
|
||||||
|
jan.poll().expect("poll");
|
||||||
|
jan.send(jan_side, "still here").expect("send");
|
||||||
|
let Event::Joined {
|
||||||
|
contact: eva_side, ..
|
||||||
|
} = events[0].clone()
|
||||||
|
else {
|
||||||
|
unreachable!()
|
||||||
|
};
|
||||||
|
assert_eq!(
|
||||||
|
eva.poll().expect("poll"),
|
||||||
|
vec![Event::Message {
|
||||||
|
contact: eva_side,
|
||||||
|
text: "still here".into()
|
||||||
|
}]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn text_before_a_hello_is_not_shown() {
|
||||||
|
// A Welcome alone makes a group, not a contact: nothing is shown until the hello arrives.
|
||||||
|
let relay = MemoryTransport::default();
|
||||||
|
let mut eva = Client::new("Eva", relay.clone()).expect("eva");
|
||||||
|
let mut jan = Client::new("Jan", relay.clone()).expect("jan");
|
||||||
|
let invite = eva.create_invite().expect("invite");
|
||||||
|
let jan_side = jan.accept_invite(&invite).expect("accept");
|
||||||
|
assert_eq!(
|
||||||
|
jan.send(jan_side, "too early"),
|
||||||
|
Err(ClientError::UnknownContact)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn limits_are_kept() {
|
||||||
|
let relay = MemoryTransport::default();
|
||||||
|
assert!(Client::new(&"x".repeat(MAX_NAME_CHARS + 1), relay.clone()).is_err());
|
||||||
|
let (mut eva, eva_side, _jan, _) = pair(&relay);
|
||||||
|
assert_eq!(
|
||||||
|
eva.send(eva_side, &"x".repeat(MAX_TEXT_BYTES + 1)),
|
||||||
|
Err(ClientError::TooLong)
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
eva.send(ContactId(99), "hi"),
|
||||||
|
Err(ClientError::UnknownContact)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn the_welcome_mailbox_derivation_is_fixed() {
|
||||||
|
// A pinned vector: changing labels or the KDF breaks pairing between versions, so it must be
|
||||||
|
// a deliberate protocol change, not an accident.
|
||||||
|
let (id, post) = welcome_mailbox(&Token::from_bytes([0; 32]));
|
||||||
|
let (id2, post2) = welcome_mailbox(&Token::from_bytes([0; 32]));
|
||||||
|
assert_eq!((id, post.to_wire()), (id2, post2.to_wire()));
|
||||||
|
assert_ne!(
|
||||||
|
id.as_bytes()[..],
|
||||||
|
post.as_bytes()[..16],
|
||||||
|
"id and post token are independent"
|
||||||
|
);
|
||||||
|
assert_eq!(id.to_wire(), WELCOME_ID_VECTOR);
|
||||||
|
assert_eq!(post.to_wire(), WELCOME_POST_VECTOR);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Computed independently: HKDF-SHA256 (RFC 5869, empty salt) written out with Python's hmac module.
|
||||||
|
const WELCOME_ID_VECTOR: &str = "tsx3c7bagkEGmf1aDem6SA";
|
||||||
|
const WELCOME_POST_VECTOR: &str = "FE6Xgv4j9CYnZA1EF_l4UaCNkxrZrfXmkNXnwm9K02w";
|
||||||
@@ -0,0 +1,207 @@
|
|||||||
|
//! Two clients through the real relay over loopback TCP, then a byte search of the relay's
|
||||||
|
//! database file: the canary in a message, and both names, must not be in it (`PROTOCOL.md` §7).
|
||||||
|
//! The relay is a dev-dependency only; the client library never depends on it.
|
||||||
|
|
||||||
|
use std::io::{Read, Write};
|
||||||
|
use std::net::{SocketAddr, TcpStream};
|
||||||
|
use std::sync::Arc;
|
||||||
|
use tabellarius_client::*;
|
||||||
|
use tabellarius_protocol::*;
|
||||||
|
use tabellarius_relay::http::{router, AppState, Clock};
|
||||||
|
use tabellarius_relay::store::Store;
|
||||||
|
|
||||||
|
/// A deliberately small blocking HTTP/1.1 transport for the test: one connection per request.
|
||||||
|
#[derive(Clone)]
|
||||||
|
struct Http(SocketAddr);
|
||||||
|
|
||||||
|
impl Http {
|
||||||
|
fn call(
|
||||||
|
&self,
|
||||||
|
method: &str,
|
||||||
|
path: &str,
|
||||||
|
auth: Option<&Token>,
|
||||||
|
body: &[u8],
|
||||||
|
json: bool,
|
||||||
|
) -> Result<Vec<u8>, TransportError> {
|
||||||
|
let mut s = TcpStream::connect(self.0).map_err(|_| TransportError::Failed)?;
|
||||||
|
let auth = auth
|
||||||
|
.map(|t| format!("Authorization: {}\r\n", t.to_bearer()))
|
||||||
|
.unwrap_or_default();
|
||||||
|
let ctype = if json {
|
||||||
|
"Content-Type: application/json\r\n"
|
||||||
|
} else {
|
||||||
|
""
|
||||||
|
};
|
||||||
|
let head = format!(
|
||||||
|
"{method} {path} HTTP/1.1\r\nHost: relay\r\n{auth}{ctype}Content-Length: {}\r\nConnection: close\r\n\r\n",
|
||||||
|
body.len()
|
||||||
|
);
|
||||||
|
s.write_all(head.as_bytes())
|
||||||
|
.map_err(|_| TransportError::Failed)?;
|
||||||
|
s.write_all(body).map_err(|_| TransportError::Failed)?;
|
||||||
|
let mut resp = Vec::new();
|
||||||
|
s.read_to_end(&mut resp)
|
||||||
|
.map_err(|_| TransportError::Failed)?;
|
||||||
|
let split = resp
|
||||||
|
.windows(4)
|
||||||
|
.position(|w| w == b"\r\n\r\n")
|
||||||
|
.ok_or(TransportError::Failed)?;
|
||||||
|
let status = std::str::from_utf8(&resp[9..12]).map_err(|_| TransportError::Failed)?;
|
||||||
|
match status {
|
||||||
|
"200" | "201" | "204" => Ok(resp[split + 4..].to_vec()),
|
||||||
|
"404" => Err(TransportError::NotFound),
|
||||||
|
"409" => Err(TransportError::Conflict),
|
||||||
|
_ => Err(TransportError::Failed),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Transport for Http {
|
||||||
|
fn create_mailbox(&self, req: &CreateMailbox) -> Result<(), TransportError> {
|
||||||
|
let body = serde_json::to_vec(req).map_err(|_| TransportError::Failed)?;
|
||||||
|
self.call("POST", "/v0/mailboxes", None, &body, true)
|
||||||
|
.map(|_| ())
|
||||||
|
}
|
||||||
|
fn post(&self, id: &MailboxId, post: &Token, blob: &[u8]) -> Result<(), TransportError> {
|
||||||
|
self.call(
|
||||||
|
"POST",
|
||||||
|
&format!("/v0/mailboxes/{}/blobs", id.to_wire()),
|
||||||
|
Some(post),
|
||||||
|
blob,
|
||||||
|
false,
|
||||||
|
)
|
||||||
|
.map(|_| ())
|
||||||
|
}
|
||||||
|
fn fetch(&self, id: &MailboxId, fetch: &Token) -> Result<Vec<Vec<u8>>, TransportError> {
|
||||||
|
let body = self.call(
|
||||||
|
"GET",
|
||||||
|
&format!("/v0/mailboxes/{}/blobs", id.to_wire()),
|
||||||
|
Some(fetch),
|
||||||
|
&[],
|
||||||
|
false,
|
||||||
|
)?;
|
||||||
|
let blobs: FetchedBlobs =
|
||||||
|
serde_json::from_slice(&body).map_err(|_| TransportError::Failed)?;
|
||||||
|
Ok(blobs
|
||||||
|
.blobs
|
||||||
|
.into_iter()
|
||||||
|
.map(|b| b.blob.bytes().to_vec())
|
||||||
|
.collect())
|
||||||
|
}
|
||||||
|
fn acknowledge(
|
||||||
|
&self,
|
||||||
|
id: &MailboxId,
|
||||||
|
fetch: &Token,
|
||||||
|
hash: &Sha256Hash,
|
||||||
|
) -> Result<(), TransportError> {
|
||||||
|
let path = format!("/v0/mailboxes/{}/blobs/{}", id.to_wire(), hash.to_wire());
|
||||||
|
self.call("DELETE", &path, Some(fetch), &[], false)
|
||||||
|
.map(|_| ())
|
||||||
|
}
|
||||||
|
fn create_invite(&self, req: &CreateInvite) -> Result<(), TransportError> {
|
||||||
|
let body = serde_json::to_vec(req).map_err(|_| TransportError::Failed)?;
|
||||||
|
self.call("POST", "/v0/invites", None, &body, true)
|
||||||
|
.map(|_| ())
|
||||||
|
}
|
||||||
|
fn claim_invite(&self, id: &InviteId, secret: &Token) -> Result<Vec<u8>, TransportError> {
|
||||||
|
let body = self.call(
|
||||||
|
"GET",
|
||||||
|
&format!("/v0/invites/{}", id.to_wire()),
|
||||||
|
Some(secret),
|
||||||
|
&[],
|
||||||
|
false,
|
||||||
|
)?;
|
||||||
|
let claimed: ClaimedInvite =
|
||||||
|
serde_json::from_slice(&body).map_err(|_| TransportError::Failed)?;
|
||||||
|
Ok(claimed.key_package.bytes().to_vec())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Starts the real relay on 127.0.0.1:<free port> with its database in `db`.
|
||||||
|
fn start_relay(db: &std::path::Path) -> SocketAddr {
|
||||||
|
let store = Arc::new(Store::open(db).expect("store"));
|
||||||
|
let clock: Clock = Arc::new(|| 1_794_000_000);
|
||||||
|
let app = router(AppState { store, clock });
|
||||||
|
let (tx, rx) = std::sync::mpsc::channel();
|
||||||
|
std::thread::spawn(move || {
|
||||||
|
let rt = tokio::runtime::Builder::new_current_thread()
|
||||||
|
.enable_all()
|
||||||
|
.build()
|
||||||
|
.expect("runtime");
|
||||||
|
rt.block_on(async move {
|
||||||
|
let listener = tokio::net::TcpListener::bind("127.0.0.1:0")
|
||||||
|
.await
|
||||||
|
.expect("bind");
|
||||||
|
tx.send(listener.local_addr().expect("addr"))
|
||||||
|
.expect("send addr");
|
||||||
|
let _ = axum::serve(listener, app).await;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
rx.recv().expect("relay address")
|
||||||
|
}
|
||||||
|
|
||||||
|
fn contains(haystack: &[u8], needle: &[u8]) -> bool {
|
||||||
|
!needle.is_empty() && haystack.windows(needle.len()).any(|w| w == needle)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn pair_and_talk_through_a_real_relay_which_never_sees_a_name_or_a_word() {
|
||||||
|
let dir = tempfile::tempdir().expect("tempdir");
|
||||||
|
let db = dir.path().join("relay.db");
|
||||||
|
let relay = Http(start_relay(&db));
|
||||||
|
|
||||||
|
let mut eva = Client::new("Eva Nováková", relay.clone()).expect("eva");
|
||||||
|
let mut jan = Client::new("Jan Dvořák", relay.clone()).expect("jan");
|
||||||
|
let invite = eva.create_invite().expect("invite");
|
||||||
|
// While the invite waits, the relay holds Eva's KeyPackage: it must not carry her name.
|
||||||
|
let invited = std::fs::read(&db).expect("db");
|
||||||
|
let jan_side = jan.accept_invite(&invite).expect("accept");
|
||||||
|
let events = eva.poll().expect("poll");
|
||||||
|
let Some(Event::Joined {
|
||||||
|
contact: eva_side,
|
||||||
|
name,
|
||||||
|
}) = events.first().cloned()
|
||||||
|
else {
|
||||||
|
panic!("no join: {events:?}");
|
||||||
|
};
|
||||||
|
assert_eq!(name, "Jan Dvořák");
|
||||||
|
assert_eq!(jan.poll().expect("poll").len(), 1);
|
||||||
|
|
||||||
|
let canary = "CANARY-relay-test-4b2e-never-in-the-database";
|
||||||
|
eva.send(eva_side, canary).expect("send");
|
||||||
|
jan.send(jan_side, &format!("re: {canary}")).expect("send");
|
||||||
|
|
||||||
|
// Snapshot the database while both messages wait, before anyone fetches.
|
||||||
|
let waiting = std::fs::read(&db).expect("db");
|
||||||
|
assert_eq!(
|
||||||
|
jan.poll().expect("poll"),
|
||||||
|
vec![Event::Message {
|
||||||
|
contact: jan_side,
|
||||||
|
text: canary.into()
|
||||||
|
}]
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
eva.poll().expect("poll"),
|
||||||
|
vec![Event::Message {
|
||||||
|
contact: eva_side,
|
||||||
|
text: format!("re: {canary}")
|
||||||
|
}]
|
||||||
|
);
|
||||||
|
let after = std::fs::read(&db).expect("db");
|
||||||
|
|
||||||
|
for snapshot in [&invited, &waiting, &after] {
|
||||||
|
for (what, needle) in [
|
||||||
|
("canary", canary.as_bytes()),
|
||||||
|
("inviter's name", "Eva Nováková".as_bytes()),
|
||||||
|
("invitee's name", "Jan Dvořák".as_bytes()),
|
||||||
|
("invite secret", invite.secret.as_bytes().as_slice()),
|
||||||
|
] {
|
||||||
|
assert!(
|
||||||
|
!contains(snapshot, needle),
|
||||||
|
"{what} is readable in the relay's database"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// The messages were there, as ciphertext: the database grew while they waited.
|
||||||
|
assert!(waiting.len() >= 4096, "the relay stored something");
|
||||||
|
}
|
||||||
+41
-5
@@ -1,7 +1,8 @@
|
|||||||
# Tabellarius protocol v0 — what crosses the wire, and what the relay learns
|
# Tabellarius protocol v0 — what crosses the wire, and what the relay learns
|
||||||
|
|
||||||
**Approved 2026-11-08 (Mark)** as v0, before any relay code. Every claim below must have a test. A change
|
**Approved 2026-11-08 (Mark)** as v0, before any relay code. Every claim below must have a test. A change
|
||||||
is a protocol version bump: documented, reviewed, approved (`CLAUDE.md` §2.2).
|
is a protocol version bump: documented here with its date and reason, and reviewed in its PR
|
||||||
|
(`CLAUDE.md` §2.2, §3).
|
||||||
|
|
||||||
## 1. Threat model
|
## 1. Threat model
|
||||||
| Adversary | Protected | Not protected |
|
| Adversary | Protected | Not protected |
|
||||||
@@ -27,10 +28,23 @@ is a protocol version bump: documented, reviewed, approved (`CLAUDE.md` §2.2).
|
|||||||
- **Block** = the owner rotates the post token; the old one is refused. The blocked person is not told.
|
- **Block** = the owner rotates the post token; the old one is refused. The blocked person is not told.
|
||||||
|
|
||||||
## 4. Invitations
|
## 4. Invitations
|
||||||
A QR code (in person) or a link carries: relay URL, an invite id, and a one-time fetch secret. The
|
A QR code (in person) or a link carries: relay URL, an invite id, and a one-time secret. Unclaimed
|
||||||
invitee fetches the inviter's MLS KeyPackage from the relay with it, replies with their own, and
|
invites expire after **7 days** *(decided 2026-11-08)*.
|
||||||
both sides exchange mailbox ids and post tokens **inside** MLS. Unclaimed invites expire after
|
1. **The inviter** leaves its MLS KeyPackage on the relay under the invite id and the secret's hash.
|
||||||
**7 days** *(decided 2026-11-08)*.
|
It also creates a **welcome mailbox**, whose id and post token are derived from the secret with
|
||||||
|
HKDF-SHA256: empty salt, info `tabellarius v0 welcome mailbox` (16 bytes) and
|
||||||
|
`tabellarius v0 welcome mailbox post` (32 bytes).
|
||||||
|
2. **The invitee** claims the KeyPackage with the secret, which deletes the invite. It creates the
|
||||||
|
MLS group with the inviter in it, and posts to the welcome mailbox:
|
||||||
|
- the Welcome;
|
||||||
|
- an MLS message carrying its own mailbox id, a post token for it, and its name.
|
||||||
|
3. **The inviter** joins from the Welcome and answers inside MLS with its own mailbox, post token and
|
||||||
|
name.
|
||||||
|
|
||||||
|
From then on each side posts to the other's mailbox. Names and post tokens travel **only inside
|
||||||
|
MLS**. To the relay, the welcome mailbox is an ordinary mailbox.
|
||||||
|
*(Changed 2026-11-14, approved by Mark, from "the invitee replies with their own KeyPackage": the
|
||||||
|
invitee needs no KeyPackage, because it creates the group itself.)*
|
||||||
|
|
||||||
## 5. What the relay stores — the complete list
|
## 5. What the relay stores — the complete list
|
||||||
| Table | Columns |
|
| Table | Columns |
|
||||||
@@ -61,3 +75,25 @@ The platform facts above are Claude's understanding, to be verified in `.agents/
|
|||||||
- A delivered blob is gone; an undelivered blob is gone after the TTL (clock injected).
|
- A delivered blob is gone; an undelivered blob is gone after the TTL (clock injected).
|
||||||
- Parsers are fuzzed (`cargo fuzz`) for every message type.
|
- Parsers are fuzzed (`cargo fuzz`) for every message type.
|
||||||
- Every check in `VERIFY.md` §1 has a CI job or a documented manual procedure.
|
- 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
|
||||||
|
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.
|
||||||
|
|
||||||
|
| Method and path | Auth (`Authorization: Bearer`) | Effect |
|
||||||
|
|:--|:--|:--|
|
||||||
|
| `POST /v0/mailboxes` `{id, postTokenHash, fetchTokenHash}` | none | creates a mailbox. The owner sends **hashes**, so the relay never holds a token |
|
||||||
|
| `POST /v0/mailboxes/{id}/blobs` (bytes) | post token | stores the blob with its size and the hour it arrived |
|
||||||
|
| `GET /v0/mailboxes/{id}/blobs` | fetch token | the waiting blobs, oldest first, at most 100. Fetching deletes nothing |
|
||||||
|
| `DELETE /v0/mailboxes/{id}/blobs/{sha256}` | fetch token | acknowledges: deletes that mailbox's blob with this SHA-256. §5 has no blob id, and a sequential id would leak how busy the relay is |
|
||||||
|
| `PUT /v0/mailboxes/{id}/post-token` `{postTokenHash}` | fetch token | blocks: the old post token is refused from now on |
|
||||||
|
| `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 |
|
||||||
|
| `GET /version` | none | the protocol and relay versions |
|
||||||
|
|
||||||
|
- A wrong token, an unknown id and a malformed id all give the same bare **404**, so nobody can probe
|
||||||
|
what exists.
|
||||||
|
- A refusal has no body.
|
||||||
|
- The relay prints no request.
|
||||||
|
- Tests: `crates/relay/tests/relay.rs`, `crates/protocol/tests/wire.rs`.
|
||||||
|
|||||||
Reference in New Issue
Block a user