Repository navigation
refactor(remote): one paired E2EE handshake core for desktop, CLI, web and mobile clients - #27523
Conversation
67037eb to
de51381
Compare
…b and mobile clients Every paired client now builds its hello, checks the host's ready, seals its auth frame and opens host frames through src/shared/paired-e2ee-client-handshake. Platforms inject their own NaCl/base64 primitives. The v2 client session and its pure-JS key schedule (@noble/hashes 1.8.0, the version mobile pins) move to src/shared, and the per-host v2 latch policy is shared with an injected store. No wire change: frames match the captured legacy and v2 fixtures byte for byte, and a cross-version test drives the core against the released host and the released client against this host. The auth step is now async so a device-key signer can slot in later.
The packaged CLI loads src/shared output from disk, so a bare @noble/hashes import failed the packaged-runtime check. The v2 key schedule is now a primitive: Node clients use the node:crypto schedule (moved to src/shared so the CLI can reach it), while the browser and phone keep the pure-JS one.
The auth step is async, so another socket can latch the host to v2 while a legacy auth frame is being sealed. Refuse it at send time, as before.
de51381 to
1eb704a
Compare
📝 Walkthrough
Priority: ➖ Normal Merge Risk: 🔵 Low · up to The handshake refactor appears consistent across clients. A test helper encrypts the auth frame with a different key than the rest of the session, which could confuse future tests. Production behavior is not affected. The change is mergeable, with this fixture as a small follow-up. Pre-merge checks |
|
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/shared/paired-e2ee-fixed-key-test-fixture.ts (1)
13-20: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winMake
sealAuthuse the same fixed key aschannel.The fixture replaces only
channel. The spreadsealAuthstill closes over the legacy channel thatcreateLegacyHandshakebuilt. That channel uses the ECDH key from the dummy host key (Buffer.alloc(32, 9)), notsharedKey. The result is thatsealAuthseals the auth frame with a different key thanchannel.sealText.Current tests pass because the fake hosts do not decrypt the auth frame. A future test that opens the auth frame with
sharedKeywill fail, and the cause will be hard to find. OverridesealAuthso it also seals through the fixed-key channel.♻️ Proposed fix
export function createFixedKeyLegacyHandshakeForTest( sharedKey: Uint8Array ): PairedE2EEClientHandshake { + const channel = createPairedE2EELegacyChannel(NODE_PAIRED_E2EE_PRIMITIVES, sharedKey) return { ...createPairedE2EEClientHandshake({ primitives: NODE_PAIRED_E2EE_PRIMITIVES, hostPublicKeyB64: Buffer.alloc(32, 9).toString('base64'), framing: 'legacy' }), - channel: createPairedE2EELegacyChannel(NODE_PAIRED_E2EE_PRIMITIVES, sharedKey) + channel, + sealAuth: async (credential, options) => + channel.sealText( + JSON.stringify({ + type: 'e2ee_auth', + deviceToken: credential.deviceToken, + ...(options?.clientCapabilities ? { clientCapabilities: options.clientCapabilities } : {}) + }) + ) } }
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
3bbf15ac-d872-4143-88ee-6d6cef6ea4d8
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (68)
mobile/src/transport/cellular-connecting-label-stall.test.tsmobile/src/transport/direct-e2ee-framing-policy.tsmobile/src/transport/direct-socket-framing.test.tsmobile/src/transport/direct-socket-framing.tsmobile/src/transport/e2ee.tsmobile/src/transport/legacy-direct-framing-test-policy.tsmobile/src/transport/mobile-e2ee-v2-client-session.test.tsmobile/src/transport/mobile-e2ee-v2-client-session.tsmobile/src/transport/mobile-e2ee-v2-key-schedule.test.tsmobile/src/transport/mobile-e2ee-v2-physical-channel.test.tsmobile/src/transport/mobile-e2ee-v2-physical-channel.tsmobile/src/transport/mobile-paired-e2ee-primitives.tsmobile/src/transport/rpc-client-socket-factory.tsmobile/src/transport/rpc-client-socket-session.tsmobile/tsconfig.jsonpackage.jsonsrc/main/runtime/relay/simulated-mobile-e2ee-v2-peer.tssrc/main/runtime/rpc/e2ee-channel-v2.test.tssrc/main/runtime/rpc/mobile-e2ee-v2-desktop-session.test.tssrc/main/runtime/rpc/mobile-e2ee-v2-desktop-session.tssrc/main/runtime/rpc/mobile-socket-wiring.test.tssrc/renderer/src/runtime/paired-host-client-capabilities.test.tssrc/renderer/src/web/web-paired-e2ee-primitives.tssrc/renderer/src/web/web-runtime-client-file-watch-replay.test.tssrc/renderer/src/web/web-runtime-client-heartbeat.test.tssrc/renderer/src/web/web-runtime-client.test.tssrc/renderer/src/web/web-runtime-client.tssrc/renderer/src/web/web-runtime-connection-frame-router.test.tssrc/renderer/src/web/web-runtime-connection-frame-router.tssrc/renderer/src/web/web-runtime-connection-transport.tssrc/shared/e2ee-crypto.tssrc/shared/mobile-e2ee-v2-framing.tssrc/shared/mobile-e2ee-v2-node-key-schedule.test.tssrc/shared/mobile-e2ee-v2-node-key-schedule.tssrc/shared/paired-e2ee-client-handshake.test.tssrc/shared/paired-e2ee-client-handshake.tssrc/shared/paired-e2ee-fixed-key-test-fixture.tssrc/shared/paired-e2ee-framing-policy.tssrc/shared/paired-e2ee-node-primitives.tssrc/shared/paired-e2ee-primitives.tssrc/shared/paired-e2ee-v2-client-session.tssrc/shared/paired-e2ee-v2-key-schedule.tssrc/shared/remote-runtime-client-handshake.tssrc/shared/remote-runtime-passthrough-socket.tssrc/shared/remote-runtime-request-connection-stale.test.tssrc/shared/remote-runtime-request-connection.tssrc/shared/remote-runtime-request-frames.test.tssrc/shared/remote-runtime-request-frames.tssrc/shared/remote-runtime-request-response-router.test.tssrc/shared/remote-runtime-request-response-router.tssrc/shared/remote-runtime-request-socket.tssrc/shared/remote-runtime-request-websocket.tssrc/shared/remote-runtime-shared-control-connection-actions.tssrc/shared/remote-runtime-shared-control-connection-frame.tssrc/shared/remote-runtime-shared-control-connection.test.tssrc/shared/remote-runtime-shared-control-connection.tssrc/shared/remote-runtime-shared-control-frame-handler.tssrc/shared/remote-runtime-shared-control-open.tssrc/shared/remote-runtime-shared-control-protocol.tssrc/shared/remote-runtime-shared-control-ready-wait.tssrc/shared/remote-runtime-shared-control-ready.tssrc/shared/remote-runtime-subscription-frame-router.test.tssrc/shared/remote-runtime-subscription-frame-router.tssrc/shared/remote-runtime-subscription-request-channel.tssrc/shared/remote-runtime-subscription-transport.tssrc/shared/remote-runtime-transport-error-agreement.test.tstests/e2e/cross-version-wire/cross-version-mobile-direct-e2ee-v2.unit.test.tstests/e2e/cross-version-wire/cross-version-paired-e2ee-handshake-core.unit.test.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 4 remain after this review.
ELI5
Every Orca app that talks to a paired host (the desktop app, the
orcacommand line, the browser client and the phone) opens an encrypted connection with the same three steps: say hello, check the host's answer, then prove which device it is. Each app had its own copy of those steps, six copies in all. This PR replaces the copies with one shared piece of code. Nothing the user sees changes, and the bytes on the wire stay exactly the same.What Changed
src/shared/paired-e2ee-client-handshake.ts, which owns:sealText/openText/sealBinary/openBinary) that callers hold instead of a raw shared key.src/shared. The v2 key schedule is passed in like the other primitives: desktop and CLI use the existingnode:cryptoschedule (moved fromsrc/maintosrc/shared/mobile-e2ee-v2-node-key-schedule.tsso the CLI can reach it), while the browser and phone use a pure-JS schedule on@noble/[email protected](the version the phone already pins). The browser one works on plainhttp://<lan-ip>, where WebCrypto is missing.@noble/hashesis a dev dependency, bundled into the web client only. The packaged CLI never loads it.src/shared/paired-e2ee-framing-policy.ts; the phone still stores the latch in its own storage.async. Callers re-check that the socket is still the current one before sending the auth frame.Desktop, CLI and web still connect with the legacy framing and the same auth fields. Switching them to v2 is later work.
Why
The next steps of the pairing work add per-device keys for the browser and then the desktop and CLI. Those keys sign the v2 handshake, and a browser's key can only sign asynchronously. Adding that to six hand-written handshakes would mean six chances to get the security check wrong. One core keeps the check in one place and lets later changes stay small. Each platform injects its own primitives instead of the core importing them, because the browser has no
Bufferand the phone needs its own typed-array handling.The alternative was to switch every client to v2 in the same PR. That would change the wire and mix a refactor with a protocol change, so it is left for later.
Linked Issue
Part of #17394 (prepares for device-key auth). No user-visible fix on its own.
Visual Proof
N/A: no UI or behaviour change. The wire bytes are pinned by fixture tests.
Testing
src/shared/paired-e2ee-client-handshake.test.ts: the core writes the captured legacy hello, auth and binary frames byte for byte (mobile-e2ee-legacy-fixtures.ts). It writes the normative v2 hello and derives the vector transcript (mobile-e2ee-v2-fixtures.ts). It refuses a legacy hello, ready or auth once the host is latched to v2. It rejects a v2 "authenticated" reply that does not echo the transcript.src/shared/mobile-e2ee-v2-node-key-schedule.test.ts: the pure-JS key schedule matches thenode:cryptoone across fresh nonces.Cross-version (
tests/e2e/cross-version-wire/cross-version-paired-e2ee-handshake-core.unit.test.ts, run against the latest release tag):The existing transport suites (request, subscription, shared control, passthrough, web, phone direct and relay) pass. Tests that injected a raw shared key now inject a fixed-key handshake.
pnpm tc, mobiletsc, oxlint,pnpm run check:code-quality:changed,pnpm lint.Automated tests added/updated
Review
P0/P1 review by the author, plus an independent adversarial review.
Agent skill upstream boundary
Notes
@noble/hashesfromsrc/shared, the same way it already importstweetnaclthere.mobile/tsconfig.jsonmaps it to the phone's own copy, as it does fortweetnacl.Checklist
N/Afor visuals, with reason