Phase 11: end-to-end encryption, and 1.0.0
Status: approved, with every recommendation in §16, and with agents reaching encrypted workspaces over MCP through an agent device as part of 1.0 (§6.4). Being built in the order of §13.
Changed from the plan, so far
Kept up to date as each step of §13 lands.
- Keys and certificates travel inside sync (step 3). A workspace’s container keys (wrapped to
the member) and the certificates of the devices that sealed a batch of entries come with
Updates, the first time a connection needs them. There are no extra REST calls, so the browser’s worker and the native driver only pass frames, as before. - A device that doesn’t know a workspace is encrypted is told so (step 3). The server answers
its subscription with a new error code,
Encrypted, and the device subscribes again sealed. The workspace list (GET /api/v1/workspaces) also saysencrypted, and the native app notes it ahead of time. - A snapshot declares no peers (step 3). A snapshot carries everyone’s changes, which their own updates already registered. So the server records no peers for it, and devices check peers only on updates. Snapshots are trusted as written by a member who may edit, as §4.4’s checks already assume. A member with the key could slip forged changes into one. That’s listed for the independent review (decision 6).
- Device snapshots are stored by the server as the system (step 3). Only the server’s own
compactor ever wrote
document_snapshotsand changeddocument_updates. Once a sealed snapshot passes every check, the push’s own transaction finishes as the system. A new row-level policy lets only the system mark updates replaced. - Key work travels in sync (step 4). The server can’t make a wrap or a key. When a device
that may share connects, it gets
KeyWork: people waiting for a container’s key, or a key due to rotate. It answers withShareKeysorRotate, which the server checks: wraps only to people with access, and a new epoch wrapped to exactly them. The first device online does it, so a newcomer waits for one of them. - Removing a member rotates every key of the workspace (step 4), its own and each tree’s, rather than working out which trees they had. Taking someone off one page rotates only that page’s tree.
- A moved page’s old log is deleted, not kept 14 days (step 4), unlike a compacted one. It was sealed under the key of where the page was, which people who just lost access hold.
- Opening an entry uses the container its header names (step 4), when this device has that key. A page another device just moved arrives under its new tree’s key before this device has caught up with the move.
- The memory budgets are 50 MB higher, for now (asked for during step 4): idle RAM 300 MiB (500 on Linux CI) and the browser tab 98 MB. Linux CI was already measuring 444–452 MiB against 450 on main. §12’s “Idle RAM unchanged” still holds for what this phase adds.
- A published page’s link token is kept readable (step 5) in encrypted workspaces. Standard workspaces seal it with the workspace key, which the server no longer has here; the token is the address of a page the server shows anyone who has it anyway.
- The device, not the server, writes a published page’s share state into an encrypted workspace’s document (step 5), right after the server answers a publish, unpublish or new link.
- Unpublishing deletes the copy’s readable files from storage too (step 5), unless another published page shows the same file.
- The web app’s JS budget is 1 KB higher (step 5): 186 KB brotli. The main chunk was already within 200 bytes of 185 KB before publishing copies were added.
- Your own document is a tree only you are in (step 5, §6.3). The server stores it as kind
accountwithtree_idits own ID, so the policies that keep a tree to the people it’s shared with keep it to you, and its key is wrapped to you alone. Its first key comes from the account’s container seed, so every one of your devices makes the same one. A device makes the document with its first chat. If two did before hearing of each other, the server’s copy wins and the other’s chats go into it. - Phones don’t make vectors yet (step 5, §6.1). Desktops make them in the background. A phone searches by meaning with the vectors it has, which is none until it can tell it’s charging.
- Meeting notes with the opt-in keep their progress in the job (step 5, §6). The server can’t write the Status column, so devices copy it in. Such a job keeps no parts to resume from: a restart begins again.
- Analytics has a per-workspace switch (step 5, §6). “As today” was the server’s switch alone. Owners now have one too, beside the opt-in in Workspace settings → AI: off by default in an encrypted workspace, on in a standard one.
- The browser asks, makes vectors and makes meeting notes only with the opt-in (step 5). It has no models of its own.
- An agent device keeps one store per workspace (step 6, §6.4), each holding its identity, since a store holds one open workspace at a time. One MCP endpoint serves them all.
- The agent device’s binary is
drusite, withagent enrollandagent run(step 6). For a container’s first start,runenrolls first when it’s given a server and a code. - An agent device checks tokens with
POST /api/v1/agent-devices/introspect(step 6), signed in as itself, rather than RFC 7662’s form endpoint. The server narrows the grant there to the workspaces the agent device holds and its own access. - The keys of trees an agent device may hold come through its person’s key work (step 6): approving it wraps only the workspaces’ own keys. After a rotation, its person’s devices wrap the new key to it, as they do for a new member.
- Agent devices can’t publish (step 6): publishing makes a readable copy, which only the person’s own devices make.
- A workspace being converted is
encrypted, withconvertingsaying which way (step 7, §8), rather than aconvertingstate of its own: everything that treats a workspace as encrypted does so from the start, and each document’s own state says whether it’s sealed yet. A device subscribed the wrong way is told so (Encrypted, or the newStandard). - Old copies of files go when the conversion ends (step 7), not 14 days later: each page’s files are converted before its snapshot is, so nothing points at them by then.
- Agents move to the agent device only when their grant reaches just this workspace (step 7).
A grant that reaches others too stays on the server’s
/mcp, which now names the agent device for this one. - Conversion runs in the apps (step 7). The browser shows where it’s up to, but a device that holds the keys and has the pages does the work.
- Ask chats stay on the server until each person’s device moves them (step 7), into their own sealed document, when it first sees the conversion.
- Account deletion is new (§14, item 8): there was none before, for any account. Settings →
Account deletes the account, its sign-ins, keys, agent devices and the workspaces only it was
in, at once; the workspaces it leaves rotate. It’s refused while the account is the last owner
of a workspace others are in.
created_byon workspaces and documents may now be empty. - The web app’s budgets are 1 KB (JS, 187 KB) and 2 KB (encryption screens, 14 KB) higher (§14): exporting, Members listing agent devices, deleting an account and starting over with new keys came to 718 and 1,086 bytes over.
- The clean export is in Notion’s layout (§14, item 7), as a zip made on the device: Markdown pages, CSV databases, files beside them. Drusite’s Notion import reads it back.
- Starting over after losing everything (§3.5) is “Lost every device and your recovery key?” on the Security screen. The other members accept the changed safety code, rather than a separate “Give access again”.
- The Updates & analytics, Ask and search code on the server see encrypted documents as
missing (
store::loadanswers nothing for them), and the search queue never takes one. Step 5 gave each its device-side version (§6), and the opt-in its routes:ask/prompted,embed, and the sealed meeting job.
The plan in brief
- End-to-end encrypted workspaces. A workspace is either end-to-end encrypted or standard. In an encrypted one, every page, title, database, canvas, journal entry, meeting and attachment is sealed on the device with keys only its members’ devices hold. The server stores and relays ciphertext it cannot read. A standard workspace works exactly as it does today, so the server can still read it for its AI, agents and meeting jobs.
- Keys that survive real life. Each account has its own keys. A new device is approved from one you already have, by comparing a code. A 24-word recovery key works when every device is gone. None of this depends on how you sign in (passkey, OIDC, password or magic link).
- Sync, history and sharing over ciphertext. Loro updates are sealed and signed by the device that wrote them. Devices compact documents instead of the server, so Phase 9’s full history survives. Workspaces, invites, guests, private pages and single-page sharing all keep working. Removing someone rotates the keys.
- Every server feature that reads text gets a decision. Search and Ask move to the device. Meeting transcription runs from the device. Publishing uploads a readable copy only when you publish. A per-workspace opt-in lets your server’s AI read pages when you ask it to.
- Agents reach encrypted workspaces over MCP. An agent device (
drusite agent, a headless Drusite) runs wherever the agent runs, is approved like a new phone, holds keys only for what you give it, and serves the same MCP tools. Agents sign in to it exactly as they sign in to the server’s/mcptoday. The desktop’s local MCP works too. The server still never holds a key. - Converting existing workspaces, one document at a time, resumable, with nothing lost.
- 1.0.0: this phase, plus Phase 10’s release checklist, a frozen protocol and a published security design.
As in every phase, design/DESIGN.md decides how it looks. Everything behaves the same on macOS,
Windows, Linux, iOS, Android and the browser, and where a platform can’t do something the app says
so where you’d look for it. Nothing assumes a particular deployment, identity provider or AI
provider. Examples use made-up names (“Sam”, “Alex”, “Work”).
0. What the code says today
These facts decide most of the plan.
| Fact | Where | What it means here |
|---|---|---|
| The server seals everything with a per-workspace data key (XChaCha20-Poly1305, random 192-bit nonces, AAD binding workspace, key version and object). The key is wrapped by a master key from the key source (env, file or a KMS). | drusite-server/src/crypto.rs, keys.rs, workspace_keys in 0001_core.sql | This is encryption at rest. The server unwraps the key to serve members, so the operator can read everything. The sealing format is reusable on the device. workspace_keys stays for standard workspaces. |
The server parses every update. check_blob decodes Loro’s blob metadata, append_as refuses a log with a hole (Gap), Subscribed.version is the server’s version vector, check_first_snapshot loads the document to check its ID, and compact imports the log into a LoroDoc after 500 updates. | sync/store.rs | None of this can happen over ciphertext. Gap checks, version vectors and compaction move to the devices (§4). |
The peer register (document_peers) binds each Loro peer to a person and device grant, from the peers the server reads out of each update. It refuses a peer that belongs to someone else. | 0011_history.sql, store::record_peers | The device must declare its peers in clear and sign each push, so the binding still holds and members can’t forge each other’s edits (§4.2). |
The server edits documents itself. Moving a page between Workspace and a restricted tree is access::move_to: it loads the workspace document, moves the entry and appends the updates. The OAuth consent page reads root page titles. Members read the workspace’s name from its document. Meeting jobs write transcripts into pages. | access.rs, auth/oauth.rs, members.rs, meetings.rs | In an encrypted workspace, the device makes every one of these edits and the server only stores them (§5, §6). |
Server features read plaintext: the indexer (search_blocks tsvector, search_embeddings pgvector), Ask’s retrieval and prompts, server-side MCP, meeting transcription and summaries, publishing’s renderer, and the Updates feed’s titles. | search/, ask/, mcp.rs, meetings.rs, publish/, analytics.rs | Each gets a line in §6: what moves to the device, what becomes opt-in, what is lost. |
| The device already has full-text search (tantivy, in memory only, never written to disk), and the browser has its own in-memory index. | drusite-core/src/search* | Search by words in an encrypted workspace already works offline. Search by meaning needs a local vector index. |
| Attachments are named by the BLAKE3 hash of their plaintext, and the server checks uploads against it. | attachments.rs (both crates) | A hash of the plaintext lets anyone with a candidate file test whether it’s in a workspace. Encrypted attachments are named by the hash of their ciphertext instead, so the server keeps its integrity check (§7). |
| The device’s store is SQLCipher with one 32-byte key in the OS keychain or keystore. In the browser that key is wrapped by a non-extractable WebCrypto key in IndexedDB and wiped on sign-out. | drusite-core/src/key.rs, docs/phase7.md | Account and device keys live inside the encrypted store, so no new keychain item and no new OS prompt (§3.7). |
Restricted pages (private, shared with some people, shared with guests) live in tree documents that only the people in page_access can sync. | access.rs, 0013_access.sql, docs/phase9.md | Each tree becomes a key container of its own. The server still enforces page_access. Encryption makes that check a second line, not the only one (§5.3). |
The Notion import runs on the device (zip or Notion’s API, straight from drusite-core). | drusite-core/src/database/notion*.rs | Nothing changes. What it makes is sealed like any other page. |
Crypto crates already in the tree: chacha20poly1305, aead, hkdf, sha2, blake3, argon2, ed25519-dalek, curve25519-dalek, getrandom, zeroize. cargo vet and cargo deny gate new ones. | Cargo.lock, supply-chain/, deny.toml | Most of what’s needed is already vetted. §9 adds HPKE and a post-quantum KEM. |
PROTOCOL_VERSION is 1. A change that old clients can’t ignore is a new version and subprotocol. | drusite-proto/src/lib.rs | Encrypted documents need protocol 2. Standard documents keep working on 1, so an old app isn’t cut off from a standard workspace. |
1. Threat model
1.1 Who we defend against
- The server’s operator, and anyone who gets what the server has: the database, its backups, the S3 bucket, the key source, the server’s memory, its logs. For an encrypted workspace, none of that is enough to read your notes.
- Someone who was removed from a workspace or a page. They lose everything written after their removal, even if they still have a copy of the database.
- Another member forging edits. History’s “who changed this” must be true even against a member with the workspace’s key.
- The network, as today: TLS, DPoP-bound tokens.
Out of scope, and the security page says so:
- A compromised device that’s unlocked. It holds the keys and the notes, as any notes app’s device does.
- The host of an agent device you add. It holds keys for what you gave it, by design (§6.4).
- A server that changes the code it serves to the browser. The web app comes from the server. An operator who changes it can steal keys from that browser (§1.4).
- A server that lies about someone’s public key, unless you compare safety codes (§3.6).
- Availability. A server can refuse, delay or withhold updates. Devices notice some of this (§1.4) but can’t prevent it.
1.2 What the operator can and can’t see
| In an encrypted workspace | In a standard workspace (today) | |
|---|---|---|
| Page text, titles, icons, properties, database columns, options, views and values | No | Yes |
| The page tree: which page is inside which, the sidebar’s order, the trash | No (it’s in the workspace document) | Yes |
| The workspace’s name and icon, journal and meeting settings | No | Yes |
| Canvas content, journal entries, meeting audio, transcripts and summaries | No | Yes |
| Attachment contents and file names | No | Yes |
| Version history’s content, named versions’ names | No | Yes |
| Ask questions and answers, search queries | No, unless you opt in to the server’s AI for that workspace (§6) | Yes |
| Who is a member and their role; guests; who has which restricted tree | Yes. The server enforces access, so it must know. | Yes |
| How many documents there are, and which restricted tree each page document belongs to | Yes, as opaque IDs | Yes |
| Each document’s size, to within padding (§4.1), and each attachment’s size, to within padding | Yes | Yes |
| When each person’s device pushes to which document, and from which address | Yes. That’s when you type. | Yes |
| Loro peer IDs (random 64-bit numbers) and which person and device each belongs to | Yes | Yes |
| Page views (Analytics), if the workspace turns Analytics on | Yes, by document ID, never by title. Off by default in encrypted workspaces. | Yes |
| Published pages | Yes. Publishing uploads a readable copy (§6). | Yes |
| What an agent reads | No, through the server. An agent device (§6.4) reads what you gave it, on its own host, which you choose and trust. | Yes, through the server’s /mcp |
So an operator learns a workspace’s shape: who works with whom, how many pages there are, roughly how big they are and when they change. They learn nothing of what the pages say.
1.3 What happens to the server’s own at-rest encryption
It stays for standard workspaces. For encrypted ones, the device’s ciphertext is stored as it is, with no server layer on top: a second layer would protect nothing the first doesn’t, and it would cost a key the server must keep.
1.4 Limits, said plainly
- The browser. The web app runs code the server sends it. Against an operator who’s curious, or a stolen database or backup, the browser is as safe as the apps. Against an operator who ships modified JavaScript, it isn’t. Settings → Security says so the first time you open an encrypted workspace in a browser. The desktop and phone apps are signed builds from GitHub releases, and they don’t run code from the server.
- Withheld updates. A server can hide one device’s edits from another. Loro reports an update whose dependencies never arrive as pending. A document left pending for more than a day shows “Some changes to this page haven’t arrived. Your server may be missing them.” A device also checks, after a snapshot, that the server still has everything it pushed (§4.4).
- Removed people keep what they had. Rotation protects what’s written after the removal. It can’t reach into a copy someone already downloaded. Phase 9 already says this on the Members screen.
- Viewers hold the history. As Phase 9 already noted, a viewer’s device has the full document, history included. Encryption doesn’t change that.
2. Encrypted or standard, per workspace
The choice is made per workspace. The roadmap always said “end-to-end-encrypted spaces”, and the reason holds. Account AI providers and meeting jobs that outlive a locked phone need the server to read, and so does any agent that should work without a device of yours that holds keys. Some people want that for a workspace, and some want the opposite. One account can have both, side by side in the switcher.
- New workspace asks: End-to-end encrypted (“Only your devices and the people you share
with can read it. Your server’s AI can’t, and agents reach it through an agent device.”) or Standard (“Your server can read it,
so its AI, agents and meeting jobs work.”). The server’s owner sets what’s offered:
[e2ee] new_workspaces = "ask" | "encrypted" | "standard", default"ask"(decision 1). - An encrypted workspace shows a lock beside its name in the switcher, and Workspace settings → General says “End-to-end encrypted” with a link to what that means (§1.2, in plain words).
- Converting: owners can turn encryption on for a standard workspace (§8), and off again, which is the same process in reverse. Both are resumable and lose nothing.
- The first workspace of a new account follows the server’s setting. If it’s
"ask", the question is part of the first-run screen.
3. Keys
3.1 The hierarchy
Recovery key (24 words; only you hold it)
└─ decrypts → Account root key (ARK), versioned
Device key pairs (one per device; private half never leaves it)
└─ receives the ARK when another device approves it
ARK
└─ seals → the account's identity keys:
• signing key pair (Ed25519): signs device certificates and key changes
• encryption key pair (X25519 + ML-KEM-768, hybrid): receives container keys
• the account container key: seals your own documents (Ask chats)
Container keys (32 bytes, versioned by epoch), one per:
• encrypted workspace (its workspace document and every page in it)
• restricted tree (private pages, pages shared with some people, guest trees)
└─ wrapped to each member's account encryption key (HPKE)
└─ each epoch also seals the previous epoch's key (a chain, so history stays readable)
Document keys = HKDF(container key at epoch e, document ID): derived, never stored
└─ seal each update and snapshot of that document
Attachment keys: random per file, kept in the block that shows the file (inside the page)
Why this shape:
- The account root key is the one thing a device needs. A new device gets it once and can then unseal everything else from the server. Recovery is a wrap of the root key and nothing more.
- The recovery key is a key pair. The 24 words are the private half. The public half is stored with the account, so any device can wrap a new root key to it without ever knowing the words. When keys rotate after you lose a device, your recovery key keeps working and you don’t have to type it.
- Container keys are wrapped per person, not per device. Adding a device touches no workspace. Inviting Sam is one wrap per container.
- Document keys are derived, not stored. Rotating a container’s key changes every document key in it at once, with no table of page keys to keep in step. This covers the brief’s “page keys”: each page has its own key, but it’s never stored anywhere.
- Moving a page to another container re-seals it under the new container (§5.3). There’s no per-page key to carry around, and nobody who loses access keeps one.
3.2 Setting up, and the recovery key
Encryption keys are made the first time you need them: when you create or join an encrypted workspace, or are invited to an encrypted page. Someone who only ever uses standard workspaces never sees this.
- “Set up encryption”. The device makes the root key, the identity keys and the recovery key. It uploads the identity keys’ public halves, the private halves sealed by the root key, and the root key wrapped to the recovery public key.
- “Save your recovery key” shows the 24 words, with Copy, Save as PDF (a printable page with the server’s address and the account’s email, made on the device) and Save to a password manager (the platform’s share sheet or a file). It’s the one key that opens your encrypted workspaces if every device is gone. Drusite and your server can’t recover it.
- “Check it” asks for words 3, 11 and 20. You can skip this, and Settings → Security then shows “Recovery key not checked” until you do.
Settings → Security (an Account page):
- Recovery key: when it was made, and Make a new recovery key, which shows new words and stops the old ones working. The words are never shown again after setup, because the device doesn’t keep them.
- Devices with your keys: every device that holds the root key, with its name, when it was approved and by which device, and Remove (§3.5).
- Your safety code (§3.6).
The words come from the BIP-39 English list, which was chosen to be easy to write by hand and has a checksum. A mistyped word is caught as you type it. The words are only an encoding of 32 random bytes. Nothing about cryptocurrency is involved, and the UI never says “seed phrase”.
3.3 Adding a device
A new device signs in as it does today (any login method). It then has a server session but no keys, and shows “Open your encrypted workspaces” with two ways in:
- Approve from another device (the default). The new device makes its device key pair and
posts an approval request. Every signed-in device of yours that has the keys shows “A new
device wants your keys: Firefox on Linux, signed in 1 minute ago”. Both screens show the same
six-digit code. If they match, Approve on the old device seals the root key to the new
device’s key and certifies it with your signing key. The new device has its keys within a
second or two.
- The code is a short authentication string over both devices’ public keys, with a commitment first. The new device commits to its key before it learns the approver’s nonce, so a server in the middle can’t search for a key pair that gives the same code. This is the numeric comparison pattern from Bluetooth pairing and ZRTP, built from HKDF-SHA256 and nothing new.
- A request expires after 10 minutes. You can deny it, and Deny and sign it out ends that session too.
- Use your recovery key: type or paste the 24 words.
Until one of these is done, the device can open standard workspaces as usual. Encrypted ones show in the switcher with “Waiting for your keys”.
The browser is a device like any other. Its keys live in its OPFS store, wiped on sign-out as Phase 7 does with everything else, so signing in again means approving it again.
3.4 Passkeys, OIDC, passwords, magic links
The login is never the key. Signing in proves to the server who you are. Keys come only from an approved device or the recovery key. This is the same for every login method, so:
- Changing how you sign in (adding a passkey, moving to OIDC, resetting a password) never touches your keys.
- A server admin’s
drusite-server account recoverlink gets you back into your account and your standard workspaces. It can’t open encrypted ones. The recovery page says: “Your encrypted workspaces need your recovery key or one of your devices.” - An identity provider that’s compromised can sign someone in as you. They still need one of your devices to approve them, or your recovery key.
Passkey unlock (WebAuthn’s PRF extension, which lets a passkey derive a secret) would let a passkey also unwrap the root key on a new device. Support varies too much across platforms and password managers today to count on, so it’s listed under Not in this phase. The wrap format leaves room for it as one more way to unlock.
3.5 Losing devices
-
One device lost, others left: Security → Devices → Remove. This signs it out on the server (as Account → Devices does today) and then, from the device you’re using:
- makes a new root key version and new identity keys, signed by the old signing key, so everyone you share with accepts the change without a warning (§3.6);
- wraps the new root key to your recovery public key and to each remaining device;
- rotates every container key the lost device could read (§5.5): your workspaces, your trees and the shared ones. Rotating a shared container needs only the members’ public keys, so you can rotate a workspace you don’t own.
The lost device keeps the notes it already had. It can’t read anything written afterwards.
-
Every device lost, recovery key kept: sign in on a new device and use the recovery key. Then do the same rotation as above, because whoever has your old devices also has the old keys.
-
Every device lost, no recovery key:
- Your private pages, and every encrypted workspace you’re the only member of, are gone for good. The server holds only ciphertext. Setup says this before showing the words, and in the same words.
- Shared encrypted workspaces can be given back. Security → Start over with new keys makes fresh keys. The members who still have the workspace see “Sam’s keys were reset” and Give access again, which wraps the current key to Sam’s new one. Sam then has the whole workspace again, history included, through the epoch chain.
3.6 Knowing a key is really someone’s
The server hands out public keys, so a dishonest server could hand you its own key in place of Sam’s when you invite them. Two defences, both from Signal’s playbook:
- Trust on first use, with signed changes. Each device remembers every account’s signing key the first time it sees it. A later key must be signed by the previous one. One that isn’t (Sam started over, or the server is lying) shows “Sam’s safety code changed” on Members and on the page’s Share panel. Nothing is shared with the new key until someone with the old key accepts it.
- Safety codes. Members and Share show each person’s code: 30 digits in six groups of five, made from their signing key as Signal makes its half of a safety number (5,200 rounds of SHA-512), so faking one is out of reach. Two people can compare codes in person or over a call. Mark as verified keeps a check beside their name until the code changes.
Nobody has to do either for things to work. Both are there for the people who need them.
3.7 Where keys live on each platform
| Desktop (macOS, Windows, Linux) | iOS, Android | Browser | |
|---|---|---|---|
| Root key, device private keys, unwrapped container keys | Inside the SQLCipher store, as rows | Same | Same, in the OPFS store |
| What protects them | The store key in the Keychain, Credential Manager or Secret Service, as today | The store key in the Keychain or Keystore (StrongBox where present), as today | The store key wrapped by a non-extractable WebCrypto key, as today |
| New OS prompts | None: no new keychain item | None | None |
| In memory | Zeroizing buffers, dropped when the workspace closes | Same | Same |
The DPoP device key stays where it is, in the Secure Enclave or Keystore. It proves the device to the server. The new device key pair proves the device to other devices. Ed25519 and X25519 aren’t available in the Secure Enclave, so the device key pair can’t be hardware-bound. It sits behind the store key, as every note already does.
4. Loro sync over encrypted blobs
4.1 What a sealed entry is
Every update and snapshot an encrypted document’s device pushes is one sealed entry:
| Field | In clear? | What it’s for |
|---|---|---|
format (1 byte), suite (1 byte) | Yes | Versioning, so the format and algorithms can change later |
container, epoch | Yes | Which key seals it. The server refuses entries sealed with an epoch older than the container’s current one (§5.5). |
device (the device’s certified key ID) | Yes | Whose signature to check |
peers (the Loro peer IDs whose changes it carries) | Yes | The peer register (§4.2) |
kind: update or snapshot, and for a snapshot, the server sequence it replaces through | Yes | Compaction (§4.4) |
nonce (24 bytes) and the ciphertext of the padded Loro bytes | Ciphertext | XChaCha20-Poly1305 under the document key. AAD: workspace, document, document kind, container, epoch, device, peers and kind. |
| For a snapshot: its Loro version vector, sealed separately | Ciphertext | Lets a device check a snapshot without downloading it (§4.4) |
signature | Yes | Ed25519, by the device, over everything above |
- Padding: plaintext is padded to at least 512 bytes, then with Padmé, which hides all but the top few bits of the length at a cost of at most 12%. A 1-character edit and a 40-character paste look the same.
- Overhead: about 150 bytes per entry plus padding. Pushes are already batched per document (not per keystroke), so this is per batch.
- The server still stores the server sequence number and receive time next to each entry, in clear, as today.
4.2 What the server checks, and what devices check
The server can still check, and does:
- the push comes from the signed-in device: the signature verifies against that device’s certified public key;
- every peer in
peersis unclaimed or already belongs to this person and device, sodocument_peerskeeps refusing a peer that belongs to someone else (Phase 9’s rule); - the container and epoch are current, and the person may write to that document (Cedar and row-level security, unchanged);
- the size limit (
MAX_UPDATE_BYTES).
The server can’t check that the ciphertext is a valid Loro update, that it belongs to this document, or that it has no gap. Every device checks, before importing:
- the signature, and that the device’s certificate chains to a member’s signing key the device trusts (§3.6);
- that the AEAD opens. This proves it was sealed with this document’s key, epoch and AAD, so an entry copied from another document, container or epoch fails;
- that the decrypted blob’s own peer set, read with
decode_import_blob_meta, is within the declaredpeers. A member can’t push changes under someone else’s peer, even though they hold the key.
An entry that fails any check is quarantined: kept aside, never imported. The page shows “A change from Sam’s MacBook couldn’t be verified and wasn’t applied” with Details.
4.3 Catching up and pushing, without the server’s version vector
Today the server tells a device its log’s version vector (Subscribed.version), and the device
pushes whatever goes beyond it. Over ciphertext, the device works the vector out itself:
- The server log’s version is the union of the versions of every entry the device has pulled
(each decrypted entry’s metadata gives its start and end) and every push the server has acked.
The device keeps this per document in its store, as
server_version. - After catching up, the device pushes
oplog_version − server_version, as today. The sync protocol stays the same shape. Only the side doing the arithmetic changes. - Gaps are Loro’s pending changes: an update that depends on changes the device hasn’t got
waits in Loro until they arrive, exactly as today when updates arrive out of order. The server’s
Gaprefusal is skipped for encrypted documents, because it can’t detect one. - A device that pushed and then lost its store (reinstalled) pulls everything from sequence 0,
so its
server_versionis rebuilt from the entries it pulls.
4.4 Compaction by devices
The server can’t import a log, so a device makes the snapshots:
- When a document’s log passes
COMPACT_AFTER(500) entries since its last snapshot, the server setscompact_wantedinSubscribedandAck. - A device that has caught up on that document, and may edit it, exports a full snapshot
(
ExportMode::Snapshot: current state and the whole oplog). It seals and signs the snapshot, then pushes it withkind = snapshotandthrough_seq. Phones do this only on Wi-Fi or a charger when the snapshot is over 1 MB. Desktops always do. Only one device does it: the server hands the job to the first device that asks and gives it 10 minutes. - The server stores the snapshot and keeps the entries it replaces for 14 days, still encrypted, before deleting them.
- Every other device checks it. When a device sees a new snapshot on a document it has, it
downloads only the snapshot’s sealed version vector (a few hundred bytes) and compares it with
its own
server_version. If the snapshot is missing anything the device knows the server had, the device pushes those changes again, and reports the snapshot with aBadSnapshotframe. That restores the old entries, deletes the snapshot and locks out that device’s compaction until a person looks. A buggy or malicious snapshot can’t lose an edit while any device, or the 14-day window, still holds it.
New devices load the snapshot and then the updates after it, as today.
4.5 Version history (Phase 9) survives
- Snapshots keep the full oplog (§4.4 step 2), so every change, its time and its commit message
(
restore:…,import:notion,agent:…,encrypt) stay in the document. Shallow snapshots stay unused, as Phase 9 decided. - Who:
document_peersstill binds each peer to a person and device, from the declared and signedpeers(§4.2). It’s now verified by every device as well as recorded by the server. - The server’s clock: Phase 9 uses the server’s receive time when a live edit’s clock is off by
more than 5 minutes. The server can’t read the change’s time, so it sends
received_atwith each entry and the device applies the same rule. - Named versions live in the workspace or tree document, so they’re encrypted like everything else.
- Restore is a new edit on the device, as today.
4.6 Protocol changes (protocol 2)
Added fields, so an encrypted-aware app on protocol 2 still speaks to standard documents the old way:
Welcome:e2ee: bool(the server supports it) and, per workspace,encryption(standard,encryptedorconverting).Push: the sealed entry’s clear fields (§4.1).Entry:received_at, and whether it’s a sealed entry.Subscribed:compact_wanted,snapshot_seq, and an emptyversionfor encrypted documents.- New frames:
Snapshot(§4.4),BadSnapshot,KeysChanged(a container got a new epoch or a new member’s wrap, so fetch keys) andApprovalRequest(§3.3). - New error codes:
StaleEpoch(re-seal with the current key and push again; the device does this without asking),NeedsKeys(this device has no keys for that container yet) andNeedsUpdate(a protocol 1 app subscribing to an encrypted document; the app says “Update Drusite to open this workspace” and points at Check for Updates). - REST, under
/api/v1/:account/keys(public keys, sealed private keys, recovery wrap),account/devices/{id}/approval,workspaces/{ws}/keysandworkspaces/{ws}/trees/{t}/keys(epochs, wraps, the epoch chain),workspaces/{ws}/encryption(conversion, §8).
5. Sharing (Phase 9) over encrypted workspaces
5.1 Members and invites
Invites work as Phase 9 built them (email links, the invite link, roles, every login method). The key step comes after the invite:
- Sam opens the invite and joins, which needs encryption keys (§3.2) if they have none yet.
- Their membership exists at once on the server, but they have no key yet. Their switcher shows “Work · Waiting for access”.
- Any online device of someone who may invite (owners, and editors when “Editors can invite” is on) sees the new member, checks their signing key (§3.6: first use, or a signed change), wraps the current workspace key to them and uploads it. This runs in the background, with no prompt. If the person inviting is online, it happens within seconds.
- Sam’s devices get
KeysChangedand open the workspace, history included.
If no one who may invite has a device online, Members shows Sam as “Joined, waiting for a device”, and the invite screen says “Sam can open Work once one of your devices is online.”
- Invite pages and emails can’t show the workspace’s name, because the server can’t read it. They say “Alex invited you to an end-to-end encrypted workspace on (server)”. The name appears once Sam has the key.
- The OAuth consent page lists encrypted workspaces as “End-to-end encrypted workspace”, with the agent device that serves each one (§6.4), or, with none, “Add an agent device to let agents read this workspace.”
5.2 Roles
Owner, editor and viewer stay as they are, enforced by the server (Cedar and row-level security) as today. Encryption adds:
- Viewers hold the key, because reading needs it. The server refuses their pushes, as today. A viewer with a modified app could seal an update, but the server won’t store it, and other devices would reject it anyway: they check the signer’s role in the membership list before importing.
- Who can rotate: any member, because rotating needs only public keys. In practice it’s the device of whoever removes someone (§5.5).
5.3 Private pages and restricted trees
Each restricted tree (Phase 9 as built: private pages, pages shared with some people, guest trees)
is a container of its own, with its own key wrapped only to the people page_access lists. A
private tree’s key is wrapped only to you. The server keeps checking page_access on every
subscription. Encryption means a mistake there would leak ciphertext, not notes.
Moving a page (to Private, to Workspace, into a tree shared with a guest) is done by the device, not the server, because the server can’t edit the workspace document any more:
- The device makes both edits (delete the entry from one tree document, write it in the other), seals them, and re-seals a fresh snapshot of each moved page document (and its subpages) under the destination container’s key.
- It sends all of it to
POST …/pages/{page}/move, which the server applies in one transaction. It appends both tree updates, swaps each page’s log for its new snapshot, and updatespage_access, so nobody ever sees half a move. - The page keeps its ID, links and history (the snapshot carries the whole oplog). The old entries are deleted, so the server never keeps the page under a key that people who’ve just lost access hold.
Moving still needs a connection, as Phase 9 built it.
5.4 Guests and single-page sharing
A page shared with a guest is a tree of its own (Phase 9 as built). Sharing it is a wrap of that tree’s key to the guest’s account key, done by the sharer’s device once the guest has keys, as in §5.1. The Share panel shows “Sam · Waiting for access” until then.
A link to a page the reader can’t decrypt shows the existing “No access” chip. A query block or inline database lists only rows from documents the reader can open. The device can’t show what it can’t decrypt, so these are now enforced twice.
5.5 Removal and key rotation
When someone is removed from a workspace or a tree (or their access to a shared page is taken away, or a lost device is removed, §3.5):
- The server cuts them off at once, as Phase 9 built it.
- The removing device rotates the container: it makes epoch e+1, wraps it to every remaining
person, seals epoch e’s key under e+1 (the chain), and uploads all of it in one request. From
then on, the server refuses new entries at epoch e (
StaleEpoch). - Devices with unsynced edits at epoch e get
StaleEpochand re-seal those edits under e+1 without asking. No edit is lost by a rotation. - Old entries stay at their epochs until the document’s next compaction re-seals them under the current key. Everyone who can read the document can read them through the chain. Someone removed already had them.
- If the removal is made by the server’s admin (the CLI, or an account disabled), the
container is marked
rotation_due. The next device of a remaining member that connects does step 2. Until then, the server’s access check is what keeps the removed person out.
The cost is one HPKE wrap per remaining person, about 0.2 ms each with the hybrid KEM. A workspace of 50 people rotates in well under a second.
6. Server features that read plaintext
The per-workspace opt-in used below is Workspace settings → AI → Let your server’s AI read
pages when asked (decision 3). It’s off by default and owners turn it on. While it’s on, the
switcher’s lock shows a dot, and Settings says “Your server reads the pages it needs for Ask,
search by meaning and meeting notes, when you use them. It keeps nothing afterwards.” It sends
plaintext from the device to the server for one request at a time. The server never gets a key,
never stores the text, and logs to ai_audit without the text, as today. The server’s owner can
remove the option entirely with [e2ee] server_ai = false.
| Feature | Moves to the device | Opt-in (server reads, per request) | Lost in an encrypted workspace |
|---|---|---|---|
| Search by words | Already on the device (tantivy, and the browser’s in-memory index) | No need | The server’s index (search_blocks) isn’t built |
| Search by meaning | Vectors made from the device with a device provider’s embedding model, kept in the encrypted store, searched on the device | The device sends blocks to the server’s or account’s embedding model and keeps the vectors | search_embeddings isn’t built. The browser has meaning search only with the opt-in (it has no device providers, Phase 8). |
| Ask your notes | Retrieval on the device, the prompt built on the device, sent to a device provider | The prompt goes through the server to a server or account model, as Phase 8’s “server model” path | Saved chats move out of server tables into your encrypted account document |
| Meeting notes | Recording and the audio attachment are encrypted. Transcription and summary run from the device, through a device provider. The app has to stay open, as Phase 8 says for device providers. | The device uploads the audio for that one job, decrypted. The server transcribes it, seals the result to your account key, and your device writes it into the page when it next opens. | A server job that writes into the page by itself |
| Updates & analytics | The feed’s titles and excerpts come from the device’s own copy and its history. The server sends only who, which document and when. | No need | Analytics is off by default in encrypted workspaces (views are metadata). Owners can turn it on as today. |
| Publish to web | Not applicable | Publishing is the opt-in: “Publishing puts a readable copy of this page on your server and the web.” The device uploads a plaintext snapshot of the published page, and re-uploads it a minute after edits while any editor’s device is online. | Pages publish only when an editor’s device updates them, so a published page can lag behind until one is online |
| Agents (MCP) | An agent device (§6.4) serves the same MCP tools from wherever the agent runs, with keys for only what you give it. The desktop’s local MCP works too. | No | The server’s own /mcp can’t open encrypted workspaces. It points agents at the agent device that serves them. |
| Notion import, Markdown import and folder sync | Already on the device | No need | Nothing |
Details that matter:
6.1 Search by meaning on the device
- Where vectors come from: the embedding model chosen in Settings → AI, if it’s a device provider (Ollama on a laptop, or any OpenAI-compatible endpoint whose key is on the device). With none, ⌘K searches by words only and says “Search by meaning needs an embedding model on this device” with a link to Settings → AI. No model is hardcoded or bundled (§15).
- Where vectors live: in the encrypted store, one row per block (the same blocks the server indexes today), as int8-quantised vectors. 50,000 blocks at 768 dimensions is about 38 MB on disk. They’re loaded into memory only while searching.
- Searching: brute-force cosine over int8 in Rust: 50,000 blocks in under 50 ms on a laptop,
with no approximate-nearest-neighbour crate. Words and meaning are merged by the same rank fusion
the server uses today (
search/query.rsmoves todrusite-modelso both share it). - Per device: each device builds its own vectors as pages change, in the background, on desktops always and on phones when charging. Syncing vectors between devices is under Not in this phase.
6.2 Ask on the device
Phase 8’s device-provider path already builds the prompt on the server and sends it to the device.
For encrypted workspaces, the retrieval and the prompt builder run in drusite-core instead
(ask/retrieve.rs and ask/prompt.rs move to a shared crate), over local search. Nothing goes to
the server unless the workspace has opted in. Ask works offline with a device provider on the same
machine (Ollama), which also closes Phase 8’s “asking offline” gap for encrypted workspaces.
6.3 Your encrypted account document
Ask’s saved chats, and later anything else that’s yours alone, move into one document per
person per encrypted workspace, sealed with the account container key. It syncs like a page. The
server’s ask_conversations rows for that workspace are deleted after conversion (§8).
6.4 Agents: the agent device
An agent must be able to read and write an encrypted workspace over MCP, from anywhere it runs. Encryption changes only one thing: whatever serves MCP must hold the keys, and the server doesn’t. So 1.0 has two places that serve MCP for encrypted workspaces:
- The desktop app’s local MCP, as today, for an agent on the same computer.
- An agent device: a headless Drusite process,
drusite agent, that runs wherever the agent runs, such as a container next to an agent in a cluster, a home server or a laptop. It is approved like a new phone, holds its own keys and serves the same MCP tools over Streamable HTTP. An agent that talks to it can read and write encrypted workspaces exactly as an agent on the server’s/mcpreads and writes standard ones.
The server’s own /mcp keeps serving standard workspaces, unchanged. For an encrypted workspace,
it names the agent device to use instead (below).
What it is
- It runs
drusite-corewith no UI, plusdrusite-mcp’s tools.drusite-mcpalready runs the same tools in two places through itsNotestrait (the server’s documents and the desktop’s store). The agent device is a thirdNotes: its own encrypted store, kept in sync with the server like any device’s. No tool is written twice, and the policy is the same (no delete tools, journal read-only unless allowed, every change recorded and undoable). - It ships in every release as a container image (
ghcr.io/pranavajk1/drusite-agent, signed with cosign like the server’s) and as Linux, macOS and Windows binaries. The Helm chart gets an optionalagentDevicesection, off by default, that runs it next to the server or anywhere else. - Its store is SQLCipher like every device’s. Its store key comes from a file or an environment variable, such as a Kubernetes Secret filled from whatever secret manager the deployment uses. It keeps a full local copy of what it’s given, so tools answer from the local store in milliseconds. It stays connected and live.
Adding one (Settings → Agents → Add an agent device):
- You name it (“Cluster agents”) and choose what it may read: which encrypted workspaces, and whether it gets your private pages and pages shared with you, or only the workspace’s pages (the default). You also choose its access: read-only, or edit up to your own role.
- Settings shows a one-time enrollment command, such as
drusite agent enroll https://notes.example.com --code ABCD-EFGH. Run it on the agent’s host, or put the code in the chart’s values for a single first start. It’s valid for 15 minutes and works once. - The agent device makes its key pair and sends an approval request, and both screens show a six-digit code (§3.3), the app’s and the agent device’s log or terminal. When they match, Approve wraps to the agent device only the container keys you chose. It never gets your root key, so it can never read a workspace or a private page you didn’t give it, and it can’t approve other devices.
- It shows under Settings → Agents and Security → Devices, with what it holds and when it was last connected.
How an agent connects to it
- The agent device is an OAuth protected resource of your Drusite server. An agent signs in
exactly as it signs in to the server’s
/mcptoday: the same consent screen, the same grants in Settings → Agents, the same revocation. The token names the agent device as its audience, and the agent device checks each token with the server (token introspection, cached for a minute). So there’s one list of agents and one place to revoke them, whichever endpoint they use. - The consent screen lists encrypted workspaces with the agent device that serves them: “Work
(end-to-end encrypted) · through Cluster agents”. The server’s
/mcpprotected-resource metadata and itslist_workspacestool point at the agent device’s address for those, so an agent configured with the server’s address finds the right endpoint. - A grant can never reach more than the agent device holds keys for. The device checks this on every call, and the server checks it again when the agent device pushes.
What it writes, and the record
- Edits are made as the agent device’s own Loro peers, with commit message
agent:<grant>, signed by its device key (§4.2). History shows “Scout for Sam · via Cluster agents”, exactly as Phase 9 shows server agents. - The activity log and Undo work as today. The server keeps only what it can without reading: which grant, tool, page ID and time. The text of each change lives in the document’s history (the agent device’s peers and commit messages), where the apps read it, show it and undo it.
- Search for agents:
searchruns on the agent device, by words always and by meaning when the agent device has an embedding model configured. Like any device, it takes any OpenAI-compatible endpoint you give it in its config, with nothing assumed.
Removing one: Settings → Agents → Remove revokes every grant that goes through it, signs it out and rotates every container it held (§5.5), as removing a lost device does. Changing what it may read works the same way: taking a workspace away rotates that workspace’s key. Giving it a new one wraps that key to it from any of your online devices.
What this trusts: whoever controls the agent device’s host can read what it holds, which is the point of it. The threat model says so (§1.2). Security → Devices marks it “Agent device · reads Work”. The server still never holds a key.
On shared workspaces: an agent device belongs to one person and gets keys through that
person’s access. Other members see it in Members as “Cluster agents (Sam’s agent device)”, with its
access. Owners can turn agent devices off for a workspace (Settings → Members, Allow agent
devices, on by default), and the server’s owner can turn them off for the whole server
([e2ee] agent_devices = false).
7. Attachments and the canvas
7.1 Attachments in S3
- Each file gets a random 32-byte key, kept in the block that shows it (the attachment block, a canvas image, a meeting’s audio), so it’s inside the encrypted page. Whoever can read the page can read the file, and nobody else, whichever tree the page moves to.
- Sealing: the file is padded (Padmé) and sealed with the STREAM construction over XChaCha20-Poly1305 in 64 KiB chunks. Each chunk is authenticated, and the last is marked as last, so a file can’t be truncated or reordered. Video and audio can seek by downloading only the chunks they need.
- Its ID is the BLAKE3 hash of the sealed file, not of the plaintext. The server keeps its check that a file is stored under its own hash, and uploading twice is still harmless. Because keys are random, the same photo in two pages is two different objects. Deduplication within a workspace is the cost (it’s rare in notes).
- Who may download: the server’s existing check (a member, or a guest with a tree in that workspace) stays as a gate. The key in the block is what matters.
- Thumbnails are made on the device and stored as attachments of their own, with their own keys.
- Deleting: when no page refers to a file any more (the device sees this when trash is emptied), the device asks the server to delete it, as today.
7.2 The canvas (Phase 10)
A canvas is a page document with extra root containers, so it’s sealed, synced, compacted and kept in history like any page, with nothing of its own to change. Images on it are attachments (§7.1). Pan, zoom and drawing are local, so their budgets don’t move. A 1,000-note canvas is about 260 KB, well within one snapshot. A page card on a canvas that links to a page the reader can’t open shows “No access”, as links do.
8. Converting existing workspaces
8.1 What the owner sees
Workspace settings → General → Turn on end-to-end encryption (owners only):
- What changes: “Your server will no longer be able to read Work. Its AI, agents and meeting jobs will stop working here, unless you let its AI read pages when asked.” It names the agents and features in use: “2 agents are connected through your server.” With them, Serve them from an agent device: pick an agent device you have (or add one, §6.4), and each agent’s grant moves to it when the conversion finishes, with no new sign-in. Agents left on the server lose access to Work and are listed so you can see which.
- Who’s ready: members without encryption keys are listed: “Sam hasn’t set up encryption. They’ll be asked the next time they open Work.”
- Backups: “Backups your server made before today can still be read with its master key until they expire.” There’s a link to the admin docs on rotating the master key to shred them sooner.
- Turn on. Then progress: “Encrypting 214 of 1,032 pages · 380 MB of 1.2 GB of files”.
8.2 How it runs
- The workspace becomes
converting. The server stops indexing it and stops its meeting jobs, and refuses its agent tokens for the server’s/mcp. Agent devices chosen in §8.1 get the workspace key with the members, and their agents switch over when the last document is done. - Each document has its own state (
standard, thenencrypted), so the work is resumable and edits never stop:- The owner’s device makes the workspace’s container key, wraps it to every member who has keys, and encrypts the workspace document and every page in it (it already has full copies). For each document, it pushes a sealed snapshot of the whole document, history included. The server switches that document’s log in one transaction.
- Restricted trees belong to their people. The owner’s device can’t read Sam’s private pages, so Sam’s device encrypts their trees the next time it opens Work. Members shows “3 people’s private pages are waiting for their devices.”
- Attachments: the device downloads each file (the server still decrypts it, as a standard
file), seals it with a new random key, uploads it under its new ID, and rewrites the blocks
that point at it. That’s one Loro change per page, with commit message
encrypt, so history shows “Encrypted by Alex”.
- A device pushing to a document that’s just switched gets
NeedsKeysorStaleEpoch. It fetches the key, re-seals and pushes again, so no edit made during conversion is lost. - Protocol 1 apps get
NeedsUpdatefor encrypted documents. They keep working on the workspace’s standard documents until those are converted too. - When every document is done, the server deletes the server-sealed rows,
search_blocks,search_embeddingsand the workspace’sworkspace_keysrows. Each person’s device moves their Ask chats into their account document (§6.3) and the server then deletes the rows. The old S3 objects go 14 days later, the same grace as compaction. - Turning it off (owners) runs the same steps the other way. A device uploads plaintext snapshots, which the server seals with a new server key.
8.3 Accounts and devices
- Existing accounts have no encryption keys until they first need them (§3.2).
- Devices change nothing on disk: the store stays the store. The root key and device keys are new rows in it.
- The server’s migration (
0015_e2ee.sql) adds tables and columns. It changes none of the data in standard workspaces.
9. Crypto choices
Only reviewed, widely used crates, mostly RustCrypto and dalek, most already vetted in
supply-chain/. No primitive is written here. The formats and protocols built on them are written
up in docs/security/e2ee.md with test vectors (§14).
| Job | Choice | Crate | Why |
|---|---|---|---|
| Sealing updates, snapshots, keys | XChaCha20-Poly1305 | chacha20poly1305 (in tree) | Already the server’s choice. Random 192-bit nonces need no counter, which matters with many devices sealing under one key. Fast in software and in wasm, with no AES-NI needed. |
| Sealing attachments | STREAM over XChaCha20-Poly1305, 64 KiB chunks | aead’s STREAM (or aead-stream, wherever the current RustCrypto release keeps it) | Streaming and seekable, with truncation and reordering caught. It’s the construction age uses. |
| Wrapping keys to people and devices | HPKE (RFC 9180), base mode, with X-Wing as its KEM (the X-Wing draft defines this) | hpke (rust-hpke) or hpke-rs: whichever supports X-Wing at step 1, vetted with cargo vet before it lands | A standard, with test vectors, for exactly “seal a key to a public key” |
| KEM | X-Wing (X25519 + ML-KEM-768) | RustCrypto x-wing and ml-kem (or libcrux-ml-kem, which is formally verified) | Wrapped keys sit on the server for years. A hybrid protects them against later quantum attacks and is never weaker than X25519 alone (decision 5). |
| Signatures | Ed25519, verify_strict, batch verification on catch-up | ed25519-dalek (in tree) | Fast, deterministic and small. Already in Cargo.lock |
| Deriving document keys and approval codes; safety codes | HKDF-SHA256; safety codes are 5,200 rounds of SHA-512, as Signal’s | hkdf, sha2 (in tree) | Standard, with domain-separated labels |
| Attachment IDs | BLAKE3 of the sealed file | blake3 (in tree) | The server’s existing integrity check |
| Recovery words | BIP-39 English wordlist, checksum | bip39 (encoding only) | A familiar, checked encoding of 32 bytes |
| Length hiding | Padmé padding | a few lines, no crate | It’s arithmetic on lengths, not cryptography |
| Randomness, wiping | OS randomness; zero on drop | getrandom, zeroize (in tree) | As today |
Considered and not chosen:
- MLS (RFC 9420,
openmls). It’s built for messaging. It gives forward secrecy per message and deliberately doesn’t give new members the past. A notes workspace needs the opposite: a new member and a new device must read the whole history. - libsodium bindings (
libsodium-sys,dryoc). They would add C to the wasm build, and the RustCrypto crates already cover every primitive. - Random per-page keys in a table. Derived document keys (§3.1) rotate with their container and leave nothing to keep in step.
- A passphrase instead of a recovery key. A passphrase-wrapped key on the server can be
guessed offline by the operator. 24 random words can’t. A passphrase could be added later as an
extra unlock (Argon2id,
argon2is in tree), never as the only one. - Encrypting everything, with no standard workspaces. It would end account providers and long meeting jobs for everyone, and every agent would need an agent device even where nobody wants the server kept out. The roadmap already chose per-space.
10. Server changes
- Migration
0015_e2ee.sql, every table with row-level security like the rest:account_keys(user, version, signing and encryption public keys, private keys sealed by the root key, the root key wrapped to the recovery public key, the recovery public key, the signature by the previous version);device_keys(user, device grant, public keys, certificate, approved by, removed at);device_approvals(request, commitment, expiry, state);container_keys(workspace, container — the workspace or a tree, epoch, user, wrap, wrapped by, created) andcontainer_epochs(container, epoch, previous epoch’s key sealed by this one,rotation_due);workspaces.encryption(standard,converting,encrypted),documents.encryption;document_updates/document_snapshots: the sealed entry’s clear fields (epoch,device,kind) and the 14-dayreplaced_at;published_copies(page, plaintext snapshot uploaded by a device, uploaded by, at);agent_devices(owner, device, name, address, what it may read, access, enrollment code hash and expiry), andcontainer_keysrows wrapped to an agent device instead of a person;agent_activitywithout text for encrypted workspaces (grant, tool, page, time; §6.4).
- Code:
sync/store.rstakes a sealed path that skipscheck_blob,Gap,compactandcheck_first_snapshotfor encrypted documents and does §4.2’s checks instead.access::move_togets a device-made variant (§5.3). The indexer, Ask, MCP, meetings and the consent page skip encrypted workspaces with a clear reason.members.rsandoauth.rsstop reading names from encrypted documents. - Agents: the OAuth server issues tokens whose audience is an agent device and answers its
introspection requests.
/mcp’s metadata andlist_workspacesname the agent device for each encrypted workspace. A new binary,drusite-agent(incrates/drusite-agent):drusite-corewithout UI,drusite-mcpover Streamable HTTP, andenroll,runandstatuscommands. - Config:
[e2ee] enabled = true,new_workspaces = "ask",server_ai = true(whether the opt-in is offered at all),agent_devices = true. - Admin docs: what backups hold for each kind of workspace, how to rotate and retire the master key, and that an admin can never recover an encrypted workspace.
11. Testing
| What | How |
|---|---|
| Formats | A new crate, drusite-e2ee, with no I/O. Golden test vectors for every format (sealed entry, snapshot header, wraps, epoch chain, device certificate, SAS and safety codes, recovery words) live in crates/drusite-e2ee/vectors/. The same vectors run natively on Linux, macOS and Windows in CI, and as wasm in Chromium, Firefox and WebKit through Playwright. That’s how every platform is proven to agree byte for byte. |
| Primitives | The crates’ own known-answer tests, plus RFC 9180’s HPKE vectors and X-Wing’s draft vectors re-run in our build |
| Properties | proptest: seal then open round-trips; any changed byte, AAD field, epoch or signer fails; padding round-trips; derived keys differ per document and epoch |
| Fuzzing | cargo fuzz targets for every parser: sealed entry, key bundle, approval messages, recovery words. They run nightly, plus 10 minutes on each PR that touches drusite-e2ee. |
Sync simulation (drusite-core/tests/simulation.rs, turmoil) | New cases: two devices editing an encrypted page offline and merging; device compaction racing live pushes; a snapshot missing changes, caught and healed by another device (§4.4); rotation while a device is partitioned with unsynced edits, which re-seals them and loses nothing; a member removed while partitioned can’t read anything written after; a page moved to Private while a guest edits it; conversion interrupted at every step, then resumed from another device; a reinstall rebuilding server_version from scratch |
| A hostile server | A simulation mode in which the server misbehaves on purpose: tampers with ciphertext, replays and reorders entries, moves an entry to another document, serves an old epoch, withholds one device’s updates, substitutes a public key at invite time, and forges a peer claim. Each must be refused, quarantined or flagged as §1 and §4 promise, and the test names which. |
| Server | Postgres tests: row-level security on every new table; refusal of stale epochs, bad signatures and foreign peers; the 14-day grace; conversion per document; the indexer, Ask, MCP and meetings skipping encrypted workspaces |
| Cross-platform matrix | Every pair approves the other: macOS, Windows, Linux, iOS, Android, and the browser in Chrome, Firefox and Safari. On each: set up, recovery key, live edit, attachment up and down, rotation, conversion. Desktops and the browser run in CI. The Android emulator and iOS simulator run in the release-candidate job, as Phase 10 runs app builds. Real devices are on Pranava’s checklist. |
| Agent devices | Simulation: an agent device enrolled, approved and given one workspace reads and writes it while the owner edits; it can’t open a workspace or private page it wasn’t given, even when the server hands it the ciphertext; removing it rotates and cuts it off mid-session; a workspace taken away from it rotates. End to end in CI: the container image against a test server, driven by a real MCP client (the MCP inspector’s CLI), with every tool run on an encrypted workspace and compared with the same tools on a standard one through /mcp; Undo of an agent change from the app; a revoked grant refused within a minute; conversion moving a grant from /mcp to an agent device. |
| Migration | A fixture workspace with history, named versions, restricted trees, a guest, a canvas, a meeting with audio and 200 attachments, converted and then compared: same text, same history (every version restorable), same attributions, every file readable. Then converted back, and compared again. |
| Losing things | Tests for every row of §3.5: one device lost, all devices lost with the words, all lost without (shared workspace given back, private pages gone, said as such) |
| UI | The memory-core browser tests: setup, recovery check, approval with matching and mismatching codes, waiting for access, safety code changed, the conversion screens |
12. Performance budgets
New budgets in xtask/src/budgets.rs and the web tests. CI fails past any of them.
| What | Budget |
|---|---|
| Keystroke p95 in the core | Unchanged at 0.5 ms. Sealing happens on the push batch, off the keystroke path. |
| Sealing and signing one push of 1 KB | ≤ 0.1 ms desktop, ≤ 0.5 ms phone and wasm |
| Opening a 1,000-page encrypted workspace from the local store | Unchanged: the local copy is plaintext inside SQLCipher, as today |
| First sync of a 1,000-page workspace on a new device | ≤ 15% slower than a standard workspace (decrypting plus batch signature checks) |
| Catching up 10,000 entries | ≤ 1 s of crypto on a mid-range phone (batch Ed25519) |
| Device compaction of a 1 MB document | ≤ 200 ms of CPU on a phone, ≤ 50 ms desktop |
| Attachments | ≥ 300 MB/s sealing on desktop, ≥ 80 MB/s phone, ≥ 40 MB/s wasm |
| Rotation of a 50-person workspace | ≤ 1 s on a phone |
| Device approval, from the matching code to keys on the new device | ≤ 3 s on a normal connection |
| Search by meaning, 50,000 blocks | ≤ 50 ms desktop, ≤ 200 ms phone |
| Storage overhead of sealed entries | ≤ 15% over today’s sealed size, padding included, for a document’s whole log and snapshot. A single small update grows to the 512-byte minimum, but compaction folds those away. |
| wasm bundle | ≤ +150 KB brotli, so the budget moves from 2.15 MB to 2.30 MB |
| Idle RAM | Unchanged. Keys are kilobytes, and the vector index loads only while searching. |
| Agent device | Idle RAM ≤ 150 MB holding a 1,000-page workspace. A tool call (read a page, search by words) answers in ≤ 50 ms p95 on the agent’s host, plus the network. Enrollment to first tool call ≤ 30 s. |
| Conversion | 1,000 pages and 1 GB of files in ≤ 10 minutes on a desktop on the same network as the server; resumable at any point |
13. Order of work
Each step lands on its own PR with its tests, and nothing is switched on for users until step 6:
drusite-e2ee: formats, vectors, wasm build and fuzz targets. No app changes.- Account keys: setup, recovery key, device approval, Security settings, safety codes. Server tables and routes.
- Encrypted documents: sealed entries, protocol 2, device-side version vectors, compaction and its checks, peer binding, history.
- Containers and sharing: encrypted workspaces, invites, trees, moves by device, guests, rotation.
- Attachments, the canvas, meetings, and §6’s moves: local search by meaning, Ask on the device, the account document, publishing copies, the opt-in.
- Agent devices:
drusite-agent, enrollment and approval, scoped container keys, tokens for agent devices,/mcppointing at them, the container image and the Helm chart’sagentDevicesection. It needs steps 2–4 and can run alongside step 5. - Conversion in both directions, including moving agents to an agent device, then the
[e2ee]settings switched on. - 1.0.0 (§14).
14. The 1.0.0 release
On top of Phase 10’s release checklist (§3 there: Developer ID and notarization, the updater key, the stable channel, the signed tag):
- The security design is public:
docs/security/e2ee.mdholds the threat model (§1), every format and protocol with its vectors, and the limits stated plainly. ASECURITY.mdexplains how to report a vulnerability (GitHub’s private advisories) and what’s in scope. - An independent review of the design and
drusite-e2ee(decision 6). - The protocol is frozen: protocol 2 and the sealed formats are 1.0’s. From 1.0 a format only
changes through its
formatandsuitebytes, and 1.x apps read every format any 1.x wrote. This extends Phase 10’s major.minor promise. - Upgrade order: the server first, then the apps. Encrypted workspaces need a 1.0 server and a 1.0 app. Standard workspaces keep working with alpha apps on protocol 1 until 1.1, and the release notes say so.
- Export compliance: update
docs/releasing.md’s answers. Drusite now has end-to-end encryption with standard algorithms. Re-check Apple’s export questions, and whether the US mass-market self-classification report applies, before the App Store and Play uploads. - Docs: README (what encrypted means, in a paragraph), setting up and the recovery key, adding a device, what admins can and can’t do, and backups per workspace kind.
- A clean export: Markdown and Notion-style export work from the device for encrypted workspaces. Leaving Drusite never needs the server to read anything.
- Account deletion deletes the account’s keys and wraps along with everything else, and rotates the containers the account shared. It also removes the account’s agent devices.
- Agent devices ship with the release:
release.ymlbuilds and signs thedrusite-agentimage (cosign, like the server’s) and its Linux, macOS and Windows binaries, and the Helm chart at that version carries theagentDevicesection. - The 1.0.0 checks on real hardware (Pranava): set up on the Mac, approve the phone and a browser, lose a device (remove it), recover with the words on a fresh install, convert a copy of a real-sized standard workspace on a test server, and update an rc build to 1.0.0 in place. Run an agent device in the cluster, connect a real agent to it, and have it read and edit an encrypted workspace.
15. Not in this phase
- Passkey unlock (WebAuthn PRF) as another way to get your keys on a new device (§3.4).
- Syncing search vectors between devices, and a bundled on-device embedding model.
- Unlisted encrypted publishing: a link that carries its key after the
#, so the server serves ciphertext and the reader’s browser decrypts it. - QR codes for device approval, alongside the six-digit code.
- Hiding timing: cover traffic or batching pushes to blur when you type.
- Comments, presence and live cursors, which don’t exist yet. Each will be sealed like everything else when it does.
16. Decisions for Pranava
One recommendation each.
- Per workspace, chosen when it’s made. Encrypted and standard workspaces side by side.
Existing workspaces stay standard until an owner converts them, and the server’s default is
"ask". Recommend yes: it keeps server agents and meeting jobs for the workspaces that want them, which is how the roadmap framed it. - Recovery: device approval with a six-digit code, plus a 24-word recovery key that must be saved at setup. No passphrase. Recommend yes: the words can’t be guessed offline by an operator, and approval covers the everyday case.
- The “let your server’s AI read pages when asked” opt-in, per workspace, off by default, shown on the lock. Recommend offering it: without it, phones and the browser have no search by meaning and no long meeting jobs in encrypted workspaces.
- The browser opens encrypted workspaces, with the plain note about server-served code shown once. Recommend yes: it’s the same protection as the apps against everything except an operator who changes the app, and refusing would make the browser useless for encrypted work.
- Post-quantum hybrid key wraps (X-Wing) from 1.0. Recommend yes: the wraps sit on the server for years. The cost is about 1.1 KB per wrap and a fraction of a millisecond.
- An independent review before calling it 1.0.0. Recommend applying to NLnet’s NGI Zero fund, which pays for security audits of open-source projects. If the review can’t happen in time, 1.0.0 ships with the design public and its release notes say plainly that the encryption hasn’t been independently reviewed yet.