/** * The govern phase of transparent interception: for the destinations an * operator lists, the interceptor does not splice the connection through but * becomes its other end. A TLS connection is terminated with a leaf certificate * minted for the server name from the operator's own authority; a plaintext * connection is read as it is. Either way the bytes then reach the gateway's * listener, which runs the same lifecycle the addressed gateway runs: the * request is captured as an intent, the authority decides, and exactly the * authorized request is forwarded once to the real destination, or held, or * refused. Destinations not listed are the observe phase's business, spliced * through and counted, or refused, as the operator chose. * * TLS is terminated over a stream that replays the bytes already read while * the destination was being decided: Node's TLS reads a raw socket through * its handle, beneath the JavaScript stream those bytes were read from, so * handing it the socket would lose the hello. The adapter is the one seam * where the interceptor's own code touches the ciphertext, and it copies. */ import type { Socket } from "node:net"; import { Duplex } from "node:stream"; import type { InterceptProtocol } from "../intercept/Destination.js"; import type { LeafIssuer } from "../intercept/LeafIssuer.js"; import type { GatewayHttpServer } from "./GatewayHttpServer.js"; export type UnlistedPolicy = "passthrough" | "refuse"; export interface GovernorOptions { /** The hosts whose connections are governed, lowercase. */ readonly hosts: ReadonlySet; /** What becomes of a destination not listed: spliced through and counted, or refused. */ readonly unlisted: UnlistedPolicy; /** Mints the leaf a governed TLS connection is terminated with; null refuses governed TLS. */ readonly issuer: LeafIssuer | null; /** How long a governed TLS handshake may take. */ readonly handshakeTimeoutMs: number; } export interface GovernorDependencies { /** The gateway listener for a governed host, created on first use and kept. */ readonly gatewayFor: (host: string, protocol: InterceptProtocol) => Promise; } export declare class GovernError extends Error { readonly code: "GOVERN_TLS_UNAVAILABLE" | "GOVERN_HANDSHAKE_FAILED" | "GOVERN_GATEWAY_UNAVAILABLE"; readonly detail: string | null; constructor(code: "GOVERN_TLS_UNAVAILABLE" | "GOVERN_HANDSHAKE_FAILED" | "GOVERN_GATEWAY_UNAVAILABLE", detail?: string | null); } export declare const GOVERN_DEFAULTS: { readonly unlisted: "passthrough"; readonly handshakeTimeoutMs: 10000; }; /** * A stream over a socket whose first bytes were already read: it delivers * those bytes first, then whatever the socket delivers, and writes through. */ export declare function replayed(socket: Socket, head: Buffer): Duplex; export declare class InterceptGovernor { private readonly options; private readonly dependencies; constructor(options: GovernorOptions, dependencies: GovernorDependencies); get unlisted(): UnlistedPolicy; get hosts(): ReadonlySet; governs(host: string): boolean; /** * Takes a governed connection: terminates TLS where TLS was spoken, and * hands the plaintext stream to the host's gateway listener. Rejects with a * `GovernError` naming what could not be done; the caller refuses the * connection by that name, and the connection is closed. */ take(client: Socket, head: Buffer, destination: { readonly protocol: InterceptProtocol; readonly host: string; }): Promise; } //# sourceMappingURL=InterceptGovernor.d.ts.map