feat: add private relay for end-to-end-encrypted remote access (#2087)
Adds OpenChamber Relay — an opt-in way to reach an instance from a phone, browser, or another desktop from anywhere, with no open inbound ports, no tunnel, and no shared LAN. The instance dials outbound to a relay; all app traffic (HTTP, the event stream, terminal, dictation) is multiplexed and encrypted through a single connection per client, so the relay only ever forwards opaque ciphertext. Transport - End-to-end-encrypted channel over WebCrypto (ECDH P-256 -> HKDF -> AES-256-GCM) with a capability-negotiated handshake and a small HTTP/SSE/WebSocket multiplexing protocol. A byte-compatible JS host mirror is cross-checked by tests. - Host: outbound connection manager, per-client tunnel dispatcher to the local server over loopback, reuse of the existing instance identity key, and management routes. Disabled by default; explicit opt-in. - Client: plugs into the existing runtime layer (runtime-fetch/-url/-switch/ -auth, event pipeline, terminal, dictation) so features work over the relay unchanged; direct-URL and Electron realtime-proxy paths are untouched. Pairing & UX - Relay section in Settings -> Remote Instances (live status, QR/link pairing, revocation via the existing client-token list) and the mobile connect flow. - Frame batching and idle-gated keepalive keep tunnel message volume low without affecting streaming smoothness. Security - The tunnel is transport only; the server authenticates every tunneled request exactly as for a direct remote client. fragments only. The relay stores no keys, tokens, or payloads. Operability - The endpoint can be pinned to a self-hosted rel paired clients inherit it from the offer automatically. - Relay module DOCUMENTATION.md and a relay-trans invariants that future WebSocket/streaming changes must follow. The relay transport is complete and tested; the UI for enabling and pairing is gated behind openchamber_relay_gate and stays
This commit is contained in:
committed by
GitHub
parent
42e470cefa
commit
859b4529da
@@ -16,6 +16,8 @@ import type { Event, OpencodeClient, SessionStatus } from "@opencode-ai/sdk/v2/c
|
||||
import { opencodeClient } from "@/lib/opencode/client"
|
||||
import { getRuntimeUrlResolver } from "@/lib/runtime-url"
|
||||
import { clearRuntimeUrlAuthToken, refreshRuntimeUrlAuthToken } from "@/lib/runtime-auth"
|
||||
import { type RelayTunnelWebSocket } from "@/lib/relay/tunnel-client"
|
||||
import { openRuntimeWebSocket } from "@/lib/relay/runtime-socket"
|
||||
import { syncDebug } from "./debug"
|
||||
|
||||
const FLUSH_FRAME_MS = 33
|
||||
@@ -212,6 +214,17 @@ function buildGlobalEventWsUrl(lastEventId?: string): string {
|
||||
)
|
||||
}
|
||||
|
||||
// In relay mode the global-event WebSocket rides the E2EE tunnel instead of a
|
||||
// native network socket. The resolver still builds the authenticated URL (it
|
||||
// carries the oc_url_token the host replays to the loopback origin); we hand
|
||||
// its path+query to the tunnel, which returns a socket-like with the exact
|
||||
// on* handler surface this pipeline uses. Direct-URL runtimes keep the native
|
||||
// WebSocket path, wrapped to the same shape so the caller holds one type.
|
||||
function openGlobalEventSocket(lastEventId?: string): RelayTunnelWebSocket {
|
||||
const url = buildGlobalEventWsUrl(lastEventId)
|
||||
return openRuntimeWebSocket(url)
|
||||
}
|
||||
|
||||
type DirectoryQueue = {
|
||||
queue: Event[]
|
||||
buffer: Event[]
|
||||
@@ -569,7 +582,7 @@ export function createEventPipeline(input: EventPipelineInput): EventPipeline {
|
||||
let settled = false
|
||||
let opened = false
|
||||
let readyAt = 0
|
||||
const socket = new WebSocket(buildGlobalEventWsUrl(lastEventId))
|
||||
const socket: RelayTunnelWebSocket = openGlobalEventSocket(lastEventId)
|
||||
const setFallbackCode = (error: Error, force = false) => {
|
||||
if ((force || !opened) && transport === "auto") {
|
||||
wsFallbackUntil = Date.now() + WS_FALLBACK_WINDOW_MS
|
||||
|
||||
Reference in New Issue
Block a user