Skip to content

net, ariadne: end-to-end encrypted DMs with the keys in the host (TX.WTF's X3DH + Double Ratchet) - #1191

Merged
transfix merged 6 commits into
masterfrom
feat/e2ee-host
Nov 15, 2026
Merged

transfix merged 6 commits into
masterfrom
feat/e2ee-host

Conversation

@transfix

@transfix transfix commented Nov 12, 2026 •

Copy link
Copy Markdown
Owner

End-to-end encrypted TX.WTF DMs, with every key held by the host.

  • The crypto: cvc::net::E2eeStore is TX.WTF's client crypto ported to C++ over libsodium, byte for byte. The originals are atx-crypto-club/txwtf txwtf/static/js/e2ee.js and messaging-e2ee.js.
  • For documents: the new e2ee-* Ariadne verbs put it in front of documents, by handle, as the credential store does with names. A document such as nicotina gives them what the server sent, gets back what to send, and never holds a key.

Design: docs/E2EE.md. Verbs: docs/ARIADNE.md §10.8. libsodium comes from cy-pca/cvcpkg#612, published 2026-11-12.

What's in it

  • inc/cvc/net/e2ee.h, src/cvc/net/e2ee.cpp: the store and the crypto.
    • X3DH from a prekey bundle.
    • A Double Ratchet per message: X25519, BLAKE2b root and chain KDFs, XChaCha20-Poly1305.
    • A random content key per body, wrapped through the ratchet with the body as AD.
    • grp-dr-v1 group fan-out, and the Argon2id passphrase backup.
    • The API takes and gives public keys, ciphertext and plaintext only. It holds the state in messaging-e2ee.js's own key-store layout (identity, session:<ref>, pt:<id>).
  • The file:
    • owner-only (0600 in 0700), as the credential store's;
    • replaced whole on every change, before the call that made it returns;
    • locked to one process: <file>.lock, through flock or LockFileEx. Two writers would fork a ratchet.
  • inc/cvc/ariadne/e2ee_intrinsics.h: the verbs. The plain ones are e2ee-status, -identity, -create, -prekeys, -forget, -session?, -seal, -seal-group, -sent, -open and -fingerprint; e2ee-backup and -restore are async, for Argon2id's second. They make no requests: the document posts what they give it with http-request.
  • --e2ee-store SPEC comes through host_cli, NetHostConfig::e2ee_store and enable_net, then enable_e2ee.
    • No new process-wide state: the store lives in the app (app.slot<E2eeHost>).
    • When it can't open, the verbs stay out and (e2ee-status) says why: no libsodium, a browser, another process holding it. The host runs on.
  • src/cvc/net/private_file.{h,cpp}: the credential store's config dir and its owner-only write and check, now shared with the E2EE store. Its messages are unchanged; net_policy_test passes.
  • CMake: find_package(sodium CONFIG) (cvcpkg's sodium::sodium), else a system libsodium by header and library. CVC_HAVE_SODIUM is set only when it is found; without it e2ee_available() is false and the verbs are absent. cvcConfig.cmake recreates the target for a static cvc.
  • wasm and wasm-mt: randomness is getentropy(). libsodium's own JS source throws on a pthread (Module.getRandomValue is not a function; it is set up per thread).
    • The crypto compiles for both flavours against cvcpkg#612's local bundles.
    • The store refuses to open in a browser for now. The design note has the IDBFS plan.

Where it is safer than e2ee.js, on the same wire

  • e2ee.js advances the ratchet before it authenticates. A forged message with a fresh dh (the server is untrusted by TX.WTF's own threat model) runs a DH step and then fails. After that every later genuine message of the page load fails too, and on each reload the forged message replays first. Here decryption works on a copy and keeps it only once the message opened: E2eeStore.AForgedRatchetKeyChangesNothing.
  • e2ee.js deletes a skipped key before trying it. Here a skipped key is spent only on success.
  • Headers are checked before anything is derived: 32-byte dh, counters under 2^31.
  • What it keeps is bounded. Skipped keys (2000 a session), cached plaintext (10000 a handle), and a backup's Argon2id limits (a hostile blob can't ask for a terabyte).
  • No error quotes key material. The vector test scans every error for every secret.

The first two are worth reporting to txwtf.

Interop with e2ee.js

1. Vectors, byte for byte (e2ee_test, E2eeVectors.*).

  • tools/e2ee/txwtf_vectors.js runs txwtf's unmodified e2ee.js and messaging-e2ee.js with libsodium-wrappers-sumo 0.7.15, the build the TX.WTF page loads. It runs three users through a stand-in server, with every random draw from a seeded BLAKE2b stream, and writes src/cvc/tests/data/e2ee/txwtf_vectors.json.
  • It covers ten sends and twelve opens: out of order, two ratchet turns each way, a session without a one-time key, a group message each way, two tampered copies, and a backup.
  • The replay draws from the same streams. Every published bundle, body, wrapped key, ratchet header and X3DH envelope matches e2ee.js's byte for byte, and so does the backup blob. Every message opens, and the stores end holding exactly what e2ee.js's stores hold.
[ RUN      ] E2eeVectors.TheTranscriptOfTxwtfsClientReplaysByteForByte
[       OK ] E2eeVectors.TheTranscriptOfTxwtfsClientReplaysByteForByte (167 ms)
[       OK ] E2eeVectors.AStateFromTxwtfsStoreCarriesOn (10 ms)
[       OK ] E2eeVectors.BackupsAreTxwtfs (5055 ms)

2. Live, with the system's randomness (tools/e2ee/interop.sh). C++ seals, e2ee.js opens and replies, C++ opens the replies:

== 1. C++ seals for jill
wrote .../native.json: 3 messages sealed here, for e2ee.js to open
== 2. e2ee.js opens and replies
e2ee.js opened #501: "hello from C++"
e2ee.js opened #502: "second, with ünïcödé and 🔒"
e2ee.js opened #503: "third: \"quotes\" \\ and a\nnewline"
e2ee.js sealed #900: "hi carl, from e2ee.js"
e2ee.js sealed #901: "and once more, ✓"
== 3. C++ opens e2ee.js's replies
opened e2ee.js's reply #900: hi carl, from e2ee.js
opened e2ee.js's reply #901: and once more, ✓

3. Through nicotina (cy-pca/nicotina#28's tests/e2ee.sh, with Linux ari built from this branch). nicotina talks to TX.WTF's e2ee.js through the stub instance. The host opened e2ee.js's message, sealed nicotina's typed answer, and e2ee.js opened it: 13 passed, 0 failed.

90000 4 ok Hello Ada, sealed by TX.WTF's own e2ee.js. ✓
90001 1 ok Hi Mary, sealed by nicotina's host.

Tests

  • e2ee_test:
    • the vectors above;
    • a forged ratchet key changes nothing;
    • another device's messages say so (no-session, and a missing one-time prekey);
    • more than MAX_SKIP ahead is refused, and the session survives;
    • the file is owner-only, locked (a second store is "in use by another process"), and kept across a restart;
    • names and fingerprints;
    • E2eeInterop.*, which runs only under tools/e2ee/interop.sh.
  • ariadne_e2ee_test:
    • a document seals and opens with the verbs, and no secret reaches the state tree;
    • backup and restore through the async verbs;
    • a store in use leaves the verbs out, and (e2ee-status) says why.

Local runs:

where result
Windows, MSVC 14.44, cvcpkg#612's libsodium DLL e2ee_test 8 passed (1 skipped: the interop case), ariadne_e2ee_test 3 passed, net_policy_test 25 passed, ariadne_host_test 57 passed; interop.sh as above
Windows, no libsodium (/Zs of e2ee.cpp, e2ee_intrinsics.cpp) compiles
emsdk, wasm and wasm-mt (-fsyntax-only -Wall -Wextra of e2ee.cpp) compiles, no warnings
emsdk, the published libsodium 1.0.22+cvc.1 wasm and wasm-mt bundles (-fsyntax-only, CVC_HAVE_SODIUM) e2ee.cpp and private_file.cpp compile for both; e2ee_intrinsics.cpp for wasm-mt (single-threaded stops in this box's boost/thread, before any E2EE code)
Linux (WSL Ubuntu 22.04, gcc 11, deps from cvcpkg install-deps cvcpkg/recipes/libcvc, #612's libsodium) e2ee_test 8 passed (1 skipped), ariadne_e2ee_test 3, net_policy_test 27, ari_net_test 12 (ARI_BINARY set); interop.sh as above; every changed TU -Wall -Wextra clean (it caught a missing <sys/stat.h>); the writable-data scan finds nothing new

clang-format 18 is clean on the changed lines.

libsodium

  • Published: feat(recipes): libsodium 1.0.22 on linux, macos, windows, wasm and wasm-mt cy-pca/cvcpkg#612 merged, and Joe OK'd the publish. libsodium 1.0.22+cvc.1 is in the catalog for:
    • linux x86_64 and arm64;
    • macos arm64 and x86_64;
    • windows x86_64;
    • wasm and wasm-mt (static).
  • In the recipe: 0c8e65d adds it to cvcpkg/recipes/libcvc (depends.runtime, for linux, macos, windows, wasm and wasm-mt). The recipe jobs now build with CVC_HAVE_SODIUM on, and the E2EE tests run there.
    • That gives ari and arigl the verbs. arisrv doesn't go through the shared net host, so it doesn't.
    • ci.yml's wasm jobs list their own deps and don't install libsodium, so they build without it, as before.
  • Still Joe's call: a libcvc release, so that nicotina's packaged hosts get --e2ee-store.

…WTF's X3DH + Double Ratchet)

cvc::net::E2eeStore (inc/cvc/net/e2ee.h) ports TX.WTF's client crypto to C++ over libsodium,
byte for byte: atx-crypto-club/txwtf txwtf/static/js/e2ee.js and messaging-e2ee.js. That is:
- X3DH from a prekey bundle;
- a Double Ratchet per message (X25519, BLAKE2b KDFs, XChaCha20-Poly1305);
- a random content key per body, wrapped through the ratchet;
- grp-dr-v1 group fan-out;
- the Argon2id passphrase backup.

The store holds every secret: identities, prekeys, sessions, and a cache of opened plaintext.
Its API gives and takes public keys, ciphertext and plaintext only. Persistence:
- With a file it is owner-only (0600 in 0700), replaced whole on every change before the call
  returns, and locked to one process (<file>.lock: flock / LockFileEx).
- Without one it lives in memory.
Its state is in messaging-e2ee.js's own key-store layout.

The e2ee-* verbs (inc/cvc/ariadne/e2ee_intrinsics.h, ARIADNE.md §10.8) put it in front of
documents, by handle, as the credential store's names work. A document gives them what the server
sent and gets back what to send, and never holds a key.
- --e2ee-store SPEC (host_cli; NetHostConfig::e2ee_store; enable_net -> enable_e2ee) opens it.
- The store lives in the app (app.slot), not the process.
- A store that cannot open leaves the verbs out, and (e2ee-status) says why: no libsodium, a
  browser, another process holding it. The host still runs.
- e2ee-backup and e2ee-restore are async, for Argon2id's second.

Where it is safer than e2ee.js, on the same wire:
- Decrypting is transactional. e2ee.js runs a DH ratchet step before authenticating, so one
  forged message with a fresh ratchet key breaks the session.
- A skipped key is spent only once it opened its message.
- Headers are checked before anything is derived.
- Skipped keys, cached plaintext and a backup's Argon2id limits are bounded.

On wasm the randomness is getentropy(): libsodium's own JS source throws on a pthread.

libsodium is optional: find_package(sodium) (cvcpkg's libsodium, cy-pca/cvcpkg#612), else a
system one by header and library. Without it e2ee_available() is false. The libcvc recipe gains
the dependency once the libsodium bundles are published.

private_file.{h,cpp}: the credential store's config_dir and owner-only write and check, now
shared with the E2EE store; the messages are unchanged.

Tests:
- e2ee_test replays src/cvc/tests/data/e2ee/txwtf_vectors.json. tools/e2ee/txwtf_vectors.js
  wrote it by running txwtf's unmodified e2ee.js (libsodium-wrappers-sumo 0.7.15) for three
  users with seeded randomness: ten sends, twelve opens (out of order, ratchet turns, no
  one-time key, groups), tampered copies, and a backup.
  - Every bundle, body, wrapped key, header, envelope and backup blob comes out byte for byte the
    same.
  - Every message opens.
  - The final stores equal e2ee.js's.
- e2ee_test also checks: a forged ratchet key changes nothing; other-device messages say so;
  MAX_SKIP; the file is owner-only, locked, and survives a restart.
- ariadne_e2ee_test runs the verbs in a document, with no secret in the state tree; a backup and
  restore through the async verbs; and a locked store reported by (e2ee-status).
- tools/e2ee/interop.sh is a live round trip with e2ee.js: C++ seals, e2ee.js opens and replies,
  C++ opens the replies.
…e E2EE

libsodium 1.0.22+cvc.1 is in the catalog for linux (x86_64, arm64), macos (arm64, x86_64), windows,
wasm and wasm-mt (cy-pca/cvcpkg#612). With it CVC_HAVE_SODIUM is on and ari, arigl and arisrv get
the e2ee-* verbs and --e2ee-store; without it they build as before, with no verbs.
transfix added a commit to cy-pca/nicotina that referenced this pull request Nov 12, 2026
…d by the host (#28)

The TX.WTF window gets DMs, the bar's last button (✉ in ImGui; also the menu's Messages): the
conversations, latest first, and a conversation's last 30 messages with a box that sends.
Message on someone's profile opens or starts the conversation with them, and a plaintext
conversation can be encrypted, one-way as in the web app.

End-to-end encrypted conversations are sealed and opened by the host, which keeps the keys as it
keeps the session token: TX.WTF's X3DH + Double Ratchet through libcvc's e2ee-* verbs
(transfix/libcvc#1191, over cy-pca/cvcpkg#612's libsodium). The document names the account's
handle and posts what the host gives it, and never holds a key.

- The launcher passes --e2ee-store to a host whose --help lists it; NICOTINA_E2EE=0 leaves it out.
- DMs backs the keys up under a passphrase (Argon2id), restores them, and makes new ones.
- A conversation whose session another device holds says so and has no box.
- On a host without the verbs, encrypted conversations show locked, with the reason.

DMs is the words bar's eighth stop, so every tmux count past the bar counts one more, in run.sh
and local.sh, main's Admin walkthroughs included. The words bar's unread count is a bare number,
so the row fits 80x24. The stub gains the DM API and the E2EE key directory and message store,
ciphertext only. tests/e2ee.sh runs TX.WTF's own e2ee.js as the other side against a host that
keeps keys; without a libcvc#1191 host, node and a txwtf checkout it skips.
@transfix
transfix enabled auto-merge (squash) November 13, 2026 03:54
… check requires

net_host.cpp: master's register_http_uri_handler(app, policy) beside enable_e2ee.
…ction

#1203 turned state_exec's nil_value, true_value and false_value from constants into functions.
`k ? keys_value(*k) : se::nil_value` still compiled: the function's address converts to a bool,
so (e2ee-identity) with no identity, and five more nil results, came back true.
ariadne_e2ee_test caught it after the master merge (ui.dm.none was "some").

se::value_t() is nil on master and on release/3.x alike, so the code stays the same on both.
@transfix
transfix merged commit e22f1f8 into master Nov 15, 2026
28 checks passed
@transfix
transfix deleted the feat/e2ee-host branch November 15, 2026 05:21
transfix added a commit that referenced this pull request Nov 15, 2026
- app_runtime.cpp: the constructor hands the scene its repeat: count function (#1230), then
  takes the verb table's lock as before.
- e2ee_intrinsics.cpp (#1191): the e2ee-* provider registers its async functions on the calling
  program's host (*ictx.host, else the app's), as every provider on this branch does (B30), so an
  isolated document's e2ee-backup and e2ee-restore park on its own group.
- STATE_EXEC_THREADED.md: the e2ee provider in the provider table and the file list.
transfix added a commit that referenced this pull request Nov 15, 2026
No conflicts. Master brings 26 commits (#1171, #1191, #1221, #1236,
#1245, #1248, #1250 and others); none adds a writable global, a function
static or a signal handler to the hosts or examples, and none touches
the allowlist.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant