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.
54 lines
2.0 KiB
TypeScript
54 lines
2.0 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
import { readFileSync } from 'node:fs'
|
|
import { join } from 'node:path'
|
|
import {
|
|
computeEnrollFpr,
|
|
generateIdentity,
|
|
identityFromPrivatePem,
|
|
verifySignature,
|
|
} from '../src/keys/identity.js'
|
|
|
|
describe('AgentIdentity (INV4)', () => {
|
|
it('generates distinct keypairs', () => {
|
|
const a = generateIdentity()
|
|
const b = generateIdentity()
|
|
expect(Buffer.from(a.publicKey).equals(Buffer.from(b.publicKey))).toBe(false)
|
|
expect(a.publicKey.length).toBe(32)
|
|
})
|
|
|
|
it('sign/verify round-trips', () => {
|
|
const id = generateIdentity()
|
|
const msg = new TextEncoder().encode('transcript-bytes')
|
|
const sig = id.sign(msg)
|
|
expect(verifySignature(id.publicKey, msg, sig)).toBe(true)
|
|
expect(verifySignature(id.publicKey, new TextEncoder().encode('tampered'), sig)).toBe(false)
|
|
})
|
|
|
|
it('enrollFpr is deterministic base64url(SHA-256(pubkey))', () => {
|
|
const id = generateIdentity()
|
|
expect(computeEnrollFpr(id.publicKey)).toBe(id.enrollFpr)
|
|
expect(id.enrollFpr).not.toMatch(/[+/=]/) // base64url alphabet only
|
|
})
|
|
|
|
it('reloads the same identity from PEM', () => {
|
|
const id = generateIdentity()
|
|
const pem = id.exportPrivatePkcs8Pem()
|
|
const reloaded = identityFromPrivatePem(pem)
|
|
expect(Buffer.from(reloaded.publicKey).equals(Buffer.from(id.publicKey))).toBe(true)
|
|
expect(reloaded.enrollFpr).toBe(id.enrollFpr)
|
|
})
|
|
|
|
it('security: no API returns raw private-key bytes', () => {
|
|
const id = generateIdentity()
|
|
// The only private-key surface is a PEM export for the 0600 keystore and an in-process
|
|
// KeyObject; there is NO Uint8Array/raw-bytes getter for the private key.
|
|
expect('privateKey' in id).toBe(false)
|
|
const src = readFileSync(
|
|
join(import.meta.dirname, '..', 'src', 'keys', 'identity.ts'),
|
|
'utf8',
|
|
)
|
|
// No function exports raw private key bytes onto the network surface.
|
|
expect(src).not.toMatch(/exportPrivateRaw|privateKeyBytes|toRawPrivate/)
|
|
})
|
|
})
|