16 Encrypted sync (draft, not built)
State: a proposal for review. Nothing here is implemented. Values marked † are proposals.
An application with end-to-end encryption (12) keeps each user’s data on the server as ciphertext and works on a local copy in each client, for example a SQLite database that the client queries directly. The library stores and orders the ciphertext and checks who may write. It never reads the data, and it does not merge it: merging belongs to the client.
Keys
- The identity secret of 12 is the account key. Each passkey and the recovery key unlock it.
- The keyring holds the content keys, one for each period, sealed with a key derived from the identity secret. A client adds a period to rotate: data written later uses the new key. Old periods stay, so old data still opens.
- A new unlock method needs only the identity secret, not the other methods’ secrets.
Keyring
| Field | Content |
|---|---|
user | Owner |
version | 1, and one more with each change |
period | The current period |
ciphertext | The sealed keyring, at most 64 KiB† |
created | Time |
- A change names the version it replaces (compare-and-swap). A stale version is refused.
periodgrows by exactly one, or stays. A larger jump is refused.- The server keeps every version for 30 days† and returns them on request, so a broken update cannot destroy the only copy.
- A change needs a fresh login, as for credentials (04).
Log
Each user has an append-only log of encrypted entries.
| Field | Content |
|---|---|
seq | Assigned by the server: gap-free, one more for each entry of this user |
device | The device that wrote it. It MUST be the device of the session |
counter | The device’s own counter: one more for each entry of that device |
period | The period of the key that sealed it |
previous | The hash of the entry before it, as the writing client saw it |
ciphertext | At most 1 MiB† |
signature | By the writing device’s key, over all fields above except seq |
- An entry with an old period after the keyring moved on is refused.
- A retry with the same
deviceandcounterand the same bytes returns the firstseq. The same pair with other bytes is refused. - A read gives entries after a
seq, in pages of at most 1000†, and the current head (seqand hash). - The application gets a hook when the head moves, for example to tell open clients.
Snapshots
- A snapshot is the sealed state up to a
seq(covers). A client writes one when its log is long, for example every 300 entries†. - The server keeps the 2† newest snapshots, and may delete entries up to the older one’s
covers. A client that asks for deleted entries gets410 compacted, and starts from the newest snapshot. - Snapshot bodies can be in an object store. The table keeps the place, the size and the hash.
What a client checks
- Every entry’s signature, by a device that the client knows as the user’s.
- The chain: each
previousis the hash of the entry before it. A gap or a fork means the server withheld or changed entries: the client stops writing and tells the person. - The counter of each device: a gap or a repeat is a warning.
- The newest head it has seen is kept in the keyring, so the next device can check that the server did not roll back.
Revoking
- Revoking a device or removing a passkey and the keyring update with a new period are one server transaction. The request carries the new keyring. Without it, the revocation is refused.
- The identity secret does not change on a revocation. A device that kept a copy can still open later keyrings that it obtains. A person who fears that replaces the identity key (12), which seals everything again.
The local copy
- The local copy holds plaintext. A client SHOULD encrypt it at rest with a key that the page cannot export, and lock it when idle.
- A browser cannot protect it from a script on the same origin (THREATS.md).
What the server sees
Per entry: user, seq, device, counter, period, size and time. Per snapshot: size and time. The keyring’s version and
period. Activity times. Not the content, and not the shape of the data inside the ciphertext.
Quotas
Each user has a limit for log bytes, snapshot bytes and entries per minute†. A write over the limit is refused with
413 or 429.
Open questions
- Is the signed chain worth its cost for every application, or an option?
- Should the library also hold the blobs of large files (images), each with its own key, or leave them to an object store that the application signs URLs for?
- Should the hook for a moving head be a server-sent event stream in the library, or only a callback?
- Is 30 days of keyring versions right, and who may read old versions: every device, or only after a fresh login?