@floegence/flowersec-core 8.1.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.
Files changed (48) hide show
  1. package/THIRD_PARTY_NOTICES.md +8 -5
  2. package/dist/browser/connectSessionV3.d.ts +4 -0
  3. package/dist/browser/connectSessionV3.js +12 -4
  4. package/dist/browser/index.d.ts +1 -1
  5. package/dist/browser/index.js +1 -1
  6. package/dist/facade.d.ts +4 -0
  7. package/dist/facade.js +3 -0
  8. package/dist/node/connectSessionV3.d.ts +4 -0
  9. package/dist/node/connectSessionV3.js +7 -0
  10. package/dist/node/index.d.ts +1 -1
  11. package/dist/node/index.js +1 -1
  12. package/dist/node/nativeTransportAddon.d.ts +4 -3
  13. package/dist/node/nativeTransportAddon.js +3 -2
  14. package/dist/node/rawQuicAdapterV3.d.ts +2 -2
  15. package/dist/node/rawQuicAdapterV3.js +5 -3
  16. package/dist/tunnelAuth/artifact.d.ts +34 -0
  17. package/dist/tunnelAuth/artifact.js +74 -0
  18. package/dist/tunnelAuth/credentials.d.ts +17 -0
  19. package/dist/tunnelAuth/credentials.js +40 -0
  20. package/dist/tunnelAuth/hpke.d.ts +36 -0
  21. package/dist/tunnelAuth/hpke.js +124 -0
  22. package/dist/v3/artifact.d.ts +27 -8
  23. package/dist/v3/artifact.js +78 -42
  24. package/dist/v3/artifactLease.d.ts +4 -2
  25. package/dist/v3/artifactLease.js +13 -1
  26. package/dist/v3/browserRuntime.js +5 -3
  27. package/dist/v3/connectionController.d.ts +2 -2
  28. package/dist/v3/connectionController.js +8 -4
  29. package/dist/v3/handshake.d.ts +22 -21
  30. package/dist/v3/handshake.js +58 -60
  31. package/dist/v3/nodeRuntime.js +4 -1
  32. package/dist/v3/protocol.d.ts +17 -16
  33. package/dist/v3/protocol.js +60 -64
  34. package/dist/v3/runtimeAdapters.d.ts +2 -2
  35. package/dist/v3/runtimeAdapters.js +2 -1
  36. package/dist/v3/security.d.ts +1 -1
  37. package/dist/v3/session.d.ts +14 -4
  38. package/dist/v3/session.js +174 -114
  39. package/dist/v3/sessionConnector.d.ts +2 -2
  40. package/dist/v3/sessionConnector.js +24 -13
  41. package/dist/v3/tunnelIngress.js +2 -1
  42. package/dist/v3/unreliableMessage.d.ts +3 -0
  43. package/dist/v3/unreliableMessage.js +24 -22
  44. package/dist/v3/wireProfile.d.ts +52 -0
  45. package/dist/v3/wireProfile.js +20 -0
  46. package/package.json +5 -3
  47. package/sbom/cyclonedx.json +133 -31
  48. package/sbom/spdx.json +110 -39
