How encryption works
A plain-language account of Flaq's end-to-end encryption: keys from your password, the key backup, what the server never sees, history for newcomers, resets, and the limits.
Messages and files in Flaq are end-to-end encrypted. They are sealed in the sender's app and opened in the recipients' apps, and the server only ever holds ciphertext and the keys to it, wrapped for each person. Nobody with the server, its database or its backups can read them, the people who run it included. You never see a key: your password unlocks everything, on any device, and other members' apps share what a newcomer needs without anyone doing anything.
This page explains how in plain terms. The full specification is ENCRYPTION.md on GitHub.
What the server never sees#
| End-to-end encrypted | Visible to the server |
|---|---|
| Message text, edits included | Who is in which conversation, who wrote when, thread structure |
| File contents, names, types, image previews and dimensions | A file's size and kind (image, video, audio, file) |
| Search words | Who a message mentions, so it can badge and notify them |
| Each person's private keys | Reactions, pins, saves, read positions |
| Channel names, topics and descriptions; people's names, statuses and avatars; custom emoji | |
| System lines such as "joined" and "renamed the channel" |
The server never sees your password either. Everything also travels over TLS.
Your password makes your keys' lock#
When you sign in, the app turns your password into two things on your computer, using a deliberately slow function (PBKDF2, 600,000 rounds for new accounts):
- a sign-in secret, which is sent to the server. The server stores only a slow hash of it, so it can check your sign-in without ever learning your password;
- a backup key, which never leaves your computer.
Your identity is two key pairs: one for receiving keys from others, and one for signing what you send. The app makes them on your first sign-in, and uploads the private halves to the server in a backup sealed with the backup key. Only your password opens it.
Signing in on another computer fetches the backup and opens it with your password. The app then keeps your keys in storage only you can read, and forgets the password. Changing your password seals the same backup again under the new one, so your keys stay the same.
Conversations have their own keys#
Every conversation has a key, replaced from time to time. Messages are sealed with it, and each member receives it in an envelope only their own keys open, signed by the member who made it. The server stores the envelopes and can't open any of them.
A new key is made by whichever app next needs one:
- when a conversation starts;
- after a member leaves or is removed, so they can't read what follows;
- when someone is about to send and has no key yet.
Every message is also signed by its sender, so nobody, the server included, can forge one in someone else's name.
New members read the history#
As in other group chats, newcomers read the whole history. Any member's app that holds a conversation's keys shares them with members who lack them. The server tells the apps when there is something to share, and they answer in the background.
Until that happens, a message shows "This message will appear when another member's app is online", and opens by itself when the key arrives. An account an admin made and nobody has signed in to yet has no keys, so it gets them shared on its first sign-in. This is why the admin signs in to the app once after setting up a server.
Files and search#
Files are sealed in the app before upload, each with a key of its own carried inside the encrypted message. The server stores the sealed file and knows its size and kind, nothing else. A picture's preview travels inside the encrypted message too.
Search works without the server learning your words. The app turns every word, and every beginning of a word three letters or longer, into a short code made with the conversation's key, and sends those codes with the message. A search sends the codes for the words you typed; the server finds messages with matching codes. It learns which messages share words, never the words.
Password resets#
An admin can reset your password, or, where the server or Connect has email, you can set a new one by emailed link. Either way, nobody can recover your old key backup: only the old password opens it.
So a reset starts a new identity:
- Your next sign-in makes new keys.
- The other members' apps share the conversations' keys again with your new identity, by themselves.
- Your history comes back, as long as at least one other member of each conversation still has its keys.
- The people you talk with see a quiet notice that your security code changed, usually because your password was reset.
If every member of a conversation has lost their keys, its history can't be recovered. That is what end-to-end encryption means.
Trusting keys#
The server hands out everyone's public keys, so a dishonest server could try to hand out its own instead. Two things stop that from going unnoticed:
- Pinning. Your app remembers each person's keys the first time it sees them, and compares every later answer. A newer identity after a reset is expected and shown quietly. The same identity with different keys is not, and shows a warning.
- Security codes. Two people can compare a code made from both their keys, in person or on a call. See Security codes.
What this does not protect against#
- A device someone else controls. The keys are in the app; malware on the device can read what you can.
- A weak password. Whoever has the database can try to guess passwords against the backups. The slow function slows that; a strong password stops it.
- Metadata, listed in the table above: who talks to whom, when, and channel names.
- A server that changes the admin console. The console's page is code the server sends, so a compromised server could capture an admin's password as it is typed there. It never holds anyone's keys or messages, which are only in the apps, whose code doesn't come from the server. An admin who worries about this sets passwords from an app instead.