feat(relay): rendezvous-relay service — 7 packages + plans (contracts/transport/agent/control-plane/e2e/auth/web)

Multi-tenant reverse-tunnel service ("ngrok for Claude Code" with E2E): a
host-agent dials OUT to an operator-run relay; external devices reach the host
THROUGH the relay, routed by per-tenant subdomain, forwarding ciphertext only
(the relay never sees plaintext). Lets a customer reach their own self-hosted
web-terminal from anywhere with zero networking setup.

Packages — all tsc-strict + vitest green (656 tests), cross-package integration verified:
- relay-contracts: frozen shared contracts (mux frame codec, data model,
  capability token, E2E envelope, pairing) — the src/types.ts analog
- term-relay:   native WS mux + stateless data plane (subdomain routing, ciphertext forward)
- agent:        host-agent (pairing, per-host Ed25519 + mTLS dial-out, forwards to 127.0.0.1:3000)
- control-plane: accounts/hosts registry, pairing-code flow, routing table, provisioning
- relay-e2e:    browser<->agent E2E (X25519 ECDH through relay, AEAD, anti-replay, recoverable replay key)
- relay-auth:   Passkey/WebAuthn, capability tokens, per-host certs, deny-by-default tenant isolation
- relay-web:    browser login + Web Crypto E2E + client-side preview rendering

Security invariants INV1-15 enforced; cross-tenant isolation CI tripwire live
(.github/workflows/relay-tripwire.yml). Design + implementation-level plans in
docs/PLAN_RELAY_*.md and docs/EXPLORE_RELAY_SERVICE.md.

NOTE: generated autonomously per the reviewed plans. The security-critical
packages (relay-e2e, relay-auth) REQUIRE expert security audit before any real
deployment — passing tests prove self-consistency, not resistance to attackers.
Base app (src/, public/) unchanged; concurrent desktop work left uncommitted.
This commit is contained in:
Yaojia Wang
2026-07-02 06:10:16 +02:00
parent e4c327e25e
commit 2af57e6686
326 changed files with 40877 additions and 0 deletions

View File

@@ -0,0 +1,44 @@
/**
* P5 verifying-key registry. `verifyCapabilityToken` / `verifyDeviceProof` are frozen §4.3/§4.4
* signatures with NO key parameter, so the P5 public verifying key is configured at startup and
* read here. Signing keys are passed explicitly to issue/sign functions (never held globally).
*
* INV9: the key is loaded from the secret manager / env, validated at startup, and NEVER logged.
*/
import { importEd25519PublicRaw } from '../crypto/ed25519.js'
import { decodeBase64UrlBytes } from 'relay-contracts'
let verifyKey: CryptoKey | null = null
export class KeyConfigError extends Error {
constructor(message: string) {
super(message)
this.name = 'KeyConfigError'
}
}
/** Configure the P5 Ed25519 public verifying key (called once at startup / in test setup). */
export function configureVerifyKey(key: CryptoKey): void {
verifyKey = key
}
/** Load the verifying key from `RELAY_AUTH_VERIFY_PUBKEY` (base64url raw Ed25519). INV9. */
export async function loadVerifyKeyFromEnv(env: NodeJS.ProcessEnv = process.env): Promise<void> {
const raw = env.RELAY_AUTH_VERIFY_PUBKEY
if (raw === undefined || raw.length === 0) {
throw new KeyConfigError('RELAY_AUTH_VERIFY_PUBKEY is not configured')
}
verifyKey = await importEd25519PublicRaw(decodeBase64UrlBytes(raw))
}
export function getVerifyKey(): CryptoKey {
if (verifyKey === null) {
throw new KeyConfigError('P5 verifying key not configured (call configureVerifyKey/loadVerifyKeyFromEnv)')
}
return verifyKey
}
/** TEST-ONLY reset so suites do not leak key state into each other. */
export function resetVerifyKeyForTest(): void {
verifyKey = null
}