Fundamentum client v0.5.0
This commit is contained in:
@@ -0,0 +1,195 @@
|
||||
# Tabellarius — the relay and MLS groups (design note, day 2)
|
||||
|
||||
*Tabellarius*: the Roman letter carrier. He carried sealed tablets and could not read them.
|
||||
|
||||
Written before the code. Every app syncs its own encrypted event log through one relay, between your own
|
||||
devices and between people, without the relay being able to read anything or tell who is who.
|
||||
|
||||
## 1. Layers
|
||||
|
||||
```
|
||||
AppEvent { kind, body } the app's change
|
||||
→ TEV1 envelope (docs/TESSERA.md §8) signed by the app's subkey, carries its cert
|
||||
→ TBA1 batch of envelopes one MLS application message
|
||||
→ MLS PrivateMessage (OpenMLS) encrypted to the group's current epoch
|
||||
→ relay mailbox ciphertext, seq, size, time — nothing else
|
||||
```
|
||||
|
||||
**Deviation from the plan, on purpose.** The plan put the MLS ciphertext *inside* the envelope. But the
|
||||
envelope carries the Tessera cert and the author's subkey in the clear, so a relay that stored envelopes would
|
||||
learn who wrote what, and could link one person's mailboxes through their root key. The privacy rules win: the
|
||||
envelope travels **inside** MLS. The relay stores only MLS ciphertext. Receivers still verify every envelope
|
||||
on its own (`Envelope::verify` against the group members' roots), so an event stays attributable and
|
||||
re-verifiable after it leaves MLS, for example in a history batch for a new device (§6).
|
||||
|
||||
## 2. Identity inside MLS
|
||||
|
||||
- **Ciphersuite** `MLS_128_DHKEMX25519_CHACHA20POLY1305_SHA256_Ed25519`. Handshake messages are encrypted
|
||||
too (`PURE_CIPHERTEXT_WIRE_FORMAT_POLICY`): commits travel as PrivateMessages, so the relay does not learn
|
||||
who added or removed whom.
|
||||
- **MLS signature key**: a fresh Ed25519 key per device per group, generated by OpenMLS. The Tessera subkey
|
||||
never leaves tessera (it has no byte export), so it cannot be the MLS key itself. Instead it vouches for it.
|
||||
- **Credential** (`BasicCredential`, identity bytes, `TDC1`):
|
||||
```
|
||||
"TDC1" ‖ u16 len ‖ SubkeyCert ‖ mailbox_key (32) ‖ binding (64)
|
||||
binding = Ed25519(subkey, "tessera credential v1\0" ‖ mls_signature_key ‖ mailbox_key) (Subkey::sign_credential_tbs)
|
||||
```
|
||||
A member is accepted only if its cert verifies under its root now, its cert is for the group's app, and the
|
||||
binding signature by the cert's subkey covers its leaf's MLS signature key and mailbox key.
|
||||
- **The group's roots** are the roots of its members' certs; `Envelope::verify` uses them. A **self group**
|
||||
accepts only members whose root is the creator's root (your own devices).
|
||||
- New members are checked when a commit adds them and, on joining, every member of the Welcome's tree.
|
||||
A commit that adds an invalid member is not merged; it is reported as rejected.
|
||||
|
||||
## 3. The relay: mailboxes
|
||||
|
||||
A mailbox id is 32 bytes, base64url:
|
||||
- a **group mailbox** is `SHA-256("tabellarius mailbox v1" ‖ MLS group id)`;
|
||||
- an **invite mailbox** is 32 random bytes.
|
||||
|
||||
What the relay stores, and why (SQLite, nothing else):
|
||||
|
||||
| Table | Columns | Why |
|
||||
|:--|:--|:--|
|
||||
| `messages` | `mailbox_id, seq, size, received_at, ciphertext` | the mail |
|
||||
| `keys` | `key, mailbox_id` — `key` is **unique across all mailboxes** | who may read and write a mailbox |
|
||||
| `acks` | `key, seq` | retention: what every member has fetched |
|
||||
| `nonces` | `key, nonce, expires` (5 minutes) | replay protection |
|
||||
|
||||
No accounts, no IP addresses, no user agents, no app names, no certs. The relay's own logs are counts and
|
||||
status codes, never ids or keys. Caddy's access log for this vhost is off.
|
||||
|
||||
### Requests
|
||||
|
||||
Every request except `GET /v1/health` is signed by a **random per-mailbox Ed25519 key**. A device makes a new
|
||||
one for every group it joins and every invite. The relay never sees a Tessera key or cert, so it cannot link
|
||||
mailboxes to each other or to a person. A key registered in one mailbox cannot be registered in another.
|
||||
|
||||
```
|
||||
Tab-Key: base64url(public key)
|
||||
Tab-Time: Unix seconds
|
||||
Tab-Nonce: base64url(16 random bytes)
|
||||
Tab-Sig: base64url(Ed25519("tabellarius request v1\0" ‖ METHOD ‖ "\n" ‖ path?query ‖ "\n" ‖ time ‖ "\n" ‖ nonce ‖ "\n" ‖ hex(SHA-256(body))))
|
||||
```
|
||||
|
||||
| Check | Answer |
|
||||
|:--|:--|
|
||||
| any header missing or malformed | 401 `unsigned` |
|
||||
| `|now − time| > 120 s` | 401 `stale` |
|
||||
| bad signature | 401 `bad_signature` |
|
||||
| key not registered in this mailbox (except `PUT` creating it) | 403 `unregistered_key` |
|
||||
| nonce already seen for this key | 401 `replayed` |
|
||||
| more than 120 requests a minute for this key | 429 `slow_down` |
|
||||
|
||||
A rejected request changes nothing and stores nothing (not even its nonce).
|
||||
|
||||
| Endpoint | What |
|
||||
|:--|:--|
|
||||
| `PUT /v1/mailboxes/{id}` | create; the signing key becomes its first key. 409 `exists`, 409 `key_in_use` |
|
||||
| `POST /v1/mailboxes/{id}/keys` `{"key"}` | a member registers another member's key. 409 `key_in_use` |
|
||||
| `DELETE /v1/mailboxes/{id}/keys/{key}` | deregister (removal, or leaving). The last key gone → the mailbox and its mail are deleted |
|
||||
| `POST /v1/mailboxes/{id}/messages` `{"messages":[b64…]}` | append; at most 100 per batch, 300 KiB each, 2 MiB per request. A message already in the mailbox (same bytes) is not stored again; its seq is returned. → `{"seqs":[…]}` |
|
||||
| `GET /v1/mailboxes/{id}/messages?after=N` | up to 200 messages with `seq > N` → `{"messages":[{"seq","data"}],"more"}` |
|
||||
| `POST /v1/mailboxes/{id}/ack` `{"seq"}` | this key has everything up to `seq` |
|
||||
| `GET /v1/health` | `ok`, unsigned |
|
||||
| `GET /v1/live` | v1.1b: a WebSocket of notices `{"mailbox","seq"}`; each subscription is signed in the first message (docs/V1_1B.md §3) |
|
||||
|
||||
Every answer carries `Access-Control-Allow-Origin: *`, and `OPTIONS` answers a preflight, so a PWA on another
|
||||
origin can call the relay (docs/V1_1B.md §4). Caddy strips `Origin`, `Referer` and `User-Agent` first.
|
||||
|
||||
### Retention (config values)
|
||||
A message is deleted once **every key of its mailbox has acknowledged it and it is older than 30 days**
|
||||
(`retention_acked_days`). Every message is deleted after **90 days** regardless (`retention_max_days`). The
|
||||
plan said "30 days after the last ack"; the relay does not record when an ack happened, so it counts from
|
||||
receipt. That can delete earlier than the plan for a member who acked late, never later than 90 days.
|
||||
|
||||
## 4. Invites
|
||||
|
||||
An invite is a capability: whoever holds the token can ask to join, and the inviter's device accepts any
|
||||
**valid** credential (a valid cert for the group's app; for a self group, the same root).
|
||||
|
||||
1. The inviter's `invite(group)` creates an invite mailbox (its own fresh key) and registers a second fresh
|
||||
key whose secret goes into the token. It also makes a one-time HPKE key pair.
|
||||
2. Token: `tab1:` + base64url(`relay url ‖ invite mailbox ‖ access key secret ‖ inviter HPKE public key ‖ app`),
|
||||
about 150 bytes, small enough for a QR code. It carries no identity.
|
||||
3. The joiner's `join(token)` makes its MLS signature key, a group mailbox key and a KeyPackage with its
|
||||
credential. It HPKE-seals the KeyPackage to the inviter's key (`info = "tabellarius invite v1"`) and posts it
|
||||
to the invite mailbox. The relay never sees the credential.
|
||||
4. The inviter's next `sync` opens it and checks the credential (§2). It then commits the Add to the group
|
||||
mailbox, registers the joiner's mailbox key there, and posts `TIW1 ‖ seq ‖ Welcome` to the invite mailbox
|
||||
(`seq`: where the joiner starts reading the group mailbox). Then it sends the group's history (§6).
|
||||
5. The joiner's next `sync` reads the Welcome, checks every member, joins, and deregisters its invite key.
|
||||
|
||||
## 5. Sync, offline first
|
||||
|
||||
- `send(group, events)` seals each event in an envelope (HLC from the device clock), applies them to the local
|
||||
log, encrypts one TBA1 batch per MLS message, and queues the ciphertext in the **outbox**. It never needs the
|
||||
relay.
|
||||
- `sync(group)`:
|
||||
1. uploads the outbox;
|
||||
2. pulls since the cursor; processes commits (credential checks, then merge) and application messages
|
||||
(every envelope verified, then `tessera::merge`);
|
||||
3. acks.
|
||||
|
||||
Messages it sent itself are recognised by hash and skipped. If the relay is unreachable, `sync` returns
|
||||
`relay_ok: false` and changes nothing; the app shows "last synced" quietly.
|
||||
- Rejected events and members come back in `SyncReport::rejected` with the reason, never half-applied.
|
||||
- Group state (OpenMLS storage, keys, cursors, the log, the outbox) is saved through a `StateStore`. The file
|
||||
store encrypts it (XChaCha20-Poly1305) with a 32-byte key **held in Custos**. The state never lies on disk in
|
||||
the clear.
|
||||
|
||||
## 6. History for a new member
|
||||
|
||||
MLS gives a new member nothing from before it joined. A new device of yours must still see the whole log, so
|
||||
after an Add the inviter sends the existing envelopes as ordinary TBA1 batches. Each envelope is still signed
|
||||
by its author and verified by the receiver, and duplicates disappear in `merge`.
|
||||
|
||||
## 7. Removal
|
||||
|
||||
`remove(group, member)` commits a Remove and deregisters the member's mailbox key (it is in the member's
|
||||
credential). The removed device can no longer fetch (403). Even with the ciphertext in hand, it cannot decrypt
|
||||
anything from the next epoch on.
|
||||
|
||||
## 7a. v1.1: revocation, renewal, backup (docs/V1_1.md)
|
||||
|
||||
- **Revocation.**
|
||||
- A `TRV1` statement (docs/TESSERA.md §12) travels as an event of kind `tessera.revoke`.
|
||||
- `log()` leaves out every event a complete revocation rules out, and the revocations themselves.
|
||||
- Events ruled out on arrival are reported in `SyncReport::rejected`.
|
||||
- `revoke(group, statements)` announces, uploads, then removes the revoked leaves and deregisters their
|
||||
mailbox keys.
|
||||
- A device of the same person that sees a revocation in force removes the leaves on its next sync.
|
||||
- **Who may remove whom.** A commit that removes some of another person's devices, while that person stays in
|
||||
the group, needs that person's revocation in the log for each one; otherwise it is not applied. Removing
|
||||
all of a person's devices removes the person, as in v0.2.
|
||||
- **Renewal.**
|
||||
- `renew(cert)` takes a new cert for the same subkey and commits a self-update with the new credential in
|
||||
every group.
|
||||
- A member's updated credential is checked like a new member's.
|
||||
- A device whose cert has expired cannot be joined (the joiner checks every leaf), so renew before expiry.
|
||||
- **The root-sealed backup.**
|
||||
- `backup(secret)` uploads the self group's log to the backup mailbox: id = SHA-256(`tabellarius backup
|
||||
v1` ‖ the access key's public key), access key from the secret's mailbox seed. It goes in 200 KiB parts,
|
||||
each `seal(nonce, aad = "tabellarius backup v1", id ‖ part ‖ parts ‖ chunk)`: the relay sees ciphertext
|
||||
of known sizes, no header.
|
||||
- It acks the previous backups, so the relay drops them after its retention.
|
||||
- An unchanged log is not uploaded again.
|
||||
- `restore(secret)` returns the envelopes of the latest complete backup; `import(group, envelopes)`
|
||||
verifies each at its own time and sends them into a new self group.
|
||||
- **Retention:** the relay keeps every message at most 90 days, so a backup survives 90 days after its
|
||||
last upload.
|
||||
|
||||
## 8. Known limits (v1)
|
||||
|
||||
- **Concurrent commits.** If two members commit in the same epoch, the one the relay ordered second is
|
||||
dropped by the others. Its sender sees the conflict on the next sync, discards its own commit, and must redo
|
||||
it. Day 2 tests commits sequentially.
|
||||
- The relay sees **timing and sizes**: when a mailbox is written and fetched, and how large each message is.
|
||||
Fetching several mailboxes from one connection links them by IP. Caddy drops access logs, but the network
|
||||
path still sees it.
|
||||
- A leaked invite token lets its holder join until the inviter's device accepts the first answer. One answer
|
||||
per token is accepted; the token is dead afterwards.
|
||||
- A browser sends a CORS preflight before each request (the URL changes with `?after=N`): twice the round
|
||||
trips (docs/V1_1B.md Status).
|
||||
- Live subscribe (v1.1b) tells a client *that* a mailbox has mail, never what. Native apps still poll; the
|
||||
browser package listens.
|
||||
+255
@@ -0,0 +1,255 @@
|
||||
# Tessera and the event envelope — design note (v1)
|
||||
|
||||
*A tessera hospitalis was a token broken between two families so they could recognise each other.*
|
||||
|
||||
Status: written before the code on day 1. Every format here is versioned by its magic; a change bumps it.
|
||||
|
||||
## 1. What it is for
|
||||
|
||||
One Domi identity per person, held in Custos. Every Domi app gets its **own subkey**, certified by that
|
||||
identity, so no app ever creates long-term identity on its own. Apps then sign their events with the subkey;
|
||||
anyone who knows the person's root public key can check that an event really came from one of their apps.
|
||||
|
||||
| Piece | Lives in | Holds secrets? |
|
||||
|:--|:--|:--|
|
||||
| Root key | the Custos vault, never leaves it (CustosPublic `custos-vault`, `docs/IDENTITY.md` there) | yes |
|
||||
| Root derivation, cert format, cert verification, match code, HLC, merge | `crates/tessera` | no, except in-memory `RootKey`/`Subkey` |
|
||||
| Event envelope | `crates/envelope` | no |
|
||||
| Asking Custos for a cert on Windows | `crates/custos-local` | no |
|
||||
|
||||
`tessera` and `envelope` are **pure**: no I/O, no network, no clock. Time is always a parameter.
|
||||
|
||||
## 2. Encoding primitives
|
||||
|
||||
All multi-byte integers are big-endian. `str8` = one length byte, then that many bytes. Text fields are
|
||||
restricted ASCII so there is exactly one encoding of every value:
|
||||
|
||||
- **id** (`app_id`, `purpose`, envelope `app`): 1–32 bytes of `[a-z0-9-]`, not starting or ending with `-`.
|
||||
|
||||
Base64 in JSON and QR codes is **base64url without padding**.
|
||||
|
||||
## 3. The root key
|
||||
|
||||
```
|
||||
entropy 32 bytes from the OS CSPRNG (Custos makes it; tessera only takes it as a parameter)
|
||||
mnemonic BIP39, English, 24 words = bip39::Mnemonic::from_entropy(entropy)
|
||||
seed BIP39 seed of the mnemonic with the empty passphrase (PBKDF2-HMAC-SHA512, 2048 rounds, 64 bytes)
|
||||
root Ed25519 secret key = HKDF-SHA256(salt = "tessera root v1", ikm = seed, info = "ed25519")[0..32]
|
||||
```
|
||||
|
||||
- The same mnemonic gives the same root public key, every time (test vector in §9).
|
||||
- **Order (decided):** entropy → mnemonic shown **once** → root imported into the vault → entropy, seed and
|
||||
mnemonic dropped (zeroized). A key that was created non-extractable first could never be backed up, so the
|
||||
code makes the other order impossible: Custos' `Enrollment` is a typestate (`begin → show → confirm →
|
||||
import`), and `import` exists only on the type that `show` returns.
|
||||
- `tessera::RootKey::from_mnemonic` exists for recovery (v1.1) and tests. It has no method that returns the
|
||||
secret; it can only sign certs and report its public key.
|
||||
|
||||
## 4. Subkey certificate (`TSC1`)
|
||||
|
||||
```
|
||||
"TSC1" 4
|
||||
root 32 the root public key that signs this cert
|
||||
subkey 32 the subkey's Ed25519 public key
|
||||
app_id str8 id; "device" is reserved for device subkeys
|
||||
purpose str8 id, e.g. "sync"; for device subkeys "device"
|
||||
not_before 8 u64 Unix seconds
|
||||
not_after 8 u64 Unix seconds, > not_before
|
||||
sig 64 Ed25519(root, "tessera cert v1\0" ‖ every byte above)
|
||||
```
|
||||
|
||||
`tbs` ("to be signed") is every byte before `sig`. The domain prefix means the root can only ever sign
|
||||
something that parses as a cert: Custos' vault refuses a `tbs` that does not start with `TSC1` and name its
|
||||
own root.
|
||||
|
||||
`verify(cert, root, now)` checks, in this order, and returns the first failure:
|
||||
|
||||
| Check | Error |
|
||||
|:--|:--|
|
||||
| `cert.root == root` | `WrongRoot` |
|
||||
| signature valid (`verify_strict`) | `BadSignature` (tampered) |
|
||||
| `now >= not_before` | `NotYetValid` |
|
||||
| `now < not_after` | `Expired` |
|
||||
|
||||
Decoding is strict: wrong magic, a wrong length, an invalid id, `not_after <= not_before` or trailing bytes
|
||||
are errors.
|
||||
|
||||
**Validity Custos issues:** `not_before = now − 5 min` (clock skew between devices), `not_after = now + 365 days`.
|
||||
Renewal and revocation are v1.1.
|
||||
|
||||
## 5. Match code
|
||||
|
||||
Six digits the app and Custos both show, so the person approves the key the app actually holds:
|
||||
|
||||
```
|
||||
match = u32_be(SHA-256("tessera match v1" ‖ subkey_pub)[0..4]) mod 1 000 000, zero-padded to 6 digits
|
||||
```
|
||||
|
||||
The code is not secret. Test vector in §9.
|
||||
|
||||
## 6. Hybrid logical clock
|
||||
|
||||
`Hlc { wall: u64 ms, logical: u32 }`, ordered by `wall` then `logical`; encoded as 12 bytes.
|
||||
|
||||
- `Clock::tick(now)`: `wall' = max(last.wall, now)`; `logical' = last.logical + 1` if `wall' == last.wall`,
|
||||
else 0.
|
||||
- `Clock::observe(remote, now)`: refuses `remote.wall > now + max_drift` (`TooFarAhead`); then
|
||||
`wall' = max(last.wall, remote.wall, now)` and `logical'` per the HLC paper (the larger logical of the
|
||||
clocks that hold `wall'`, plus one).
|
||||
- A logical counter that would overflow is an error, never a wrap.
|
||||
|
||||
## 7. Merge
|
||||
|
||||
`merge(log, batch, verify) -> (log', rejected)`:
|
||||
|
||||
- Each event has an **order key** `(hlc, author, hash)`, where `hash = SHA-256(encoded event)`.
|
||||
- Every event in `batch` is verified with the caller's `verify`; a failure goes to `rejected` with its
|
||||
reason and is never inserted (the app logs it).
|
||||
- `log'` = the union of `log` and the verified events, de-duplicated by `hash`, sorted by order key.
|
||||
- The log's bytes are `u32 length ‖ encoded event` for each event in order. Merging the same batches in any
|
||||
order, any number of times, gives byte-identical logs (property test).
|
||||
|
||||
The events already in `log` are not verified again: they were verified when they arrived.
|
||||
|
||||
## 8. The event envelope (`TEV1`)
|
||||
|
||||
```
|
||||
"TEV1" 4
|
||||
then exactly these fields, in this order, each as tag (1) ‖ length (u32) ‖ value:
|
||||
1 app id
|
||||
2 schema u32 (4 bytes): the version of the payload's schema
|
||||
3 hlc 12 bytes
|
||||
4 author 32 bytes: the subkey public key
|
||||
5 cert a TSC1 cert (§4)
|
||||
6 payload 0–256 KiB: MLS ciphertext from day 2; opaque here
|
||||
7 sig 64 bytes: Ed25519(author, "tessera event v1\0" ‖ every byte before field 7)
|
||||
```
|
||||
|
||||
Decoding is strict and total: it returns a whole `Envelope` or a typed error with a reason (`BadMagic`,
|
||||
`UnknownField`, `FieldOutOfOrder`, `BadLength`, `Invalid`, `TrailingBytes`, `TooLarge`, …). An unknown tag is
|
||||
`UnknownField`, a known tag in the wrong place is `FieldOutOfOrder`. Encoding is canonical: decoding and
|
||||
encoding again gives the same bytes. A decoded envelope is not yet trusted.
|
||||
|
||||
`Envelope::verify(roots, now, max_drift)` checks:
|
||||
|
||||
| Check | Error |
|
||||
|:--|:--|
|
||||
| `author == cert.subkey` | `AuthorNotCert` |
|
||||
| `cert.app_id == app` (app boundaries) | `WrongApp` |
|
||||
| `cert.root` is one of the trusted `roots` (the group's members) | `UnknownRoot` |
|
||||
| the cert is valid at the event's time (`hlc.wall / 1000`), §4 | `Cert(…)` |
|
||||
| `hlc.wall <= now + max_drift` | `FromTheFuture` |
|
||||
| the signature is valid (`verify_strict`) | `BadSignature` |
|
||||
|
||||
The cert is checked at the event's own time, so a log stays verifiable after a cert expires and rebuilding
|
||||
from it is deterministic. The cost: whoever steals a subkey can backdate events into its validity. Revocation
|
||||
(v1.1) closes this; until then validity is one year.
|
||||
|
||||
## 9. Test vectors
|
||||
|
||||
| Input | Output |
|
||||
|:--|:--|
|
||||
| entropy `00` × 32 | mnemonic `abandon` × 23 + `art` |
|
||||
| that mnemonic | root public key in `crates/tessera/tests/mandatory.rs` (`ROOT_PUB_ZERO`), also pinned in CustosPublic |
|
||||
| subkey public key `07` × 32 | match code in `crates/tessera/tests/mandatory.rs` |
|
||||
|
||||
## 10. Asking Custos for a cert (`custos-local`, Windows)
|
||||
|
||||
Custos' local API is the named pipe `\\.\pipe\custos-domi` (Custos `docs/02_app.md`; only the current
|
||||
Windows user can open it; Custos identifies the caller by its executable). Day 1 adds one operation:
|
||||
|
||||
```
|
||||
→ {"op":"subkey","app":"Fiscus Domi","app_id":"fiscus","purpose":"sync","subkey":"<base64url 32 bytes>"}
|
||||
← {"ok":true,"cert":"<base64url TSC1>","match":"123456"}
|
||||
← {"ok":false,"error":"denied"|"locked"|"no_identity"|"bad_request","message":"…"}
|
||||
```
|
||||
|
||||
1. The app makes its subkey itself (`Subkey::from_seed` with 32 bytes from the OS CSPRNG) and keeps the seed
|
||||
in Custos (`set domi://<app_id>/tessera-subkey`), never in a file.
|
||||
2. It shows the match code of its subkey and sends the request.
|
||||
3. Custos shows the app (program path and signer), the app id, the purpose and the match code. One click
|
||||
approves. Custos signs the cert with the root, records it (Domi identity → apps), and answers.
|
||||
|
||||
No answer ever contains private key material: only the cert (public keys and a signature).
|
||||
|
||||
## 11. Not in v1
|
||||
|
||||
Revocation, renewal, recovery UI (v1.1), MLS and the relay (day 2), WASM (v1.1).
|
||||
|
||||
## 12. v1.1: revocation and the backup secret (docs/V1_1.md)
|
||||
|
||||
### Revocation (`TRV1`)
|
||||
```
|
||||
"TRV1" 4
|
||||
root 32 the root that withdraws the subkey
|
||||
subkey 32 the revoked subkey
|
||||
revoked_at 8 u64 Unix seconds
|
||||
part 2 u16, this part's index
|
||||
parts 2 u16, how many parts the statement has (1..256)
|
||||
count 4 u32, hashes in this part (0..7000)
|
||||
hashes count×32 SHA-256 of each event by the subkey that stays valid: sorted, unique
|
||||
sig 64 Ed25519(root, "tessera revoke v1\0" ‖ every byte above)
|
||||
```
|
||||
- The root signs it through `RevokeSigner::sign_revocation_tbs`, in its own domain. A signer refuses a `tbs`
|
||||
that does not start `TRV1 ‖ its own root`, and the cert signer refuses a `TRV1`, so neither statement can
|
||||
pass for the other.
|
||||
- Decoding is strict: wrong magic, a part outside its count, unsorted or repeated hashes, a short field or
|
||||
trailing bytes are errors.
|
||||
- **`RevocationSet`** applies a group's statements:
|
||||
- A statement counts once all its parts are in (parts add up).
|
||||
- An event by a revoked subkey stays valid only if every complete statement for that subkey lists it, so a
|
||||
later statement never widens what is kept.
|
||||
- The answer does not depend on the order statements arrive in.
|
||||
- Statements are accepted only from a root of the group.
|
||||
|
||||
### The backup secret
|
||||
```
|
||||
backup secret = HKDF-SHA256(salt "tessera backup v1", ikm = root secret (the Ed25519 seed, §3), info = app id)
|
||||
seal key = HKDF-Expand(backup secret, "seal") XChaCha20-Poly1305: nonce (24) ‖ ciphertext
|
||||
mailbox seed = HKDF-Expand(backup secret, "mailbox") the backup mailbox's Tabellarius access key
|
||||
```
|
||||
- Custos derives it (the root never leaves Custos) and hands an app only its own.
|
||||
- `BackupSecret` has no method that returns the secret: it seals, opens, and gives the mailbox seed. That seed
|
||||
is a relay credential of the kind invite tokens carry, the one exception in `tests/surface.rs`.
|
||||
|
||||
**Test vector** (the zero-entropy mnemonic of §9, app `fiscus`):
|
||||
- mailbox seed: `IygCOrh-ibO6-KY5AXQ9Prl2SyPWQIyZZ-anffcbMCU`
|
||||
- `seal(nonce = 24 zero bytes, aad = "", plain = "")`: `AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAci_JRbtsx5prR83KT9Y7LA`
|
||||
|
||||
### Custos' part (`custos-local`, three more pipe operations)
|
||||
|
||||
The person starts a revocation **in Custos** (Domi identity → a key → Revoke). Custos cannot call an app, so
|
||||
each app asks, on every sync, whether there is anything to do:
|
||||
|
||||
```
|
||||
→ {"op":"revocations","app":"Fiscus Domi","app_id":"fiscus"}
|
||||
← {"ok":true,"revocations":[{"subkey":"<base64url>","revoked_at":1793000000,"statements":["<base64url TRV1>",…]|null}]}
|
||||
|
||||
→ {"op":"revoke","app":"Fiscus Domi","app_id":"fiscus","subkey":"<base64url>","revoked_at":1793000000,
|
||||
"accepted":"<base64url: the kept events' SHA-256, 32 bytes each, concatenated>"}
|
||||
← {"ok":true,"statements":["<base64url TRV1>",…]}
|
||||
|
||||
→ {"op":"backup_key","app":"Fiscus Domi","app_id":"fiscus"}
|
||||
← {"ok":true,"secret":"<base64url, 32 bytes>"}
|
||||
```
|
||||
|
||||
- **All three need the app's namespace grant** (`domi://<app_id>/…`, the one its subkey seed lives in), so an
|
||||
app reaches only its own revocations and its own backup secret.
|
||||
- **`revocations`** lists the revocations the person started for this app's subkeys and for device keys.
|
||||
`statements` is `null` until a device of this app sent its list.
|
||||
- **`revoke`** signs only a revocation the person started, at the `revoked_at` Custos chose (otherwise
|
||||
`not_found`), and only once: a second call gets the statements already signed. The app sends the hashes of
|
||||
every event by that subkey in all its groups (`Client::events_by_all`).
|
||||
- **An app that does not answer:** Custos shows the revocation as waiting. A second, explicit click signs it
|
||||
with an empty list, which throws away every event that key wrote (docs/V1_1.md decision 2). A device key
|
||||
(`app_id` `device`) is signed at once with an empty list: in v1.1a no app log holds events by one.
|
||||
- With the statements in hand the app calls `Client::apply_revocation`: in every group the key was in, it
|
||||
announces them, removes the key's leaves and takes their mailbox keys off the relay. It skips a group that
|
||||
already has them, so calling it on every sync is safe.
|
||||
- **`backup_key`** gives the app its backup secret (above). The app keeps it as `BackupSecret` and calls
|
||||
`Client::backup` after each sync and `Client::restore` on a new device.
|
||||
- **Limits:** one pipe message is at most 1 MiB, so one `revoke` carries up to 24,000 kept events.
|
||||
|
||||
Custos' vault signs `TRV1` only for a key the person marked revoked, at that time (CustosPublic
|
||||
docs/IDENTITY.md), so an app with the namespace grant can choose which events stay, not which key is
|
||||
revoked.
|
||||
+206
@@ -0,0 +1,206 @@
|
||||
# Fundamentum v1.1 — revocation, recovery, the browser, live sync (design note, proposals)
|
||||
|
||||
Written before any v1.1 code, so the open decisions can be made first. **(proposal)** marks my judgment;
|
||||
each has an alternative and its cost. Nothing here changes v1's formats; every new structure is a new
|
||||
magic with its own signing domain.
|
||||
|
||||
**The gate (roadmap):** lose a phone, revoke it, and recover everything from the 24 words, with no data loss.
|
||||
|
||||
v1.1 is too big for one session. Proposed split:
|
||||
|
||||
| Day | Contents |
|
||||
|:--|:--|
|
||||
| **v1.1a** | revocation (§1), renewal (§2), the root-sealed backup and recovery (§3), Custos UI for all three |
|
||||
| **v1.1b** | a sans-IO client and its WASM build (§4), live subscribe on the relay (§5), the JS package for PWAs (§6) |
|
||||
|
||||
v1.1a alone passes the gate for the desktop apps. v1.1b is what the phone apps need.
|
||||
|
||||
---
|
||||
|
||||
## 1. Revocation
|
||||
|
||||
### What a lost phone holds
|
||||
- One device subkey per Domi app it ran (`TSC1` certs for that app) and, in the browser, the device key from
|
||||
day-1 pairing.
|
||||
- For each group it was in: an MLS leaf, its signature key, the group state and a mailbox key.
|
||||
|
||||
Revoking it has to do three separate things:
|
||||
1. **Readers stop trusting its signatures.** Nothing it signs from now on is accepted.
|
||||
2. **It stops reading.** It leaves every MLS group, so it cannot decrypt future epochs.
|
||||
3. **The relay stops serving it.** Its mailbox keys are deregistered.
|
||||
|
||||
### The revocation statement (`TRV1`)
|
||||
```
|
||||
"TRV1" 4
|
||||
root 32 the root that certified the subkey
|
||||
subkey 32 the revoked subkey
|
||||
revoked_at 8 u64 Unix seconds, when the person revoked it
|
||||
accepted u32 count ‖ count × 32 SHA-256 of every event by this subkey that stays valid, sorted
|
||||
sig 64 Ed25519(root, "tessera revoke v1\0" ‖ every byte above)
|
||||
```
|
||||
- Custos signs it. Its vault refuses a `tbs` that does not start with `TRV1` and name its own root, exactly
|
||||
as it does for `TSC1`, so the root still signs only things that parse as one of its two statements.
|
||||
- It travels as an ordinary event (`kind = "tessera.revoke"`) in each group the subkey was in. Any device of
|
||||
the same person sends it.
|
||||
|
||||
### Why a list of accepted events, not a time (proposal)
|
||||
v1 checks a cert at the event's own time, so a thief who has the subkey can **backdate** an event to
|
||||
before `revoked_at`, and a time cutoff would accept it. Instead, the revocation names exactly which of that
|
||||
subkey's events stay valid: those already in the revoking device's log. Every other event by that subkey,
|
||||
whenever it claims to be from, is rejected.
|
||||
|
||||
- This is deterministic: every device applies the same list once the logs converge.
|
||||
- **The cost:** events the lost phone wrote but never synced are lost too. They exist only on the phone.
|
||||
- Size: 32 bytes per kept event (1,000 events from one phone in one group = 32 KB, once).
|
||||
- *Alternative:* a time cutoff (`revoked_at` only). Simpler and smaller, but it leaves the backdating hole open.
|
||||
|
||||
### Applying it (`tessera::merge`)
|
||||
The verifier gets the group's revocations as a second input. Merging becomes two passes:
|
||||
1. Collect every valid `TRV1` in the log: root-signed, by a root of the group, for a subkey that root certified.
|
||||
2. Drop each event whose author is revoked and whose hash is not in that revocation's list. It goes to
|
||||
`rejected` with the reason "revoked".
|
||||
|
||||
Revoking twice is idempotent: the lists are intersected, never widened.
|
||||
|
||||
### MLS and the relay
|
||||
- **The revoking device:**
|
||||
- commits a `Remove` of every leaf whose credential names a revoked subkey;
|
||||
- deregisters the mailbox key in that credential (v0.2.0's `remove` does both);
|
||||
- then sends the `TRV1` event.
|
||||
- A member device that sees a valid `TRV1` before the `Remove` lands may commit the `Remove` itself, so a
|
||||
revocation finishes even if the revoking device goes offline.
|
||||
- **Shared groups:** another person's device in the group accepts a `Remove` of your leaf only with your
|
||||
`TRV1` beside it (a member removing someone else needs a reason the others can verify). *(proposal)*
|
||||
|
||||
### In Custos
|
||||
- **Domi identity → Devices → Revoke.** Custos groups certs by the label it recorded when it issued them
|
||||
("Phone browser", "Fiscus on Mark's PC"), so one revoke covers every key of that device.
|
||||
- The `accepted` list comes from the app's own log: Custos asks each app on this PC (pipe op `revoke`) for
|
||||
that subkey's event hashes. An app that is not running cannot answer.
|
||||
- **(Decision)** Revoke then: (a) waits until each app has answered, or (b) lets the person revoke with an
|
||||
empty list for apps that did not answer. That throws away everything that phone wrote in those apps. I
|
||||
propose (a), with (b) behind a second, explicit click.
|
||||
|
||||
## 2. Renewal
|
||||
- Certs live 365 days. An app asks Custos for a fresh cert for the same subkey when 30 days are left (same
|
||||
`subkey` op, one click, the same match code).
|
||||
- An expired cert keeps its old events valid (they are checked at their own time); the subkey just signs
|
||||
nothing new until renewed.
|
||||
- No new format.
|
||||
|
||||
## 3. Recovery from the 24 words
|
||||
|
||||
`RootKey::from_mnemonic` already gives back the same root, so every group still trusts it. What is lost
|
||||
with every device is the **data** and the **MLS state**.
|
||||
|
||||
- **Shared groups:** the other members still hold the group. They re-invite your new device; the credential
|
||||
check passes because the root matches. Their copy of the log comes with the history (v0.2.0 §6).
|
||||
- **Your self group** (your own devices only): if every device is gone, nobody holds it. Hence:
|
||||
|
||||
### The root-sealed backup (proposal)
|
||||
- Custos derives, per app, a backup key and a backup mailbox from the **root secret**, never stored:
|
||||
- `backup_key = HKDF(root secret, "tessera backup v1", app_id)`
|
||||
- `mailbox access key = HKDF(root secret, "tessera backup mailbox v1", app_id)`
|
||||
- The mailbox id is the hash of that key's public half.
|
||||
- Both come back from the 24 words alone. Custos hands an app its own pair only (pipe op `backup_key`).
|
||||
- Each desktop app, after a sync, uploads its self group's verified log: `TBK1 ‖ XChaCha20-Poly1305(backup_key,
|
||||
envelopes)`. The relay keeps the latest few; they are ciphertext like everything else.
|
||||
- **Recovery:**
|
||||
1. Custos: "Restore from 24 words".
|
||||
2. Each app asks for its backup pair, downloads the latest blob, verifies every envelope, opens a new self
|
||||
group and sends the history into it.
|
||||
3. Your other people re-invite you into shared groups.
|
||||
- **Cost:** the relay can tell that one backup mailbox gets written now and then. It cannot tell whose it is
|
||||
or what is in it, and it cannot link it to any group mailbox.
|
||||
- *Alternative:* no backup. Recovery then works only if one device survives (an always-on node such as
|
||||
fiscus-node counts). Simpler, but it fails the gate for anyone with one PC and one phone who loses both.
|
||||
|
||||
## 4. The client in the browser (WASM)
|
||||
|
||||
**The probe (2026-11-04)** answers the open point from the plan ("whether OpenMLS runs well in WASM"):
|
||||
**it builds.** `tessera`, `envelope`, `tabellarius-proto` and OpenMLS 0.9 all compile for
|
||||
`wasm32-unknown-unknown` once the browser's clock and randomness are switched on. The client itself stops
|
||||
only at its HTTP transport. Details under "Probe" at the end. The client needs two changes:
|
||||
- **Transport:** the client is blocking (`ureq`). Proposal: split it into a **sans-IO core** (a state machine
|
||||
that says which request to make and consumes the answer) and two thin drivers: `ureq` (native, unchanged
|
||||
API) and `fetch` (browser, async). The tests drive the core directly.
|
||||
- **Signing:** in the browser the device subkey is a non-extractable WebCrypto key. Tessera gets a `Signer`
|
||||
trait (`public`, `sign_event_tbs`, `sign_credential_tbs`), async in the browser. `Subkey` implements it on
|
||||
native.
|
||||
- **MLS keys:** OpenMLS makes its own signature key per group; in the browser it lives in the client state.
|
||||
That state is encrypted with a non-extractable WebCrypto AES-GCM key and kept in IndexedDB (the same rule as
|
||||
the desktop's Custos-held state key).
|
||||
|
||||
## 5. Live subscribe
|
||||
|
||||
- **`GET /v1/live`**, a WebSocket.
|
||||
- The first message is a list of `(mailbox, after)`, each signed as a v0.2.0 request: a browser cannot set
|
||||
headers on a WebSocket.
|
||||
- The relay then sends `{"mailbox", "seq"}` whenever a message arrives, never the message. The client
|
||||
fetches as today.
|
||||
- **Limits:** 32 mailboxes per connection, 4 connections per mailbox key, idle timeout 10 minutes.
|
||||
- **Privacy:** no worse than polling. One connection for several mailboxes links them by connection, as
|
||||
fetching them from one IP already does. Apps that care open one connection per group.
|
||||
- Caddy proxies it; the access log stays off.
|
||||
|
||||
## 6. The JS package (`@domi/fundamentum`)
|
||||
|
||||
- `wasm-bindgen` over the sans-IO core and the fetch driver, in the Fundamentum repo, served by each PWA
|
||||
itself (Domi: nothing fetched from a CDN).
|
||||
- The API mirrors the Rust one (`open`, `selfGroup`, `openGroup`, `invite`, `join`, `send`, `sync`, `log`,
|
||||
`remove`, `revoke`) plus `subscribe(onChange)`.
|
||||
|
||||
## Decisions wanted before v1.1a starts
|
||||
|
||||
| # | Question | Proposal |
|
||||
|:--|:--|:--|
|
||||
| 1 | Revocation keeps a list of accepted events (closes backdating) or uses a time cutoff | the list |
|
||||
| 2 | Revoke while an app did not answer | wait; an explicit second click to drop its events |
|
||||
| 3 | Another person's device may `Remove` your leaf only with your `TRV1` | yes, refined in v1.1a (below) |
|
||||
| 4 | Root-sealed backup on the relay, so recovery works with every device lost | yes |
|
||||
| 5 | Split v1.1 into v1.1a (revocation, renewal, recovery) and v1.1b (WASM, live, JS) | yes |
|
||||
| 6 | The v1 gate (live relay, two real devices) before v1.1 starts, or in parallel | in parallel: v1.1a needs no server |
|
||||
|
||||
## Status
|
||||
|
||||
**v1.1a in the crates (Fundamentum v0.3.0):** `TRV1` and `RevocationSet`, `RevokeSigner`, `BackupSecret`
|
||||
(tessera); `revoke`, `announce_revocation`, `events_by`, `renew`, `backup`, `restore`, `import` and the
|
||||
removal rule (client). The gate's scenario passes against the in-process relay: a phone is revoked, its
|
||||
later and backdated events are dropped on every device, and with every device lost the self group comes back
|
||||
from the backup.
|
||||
|
||||
**Decision 3, refined while building it.** As written, it would also have stopped anyone removing a
|
||||
*person* from a shared group, which v0.2 deliberately allows. The intent was to stop one person cutting off
|
||||
another's device while that person stays. So:
|
||||
- removing **some** of another person's devices needs their revocation for each one;
|
||||
- removing **all** of them removes the person, as before.
|
||||
|
||||
**Custos' half (Fundamentum v0.3.1, CustosPublic v0.10.0, Custos 0.5.0):** the pipe ops `revocations`,
|
||||
`revoke` and `backup_key` (docs/TESSERA.md §12); Domi identity → a key → **Revoke**, **Revoke without
|
||||
waiting** (decision 2's second click) and **Restore from 24 words**. The vault signs `TRV1` only for a key
|
||||
the person revoked, at the time they did. CustosPublic and Custos check the backup secret against the
|
||||
test vector of §12.
|
||||
|
||||
**One change to §1 "In Custos":** Custos cannot call an app over the pipe, so the person starts the
|
||||
revocation in Custos and each app asks on its next sync (`revocations`), then sends its list (`revoke`).
|
||||
Device keys are signed at once with an empty list: no app log holds their events in v1.1a.
|
||||
|
||||
**Still to do for v1.1a:** each app, on every sync, calls `revocations_to_apply` → `apply_revocation`, then
|
||||
`backup`; and offers `restore` on a new device. Then the gate by hand on two real devices.
|
||||
|
||||
## Probe
|
||||
|
||||
`cargo build --target wasm32-unknown-unknown`, rustc 1.94.1 from the server's nixpkgs-unstable pin
|
||||
(`0726a0ec`), in WSL, on Fundamentum `95b7579` (v0.2.1). Not run in a browser yet: this shows the code
|
||||
compiles, not that it works there.
|
||||
|
||||
| Crate | Result | Needs |
|
||||
|:--|:--|:--|
|
||||
| `tessera` | builds | nothing |
|
||||
| `envelope` | builds | nothing |
|
||||
| `tabellarius-proto` | builds | the browser random source (`getrandom` 0.2 `js`, 0.3 and 0.4 `wasm_js` + `--cfg getrandom_backend="wasm_js"`) |
|
||||
| OpenMLS 0.9 + `openmls_rust_crypto`, `_basic_credential`, `_memory_storage` | builds | the same, plus OpenMLS's own `js` feature (time and randomness from JavaScript) |
|
||||
| `tabellarius-client` | fails at `ring` (C code, via `ureq` → `rustls`) | the sans-IO split (§4): the browser build has no `ureq`, it talks through `fetch` |
|
||||
|
||||
The browser build therefore needs no change to the crypto, the formats or OpenMLS: only the transport and
|
||||
a `Signer` for the WebCrypto device key.
|
||||
+176
@@ -0,0 +1,176 @@
|
||||
# Fundamentum v1.1b — the client in the browser, live subscribe, the JS package (design note)
|
||||
|
||||
Written before the v1.1b code. It turns `docs/V1_1.md` §4–§6 (accepted with decision 5 on 2026-11-04) into
|
||||
what gets built. **(choice)** marks where this note settles something §4–§6 left open; each says what
|
||||
it costs. Nothing here changes a v1 or v1.1a format.
|
||||
|
||||
**The goal:** a PWA on a phone is a Domi device. It joins the self group, sends and reads verified events,
|
||||
and hears about new mail without polling. Its device key and its state never leave the browser unencrypted.
|
||||
|
||||
Two releases:
|
||||
|
||||
| Release | Contents |
|
||||
|:--|:--|
|
||||
| **v0.4.0** | the client split into an async core and a blocking native driver (§1); `DeviceSigner` (§2); live subscribe on the relay (§3); CORS (§4) |
|
||||
| **v0.5.0** | `crates/wasm` (fetch transport, WebCrypto signer) and the JS package `@domi/fundamentum` (§5), tested in a browser against a local relay |
|
||||
|
||||
## 1. One core, two drivers
|
||||
|
||||
§4 proposed a sans-IO state machine. **(choice)** The core is `async` code generic over a transport and a
|
||||
signer, and Rust's `async` produces the state machine. A hand-written state machine for `sync` (several
|
||||
mailboxes, `more` pages, invites, joins, acks) would duplicate every control path the client already has, and
|
||||
every bug fix would have to be made twice.
|
||||
|
||||
```rust
|
||||
pub trait Transport {
|
||||
/// `Err` only when the relay could not be reached (offline); any HTTP status is an `Ok` response.
|
||||
fn send(&self, req: HttpRequest) -> impl Future<Output = Result<HttpResponse, String>>;
|
||||
}
|
||||
pub struct Core<T: Transport, S: DeviceSigner> { … } // every operation that talks to the relay or signs is `async`
|
||||
pub struct Client(Core<Ureq, Subkey>); // native: the v0.3 API, unchanged, blocking
|
||||
```
|
||||
|
||||
- **Native** (`Client`): the API every app uses today keeps its exact signatures. Its transport (`ureq`)
|
||||
and signer (`Subkey`) never wait, so each call polls the core's future exactly once. There is no executor
|
||||
and no thread. The core never waits on anything else (no timers, no channels).
|
||||
- **Browser** (`crates/wasm`): the same core over `fetch` and a WebCrypto signer, driven by the browser's
|
||||
event loop through `wasm-bindgen-futures`.
|
||||
- The tests stay as they are. They drive `Client`, so they test the core.
|
||||
- `ureq` is a dependency only off `wasm32`. `EncryptedFileStore` is native only. The clock is a parameter
|
||||
of `Core::open` (`std::time` panics in the browser).
|
||||
- **Cost:** `Core` is generic, so a native app compiles one instance and the browser another. That is fine.
|
||||
|
||||
## 2. The device key in the browser
|
||||
|
||||
```rust
|
||||
pub trait DeviceSigner {
|
||||
fn public(&self) -> PublicKey;
|
||||
fn sign_event_tbs(&self, tbs: &[u8]) -> impl Future<Output = Result<Signature, String>>; // EVENT_DOMAIN ‖ tbs
|
||||
fn sign_credential_tbs(&self, tbs: &[u8]) -> impl Future<Output = Result<Signature, String>>; // CREDENTIAL_DOMAIN ‖ tbs
|
||||
}
|
||||
```
|
||||
- `tessera::Subkey` implements it (native).
|
||||
- In the browser the private key is a **non-extractable** WebCrypto Ed25519 key, the one day-1 pairing
|
||||
certified. Rust prepends the domain, and JavaScript calls `crypto.subtle.sign("Ed25519", key, message)`.
|
||||
JavaScript never chooses the domain, so it cannot be tricked into signing one statement as another.
|
||||
- `envelope` gains a two-step seal for a signer that cannot be called synchronously:
|
||||
- `Envelope::to_be_signed(author, cert, schema, hlc, payload)` gives the bytes to sign.
|
||||
- `Envelope::with_signature(tbs, sig)` finishes the envelope. It checks the signature against the author
|
||||
before returning, so a broken signer cannot produce an envelope that others would drop.
|
||||
- `seal` is unchanged.
|
||||
- No hand-written crypto: Ed25519 is WebCrypto's in the browser and `ed25519-dalek` everywhere it is checked.
|
||||
|
||||
## 3. Live subscribe
|
||||
|
||||
As in V1_1 §5, with the details settled:
|
||||
|
||||
- **`GET /v1/live`** upgrades to a WebSocket.
|
||||
- **Subscribing.** The client's first message (text, JSON) lists up to 32 subscriptions:
|
||||
```json
|
||||
{"subscribe": [{"mailbox": "<id>", "after": 17, "key": "…", "time": "…", "nonce": "…", "sig": "…"}]}
|
||||
```
|
||||
- Each one is signed like a request, with method `LIVE`, path `/v1/mailboxes/{id}/live?after={after}` and
|
||||
an empty body. The relay checks it like any request: time, signature, registration in that mailbox,
|
||||
replay, rate. A subscription that fails is answered `{"mailbox", "error"}`, and the others still count.
|
||||
- A WebSocket from a browser cannot carry the `Tab-*` headers, which is why the signatures travel in the
|
||||
message.
|
||||
- **Notices.** The relay sends `{"mailbox", "seq"}` when that mailbox holds a message with a higher seq than
|
||||
`after`. It sends one at once if there already is one, and then one per append. It never sends the
|
||||
message itself; the client fetches as it does today. Notices only say "something is new": a client that
|
||||
misses one loses nothing, because its next fetch starts from its cursor.
|
||||
- **Removed keys.** A key deregistered while subscribed gets `{"mailbox", "error": "unregistered_key"}`, and
|
||||
that subscription ends. The relay checks the registration again before every notice.
|
||||
- **Keeping it open.** The client sends `{"ping": true}` at least every 5 minutes, and the relay answers
|
||||
`{"pong": true}`. After **10 minutes** with nothing from the client, the relay closes the socket.
|
||||
- **Limits:** 32 subscriptions per connection; **4 open subscriptions per mailbox key** (the 5th is refused
|
||||
`too_many`). Rate counting is the same per key as for requests.
|
||||
- **In memory only.** Nothing about a socket is stored or logged. One process-wide broadcast of
|
||||
`(mailbox, seq)` feeds every socket. A socket that falls behind it is told to re-fetch everything it
|
||||
watches (`{"mailbox", "seq": null}` for each).
|
||||
- **The core is sans-IO here.** `Core::live_subscribe()` returns the signed first message for every active
|
||||
group, and `Core::live_notice(text)` names the group that has mail. The drivers own the socket. The
|
||||
browser package uses it; the native `Client` gets no socket yet (desktop apps keep polling).
|
||||
- **Privacy:** no worse than polling, as V1_1 §5 says. A socket that watches several mailboxes links them,
|
||||
as fetching them from one address already does. The JS package therefore opens one socket per group by
|
||||
default.
|
||||
|
||||
## 4. CORS
|
||||
|
||||
A PWA at `fiscus.…` calling `tabellarius.…` needs CORS. **(choice)** The relay answers every request with
|
||||
`Access-Control-Allow-Origin: *`, and a preflight (`OPTIONS`) with the methods, the `content-type` and
|
||||
`tab-*` headers, and `max-age` one day.
|
||||
- `*` is safe here because nothing is authorised by a cookie or by the origin. Every request is authorised
|
||||
only by its signature, and browsers never send cookies to a `*` origin.
|
||||
- **Caddy strips `Origin`, `Referer` and `User-Agent` before the relay sees them.** The relay never learns
|
||||
which app a request came from. (The browser still sends `Origin`, so the TLS endpoint sees it, as it sees
|
||||
the address. Caddy's access log stays off.)
|
||||
- The CORS handling is ~20 lines in the relay, tested, not a new dependency.
|
||||
- *Alternative:* proxy the relay under each app's own origin (`fiscus.…/tabellarius/`). No CORS, but every
|
||||
app's vhost then knows which app talks to the relay, and the relay would need one configuration per app.
|
||||
|
||||
## 5. The JS package (`@domi/fundamentum`, v0.5.0)
|
||||
|
||||
- `crates/wasm` (`wasm-bindgen`) wraps `Core<Fetch, WebCryptoSigner>`. `packages/fundamentum` holds the
|
||||
generated module and a small hand-written `index.js`. Each PWA serves it itself; nothing comes from a CDN.
|
||||
- **API** (mirrors the Rust one):
|
||||
- `Fundamentum.open({relay, cert, key, state})` takes the cert text, the non-extractable `CryptoKey` and
|
||||
the previously saved state.
|
||||
- Then: `selfGroup`, `openGroup`, `groups`, `invite`, `join`, `send`, `sync`, `log`, `members`, `remove`,
|
||||
`applyRevocation`, `backup`, `restore`, `import`.
|
||||
- `subscribe(onChange)` opens the sockets and runs `sync` when a notice arrives.
|
||||
- **State:** after every call that changes it, the package hands the encrypted state to `onSave(bytes)`.
|
||||
It is encrypted with a non-extractable WebCrypto AES-GCM key (V1_1 §4), and the app keeps it in IndexedDB.
|
||||
- The plaintext exists only inside the page, which already holds the wasm memory that contains it. This
|
||||
is the same trust boundary as the desktop app's process.
|
||||
- **Calls are serialised:** the package queues them, so two `sync`s never run at once. If one still
|
||||
overlaps, the core answers `busy` instead of panicking.
|
||||
- **The browser build:** `wasm32-unknown-unknown`, with the browser's randomness (`getrandom` `wasm_js`)
|
||||
and OpenMLS's `js` feature, built in WSL with nix (rustup targets are not installed on the dev machine). It
|
||||
is checked by a test page against a local relay: a native CLI device and a browser device join one group,
|
||||
exchange events both ways, and the browser hears the live notice.
|
||||
|
||||
## Status
|
||||
|
||||
**v0.4.0:**
|
||||
- `Core<T, S>` with `Transport` and `DeviceSigner`. `Client` is the native driver, and its API is
|
||||
unchanged.
|
||||
- The two-step seal: `Envelope::to_be_signed` and `with_signature`.
|
||||
- `/v1/live`, with `Core::live_subscribe` and `live_notice`.
|
||||
- CORS, and Caddy stripping `Origin`, `Referer` and `User-Agent`.
|
||||
|
||||
Tested against the in-process relay:
|
||||
- A core whose transport and signer really wait pairs and syncs with a native device.
|
||||
- A device hears that its group has mail, and later that it was removed.
|
||||
- The relay's checks and limits on subscriptions hold.
|
||||
- The preflight works.
|
||||
|
||||
Not built for `wasm32` yet; that comes with `crates/wasm` in v0.5.0.
|
||||
|
||||
**v0.5.0:** `crates/wasm` and `packages/fundamentum` (`index.js`; `pkg/` is built by `build.sh` in
|
||||
`nix develop .#wasm` and is not in git). The wasm module is 3.1 MB.
|
||||
|
||||
The browser check (packages/fundamentum/README.md) passed on 2026-11-04 in the desktop app's Chromium,
|
||||
against a local relay, cross-origin:
|
||||
- A native CLI device and a browser device joined one self group. The browser's credential and events were
|
||||
signed by its non-extractable WebCrypto key; `exportKey` refused with `InvalidAccessError`.
|
||||
- Events went both ways, and the browser heard the CLI's event live and synced it.
|
||||
- The sealed state reopened to the same log. It does not show the group id, and a wrong AES key does not
|
||||
open it.
|
||||
|
||||
**Seen while testing it:** a browser sends a CORS preflight (`OPTIONS`) before each relay request, because
|
||||
the URL changes (`?after=N`) and preflights are cached per URL. That doubles the round trips. The answers
|
||||
are small and unsigned, and do not count against the rate limit.
|
||||
- *Possible later:* put `after` into a signed header so the URL stays the same. That would be a protocol
|
||||
change.
|
||||
|
||||
**Not checked:**
|
||||
- A real phone.
|
||||
- WebKit/Firefox. Ed25519 in WebCrypto is recent there.
|
||||
- The live server (it needs the `nixos-rebuild` for v0.4.0's relay).
|
||||
|
||||
## Not in v1.1b
|
||||
- Pairing a phone end to end (the PWA asking the factor service for its cert, as day 1 did for the Custos web
|
||||
vault). This needs the live server.
|
||||
- A native WebSocket driver for desktop apps.
|
||||
- Service-worker push while the PWA is closed: no third-party push service (Domi rule), so a closed PWA
|
||||
syncs when it is opened.
|
||||
Reference in New Issue
Block a user