@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
@@ -1,3 +1,4 @@
1
+ import { tunnelAuthV1, type WireProfile } from "./wireProfile.js";
1
2
  import { FLOWERSEC_V3_PROFILE } from "./transportConstants.js";
2
3
  export type ArtifactCarrierV3 = "websocket" | "raw_quic" | "webtransport";
3
4
  export type ArtifactPathKindV3 = "direct" | "tunnel";
@@ -80,8 +81,24 @@ export type ArtifactV3 = Readonly<{
80
81
  scoped: readonly ScopeMetadataV3[];
81
82
  correlation: CorrelationContextV3;
82
83
  }>;
84
+ export type EndpointSessionContract = Omit<SessionContractV3, "e2ee_psk_b64u"> & Readonly<{
85
+ auth_mode: "responder" | "mutual";
86
+ }>;
87
+ export type EndpointArtifact = Readonly<{
88
+ v: 1;
89
+ profile: typeof tunnelAuthV1.name;
90
+ session: EndpointSessionContract;
91
+ path: TunnelArtifactPathV3;
92
+ scoped: readonly ScopeMetadataV3[];
93
+ correlation: Readonly<{
94
+ v: 1;
95
+ tags: readonly CorrelationTagV3[];
96
+ }>;
97
+ }>;
98
+ export type ConnectionArtifact = ArtifactV3 | EndpointArtifact;
99
+ export declare function validatedCandidates(artifact: ConnectionArtifact): CanonicalCandidateSetV3;
83
100
  type CommonFSB3RequestV3 = Readonly<{
84
- profile: typeof FLOWERSEC_V3_PROFILE;
101
+ profile: WireProfile["name"];
85
102
  channel_id: string;
86
103
  session_contract_hash_b64u: string;
87
104
  rendezvous_group_id: string;
@@ -128,18 +145,20 @@ export type LabeledHashV3 = Readonly<{
128
145
  export type CanonicalCandidateSetV3 = LabeledHashV3 & Readonly<{
129
146
  candidates: readonly CanonicalArtifactCandidateV3[];
130
147
  }>;
131
- export declare function computeSessionContractHashV3(session: SessionContractV3): LabeledHashV3;
132
- export declare function canonicalizeCandidatesV3(kind: ArtifactPathKindV3, candidates: readonly ArtifactCandidateV3[]): CanonicalCandidateSetV3;
148
+ export declare function computeSessionContractHashV3(session: SessionContractV3 | EndpointSessionContract, profile?: WireProfile): LabeledHashV3;
149
+ export declare function canonicalizeCandidatesV3(kind: ArtifactPathKindV3, candidates: readonly ArtifactCandidateV3[], profile?: WireProfile): CanonicalCandidateSetV3;
133
150
  export declare function decodeArtifactV3JSON(raw: string | Uint8Array): ArtifactV3;
134
151
  export declare function encodeArtifactV3JSON(artifact: ArtifactV3): Uint8Array;
135
152
  export declare function validateArtifactV3(artifact: ArtifactV3): CanonicalCandidateSetV3;
153
+ export declare function decodeTunnelAuthArtifactJSON(raw: string | Uint8Array): EndpointArtifact;
136
154
  export declare function buildFSB3RequestV3(artifact: ArtifactV3, chosenCandidateID: string): FSB3RequestV3;
137
- export declare function encodeFSB3RequestV3(request: FSB3RequestV3): Uint8Array;
138
- export declare function decodeFSB3RequestV3(raw: Uint8Array): DecodedFSB3RequestV3;
139
- export declare function admissionBindingV3(rawFSB3: Uint8Array): Uint8Array;
155
+ export declare function buildEndpointAdmission(artifact: EndpointArtifact, chosenCandidateID: string): Uint8Array;
156
+ export declare function encodeFSB3RequestV3(request: FSB3RequestV3, profile?: WireProfile): Uint8Array;
157
+ export declare function decodeFSB3RequestV3(raw: Uint8Array, profile?: WireProfile): DecodedFSB3RequestV3;
158
+ export declare function admissionBindingV3(rawFSB3: Uint8Array, profile?: WireProfile): Uint8Array;
140
159
  export declare function acceptorAdmissionsHashV3(framesByCandidateID: ReadonlyMap<string, Uint8Array>): Uint8Array;
141
- export declare function encodeFSA3ResponseV3(response: AdmissionResponseV3, admissionReasons?: ReadonlySet<string>): Uint8Array;
142
- export declare function decodeFSA3ResponseV3(raw: Uint8Array): AdmissionResponseV3;
160
+ export declare function encodeFSA3ResponseV3(response: AdmissionResponseV3, admissionReasons?: ReadonlySet<string>, profile?: WireProfile): Uint8Array;
161
+ export declare function decodeFSA3ResponseV3(raw: Uint8Array, profile?: WireProfile): AdmissionResponseV3;
143
162
  export declare function tlsPolicyDigestV3(policy: TransportSecurityPolicyV3): LabeledHashV3;
144
163
  export declare function activePinsV3(policy: TransportSecurityPolicyV3, attemptNowUnixSeconds: number): readonly CertificatePinV3[];
145
164
  export {};
@@ -5,7 +5,15 @@ import { unicode151Assigned } from "../generated/unicode151.js";
5
5
  import { toASCII, toUnicode } from "../vendor/tr46.js";
6
6
  import { canonicalizeJCSV3 } from "./jcs.js";
7
7
  import { preflightJSONV3 } from "./jsonPreflight.js";
8
+ import { matchesFramePrefix, transportV5, tunnelAuthV1, writeFramePrefix } from "./wireProfile.js";
8
9
  import { FLOWERSEC_V3_CRYPTO_LABELS, FLOWERSEC_V3_PROFILE, wireProfileForPathV3, } from "./transportConstants.js";
10
+ export function validatedCandidates(artifact) {
11
+ if (artifact.v === 5)
12
+ return validateArtifactV3(artifact);
13
+ if (artifact.profile !== tunnelAuthV1.name || artifact.path.kind !== "tunnel")
14
+ throw invalidArtifact("endpoint profile");
15
+ return validateArtifactFields(artifact, tunnelAuthV1);
16
+ }
9
17
  export var AdmissionStatusV3;
10
18
  (function (AdmissionStatusV3) {
11
19
  AdmissionStatusV3[AdmissionStatusV3["Success"] = 0] = "Success";
@@ -49,25 +57,28 @@ const registryIDPattern = /^[A-Za-z0-9._~-]+$/;
49
57
  const candidateIDPattern = /^[a-z0-9][a-z0-9._-]*$/;
50
58
  const scopePattern = /^[a-z][a-z0-9._-]{0,63}$/;
51
59
  const correlationKeyPattern = /^[a-z][a-z0-9._-]{0,31}$/;
52
- export function computeSessionContractHashV3(session) {
53
- validateSession(session);
60
+ export function computeSessionContractHashV3(session, profile = transportV5) {
61
+ validateSession(session, profile);
54
62
  const canonicalJSON = canonicalizeJCSV3({
63
+ ...("auth_mode" in session ? { auth_mode: session.auth_mode } : {}),
55
64
  allowed_suites: session.allowed_suites,
56
65
  channel_id: session.channel_id,
57
66
  default_suite: session.default_suite,
58
67
  establish_timeout_seconds: session.establish_timeout_seconds,
59
68
  idle_timeout_seconds: session.idle_timeout_seconds,
60
69
  max_inbound_streams: session.max_inbound_streams,
61
- profile: PROFILE,
70
+ profile: profile.name,
62
71
  rekey_completion_timeout_seconds: session.rekey_completion_timeout_seconds,
63
72
  rekey_prepare_timeout_seconds: session.rekey_prepare_timeout_seconds,
64
73
  selected_features: session.selected_features,
65
74
  });
66
- return labeledHash(FLOWERSEC_V3_CRYPTO_LABELS["session-contract"], canonicalJSON);
75
+ return labeledHash(profile.labels["session-contract"], canonicalJSON);
67
76
  }
68
- export function canonicalizeCandidatesV3(kind, candidates) {
77
+ export function canonicalizeCandidatesV3(kind, candidates, profile = transportV5) {
69
78
  if (kind !== "direct" && kind !== "tunnel")
70
79
  throw invalidCandidate("path kind");
80
+ if (profile === tunnelAuthV1 && kind !== "tunnel")
81
+ throw invalidCandidate("path kind");
71
82
  if (!Array.isArray(candidates) || candidates.length < 1 || candidates.length > MAX_CANDIDATES) {
72
83
  throw invalidCandidate("candidate count");
73
84
  }
@@ -85,13 +96,13 @@ export function canonicalizeCandidatesV3(kind, candidates) {
85
96
  if (utf8Length(candidate.url) < 1 || utf8Length(candidate.url) > 2_048) {
86
97
  throw invalidCandidate("candidate URL length");
87
98
  }
88
- const normalizedURL = normalizeCandidateURL(kind, candidate.carrier, candidate.url);
99
+ const normalizedURL = normalizeCandidateURL(kind, candidate.carrier, candidate.url, profile);
89
100
  if (utf8Length(normalizedURL) > 2_048)
90
101
  throw invalidCandidate("normalized URL length");
91
102
  if (candidate.normalized_url !== undefined && candidate.normalized_url !== normalizedURL) {
92
103
  throw invalidCandidate("normalized URL mismatch");
93
104
  }
94
- const wireProfile = wireProfileForPathV3(kind);
105
+ const wireProfile = profile === tunnelAuthV1 ? profile.name : wireProfileForPathV3(kind);
95
106
  if (candidate.wire_profile !== wireProfile)
96
107
  throw invalidCandidate("wire profile");
97
108
  validateTLSPolicy(candidate.tls, "invalid_candidate");
@@ -118,7 +129,7 @@ export function canonicalizeCandidatesV3(kind, candidates) {
118
129
  }
119
130
  return {
120
131
  candidates: canonical,
121
- ...labeledHash(FLOWERSEC_V3_CRYPTO_LABELS.candidates, canonicalJSON),
132
+ ...labeledHash(profile.labels.candidates, canonicalJSON),
122
133
  };
123
134
  }
124
135
  export function decodeArtifactV3JSON(raw) {
@@ -187,11 +198,30 @@ export function validateArtifactV3(artifact) {
187
198
  validateArtifactShape(artifact);
188
199
  if (artifact.v !== 5 || artifact.profile !== PROFILE)
189
200
  throw invalidArtifact("version or profile");
190
- const sessionHash = computeSessionContractHashV3(artifact.session);
201
+ return validateArtifactFields(artifact, transportV5);
202
+ }
203
+ export function decodeTunnelAuthArtifactJSON(raw) {
204
+ const text = decodeBoundedJSON(raw);
205
+ const wire = requireRecord(parseStrictJSON(text, true), "artifact");
206
+ assertExactKeys(wire, ["v", "profile", "session", "path", "scoped", "correlation"], "artifact", "invalid_artifact");
207
+ if (wire.v !== 1 || wire.profile !== tunnelAuthV1.name || canonicalizeJCSV3(wire) !== text)
208
+ throw invalidArtifact("version, profile or canonical encoding");
209
+ const path = decodePathValue(wire.path);
210
+ if (path.kind !== "tunnel")
211
+ throw invalidArtifact("tunnel path");
212
+ const session = requireRecord(wire.session, "session");
213
+ const correlation = requireRecord(wire.correlation, "correlation");
214
+ const artifact = { v: 1, profile: tunnelAuthV1.name, path, session, correlation, scoped: decodeScopesValue(wire.scoped) };
215
+ const candidateSet = validateArtifactFields(artifact, tunnelAuthV1);
216
+ const normalized = new Map(candidateSet.candidates.map(candidate => [candidate.id, candidate.normalized_url]));
217
+ return { ...artifact, path: { ...path, candidates: path.candidates.map(candidate => ({ ...candidate, normalized_url: normalized.get(candidate.id) })) } };
218
+ }
219
+ function validateArtifactFields(artifact, profile) {
220
+ const sessionHash = computeSessionContractHashV3(artifact.session, profile);
191
221
  if (sessionHash.hashBase64URL !== artifact.session.contract_hash_b64u) {
192
222
  throw invalidArtifact("session contract hash");
193
223
  }
194
- const candidateSet = canonicalizeCandidatesV3(artifact.path.kind, artifact.path.candidates);
224
+ const candidateSet = canonicalizeCandidatesV3(artifact.path.kind, artifact.path.candidates, profile);
195
225
  if (!validRegistryID(artifact.path.rendezvous_group_id, 128) || !validRegistryID(artifact.path.listener_audience, 128)) {
196
226
  throw invalidArtifact("rendezvous group or listener audience");
197
227
  }
@@ -210,7 +240,7 @@ export function validateArtifactV3(artifact) {
210
240
  }
211
241
  }
212
242
  validateScopes(artifact.scoped);
213
- validateCorrelationShape(artifact.correlation);
243
+ validateCorrelationShape(artifact.correlation, profile);
214
244
  for (const candidate of candidateSet.candidates) {
215
245
  const request = requestFromValidatedArtifact(artifact, candidateSet, candidate.id);
216
246
  if (marshalFSB3Payload(request).length > MAX_CANONICAL_FSB3_PAYLOAD) {
@@ -225,28 +255,27 @@ export function buildFSB3RequestV3(artifact, chosenCandidateID) {
225
255
  validateFSB3Request(request);
226
256
  return request;
227
257
  }
228
- export function encodeFSB3RequestV3(request) {
229
- validateFSB3Request(request);
258
+ export function buildEndpointAdmission(artifact, chosenCandidateID) {
259
+ const candidateSet = validateArtifactFields(artifact, tunnelAuthV1);
260
+ return encodeFSB3RequestV3(requestFromValidatedArtifact(artifact, candidateSet, chosenCandidateID), tunnelAuthV1);
261
+ }
262
+ export function encodeFSB3RequestV3(request, profile = transportV5) {
263
+ validateFSB3Request(request, profile);
230
264
  const payload = marshalFSB3Payload(request);
231
265
  if (payload.length > MAX_CANONICAL_FSB3_PAYLOAD) {
232
266
  throw new ArtifactV3Error("fsb5_payload_too_large", "FSB5 canonical payload is too large");
233
267
  }
234
268
  const out = new Uint8Array(FSB3_HEADER_BYTES + payload.length);
235
- out.set(encoder.encode("FSB5"), 0);
236
- out[4] = 5;
269
+ writeFramePrefix(out, 0x42, profile);
237
270
  out[5] = request.pathKind === "direct" ? 1 : 2;
238
271
  out.set(u32be(payload.length), 8);
239
272
  out.set(payload, FSB3_HEADER_BYTES);
240
273
  return out;
241
274
  }
242
- export function decodeFSB3RequestV3(raw) {
275
+ export function decodeFSB3RequestV3(raw, profile = transportV5) {
243
276
  if (raw.length < FSB3_HEADER_BYTES)
244
277
  throw invalidFSB3("truncated header");
245
- if (raw[0] !== 0x46 ||
246
- raw[1] !== 0x53 ||
247
- raw[2] !== 0x42 ||
248
- raw[3] !== 0x35 ||
249
- raw[4] !== 5 ||
278
+ if (!matchesFramePrefix(raw, 0x42, profile) ||
250
279
  raw[6] !== 0 ||
251
280
  raw[7] !== 0) {
252
281
  throw invalidFSB3("header");
@@ -270,7 +299,7 @@ export function decodeFSB3RequestV3(raw) {
270
299
  throw invalidFSB3(`strict JSON: ${errorMessage(error)}`);
271
300
  }
272
301
  const request = decodeFSB3Value(pathKind, value);
273
- validateFSB3Request(request);
302
+ validateFSB3Request(request, profile);
274
303
  if (!bytesEqual(payload, marshalFSB3Payload(request))) {
275
304
  throw new ArtifactV3Error("noncanonical_fsb5", "FSB5 payload is not canonical");
276
305
  }
@@ -278,11 +307,11 @@ export function decodeFSB3RequestV3(raw) {
278
307
  return {
279
308
  request,
280
309
  raw: copied,
281
- localAdmissionBinding: admissionBindingV3(copied),
310
+ localAdmissionBinding: admissionBindingV3(copied, profile),
282
311
  };
283
312
  }
284
- export function admissionBindingV3(rawFSB3) {
285
- return sha256(concatBytes([encoder.encode(FLOWERSEC_V3_CRYPTO_LABELS.admission), rawFSB3]));
313
+ export function admissionBindingV3(rawFSB3, profile = transportV5) {
314
+ return sha256(concatBytes([encoder.encode(profile.labels.admission), rawFSB3]));
286
315
  }
287
316
  export function acceptorAdmissionsHashV3(framesByCandidateID) {
288
317
  if (framesByCandidateID.size < 1 || framesByCandidateID.size > MAX_CANDIDATES) {
@@ -304,12 +333,11 @@ export function acceptorAdmissionsHashV3(framesByCandidateID) {
304
333
  }
305
334
  // Server-side encoding requires an audited registry for every rejection.
306
335
  // Success has no reason and therefore needs no registry entry.
307
- export function encodeFSA3ResponseV3(response, admissionReasons = new Set()) {
336
+ export function encodeFSA3ResponseV3(response, admissionReasons = new Set(), profile = transportV5) {
308
337
  validateFSA3Response(response, admissionReasons, true);
309
338
  const reason = encoder.encode(response.reason);
310
339
  const out = new Uint8Array(FSA3_HEADER_BYTES + reason.length);
311
- out.set(encoder.encode("FSA5"), 0);
312
- out[4] = 5;
340
+ writeFramePrefix(out, 0x41, profile);
313
341
  out[5] = response.status;
314
342
  new DataView(out.buffer).setUint16(6, reason.length, false);
315
343
  out.set(reason, FSA3_HEADER_BYTES);
@@ -317,10 +345,10 @@ export function encodeFSA3ResponseV3(response, admissionReasons = new Set()) {
317
345
  }
318
346
  // Clients accept any canonical bounded rejection token. Deployment policy is
319
347
  // server-owned and is not duplicated as a client-side reason registry.
320
- export function decodeFSA3ResponseV3(raw) {
348
+ export function decodeFSA3ResponseV3(raw, profile = transportV5) {
321
349
  if (raw.length < FSA3_HEADER_BYTES)
322
350
  throw invalidFSA3("truncated header");
323
- if (raw[0] !== 0x46 || raw[1] !== 0x53 || raw[2] !== 0x41 || raw[3] !== 0x35 || raw[4] !== 5) {
351
+ if (!matchesFramePrefix(raw, 0x41, profile)) {
324
352
  throw invalidFSA3("header");
325
353
  }
326
354
  const reasonLength = new DataView(raw.buffer, raw.byteOffset, raw.byteLength).getUint16(6, false);
@@ -338,7 +366,7 @@ export function decodeFSA3ResponseV3(raw) {
338
366
  validateFSA3Response(response, new Set(), false);
339
367
  return response;
340
368
  }
341
- function validateSession(session) {
369
+ function validateSession(session, profile = transportV5) {
342
370
  assertRecord(session, "session", "invalid_artifact");
343
371
  assertExactKeys(session, [
344
372
  "channel_id",
@@ -348,7 +376,7 @@ function validateSession(session) {
348
376
  "rekey_prepare_timeout_seconds",
349
377
  "rekey_completion_timeout_seconds",
350
378
  "max_inbound_streams",
351
- "e2ee_psk_b64u",
379
+ profile === tunnelAuthV1 ? "auth_mode" : "e2ee_psk_b64u",
352
380
  "allowed_suites",
353
381
  "default_suite",
354
382
  "selected_features",
@@ -364,7 +392,15 @@ function validateSession(session) {
364
392
  throw invalidArtifact("fixed session timing");
365
393
  }
366
394
  assertSafeInteger(session.max_inbound_streams, 1, 128, "max inbound streams");
367
- assertCanonical32(session.e2ee_psk_b64u, "e2ee PSK", "invalid_artifact");
395
+ if (profile === tunnelAuthV1) {
396
+ if (!("auth_mode" in session) || (session.auth_mode !== "responder" && session.auth_mode !== "mutual") || session.allowed_suites?.length !== 1)
397
+ throw invalidArtifact("endpoint auth contract");
398
+ }
399
+ else {
400
+ if (!("e2ee_psk_b64u" in session))
401
+ throw invalidArtifact("missing PSK");
402
+ assertCanonical32(session.e2ee_psk_b64u, "e2ee PSK", "invalid_artifact");
403
+ }
368
404
  assertCanonical32(session.contract_hash_b64u, "contract hash", "invalid_artifact");
369
405
  if (!Array.isArray(session.allowed_suites) || session.allowed_suites.length < 1) {
370
406
  throw invalidArtifact("allowed suites");
@@ -551,10 +587,10 @@ function validateScopedPayload(payload) {
551
587
  if (utf8Length(canonical) > 4_096)
552
588
  throw invalidArtifact("scope payload bytes");
553
589
  }
554
- function validateCorrelationShape(correlation) {
590
+ function validateCorrelationShape(correlation, profile = transportV5) {
555
591
  assertRecord(correlation, "correlation", "invalid_artifact");
556
592
  assertExactKeys(correlation, ["v", "tags"], "correlation", "invalid_artifact");
557
- if (correlation.v !== 5 || !Array.isArray(correlation.tags) || correlation.tags.length > 8) {
593
+ if (correlation.v !== profile.version || !Array.isArray(correlation.tags) || correlation.tags.length > 8) {
558
594
  throw invalidArtifact("correlation");
559
595
  }
560
596
  const seen = new Set();
@@ -572,7 +608,7 @@ function validateCorrelationShape(correlation) {
572
608
  }
573
609
  }
574
610
  /** @internal Uses the signed candidate grammar for endpoint selection. */
575
- export function normalizeCandidateURL(kind, carrier, raw) {
611
+ export function normalizeCandidateURL(kind, carrier, raw, profile = transportV5) {
576
612
  if (/[\\?#%]/.test(raw))
577
613
  throw invalidCandidate("forbidden URL component");
578
614
  const separator = raw.indexOf("://");
@@ -591,7 +627,7 @@ export function normalizeCandidateURL(kind, carrier, raw) {
591
627
  switch (carrier) {
592
628
  case "websocket":
593
629
  expectedScheme = "wss";
594
- expectedPath = `/flowersec/v5/${kind}`;
630
+ expectedPath = profile === tunnelAuthV1 ? "/flowersec/tunnel-auth/v1" : `/flowersec/v5/${kind}`;
595
631
  break;
596
632
  case "raw_quic":
597
633
  expectedScheme = "quic";
@@ -601,7 +637,7 @@ export function normalizeCandidateURL(kind, carrier, raw) {
601
637
  break;
602
638
  case "webtransport":
603
639
  expectedScheme = "https";
604
- expectedPath = `/flowersec/webtransport/v5/${kind}`;
640
+ expectedPath = profile === tunnelAuthV1 ? "/flowersec/webtransport/tunnel-auth/v1" : `/flowersec/webtransport/v5/${kind}`;
605
641
  break;
606
642
  default:
607
643
  throw invalidCandidate("carrier registry");
@@ -708,7 +744,7 @@ function hasOnlyUnicode151Scalars(value) {
708
744
  }
709
745
  function requestFromValidatedArtifact(artifact, candidateSet, chosenCandidateID) {
710
746
  const common = {
711
- profile: PROFILE,
747
+ profile: artifact.profile,
712
748
  channel_id: artifact.session.channel_id,
713
749
  session_contract_hash_b64u: artifact.session.contract_hash_b64u,
714
750
  rendezvous_group_id: artifact.path.rendezvous_group_id,
@@ -728,11 +764,11 @@ function requestFromValidatedArtifact(artifact, candidateSet, chosenCandidateID)
728
764
  attach_token: artifact.path.token,
729
765
  };
730
766
  }
731
- function validateFSB3Request(request) {
767
+ function validateFSB3Request(request, profile = transportV5) {
732
768
  try {
733
769
  if (request.pathKind !== "direct" && request.pathKind !== "tunnel")
734
770
  throw new Error("path kind");
735
- if (request.profile !== PROFILE)
771
+ if (request.profile !== profile.name)
736
772
  throw new Error("profile");
737
773
  if (!validRegistryID(request.channel_id, 128) ||
738
774
  !validRegistryID(request.rendezvous_group_id, 128) ||
@@ -749,7 +785,7 @@ function validateFSB3Request(request) {
749
785
  tls: candidate.tls,
750
786
  wire_profile: candidate.wire_profile,
751
787
  }));
752
- const canonical = canonicalizeCandidatesV3(request.pathKind, source);
788
+ const canonical = canonicalizeCandidatesV3(request.pathKind, source, profile);
753
789
  if (canonical.hashBase64URL !== request.candidate_set_hash_b64u ||
754
790
  canonicalizeJCSV3(canonical.candidates) !==
755
791
  canonicalizeJCSV3(request.candidates)) {
@@ -1,4 +1,5 @@
1
- import { type ArtifactV3 } from "./artifact.js";
1
+ import { type ConnectionArtifact } from "./artifact.js";
2
+ import type { TunnelAuth } from "../tunnelAuth/credentials.js";
2
3
  export declare class ArtifactLeaseV3Error extends Error {
3
4
  readonly code = "already_consumed";
4
5
  constructor();
@@ -21,6 +22,7 @@ export declare function leaseScopeV3(lease: ArtifactLeaseV3, name: string): Read
21
22
  /** Local routing mistakes must not claim, retire or spend the invitation. */
22
23
  export type KeyExchangeMode = "classic" | "hybridRequired" | "hybridPreferred";
23
24
  export declare function claimConnectionLeaseV3(lease: ArtifactLeaseV3, ingress?: string, mode?: KeyExchangeMode): ClaimedArtifactLeaseV3;
24
- export declare function claimedArtifactV3(claim: ClaimedArtifactLeaseV3): ArtifactV3;
25
+ export declare function claimedTunnelAuth(claim: ClaimedArtifactLeaseV3): TunnelAuth | undefined;
26
+ export declare function claimedArtifactV3(claim: ClaimedArtifactLeaseV3): ConnectionArtifact;
25
27
  export declare function commitArtifactLeaseSpendV3(claim: ClaimedArtifactLeaseV3, signal?: AbortSignal): Promise<void>;
26
28
  export declare function retireArtifactLeaseV3(claim: ClaimedArtifactLeaseV3): Promise<void>;
@@ -1,4 +1,5 @@
1
1
  import { canonicalizeCandidatesV3 } from "./artifact.js";
2
+ import { tunnelAuthV1 } from "./wireProfile.js";
2
3
  import { selectTunnelIngress } from "./tunnelIngress.js";
3
4
  import { ConnectErrorV3 } from "./security.js";
4
5
  export class ArtifactLeaseV3Error extends Error {
@@ -17,13 +18,14 @@ export class ClaimedArtifactLeaseV3 {
17
18
  constructor() { }
18
19
  }
19
20
  /** @internal Artifact sources construct idle one-shot leases through this boundary. */
20
- export function createArtifactLeaseV3Internal(artifact, commitSpend, retireCleanup) {
21
+ export function createArtifactLeaseV3Internal(artifact, commitSpend, retireCleanup, endpointAuth) {
21
22
  if (typeof commitSpend !== "function" || (retireCleanup !== undefined && typeof retireCleanup !== "function")) {
22
23
  throw new TypeError("invalid Flowersec v5 artifact lease callbacks");
23
24
  }
24
25
  const lease = new ArtifactLeaseV3();
25
26
  leaseStates.set(lease, {
26
27
  artifact,
28
+ ...(endpointAuth ? { endpointAuth } : {}),
27
29
  status: "idle",
28
30
  commit: commitSpend,
29
31
  cleanup: retireCleanup,
@@ -60,6 +62,13 @@ export function claimConnectionLeaseV3(lease, ingress, mode = "classic") {
60
62
  if (state === undefined || state.status !== "idle")
61
63
  throw new ArtifactLeaseV3Error();
62
64
  const path = state.artifact?.path;
65
+ if (state.artifact?.v === 1) {
66
+ if (mode !== "classic" || !state.endpointAuth || state.endpointAuth.role !== state.artifact.path.role || state.endpointAuth.mode !== state.artifact.session.auth_mode) {
67
+ throw new ConnectErrorV3("artifact_invalid", { kind: "terminal" });
68
+ }
69
+ selectTunnelIngress("tunnel", canonicalizeCandidatesV3("tunnel", state.artifact.path.candidates, tunnelAuthV1).candidates, ingress);
70
+ return claimArtifactLeaseV3(lease);
71
+ }
63
72
  if (mode !== "classic" && mode !== "hybridRequired" && mode !== "hybridPreferred")
64
73
  throw new ConnectErrorV3("artifact_invalid", { kind: "terminal" });
65
74
  if (path?.kind === "tunnel" && path.role === 2 ? mode !== "classic" : (state.artifact?.session?.default_suite === 3) !== (mode !== "classic")) {
@@ -70,6 +79,9 @@ export function claimConnectionLeaseV3(lease, ingress, mode = "classic") {
70
79
  }
71
80
  return claimArtifactLeaseV3(lease);
72
81
  }
82
+ export function claimedTunnelAuth(claim) {
83
+ return claimStates.get(claim)?.endpointAuth;
84
+ }
73
85
  export function claimedArtifactV3(claim) {
74
86
  const state = claimStates.get(claim);
75
87
  if (state === undefined || (state.status !== "claimed" && state.status !== "spending")) {
@@ -1,4 +1,5 @@
1
1
  import { defineRuntimeCapabilityDescriptorV3 } from "./capability.js";
2
+ import { endpointIngress, tunnelAuthProfile } from "./wireProfile.js";
2
3
  import { snapshotTransportSecurityPolicyV3, TransportFailureV3 } from "./security.js";
3
4
  import { adaptWebTransportCarrierSessionV3, hasWebTransportConstructorSurfaceV3, } from "./webTransportCarrier.js";
4
5
  import { FLOWERSEC_V3_PATHS, FLOWERSEC_V3_WIRE_PROFILES } from "./transportConstants.js";
@@ -57,7 +58,7 @@ export async function createBrowserWebTransportV3(candidate, attemptNowUnixSecon
57
58
  if (candidate.carrier !== "webtransport")
58
59
  throw new TransportFailureV3("invalid_artifact");
59
60
  const path = pathFromProfile(candidate.wire_profile);
60
- validateNormalizedBrowserURL(candidate.normalized_url, path);
61
+ validateNormalizedBrowserURL(candidate.normalized_url, candidate.wire_profile === tunnelAuthProfile ? endpointIngress.webtransport : FLOWERSEC_V3_PATHS.webtransport[path]);
61
62
  const tuple = capabilitySnapshot.tuples.find((entry) => entry.carrier === "webtransport" && entry.networkMode === "dial" && entry.path === path);
62
63
  const modes = tuple?.securityModes ?? [];
63
64
  const policy = snapshotTransportSecurityPolicyV3(candidate.tls, attemptNowUnixSeconds, modes);
@@ -147,7 +148,7 @@ function tuplesFor(carrier, datagrams, securityModes) {
147
148
  { carrier, datagrams, migration: false, networkMode: "dial", path: "tunnel", reliableStreams: true, securityModes, sessionRole: "server" },
148
149
  ]);
149
150
  }
150
- function validateNormalizedBrowserURL(raw, path) {
151
+ function validateNormalizedBrowserURL(raw, expectedPath) {
151
152
  let parsed;
152
153
  try {
153
154
  parsed = new URL(raw);
@@ -155,13 +156,14 @@ function validateNormalizedBrowserURL(raw, path) {
155
156
  catch {
156
157
  throw new TransportFailureV3("invalid_artifact");
157
158
  }
158
- const expectedPath = FLOWERSEC_V3_PATHS.webtransport[path];
159
159
  if (parsed.href !== raw || parsed.protocol !== "https:" || parsed.username !== "" || parsed.password !== "" ||
160
160
  parsed.pathname !== expectedPath || parsed.search !== "" || parsed.hash !== "") {
161
161
  throw new TransportFailureV3("invalid_artifact");
162
162
  }
163
163
  }
164
164
  function pathFromProfile(profile) {
165
+ if (profile === tunnelAuthProfile)
166
+ return "tunnel";
165
167
  if (profile === FLOWERSEC_V3_WIRE_PROFILES.direct)
166
168
  return "direct";
167
169
  if (profile === FLOWERSEC_V3_WIRE_PROFILES.tunnel)
@@ -1,4 +1,4 @@
1
- import { type ArtifactV3, type CanonicalArtifactCandidateV3 } from "./artifact.js";
1
+ import { type ConnectionArtifact, type ArtifactV3, type CanonicalArtifactCandidateV3 } from "./artifact.js";
2
2
  import { type ArtifactLeaseV3, type ClaimedArtifactLeaseV3, type KeyExchangeMode } from "./artifactLease.js";
3
3
  import { type CandidateFailureV3, type ControllerClockV3 } from "./controller.js";
4
4
  import { ConnectErrorV3, type RetryDispositionV3 } from "./security.js";
@@ -27,7 +27,7 @@ export type ManagedSessionV3 = Readonly<{
27
27
  }>;
28
28
  export type LeaseAttemptContextV3 = Readonly<{
29
29
  kind: "primary" | "replacement";
30
- artifact: ArtifactV3;
30
+ artifact: ConnectionArtifact;
31
31
  candidates: readonly CanonicalArtifactCandidateV3[];
32
32
  claim: ClaimedArtifactLeaseV3;
33
33
  signal: AbortSignal;
@@ -1,4 +1,4 @@
1
- import { canonicalizeCandidatesV3, validateArtifactV3, } from "./artifact.js";
1
+ import { canonicalizeCandidatesV3, validatedCandidates, } from "./artifact.js";
2
2
  import { artifactLeaseStateV3, claimArtifactLeaseV3, claimConnectionLeaseV3, claimedArtifactV3, retireArtifactLeaseV3, } from "./artifactLease.js";
3
3
  import { canonicalizeJCSV3 } from "./jcs.js";
4
4
  import { SDK_DEFAULTS } from "../defaults.js";
@@ -294,11 +294,11 @@ export class ConnectionControllerV3 {
294
294
  const artifact = claimedArtifactV3(claim);
295
295
  let allCandidates;
296
296
  try {
297
- validateArtifactV3(artifact);
297
+ allCandidates = validatedCandidates(artifact).candidates;
298
298
  if (fallback && (performance.now() >= deadline || !validClassicReplacement(fallback.from, artifact)))
299
299
  throw new TypeError("invalid fallback grant");
300
- this.#rotation?.accept(artifact);
301
- allCandidates = canonicalizeCandidatesV3(artifact.path.kind, artifact.path.candidates).candidates;
300
+ if (this.#rotation && artifact.v === 5)
301
+ this.#rotation.accept(artifact);
302
302
  }
303
303
  catch {
304
304
  await retireArtifactLeaseV3(claim);
@@ -761,6 +761,8 @@ const LEASE_ATTEMPT_RESULT_KINDS_V3 = new Set([
761
761
  ]);
762
762
  const CONNECT_ERROR_CODES_V3 = new Set([
763
763
  "hybrid_unavailable",
764
+ "endpoint_auth_failed",
765
+ "endpoint_auth_unsupported",
764
766
  "tunnel_ingress_mismatch",
765
767
  "artifact_invalid",
766
768
  "expired_artifact",
@@ -828,6 +830,8 @@ function normalizeLeaseAttemptResultV3(value, candidates, capability) {
828
830
  }
829
831
  }
830
832
  function validClassicReplacement(previous, next) {
833
+ if (previous.v !== 5 || next.v !== 5)
834
+ return false;
831
835
  const before = previous.path, after = next.path;
832
836
  if (previous.session.default_suite !== 3 || next.session.default_suite === 3 ||
833
837
  previous.session.channel_id !== next.session.channel_id || previous.session.e2ee_psk_b64u === next.session.e2ee_psk_b64u ||
@@ -1,5 +1,5 @@
1
1
  import { CipherSuiteV3 } from "./protocol.js";
2
- import { FLOWERSEC_V3_PROFILE } from "./transportConstants.js";
2
+ import { type WireProfile } from "./wireProfile.js";
3
3
  export declare enum HandshakeMessageTypeV3 {
4
4
  ClientInit = 1,
5
5
  ServerFinished = 2,
@@ -12,7 +12,8 @@ export type HandshakeFrameV3 = Readonly<{
12
12
  raw: Uint8Array;
13
13
  }>;
14
14
  export type ClientInitV3 = Readonly<{
15
- profile: typeof FLOWERSEC_V3_PROFILE;
15
+ profile: WireProfile["name"];
16
+ hpkeEnc?: Uint8Array;
16
17
  channelID: string;
17
18
  sessionContractHash: Uint8Array;
18
19
  clientRole: 1;
@@ -52,18 +53,18 @@ export type HandshakeExpectationsV3 = Readonly<{
52
53
  admissionBinding: Uint8Array;
53
54
  expectedEndpointInstanceID: string;
54
55
  }>;
55
- export declare function encodeControlPrefaceV3(): Uint8Array;
56
- export declare function parseControlPrefaceV3(raw: Uint8Array): void;
57
- export declare function encodeHandshakeFrameV3(type: HandshakeMessageTypeV3, payload: Uint8Array): Uint8Array;
58
- export declare function decodeHandshakeFrameV3(raw: Uint8Array): HandshakeFrameV3;
59
- export declare function encodeClientInitV3(message: ClientInitV3): Uint8Array;
60
- export declare function decodeClientInitV3(raw: Uint8Array): ClientInitV3;
61
- export declare function encodeServerFinishedCoreV3(core: ServerFinishedCoreV3, suite: CipherSuiteV3): Uint8Array;
62
- export declare function encodeServerFinishedV3(message: ServerFinishedV3, suite: CipherSuiteV3): Uint8Array;
63
- export declare function decodeServerFinishedV3(raw: Uint8Array, suite: CipherSuiteV3): ServerFinishedV3;
64
- export declare function encodeClientFinishedCoreV3(handshakeID: Uint8Array): Uint8Array;
65
- export declare function encodeClientFinishedV3(message: ClientFinishedV3): Uint8Array;
66
- export declare function decodeClientFinishedV3(raw: Uint8Array): ClientFinishedV3;
56
+ export declare function encodeControlPrefaceV3(profile?: WireProfile): Uint8Array;
57
+ export declare function parseControlPrefaceV3(raw: Uint8Array, profile?: WireProfile): void;
58
+ export declare function encodeHandshakeFrameV3(type: HandshakeMessageTypeV3, payload: Uint8Array, profile?: WireProfile): Uint8Array;
59
+ export declare function decodeHandshakeFrameV3(raw: Uint8Array, profile?: WireProfile): HandshakeFrameV3;
60
+ export declare function encodeClientInitV3(message: ClientInitV3, profile?: WireProfile): Uint8Array;
61
+ export declare function decodeClientInitV3(raw: Uint8Array, profile?: WireProfile): ClientInitV3;
62
+ export declare function encodeServerFinishedCoreV3(core: ServerFinishedCoreV3, suite: CipherSuiteV3, profile?: WireProfile): Uint8Array;
63
+ export declare function encodeServerFinishedV3(message: ServerFinishedV3, suite: CipherSuiteV3, profile?: WireProfile): Uint8Array;
64
+ export declare function decodeServerFinishedV3(raw: Uint8Array, suite: CipherSuiteV3, profile?: WireProfile): ServerFinishedV3;
65
+ export declare function encodeClientFinishedCoreV3(handshakeID: Uint8Array, profile?: WireProfile): Uint8Array;
66
+ export declare function encodeClientFinishedV3(message: ClientFinishedV3, profile?: WireProfile): Uint8Array;
67
+ export declare function decodeClientFinishedV3(raw: Uint8Array, profile?: WireProfile): ClientFinishedV3;
67
68
  export declare function generateEphemeralKeyV3(suite: CipherSuiteV3, entropy: (length: number) => Uint8Array): Readonly<{
68
69
  privateKey: Uint8Array;
69
70
  publicKey: Uint8Array;
@@ -78,12 +79,12 @@ export declare function serverKeyShareV3(suite: CipherSuiteV3, clientShare: Uint
78
79
  export declare function clientSharedSecretV3(suite: CipherSuiteV3, privateKey: Uint8Array, serverShare: Uint8Array): Uint8Array<ArrayBufferLike>;
79
80
  export declare function serverUnavailableV3(psk: Uint8Array, h0: Uint8Array, binding: Uint8Array, endpoint: string): Uint8Array;
80
81
  export declare function verifyServerUnavailableV3(raw: Uint8Array, psk: Uint8Array, h0: Uint8Array, expected: HandshakeExpectationsV3): void;
81
- export declare function computeHandshakeH0V3(controlPrefaceRaw: Uint8Array, clientInitRaw: Uint8Array): Uint8Array;
82
- export declare function computeHandshakeH1V3(h0: Uint8Array, serverCoreRaw: Uint8Array): Uint8Array;
83
- export declare function computeServerConfirmV3(handshakePRK: Uint8Array, h1: Uint8Array): Uint8Array;
84
- export declare function computeHandshakeH2V3(h1: Uint8Array, serverFinishedRaw: Uint8Array, clientCoreRaw: Uint8Array): Uint8Array;
85
- export declare function computeClientConfirmV3(handshakePRK: Uint8Array, h2: Uint8Array): Uint8Array;
86
- export declare function computeHandshakeH3V3(h2: Uint8Array, clientFinishedRaw: Uint8Array): Uint8Array;
82
+ export declare function computeHandshakeH0V3(controlPrefaceRaw: Uint8Array, clientInitRaw: Uint8Array, profile?: WireProfile): Uint8Array;
83
+ export declare function computeHandshakeH1V3(h0: Uint8Array, serverCoreRaw: Uint8Array, profile?: WireProfile): Uint8Array;
84
+ export declare function computeServerConfirmV3(handshakePRK: Uint8Array, h1: Uint8Array, profile?: WireProfile): Uint8Array;
85
+ export declare function computeHandshakeH2V3(h1: Uint8Array, serverFinishedRaw: Uint8Array, clientCoreRaw: Uint8Array, profile?: WireProfile): Uint8Array;
86
+ export declare function computeClientConfirmV3(handshakePRK: Uint8Array, h2: Uint8Array, profile?: WireProfile): Uint8Array;
87
+ export declare function computeHandshakeH3V3(h2: Uint8Array, clientFinishedRaw: Uint8Array, profile?: WireProfile): Uint8Array;
87
88
  export declare function deriveSessionPRKV3(h3: Uint8Array, handshakePRK: Uint8Array): Uint8Array;
88
- export declare function validateClientInitV3(message: ClientInitV3, expected: HandshakeExpectationsV3): void;
89
+ export declare function validateClientInitV3(message: ClientInitV3, expected: HandshakeExpectationsV3, profile?: WireProfile): void;
89
90
  export declare function validateServerFinishedV3(message: ServerFinishedV3, expected: HandshakeExpectationsV3): void;