@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.
- package/THIRD_PARTY_NOTICES.md +8 -5
- package/dist/browser/connectSessionV3.d.ts +4 -0
- package/dist/browser/connectSessionV3.js +12 -4
- package/dist/browser/index.d.ts +1 -1
- package/dist/browser/index.js +1 -1
- package/dist/facade.d.ts +4 -0
- package/dist/facade.js +3 -0
- package/dist/node/connectSessionV3.d.ts +4 -0
- package/dist/node/connectSessionV3.js +7 -0
- package/dist/node/index.d.ts +1 -1
- package/dist/node/index.js +1 -1
- package/dist/node/nativeTransportAddon.d.ts +4 -3
- package/dist/node/nativeTransportAddon.js +3 -2
- package/dist/node/rawQuicAdapterV3.d.ts +2 -2
- package/dist/node/rawQuicAdapterV3.js +5 -3
- package/dist/tunnelAuth/artifact.d.ts +34 -0
- package/dist/tunnelAuth/artifact.js +74 -0
- package/dist/tunnelAuth/credentials.d.ts +17 -0
- package/dist/tunnelAuth/credentials.js +40 -0
- package/dist/tunnelAuth/hpke.d.ts +36 -0
- package/dist/tunnelAuth/hpke.js +124 -0
- package/dist/v3/artifact.d.ts +27 -8
- package/dist/v3/artifact.js +78 -42
- package/dist/v3/artifactLease.d.ts +4 -2
- package/dist/v3/artifactLease.js +13 -1
- package/dist/v3/browserRuntime.js +5 -3
- package/dist/v3/connectionController.d.ts +2 -2
- package/dist/v3/connectionController.js +8 -4
- package/dist/v3/handshake.d.ts +22 -21
- package/dist/v3/handshake.js +58 -60
- package/dist/v3/nodeRuntime.js +4 -1
- package/dist/v3/protocol.d.ts +17 -16
- package/dist/v3/protocol.js +60 -64
- package/dist/v3/runtimeAdapters.d.ts +2 -2
- package/dist/v3/runtimeAdapters.js +2 -1
- package/dist/v3/security.d.ts +1 -1
- package/dist/v3/session.d.ts +14 -4
- package/dist/v3/session.js +174 -114
- package/dist/v3/sessionConnector.d.ts +2 -2
- package/dist/v3/sessionConnector.js +24 -13
- package/dist/v3/tunnelIngress.js +2 -1
- package/dist/v3/unreliableMessage.d.ts +3 -0
- package/dist/v3/unreliableMessage.js +24 -22
- package/dist/v3/wireProfile.d.ts +52 -0
- package/dist/v3/wireProfile.js +20 -0
- package/package.json +5 -3
- package/sbom/cyclonedx.json +133 -31
- package/sbom/spdx.json +110 -39
package/dist/v3/handshake.js
CHANGED
|
@@ -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 {
|
|
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
|
|
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
|
|
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 >
|
|
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
|
|
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
|
|
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 >
|
|
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(
|
|
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,
|
|
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,
|
|
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 !==
|
|
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;
|
package/dist/v3/nodeRuntime.js
CHANGED
|
@@ -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)
|
package/dist/v3/protocol.d.ts
CHANGED
|
@@ -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;
|
package/dist/v3/protocol.js
CHANGED
|
@@ -4,10 +4,12 @@ import { expand } from "@noble/hashes/hkdf.js";
|
|
|
4
4
|
import { hmac } from "@noble/hashes/hmac.js";
|
|
5
5
|
import { sha256 } from "@noble/hashes/sha2.js";
|
|
6
6
|
import { unicode151Assigned } from "../generated/unicode151.js";
|
|
7
|
-
import {
|
|
7
|
+
import { matchesFramePrefix, transportV5, tunnelAuthV1, writeFramePrefix } from "./wireProfile.js";
|
|
8
8
|
const encoder = new TextEncoder();
|
|
9
|
-
const
|
|
10
|
-
|
|
9
|
+
const recordAADLabels = {
|
|
10
|
+
[transportV5.name]: encoder.encode(transportV5.labels["record-aad"]),
|
|
11
|
+
[tunnelAuthV1.name]: encoder.encode(tunnelAuthV1.labels["record-aad"]),
|
|
12
|
+
};
|
|
11
13
|
const MAX_UINT32 = 0xffffffff;
|
|
12
14
|
const MAX_UINT64 = (1n << 64n) - 1n;
|
|
13
15
|
const SETUP_PREFACE_BYTES = 56;
|
|
@@ -59,61 +61,61 @@ export var InnerTypeV3;
|
|
|
59
61
|
InnerTypeV3[InnerTypeV3["StreamKeyUpdateACK"] = 25] = "StreamKeyUpdateACK";
|
|
60
62
|
InnerTypeV3[InnerTypeV3["SessionReadyConfirm"] = 26] = "SessionReadyConfirm";
|
|
61
63
|
})(InnerTypeV3 || (InnerTypeV3 = {}));
|
|
62
|
-
export function deriveEpochZero(sessionPRK, direction) {
|
|
64
|
+
export function deriveEpochZero(sessionPRK, direction, profile = transportV5) {
|
|
63
65
|
assertBytes("session PRK", sessionPRK, 32);
|
|
64
66
|
assertDirection(direction);
|
|
65
|
-
const epochSecret = expand32(sessionPRK, labelWith(
|
|
66
|
-
return deriveEpochRoots(epochSecret);
|
|
67
|
+
const epochSecret = expand32(sessionPRK, labelWith(profile.labels["epoch-zero"], byte(direction)));
|
|
68
|
+
return deriveEpochRoots(epochSecret, profile);
|
|
67
69
|
}
|
|
68
|
-
export function deriveEpochRoots(epochSecret) {
|
|
70
|
+
export function deriveEpochRoots(epochSecret, profile = transportV5) {
|
|
69
71
|
assertBytes("epoch secret", epochSecret, 32);
|
|
70
72
|
return {
|
|
71
73
|
epochSecret: epochSecret.slice(),
|
|
72
|
-
controlRoot: expand32(epochSecret, labelWith(
|
|
73
|
-
streamRoot: expand32(epochSecret, labelWith(
|
|
74
|
-
setupRoot: expand32(epochSecret, labelWith(
|
|
75
|
-
rekeyRoot: expand32(epochSecret, labelWith(
|
|
74
|
+
controlRoot: expand32(epochSecret, labelWith(profile.labels["control-root"])),
|
|
75
|
+
streamRoot: expand32(epochSecret, labelWith(profile.labels["stream-root"])),
|
|
76
|
+
setupRoot: expand32(epochSecret, labelWith(profile.labels["setup-root"])),
|
|
77
|
+
rekeyRoot: expand32(epochSecret, labelWith(profile.labels["rekey-root"])),
|
|
76
78
|
};
|
|
77
79
|
}
|
|
78
|
-
export function deriveNextEpoch(rekeyRoot, h3, direction, nextEpoch) {
|
|
80
|
+
export function deriveNextEpoch(rekeyRoot, h3, direction, nextEpoch, profile = transportV5) {
|
|
79
81
|
assertBytes("rekey root", rekeyRoot, 32);
|
|
80
82
|
assertBytes("H3", h3, 32);
|
|
81
83
|
assertDirection(direction);
|
|
82
84
|
assertU32("next epoch", nextEpoch);
|
|
83
|
-
return expand32(rekeyRoot, labelWith(
|
|
85
|
+
return expand32(rekeyRoot, labelWith(profile.labels["next-epoch"], h3, byte(direction), u32be(nextEpoch)));
|
|
84
86
|
}
|
|
85
|
-
export function deriveStreamMaterial(streamRoot, h3, logicalStreamID, direction, epoch) {
|
|
87
|
+
export function deriveStreamMaterial(streamRoot, h3, logicalStreamID, direction, epoch, profile = transportV5) {
|
|
86
88
|
assertBytes("stream root", streamRoot, 32);
|
|
87
89
|
assertBytes("H3", h3, 32);
|
|
88
90
|
assertLogicalStreamID(logicalStreamID);
|
|
89
91
|
assertDirection(direction);
|
|
90
92
|
assertU32("epoch", epoch);
|
|
91
|
-
const secret = expand32(streamRoot, labelWith(
|
|
93
|
+
const secret = expand32(streamRoot, labelWith(profile.labels.stream, h3, u64be(logicalStreamID), byte(direction), u32be(epoch)));
|
|
92
94
|
return {
|
|
93
95
|
secret,
|
|
94
|
-
recordKey: expand32(secret, labelWith(
|
|
95
|
-
noncePrefix: expand(sha256, secret, labelWith(
|
|
96
|
+
recordKey: expand32(secret, labelWith(profile.labels["record-key"])),
|
|
97
|
+
noncePrefix: expand(sha256, secret, labelWith(profile.labels.nonce), 4),
|
|
96
98
|
};
|
|
97
99
|
}
|
|
98
|
-
export function deriveControlMaterial(controlRoot, h3, direction, epoch) {
|
|
100
|
+
export function deriveControlMaterial(controlRoot, h3, direction, epoch, profile = transportV5) {
|
|
99
101
|
assertBytes("control root", controlRoot, 32);
|
|
100
102
|
assertBytes("H3", h3, 32);
|
|
101
103
|
assertDirection(direction);
|
|
102
104
|
assertU32("epoch", epoch);
|
|
103
|
-
const secret = expand32(controlRoot, labelWith(
|
|
105
|
+
const secret = expand32(controlRoot, labelWith(profile.labels.control, h3, u64be(0n), byte(direction), u32be(epoch)));
|
|
104
106
|
return {
|
|
105
107
|
secret,
|
|
106
|
-
recordKey: expand32(secret, labelWith(
|
|
107
|
-
noncePrefix: expand(sha256, secret, labelWith(
|
|
108
|
+
recordKey: expand32(secret, labelWith(profile.labels["record-key"])),
|
|
109
|
+
noncePrefix: expand(sha256, secret, labelWith(profile.labels.nonce), 4),
|
|
108
110
|
};
|
|
109
111
|
}
|
|
110
|
-
export function computeSetupMAC(setupRoot, h3, preface) {
|
|
112
|
+
export function computeSetupMAC(setupRoot, h3, preface, profile = transportV5) {
|
|
111
113
|
assertBytes("setup root", setupRoot, 32);
|
|
112
114
|
assertBytes("H3", h3, 32);
|
|
113
|
-
const raw = encodeSetupPreface(preface);
|
|
114
|
-
return hmac(sha256, setupRoot, exactLabelWith(
|
|
115
|
+
const raw = encodeSetupPreface(preface, profile);
|
|
116
|
+
return hmac(sha256, setupRoot, exactLabelWith(profile.labels["setup-mac"], h3, raw.subarray(0, 24)));
|
|
115
117
|
}
|
|
116
|
-
export function encodeSetupPreface(preface) {
|
|
118
|
+
export function encodeSetupPreface(preface, profile = transportV5) {
|
|
117
119
|
assertLogicalStreamID(preface.logicalStreamID);
|
|
118
120
|
if ((preface.openerRole !== 1 && preface.openerRole !== 2) ||
|
|
119
121
|
(preface.openerRole === 1 && (preface.logicalStreamID & 1n) !== 1n) ||
|
|
@@ -123,18 +125,16 @@ export function encodeSetupPreface(preface) {
|
|
|
123
125
|
assertU32("initial send epoch", preface.initialSendEpoch);
|
|
124
126
|
assertBytes("setup MAC", preface.setupMAC, 32);
|
|
125
127
|
const out = new Uint8Array(SETUP_PREFACE_BYTES);
|
|
126
|
-
out
|
|
127
|
-
out[4] = 5;
|
|
128
|
+
writeFramePrefix(out, 0x53, profile);
|
|
128
129
|
out[5] = preface.openerRole;
|
|
129
130
|
out.set(u64be(preface.logicalStreamID), 8);
|
|
130
131
|
out.set(u32be(preface.initialSendEpoch), 16);
|
|
131
132
|
out.set(preface.setupMAC, 24);
|
|
132
133
|
return out;
|
|
133
134
|
}
|
|
134
|
-
export function decodeSetupPrefaceV3(raw) {
|
|
135
|
+
export function decodeSetupPrefaceV3(raw, profile = transportV5) {
|
|
135
136
|
if (raw.length !== SETUP_PREFACE_BYTES ||
|
|
136
|
-
raw
|
|
137
|
-
raw[4] !== 5 || raw[6] !== 0 || raw[7] !== 0 || readU32be(raw, 20) !== 0) {
|
|
137
|
+
!matchesFramePrefix(raw, 0x53, profile) || raw[6] !== 0 || raw[7] !== 0 || readU32be(raw, 20) !== 0) {
|
|
138
138
|
throw new ProtocolV3Error("invalid FSS3 setup preface");
|
|
139
139
|
}
|
|
140
140
|
const openerRole = raw[5];
|
|
@@ -152,40 +152,35 @@ export function decodeSetupPrefaceV3(raw) {
|
|
|
152
152
|
setupMAC: raw.slice(24, 56),
|
|
153
153
|
};
|
|
154
154
|
}
|
|
155
|
-
export function verifySetupMAC(setupRoot, h3, preface) {
|
|
156
|
-
const want = computeSetupMAC(setupRoot, h3, { ...preface, setupMAC: new Uint8Array(32) });
|
|
155
|
+
export function verifySetupMAC(setupRoot, h3, preface, profile = transportV5) {
|
|
156
|
+
const want = computeSetupMAC(setupRoot, h3, { ...preface, setupMAC: new Uint8Array(32) }, profile);
|
|
157
157
|
return bytesEqual(want, preface.setupMAC);
|
|
158
158
|
}
|
|
159
|
-
export function computeFSS3HashV3(raw) {
|
|
160
|
-
decodeSetupPrefaceV3(raw);
|
|
159
|
+
export function computeFSS3HashV3(raw, profile = transportV5) {
|
|
160
|
+
decodeSetupPrefaceV3(raw, profile);
|
|
161
161
|
return computeValidatedFSS3HashV3Internal(raw);
|
|
162
162
|
}
|
|
163
163
|
/** @internal Hashes an FSS3 preface that was encoded or decoded by this module. */
|
|
164
164
|
export function computeValidatedFSS3HashV3Internal(raw) {
|
|
165
165
|
return sha256(raw);
|
|
166
166
|
}
|
|
167
|
-
export function encodeRecordHeader(header) {
|
|
167
|
+
export function encodeRecordHeader(header, profile = transportV5) {
|
|
168
168
|
const out = new Uint8Array(RECORD_HEADER_BYTES);
|
|
169
|
-
writeRecordHeader(out, header);
|
|
169
|
+
writeRecordHeader(out, header, profile);
|
|
170
170
|
return out;
|
|
171
171
|
}
|
|
172
|
-
function writeRecordHeader(out, header) {
|
|
172
|
+
function writeRecordHeader(out, header, profile) {
|
|
173
173
|
validateRecordHeader(header);
|
|
174
174
|
const fields = new DataView(out.buffer, out.byteOffset, out.byteLength);
|
|
175
|
-
out
|
|
176
|
-
out[4] = 5;
|
|
175
|
+
writeFramePrefix(out, 0x52, profile);
|
|
177
176
|
out[5] = RECORD_HEADER_BYTES;
|
|
178
177
|
fields.setUint32(8, header.epoch, false);
|
|
179
178
|
fields.setBigUint64(12, header.sequence, false);
|
|
180
179
|
fields.setUint32(20, header.ciphertextLength, false);
|
|
181
180
|
}
|
|
182
|
-
export function decodeRecordHeader(raw) {
|
|
181
|
+
export function decodeRecordHeader(raw, profile = transportV5) {
|
|
183
182
|
if (raw.length !== RECORD_HEADER_BYTES ||
|
|
184
|
-
raw
|
|
185
|
-
raw[1] !== 0x53 ||
|
|
186
|
-
raw[2] !== 0x52 ||
|
|
187
|
-
raw[3] !== 0x35 ||
|
|
188
|
-
raw[4] !== 5 ||
|
|
183
|
+
!matchesFramePrefix(raw, 0x52, profile) ||
|
|
189
184
|
raw[5] !== RECORD_HEADER_BYTES ||
|
|
190
185
|
raw[6] !== 0 ||
|
|
191
186
|
raw[7] !== 0) {
|
|
@@ -288,13 +283,13 @@ export function decodeOpenPayload(raw) {
|
|
|
288
283
|
metadata,
|
|
289
284
|
};
|
|
290
285
|
}
|
|
291
|
-
export function computeOpenHashV3(rawOpenPayload) {
|
|
286
|
+
export function computeOpenHashV3(rawOpenPayload, profile = transportV5) {
|
|
292
287
|
decodeOpenPayload(rawOpenPayload);
|
|
293
|
-
return computeValidatedOpenHashV3Internal(rawOpenPayload);
|
|
288
|
+
return computeValidatedOpenHashV3Internal(rawOpenPayload, profile);
|
|
294
289
|
}
|
|
295
290
|
/** @internal Hashes an OPEN payload that was encoded or decoded by this module. */
|
|
296
|
-
export function computeValidatedOpenHashV3Internal(rawOpenPayload) {
|
|
297
|
-
return sha256(concat(encoder.encode(
|
|
291
|
+
export function computeValidatedOpenHashV3Internal(rawOpenPayload, profile = transportV5) {
|
|
292
|
+
return sha256(concat(encoder.encode(profile.labels.open), u32be(rawOpenPayload.length), rawOpenPayload));
|
|
298
293
|
}
|
|
299
294
|
export function encodeOpenACKV3(openHash) {
|
|
300
295
|
assertBytes("OPEN hash", openHash, 32);
|
|
@@ -345,15 +340,16 @@ export function decodeStreamKeyUpdateACKV3(raw) {
|
|
|
345
340
|
throw new ProtocolV3Error("stream rekey epoch must be non-zero");
|
|
346
341
|
return value;
|
|
347
342
|
}
|
|
348
|
-
export function buildRecordAAD(h3, logicalStreamID, direction, rawHeader) {
|
|
343
|
+
export function buildRecordAAD(h3, logicalStreamID, direction, rawHeader, profile = transportV5) {
|
|
349
344
|
assertBytes("H3", h3, 32);
|
|
350
345
|
assertU64("logical stream ID", logicalStreamID);
|
|
351
346
|
assertDirection(direction);
|
|
352
|
-
decodeRecordHeader(rawHeader);
|
|
353
|
-
return buildValidatedRecordAAD(h3, logicalStreamID, direction, rawHeader);
|
|
347
|
+
decodeRecordHeader(rawHeader, profile);
|
|
348
|
+
return buildValidatedRecordAAD(h3, logicalStreamID, direction, rawHeader, profile);
|
|
354
349
|
}
|
|
355
|
-
function buildValidatedRecordAAD(h3, logicalStreamID, direction, rawHeader) {
|
|
350
|
+
function buildValidatedRecordAAD(h3, logicalStreamID, direction, rawHeader, profile) {
|
|
356
351
|
assertU64("uint64", logicalStreamID);
|
|
352
|
+
const recordAADLabel = recordAADLabels[profile.name];
|
|
357
353
|
const streamOffset = recordAADLabel.length + h3.length;
|
|
358
354
|
const aad = new Uint8Array(streamOffset + 9 + rawHeader.length);
|
|
359
355
|
aad.set(recordAADLabel);
|
|
@@ -370,31 +366,31 @@ function recordNonce(prefix, sequence) {
|
|
|
370
366
|
new DataView(nonce.buffer).setBigUint64(prefix.length, sequence, false);
|
|
371
367
|
return nonce;
|
|
372
368
|
}
|
|
373
|
-
export function sealRecord(suite, material, h3, logicalStreamID, direction, header, plaintext) {
|
|
369
|
+
export function sealRecord(suite, material, h3, logicalStreamID, direction, header, plaintext, profile = transportV5) {
|
|
374
370
|
assertBytes("H3", h3, 32);
|
|
375
371
|
assertDirection(direction);
|
|
376
372
|
validateMaterial(material);
|
|
377
373
|
if (plaintext.length + 16 !== header.ciphertextLength) {
|
|
378
374
|
throw new ProtocolV3Error("FSR3 plaintext length does not match the header");
|
|
379
375
|
}
|
|
380
|
-
const rawHeader = encodeRecordHeader(header);
|
|
376
|
+
const rawHeader = encodeRecordHeader(header, profile);
|
|
381
377
|
const nonce = recordNonce(material.noncePrefix, header.sequence);
|
|
382
|
-
const aad = buildValidatedRecordAAD(h3, logicalStreamID, direction, rawHeader);
|
|
378
|
+
const aad = buildValidatedRecordAAD(h3, logicalStreamID, direction, rawHeader, profile);
|
|
383
379
|
return cipher(suite, material.recordKey, nonce, aad).encrypt(plaintext);
|
|
384
380
|
}
|
|
385
381
|
/** @internal Seals an inner record in the buffer used for the carrier write. */
|
|
386
|
-
export function sealRecordWireV3Internal(suite, material, h3, logicalStreamID, direction, epoch, sequence, type, payload) {
|
|
382
|
+
export function sealRecordWireV3Internal(suite, material, h3, logicalStreamID, direction, epoch, sequence, type, payload, profile = transportV5) {
|
|
387
383
|
validateInnerPayload(type, payload.length);
|
|
388
384
|
validateMaterial(material);
|
|
389
385
|
const ciphertextLength = INNER_HEADER_BYTES + payload.length + 16;
|
|
390
386
|
const wire = new Uint8Array(RECORD_HEADER_BYTES + ciphertextLength);
|
|
391
387
|
const rawHeader = wire.subarray(0, RECORD_HEADER_BYTES);
|
|
392
|
-
writeRecordHeader(rawHeader, { epoch, sequence, ciphertextLength });
|
|
388
|
+
writeRecordHeader(rawHeader, { epoch, sequence, ciphertextLength }, profile);
|
|
393
389
|
const body = wire.subarray(RECORD_HEADER_BYTES);
|
|
394
390
|
const inner = body.subarray(0, -16);
|
|
395
391
|
writeInnerRecord(inner, type, payload);
|
|
396
392
|
const nonce = recordNonce(material.noncePrefix, sequence);
|
|
397
|
-
const aad = buildValidatedRecordAAD(h3, logicalStreamID, direction, rawHeader);
|
|
393
|
+
const aad = buildValidatedRecordAAD(h3, logicalStreamID, direction, rawHeader, profile);
|
|
398
394
|
if (suite === CipherSuiteV3.ChaCha20Poly1305 || suite === CipherSuiteV3.XWing) {
|
|
399
395
|
chacha20poly1305(material.recordKey, nonce, aad).encrypt(inner, body);
|
|
400
396
|
}
|
|
@@ -403,20 +399,20 @@ export function sealRecordWireV3Internal(suite, material, h3, logicalStreamID, d
|
|
|
403
399
|
}
|
|
404
400
|
return wire;
|
|
405
401
|
}
|
|
406
|
-
export function openRecord(suite, material, h3, logicalStreamID, direction, header, ciphertext) {
|
|
402
|
+
export function openRecord(suite, material, h3, logicalStreamID, direction, header, ciphertext, profile = transportV5) {
|
|
407
403
|
assertBytes("H3", h3, 32);
|
|
408
404
|
assertDirection(direction);
|
|
409
|
-
const rawHeader = encodeRecordHeader(header);
|
|
410
|
-
return openRecordWithRawHeaderV3Internal(suite, material, h3, logicalStreamID, direction, header, rawHeader, ciphertext);
|
|
405
|
+
const rawHeader = encodeRecordHeader(header, profile);
|
|
406
|
+
return openRecordWithRawHeaderV3Internal(suite, material, h3, logicalStreamID, direction, header, rawHeader, ciphertext, profile);
|
|
411
407
|
}
|
|
412
408
|
/** @internal Opens a record whose exact raw header was already decoded by this module. */
|
|
413
|
-
export function openRecordWithRawHeaderV3Internal(suite, material, h3, logicalStreamID, direction, header, rawHeader, ciphertext) {
|
|
409
|
+
export function openRecordWithRawHeaderV3Internal(suite, material, h3, logicalStreamID, direction, header, rawHeader, ciphertext, profile = transportV5) {
|
|
414
410
|
validateMaterial(material);
|
|
415
411
|
if (ciphertext.length !== header.ciphertextLength) {
|
|
416
412
|
throw new ProtocolV3Error("FSR3 ciphertext length does not match the header");
|
|
417
413
|
}
|
|
418
414
|
const nonce = recordNonce(material.noncePrefix, header.sequence);
|
|
419
|
-
const aad = buildValidatedRecordAAD(h3, logicalStreamID, direction, rawHeader);
|
|
415
|
+
const aad = buildValidatedRecordAAD(h3, logicalStreamID, direction, rawHeader, profile);
|
|
420
416
|
try {
|
|
421
417
|
return cipher(suite, material.recordKey, nonce, aad).decrypt(ciphertext);
|
|
422
418
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { type WebSocketLike } from "../ws-client/binaryTransport.js";
|
|
2
|
-
import type {
|
|
2
|
+
import type { ConnectionArtifact, CanonicalArtifactCandidateV3 } from "./artifact.js";
|
|
3
3
|
import { type NativeCarrierSessionV3 } from "./carrier.js";
|
|
4
4
|
import type { ReadyAdmissionTransportV3 } from "./sessionConnector.js";
|
|
5
5
|
export type WebSocketLikeV3 = WebSocketLike & Readonly<{
|
|
6
6
|
protocol?: string;
|
|
7
7
|
}>;
|
|
8
|
-
export declare function readyWebSocketAdmissionV3(candidate: CanonicalArtifactCandidateV3, artifact:
|
|
8
|
+
export declare function readyWebSocketAdmissionV3(candidate: CanonicalArtifactCandidateV3, artifact: ConnectionArtifact, socket: WebSocketLikeV3, signal: AbortSignal): Promise<ReadyAdmissionTransportV3>;
|
|
9
9
|
export declare function readyNativeAdmissionV3(candidate: CanonicalArtifactCandidateV3, carrier: NativeCarrierSessionV3): ReadyAdmissionTransportV3;
|