How sync keeps your notes private
Tessera syncs your devices directly with one another, with every message encrypted from one device to the next, and no personal data is ever stored on a server or sent to one in a form that it can read. This post describes how devices find each other, what the relay service that introduces them does and does not know, and what a mesh of peers makes possible.
The notes I write are on my devices, and I wanted them to stay there: the library of Tessera lives in the database of the browser on the web and in the Mac app, and in SQLite on the iPhone, and the app works without a connection. What sync adds is a way for the devices of one person, and for the friends that person chooses, to arrive at the same state, and I wanted that to happen without a server in the middle that holds the notes or can read them. A server that holds your notes is a server that can be asked for them, by whoever runs it, whoever breaks into it, and whoever has the authority to demand them, and the simplest answer I found to all three was to build a system in which the server has nothing to hand over: no personal data is stored on a server, and none reaches one in a form that it can read.
The result is a mesh. Every device runs the same program with the same rights, no device is the primary one, and none of them is more important than the others. A new device joins by showing a short phrase made of words, which a device that is already in the group approves; there is no account, no e-mail address and no password, because a device is identified by two keys that it makes for itself, one that signs what it sends and one that receives secrets, and the secret halves of both never leave it. The devices of a person form a group, a group shares a content key, and the key changes each time a device is removed, so that a device that has been removed from the group is refused at once and never learns the key that follows.
What travels between two devices of a group is encrypted and signed at every step. Each message is encrypted with the content key of the group for the current epoch, which is the period between two changes of the key, and it is signed by its sender, using the Ed25519 and X25519 curves, XChaCha20-Poly1305 and HKDF with SHA-256, all taken from the audited noble libraries and none of them written by me. Before a device applies anything, it checks that the sender is an active member of this group, that the message belongs to the current epoch, and that it was neither altered nor replayed; the updates are then checked against limits on depth, number of entries and size before they are decoded, and a peer that goes beyond them is disconnected. The two devices begin each session by exchanging a hello and signing the transcript of both, which contains the fingerprint of the connection itself, so that anything placed in between them, at the moment they found each other, is noticed and the session is closed before a single note has been exchanged.
Two devices that have never met need an introduction, and a small relay service gives it. It relays the messages that two devices exchange to set up a connection, and the connection itself when the networks of the two devices allow no direct route, in which case it carries messages that are already encrypted. To do this it keeps a short list of which devices belong together, each identified by a random identifier and a public key, and the content keys that are sealed for each of those devices. It has no accounts and nothing personal in it: no name, no e-mail address, no note, no title, no tag, no date, and nothing that it receives is readable by it. The devices do not need to trust it, either: they verify the history of the membership from its first signed statement, they refuse a list of members that is older than one they have accepted, and they refuse a key that does not come from the member who signed the change that required it.
Your devices
Each holds the library and its keys.
A friend's devices
They receive only the outlines that you share.
Sharing an outline with a friend uses the same machinery with one more boundary. The friend's devices form a group as well, the shared outline has a document and a content key that are separate from those of the rest of your library, and the friend's devices are given that key and nothing else, so that what they receive is the outline you shared and not a trace of what surrounds it. When a connection with a friend goes through the relay service, the friend learns the address of the relay service and not the address of any of your devices. A friend who can read an outline can copy it, and a device that is unlocked shows whatever it holds, and encryption between devices changes neither of those two facts; what it changes is who else can read the notes while they travel and while they are kept anywhere other than on the devices you chose.
The mesh is also what makes some uses possible that a central server would make awkward, and the clearest of them is the Multiple keys plugin. Its purpose is a note that opens only when everyone on a shared outline, whether there are two people or thirty-two, has agreed to open it, and the rule is enforced by arithmetic and not by the policy of a server. When the note is sealed, the plugin has a new random key made, it encrypts the note with it, it cuts the key into as many parts as there are people on the outline in such a way that any smaller number of parts says nothing about the key, and it seals each part for one person with the keys of that person; the plugin names the recipients and never handles a key, which is how every plugin that locks something for friends works. Each person agrees by giving their part, in any order, the note opens on every device once all the parts are there, and closing it makes a new key and new parts, so that the parts given before open nothing. The note is stored only in its sealed form, and it is the same synchronisation that carries the sealed note and the agreements from one device to another.
Sealing a note with Multiple keys
- A new random key is made, and it encrypts the note.
- The key is cut into one part for each person on the shared outline.
- Each part is sealed for one person, who is the only one able to open it.
- The note opens, in memory, on each device, once every part has been given.
I do not rule out adding a server node to the mesh at some point, as an option that a person chooses and not as a requirement. It would be one more peer, a device that is always on, for the people who want their devices to be able to sync when none of the others is awake, and nothing in the design depends on it, just as nothing in the design prevents it. What I intend to keep from the present system is the order of the reasoning: a notes app should work with no server at all, a person should be able to add one on purpose, and none of the machines in between, the relay service today and a server node tomorrow, should be given the means to read what it carries.