@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.
Files changed (57) 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 +15 -8
  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/framing/jsonframe.d.ts +1 -1
  9. package/dist/framing/jsonframe.js +13 -6
  10. package/dist/node/connectSessionV3.d.ts +6 -2
  11. package/dist/node/connectSessionV3.js +12 -6
  12. package/dist/node/index.d.ts +1 -1
  13. package/dist/node/index.js +1 -1
  14. package/dist/node/nativeTransportAddon.d.ts +4 -3
  15. package/dist/node/nativeTransportAddon.js +3 -2
  16. package/dist/node/rawQuicAdapterV3.d.ts +2 -2
  17. package/dist/node/rawQuicAdapterV3.js +5 -3
  18. package/dist/public/sessionHandlers.d.ts +3 -1
  19. package/dist/public/sessionHandlers.js +11 -3
  20. package/dist/rpc/server.js +3 -3
  21. package/dist/tunnelAuth/artifact.d.ts +34 -0
  22. package/dist/tunnelAuth/artifact.js +74 -0
  23. package/dist/tunnelAuth/credentials.d.ts +17 -0
  24. package/dist/tunnelAuth/credentials.js +40 -0
  25. package/dist/tunnelAuth/hpke.d.ts +36 -0
  26. package/dist/tunnelAuth/hpke.js +124 -0
  27. package/dist/v3/artifact.d.ts +27 -8
  28. package/dist/v3/artifact.js +78 -42
  29. package/dist/v3/artifactLease.d.ts +4 -2
  30. package/dist/v3/artifactLease.js +13 -1
  31. package/dist/v3/browserRuntime.js +5 -3
  32. package/dist/v3/connectionController.d.ts +2 -2
  33. package/dist/v3/connectionController.js +8 -4
  34. package/dist/v3/connectorRPCLimits.d.ts +7 -0
  35. package/dist/v3/connectorRPCLimits.js +14 -0
  36. package/dist/v3/handshake.d.ts +22 -21
  37. package/dist/v3/handshake.js +58 -60
  38. package/dist/v3/nodeRuntime.js +4 -1
  39. package/dist/v3/protocol.d.ts +17 -16
  40. package/dist/v3/protocol.js +60 -64
  41. package/dist/v3/publicApi.d.ts +1 -0
  42. package/dist/v3/publicApi.js +7 -0
  43. package/dist/v3/runtimeAdapters.d.ts +2 -2
  44. package/dist/v3/runtimeAdapters.js +2 -1
  45. package/dist/v3/security.d.ts +1 -1
  46. package/dist/v3/session.d.ts +14 -4
  47. package/dist/v3/session.js +174 -114
  48. package/dist/v3/sessionConnector.d.ts +2 -2
  49. package/dist/v3/sessionConnector.js +24 -13
  50. package/dist/v3/tunnelIngress.js +2 -1
  51. package/dist/v3/unreliableMessage.d.ts +3 -0
  52. package/dist/v3/unreliableMessage.js +24 -22
  53. package/dist/v3/wireProfile.d.ts +52 -0
  54. package/dist/v3/wireProfile.js +20 -0
  55. package/package.json +5 -3
  56. package/sbom/cyclonedx.json +133 -31
  57. package/sbom/spdx.json +110 -39
@@ -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 ||
@@ -0,0 +1,7 @@
1
+ export declare function connectorRPCLimits(options: Readonly<{
2
+ maxRpcFrameBytes?: number;
3
+ maxConcurrentRpcRequests?: number;
4
+ }>): {
5
+ maxRpcFrameBytes: number;
6
+ maxConcurrentRpcRequests: number;
7
+ };
@@ -0,0 +1,14 @@
1
+ import { rpcFrameLimit } from "../framing/jsonframe.js";
2
+ import { rpcConcurrency } from "../rpc/server.js";
3
+ import { ConnectErrorV3 } from "./security.js";
4
+ export function connectorRPCLimits(options) {
5
+ try {
6
+ return {
7
+ maxRpcFrameBytes: rpcFrameLimit(options.maxRpcFrameBytes),
8
+ maxConcurrentRpcRequests: rpcConcurrency(options.maxConcurrentRpcRequests),
9
+ };
10
+ }
11
+ catch {
12
+ throw new ConnectErrorV3("artifact_invalid", { kind: "terminal" });
13
+ }
14
+ }
@@ -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;
@@ -7,7 +7,7 @@ import { ml_kem768_x25519 as xwing } from "@noble/post-quantum/hybrid.js";
7
7
  import { base64urlDecode, base64urlEncode } from "../utils/base64url.js";
