@floegence/flowersec-core 8.0.0 → 8.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/THIRD_PARTY_NOTICES.md +8 -5
- package/dist/browser/connectSessionV3.d.ts +4 -0
- package/dist/browser/connectSessionV3.js +15 -8
- package/dist/browser/index.d.ts +1 -1
- package/dist/browser/index.js +1 -1
- package/dist/facade.d.ts +4 -0
- package/dist/facade.js +3 -0
- package/dist/framing/jsonframe.d.ts +1 -1
- package/dist/framing/jsonframe.js +13 -6
- package/dist/node/connectSessionV3.d.ts +6 -2
- package/dist/node/connectSessionV3.js +12 -6
- package/dist/node/index.d.ts +1 -1
- package/dist/node/index.js +1 -1
- package/dist/node/nativeTransportAddon.d.ts +4 -3
- package/dist/node/nativeTransportAddon.js +3 -2
- package/dist/node/rawQuicAdapterV3.d.ts +2 -2
- package/dist/node/rawQuicAdapterV3.js +5 -3
- package/dist/public/sessionHandlers.d.ts +3 -1
- package/dist/public/sessionHandlers.js +11 -3
- package/dist/rpc/server.js +3 -3
- package/dist/tunnelAuth/artifact.d.ts +34 -0
- package/dist/tunnelAuth/artifact.js +74 -0
- package/dist/tunnelAuth/credentials.d.ts +17 -0
- package/dist/tunnelAuth/credentials.js +40 -0
- package/dist/tunnelAuth/hpke.d.ts +36 -0
- package/dist/tunnelAuth/hpke.js +124 -0
- package/dist/v3/artifact.d.ts +27 -8
- package/dist/v3/artifact.js +78 -42
- package/dist/v3/artifactLease.d.ts +4 -2
- package/dist/v3/artifactLease.js +13 -1
- package/dist/v3/browserRuntime.js +5 -3
- package/dist/v3/connectionController.d.ts +2 -2
- package/dist/v3/connectionController.js +8 -4
- package/dist/v3/connectorRPCLimits.d.ts +7 -0
- package/dist/v3/connectorRPCLimits.js +14 -0
- package/dist/v3/handshake.d.ts +22 -21
- package/dist/v3/handshake.js +58 -60
- package/dist/v3/nodeRuntime.js +4 -1
- package/dist/v3/protocol.d.ts +17 -16
- package/dist/v3/protocol.js +60 -64
- package/dist/v3/publicApi.d.ts +1 -0
- package/dist/v3/publicApi.js +7 -0
- package/dist/v3/runtimeAdapters.d.ts +2 -2
- package/dist/v3/runtimeAdapters.js +2 -1
- package/dist/v3/security.d.ts +1 -1
- package/dist/v3/session.d.ts +14 -4
- package/dist/v3/session.js +174 -114
- package/dist/v3/sessionConnector.d.ts +2 -2
- package/dist/v3/sessionConnector.js +24 -13
- package/dist/v3/tunnelIngress.js +2 -1
- package/dist/v3/unreliableMessage.d.ts +3 -0
- package/dist/v3/unreliableMessage.js +24 -22
- package/dist/v3/wireProfile.d.ts +52 -0
- package/dist/v3/wireProfile.js +20 -0
- package/package.json +5 -3
- package/sbom/cyclonedx.json +133 -31
- package/sbom/spdx.json +110 -39
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { tunnelAuthProfile } from "../v3/wireProfile.js";
|
|
2
|
+
export { tunnelAuthProfile };
|
|
3
|
+
export declare class EndpointHandshakeError extends Error {
|
|
4
|
+
constructor();
|
|
5
|
+
}
|
|
6
|
+
export declare function requireEndpointCrypto(): Promise<void>;
|
|
7
|
+
export type Binding = Readonly<{
|
|
8
|
+
mode: "responder" | "mutual";
|
|
9
|
+
suite: 1 | 2 | 3;
|
|
10
|
+
channelID: string;
|
|
11
|
+
rendezvousGroupID: string;
|
|
12
|
+
listenerAudience: string;
|
|
13
|
+
clientEndpointID: string;
|
|
14
|
+
serverEndpointID: string;
|
|
15
|
+
contractHash: Uint8Array;
|
|
16
|
+
}>;
|
|
17
|
+
export declare function bindingInfo(binding: Binding): Uint8Array;
|
|
18
|
+
export declare class EndpointPublicKey {
|
|
19
|
+
#private;
|
|
20
|
+
private constructor();
|
|
21
|
+
static importPublic(raw: Uint8Array): EndpointPublicKey;
|
|
22
|
+
exportPublic(): Uint8Array;
|
|
23
|
+
}
|
|
24
|
+
export declare class EndpointIdentity {
|
|
25
|
+
#private;
|
|
26
|
+
private constructor();
|
|
27
|
+
static generate(): EndpointIdentity;
|
|
28
|
+
static importPrivate(raw: Uint8Array): EndpointIdentity;
|
|
29
|
+
publicKey(): EndpointPublicKey;
|
|
30
|
+
exportPrivate(): Uint8Array;
|
|
31
|
+
}
|
|
32
|
+
export declare function initiate(binding: Binding, peer: EndpointPublicKey, local?: EndpointIdentity): Promise<{
|
|
33
|
+
enc: Uint8Array;
|
|
34
|
+
secret: Uint8Array;
|
|
35
|
+
}>;
|
|
36
|
+
export declare function respond(binding: Binding, encapsulation: Uint8Array, local: EndpointIdentity, peer?: EndpointPublicKey): Promise<Uint8Array>;
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { Aes128Gcm, CipherSuite, HkdfSha256 } from "@hpke/core";
|
|
2
|
+
import { DhkemX25519HkdfSha256 } from "@hpke/dhkem-x25519";
|
|
3
|
+
import { x25519 } from "@noble/curves/ed25519.js";
|
|
4
|
+
import { base64urlEncode } from "../utils/base64url.js";
|
|
5
|
+
import { concatBytes, u32be } from "../utils/bin.js";
|
|
6
|
+
import { jcsUTF8V3 } from "../v3/jcs.js";
|
|
7
|
+
import { tunnelAuthProfile } from "../v3/wireProfile.js";
|
|
8
|
+
export { tunnelAuthProfile };
|
|
9
|
+
export class EndpointHandshakeError extends Error {
|
|
10
|
+
constructor() { super("tunnel endpoint authentication failed"); }
|
|
11
|
+
}
|
|
12
|
+
const text = new TextEncoder();
|
|
13
|
+
const exporter = text.encode("flowersec-tunnel-auth-v1-auth-secret");
|
|
14
|
+
const infoLabel = text.encode("flowersec-tunnel-auth-v1-hpke\0");
|
|
15
|
+
const kem = new DhkemX25519HkdfSha256();
|
|
16
|
+
const suite = new CipherSuite({ kem, kdf: new HkdfSha256(), aead: new Aes128Gcm() });
|
|
17
|
+
let capability;
|
|
18
|
+
export async function requireEndpointCrypto() {
|
|
19
|
+
capability ??= (async () => {
|
|
20
|
+
const recipient = await kem.generateKeyPair();
|
|
21
|
+
const context = await suite.createSenderContext({ recipientPublicKey: recipient.publicKey });
|
|
22
|
+
new Uint8Array(await context.export(exporter, 32)).fill(0);
|
|
23
|
+
})().catch(error => {
|
|
24
|
+
capability = undefined;
|
|
25
|
+
throw error;
|
|
26
|
+
});
|
|
27
|
+
return capability;
|
|
28
|
+
}
|
|
29
|
+
export function bindingInfo(binding) {
|
|
30
|
+
const identifiers = [binding.channelID, binding.rendezvousGroupID, binding.listenerAudience, binding.clientEndpointID, binding.serverEndpointID];
|
|
31
|
+
if (identifiers.some(value => typeof value !== "string" || value.length < 1 || value.length > 128 || /[^A-Za-z0-9._~-]/.test(value)) ||
|
|
32
|
+
binding.clientEndpointID === binding.serverEndpointID || binding.contractHash.length !== 32 ||
|
|
33
|
+
![1, 2, 3].includes(binding.suite) || !["responder", "mutual"].includes(binding.mode)) {
|
|
34
|
+
throw new Error("invalid tunnel endpoint binding");
|
|
35
|
+
}
|
|
36
|
+
const payload = jcsUTF8V3({
|
|
37
|
+
auth_mode: binding.mode, channel_id: binding.channelID, client_endpoint_instance_id: binding.clientEndpointID,
|
|
38
|
+
contract_hash_b64u: base64urlEncode(binding.contractHash), listener_audience: binding.listenerAudience,
|
|
39
|
+
profile: tunnelAuthProfile, rendezvous_group_id: binding.rendezvousGroupID, server_endpoint_instance_id: binding.serverEndpointID,
|
|
40
|
+
suite: binding.suite,
|
|
41
|
+
});
|
|
42
|
+
return concatBytes([infoLabel, u32be(payload.length), payload]);
|
|
43
|
+
}
|
|
44
|
+
function checkPublic(raw) {
|
|
45
|
+
if (raw.length !== 32 || raw[31] > 127 ||
|
|
46
|
+
(raw[31] === 127 && raw[0] >= 237 && raw.subarray(1, 31).every(octet => octet === 255))) {
|
|
47
|
+
throw new Error("invalid endpoint public key");
|
|
48
|
+
}
|
|
49
|
+
const probe = new Uint8Array(32);
|
|
50
|
+
probe[0] = 8;
|
|
51
|
+
try {
|
|
52
|
+
x25519.getSharedSecret(probe, raw).fill(0);
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
throw new Error("invalid endpoint public key");
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
export class EndpointPublicKey {
|
|
59
|
+
#raw;
|
|
60
|
+
constructor(raw) { this.#raw = raw; }
|
|
61
|
+
static importPublic(raw) {
|
|
62
|
+
const copy = new Uint8Array(raw);
|
|
63
|
+
checkPublic(copy);
|
|
64
|
+
return new EndpointPublicKey(copy);
|
|
65
|
+
}
|
|
66
|
+
exportPublic() { return new Uint8Array(this.#raw); }
|
|
67
|
+
}
|
|
68
|
+
export class EndpointIdentity {
|
|
69
|
+
#raw;
|
|
70
|
+
#public;
|
|
71
|
+
constructor(raw) {
|
|
72
|
+
this.#raw = raw;
|
|
73
|
+
this.#public = EndpointPublicKey.importPublic(x25519.getPublicKey(raw));
|
|
74
|
+
}
|
|
75
|
+
static generate() { return new EndpointIdentity(x25519.utils.randomSecretKey()); }
|
|
76
|
+
static importPrivate(raw) {
|
|
77
|
+
if (raw.length !== 32)
|
|
78
|
+
throw new Error("invalid endpoint identity");
|
|
79
|
+
return new EndpointIdentity(new Uint8Array(raw));
|
|
80
|
+
}
|
|
81
|
+
publicKey() { return this.#public; }
|
|
82
|
+
exportPrivate() { return new Uint8Array(this.#raw); }
|
|
83
|
+
}
|
|
84
|
+
async function privateKey(identity) {
|
|
85
|
+
const raw = identity.exportPrivate();
|
|
86
|
+
try {
|
|
87
|
+
return await kem.deserializePrivateKey(raw);
|
|
88
|
+
}
|
|
89
|
+
finally {
|
|
90
|
+
raw.fill(0);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
function distinct(local, peer) {
|
|
94
|
+
const other = peer.exportPublic();
|
|
95
|
+
return local.publicKey().exportPublic().some((value, index) => value !== other[index]);
|
|
96
|
+
}
|
|
97
|
+
export async function initiate(binding, peer, local) {
|
|
98
|
+
try {
|
|
99
|
+
const info = bindingInfo(binding);
|
|
100
|
+
if ((binding.mode === "mutual") !== (local !== undefined) || (local && !distinct(local, peer)))
|
|
101
|
+
throw new Error();
|
|
102
|
+
const recipientPublicKey = await kem.deserializePublicKey(peer.exportPublic());
|
|
103
|
+
const channel = await suite.createSenderContext({ info, recipientPublicKey, ...(local ? { senderKey: await privateKey(local) } : {}) });
|
|
104
|
+
return { enc: new Uint8Array(channel.enc), secret: new Uint8Array(await channel.export(exporter, 32)) };
|
|
105
|
+
}
|
|
106
|
+
catch {
|
|
107
|
+
throw new EndpointHandshakeError();
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
export async function respond(binding, encapsulation, local, peer) {
|
|
111
|
+
try {
|
|
112
|
+
const info = bindingInfo(binding);
|
|
113
|
+
const enc = new Uint8Array(encapsulation);
|
|
114
|
+
checkPublic(enc);
|
|
115
|
+
if ((binding.mode === "mutual") !== (peer !== undefined) || (peer && !distinct(local, peer)))
|
|
116
|
+
throw new Error();
|
|
117
|
+
const recipientKey = await privateKey(local);
|
|
118
|
+
const channel = await suite.createRecipientContext({ info, enc, recipientKey, ...(peer ? { senderPublicKey: await kem.deserializePublicKey(peer.exportPublic()) } : {}) });
|
|
119
|
+
return new Uint8Array(await channel.export(exporter, 32));
|
|
120
|
+
}
|
|
121
|
+
catch {
|
|
122
|
+
throw new EndpointHandshakeError();
|
|
123
|
+
}
|
|
124
|
+
}
|
package/dist/v3/artifact.d.ts
CHANGED
|
@@ -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:
|
|
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
|
|
138
|
-
export declare function
|
|
139
|
-
export declare function
|
|
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
|
|
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 {};
|
package/dist/v3/artifact.js
CHANGED
|
@@ -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:
|
|
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(
|
|
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(
|
|
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
|
-
|
|
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
|
|
229
|
-
|
|
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
|
|
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
|
|
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(
|
|
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
|
|
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
|
|
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
|
-
|
|
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 !==
|
|
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:
|
|
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 !==
|
|
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
|
|
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
|
|
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>;
|
package/dist/v3/artifactLease.js
CHANGED
|
@@ -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,
|
|
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:
|
|
30
|
+
artifact: ConnectionArtifact;
|
|
31
31
|
candidates: readonly CanonicalArtifactCandidateV3[];
|
|
32
32
|
claim: ClaimedArtifactLeaseV3;
|
|
33
33
|
signal: AbortSignal;
|