@floegence/flowersec-core 8.0.0 → 8.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/THIRD_PARTY_NOTICES.md +8 -5
- package/dist/browser/connectSessionV3.d.ts +4 -0
- package/dist/browser/connectSessionV3.js +15 -8
- package/dist/browser/index.d.ts +1 -1
- package/dist/browser/index.js +1 -1
- package/dist/facade.d.ts +4 -0
- package/dist/facade.js +3 -0
- package/dist/framing/jsonframe.d.ts +1 -1
- package/dist/framing/jsonframe.js +13 -6
- package/dist/node/connectSessionV3.d.ts +6 -2
- package/dist/node/connectSessionV3.js +12 -6
- package/dist/node/index.d.ts +1 -1
- package/dist/node/index.js +1 -1
- package/dist/node/nativeTransportAddon.d.ts +4 -3
- package/dist/node/nativeTransportAddon.js +3 -2
- package/dist/node/rawQuicAdapterV3.d.ts +2 -2
- package/dist/node/rawQuicAdapterV3.js +5 -3
- package/dist/public/sessionHandlers.d.ts +3 -1
- package/dist/public/sessionHandlers.js +11 -3
- package/dist/rpc/server.js +3 -3
- package/dist/tunnelAuth/artifact.d.ts +34 -0
- package/dist/tunnelAuth/artifact.js +74 -0
- package/dist/tunnelAuth/credentials.d.ts +17 -0
- package/dist/tunnelAuth/credentials.js +40 -0
- package/dist/tunnelAuth/hpke.d.ts +36 -0
- package/dist/tunnelAuth/hpke.js +124 -0
- package/dist/v3/artifact.d.ts +27 -8
- package/dist/v3/artifact.js +78 -42
- package/dist/v3/artifactLease.d.ts +4 -2
- package/dist/v3/artifactLease.js +13 -1
- package/dist/v3/browserRuntime.js +5 -3
- package/dist/v3/connectionController.d.ts +2 -2
- package/dist/v3/connectionController.js +8 -4
- package/dist/v3/connectorRPCLimits.d.ts +7 -0
- package/dist/v3/connectorRPCLimits.js +14 -0
- package/dist/v3/handshake.d.ts +22 -21
- package/dist/v3/handshake.js +58 -60
- package/dist/v3/nodeRuntime.js +4 -1
- package/dist/v3/protocol.d.ts +17 -16
- package/dist/v3/protocol.js +60 -64
- package/dist/v3/publicApi.d.ts +1 -0
- package/dist/v3/publicApi.js +7 -0
- package/dist/v3/runtimeAdapters.d.ts +2 -2
- package/dist/v3/runtimeAdapters.js +2 -1
- package/dist/v3/security.d.ts +1 -1
- package/dist/v3/session.d.ts +14 -4
- package/dist/v3/session.js +174 -114
- package/dist/v3/sessionConnector.d.ts +2 -2
- package/dist/v3/sessionConnector.js +24 -13
- package/dist/v3/tunnelIngress.js +2 -1
- package/dist/v3/unreliableMessage.d.ts +3 -0
- package/dist/v3/unreliableMessage.js +24 -22
- package/dist/v3/wireProfile.d.ts +52 -0
- package/dist/v3/wireProfile.js +20 -0
- package/package.json +5 -3
- package/sbom/cyclonedx.json +133 -31
- package/sbom/spdx.json +110 -39
package/THIRD_PARTY_NOTICES.md
CHANGED
|
@@ -3,11 +3,14 @@
|
|
|
3
3
|
This file is generated from the canonical Flowersec source dependency inventory for flowersec-ts.
|
|
4
4
|
Do not edit it manually. License decisions are reviewed by the repository source license policy.
|
|
5
5
|
|
|
6
|
-
- @floegence/flowersec-node-native 8.
|
|
7
|
-
- @floegence/flowersec-node-native-darwin-arm64 8.
|
|
8
|
-
- @floegence/flowersec-node-native-darwin-x64 8.
|
|
9
|
-
- @floegence/flowersec-node-native-linux-arm64-gnu 8.
|
|
10
|
-
- @floegence/flowersec-node-native-linux-x64-gnu 8.
|
|
6
|
+
- @floegence/flowersec-node-native 8.2.0 (Declared: MIT; selected: MIT; source: https://github.com/floegence/flowersec.git)
|
|
7
|
+
- @floegence/flowersec-node-native-darwin-arm64 8.2.0 (Declared: MIT; selected: MIT; source: https://github.com/floegence/flowersec.git)
|
|
8
|
+
- @floegence/flowersec-node-native-darwin-x64 8.2.0 (Declared: MIT; selected: MIT; source: https://github.com/floegence/flowersec.git)
|
|
9
|
+
- @floegence/flowersec-node-native-linux-arm64-gnu 8.2.0 (Declared: MIT; selected: MIT; source: https://github.com/floegence/flowersec.git)
|
|
10
|
+
- @floegence/flowersec-node-native-linux-x64-gnu 8.2.0 (Declared: MIT; selected: MIT; source: https://github.com/floegence/flowersec.git)
|
|
11
|
+
- @hpke/common 1.13.0 (Declared: MIT; selected: MIT; source: https://registry.npmjs.org/@hpke/common/-/common-1.13.0.tgz)
|
|
12
|
+
- @hpke/core 1.10.1 (Declared: MIT; selected: MIT; source: https://registry.npmjs.org/@hpke/core/-/core-1.10.1.tgz)
|
|
13
|
+
- @hpke/dhkem-x25519 1.8.1 (Declared: MIT; selected: MIT; source: https://registry.npmjs.org/@hpke/dhkem-x25519/-/dhkem-x25519-1.8.1.tgz)
|
|
11
14
|
- @noble/ciphers 2.4.0 (Declared: MIT; selected: MIT; source: https://registry.npmjs.org/@noble/ciphers/-/ciphers-2.4.0.tgz)
|
|
12
15
|
- @noble/curves 2.4.0 (Declared: MIT; selected: MIT; source: https://registry.npmjs.org/@noble/curves/-/curves-2.4.0.tgz)
|
|
13
16
|
- @noble/hashes 2.4.0 (Declared: MIT; selected: MIT; source: https://registry.npmjs.org/@noble/hashes/-/hashes-2.4.0.tgz)
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type { Session } from "../public/contract.js";
|
|
2
|
+
import { type TunnelAuthLease, type TunnelAuthOptions, type TunnelAuthSource } from "../tunnelAuth/artifact.js";
|
|
3
|
+
import type { TunnelAuth } from "../tunnelAuth/credentials.js";
|
|
2
4
|
import { RPCHandlers, type SessionHandlerBinding } from "../public/sessionHandlers.js";
|
|
3
5
|
import { type ArtifactLeaseV3, type KeyExchangeMode } from "../v3/artifactLease.js";
|
|
4
6
|
import { type ArtifactSourceV3, type ConnectionControllerV3, type RotationDriver } from "../v3/connectionController.js";
|
|
@@ -37,6 +39,8 @@ export type PrivateLoopbackConnectionControllerOptionsV1 = ControllerRPCOptions
|
|
|
37
39
|
}>;
|
|
38
40
|
export declare function connectV3(lease: ArtifactLeaseV3, options?: SessionOptionsV3): Promise<Session>;
|
|
39
41
|
export declare function createConnectionControllerV3(source: ArtifactSourceV3, options?: ConnectionControllerOptionsV3): Promise<ConnectionControllerV3<Session>>;
|
|
42
|
+
export declare function connectAuthenticatedTunnel(lease: TunnelAuthLease, auth: TunnelAuth, options?: TunnelAuthOptions & Omit<SessionOptionsV3, "keyExchange" | "enableHybridKeyExchange">): Promise<Session>;
|
|
43
|
+
export declare function newAuthenticatedTunnelController(source: TunnelAuthSource, auth: TunnelAuth, options?: TunnelAuthOptions & Omit<ConnectionControllerOptionsV3, "keyExchange" | "enableHybridKeyExchange">): Promise<ConnectionControllerV3<Session>>;
|
|
40
44
|
export declare function createBrowserController(source: ArtifactSourceV3, options: ConnectionControllerOptionsV3, rotation?: RotationDriver<Session>): Promise<ConnectionControllerV3<Session>>;
|
|
41
45
|
export type HTTPDirectSessionOptionsV1 = PrivateLoopbackSessionOptionsV1;
|
|
42
46
|
export type HTTPDirectConnectionControllerOptionsV1 = PrivateLoopbackConnectionControllerOptionsV1;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { bindEndpointLease, bindEndpointSource } from "../tunnelAuth/artifact.js";
|
|
2
|
+
import { endpointIngress } from "../v3/wireProfile.js";
|
|
1
3
|
import { SDK_DEFAULTS } from "../defaults.js";
|
|
2
|
-
import {
|
|
3
|
-
import { rpcConcurrency } from "../rpc/server.js";
|
|
4
|
+
import { connectorRPCLimits } from "../v3/connectorRPCLimits.js";
|
|
4
5
|
import { createRPCRouter, freezeRPCHandlers, RPCHandlers } from "../public/sessionHandlers.js";
|
|
5
6
|
import { claimArtifactLeaseV3, retireArtifactLeaseV3, } from "../v3/artifactLease.js";
|
|
6
7
|
import { createConnectionControllerV3 as createCoreControllerV3, } from "../v3/connectionController.js";
|
|
@@ -20,6 +21,12 @@ export async function connectV3(lease, options = {}) {
|
|
|
20
21
|
export async function createConnectionControllerV3(source, options = {}) {
|
|
21
22
|
return createBrowserController(source, options);
|
|
22
23
|
}
|
|
24
|
+
export async function connectAuthenticatedTunnel(lease, auth, options = {}) {
|
|
25
|
+
return connectV3(bindEndpointLease(lease, auth, options), { ...options, keyExchange: "classic" });
|
|
26
|
+
}
|
|
27
|
+
export async function newAuthenticatedTunnelController(source, auth, options = {}) {
|
|
28
|
+
return createBrowserController(bindEndpointSource(source, auth, options), { ...options, keyExchange: "classic" });
|
|
29
|
+
}
|
|
23
30
|
export async function createBrowserController(source, options, rotation) {
|
|
24
31
|
requireControllerHandlers(options);
|
|
25
32
|
const registry = await BrowserRuntimeCapabilityRegistryV3.create();
|
|
@@ -156,9 +163,9 @@ async function retireInnerLease(lease) {
|
|
|
156
163
|
}
|
|
157
164
|
}
|
|
158
165
|
function rpcOptions(options) {
|
|
166
|
+
const limits = connectorRPCLimits(options);
|
|
159
167
|
const handlers = options.rpcHandlers === undefined ? undefined : freezeRPCHandlers(options.rpcHandlers);
|
|
160
|
-
return {
|
|
161
|
-
maxConcurrentRpcRequests: rpcConcurrency(options.maxConcurrentRpcRequests),
|
|
168
|
+
return { ...limits,
|
|
162
169
|
...(handlers === undefined ? {} : { createRPCRouter: () => createRPCRouter(handlers) }) };
|
|
163
170
|
}
|
|
164
171
|
function requireControllerHandlers(options) {
|
|
@@ -187,7 +194,7 @@ function browserRuntime(registry, options) {
|
|
|
187
194
|
if (candidate.carrier !== "websocket" || candidate.tls.mode !== "ca") {
|
|
188
195
|
throw new TransportFailureV3("tls_unsupported");
|
|
189
196
|
}
|
|
190
|
-
validateBrowserWebSocketURL(candidate.normalized_url, artifact.path.kind);
|
|
197
|
+
validateBrowserWebSocketURL(candidate.normalized_url, artifact.path.kind, artifact.v === 1);
|
|
191
198
|
return await dialBrowserWebSocket(candidate, artifact, candidate.normalized_url, signal);
|
|
192
199
|
},
|
|
193
200
|
};
|
|
@@ -217,7 +224,7 @@ async function dialBrowserWebSocket(candidate, artifact, targetURL, signal) {
|
|
|
217
224
|
const Constructor = globalThis.WebSocket;
|
|
218
225
|
if (Constructor === undefined)
|
|
219
226
|
throw new TransportFailureV3("tls_unsupported");
|
|
220
|
-
const protocol = artifact.path.kind === "direct" ? "flowersec.direct.v5" : "flowersec.tunnel.v5";
|
|
227
|
+
const protocol = artifact.v === 1 ? endpointIngress.subprotocol : artifact.path.kind === "direct" ? "flowersec.direct.v5" : "flowersec.tunnel.v5";
|
|
221
228
|
let socket;
|
|
222
229
|
try {
|
|
223
230
|
socket = new Constructor(targetURL, protocol);
|
|
@@ -245,7 +252,7 @@ function profileWebSocketURL(candidateURL, profileOrigin) {
|
|
|
245
252
|
return undefined;
|
|
246
253
|
}
|
|
247
254
|
}
|
|
248
|
-
function validateBrowserWebSocketURL(raw, path) {
|
|
255
|
+
function validateBrowserWebSocketURL(raw, path, authenticated) {
|
|
249
256
|
let parsed;
|
|
250
257
|
try {
|
|
251
258
|
parsed = new URL(raw);
|
|
@@ -253,7 +260,7 @@ function validateBrowserWebSocketURL(raw, path) {
|
|
|
253
260
|
catch {
|
|
254
261
|
throw new TransportFailureV3("invalid_artifact");
|
|
255
262
|
}
|
|
256
|
-
const expectedPath =
|
|
263
|
+
const expectedPath = authenticated ? endpointIngress.websocket : `/flowersec/v5/${path}`;
|
|
257
264
|
if (parsed.href !== raw || parsed.protocol !== "wss:" || parsed.username !== "" || parsed.password !== "" ||
|
|
258
265
|
parsed.pathname !== expectedPath || parsed.search !== "" || parsed.hash !== "") {
|
|
259
266
|
throw new TransportFailureV3("invalid_artifact");
|
package/dist/browser/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export * from "../facade.js";
|
|
2
2
|
export { RPCHandlers } from "../public/sessionHandlers.js";
|
|
3
3
|
export type { RPCHandler, RPCHandlerResult, NotificationHandler, SessionHandlerBinding } from "../public/sessionHandlers.js";
|
|
4
|
-
export { connectV3 as connect, createConnectionControllerV3 as createConnectionController, connectPrivateLoopbackV1, connectHTTPDirectV1, createHTTPDirectConnectionControllerV1, createPrivateLoopbackConnectionControllerV1, } from "./connectSessionV3.js";
|
|
4
|
+
export { connectV3 as connect, connectAuthenticatedTunnel, newAuthenticatedTunnelController, createConnectionControllerV3 as createConnectionController, connectPrivateLoopbackV1, connectHTTPDirectV1, createHTTPDirectConnectionControllerV1, createPrivateLoopbackConnectionControllerV1, } from "./connectSessionV3.js";
|
|
5
5
|
export { PRIVATE_LOOPBACK_PROFILE_V1, PrivateLoopbackArtifactErrorV1, createPrivateLoopbackArtifactLeaseV1, parsePrivateLoopbackArtifactV1, } from "./privateLoopbackV1.js";
|
|
6
6
|
export type { ConnectionControllerOptionsV3 as ConnectionControllerOptions, SessionOptionsV3 as SessionOptions, } from "./connectSessionV3.js";
|
|
7
7
|
export type { PrivateLoopbackConnectionControllerOptionsV1, PrivateLoopbackSessionOptionsV1, } from "./connectSessionV3.js";
|
package/dist/browser/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export * from "../facade.js";
|
|
2
2
|
export { RPCHandlers } from "../public/sessionHandlers.js";
|
|
3
|
-
export { connectV3 as connect, createConnectionControllerV3 as createConnectionController, connectPrivateLoopbackV1, connectHTTPDirectV1, createHTTPDirectConnectionControllerV1, createPrivateLoopbackConnectionControllerV1, } from "./connectSessionV3.js";
|
|
3
|
+
export { connectV3 as connect, connectAuthenticatedTunnel, newAuthenticatedTunnelController, createConnectionControllerV3 as createConnectionController, connectPrivateLoopbackV1, connectHTTPDirectV1, createHTTPDirectConnectionControllerV1, createPrivateLoopbackConnectionControllerV1, } from "./connectSessionV3.js";
|
|
4
4
|
export { PRIVATE_LOOPBACK_PROFILE_V1, PrivateLoopbackArtifactErrorV1, createPrivateLoopbackArtifactLeaseV1, parsePrivateLoopbackArtifactV1, } from "./privateLoopbackV1.js";
|
|
5
5
|
export { HTTP_DIRECT_PROFILE_V1, HTTPDirectArtifactErrorV1, parseHTTPDirectArtifactV1, createHTTPDirectArtifactLeaseV1, } from "./httpDirectV1.js";
|
package/dist/facade.d.ts
CHANGED
|
@@ -19,3 +19,7 @@ export type ConnectionControllerOptions = Readonly<{
|
|
|
19
19
|
export { ConnectionControllerV3Error as ConnectionControllerError, } from "./v3/connectionController.js";
|
|
20
20
|
export { ConnectErrorV3 as ConnectError } from "./v3/security.js";
|
|
21
21
|
export type { PublicConnectErrorCodeV3 as ConnectErrorCode, RetryDispositionV3 as RetryDisposition, } from "./v3/security.js";
|
|
22
|
+
export { EndpointIdentity, EndpointPublicKey } from "./tunnelAuth/hpke.js";
|
|
23
|
+
export { TunnelAuth } from "./tunnelAuth/credentials.js";
|
|
24
|
+
export { TunnelAuthArtifact, TunnelAuthLease, parseTunnelAuthArtifact } from "./tunnelAuth/artifact.js";
|
|
25
|
+
export type { TunnelAuthOptions, TunnelAuthSource } from "./tunnelAuth/artifact.js";
|
package/dist/facade.js
CHANGED
|
@@ -6,3 +6,6 @@ export { ArtifactLeaseV3 as ArtifactLease, ArtifactLeaseV3Error as ArtifactLease
|
|
|
6
6
|
export { connectionDiagnosticV3 as connectionDiagnostic } from "./v3/connectionController.js";
|
|
7
7
|
export { ConnectionControllerV3Error as ConnectionControllerError, } from "./v3/connectionController.js";
|
|
8
8
|
export { ConnectErrorV3 as ConnectError } from "./v3/security.js";
|
|
9
|
+
export { EndpointIdentity, EndpointPublicKey } from "./tunnelAuth/hpke.js";
|
|
10
|
+
export { TunnelAuth } from "./tunnelAuth/credentials.js";
|
|
11
|
+
export { TunnelAuthArtifact, TunnelAuthLease, parseTunnelAuthArtifact } from "./tunnelAuth/artifact.js";
|
|
@@ -12,7 +12,7 @@ type ReadExactlyFn = (n: number) => Promise<Uint8Array>;
|
|
|
12
12
|
type ReadExactlyLike = Readonly<{
|
|
13
13
|
readExactly: (n: number) => Promise<Uint8Array>;
|
|
14
14
|
}>;
|
|
15
|
-
export declare function writeJsonFrame(write: WriteFn | WriteLike, v: unknown, maxBytes?: number, rpc?: boolean): Promise<void>;
|
|
15
|
+
export declare function writeJsonFrame(write: WriteFn | WriteLike, v: unknown, maxBytes?: number, rpc?: boolean, overflow?: () => unknown): Promise<void>;
|
|
16
16
|
export declare function readJsonFrame(readExactly: ReadExactlyFn | ReadExactlyLike, maxBytes: number): Promise<unknown>;
|
|
17
17
|
export declare function readRpcFrame(readExactly: ReadExactlyFn | ReadExactlyLike, maxBytes: number): Promise<{
|
|
18
18
|
value: unknown;
|
|
@@ -37,13 +37,10 @@ function normalizeReadExactly(readExactly) {
|
|
|
37
37
|
return typeof readExactly === "function" ? readExactly : (n) => readExactly.readExactly(n);
|
|
38
38
|
}
|
|
39
39
|
// writeJsonFrame encodes a JSON payload with a 4-byte length prefix.
|
|
40
|
-
|
|
41
|
-
const text = JSON.stringify(v);
|
|
42
|
-
if (typeof text !== "string")
|
|
43
|
-
throw new JsonFramingError("invalid JSON value");
|
|
40
|
+
function encodedLength(text, maxBytes) {
|
|
44
41
|
let length = text.length;
|
|
45
42
|
if (maxBytes > 0 && length > maxBytes)
|
|
46
|
-
|
|
43
|
+
return length;
|
|
47
44
|
for (let i = 0; i < text.length; i++) {
|
|
48
45
|
const code = text.charCodeAt(i);
|
|
49
46
|
if (code < 0x80)
|
|
@@ -56,8 +53,18 @@ export async function writeJsonFrame(write, v, maxBytes = 0, rpc = false) {
|
|
|
56
53
|
i++;
|
|
57
54
|
}
|
|
58
55
|
}
|
|
59
|
-
|
|
56
|
+
return length;
|
|
57
|
+
}
|
|
58
|
+
export async function writeJsonFrame(write, v, maxBytes = 0, rpc = false, overflow) {
|
|
59
|
+
const text = JSON.stringify(v);
|
|
60
|
+
if (typeof text !== "string")
|
|
61
|
+
throw new JsonFramingError("invalid JSON value");
|
|
62
|
+
const length = encodedLength(text, maxBytes);
|
|
63
|
+
if (length > 0xffffffff || (maxBytes > 0 && length > maxBytes)) {
|
|
64
|
+
if (overflow)
|
|
65
|
+
return await writeJsonFrame(write, overflow(), maxBytes, rpc);
|
|
60
66
|
throw new JsonFramingError("frame too large");
|
|
67
|
+
}
|
|
61
68
|
const release = rpc ? reserveFrame(length, 4 + length + 2 * text.length) : noCharge;
|
|
62
69
|
try {
|
|
63
70
|
const frame = new Uint8Array(4 + length);
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type { NodeConnectionPath } from "./connectionPath.js";
|
|
2
|
+
import { type TunnelAuthLease, type TunnelAuthOptions, type TunnelAuthSource } from "../tunnelAuth/artifact.js";
|
|
3
|
+
import type { TunnelAuth } from "../tunnelAuth/credentials.js";
|
|
2
4
|
import type { Session } from "../public/contract.js";
|
|
3
5
|
import type { ArtifactLeaseV3, KeyExchangeMode } from "../v3/artifactLease.js";
|
|
4
6
|
import { type ArtifactSourceV3, type ConnectionControllerV3 } from "../v3/connectionController.js";
|
|
@@ -33,5 +35,7 @@ export type ConnectionControllerOptionsV3 = Readonly<{
|
|
|
33
35
|
maxConcurrentRpcRequests?: number;
|
|
34
36
|
tunnelIngressURL?: string;
|
|
35
37
|
}>;
|
|
36
|
-
export declare function connectV3(lease: ArtifactLeaseV3, options
|
|
37
|
-
export declare function createConnectionControllerV3(source: ArtifactSourceV3, options
|
|
38
|
+
export declare function connectV3(lease: ArtifactLeaseV3, options?: SessionOptionsV3): Promise<Session>;
|
|
39
|
+
export declare function createConnectionControllerV3(source: ArtifactSourceV3, options?: ConnectionControllerOptionsV3): ConnectionControllerV3<Session>;
|
|
40
|
+
export declare function connectAuthenticatedTunnel(lease: TunnelAuthLease, auth: TunnelAuth, options?: TunnelAuthOptions & Omit<SessionOptionsV3, "keyExchange" | "enableHybridKeyExchange">): Promise<Session>;
|
|
41
|
+
export declare function newAuthenticatedTunnelController(source: TunnelAuthSource, auth: TunnelAuth, options?: TunnelAuthOptions & Omit<ConnectionControllerOptionsV3, "keyExchange" | "enableHybridKeyExchange">): ConnectionControllerV3<Session>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { bindEndpointLease, bindEndpointSource } from "../tunnelAuth/artifact.js";
|
|
1
2
|
import { SDK_DEFAULTS } from "../defaults.js";
|
|
2
|
-
import {
|
|
3
|
-
import { rpcConcurrency } from "../rpc/server.js";
|
|
3
|
+
import { connectorRPCLimits } from "../v3/connectorRPCLimits.js";
|
|
4
4
|
import { createConnectionControllerV3 as createCoreControllerV3, } from "../v3/connectionController.js";
|
|
5
5
|
import { connectNodeWebSocketV3, detectNodeRuntimeCapabilityV3, } from "../v3/nodeRuntime.js";
|
|
6
6
|
import { attemptClaimedArtifactLeaseV3, connectArtifactLeaseWithRuntimeV3, } from "../v3/sessionConnector.js";
|
|
@@ -10,11 +10,11 @@ import { nodeSessionRuntimeV3 } from "../v3/nodeSessionRuntime.js";
|
|
|
10
10
|
import { createNativeRawQuicDriver, createNativeWebTransportDriver, tryLoadNativeTransportAddon, } from "./nativeTransportAddon.js";
|
|
11
11
|
import { createNodeRawQuicClientV3 } from "./rawQuicAdapterV3.js";
|
|
12
12
|
import { createRPCRouter, freezeRPCHandlers, RPCHandlers, } from "./acceptor.js";
|
|
13
|
-
export async function connectV3(lease, options) {
|
|
13
|
+
export async function connectV3(lease, options = {}) {
|
|
14
14
|
validateWebTransportOptIn(options);
|
|
15
15
|
return await connectArtifactLeaseWithRuntimeV3(lease, options, () => nodeRuntime(options));
|
|
16
16
|
}
|
|
17
|
-
export function createConnectionControllerV3(source, options) {
|
|
17
|
+
export function createConnectionControllerV3(source, options = {}) {
|
|
18
18
|
validateWebTransportOptIn(options);
|
|
19
19
|
if (options.rpcHandlers !== undefined && !(options.rpcHandlers instanceof RPCHandlers)) {
|
|
20
20
|
throw new ConnectErrorV3("artifact_invalid", { kind: "terminal" });
|
|
@@ -36,6 +36,12 @@ function validateWebTransportOptIn(options) {
|
|
|
36
36
|
if (options.webTransport !== undefined && typeof options.webTransport !== "boolean")
|
|
37
37
|
throw new TypeError("webTransport must be a boolean");
|
|
38
38
|
}
|
|
39
|
+
export async function connectAuthenticatedTunnel(lease, auth, options = {}) {
|
|
40
|
+
return connectV3(bindEndpointLease(lease, auth, options), { ...options, keyExchange: "classic" });
|
|
41
|
+
}
|
|
42
|
+
export function newAuthenticatedTunnelController(source, auth, options = {}) {
|
|
43
|
+
return createConnectionControllerV3(bindEndpointSource(source, auth, options), { ...options, keyExchange: "classic" });
|
|
44
|
+
}
|
|
39
45
|
function nodeRuntime(options) {
|
|
40
46
|
const connectTimeoutMilliseconds = options.connectTimeoutMs ?? SDK_DEFAULTS.transport.connectTimeoutMs;
|
|
41
47
|
if (!Number.isSafeInteger(connectTimeoutMilliseconds) || connectTimeoutMilliseconds < 1) {
|
|
@@ -48,6 +54,7 @@ function nodeRuntime(options) {
|
|
|
48
54
|
const rawQuic = addon === undefined ? undefined : createNativeRawQuicDriver(addon);
|
|
49
55
|
const webTransport = addon !== undefined && options.webTransport === true ? createNativeWebTransportDriver(addon) : undefined;
|
|
50
56
|
const capability = detectNodeRuntimeCapabilityV3(rawQuic !== undefined, options.origin !== undefined, webTransport !== undefined);
|
|
57
|
+
const limits = connectorRPCLimits(options);
|
|
51
58
|
let rpcSnapshot;
|
|
52
59
|
try {
|
|
53
60
|
rpcSnapshot = options.rpcHandlers === undefined ? undefined : freezeRPCHandlers(options.rpcHandlers);
|
|
@@ -63,8 +70,7 @@ function nodeRuntime(options) {
|
|
|
63
70
|
protocolRuntime: nodeSessionRuntimeV3,
|
|
64
71
|
keyExchange: options.keyExchange ?? "classic",
|
|
65
72
|
enableHybridKeyExchange: options.enableHybridKeyExchange === true,
|
|
66
|
-
|
|
67
|
-
maxConcurrentRpcRequests: rpcConcurrency(options.maxConcurrentRpcRequests),
|
|
73
|
+
...limits,
|
|
68
74
|
...(options.tunnelIngressURL === undefined ? {} : { tunnelIngressURL: options.tunnelIngressURL }),
|
|
69
75
|
...(rpcSnapshot === undefined ? {} : { createRPCRouter: () => createRPCRouter(rpcSnapshot) }),
|
|
70
76
|
dial: async (candidate, artifact, attemptNow, _capability, signal) => {
|
package/dist/node/index.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export { RuntimeAuthorizationRequestV3 as RuntimeAuthorizationRequest, TunnelAut
|
|
|
6
6
|
export type { TunnelAuthorizationGrantOptionsV3 as TunnelAuthorizationGrantOptions, TunnelVerificationRecord, } from "./runtimeAuthorizationV3.js";
|
|
7
7
|
export * from "../facade.js";
|
|
8
8
|
import type { NodeTLSRootsV3 as NodeTLSRoots } from "./connectSessionV3.js";
|
|
9
|
-
export { connectV3 as connect, createConnectionControllerV3 as createConnectionController, } from "./connectSessionV3.js";
|
|
9
|
+
export { connectV3 as connect, connectAuthenticatedTunnel, newAuthenticatedTunnelController, createConnectionControllerV3 as createConnectionController, } from "./connectSessionV3.js";
|
|
10
10
|
export type { ConnectionControllerOptionsV3 as ConnectionControllerOptions, NodeTLSRootsV3 as NodeTLSRoots, SessionOptionsV3 as SessionOptions, } from "./connectSessionV3.js";
|
|
11
11
|
export type SessionTLSOptions = Readonly<{
|
|
12
12
|
ca?: NodeTLSRoots;
|
package/dist/node/index.js
CHANGED
|
@@ -2,7 +2,7 @@ export { AcceptedSessionV3 as AcceptedSession, AcceptorV3 as Acceptor, createAcc
|
|
|
2
2
|
export { TunnelRuntimeV3 as TunnelRuntime, createTunnelRuntimeV3 as createTunnelRuntime, } from "./tunnelRuntimeV3.js";
|
|
3
3
|
export { RuntimeAuthorizationRequestV3 as RuntimeAuthorizationRequest, TunnelAuthorizationGrantV3 as TunnelAuthorizationGrant, verifyTunnelAuthorizationGrantV3 as verifyTunnelAuthorizationGrant, createTunnelVerificationRecord, } from "./runtimeAuthorizationV3.js";
|
|
4
4
|
export * from "../facade.js";
|
|
5
|
-
export { connectV3 as connect, createConnectionControllerV3 as createConnectionController, } from "./connectSessionV3.js";
|
|
5
|
+
export { connectV3 as connect, connectAuthenticatedTunnel, newAuthenticatedTunnelController, createConnectionControllerV3 as createConnectionController, } from "./connectSessionV3.js";
|
|
6
6
|
export { HandlerRegistrationError, RPCHandlers, SessionHandlersV3 as SessionHandlers, } from "./acceptor.js";
|
|
7
7
|
export { ProxyServer, ProxyServerError } from "./proxyServer.js";
|
|
8
8
|
export { createByteStreamDuplex } from "./byteStreamDuplex.js";
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { NativeCarrierSessionV3, NativeCarrierStreamV3 } from "../v3/carrier.js";
|
|
2
2
|
import type { PathKind } from "../v3/contract.js";
|
|
3
3
|
export declare const NATIVE_TRANSPORT_CONTRACT_VERSION = 5;
|
|
4
|
+
type NativePathProfile = PathKind | "authenticated_tunnel";
|
|
4
5
|
export type NativeRawQuicBindOptions = Readonly<{
|
|
5
6
|
host: string;
|
|
6
7
|
port: number;
|
|
@@ -14,7 +15,7 @@ type NativeRawQuicConnectOptionsBase = Readonly<{
|
|
|
14
15
|
host: string;
|
|
15
16
|
port: number;
|
|
16
17
|
serverName: string;
|
|
17
|
-
path:
|
|
18
|
+
path: NativePathProfile;
|
|
18
19
|
inboundBidirectionalStreamCapacity: number;
|
|
19
20
|
handshakeTimeoutMs: number;
|
|
20
21
|
}>;
|
|
@@ -66,8 +67,8 @@ type NativeRawQuicStreamBinding = Readonly<{
|
|
|
66
67
|
}>;
|
|
67
68
|
type NativeRawQuicSessionBinding = Readonly<{
|
|
68
69
|
kind: "raw_quic" | "webtransport";
|
|
69
|
-
path:
|
|
70
|
-
wireVersion: 5;
|
|
70
|
+
path: NativePathProfile;
|
|
71
|
+
wireVersion: 1 | 5;
|
|
71
72
|
inboundBidirectionalStreamCapacity: number;
|
|
72
73
|
maxDatagramSize?: number;
|
|
73
74
|
localAddress(): Readonly<{
|
|
@@ -92,7 +92,8 @@ export function createNativeWebTransportDriver(addon) {
|
|
|
92
92
|
});
|
|
93
93
|
}
|
|
94
94
|
function wrapSession(native, kind, path) {
|
|
95
|
-
|
|
95
|
+
const version = path === "authenticated_tunnel" ? 1 : 5;
|
|
96
|
+
if (native.wireVersion !== version || native.kind !== kind || native.path !== path) {
|
|
96
97
|
native.abort();
|
|
97
98
|
throw new NativeTransportUnavailableError();
|
|
98
99
|
}
|
|
@@ -123,7 +124,7 @@ function wrapSession(native, kind, path) {
|
|
|
123
124
|
});
|
|
124
125
|
return Object.freeze({
|
|
125
126
|
kind: native.kind,
|
|
126
|
-
path:
|
|
127
|
+
path: path === "authenticated_tunnel" ? "tunnel" : path,
|
|
127
128
|
inboundBidirectionalStreamCapacity: native.inboundBidirectionalStreamCapacity,
|
|
128
129
|
...(unreliableDatagrams === undefined ? {} : { unreliableDatagrams }),
|
|
129
130
|
async openStream(options = {}) {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ConnectionArtifact, CanonicalArtifactCandidateV3 } from "../v3/artifact.js";
|
|
2
2
|
import type { NativeCarrierSessionV3 } from "../v3/carrier.js";
|
|
3
3
|
import type { NativeRawQuicDriver, NativeWebTransportDriver } from "./nativeTransportAddon.js";
|
|
4
4
|
type NodeTLSRootsV3 = string | Uint8Array | readonly (string | Uint8Array)[];
|
|
5
|
-
export declare function createNodeRawQuicClientV3(driver: NativeRawQuicDriver | NativeWebTransportDriver, candidate: CanonicalArtifactCandidateV3, artifact:
|
|
5
|
+
export declare function createNodeRawQuicClientV3(driver: NativeRawQuicDriver | NativeWebTransportDriver, candidate: CanonicalArtifactCandidateV3, artifact: ConnectionArtifact, attemptNowUnixSeconds: number, options?: Readonly<{
|
|
6
6
|
roots?: NodeTLSRootsV3;
|
|
7
7
|
signal?: AbortSignal;
|
|
8
8
|
handshakeTimeoutMs?: number;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { getCACertificates } from "node:tls";
|
|
2
|
+
import { endpointIngress, tunnelAuthProfile } from "../v3/wireProfile.js";
|
|
2
3
|
import { snapshotTransportSecurityPolicyV3, TransportFailureV3, } from "../v3/security.js";
|
|
3
4
|
import { normalizeCertificateChain } from "./rawQuicTls.js";
|
|
4
5
|
import { alpnForPathV3, FLOWERSEC_V3_PATHS } from "../v3/transportConstants.js";
|
|
@@ -8,7 +9,7 @@ export async function createNodeRawQuicClientV3(driver, candidate, artifact, att
|
|
|
8
9
|
const raw = "connectRawQuic" in driver;
|
|
9
10
|
if (candidate.carrier !== (raw ? "raw_quic" : "webtransport"))
|
|
10
11
|
throw new TransportFailureV3("invalid_artifact");
|
|
11
|
-
if (candidate.wire_profile !== alpnForPathV3(artifact.path.kind)) {
|
|
12
|
+
if (candidate.wire_profile !== (artifact.v === 1 ? tunnelAuthProfile : alpnForPathV3(artifact.path.kind))) {
|
|
12
13
|
throw new TransportFailureV3("invalid_artifact");
|
|
13
14
|
}
|
|
14
15
|
let url;
|
|
@@ -18,7 +19,8 @@ export async function createNodeRawQuicClientV3(driver, candidate, artifact, att
|
|
|
18
19
|
catch {
|
|
19
20
|
throw new TransportFailureV3("invalid_artifact");
|
|
20
21
|
}
|
|
21
|
-
|
|
22
|
+
const connectPath = artifact.v === 1 ? endpointIngress.webtransport : FLOWERSEC_V3_PATHS.webtransport[artifact.path.kind];
|
|
23
|
+
if ((raw ? url.protocol !== "quic:" || url.pathname !== "" : url.protocol !== "https:" || url.href !== candidate.normalized_url || url.pathname !== connectPath) || url.search !== "" || url.hash !== "" ||
|
|
22
24
|
url.username !== "" || url.password !== "") {
|
|
23
25
|
throw new TransportFailureV3("invalid_artifact");
|
|
24
26
|
}
|
|
@@ -31,7 +33,7 @@ export async function createNodeRawQuicClientV3(driver, candidate, artifact, att
|
|
|
31
33
|
host: unbracket(url.hostname),
|
|
32
34
|
port: url.port === "" ? 443 : Number(url.port),
|
|
33
35
|
serverName: unbracket(url.hostname),
|
|
34
|
-
path: artifact.path.kind,
|
|
36
|
+
path: artifact.v === 1 ? "authenticated_tunnel" : artifact.path.kind,
|
|
35
37
|
inboundBidirectionalStreamCapacity: artifact.session.max_inbound_streams + 2,
|
|
36
38
|
handshakeTimeoutMs,
|
|
37
39
|
};
|
|
@@ -30,7 +30,9 @@ export declare class RPCHandlers {
|
|
|
30
30
|
constructor();
|
|
31
31
|
/** Bind local state for one connect or accepted session. Reuse the registry across sessions. */
|
|
32
32
|
forSession(context: object): SessionHandlerBinding<this>;
|
|
33
|
-
handleRPC(typeId: number, handler: RPCHandler
|
|
33
|
+
handleRPC(typeId: number, handler: RPCHandler, options?: Readonly<{
|
|
34
|
+
acceptsNotifications?: boolean;
|
|
35
|
+
}>): void;
|
|
34
36
|
handleNotification(typeId: number, handler: NotificationHandler): void;
|
|
35
37
|
}
|
|
36
38
|
export declare class SessionHandlersV3 extends RPCHandlers {
|
|
@@ -14,8 +14,11 @@ export class RPCHandlers {
|
|
|
14
14
|
throw new HandlerRegistrationError("invalid_handler");
|
|
15
15
|
return Object.freeze({ [bindingKey]: Object.freeze({ handlers: this, context }) });
|
|
16
16
|
}
|
|
17
|
-
handleRPC(typeId, handler) {
|
|
18
|
-
|
|
17
|
+
handleRPC(typeId, handler, options = {}) {
|
|
18
|
+
const acceptsNotifications = options.acceptsNotifications ?? false;
|
|
19
|
+
if (typeof acceptsNotifications !== "boolean")
|
|
20
|
+
throw new HandlerRegistrationError("invalid_handler");
|
|
21
|
+
registerRPC(mutableRPCHandlerState(this), typeId, handler, acceptsNotifications);
|
|
19
22
|
}
|
|
20
23
|
handleNotification(typeId, handler) {
|
|
21
24
|
registerNotification(mutableRPCHandlerState(this), typeId, handler);
|
|
@@ -60,7 +63,7 @@ export function registerSessionStreamHandlersAtomically(handlers, entries) {
|
|
|
60
63
|
const state = mutableSessionHandlerState(handlers);
|
|
61
64
|
registerStreamHandlersAtomically(state.streams, entries);
|
|
62
65
|
}
|
|
63
|
-
function registerRPC(state, typeId, handler) {
|
|
66
|
+
function registerRPC(state, typeId, handler, acceptsNotifications) {
|
|
64
67
|
validateRPCRegistration(typeId, handler);
|
|
65
68
|
if (state.requests.has(typeId) || state.notifications.has(typeId)) {
|
|
66
69
|
throw new HandlerRegistrationError("already_registered");
|
|
@@ -69,6 +72,11 @@ function registerRPC(state, typeId, handler) {
|
|
|
69
72
|
const result = await raceWithSignal(handler(payload, handlerRequest(typeId, signal, context)), signal);
|
|
70
73
|
return "error" in result ? { payload: null, error: validRPCError(result.error) } : { payload: result.payload };
|
|
71
74
|
});
|
|
75
|
+
if (acceptsNotifications) {
|
|
76
|
+
state.notifications.set(typeId, async (payload, signal, context) => {
|
|
77
|
+
await raceWithSignal(handler(payload, handlerRequest(typeId, signal, context)), signal);
|
|
78
|
+
});
|
|
79
|
+
}
|
|
72
80
|
}
|
|
73
81
|
function registerNotification(state, typeId, handler) {
|
|
74
82
|
validateRPCRegistration(typeId, handler);
|
package/dist/rpc/server.js
CHANGED
|
@@ -229,10 +229,10 @@ export class RpcServer {
|
|
|
229
229
|
payload: out.payload,
|
|
230
230
|
...(error != null ? { error } : {}),
|
|
231
231
|
};
|
|
232
|
-
await this.writeEnvelope(resp);
|
|
232
|
+
await this.writeEnvelope(resp, () => ({ ...resp, payload: null, error: { code: 413, message: "encoded RPC response exceeds write limit" } }));
|
|
233
233
|
}
|
|
234
|
-
async writeEnvelope(envelope) {
|
|
235
|
-
const write = this.writeChain.then(() => writeJsonFrame(this.transport.write, envelope, this.options.maxFrameBytes, true));
|
|
234
|
+
async writeEnvelope(envelope, overflow) {
|
|
235
|
+
const write = this.writeChain.then(() => writeJsonFrame(this.transport.write, envelope, this.options.maxFrameBytes, true, overflow));
|
|
236
236
|
this.writeChain = write;
|
|
237
237
|
try {
|
|
238
238
|
await write;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { type ArtifactLeaseV3 } from "../v3/artifactLease.js";
|
|
2
|
+
import type { ArtifactSourceV3, ArtifactSourceResultV3 } from "../v3/connectionController.js";
|
|
3
|
+
import { type TunnelAuth } from "./credentials.js";
|
|
4
|
+
type Spend = (signal?: AbortSignal) => Promise<void>;
|
|
5
|
+
type Cleanup = () => Promise<void>;
|
|
6
|
+
export declare class TunnelAuthArtifact {
|
|
7
|
+
private readonly artifactBrand;
|
|
8
|
+
private constructor();
|
|
9
|
+
static parse(raw: string | Uint8Array): TunnelAuthArtifact;
|
|
10
|
+
lookupKey(): string;
|
|
11
|
+
}
|
|
12
|
+
export declare const parseTunnelAuthArtifact: typeof TunnelAuthArtifact.parse;
|
|
13
|
+
export declare class TunnelAuthLease {
|
|
14
|
+
private readonly leaseBrand;
|
|
15
|
+
constructor(handle: TunnelAuthArtifact, spend: Spend, cleanup?: Cleanup);
|
|
16
|
+
}
|
|
17
|
+
export type TunnelAuthOptions = Readonly<{
|
|
18
|
+
suite?: 1 | 2 | 3;
|
|
19
|
+
expectedChannel?: string;
|
|
20
|
+
expectedAudience?: string;
|
|
21
|
+
}>;
|
|
22
|
+
export type TunnelAuthSource = Readonly<{
|
|
23
|
+
acquire(options: Readonly<{
|
|
24
|
+
signal: AbortSignal;
|
|
25
|
+
}>): Promise<Exclude<ArtifactSourceResultV3, {
|
|
26
|
+
kind: "lease";
|
|
27
|
+
}> | Readonly<{
|
|
28
|
+
kind: "lease";
|
|
29
|
+
lease: TunnelAuthLease;
|
|
30
|
+
}>>;
|
|
31
|
+
}>;
|
|
32
|
+
export declare function bindEndpointLease(lease: TunnelAuthLease, auth: TunnelAuth, options: TunnelAuthOptions): ArtifactLeaseV3;
|
|
33
|
+
export declare function bindEndpointSource(source: TunnelAuthSource, auth: TunnelAuth, options: TunnelAuthOptions): ArtifactSourceV3;
|
|
34
|
+
export {};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { sha256 } from "@noble/hashes/sha2.js";
|
|
2
|
+
import { base64urlEncode } from "../utils/base64url.js";
|
|
3
|
+
import { decodeTunnelAuthArtifactJSON } from "../v3/artifact.js";
|
|
4
|
+
import { createArtifactLeaseV3Internal } from "../v3/artifactLease.js";
|
|
5
|
+
import { ArtifactParseErrorV3 } from "../v3/publicApi.js";
|
|
6
|
+
import { ConnectErrorV3 } from "../v3/security.js";
|
|
7
|
+
import { tunnelAuthProfile } from "../v3/wireProfile.js";
|
|
8
|
+
import { hasTunnelAuth } from "./credentials.js";
|
|
9
|
+
const artifacts = new WeakMap();
|
|
10
|
+
const leases = new WeakMap();
|
|
11
|
+
export class TunnelAuthArtifact {
|
|
12
|
+
constructor() { }
|
|
13
|
+
static parse(raw) {
|
|
14
|
+
try {
|
|
15
|
+
const artifact = decodeTunnelAuthArtifactJSON(raw);
|
|
16
|
+
const handle = new TunnelAuthArtifact();
|
|
17
|
+
artifacts.set(handle, artifact);
|
|
18
|
+
return handle;
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
throw new ArtifactParseErrorV3("invalid_artifact");
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
lookupKey() {
|
|
25
|
+
const artifact = artifacts.get(this);
|
|
26
|
+
if (!artifact)
|
|
27
|
+
throw invalid();
|
|
28
|
+
return `${tunnelAuthProfile}:${base64urlEncode(sha256(new TextEncoder().encode(artifact.path.token)))}`;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
export const parseTunnelAuthArtifact = TunnelAuthArtifact.parse;
|
|
32
|
+
export class TunnelAuthLease {
|
|
33
|
+
constructor(handle, spend, cleanup) {
|
|
34
|
+
const artifact = artifacts.get(handle);
|
|
35
|
+
if (!artifact || typeof spend !== "function" || (cleanup !== undefined && typeof cleanup !== "function"))
|
|
36
|
+
throw invalid();
|
|
37
|
+
leases.set(this, { artifact, spend, ...(cleanup ? { cleanup } : {}) });
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
export function bindEndpointLease(lease, auth, options) {
|
|
41
|
+
const state = leases.get(lease);
|
|
42
|
+
if (!state || !hasTunnelAuth(auth))
|
|
43
|
+
throw invalid();
|
|
44
|
+
const { artifact } = state;
|
|
45
|
+
if (artifact.path.role !== auth.role || artifact.session.auth_mode !== auth.mode || artifact.session.default_suite !== (options.suite ?? 1) ||
|
|
46
|
+
(options.expectedChannel !== undefined && options.expectedChannel !== artifact.session.channel_id) ||
|
|
47
|
+
(options.expectedAudience !== undefined && options.expectedAudience !== artifact.path.listener_audience))
|
|
48
|
+
throw invalid();
|
|
49
|
+
leases.delete(lease);
|
|
50
|
+
return createArtifactLeaseV3Internal(artifact, state.spend, state.cleanup, auth);
|
|
51
|
+
}
|
|
52
|
+
export function bindEndpointSource(source, auth, options) {
|
|
53
|
+
if (!source || typeof source.acquire !== "function" || !hasTunnelAuth(auth))
|
|
54
|
+
throw invalid();
|
|
55
|
+
const policy = {
|
|
56
|
+
suite: options.suite ?? 1,
|
|
57
|
+
...(options.expectedChannel === undefined ? {} : { expectedChannel: options.expectedChannel }),
|
|
58
|
+
...(options.expectedAudience === undefined ? {} : { expectedAudience: options.expectedAudience }),
|
|
59
|
+
};
|
|
60
|
+
return {
|
|
61
|
+
async acquire(operation) {
|
|
62
|
+
const result = await source.acquire(operation);
|
|
63
|
+
if (result.kind !== "lease")
|
|
64
|
+
return result;
|
|
65
|
+
try {
|
|
66
|
+
return { kind: "lease", lease: bindEndpointLease(result.lease, auth, policy) };
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
return { kind: "failure", code: "artifact_invalid", disposition: { kind: "terminal" } };
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
function invalid() { return new ConnectErrorV3("artifact_invalid", { kind: "terminal" }); }
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { EndpointIdentity, EndpointPublicKey, type Binding } from "./hpke.js";
|
|
2
|
+
export declare class TunnelAuth {
|
|
3
|
+
private readonly authBrand;
|
|
4
|
+
readonly role: 1 | 2;
|
|
5
|
+
readonly mode: Binding["mode"];
|
|
6
|
+
private constructor();
|
|
7
|
+
static initiator(peer: EndpointPublicKey): TunnelAuth;
|
|
8
|
+
static responder(identity: EndpointIdentity): TunnelAuth;
|
|
9
|
+
static mutualInitiator(identity: EndpointIdentity, peer: EndpointPublicKey): TunnelAuth;
|
|
10
|
+
static mutualResponder(identity: EndpointIdentity, peer: EndpointPublicKey): TunnelAuth;
|
|
11
|
+
}
|
|
12
|
+
export declare function hasTunnelAuth(value: TunnelAuth): boolean;
|
|
13
|
+
export declare function initiateTunnelAuth(auth: TunnelAuth, binding: Binding): Promise<{
|
|
14
|
+
enc: Uint8Array;
|
|
15
|
+
secret: Uint8Array;
|
|
16
|
+
}>;
|
|
17
|
+
export declare function respondTunnelAuth(auth: TunnelAuth, binding: Binding, enc: Uint8Array): Promise<Uint8Array<ArrayBufferLike>>;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { EndpointIdentity, EndpointPublicKey, initiate, respond } from "./hpke.js";
|
|
2
|
+
const keys = new WeakMap();
|
|
3
|
+
export class TunnelAuth {
|
|
4
|
+
role;
|
|
5
|
+
mode;
|
|
6
|
+
constructor(role, mode, identity, peer) {
|
|
7
|
+
if ((role === 2 || mode === "mutual") !== (identity instanceof EndpointIdentity) ||
|
|
8
|
+
(role === 1 || mode === "mutual") !== (peer instanceof EndpointPublicKey)) {
|
|
9
|
+
throw new Error("invalid tunnel endpoint identity");
|
|
10
|
+
}
|
|
11
|
+
if (identity && peer) {
|
|
12
|
+
const local = identity.publicKey().exportPublic();
|
|
13
|
+
if (peer.exportPublic().every((octet, index) => octet === local[index]))
|
|
14
|
+
throw new Error("identical tunnel endpoint identities");
|
|
15
|
+
}
|
|
16
|
+
this.role = role;
|
|
17
|
+
this.mode = mode;
|
|
18
|
+
keys.set(this, { identity, peer });
|
|
19
|
+
Object.freeze(this);
|
|
20
|
+
}
|
|
21
|
+
static initiator(peer) { return new TunnelAuth(1, "responder", undefined, peer); }
|
|
22
|
+
static responder(identity) { return new TunnelAuth(2, "responder", identity); }
|
|
23
|
+
static mutualInitiator(identity, peer) { return new TunnelAuth(1, "mutual", identity, peer); }
|
|
24
|
+
static mutualResponder(identity, peer) { return new TunnelAuth(2, "mutual", identity, peer); }
|
|
25
|
+
}
|
|
26
|
+
export function hasTunnelAuth(value) {
|
|
27
|
+
return keys.has(value);
|
|
28
|
+
}
|
|
29
|
+
export function initiateTunnelAuth(auth, binding) {
|
|
30
|
+
const material = keys.get(auth);
|
|
31
|
+
if (!material?.peer || auth.role !== 1 || binding.mode !== auth.mode)
|
|
32
|
+
throw new Error("invalid endpoint auth role");
|
|
33
|
+
return initiate(binding, material.peer, material.identity);
|
|
34
|
+
}
|
|
35
|
+
export function respondTunnelAuth(auth, binding, enc) {
|
|
36
|
+
const material = keys.get(auth);
|
|
37
|
+
if (!material?.identity || auth.role !== 2 || binding.mode !== auth.mode)
|
|
38
|
+
throw new Error("invalid endpoint auth role");
|
|
39
|
+
return respond(binding, enc, material.identity, material.peer);
|
|
40
|
+
}
|