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:
58
relay-e2e/test/replay-key.test.ts
Normal file
58
relay-e2e/test/replay-key.test.ts
Normal file
@@ -0,0 +1,58 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import type { AeadAlg, ReplayKeyParams } from 'relay-contracts'
|
||||
import { unwrapAeadKey } from '../src/aead-key.js'
|
||||
import { encodeEnvelope } from '../src/envelope.js'
|
||||
import { AeadOpenError } from '../src/errors.js'
|
||||
import { deriveContentKey, openReplayCiphertext, sealReplayFrame } from '../src/replay-key.js'
|
||||
import { bytesToHex, fromUtf8, utf8 } from './helpers.js'
|
||||
|
||||
const params = (secret: Uint8Array, sessionId: string, alg: AeadAlg = 'aes-256-gcm'): ReplayKeyParams => ({
|
||||
hostContentSecret: secret,
|
||||
sessionId,
|
||||
alg,
|
||||
})
|
||||
|
||||
describe('T10 recoverable replay content-key', () => {
|
||||
it('load-bearing: seal under K_content, "reload" (new key object), re-derive, decrypt survives', () => {
|
||||
const secret = new Uint8Array(32).fill(0x11)
|
||||
// Device X seals output; the base-app ring buffer stores the ciphertext bytes.
|
||||
const ringBuffer: Uint8Array[] = []
|
||||
const kSeal = deriveContentKey(params(secret, 'sess-1'))
|
||||
ringBuffer.push(encodeEnvelope(sealReplayFrame(kSeal, 0n, utf8('scrollback line'))))
|
||||
// Reload: brand new derivation, no in-memory key.
|
||||
const kReload = deriveContentKey(params(secret, 'sess-1'))
|
||||
expect(fromUtf8(openReplayCiphertext(kReload, ringBuffer[0]!))).toBe('scrollback line')
|
||||
})
|
||||
|
||||
it('second authorized device (same secret) re-derives the identical K_content → decrypts', () => {
|
||||
const secret = new Uint8Array(32).fill(0x22)
|
||||
const wire = encodeEnvelope(sealReplayFrame(deriveContentKey(params(secret, 's')), 0n, utf8('mirror')))
|
||||
const deviceY = deriveContentKey(params(secret, 's'))
|
||||
expect(fromUtf8(openReplayCiphertext(deviceY, wire))).toBe('mirror')
|
||||
})
|
||||
|
||||
it('K_content is deterministic per (secret, sessionId, alg)', () => {
|
||||
const secret = new Uint8Array(32).fill(0x33)
|
||||
expect(bytesToHex(unwrapAeadKey(deriveContentKey(params(secret, 's'))).raw)).toBe(
|
||||
bytesToHex(unwrapAeadKey(deriveContentKey(params(secret, 's'))).raw),
|
||||
)
|
||||
})
|
||||
|
||||
it('SECURITY: a different / cross-session / cross-host secret cannot open (reinforces INV1)', () => {
|
||||
const secretA = new Uint8Array(32).fill(0x44)
|
||||
const secretB = new Uint8Array(32).fill(0x45)
|
||||
const wire = encodeEnvelope(sealReplayFrame(deriveContentKey(params(secretA, 's1')), 0n, utf8('x')))
|
||||
// different host secret
|
||||
expect(() => openReplayCiphertext(deriveContentKey(params(secretB, 's1')), wire)).toThrow(AeadOpenError)
|
||||
// different session id (per-sessionId key, no cross-session reuse)
|
||||
expect(() => openReplayCiphertext(deriveContentKey(params(secretA, 's2')), wire)).toThrow(AeadOpenError)
|
||||
})
|
||||
|
||||
it('revocation (INV12): a revoked wrap yields no secret → no key derivable for that host going forward', () => {
|
||||
// The unwrap mechanism is P5/P2; P4 asserts derivation is GATED on having the unwrapped secret.
|
||||
const revokedUnwrap = (): Uint8Array => {
|
||||
throw new Error('revoked: hostContentSecret wrap no longer unwraps')
|
||||
}
|
||||
expect(() => deriveContentKey(params(revokedUnwrap(), 's1'))).toThrow()
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user