End-to-end encryption
Overview#
Encrypted text has passed the BestBuds dev pilot on both physical phones. The broader application integration is still in progress. The native engine, signed device credentials, ordered directory, common security actor and platform secret boxes are implemented. Forty-two native tests, five actual JVM/native scenarios and directory and content SQL checks passed. Two separate JVM processes exchanged ciphertext through the deployed dev services, recovered from competing commits and restarted to read history. In R21, Android and iPhone each passed a 26-step direct send and history flow, a 21-step receive and history flow, and a 29-step three-member group flow. The native third member authenticated the iPhone reply and reopened it after restart. SQL verified five fresh direct and group rows contain ciphertext and complete envelopes only. R21 security checks passed 22 JVM and five JavaScript tests, including rejected pre-join history, tampered content and protected-write failure regressions. On 3 November the P4 content work passed part of its phone checks on dev: the Android phone sent and reread polls, voice notes, video, audio and document files, and a consented BestBud share, and two JVM processes filed a genuine report, which was accepted, and a tampered one, which was refused. Later that evening, after two slowdown fixes, the iPhone passed the poll, voice note, file, sticker and photo, and BestBud share flows. Replies, edits and deletion on both phones, stickers and photos after a restart on Android, exchanges between the two phones, locked-phone previews, web encryption and recovery remain open.
reaktor-security owns the reusable encryption engine. Auth identifies devices, while each application decides who belongs to a conversation. BestBuds is the first planned consumer. Direct chats, groups and Circles will share the same engine.
The first application checkpoint passed in an allowlisted dev chat: the physical Android phone and iPhone sent and received text, restarted and read history, with ciphertext stored on the server. A three-member group passed the same phone checks with a native third member. Other content types, notification previews, web support and recovery follow this working path.
Try it#
The dev pilot is restricted to an explicit chat allowlist. The live service path has passed the two-process JVM proof and text acceptance on both physical phones. General application availability remains pending. From the BestBuds workspace, run ./gradlew :reaktor:reaktor-security:jvmTest :reaktor:reaktor-security:nativeHostCheck. The wrapper chooses the build host. The JVM test loads the actual native library; GoogleTest exercises durable state, signed credentials, content, attachments, the C ABI and pinned MLS reference vectors. Reference files are downloaded at a fixed revision and checked against SHA-256 pins.
SecurityNode owns the native engine and exposes ReaktorSecurity through the graph. It stores device identity, key packages, pending commits and accepted snapshots in one protected record before publishing network effects. Android uses Android Keystore, iOS uses a device-only Keychain root, and macOS uses Keychain. Raw snapshots and exported key rings contain secret material. Native state is persisted after sealing and before ciphertext is released. An opened message's plaintext is released only after a protected write covers the state that opened it. Opens waiting together in the actor's mailbox share one write, and the app opens a page of history at once, so a page of history costs one or two writes rather than one per message. If a later command fails and the actor rolls back to its durable state, it opens the held messages again before the next write; a failed write withholds every held message. A protected rewrite is skipped only when saved metadata and the complete native snapshot are unchanged. JVM tests cover restart before any echo, failure of a new-state write, repeated authenticated history while protected writes are disabled, queued opens sharing writes, a failed shared write and a rejected message among queued opens. Direct and group history survived application restart on both phones. Rejected pre-join history and tampered messages preserve healthy membership only after durable rollback succeeds; failed protected writes still withhold content. The real macOS Keychain check remains deferred.
How it works#
The following describes the target design. The phase table below distinguishes it from the current implementation.
Devices and credentials#
Each install creates its own signing identity. The engine verifies credentials against pinned auth public keys, expected tenant and application, validity times, the MLS leaf signature key and the supported cipher suite. It checks every group member against the authoritative user set supplied by the application. The Auth service issues these credentials using dedicated persistent ES256 keys. The directory publishes active devices and one-use MLS key packages, with an explicit last-resort package.
The existing desktop credential store belongs to reaktor-auth: macOS Keychain persists sign-in sessions without loading the MLS engine. Device credentials for encryption are separate from those sign-in records.
Groups, epochs and membership#
One application conversation id identifies one MLS group. Every membership change or key refresh advances its epoch. The application compares the MLS roster with its authoritative conversation membership before sending.
The engine stages a commit without advancing its accepted epoch. The application must persist that pending state before publishing and accept it only after the server acknowledges the exact commit. The directory locks the conversation row and accepts one winner when two devices commit at the same epoch. Other devices process ordered public commits; newly added devices receive welcomes. Historical member and roster metadata lets devices catch up across membership changes. Authorized new devices can prepare an external join using an inline ratchet tree. Real PostgreSQL tests cover ordering and rollback; actor tests cover restart, competing creation and recovery from a lost publication response. The live dev-service proof passed with two separate JVM processes, two recovered commit conflicts, two process restarts and reopened history.
Sealed content and history#
The implemented native message construction derives one content key per conversation and epoch from the MLS exporter. Each message uses fresh random input to derive its own encryption key and nonce. The authenticated envelope binds its identifiers, epoch, format and franking commitment to the ciphertext. A sender-device signature inside the ciphertext identifies its author to recipients.
Devices retain the content keys for epochs they belonged to, allowing them to open older server pages repeatedly. This provides secrecy at epoch granularity; it does not provide MLS application-message key deletion after each individual message. The construction requires independent cryptographic review before general activation.
The native attachment API encrypts authenticated chunks with a final-chunk marker and verifies a digest before publishing the completed file. Application integration remains to be built. File keys, names, MIME types, dimensions and durations belong inside the sealed message body. The server stores encrypted objects and checks conversation membership before serving chat media.
Push, reports and recovery#
Notification extensions will read a sealed epoch-key ring without advancing MLS state. When a notice cannot be opened, it retains a generic preview.
Reporting a message deliberately discloses that message and its proof to the service. The service verifies its commitment and the tag it assigned when accepting the message, and refuses the report when either does not match. On 3 November the dev proof filed a genuine report, which was accepted with its sealed evidence stored, and a tampered one, which was refused. Unreported message content remains unavailable to the service.
Recovery will back up the epoch-key ring under a separate backup key. The device signing identity is never backed up. Platform encrypted key sync or a saved recovery code will restore history on a replacement install; the replacement registers a new device identity.
What the server sees#
The proposed readable envelope includes conversation and message ids, sender user and device, times, message kind, reply links, mentions, epoch, content version, commitments, tags and attached-object storage keys. Membership, reactions, poll votes, read and delivery receipts, typing, presence, group names and profile information remain readable.
System messages and fixed server-authored prompts remain readable. A message explicitly addressed to the bot will be shared with it after an application notice; the bot will receive only that message. User-written text, captions, poll questions, file details and Circle free-text answers belong inside ciphertext.
What it improves#
| Usual approach | What goes wrong | Proposed Reaktor behavior |
|---|---|---|
| Store message bodies in the service database | Database and backup readers can read conversations | Devices seal content before publishing |
| Advance native state before storing a commit | Concurrent commits can fork a group | Stage changes until the server accepts their epoch |
| Use a separate notification-process MLS state | Processes can advance the same ratchet independently | Open previews with an epoch-key ring |
| Introduce encryption without recovery | Reinstallation makes history unreadable | Qualify recovery before general activation |
| Let the encryption module define product membership | Security membership can diverge from chat membership | The application supplies conversation authority |
Limitations#
Existing chats retain their current format. The dev pilot can seal text in allowlisted chats; general activation is still disabled. The target architecture does not protect against malware on a recipient device, access to an unlocked device, traffic analysis, or an auth server that fraudulently issues device credentials. Device lists, visible key changes and later safety numbers will help users inspect the last case.
Existing plaintext messages will remain readable by the service after activation. The proposed migration affects new messages. Servers retain the metadata listed above, and reported content is intentionally disclosed.
Android and iOS bindings and secret-box implementations compile. Both physical phones passed direct and three-member group text flows, including fresh messages, receipt and restart/history. The native third member authenticated the iPhone reply and reopened history after restart. SQL verified ciphertext-only storage for five fresh messages. The earlier Android group trace reached the live service, ClickHouse and Hangar; missing server application, installation and platform labels leave that trace partial, and native performance budgets remain unqualified. Web compilation and recovery still require implementation. Sealed notification previews are implemented but have not been checked on a locked phone. On the iPhone, opening an encrypted chat with a long history took about 70 seconds. Client telemetry rebuilt the whole app graph on the main thread for each recorded span, and the device's security state was saved after every opened message. With telemetry trying each graph once and opened messages sharing protected writes, the same chat opened in about 10 seconds. The pilot checkpoint does not establish general application privacy.
Reference#
Source and wire boundary#
The framework source lives in reaktor-security. src/commonMain/cpp/MlsEngine.cpp owns the native engine, src/commonMain/cpp/include/rsec/rsec.h owns the C ABI, and src/commonTest/cpp/ owns its GoogleTests. Dependency revisions and licenses are recorded in THIRD_PARTY_LOCK.md.
ABI version 2 exposes durable state, pending commits, verified credentials, authoritative rosters, external joins, exporter-based sealing, attachments, storage sealing and a key-ring-only reader. Returned buffers belong to the caller and must be released with rsec_buffer_free; exceptions become stable status codes. Legacy constructors remain for compatibility and must not be used by the product. FFI describes how specialist native ABIs fit the framework.
The common API provides the graph-owned SecurityNode, ReaktorSecurity, SecureDirectoryApi and a native read-only key-ring reader. Platform secret boxes seal local state before storage. The dev schema contains security_devices, security_key_packages, security_commits, security_welcomes and security_key_backups. A three-epoch migration fixture verifies historical roster backfill and repeat application. The directory is deployed in dev and the two-process live proof passed. Production SQL and application activation remain separate delivery steps.
Device credential format#
The credential is a canonical binary record, separate from the user's sign-in token. Integers use network byte order. Every length-prefixed field is a nonempty byte sequence with a 32-bit length, bounded to 4096 bytes. Identifiers use printable ASCII without spaces; the full record is bounded to 32768 bytes. The fields, in order, are:
- Magic
RSC1and a 16-bit version1. - Length-prefixed tenant id, application id, user id, device id and MLS signature public key.
- A 16-bit cipher-suite count followed by one to three distinct, increasing 16-bit suite ids from
1,2and3. - Creation and expiry times as unsigned 64-bit Unix milliseconds, followed by the length-prefixed auth key id.
- A 64-byte ES256 signature, encoded as fixed-width
rfollowed bys, over the SHA-256 digest of all preceding bytes.
Pinned auth public keys are 65-byte uncompressed P-256 points. Verification requires created <= now < expires and a lifetime of at most 366 days. Unknown keys, noncanonical encodings and trailing bytes fail. Auth issuance and native verification are implemented and tested together. Credential renewal remains a later phase.
Delivery checkpoints#
| Phase | Acceptance | Current status |
|---|---|---|
| P0: groundwork | Pinned BoringSSL host tests, auth separated, credentialed media reader, live design page | In progress |
| P1: durable engine | Restart, history, membership, pending commits, tamper checks and JVM binding | 42 native tests and five JVM scenarios passed; design documentation is live |
| P2: directory | Two JVM devices exchange ciphertext through dev services | Live two-process proof passed again on 3 November against freshly deployed dev services: ciphertext-only database rows, two conflicting commits, two process restarts and reopened history |
| P3: phone pilot | Direct and group chats survive restart on both physical phones | Both physical phones passed 26-step direct, 21-step receive and 29-step group flows. Five fresh SQL rows are ciphertext-only; the native third member authenticated the iPhone reply and reopened history. R21 security checks passed 27 tests. Native performance budgets and complete telemetry labels remain unqualified |
| P4: content and safety | All content types, locked-phone previews and verified reports | Implemented. On 3 November the Android phone passed the poll, voice note, file and BestBud share flows on dev, the iPhone passed the poll, voice note, file, sticker and photo, and BestBud share flows, and the two-JVM proof's genuine report was accepted and its tampered report refused. Open: the reply, edit and delete flow on both phones, the sticker and photo flow on Android, two-phone exchanges, locked-phone previews and native Android timings |
| P5: web | Browser and phone exchange messages; browser history survives reload | Not implemented |
| P6: recovery | Reinstallation restores history; revoked devices lose new messages | Not implemented |
| P7: general activation | Capability-gated rollout, telemetry and disclosures, with owner approval | Not implemented |
| P8: hardening | Safety numbers, sealed cache, fuzzing and external review | Not implemented |
Protocol references: MLS, RFC 9420 and SFrame, RFC 9605.