End-to-end encryption for tunneled connections

When the web console or the mobile and desktop apps reach devctrl through a public tunnel (Cloudflare, ngrok, localhost.run, Tailscale Funnel, a reverse proxy), the tunnel terminates TLS and can read every request, response and terminal byte. End-to-end encryption adds a second, independent encryption layer between the client and the devctrl web gateway, so the tunnel and every proxy between them relay only ciphertext.

The feature is optional. An administrator can make it mandatory for remote connections; local connections stay unaffected unless configured.

How it works

  1. Core (the controller) holds a server static key pair (X25519). Its private half is kept in Core's encrypted credential store; only the colocated web gateway can read it, through the launcher-only route GET /v1/server/e2e/gateway (operator token, launcher header and a private infrastructure peer address are all required, and the gateway refuses to proxy that route for browsers).
  2. Each device or user gets a client key pair (X25519). Core stores only its public key, its fingerprint, its owner and a label.
  3. The device receives a pairing code, dce2e1.<client private key>.<server public key>. The user pastes it once in the web or mobile client (Console → End-to-end encryption). The client imports the private key as a non-extractable CryptoKey and keeps it in IndexedDB, and pins the server public key. Pairing completes only after a successful handshake with that server key.
  4. While an origin is paired, every request and WebSocket of that console goes through one WebSocket to /e2e/channel, protected as described below. The gateway decrypts each request and replays it against its own listener on the loopback interface, tagged with a per-process secret, so the existing sign-in, Origin, ticket and ownership checks apply unchanged. Plain HTTP API calls are therefore covered: the console API is tunneled over the encrypted WebSocket.

Handshake: Noise IK

The channel uses the standard Noise Protocol Framework pattern Noise_IK_25519_AESGCM_SHA256, unmodified:

<- s
...
-> e, es, s, ss
<- e, ee, se

"Another key pair for the reverse direction"

The request was to use a separate key pair for the reverse direction. Noise's Split() already gives each connection two independent AES-256-GCM keys, one for client→server and one for server→client, each with its own nonce counter. A second long-term key pair would add nothing: the per-direction keys are derived fresh for every connection from ephemeral keys, so the two directions never share a key and a compromise of one connection does not expose another.

Message protection

Primitives and libraries

Purpose Primitive Browser and Node Fallback
Key agreement X25519 WebCrypto X25519 @noble/curves 2.0.1
AEAD AES-256-GCM WebCrypto AES-GCM @noble/ciphers 2.0.1
Hash, HKDF SHA-256, HMAC-SHA-256 WebCrypto @noble/hashes 2.0.1

WebCrypto is used whenever the runtime supports X25519 end to end. Older browsers and web views fall back to the pinned, independently audited noble packages; with the fallback the private key is stored as raw bytes in IndexedDB instead of a non-extractable CryptoKey. The implementation is checked byte for byte against vectors produced by the independent Python noiseprotocol implementation (apps/tui/web/e2e-noise.test.ts).

Generate and pair a key

Over SSH on the server, or wherever devctl reaches Core:

./devctl e2e status                        # server fingerprint, policy, keys
./devctl e2e keygen --label "Anna phone"   # key pair made here; only the public key goes to Core

keygen prints the device's pairing code (secret), its key fingerprint and the server fingerprint. Paste the code on the device, then clear your terminal scrollback. Variants:

Generating a key for another user (--user, or the settings screen) hands over that user's private key, so only the installation operator may do it; any other administrator, and every user, generates only their own key and is refused (403, audited as e2e.key.generate-refused) otherwise. The same applies to rotating another user's key. Administrators may still register a public key for another user, and list or revoke other users' keys; users manage only their own keys. A key belongs to one user: a channel opened with Alice's key cannot sign in as Bob.

On the device, open Console → End-to-end encryption, paste the code and compare the server fingerprint with the one shown by devctl e2e status or in Settings. The header badge shows the server fingerprint while the console is paired.

Rotation and revocation

Action Command Settings key Audit event
Register a public key devctl e2e register / keygen — e2e.key.registered
Generate a key on Core devctl e2e generate g e2e.key.generated
Rotate a key (new code, old key revoked) devctl e2e rotate KEY_ID, keygen --replace KEY_ID r e2e.key.rotated
Revoke a key devctl e2e revoke KEY_ID --confirm x, x e2e.key.revoked
Replace the server key (all devices pair again) devctl e2e server-key rotate --confirm S, S e2e.server-key.rotated

The gateway reloads Core's registry every ten seconds and immediately after a key change made through it. Revoking or rotating a key, disabling its user or replacing the server key closes the affected live channels. Revoked keys remain listed with their fingerprints for review. Fingerprints are the first 128 bits of the SHA-256 of the raw public key, shown as eight groups of four hexadecimal digits; the key ID is the first 24 hexadecimal digits.

Policy

Setting Who Effect
optional (default) administrator Paired clients encrypt; plaintext stays allowed.
required administrator Core's gateway refuses plaintext remote requests and upgrades.
LAN included administrator Applies required to private-network peers as well.
My preference each user Refuses that user's plaintext remote requests after sign-in, regardless of the installation policy.

devctl e2e policy required [--lan|--no-lan], devctl e2e prefer required|optional, or m, l and u in Settings. Changes are audited as e2e.policy.updated and e2e.preference.updated.

A plain request is local when it comes from loopback with a loopback Host and no proxy headers; LAN when it comes from a private address without proxy headers; otherwise remote. Tunnel connectors run beside the gateway and connect from loopback, so the public Host or the forwarding headers they add (X-Forwarded-For, CF-Connecting-IP, Forwarded and similar) mark their requests remote. An SSH port forward stays local. In container installs the Docker host reaches a published port from a private bridge address, so including LAN also covers browsers on the Docker host itself.

With required, remote plaintext is refused (403, code: E2E_REQUIRED, X-Devctl-E2E: required) except for:

If the gateway has never been able to read Core's policy, remote plaintext is refused with 503 E2E_POLICY_UNAVAILABLE (fail closed). A controller without this feature (404) leaves everything as before.

Threat model

What the tunnel or proxy can no longer see

What it can still see (metadata)

What it can still do

Not in scope

Limitations