8
8
  import { concatBytes, readU32be, u32be } from "../utils/bin.js";
9
9
  import { CipherSuiteV3, ProtocolV3Error } from "./protocol.js";
10
- import { FLOWERSEC_V3_CRYPTO_LABELS, FLOWERSEC_V3_PROFILE } from "./transportConstants.js";
10
+ import { matchesFramePrefix, transportV5, writeFramePrefix } from "./wireProfile.js";
11
11
  const encoder = new TextEncoder();
12
12
  const decoder = new TextDecoder("utf-8", { fatal: true });
13
13
  const CONTROL_PREFACE_BYTES = 16;
@@ -22,45 +22,41 @@ export var HandshakeMessageTypeV3;
22
22
  HandshakeMessageTypeV3[HandshakeMessageTypeV3["ClientFinished"] = 3] = "ClientFinished";
23
23
  HandshakeMessageTypeV3[HandshakeMessageTypeV3["ServerUnavailable"] = 4] = "ServerUnavailable";
24
24
  })(HandshakeMessageTypeV3 || (HandshakeMessageTypeV3 = {}));
25
- export function encodeControlPrefaceV3() {
25
+ export function encodeControlPrefaceV3(profile = transportV5) {
26
26
  const out = new Uint8Array(CONTROL_PREFACE_BYTES);
27
- out.set(encoder.encode("FSC5"));
28
- out[4] = 5;
27
+ writeFramePrefix(out, 0x43, profile);
29
28
  out[5] = 1;
30
29
  return out;
31
30
  }
32
- export function parseControlPrefaceV3(raw) {
31
+ export function parseControlPrefaceV3(raw, profile = transportV5) {
33
32
  if (raw.length !== CONTROL_PREFACE_BYTES ||
34
- raw[0] !== 0x46 || raw[1] !== 0x53 || raw[2] !== 0x43 || raw[3] !== 0x35 ||
35
- raw[4] !== 5 || raw[5] !== 1 || raw.subarray(6).some((value) => value !== 0)) {
33
+ !matchesFramePrefix(raw, 0x43, profile) || raw[5] !== 1 || raw.subarray(6).some((value) => value !== 0)) {
36
34
  throw new ProtocolV3Error("invalid FSC3 control preface");
37
35
  }
38
36
  }
39
- export function encodeHandshakeFrameV3(type, payload) {
37
+ export function encodeHandshakeFrameV3(type, payload, profile = transportV5) {
40
38
  if (type < HandshakeMessageTypeV3.ClientInit ||
41
- type > HandshakeMessageTypeV3.ServerUnavailable ||
39
+ type > profile.lastHandshakeType ||
42
40
  payload.length < 1 ||
43
41
  payload.length > MAX_HANDSHAKE_PAYLOAD_BYTES) {
44
42
  throw new ProtocolV3Error("invalid FSH3 handshake frame");
45
43
  }
46
44
  const out = new Uint8Array(HANDSHAKE_HEADER_BYTES + payload.length);
47
- out.set(encoder.encode("FSH5"));
48
- out[4] = 5;
45
+ writeFramePrefix(out, 0x48, profile);
49
46
  out[5] = type;
50
47
  out.set(u32be(payload.length), 8);
51
48
  out.set(payload, HANDSHAKE_HEADER_BYTES);
52
49
  return out;
53
50
  }
54
- export function decodeHandshakeFrameV3(raw) {
51
+ export function decodeHandshakeFrameV3(raw, profile = transportV5) {
55
52
  if (raw.length < HANDSHAKE_HEADER_BYTES ||
56
- raw[0] !== 0x46 || raw[1] !== 0x53 || raw[2] !== 0x48 || raw[3] !== 0x35 ||
57
- raw[4] !== 5 || raw[6] !== 0 || raw[7] !== 0) {
53
+ !matchesFramePrefix(raw, 0x48, profile) || raw[6] !== 0 || raw[7] !== 0) {
58
54
  throw new ProtocolV3Error("invalid FSH3 handshake frame");
59
55
  }
60
56
  const type = raw[5];
61
57
  const length = readU32be(raw, 8);
62
58
  if (type < HandshakeMessageTypeV3.ClientInit ||
63
- type > HandshakeMessageTypeV3.ServerUnavailable ||
59
+ type > profile.lastHandshakeType ||
64
60
  length < 1 || length > MAX_HANDSHAKE_PAYLOAD_BYTES ||
65
61
  raw.length !== HANDSHAKE_HEADER_BYTES + length) {
66
62
  throw new ProtocolV3Error("invalid FSH3 handshake frame");
@@ -74,30 +70,32 @@ export function decodeHandshakeFrameV3(raw) {
74
70
  }
75
71
  return { type, payload, raw: raw.slice() };
76
72
  }
77
- export function encodeClientInitV3(message) {
78
- validateClientInit(message);
73
+ export function encodeClientInitV3(message, profile = transportV5) {
74
+ validateClientInit(message, profile);
79
75
  return encodeCanonicalHandshake(HandshakeMessageTypeV3.ClientInit, {
80
76
  channel_id: message.channelID,
81
77
  client_admission_binding_b64u: encode32(message.clientAdmissionBinding),
82
78
  client_endpoint_instance_id: message.clientEndpointInstanceID,
83
79
  client_eph_pub_b64u: base64urlEncode(message.clientEphemeralPublic),
84
80
  client_role: message.clientRole,
81
+ ...(message.hpkeEnc ? { hpke_enc_b64u: encode32(message.hpkeEnc) } : {}),
85
82
  max_inbound_streams: message.maxInboundStreams,
86
83
  nonce_c_b64u: encode32(message.nonceC),
87
84
  profile: message.profile,
88
85
  selected_features: message.selectedFeatures,
89
86
  session_contract_hash_b64u: encode32(message.sessionContractHash),
90
87
  suite: message.suite,
91
- });
88
+ }, profile);
92
89
  }
93
- export function decodeClientInitV3(raw) {
90
+ export function decodeClientInitV3(raw, profile = transportV5) {
94
91
  const value = decodeCanonicalObject(raw, HandshakeMessageTypeV3.ClientInit, [
95
92
  "channel_id", "client_admission_binding_b64u", "client_endpoint_instance_id", "client_eph_pub_b64u",
96
93
  "client_role", "max_inbound_streams", "nonce_c_b64u", "profile", "selected_features",
97
- "session_contract_hash_b64u", "suite",
98
- ]);
94
+ "session_contract_hash_b64u", "suite", ...(profile === transportV5 ? [] : ["hpke_enc_b64u"]),
95
+ ], profile);
99
96
  const message = {
100
97
  profile: requireString(value.profile),
98
+ ...(profile === transportV5 ? {} : { hpkeEnc: decode32(value.hpke_enc_b64u) }),
101
99
  channelID: requireString(value.channel_id),
102
100
  sessionContractHash: decode32(value.session_contract_hash_b64u),
103
101
  clientRole: requireInteger(value.client_role, 1),
@@ -109,16 +107,16 @@ export function decodeClientInitV3(raw) {
109
107
  clientAdmissionBinding: decode32(value.client_admission_binding_b64u),
110
108
  clientEndpointInstanceID: requireString(value.client_endpoint_instance_id),
111
109
  };
112
- validateClientInit(message);
113
- requireCanonical(raw, encodeClientInitV3(message));
110
+ validateClientInit(message, profile);
111
+ requireCanonical(raw, encodeClientInitV3(message, profile));
114
112
  return message;
115
113
  }
116
- export function encodeServerFinishedCoreV3(core, suite) {
114
+ export function encodeServerFinishedCoreV3(core, suite, profile = transportV5) {
117
115
  const normalized = { ...core, suite };
118
116
  validateServerCore(normalized);
119
- return encodeCanonicalHandshake(HandshakeMessageTypeV3.ServerFinished, serverCoreWire(normalized));
117
+ return encodeCanonicalHandshake(HandshakeMessageTypeV3.ServerFinished, serverCoreWire(normalized), profile);
120
118
  }
121
- export function encodeServerFinishedV3(message, suite) {
119
+ export function encodeServerFinishedV3(message, suite, profile = transportV5) {
122
120
  const core = { ...message.core, suite };
123
121
  validateServerCore(core);
124
122
  assertBytes("server confirm", message.serverConfirm, 32);
@@ -132,14 +130,14 @@ export function encodeServerFinishedV3(message, suite) {
132
130
  server_endpoint_instance_id: core.serverEndpointInstanceID,
133
131
  server_eph_pub_b64u: base64urlEncode(core.serverEphemeralPublic),
134
132
  session_contract_hash_b64u: encode32(core.sessionContractHash),
135
- });
133
+ }, profile);
136
134
  }
137
- export function decodeServerFinishedV3(raw, suite) {
135
+ export function decodeServerFinishedV3(raw, suite, profile = transportV5) {
138
136
  const value = decodeCanonicalObject(raw, HandshakeMessageTypeV3.ServerFinished, [
139
137
  "handshake_id", "max_inbound_streams", "nonce_s_b64u", "selected_features",
140
138
  "server_admission_binding_b64u", "server_confirm_b64u", "server_endpoint_instance_id",
141
139
  "server_eph_pub_b64u", "session_contract_hash_b64u",
142
- ]);
140
+ ], profile);
143
141
  const core = {
144
142
  suite,
145
143
  handshakeID: decodeBase64(value.handshake_id),
@@ -153,33 +151,33 @@ export function decodeServerFinishedV3(raw, suite) {
153
151
  };
154
152
  const message = { core, serverConfirm: decode32(value.server_confirm_b64u) };
155
153
  validateServerCore(core);
156
- requireCanonical(raw, encodeServerFinishedV3(message, suite));
154
+ requireCanonical(raw, encodeServerFinishedV3(message, suite, profile));
157
155
  return message;
158
156
  }
159
- export function encodeClientFinishedCoreV3(handshakeID) {
157
+ export function encodeClientFinishedCoreV3(handshakeID, profile = transportV5) {
160
158
  validateHandshakeID(handshakeID);
161
159
  return encodeCanonicalHandshake(HandshakeMessageTypeV3.ClientFinished, {
162
160
  handshake_id: base64urlEncode(handshakeID),
163
- });
161
+ }, profile);
164
162
  }
165
- export function encodeClientFinishedV3(message) {
163
+ export function encodeClientFinishedV3(message, profile = transportV5) {
166
164
  validateHandshakeID(message.handshakeID);
167
165
  assertBytes("client confirm", message.clientConfirm, 32);
168
166
  return encodeCanonicalHandshake(HandshakeMessageTypeV3.ClientFinished, {
169
167
  client_confirm_b64u: encode32(message.clientConfirm),
170
168
  handshake_id: base64urlEncode(message.handshakeID),
171
- });
169
+ }, profile);
172
170
  }
173
- export function decodeClientFinishedV3(raw) {
171
+ export function decodeClientFinishedV3(raw, profile = transportV5) {
174
172
  const value = decodeCanonicalObject(raw, HandshakeMessageTypeV3.ClientFinished, [
175
173
  "client_confirm_b64u", "handshake_id",
176
- ]);
174
+ ], profile);
177
175
  const message = {
178
176
  handshakeID: decodeBase64(value.handshake_id),
179
177
  clientConfirm: decode32(value.client_confirm_b64u),
180
178
  };
181
179
  validateHandshakeID(message.handshakeID);
182
- requireCanonical(raw, encodeClientFinishedV3(message));
180
+ requireCanonical(raw, encodeClientFinishedV3(message, profile));
183
181
  return message;
184
182
  }