@@ -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.1.0 (Declared: MIT; selected: MIT; source: https://github.com/floegence/flowersec.git)
7
- - @floegence/flowersec-node-native-darwin-arm64 8.1.0 (Declared: MIT; selected: MIT; source: https://github.com/floegence/flowersec.git)
8
- - @floegence/flowersec-node-native-darwin-x64 8.1.0 (Declared: MIT; selected: MIT; source: https://github.com/floegence/flowersec.git)
9
- - @floegence/flowersec-node-native-linux-arm64-gnu 8.1.0 (Declared: MIT; selected: MIT; source: https://github.com/floegence/flowersec.git)
10
- - @floegence/flowersec-node-native-linux-x64-gnu 8.1.0 (Declared: MIT; selected: MIT; source: https://github.com/floegence/flowersec.git)
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,3 +1,5 @@
1
+ import { bindEndpointLease, bindEndpointSource } from "../tunnelAuth/artifact.js";
2
+ import { endpointIngress } from "../v3/wireProfile.js";
1
3
  import { SDK_DEFAULTS } from "../defaults.js";
2
4
  import { connectorRPCLimits } from "../v3/connectorRPCLimits.js";
3
5
  import { createRPCRouter, freezeRPCHandlers, RPCHandlers } from "../public/sessionHandlers.js";
@@ -19,6 +21,12 @@ export async function connectV3(lease, options = {}) {
19
21
  export async function createConnectionControllerV3(source, options = {}) {
20
22
  return createBrowserController(source, options);
21
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
+ }
22
30
  export async function createBrowserController(source, options, rotation) {
23
31
  requireControllerHandlers(options);
24
32
  const registry = await BrowserRuntimeCapabilityRegistryV3.create();
@@ -186,7 +194,7 @@ function browserRuntime(registry, options) {
186
194
  if (candidate.carrier !== "websocket" || candidate.tls.mode !== "ca") {
187
195
  throw new TransportFailureV3("tls_unsupported");
188
196
  }
189
- validateBrowserWebSocketURL(candidate.normalized_url, artifact.path.kind);
197
+ validateBrowserWebSocketURL(candidate.normalized_url, artifact.path.kind, artifact.v === 1);
190
198
  return await dialBrowserWebSocket(candidate, artifact, candidate.normalized_url, signal);
191
199
  },
192
200
  };
@@ -216,7 +224,7 @@ async function dialBrowserWebSocket(candidate, artifact, targetURL, signal) {
216
224
  const Constructor = globalThis.WebSocket;
217
225
  if (Constructor === undefined)
218
226
  throw new TransportFailureV3("tls_unsupported");
219
- 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";
220
228
  let socket;
221
229
  try {
222
230
  socket = new Constructor(targetURL, protocol);
@@ -244,7 +252,7 @@ function profileWebSocketURL(candidateURL, profileOrigin) {
244
252
  return undefined;
245
253
  }
246
254
  }
247
- function validateBrowserWebSocketURL(raw, path) {
255
+ function validateBrowserWebSocketURL(raw, path, authenticated) {
248
256
  let parsed;
249
257
  try {
250
258
  parsed = new URL(raw);
@@ -252,7 +260,7 @@ function validateBrowserWebSocketURL(raw, path) {
252
260
  catch {
253
261
  throw new TransportFailureV3("invalid_artifact");
254
262
  }
255
- const expectedPath = path === "direct" ? "/flowersec/v5/direct" : "/flowersec/v5/tunnel";
263
+ const expectedPath = authenticated ? endpointIngress.websocket : `/flowersec/v5/${path}`;
256
264
  if (parsed.href !== raw || parsed.protocol !== "wss:" || parsed.username !== "" || parsed.password !== "" ||
257
265
  parsed.pathname !== expectedPath || parsed.search !== "" || parsed.hash !== "") {
258
266
  throw new TransportFailureV3("invalid_artifact");
@@ -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";
@@ -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";
@@ -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";
@@ -35,3 +37,5 @@ export type ConnectionControllerOptionsV3 = Readonly<{
35
37
  }>;
36
38
  export declare function connectV3(lease: ArtifactLeaseV3, options?: SessionOptionsV3): Promise<Session>;
37
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,3 +1,4 @@
1
+ import { bindEndpointLease, bindEndpointSource } from "../tunnelAuth/artifact.js";
1
2
  import { SDK_DEFAULTS } from "../defaults.js";
2
3
  import { connectorRPCLimits } from "../v3/connectorRPCLimits.js";
3
4
  import { createConnectionControllerV3 as createCoreControllerV3, } from "../v3/connectionController.js";
@@ -35,6 +36,12 @@ function validateWebTransportOptIn(options) {
35
36
  if (options.webTransport !== undefined && typeof options.webTransport !== "boolean")
36
37
  throw new TypeError("webTransport must be a boolean");
37
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
+ }
38
45
  function nodeRuntime(options) {
39
46
  const connectTimeoutMilliseconds = options.connectTimeoutMs ?? SDK_DEFAULTS.transport.connectTimeoutMs;
40
47
  if (!Number.isSafeInteger(connectTimeoutMilliseconds) || connectTimeoutMilliseconds < 1) {
@@ -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;
@@ -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: PathKind;
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: PathKind;
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
- if (native.wireVersion !== 5 || native.kind !== kind || native.path !== path) {
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: native.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 { ArtifactV3, CanonicalArtifactCandidateV3 } from "../v3/artifact.js";
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: ArtifactV3, attemptNowUnixSeconds: number, options?: Readonly<{
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
- if ((raw ? url.protocol !== "quic:" || url.pathname !== "" : url.protocol !== "https:" || url.href !== candidate.normalized_url || url.pathname !== FLOWERSEC_V3_PATHS.webtransport[artifact.path.kind]) || url.search !== "" || url.hash !== "" ||
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
  };
@@ -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
+ }
@@ -0,0 +1,36 @@
1
+ import { tunnelAuthProfile } from "../v3/wireProfile.js";
2
+ export { tunnelAuthProfile };
3
+ export declare class EndpointHandshakeError extends Error {
4
+ constructor();
5
+ }
6
+ export declare function requireEndpointCrypto(): Promise<void>;
7
+ export type Binding = Readonly<{
8
+ mode: "responder" | "mutual";
9
+ suite: 1 | 2 | 3;
10
+ channelID: string;
11
+ rendezvousGroupID: string;
12
+ listenerAudience: string;
13
+ clientEndpointID: string;
14
+ serverEndpointID: string;
15
+ contractHash: Uint8Array;
16
+ }>;
17
+ export declare function bindingInfo(binding: Binding): Uint8Array;
18
+ export declare class EndpointPublicKey {
19
+ #private;
20
+ private constructor();
21
+ static importPublic(raw: Uint8Array): EndpointPublicKey;
22
+ exportPublic(): Uint8Array;
23
+ }
24
+ export declare class EndpointIdentity {
25
+ #private;
26
+ private constructor();
27
+ static generate(): EndpointIdentity;
28
+ static importPrivate(raw: Uint8Array): EndpointIdentity;
29
+ publicKey(): EndpointPublicKey;
30
+ exportPrivate(): Uint8Array;
31
+ }
32
+ export declare function initiate(binding: Binding, peer: EndpointPublicKey, local?: EndpointIdentity): Promise<{
33
+ enc: Uint8Array;
34
+ secret: Uint8Array;
35
+ }>;
36
+ export declare function respond(binding: Binding, encapsulation: Uint8Array, local: EndpointIdentity, peer?: EndpointPublicKey): Promise<Uint8Array>;
@@ -0,0 +1,124 @@
1
+ import { Aes128Gcm, CipherSuite, HkdfSha256 } from "@hpke/core";
2
+ import { DhkemX25519HkdfSha256 } from "@hpke/dhkem-x25519";
3
+ import { x25519 } from "@noble/curves/ed25519.js";
4
+ import { base64urlEncode } from "../utils/base64url.js";
5
+ import { concatBytes, u32be } from "../utils/bin.js";
6
+ import { jcsUTF8V3 } from "../v3/jcs.js";
7
+ import { tunnelAuthProfile } from "../v3/wireProfile.js";
8
+ export { tunnelAuthProfile };
9
+ export class EndpointHandshakeError extends Error {
10
+ constructor() { super("tunnel endpoint authentication failed"); }
11
+ }
12
+ const text = new TextEncoder();
13
+ const exporter = text.encode("flowersec-tunnel-auth-v1-auth-secret");
14
+ const infoLabel = text.encode("flowersec-tunnel-auth-v1-hpke\0");
15
+ const kem = new DhkemX25519HkdfSha256();
16
+ const suite = new CipherSuite({ kem, kdf: new HkdfSha256(), aead: new Aes128Gcm() });
17
+ let capability;
18
+ export async function requireEndpointCrypto() {
19
+ capability ??= (async () => {
20
+ const recipient = await kem.generateKeyPair();
21
+ const context = await suite.createSenderContext({ recipientPublicKey: recipient.publicKey });
22
+ new Uint8Array(await context.export(exporter, 32)).fill(0);
23
+ })().catch(error => {
24
+ capability = undefined;
25
+ throw error;
26
+ });
27
+ return capability;
28
+ }
29
+ export function bindingInfo(binding) {
30
+ const identifiers = [binding.channelID, binding.rendezvousGroupID, binding.listenerAudience, binding.clientEndpointID, binding.serverEndpointID];
31
+ if (identifiers.some(value => typeof value !== "string" || value.length < 1 || value.length > 128 || /[^A-Za-z0-9._~-]/.test(value)) ||
32
+ binding.clientEndpointID === binding.serverEndpointID || binding.contractHash.length !== 32 ||
33
+ ![1, 2, 3].includes(binding.suite) || !["responder", "mutual"].includes(binding.mode)) {
34
+ throw new Error("invalid tunnel endpoint binding");
35
+ }
36
+ const payload = jcsUTF8V3({
37
+ auth_mode: binding.mode, channel_id: binding.channelID, client_endpoint_instance_id: binding.clientEndpointID,
38
+ contract_hash_b64u: base64urlEncode(binding.contractHash), listener_audience: binding.listenerAudience,
39
+ profile: tunnelAuthProfile, rendezvous_group_id: binding.rendezvousGroupID, server_endpoint_instance_id: binding.serverEndpointID,
40
+ suite: binding.suite,
41
+ });
42
+ return concatBytes([infoLabel, u32be(payload.length), payload]);
43
+ }
44
+ function checkPublic(raw) {
45
+ if (raw.length !== 32 || raw[31] > 127 ||
46
+ (raw[31] === 127 && raw[0] >= 237 && raw.subarray(1, 31).every(octet => octet === 255))) {
47
+ throw new Error("invalid endpoint public key");
48
+ }
49
+ const probe = new Uint8Array(32);
50
+ probe[0] = 8;
51
+ try {
52
+ x25519.getSharedSecret(probe, raw).fill(0);
53
+ }
54
+ catch {
55
+ throw new Error("invalid endpoint public key");
56
+ }
57
+ }
58
+ export class EndpointPublicKey {
59
+ #raw;
60
+ constructor(raw) { this.#raw = raw; }
61
+ static importPublic(raw) {
62
+ const copy = new Uint8Array(raw);
63
+ checkPublic(copy);
64
+ return new EndpointPublicKey(copy);
65
+ }
66
+ exportPublic() { return new Uint8Array(this.#raw); }
67
+ }
68
+ export class EndpointIdentity {
69
+ #raw;
70
+ #public;
71
+ constructor(raw) {
72
+ this.#raw = raw;
73
+ this.#public = EndpointPublicKey.importPublic(x25519.getPublicKey(raw));
74
+ }
75
+ static generate() { return new EndpointIdentity(x25519.utils.randomSecretKey()); }
76
+ static importPrivate(raw) {
77
+ if (raw.length !== 32)
78
+ throw new Error("invalid endpoint identity");
79
+ return new EndpointIdentity(new Uint8Array(raw));
80
+ }
81
+ publicKey() { return this.#public; }
82
+ exportPrivate() { return new Uint8Array(this.#raw); }
83
+ }
84
+ async function privateKey(identity) {
85
+ const raw = identity.exportPrivate();
86
+ try {
87
+ return await kem.deserializePrivateKey(raw);
88
+ }
89
+ finally {
90
+ raw.fill(0);
91
+ }
92
+ }
93
+ function distinct(local, peer) {
94
+ const other = peer.exportPublic();
95
+ return local.publicKey().exportPublic().some((value, index) => value !== other[index]);
96
+ }
97
+ export async function initiate(binding, peer, local) {
98
+ try {
99
+ const info = bindingInfo(binding);
100
+ if ((binding.mode === "mutual") !== (local !== undefined) || (local && !distinct(local, peer)))
101
+ throw new Error();
102
+ const recipientPublicKey = await kem.deserializePublicKey(peer.exportPublic());
103
+ const channel = await suite.createSenderContext({ info, recipientPublicKey, ...(local ? { senderKey: await privateKey(local) } : {}) });
104
+ return { enc: new Uint8Array(channel.enc), secret: new Uint8Array(await channel.export(exporter, 32)) };
105
+ }
106
+ catch {
107
+ throw new EndpointHandshakeError();
108
+ }
109
+ }
110
+ export async function respond(binding, encapsulation, local, peer) {
111
+ try {
112
+ const info = bindingInfo(binding);
113
+ const enc = new Uint8Array(encapsulation);
114
+ checkPublic(enc);
115
+ if ((binding.mode === "mutual") !== (peer !== undefined) || (peer && !distinct(local, peer)))
116
+ throw new Error();
117
+ const recipientKey = await privateKey(local);
118
+ const channel = await suite.createRecipientContext({ info, enc, recipientKey, ...(peer ? { senderPublicKey: await kem.deserializePublicKey(peer.exportPublic()) } : {}) });
119
+ return new Uint8Array(await channel.export(exporter, 32));
120
+ }
121
+ catch {
122
+ throw new EndpointHandshakeError();
123
+ }
124
+ }