185
183
  export function generateEphemeralKeyV3(suite, entropy) {
@@ -288,39 +286,39 @@ export function verifyServerUnavailableV3(raw, psk, h0, expected) {
288
286
  throw new ProtocolV3Error("invalid handshake rejection");
289
287
  }
290
288
  }
291
- export function computeHandshakeH0V3(controlPrefaceRaw, clientInitRaw) {
292
- parseControlPrefaceV3(controlPrefaceRaw);
293
- decodeClientInitV3(clientInitRaw);
289
+ export function computeHandshakeH0V3(controlPrefaceRaw, clientInitRaw, profile = transportV5) {
290
+ parseControlPrefaceV3(controlPrefaceRaw, profile);
291
+ decodeClientInitV3(clientInitRaw, profile);
294
292
  return sha256(concatBytes([
295
- encoder.encode(FLOWERSEC_V3_CRYPTO_LABELS.handshake),
293
+ encoder.encode(profile.labels.handshake),
296
294
  controlPrefaceRaw,
297
295
  lengthPrefixed(clientInitRaw),
298
296
  ]));
299
297
  }
300
- export function computeHandshakeH1V3(h0, serverCoreRaw) {
298
+ export function computeHandshakeH1V3(h0, serverCoreRaw, profile = transportV5) {
301
299
  assertBytes("H0", h0, 32);
302
- const frame = decodeHandshakeFrameV3(serverCoreRaw);
300
+ const frame = decodeHandshakeFrameV3(serverCoreRaw, profile);
303
301
  if (frame.type !== HandshakeMessageTypeV3.ServerFinished)
304
302
  throw new ProtocolV3Error("invalid v5 transcript");
305
303
  return sha256(concatBytes([h0, lengthPrefixed(serverCoreRaw)]));
306
304
  }
307
- export function computeServerConfirmV3(handshakePRK, h1) {
308
- return computeConfirm(handshakePRK, h1, FLOWERSEC_V3_CRYPTO_LABELS["server-finished"]);
305
+ export function computeServerConfirmV3(handshakePRK, h1, profile = transportV5) {
306
+ return computeConfirm(handshakePRK, h1, profile.labels["server-finished"]);
309
307
  }
310
- export function computeHandshakeH2V3(h1, serverFinishedRaw, clientCoreRaw) {
308
+ export function computeHandshakeH2V3(h1, serverFinishedRaw, clientCoreRaw, profile = transportV5) {
311
309
  assertBytes("H1", h1, 32);
312
- if (decodeHandshakeFrameV3(serverFinishedRaw).type !== HandshakeMessageTypeV3.ServerFinished ||
313
- decodeHandshakeFrameV3(clientCoreRaw).type !== HandshakeMessageTypeV3.ClientFinished) {
310
+ if (decodeHandshakeFrameV3(serverFinishedRaw, profile).type !== HandshakeMessageTypeV3.ServerFinished ||
311
+ decodeHandshakeFrameV3(clientCoreRaw, profile).type !== HandshakeMessageTypeV3.ClientFinished) {
314
312
  throw new ProtocolV3Error("invalid v5 transcript");
315
313
  }
316
314
  return sha256(concatBytes([h1, lengthPrefixed(serverFinishedRaw), lengthPrefixed(clientCoreRaw)]));
317
315
  }
318
- export function computeClientConfirmV3(handshakePRK, h2) {
319
- return computeConfirm(handshakePRK, h2, FLOWERSEC_V3_CRYPTO_LABELS["client-finished"]);
316
+ export function computeClientConfirmV3(handshakePRK, h2, profile = transportV5) {
317
+ return computeConfirm(handshakePRK, h2, profile.labels["client-finished"]);
320
318
  }
321
- export function computeHandshakeH3V3(h2, clientFinishedRaw) {
319
+ export function computeHandshakeH3V3(h2, clientFinishedRaw, profile = transportV5) {
322
320
  assertBytes("H2", h2, 32);
323
- decodeClientFinishedV3(clientFinishedRaw);
321
+ decodeClientFinishedV3(clientFinishedRaw, profile);
324
322
  return sha256(concatBytes([h2, lengthPrefixed(clientFinishedRaw)]));
325
323
  }
326
324
  export function deriveSessionPRKV3(h3, handshakePRK) {
@@ -328,8 +326,8 @@ export function deriveSessionPRKV3(h3, handshakePRK) {
328
326
  assertBytes("handshake PRK", handshakePRK, 32);
329
327
  return extract(sha256, handshakePRK, h3);
330
328
  }
331
- export function validateClientInitV3(message, expected) {
332
- validateClientInit(message);
329
+ export function validateClientInitV3(message, expected, profile = transportV5) {
330
+ validateClientInit(message, profile);
333
331
  if (message.channelID !== expected.channelID ||
334
332
  message.suite !== expected.suite ||
335
333
  message.maxInboundStreams !== expected.maxInboundStreams ||
@@ -361,8 +359,8 @@ function serverCoreWire(core) {
361
359
  session_contract_hash_b64u: encode32(core.sessionContractHash),
362
360
  };
363
361
  }
364
- function validateClientInit(message) {
365
- if (message.profile !== FLOWERSEC_V3_PROFILE ||
362
+ function validateClientInit(message, profile) {
363
+ if (message.profile !== profile.name || (profile === transportV5) !== (message.hpkeEnc === undefined) ||
366
364
  !validRegistryID(message.channelID, false) ||
367
365
  message.clientRole !== 1 ||
368
366
  (message.selectedFeatures & ~KNOWN_FEATURES_V3) !== 0 ||
@@ -411,11 +409,11 @@ function validateEphemeralPublic(suite, value) {
411
409
  }
412
410
  invalidSuite();
413
411
  }
414
- function encodeCanonicalHandshake(type, value) {
415
- return encodeHandshakeFrameV3(type, encoder.encode(JSON.stringify(value)));
412
+ function encodeCanonicalHandshake(type, value, profile = transportV5) {
413
+ return encodeHandshakeFrameV3(type, encoder.encode(JSON.stringify(value)), profile);
416
414
  }
417
- function decodeCanonicalObject(raw, type, fields) {
418
- const frame = decodeHandshakeFrameV3(raw);
415
+ function decodeCanonicalObject(raw, type, fields, profile = transportV5) {
416
+ const frame = decodeHandshakeFrameV3(raw, profile);
419
417
  if (frame.type !== type)
420
418
  throw new ProtocolV3Error("unexpected FSH3 message type");
421
419
  let value;
@@ -2,6 +2,7 @@ import { X509Certificate, constants, createHash, getFips, timingSafeEqual } from
2
2
  import { createRequire } from "node:module";
3
3
  import { Duplex } from "node:stream";
4
4
  import tls, { checkServerIdentity as tlsCheckServerIdentity, connect as tlsConnect, } from "node:tls";
5
+ import { endpointIngress, tunnelAuthProfile } from "./wireProfile.js";
5
6
  import { defineRuntimeCapabilityDescriptorV3 } from "./capability.js";
6
7
  import { snapshotTransportSecurityPolicyV3, TransportFailureV3 } from "./security.js";
7
8
  import { FLOWERSEC_V3_PATHS, FLOWERSEC_V3_WIRE_PROFILES, websocketSubprotocolForPathV3, } from "./transportConstants.js";
@@ -230,7 +231,7 @@ export async function connectNodeWebSocketV3(candidate, attemptNowUnixSeconds, o
230
231
  ? websocketSubprotocolForPathV3("direct")
231
232
  : candidate.wire_profile === FLOWERSEC_V3_WIRE_PROFILES.tunnel
232
233
  ? websocketSubprotocolForPathV3("tunnel")
233
- : invalidProfile();
234
+ : candidate.wire_profile === tunnelAuthProfile ? endpointIngress.subprotocol : invalidProfile();
234
235
  let webSocket;
235
236
  try {
236
237
  webSocket = new Constructor(candidate.normalized_url, [subprotocol], {
@@ -334,6 +335,8 @@ function tuplesFor(carrier, datagrams) {
334
335
  ]);
335
336
  }
336
337
  function pathFromProfile(profile) {
338
+ if (profile === tunnelAuthProfile)
339
+ return endpointIngress.websocket;
337
340
  if (profile === FLOWERSEC_V3_WIRE_PROFILES.direct)
338
341
  return FLOWERSEC_V3_PATHS.websocket.direct;
339
342
  if (profile === FLOWERSEC_V3_WIRE_PROFILES.tunnel)
@@ -1,3 +1,4 @@
1
+ import { type WireProfile } from "./wireProfile.js";
1
2
  export declare class ProtocolV3Error extends Error {
2
3
  }
3
4
  export declare enum DirectionV3 {
@@ -72,30 +73,30 @@ export type StreamKeyUpdateACKV3 = Readonly<{
72
73
  transition: bigint;
73
74
  epoch: number;
74
75
  }>;
75
- export declare function deriveEpochZero(sessionPRK: Uint8Array, direction: DirectionV3): EpochRootsV3;
76
- export declare function deriveEpochRoots(epochSecret: Uint8Array): EpochRootsV3;
77
- export declare function deriveNextEpoch(rekeyRoot: Uint8Array, h3: Uint8Array, direction: DirectionV3, nextEpoch: number): Uint8Array;
78
- export declare function deriveStreamMaterial(streamRoot: Uint8Array, h3: Uint8Array, logicalStreamID: bigint, direction: DirectionV3, epoch: number): RecordMaterialV3;
79
- export declare function deriveControlMaterial(controlRoot: Uint8Array, h3: Uint8Array, direction: DirectionV3, epoch: number): RecordMaterialV3;
80
- export declare function computeSetupMAC(setupRoot: Uint8Array, h3: Uint8Array, preface: SetupPrefaceV3): Uint8Array;
81
- export declare function encodeSetupPreface(preface: SetupPrefaceV3): Uint8Array;
82
- export declare function decodeSetupPrefaceV3(raw: Uint8Array): SetupPrefaceV3;
83
- export declare function verifySetupMAC(setupRoot: Uint8Array, h3: Uint8Array, preface: SetupPrefaceV3): boolean;
84
- export declare function computeFSS3HashV3(raw: Uint8Array): Uint8Array;
85
- export declare function encodeRecordHeader(header: RecordHeaderV3): Uint8Array;
86
- export declare function decodeRecordHeader(raw: Uint8Array): RecordHeaderV3;
76
+ export declare function deriveEpochZero(sessionPRK: Uint8Array, direction: DirectionV3, profile?: WireProfile): EpochRootsV3;
77
+ export declare function deriveEpochRoots(epochSecret: Uint8Array, profile?: WireProfile): EpochRootsV3;
78
+ export declare function deriveNextEpoch(rekeyRoot: Uint8Array, h3: Uint8Array, direction: DirectionV3, nextEpoch: number, profile?: WireProfile): Uint8Array;
79
+ export declare function deriveStreamMaterial(streamRoot: Uint8Array, h3: Uint8Array, logicalStreamID: bigint, direction: DirectionV3, epoch: number, profile?: WireProfile): RecordMaterialV3;
80
+ export declare function deriveControlMaterial(controlRoot: Uint8Array, h3: Uint8Array, direction: DirectionV3, epoch: number, profile?: WireProfile): RecordMaterialV3;
81
+ export declare function computeSetupMAC(setupRoot: Uint8Array, h3: Uint8Array, preface: SetupPrefaceV3, profile?: WireProfile): Uint8Array;
82
+ export declare function encodeSetupPreface(preface: SetupPrefaceV3, profile?: WireProfile): Uint8Array;
83
+ export declare function decodeSetupPrefaceV3(raw: Uint8Array, profile?: WireProfile): SetupPrefaceV3;
84
+ export declare function verifySetupMAC(setupRoot: Uint8Array, h3: Uint8Array, preface: SetupPrefaceV3, profile?: WireProfile): boolean;
85
+ export declare function computeFSS3HashV3(raw: Uint8Array, profile?: WireProfile): Uint8Array;
86
+ export declare function encodeRecordHeader(header: RecordHeaderV3, profile?: WireProfile): Uint8Array;
87
+ export declare function decodeRecordHeader(raw: Uint8Array, profile?: WireProfile): RecordHeaderV3;
87
88
  export declare function buildDataInner(payload: Uint8Array): Uint8Array;
88
89
  export declare function encodeInnerRecordV3(type: InnerTypeV3, payload: Uint8Array): Uint8Array;
89
90
  export declare function decodeInnerRecordV3(raw: Uint8Array): InnerRecordV3;
90
91
  export declare function encodeOpenPayload(payload: OpenPayloadV3): Uint8Array;
91
92
  export declare function decodeOpenPayload(raw: Uint8Array): OpenPayloadV3;
92
- export declare function computeOpenHashV3(rawOpenPayload: Uint8Array): Uint8Array;
93
+ export declare function computeOpenHashV3(rawOpenPayload: Uint8Array, profile?: WireProfile): Uint8Array;
93
94
  export declare function encodeOpenACKV3(openHash: Uint8Array): Uint8Array;
94
95
  export declare function decodeOpenACKV3(raw: Uint8Array): Uint8Array;
95
96
  export declare function encodeOpenRejectV3(openHash: Uint8Array, reason: number): Uint8Array;
96
97
  export declare function decodeOpenRejectV3(raw: Uint8Array): OpenRejectV3;
97
98
  export declare function encodeStreamKeyUpdateACKV3(value: StreamKeyUpdateACKV3): Uint8Array;
98
99
  export declare function decodeStreamKeyUpdateACKV3(raw: Uint8Array): StreamKeyUpdateACKV3;
99
- export declare function buildRecordAAD(h3: Uint8Array, logicalStreamID: bigint, direction: DirectionV3, rawHeader: Uint8Array): Uint8Array;
100
- export declare function sealRecord(suite: CipherSuiteV3, material: RecordMaterialV3, h3: Uint8Array, logicalStreamID: bigint, direction: DirectionV3, header: RecordHeaderV3, plaintext: Uint8Array): Uint8Array;
101
- export declare function openRecord(suite: CipherSuiteV3, material: RecordMaterialV3, h3: Uint8Array, logicalStreamID: bigint, direction: DirectionV3, header: RecordHeaderV3, ciphertext: Uint8Array): Uint8Array;
100
+ export declare function buildRecordAAD(h3: Uint8Array, logicalStreamID: bigint, direction: DirectionV3, rawHeader: Uint8Array, profile?: WireProfile): Uint8Array;
101
+ export declare function sealRecord(suite: CipherSuiteV3, material: RecordMaterialV3, h3: Uint8Array, logicalStreamID: bigint, direction: DirectionV3, header: RecordHeaderV3, plaintext: Uint8Array, profile?: WireProfile): Uint8Array;
102
+ export declare function openRecord(suite: CipherSuiteV3, material: RecordMaterialV3, h3: Uint8Array, logicalStreamID: bigint, direction: DirectionV3, header: RecordHeaderV3, ciphertext: Uint8Array, profile?: WireProfile): Uint8Array;