@php-wasm/web 1.0.29 → 1.1.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/index.cjs +21 -0
- package/index.cjs.map +1 -0
- package/index.js +666 -631
- package/index.js.map +1 -1
- package/lib/chunked-decoder.d.ts +8 -0
- package/lib/directory-handle-mount.d.ts +1 -1
- package/lib/get-php-loader-module.d.ts +1 -1
- package/lib/load-runtime.d.ts +4 -3
- package/lib/tcp-over-fetch-websocket.d.ts +32 -4
- package/lib/tls/1_2/types.d.ts +19 -17
- package/lib/tls/extensions/parse-extensions.d.ts +8 -4
- package/lib/tls/utils.d.ts +1 -1
- package/lib/with-icu-data.d.ts +2 -0
- package/package.json +28 -14
- package/php/asyncify/7_0_33/php_7_0.wasm +0 -0
- package/php/asyncify/7_1_30/php_7_1.wasm +0 -0
- package/php/asyncify/7_2_34/php_7_2.wasm +0 -0
- package/php/asyncify/7_3_33/php_7_3.wasm +0 -0
- package/php/asyncify/7_4_33/php_7_4.wasm +0 -0
- package/php/asyncify/8_0_30/php_8_0.wasm +0 -0
- package/php/asyncify/8_1_23/php_8_1.wasm +0 -0
- package/php/asyncify/8_2_10/php_8_2.wasm +0 -0
- package/php/asyncify/8_3_0/php_8_3.wasm +0 -0
- package/php/asyncify/8_4_0/php_8_4.wasm +0 -0
- package/php/asyncify/php_7_0.js +13 -39
- package/php/asyncify/php_7_1.js +13 -39
- package/php/asyncify/php_7_2.js +13 -39
- package/php/asyncify/php_7_3.js +13 -39
- package/php/asyncify/php_7_4.js +13 -39
- package/php/asyncify/php_8_0.js +13 -39
- package/php/asyncify/php_8_1.js +13 -39
- package/php/asyncify/php_8_2.js +13 -39
- package/php/asyncify/php_8_3.js +13 -39
- package/php/asyncify/php_8_4.js +13 -39
- package/php/jspi/7_0_33/php_7_0.wasm +0 -0
- package/php/jspi/7_1_30/php_7_1.wasm +0 -0
- package/php/jspi/7_2_34/php_7_2.wasm +0 -0
- package/php/jspi/7_3_33/php_7_3.wasm +0 -0
- package/php/jspi/7_4_33/php_7_4.wasm +0 -0
- package/php/jspi/8_0_30/php_8_0.wasm +0 -0
- package/php/jspi/8_1_23/php_8_1.wasm +0 -0
- package/php/jspi/8_2_10/php_8_2.wasm +0 -0
- package/php/jspi/8_3_0/php_8_3.wasm +0 -0
- package/php/jspi/8_4_0/php_8_4.wasm +0 -0
- package/php/jspi/php_7_0.js +13 -39
- package/php/jspi/php_7_1.js +13 -39
- package/php/jspi/php_7_2.js +13 -39
- package/php/jspi/php_7_3.js +13 -39
- package/php/jspi/php_7_4.js +13 -39
- package/php/jspi/php_8_0.js +13 -39
- package/php/jspi/php_8_1.js +13 -39
- package/php/jspi/php_8_2.js +13 -39
- package/php/jspi/php_8_3.js +13 -39
- package/php/jspi/php_8_4.js +13 -39
- package/shared/icudt74l.dat +0 -0
- package/shared/icudt74l.js +2 -0
package/index.js
CHANGED
|
@@ -1,48 +1,48 @@
|
|
|
1
|
-
import { PHPResponse as
|
|
1
|
+
import { PHPResponse as Le, LatestSupportedPHPVersion as me, FSHelpers as R, loadPHPRuntime as ge, __private__dont__use as q } from "@php-wasm/universal";
|
|
2
2
|
import * as E from "comlink";
|
|
3
|
-
import { jspi as
|
|
4
|
-
import { logger as
|
|
5
|
-
import { cloneRequest as
|
|
6
|
-
import { Semaphore as
|
|
7
|
-
import { journalFSEvents as
|
|
8
|
-
function
|
|
9
|
-
|
|
10
|
-
const t =
|
|
11
|
-
return new Proxy(
|
|
12
|
-
get: (i,
|
|
3
|
+
import { jspi as Ke } from "wasm-feature-detect";
|
|
4
|
+
import { logger as v } from "@php-wasm/logger";
|
|
5
|
+
import { teeRequest as Ie, cloneRequest as De } from "@php-wasm/web-service-worker";
|
|
6
|
+
import { Semaphore as We, joinPaths as oe, basename as Re } from "@php-wasm/util";
|
|
7
|
+
import { journalFSEvents as be } from "@php-wasm/fs-journal";
|
|
8
|
+
function pt(s, e = void 0) {
|
|
9
|
+
ce();
|
|
10
|
+
const t = s instanceof Worker ? s : E.windowEndpoint(s, e), r = E.wrap(t), n = j(r);
|
|
11
|
+
return new Proxy(n, {
|
|
12
|
+
get: (i, a) => a === "isConnected" ? async () => {
|
|
13
13
|
for (; ; )
|
|
14
14
|
try {
|
|
15
|
-
await
|
|
15
|
+
await Pe(r.isConnected(), 200);
|
|
16
16
|
break;
|
|
17
17
|
} catch {
|
|
18
18
|
}
|
|
19
|
-
} : r[
|
|
19
|
+
} : r[a]
|
|
20
20
|
});
|
|
21
21
|
}
|
|
22
|
-
async function
|
|
22
|
+
async function Pe(s, e) {
|
|
23
23
|
return new Promise((t, r) => {
|
|
24
|
-
setTimeout(r, e),
|
|
24
|
+
setTimeout(r, e), s.then(t);
|
|
25
25
|
});
|
|
26
26
|
}
|
|
27
|
-
function
|
|
28
|
-
|
|
27
|
+
function wt(s, e) {
|
|
28
|
+
ce();
|
|
29
29
|
const t = Promise.resolve();
|
|
30
|
-
let r,
|
|
30
|
+
let r, n;
|
|
31
31
|
const i = new Promise((c, S) => {
|
|
32
|
-
r = c,
|
|
33
|
-
}),
|
|
32
|
+
r = c, n = S;
|
|
33
|
+
}), a = j(s), _ = new Proxy(a, {
|
|
34
34
|
get: (c, S) => S === "isConnected" ? () => t : S === "isReady" ? () => i : S in c ? c[S] : e == null ? void 0 : e[S]
|
|
35
35
|
});
|
|
36
36
|
return E.expose(
|
|
37
|
-
|
|
37
|
+
_,
|
|
38
38
|
typeof window < "u" ? E.windowEndpoint(self.parent) : void 0
|
|
39
|
-
), [r,
|
|
39
|
+
), [r, n, _];
|
|
40
40
|
}
|
|
41
|
-
let
|
|
42
|
-
function
|
|
43
|
-
if (
|
|
41
|
+
let V = !1;
|
|
42
|
+
function ce() {
|
|
43
|
+
if (V)
|
|
44
44
|
return;
|
|
45
|
-
|
|
45
|
+
V = !0, E.transferHandlers.set("EVENT", {
|
|
46
46
|
canHandle: (t) => t instanceof CustomEvent,
|
|
47
47
|
serialize: (t) => [
|
|
48
48
|
{
|
|
@@ -52,10 +52,12 @@ function ie() {
|
|
|
52
52
|
],
|
|
53
53
|
deserialize: (t) => t
|
|
54
54
|
}), E.transferHandlers.set("FUNCTION", {
|
|
55
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
|
|
55
56
|
canHandle: (t) => typeof t == "function",
|
|
57
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
|
|
56
58
|
serialize(t) {
|
|
57
|
-
const { port1: r, port2:
|
|
58
|
-
return E.expose(t, r), [
|
|
59
|
+
const { port1: r, port2: n } = new MessageChannel();
|
|
60
|
+
return E.expose(t, r), [n, [n]];
|
|
59
61
|
},
|
|
60
62
|
deserialize(t) {
|
|
61
63
|
return t.start(), E.wrap(t);
|
|
@@ -66,23 +68,23 @@ function ie() {
|
|
|
66
68
|
return [t.toRawData(), []];
|
|
67
69
|
},
|
|
68
70
|
deserialize(t) {
|
|
69
|
-
return
|
|
71
|
+
return Le.fromRawData(t);
|
|
70
72
|
}
|
|
71
73
|
});
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
+
const s = E.transferHandlers.get("throw"), e = s == null ? void 0 : s.serialize;
|
|
75
|
+
s.serialize = ({ value: t }) => {
|
|
74
76
|
const r = e({ value: t });
|
|
75
77
|
return t.response && (r[0].value.response = t.response), t.source && (r[0].value.source = t.source), r;
|
|
76
78
|
};
|
|
77
79
|
}
|
|
78
|
-
function
|
|
79
|
-
return new Proxy(
|
|
80
|
+
function j(s) {
|
|
81
|
+
return new Proxy(s, {
|
|
80
82
|
get(e, t) {
|
|
81
83
|
switch (typeof e[t]) {
|
|
82
84
|
case "function":
|
|
83
85
|
return (...r) => e[t](...r);
|
|
84
86
|
case "object":
|
|
85
|
-
return e[t] === null ? e[t] :
|
|
87
|
+
return e[t] === null ? e[t] : j(e[t]);
|
|
86
88
|
case "undefined":
|
|
87
89
|
case "number":
|
|
88
90
|
case "string":
|
|
@@ -93,9 +95,9 @@ function x(n) {
|
|
|
93
95
|
}
|
|
94
96
|
});
|
|
95
97
|
}
|
|
96
|
-
async function
|
|
97
|
-
if (await
|
|
98
|
-
switch (
|
|
98
|
+
async function Be(s = me) {
|
|
99
|
+
if (await Ke())
|
|
100
|
+
switch (s) {
|
|
99
101
|
case "8.4":
|
|
100
102
|
return await import("./php/jspi/php_8_4.js");
|
|
101
103
|
case "8.3":
|
|
@@ -112,13 +114,9 @@ async function We(n = Le) {
|
|
|
112
114
|
return await import("./php/jspi/php_7_3.js");
|
|
113
115
|
case "7.2":
|
|
114
116
|
return await import("./php/jspi/php_7_2.js");
|
|
115
|
-
case "7.1":
|
|
116
|
-
return await import("./php/jspi/php_7_1.js");
|
|
117
|
-
case "7.0":
|
|
118
|
-
return await import("./php/jspi/php_7_0.js");
|
|
119
117
|
}
|
|
120
118
|
else
|
|
121
|
-
switch (
|
|
119
|
+
switch (s) {
|
|
122
120
|
case "8.4":
|
|
123
121
|
return await import("./php/asyncify/php_8_4.js");
|
|
124
122
|
case "8.3":
|
|
@@ -135,45 +133,41 @@ async function We(n = Le) {
|
|
|
135
133
|
return await import("./php/asyncify/php_7_3.js");
|
|
136
134
|
case "7.2":
|
|
137
135
|
return await import("./php/asyncify/php_7_2.js");
|
|
138
|
-
case "7.1":
|
|
139
|
-
return await import("./php/asyncify/php_7_1.js");
|
|
140
|
-
case "7.0":
|
|
141
|
-
return await import("./php/asyncify/php_7_0.js");
|
|
142
136
|
}
|
|
143
|
-
throw new Error(`Unsupported PHP version ${
|
|
137
|
+
throw new Error(`Unsupported PHP version ${s}`);
|
|
144
138
|
}
|
|
145
|
-
function p(
|
|
146
|
-
return Object.fromEntries(Object.entries(
|
|
139
|
+
function p(s) {
|
|
140
|
+
return Object.fromEntries(Object.entries(s).map(([e, t]) => [t, e]));
|
|
147
141
|
}
|
|
148
|
-
function
|
|
142
|
+
function u(s) {
|
|
149
143
|
let e = 0;
|
|
150
|
-
|
|
144
|
+
s.forEach((n) => e += n.length);
|
|
151
145
|
const t = new Uint8Array(e);
|
|
152
146
|
let r = 0;
|
|
153
|
-
return
|
|
154
|
-
t.set(
|
|
147
|
+
return s.forEach((n) => {
|
|
148
|
+
t.set(n, r), r += n.length;
|
|
155
149
|
}), t;
|
|
156
150
|
}
|
|
157
|
-
function
|
|
158
|
-
return
|
|
151
|
+
function B(s) {
|
|
152
|
+
return u(s.map((e) => new Uint8Array(e))).buffer;
|
|
159
153
|
}
|
|
160
|
-
function I(
|
|
161
|
-
return new Uint8Array([
|
|
154
|
+
function I(s) {
|
|
155
|
+
return new Uint8Array([s >> 8 & 255, s & 255]);
|
|
162
156
|
}
|
|
163
|
-
function
|
|
157
|
+
function y(s) {
|
|
164
158
|
return new Uint8Array([
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
159
|
+
s >> 16 & 255,
|
|
160
|
+
s >> 8 & 255,
|
|
161
|
+
s & 255
|
|
168
162
|
]);
|
|
169
163
|
}
|
|
170
|
-
function
|
|
164
|
+
function Y(s) {
|
|
171
165
|
const e = new ArrayBuffer(8);
|
|
172
|
-
return new DataView(e).setBigUint64(0, BigInt(
|
|
166
|
+
return new DataView(e).setBigUint64(0, BigInt(s), !1), new Uint8Array(e);
|
|
173
167
|
}
|
|
174
|
-
class
|
|
168
|
+
class m {
|
|
175
169
|
constructor(e) {
|
|
176
|
-
this.
|
|
170
|
+
this.offset = 0, this.buffer = e, this.view = new DataView(e);
|
|
177
171
|
}
|
|
178
172
|
readUint8() {
|
|
179
173
|
const e = this.view.getUint8(this.offset);
|
|
@@ -195,7 +189,7 @@ class g {
|
|
|
195
189
|
return this.offset >= this.buffer.byteLength;
|
|
196
190
|
}
|
|
197
191
|
}
|
|
198
|
-
class
|
|
192
|
+
class M {
|
|
199
193
|
constructor(e) {
|
|
200
194
|
this.offset = 0, this.buffer = new ArrayBuffer(e), this.uint8Array = new Uint8Array(this.buffer), this.view = new DataView(this.buffer);
|
|
201
195
|
}
|
|
@@ -266,33 +260,33 @@ const b = {
|
|
|
266
260
|
key_share: 51,
|
|
267
261
|
transparency_info: 52,
|
|
268
262
|
connection_id: 54
|
|
269
|
-
},
|
|
263
|
+
}, Ue = p(b), Se = {
|
|
270
264
|
host_name: 0
|
|
271
|
-
},
|
|
272
|
-
class
|
|
265
|
+
}, ve = p(Se);
|
|
266
|
+
class Ce {
|
|
273
267
|
static decodeFromClient(e) {
|
|
274
268
|
const t = new DataView(e.buffer);
|
|
275
269
|
let r = 0;
|
|
276
|
-
const
|
|
270
|
+
const n = t.getUint16(r);
|
|
277
271
|
r += 2;
|
|
278
272
|
const i = [];
|
|
279
|
-
for (; r <
|
|
280
|
-
const
|
|
273
|
+
for (; r < n + 2; ) {
|
|
274
|
+
const a = e[r];
|
|
281
275
|
r += 1;
|
|
282
|
-
const
|
|
276
|
+
const _ = t.getUint16(r);
|
|
283
277
|
r += 2;
|
|
284
|
-
const c = e.slice(r, r +
|
|
285
|
-
switch (r +=
|
|
286
|
-
case
|
|
278
|
+
const c = e.slice(r, r + _);
|
|
279
|
+
switch (r += _, a) {
|
|
280
|
+
case Se.host_name:
|
|
287
281
|
i.push({
|
|
288
|
-
name_type:
|
|
282
|
+
name_type: ve[a],
|
|
289
283
|
name: {
|
|
290
284
|
host_name: new TextDecoder().decode(c)
|
|
291
285
|
}
|
|
292
286
|
});
|
|
293
287
|
break;
|
|
294
288
|
default:
|
|
295
|
-
throw new Error(`Unsupported name type ${
|
|
289
|
+
throw new Error(`Unsupported name type ${a}`);
|
|
296
290
|
}
|
|
297
291
|
}
|
|
298
292
|
return { server_name_list: i };
|
|
@@ -313,11 +307,11 @@ class ae {
|
|
|
313
307
|
throw new Error(
|
|
314
308
|
"Encoding non-empty lists for ClientHello is not supported yet. Only empty lists meant for ServerHello are supported today."
|
|
315
309
|
);
|
|
316
|
-
const t = new
|
|
310
|
+
const t = new M(4);
|
|
317
311
|
return t.writeUint16(b.server_name), t.writeUint16(0), t.uint8Array;
|
|
318
312
|
}
|
|
319
313
|
}
|
|
320
|
-
const
|
|
314
|
+
const he = {
|
|
321
315
|
TLS1_CK_PSK_WITH_RC4_128_SHA: 138,
|
|
322
316
|
TLS1_CK_PSK_WITH_3DES_EDE_CBC_SHA: 139,
|
|
323
317
|
TLS1_CK_PSK_WITH_AES_128_CBC_SHA: 140,
|
|
@@ -520,14 +514,14 @@ const oe = {
|
|
|
520
514
|
TLS1_CK_ECDHE_PSK_WITH_CHACHA20_POLY1305: 52396,
|
|
521
515
|
TLS1_CK_DHE_PSK_WITH_CHACHA20_POLY1305: 52397,
|
|
522
516
|
TLS1_CK_RSA_PSK_WITH_CHACHA20_POLY1305: 52398
|
|
523
|
-
},
|
|
517
|
+
}, Z = p(he), le = {
|
|
524
518
|
secp256r1: 23,
|
|
525
519
|
secp384r1: 24,
|
|
526
520
|
secp521r1: 25,
|
|
527
521
|
x25519: 29,
|
|
528
522
|
x448: 30
|
|
529
|
-
},
|
|
530
|
-
class
|
|
523
|
+
}, J = p(le);
|
|
524
|
+
class Me {
|
|
531
525
|
/**
|
|
532
526
|
* +--------------------------------------------------+
|
|
533
527
|
* | Payload Length [2B] |
|
|
@@ -544,12 +538,12 @@ class Se {
|
|
|
544
538
|
* +--------------------------------------------------+
|
|
545
539
|
*/
|
|
546
540
|
static decodeFromClient(e) {
|
|
547
|
-
const t = new
|
|
541
|
+
const t = new m(e.buffer);
|
|
548
542
|
t.readUint16();
|
|
549
543
|
const r = [];
|
|
550
544
|
for (; !t.isFinished(); ) {
|
|
551
|
-
const
|
|
552
|
-
|
|
545
|
+
const n = t.readUint16();
|
|
546
|
+
n in J && r.push(J[n]);
|
|
553
547
|
}
|
|
554
548
|
return r;
|
|
555
549
|
}
|
|
@@ -564,16 +558,16 @@ class Se {
|
|
|
564
558
|
* +--------------------------------------------------+
|
|
565
559
|
*/
|
|
566
560
|
static encodeForClient(e) {
|
|
567
|
-
const t = new
|
|
568
|
-
return t.writeUint16(b.supported_groups), t.writeUint16(2), t.writeUint16(
|
|
561
|
+
const t = new M(6);
|
|
562
|
+
return t.writeUint16(b.supported_groups), t.writeUint16(2), t.writeUint16(le[e]), t.uint8Array;
|
|
569
563
|
}
|
|
570
564
|
}
|
|
571
|
-
const
|
|
565
|
+
const Ae = {
|
|
572
566
|
uncompressed: 0,
|
|
573
567
|
ansiX962_compressed_prime: 1,
|
|
574
568
|
ansiX962_compressed_char2: 2
|
|
575
|
-
},
|
|
576
|
-
class
|
|
569
|
+
}, X = p(Ae);
|
|
570
|
+
class Ne {
|
|
577
571
|
/**
|
|
578
572
|
* +--------------------------------------------------+
|
|
579
573
|
* | Payload Length [2B] |
|
|
@@ -590,12 +584,12 @@ class le {
|
|
|
590
584
|
* +--------------------------------------------------+
|
|
591
585
|
*/
|
|
592
586
|
static decodeFromClient(e) {
|
|
593
|
-
const t = new
|
|
587
|
+
const t = new m(e.buffer), r = t.readUint8(), n = [];
|
|
594
588
|
for (let i = 0; i < r; i++) {
|
|
595
|
-
const
|
|
596
|
-
|
|
589
|
+
const a = t.readUint8();
|
|
590
|
+
a in X && n.push(X[a]);
|
|
597
591
|
}
|
|
598
|
-
return
|
|
592
|
+
return n;
|
|
599
593
|
}
|
|
600
594
|
/**
|
|
601
595
|
* Encode the ec_point_formats extension
|
|
@@ -612,16 +606,16 @@ class le {
|
|
|
612
606
|
* +--------------------------------------------------+
|
|
613
607
|
*/
|
|
614
608
|
static encodeForClient(e) {
|
|
615
|
-
const t = new
|
|
616
|
-
return t.writeUint16(b.ec_point_formats), t.writeUint16(2), t.writeUint8(1), t.writeUint8(
|
|
609
|
+
const t = new M(6);
|
|
610
|
+
return t.writeUint16(b.ec_point_formats), t.writeUint16(2), t.writeUint8(1), t.writeUint8(Ae[e]), t.uint8Array;
|
|
617
611
|
}
|
|
618
612
|
}
|
|
619
|
-
const
|
|
613
|
+
const G = {
|
|
620
614
|
anonymous: 0,
|
|
621
615
|
rsa: 1,
|
|
622
616
|
dsa: 2,
|
|
623
617
|
ecdsa: 3
|
|
624
|
-
},
|
|
618
|
+
}, Q = p(G), $ = {
|
|
625
619
|
none: 0,
|
|
626
620
|
md5: 1,
|
|
627
621
|
sha1: 2,
|
|
@@ -629,8 +623,8 @@ const N = {
|
|
|
629
623
|
sha256: 4,
|
|
630
624
|
sha384: 5,
|
|
631
625
|
sha512: 6
|
|
632
|
-
},
|
|
633
|
-
class
|
|
626
|
+
}, ee = p($);
|
|
627
|
+
class xe {
|
|
634
628
|
/**
|
|
635
629
|
* Binary layout:
|
|
636
630
|
*
|
|
@@ -647,23 +641,21 @@ class Ae {
|
|
|
647
641
|
* +------------------------------------+
|
|
648
642
|
*/
|
|
649
643
|
static decodeFromClient(e) {
|
|
650
|
-
const t = new
|
|
644
|
+
const t = new m(e.buffer);
|
|
651
645
|
t.readUint16();
|
|
652
646
|
const r = [];
|
|
653
647
|
for (; !t.isFinished(); ) {
|
|
654
|
-
const
|
|
655
|
-
if (
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
648
|
+
const n = t.readUint8(), i = t.readUint8();
|
|
649
|
+
if (Q[i]) {
|
|
650
|
+
if (!ee[n]) {
|
|
651
|
+
v.warn(`Unknown hash algorithm: ${n}`);
|
|
652
|
+
continue;
|
|
653
|
+
}
|
|
654
|
+
r.push({
|
|
655
|
+
algorithm: Q[i],
|
|
656
|
+
hash: ee[n]
|
|
657
|
+
});
|
|
662
658
|
}
|
|
663
|
-
r.push({
|
|
664
|
-
algorithm: z[i],
|
|
665
|
-
hash: Y[s]
|
|
666
|
-
});
|
|
667
659
|
}
|
|
668
660
|
return r;
|
|
669
661
|
}
|
|
@@ -679,60 +671,61 @@ class Ae {
|
|
|
679
671
|
* +--------------------------------------------------+
|
|
680
672
|
*/
|
|
681
673
|
static encodeforClient(e, t) {
|
|
682
|
-
const r = new
|
|
683
|
-
return r.writeUint16(b.signature_algorithms), r.writeUint16(2), r.writeUint8(
|
|
674
|
+
const r = new M(6);
|
|
675
|
+
return r.writeUint16(b.signature_algorithms), r.writeUint16(2), r.writeUint8($[e]), r.writeUint8(G[t]), r.uint8Array;
|
|
684
676
|
}
|
|
685
677
|
}
|
|
686
|
-
const
|
|
687
|
-
server_name:
|
|
688
|
-
signature_algorithms:
|
|
689
|
-
supported_groups:
|
|
690
|
-
ec_point_formats:
|
|
678
|
+
const te = {
|
|
679
|
+
server_name: Ce,
|
|
680
|
+
signature_algorithms: xe,
|
|
681
|
+
supported_groups: Me,
|
|
682
|
+
ec_point_formats: Ne
|
|
691
683
|
};
|
|
692
|
-
function
|
|
693
|
-
const e = new
|
|
684
|
+
function ke(s) {
|
|
685
|
+
const e = new m(s.buffer), t = [];
|
|
694
686
|
for (; !e.isFinished(); ) {
|
|
695
|
-
const r = e.offset,
|
|
696
|
-
if (!(i in
|
|
687
|
+
const r = e.offset, n = e.readUint16(), i = Ue[n], a = e.readUint16(), _ = e.readUint8Array(a);
|
|
688
|
+
if (!(i in te))
|
|
697
689
|
continue;
|
|
698
|
-
const c =
|
|
690
|
+
const c = te[i];
|
|
699
691
|
t.push({
|
|
700
692
|
type: i,
|
|
701
|
-
data: c.decodeFromClient(
|
|
702
|
-
raw:
|
|
693
|
+
data: c.decodeFromClient(_),
|
|
694
|
+
raw: s.slice(r, r + 4 + a)
|
|
703
695
|
});
|
|
704
696
|
}
|
|
705
697
|
return t;
|
|
706
698
|
}
|
|
707
|
-
async function
|
|
708
|
-
const
|
|
699
|
+
async function O(s, e, t, r) {
|
|
700
|
+
const n = B([e, t]), i = await crypto.subtle.importKey(
|
|
709
701
|
"raw",
|
|
710
|
-
|
|
702
|
+
s,
|
|
711
703
|
{ name: "HMAC", hash: { name: "SHA-256" } },
|
|
712
704
|
!1,
|
|
713
705
|
["sign"]
|
|
714
706
|
);
|
|
715
|
-
let
|
|
716
|
-
const
|
|
717
|
-
for (;
|
|
718
|
-
|
|
719
|
-
const S =
|
|
720
|
-
|
|
721
|
-
}
|
|
722
|
-
return
|
|
707
|
+
let a = n;
|
|
708
|
+
const _ = [];
|
|
709
|
+
for (; B(_).byteLength < r; ) {
|
|
710
|
+
a = await re(i, a);
|
|
711
|
+
const S = B([a, n]), h = await re(i, S);
|
|
712
|
+
_.push(h);
|
|
713
|
+
}
|
|
714
|
+
return B(_).slice(0, r);
|
|
723
715
|
}
|
|
724
|
-
async function
|
|
716
|
+
async function re(s, e) {
|
|
725
717
|
return await crypto.subtle.sign(
|
|
726
718
|
{ name: "HMAC", hash: "SHA-256" },
|
|
727
|
-
|
|
719
|
+
s,
|
|
728
720
|
e
|
|
729
721
|
);
|
|
730
722
|
}
|
|
731
|
-
|
|
732
|
-
|
|
723
|
+
const qe = {
|
|
724
|
+
Null: 0
|
|
725
|
+
}, Oe = {
|
|
733
726
|
Warning: 1,
|
|
734
727
|
Fatal: 2
|
|
735
|
-
},
|
|
728
|
+
}, ue = p(Oe), Fe = {
|
|
736
729
|
CloseNotify: 0,
|
|
737
730
|
UnexpectedMessage: 10,
|
|
738
731
|
BadRecordMac: 20,
|
|
@@ -758,26 +751,21 @@ const Be = {
|
|
|
758
751
|
UserCanceled: 90,
|
|
759
752
|
NoRenegotiation: 100,
|
|
760
753
|
UnsupportedExtension: 110
|
|
761
|
-
}, He = p(
|
|
754
|
+
}, He = p(Fe), C = {
|
|
762
755
|
ChangeCipherSpec: 20,
|
|
763
756
|
Alert: 21,
|
|
764
757
|
Handshake: 22,
|
|
765
758
|
ApplicationData: 23
|
|
766
|
-
}
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
* Indicates the elliptic curve domain parameters are
|
|
777
|
-
* conveyed verbosely, and the underlying finite field is a
|
|
778
|
-
* characteristic-2 field.
|
|
779
|
-
*/
|
|
780
|
-
ExplicitChar2: 2,
|
|
759
|
+
}, d = {
|
|
760
|
+
HelloRequest: 0,
|
|
761
|
+
ClientHello: 1,
|
|
762
|
+
ServerHello: 2,
|
|
763
|
+
Certificate: 11,
|
|
764
|
+
ServerKeyExchange: 12,
|
|
765
|
+
ServerHelloDone: 14,
|
|
766
|
+
ClientKeyExchange: 16,
|
|
767
|
+
Finished: 20
|
|
768
|
+
}, je = {
|
|
781
769
|
/**
|
|
782
770
|
* Indicates that a named curve is used. This option
|
|
783
771
|
* SHOULD be used when applicable.
|
|
@@ -786,29 +774,12 @@ const ve = {
|
|
|
786
774
|
/**
|
|
787
775
|
* Values 248 through 255 are reserved for private use.
|
|
788
776
|
*/
|
|
789
|
-
},
|
|
790
|
-
|
|
791
|
-
sect163r1: 2,
|
|
792
|
-
sect163r2: 3,
|
|
793
|
-
sect193r1: 4,
|
|
794
|
-
sect193r2: 5,
|
|
795
|
-
sect233k1: 6,
|
|
796
|
-
sect233r1: 7,
|
|
797
|
-
sect239k1: 8,
|
|
798
|
-
sect283k1: 9,
|
|
799
|
-
sect283r1: 10,
|
|
800
|
-
sect409k1: 11,
|
|
801
|
-
sect409r1: 12,
|
|
802
|
-
secp256k1: 22,
|
|
803
|
-
secp256r1: 23,
|
|
804
|
-
secp384r1: 24,
|
|
805
|
-
secp521r1: 25,
|
|
806
|
-
arbitrary_explicit_prime_curves: 65281,
|
|
807
|
-
arbitrary_explicit_char2_curves: 65282
|
|
777
|
+
}, Ge = {
|
|
778
|
+
secp256r1: 23
|
|
808
779
|
};
|
|
809
|
-
class
|
|
780
|
+
class ne extends Error {
|
|
810
781
|
}
|
|
811
|
-
const U = new Uint8Array([3, 3]),
|
|
782
|
+
const U = new Uint8Array([3, 3]), $e = crypto.subtle.generateKey(
|
|
812
783
|
{
|
|
813
784
|
name: "ECDH",
|
|
814
785
|
namedCurve: "P-256"
|
|
@@ -819,7 +790,7 @@ const U = new Uint8Array([3, 3]), xe = crypto.subtle.generateKey(
|
|
|
819
790
|
["deriveKey", "deriveBits"]
|
|
820
791
|
// Key usage
|
|
821
792
|
);
|
|
822
|
-
class
|
|
793
|
+
class ze {
|
|
823
794
|
constructor() {
|
|
824
795
|
this.receivedRecordSequenceNumber = 0, this.sentRecordSequenceNumber = 0, this.closed = !1, this.receivedBytesBuffer = new Uint8Array(), this.receivedTLSRecords = [], this.partialTLSMessages = {}, this.handshakeMessages = [], this.MAX_CHUNK_SIZE = 1024 * 16, this.clientEnd = {
|
|
825
796
|
// We don't need to chunk the encrypted data.
|
|
@@ -836,7 +807,7 @@ class Ne {
|
|
|
836
807
|
* This will spread some messages across multiple records,
|
|
837
808
|
* but TLS supports it so that's fine.
|
|
838
809
|
*/
|
|
839
|
-
downstream:
|
|
810
|
+
downstream: Ve(this.MAX_CHUNK_SIZE)
|
|
840
811
|
}, this.serverUpstreamWriter = this.serverEnd.upstream.writable.getWriter();
|
|
841
812
|
const e = this;
|
|
842
813
|
this.serverEnd.downstream.readable.pipeTo(
|
|
@@ -899,25 +870,25 @@ class Ne {
|
|
|
899
870
|
throw new Error(
|
|
900
871
|
"Client did not propose any supported cipher suites."
|
|
901
872
|
);
|
|
902
|
-
const
|
|
873
|
+
const n = crypto.getRandomValues(new Uint8Array(32));
|
|
903
874
|
await this.writeTLSRecord(
|
|
904
875
|
C.Handshake,
|
|
905
876
|
K.serverHello(
|
|
906
877
|
r.body,
|
|
907
|
-
|
|
908
|
-
|
|
878
|
+
n,
|
|
879
|
+
qe.Null
|
|
909
880
|
)
|
|
910
881
|
), await this.writeTLSRecord(
|
|
911
882
|
C.Handshake,
|
|
912
883
|
K.certificate(t)
|
|
913
884
|
);
|
|
914
|
-
const i = await
|
|
915
|
-
|
|
916
|
-
|
|
885
|
+
const i = await $e, a = r.body.random, _ = await K.ECDHEServerKeyExchange(
|
|
886
|
+
a,
|
|
887
|
+
n,
|
|
917
888
|
i,
|
|
918
889
|
e
|
|
919
890
|
);
|
|
920
|
-
await this.writeTLSRecord(C.Handshake,
|
|
891
|
+
await this.writeTLSRecord(C.Handshake, _), await this.writeTLSRecord(
|
|
921
892
|
C.Handshake,
|
|
922
893
|
K.serverHelloDone()
|
|
923
894
|
);
|
|
@@ -925,8 +896,8 @@ class Ne {
|
|
|
925
896
|
d.ClientKeyExchange
|
|
926
897
|
);
|
|
927
898
|
await this.readNextMessage(C.ChangeCipherSpec), this.sessionKeys = await this.deriveSessionKeys({
|
|
928
|
-
clientRandom:
|
|
929
|
-
serverRandom:
|
|
899
|
+
clientRandom: a,
|
|
900
|
+
serverRandom: n,
|
|
930
901
|
serverPrivateKey: i.privateKey,
|
|
931
902
|
clientPublicKey: await crypto.subtle.importKey(
|
|
932
903
|
"raw",
|
|
@@ -954,32 +925,32 @@ class Ne {
|
|
|
954
925
|
clientRandom: e,
|
|
955
926
|
serverRandom: t,
|
|
956
927
|
serverPrivateKey: r,
|
|
957
|
-
clientPublicKey:
|
|
928
|
+
clientPublicKey: n
|
|
958
929
|
}) {
|
|
959
930
|
const i = await crypto.subtle.deriveBits(
|
|
960
931
|
{
|
|
961
932
|
name: "ECDH",
|
|
962
|
-
public:
|
|
933
|
+
public: n
|
|
963
934
|
},
|
|
964
935
|
r,
|
|
965
936
|
256
|
|
966
937
|
// Length of the derived secret (256 bits for P-256)
|
|
967
|
-
),
|
|
968
|
-
await
|
|
938
|
+
), a = new Uint8Array(
|
|
939
|
+
await O(
|
|
969
940
|
i,
|
|
970
941
|
new TextEncoder().encode("master secret"),
|
|
971
|
-
|
|
942
|
+
u([e, t]),
|
|
972
943
|
48
|
|
973
944
|
)
|
|
974
|
-
),
|
|
975
|
-
|
|
945
|
+
), _ = await O(
|
|
946
|
+
a,
|
|
976
947
|
new TextEncoder().encode("key expansion"),
|
|
977
|
-
|
|
948
|
+
u([t, e]),
|
|
978
949
|
// Client key, server key, client IV, server IV
|
|
979
|
-
|
|
980
|
-
), c = new
|
|
950
|
+
40
|
|
951
|
+
), c = new m(_), S = c.readUint8Array(16), h = c.readUint8Array(16), l = c.readUint8Array(4), A = c.readUint8Array(4);
|
|
981
952
|
return {
|
|
982
|
-
masterSecret:
|
|
953
|
+
masterSecret: a,
|
|
983
954
|
clientWriteKey: await crypto.subtle.importKey(
|
|
984
955
|
"raw",
|
|
985
956
|
S,
|
|
@@ -989,13 +960,13 @@ class Ne {
|
|
|
989
960
|
),
|
|
990
961
|
serverWriteKey: await crypto.subtle.importKey(
|
|
991
962
|
"raw",
|
|
992
|
-
|
|
963
|
+
h,
|
|
993
964
|
{ name: "AES-GCM" },
|
|
994
965
|
!1,
|
|
995
966
|
["encrypt", "decrypt"]
|
|
996
967
|
),
|
|
997
|
-
clientIV:
|
|
998
|
-
serverIV:
|
|
968
|
+
clientIV: l,
|
|
969
|
+
serverIV: A
|
|
999
970
|
};
|
|
1000
971
|
}
|
|
1001
972
|
async readNextHandshakeMessage(e) {
|
|
@@ -1011,35 +982,35 @@ class Ne {
|
|
|
1011
982
|
t
|
|
1012
983
|
);
|
|
1013
984
|
while (r === !1);
|
|
1014
|
-
const
|
|
985
|
+
const n = T.TLSMessage(
|
|
1015
986
|
t.type,
|
|
1016
987
|
r
|
|
1017
988
|
);
|
|
1018
|
-
return t.type === C.Handshake && this.handshakeMessages.push(t.fragment),
|
|
989
|
+
return t.type === C.Handshake && this.handshakeMessages.push(t.fragment), n;
|
|
1019
990
|
}
|
|
1020
991
|
async readNextTLSRecord(e) {
|
|
1021
992
|
for (; ; ) {
|
|
1022
|
-
for (let
|
|
1023
|
-
const c = this.receivedTLSRecords[
|
|
993
|
+
for (let _ = 0; _ < this.receivedTLSRecords.length; _++) {
|
|
994
|
+
const c = this.receivedTLSRecords[_];
|
|
1024
995
|
if (c.type === e)
|
|
1025
|
-
return this.receivedTLSRecords.splice(
|
|
996
|
+
return this.receivedTLSRecords.splice(_, 1), c;
|
|
1026
997
|
}
|
|
1027
|
-
const t = await this.pollBytes(5), r = t[3] << 8 | t[4],
|
|
1028
|
-
type:
|
|
998
|
+
const t = await this.pollBytes(5), r = t[3] << 8 | t[4], n = t[0], i = await this.pollBytes(r), a = {
|
|
999
|
+
type: n,
|
|
1029
1000
|
version: {
|
|
1030
1001
|
major: t[1],
|
|
1031
1002
|
minor: t[2]
|
|
1032
1003
|
},
|
|
1033
1004
|
length: r,
|
|
1034
|
-
fragment: this.sessionKeys &&
|
|
1005
|
+
fragment: this.sessionKeys && n !== C.ChangeCipherSpec ? await this.decryptData(n, i) : i
|
|
1035
1006
|
};
|
|
1036
|
-
if (
|
|
1037
|
-
const
|
|
1007
|
+
if (a.type === C.Alert) {
|
|
1008
|
+
const _ = ue[a.fragment[0]], c = He[a.fragment[1]];
|
|
1038
1009
|
throw new Error(
|
|
1039
|
-
`TLS non-warning alert received: ${
|
|
1010
|
+
`TLS non-warning alert received: ${_} ${c}`
|
|
1040
1011
|
);
|
|
1041
1012
|
}
|
|
1042
|
-
this.receivedTLSRecords.push(
|
|
1013
|
+
this.receivedTLSRecords.push(a);
|
|
1043
1014
|
}
|
|
1044
1015
|
}
|
|
1045
1016
|
/**
|
|
@@ -1048,10 +1019,10 @@ class Ne {
|
|
|
1048
1019
|
*/
|
|
1049
1020
|
async pollBytes(e) {
|
|
1050
1021
|
for (; this.receivedBytesBuffer.length < e; ) {
|
|
1051
|
-
const { value: r, done:
|
|
1052
|
-
if (
|
|
1053
|
-
throw await this.close(), new
|
|
1054
|
-
if (this.receivedBytesBuffer =
|
|
1022
|
+
const { value: r, done: n } = await this.clientUpstreamReader.read();
|
|
1023
|
+
if (n)
|
|
1024
|
+
throw await this.close(), new ne("TLS connection closed");
|
|
1025
|
+
if (this.receivedBytesBuffer = u([
|
|
1055
1026
|
this.receivedBytesBuffer,
|
|
1056
1027
|
r
|
|
1057
1028
|
]), this.receivedBytesBuffer.length >= e)
|
|
@@ -1074,7 +1045,7 @@ class Ne {
|
|
|
1074
1045
|
this.serverUpstreamWriter.write(e.body);
|
|
1075
1046
|
}
|
|
1076
1047
|
} catch (e) {
|
|
1077
|
-
if (e instanceof
|
|
1048
|
+
if (e instanceof ne)
|
|
1078
1049
|
return;
|
|
1079
1050
|
throw e;
|
|
1080
1051
|
}
|
|
@@ -1084,12 +1055,12 @@ class Ne {
|
|
|
1084
1055
|
* the AES-GCM algorithm.
|
|
1085
1056
|
*/
|
|
1086
1057
|
async decryptData(e, t) {
|
|
1087
|
-
const r = this.sessionKeys.clientIV,
|
|
1058
|
+
const r = this.sessionKeys.clientIV, n = t.slice(0, 8), i = new Uint8Array([...r, ...n]), a = await crypto.subtle.decrypt(
|
|
1088
1059
|
{
|
|
1089
1060
|
name: "AES-GCM",
|
|
1090
1061
|
iv: i,
|
|
1091
1062
|
additionalData: new Uint8Array([
|
|
1092
|
-
...
|
|
1063
|
+
...Y(this.receivedRecordSequenceNumber),
|
|
1093
1064
|
e,
|
|
1094
1065
|
...U,
|
|
1095
1066
|
// Payload length without IV and tag
|
|
@@ -1101,10 +1072,10 @@ class Ne {
|
|
|
1101
1072
|
// Payload without the explicit IV
|
|
1102
1073
|
t.slice(8)
|
|
1103
1074
|
);
|
|
1104
|
-
return ++this.receivedRecordSequenceNumber, new Uint8Array(
|
|
1075
|
+
return ++this.receivedRecordSequenceNumber, new Uint8Array(a);
|
|
1105
1076
|
}
|
|
1106
1077
|
async accumulateUntilMessageIsComplete(e) {
|
|
1107
|
-
this.partialTLSMessages[e.type] =
|
|
1078
|
+
this.partialTLSMessages[e.type] = u([
|
|
1108
1079
|
this.partialTLSMessages[e.type] || new Uint8Array(),
|
|
1109
1080
|
e.fragment
|
|
1110
1081
|
]);
|
|
@@ -1140,49 +1111,49 @@ class Ne {
|
|
|
1140
1111
|
*/
|
|
1141
1112
|
async writeTLSRecord(e, t) {
|
|
1142
1113
|
e === C.Handshake && this.handshakeMessages.push(t), this.sessionKeys && e !== C.ChangeCipherSpec && (t = await this.encryptData(e, t));
|
|
1143
|
-
const r = U,
|
|
1144
|
-
i[0] = e, i[1] = r[0], i[2] = r[1], i[3] =
|
|
1145
|
-
const
|
|
1146
|
-
this.clientDownstreamWriter.write(
|
|
1114
|
+
const r = U, n = t.length, i = new Uint8Array(5);
|
|
1115
|
+
i[0] = e, i[1] = r[0], i[2] = r[1], i[3] = n >> 8 & 255, i[4] = n & 255;
|
|
1116
|
+
const a = u([i, t]);
|
|
1117
|
+
this.clientDownstreamWriter.write(a);
|
|
1147
1118
|
}
|
|
1148
1119
|
/**
|
|
1149
1120
|
* Encrypts data in a TLS 1.2-compliant manner using
|
|
1150
1121
|
* the AES-GCM algorithm.
|
|
1151
1122
|
*/
|
|
1152
1123
|
async encryptData(e, t) {
|
|
1153
|
-
const r = this.sessionKeys.serverIV,
|
|
1154
|
-
...
|
|
1124
|
+
const r = this.sessionKeys.serverIV, n = crypto.getRandomValues(new Uint8Array(8)), i = new Uint8Array([...r, ...n]), a = new Uint8Array([
|
|
1125
|
+
...Y(this.sentRecordSequenceNumber),
|
|
1155
1126
|
e,
|
|
1156
1127
|
...U,
|
|
1157
1128
|
// Payload length without IV and tag
|
|
1158
1129
|
...I(t.length)
|
|
1159
|
-
]),
|
|
1130
|
+
]), _ = await crypto.subtle.encrypt(
|
|
1160
1131
|
{
|
|
1161
1132
|
name: "AES-GCM",
|
|
1162
1133
|
iv: i,
|
|
1163
|
-
additionalData:
|
|
1134
|
+
additionalData: a,
|
|
1164
1135
|
tagLength: 128
|
|
1165
1136
|
},
|
|
1166
1137
|
this.sessionKeys.serverWriteKey,
|
|
1167
1138
|
t
|
|
1168
1139
|
);
|
|
1169
|
-
return ++this.sentRecordSequenceNumber,
|
|
1170
|
-
|
|
1171
|
-
new Uint8Array(
|
|
1140
|
+
return ++this.sentRecordSequenceNumber, u([
|
|
1141
|
+
n,
|
|
1142
|
+
new Uint8Array(_)
|
|
1172
1143
|
]);
|
|
1173
1144
|
}
|
|
1174
1145
|
}
|
|
1175
|
-
class
|
|
1146
|
+
class T {
|
|
1176
1147
|
static TLSMessage(e, t) {
|
|
1177
1148
|
switch (e) {
|
|
1178
1149
|
case C.Handshake:
|
|
1179
|
-
return
|
|
1150
|
+
return T.clientHandshake(t);
|
|
1180
1151
|
case C.Alert:
|
|
1181
|
-
return
|
|
1152
|
+
return T.alert(t);
|
|
1182
1153
|
case C.ChangeCipherSpec:
|
|
1183
|
-
return
|
|
1154
|
+
return T.changeCipherSpec();
|
|
1184
1155
|
case C.ApplicationData:
|
|
1185
|
-
return
|
|
1156
|
+
return T.applicationData(t);
|
|
1186
1157
|
default:
|
|
1187
1158
|
throw new Error(`TLS: Unsupported TLS record type ${e}`);
|
|
1188
1159
|
}
|
|
@@ -1211,12 +1182,12 @@ class f {
|
|
|
1211
1182
|
* https://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml#tls-parameters-4
|
|
1212
1183
|
*/
|
|
1213
1184
|
static parseCipherSuites(e) {
|
|
1214
|
-
const t = new
|
|
1185
|
+
const t = new m(e);
|
|
1215
1186
|
t.readUint16();
|
|
1216
1187
|
const r = [];
|
|
1217
1188
|
for (; !t.isFinished(); ) {
|
|
1218
|
-
const
|
|
1219
|
-
|
|
1189
|
+
const n = t.readUint16();
|
|
1190
|
+
n in Z && r.push(Z[n]);
|
|
1220
1191
|
}
|
|
1221
1192
|
return r;
|
|
1222
1193
|
}
|
|
@@ -1235,25 +1206,25 @@ class f {
|
|
|
1235
1206
|
static alert(e) {
|
|
1236
1207
|
return {
|
|
1237
1208
|
type: C.Alert,
|
|
1238
|
-
level:
|
|
1209
|
+
level: ue[e[0]],
|
|
1239
1210
|
description: He[e[1]]
|
|
1240
1211
|
};
|
|
1241
1212
|
}
|
|
1242
1213
|
static clientHandshake(e) {
|
|
1243
|
-
const t = e[0], r = e[1] << 16 | e[2] << 8 | e[3],
|
|
1214
|
+
const t = e[0], r = e[1] << 16 | e[2] << 8 | e[3], n = e.slice(4);
|
|
1244
1215
|
let i;
|
|
1245
1216
|
switch (t) {
|
|
1246
1217
|
case d.HelloRequest:
|
|
1247
|
-
i =
|
|
1218
|
+
i = T.clientHelloRequestPayload();
|
|
1248
1219
|
break;
|
|
1249
1220
|
case d.ClientHello:
|
|
1250
|
-
i =
|
|
1221
|
+
i = T.clientHelloPayload(n);
|
|
1251
1222
|
break;
|
|
1252
1223
|
case d.ClientKeyExchange:
|
|
1253
|
-
i =
|
|
1224
|
+
i = T.clientKeyExchangePayload(n);
|
|
1254
1225
|
break;
|
|
1255
1226
|
case d.Finished:
|
|
1256
|
-
i =
|
|
1227
|
+
i = T.clientFinishedPayload(n);
|
|
1257
1228
|
break;
|
|
1258
1229
|
default:
|
|
1259
1230
|
throw new Error(`Invalid handshake type ${t}`);
|
|
@@ -1309,7 +1280,7 @@ class f {
|
|
|
1309
1280
|
* +------+------+---------------------------+
|
|
1310
1281
|
*/
|
|
1311
1282
|
static clientHelloPayload(e) {
|
|
1312
|
-
const t = new
|
|
1283
|
+
const t = new m(e.buffer), r = {
|
|
1313
1284
|
client_version: t.readUint8Array(2),
|
|
1314
1285
|
/**
|
|
1315
1286
|
* Technically this consists of a GMT timestamp
|
|
@@ -1317,19 +1288,19 @@ class f {
|
|
|
1317
1288
|
* parse this further.
|
|
1318
1289
|
*/
|
|
1319
1290
|
random: t.readUint8Array(32)
|
|
1320
|
-
},
|
|
1321
|
-
r.session_id = t.readUint8Array(
|
|
1291
|
+
}, n = t.readUint8();
|
|
1292
|
+
r.session_id = t.readUint8Array(n);
|
|
1322
1293
|
const i = t.readUint16();
|
|
1323
|
-
r.cipher_suites =
|
|
1294
|
+
r.cipher_suites = T.parseCipherSuites(
|
|
1324
1295
|
t.readUint8Array(i).buffer
|
|
1325
1296
|
);
|
|
1326
|
-
const
|
|
1297
|
+
const a = t.readUint8();
|
|
1327
1298
|
r.compression_methods = t.readUint8Array(
|
|
1328
|
-
|
|
1299
|
+
a
|
|
1329
1300
|
);
|
|
1330
|
-
const
|
|
1331
|
-
return r.extensions =
|
|
1332
|
-
t.readUint8Array(
|
|
1301
|
+
const _ = t.readUint16();
|
|
1302
|
+
return r.extensions = ke(
|
|
1303
|
+
t.readUint8Array(_)
|
|
1333
1304
|
), r;
|
|
1334
1305
|
}
|
|
1335
1306
|
/**
|
|
@@ -1353,11 +1324,11 @@ class f {
|
|
|
1353
1324
|
};
|
|
1354
1325
|
}
|
|
1355
1326
|
}
|
|
1356
|
-
function
|
|
1327
|
+
function Ve(s) {
|
|
1357
1328
|
return new TransformStream({
|
|
1358
1329
|
transform(e, t) {
|
|
1359
1330
|
for (; e.length > 0; )
|
|
1360
|
-
t.enqueue(e.slice(0,
|
|
1331
|
+
t.enqueue(e.slice(0, s)), e = e.slice(s);
|
|
1361
1332
|
}
|
|
1362
1333
|
});
|
|
1363
1334
|
}
|
|
@@ -1365,15 +1336,15 @@ class K {
|
|
|
1365
1336
|
static certificate(e) {
|
|
1366
1337
|
const t = [];
|
|
1367
1338
|
for (const i of e)
|
|
1368
|
-
t.push(
|
|
1369
|
-
const r =
|
|
1370
|
-
...
|
|
1339
|
+
t.push(y(i.byteLength)), t.push(new Uint8Array(i));
|
|
1340
|
+
const r = u(t), n = new Uint8Array([
|
|
1341
|
+
...y(r.byteLength),
|
|
1371
1342
|
...r
|
|
1372
1343
|
]);
|
|
1373
1344
|
return new Uint8Array([
|
|
1374
1345
|
d.Certificate,
|
|
1375
|
-
...
|
|
1376
|
-
...
|
|
1346
|
+
...y(n.length),
|
|
1347
|
+
...n
|
|
1377
1348
|
]);
|
|
1378
1349
|
}
|
|
1379
1350
|
/*
|
|
@@ -1409,38 +1380,38 @@ class K {
|
|
|
1409
1380
|
* @param rsaPrivateKey - RSA private key for signing
|
|
1410
1381
|
* @returns
|
|
1411
1382
|
*/
|
|
1412
|
-
static async ECDHEServerKeyExchange(e, t, r,
|
|
1383
|
+
static async ECDHEServerKeyExchange(e, t, r, n) {
|
|
1413
1384
|
const i = new Uint8Array(
|
|
1414
1385
|
await crypto.subtle.exportKey("raw", r.publicKey)
|
|
1415
|
-
),
|
|
1386
|
+
), a = new Uint8Array([
|
|
1416
1387
|
// Curve type (1 byte)
|
|
1417
|
-
|
|
1388
|
+
je.NamedCurve,
|
|
1418
1389
|
// Curve name (2 bytes)
|
|
1419
|
-
...I(
|
|
1390
|
+
...I(Ge.secp256r1),
|
|
1420
1391
|
// Public key length (1 byte)
|
|
1421
1392
|
i.byteLength,
|
|
1422
1393
|
// Public key (65 bytes, uncompressed format)
|
|
1423
1394
|
...i
|
|
1424
|
-
]),
|
|
1395
|
+
]), _ = await crypto.subtle.sign(
|
|
1425
1396
|
{
|
|
1426
1397
|
name: "RSASSA-PKCS1-v1_5",
|
|
1427
1398
|
hash: "SHA-256"
|
|
1428
1399
|
},
|
|
1429
|
-
|
|
1430
|
-
new Uint8Array([...e, ...t, ...
|
|
1431
|
-
), c = new Uint8Array(
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
]),
|
|
1435
|
-
...
|
|
1400
|
+
n,
|
|
1401
|
+
new Uint8Array([...e, ...t, ...a])
|
|
1402
|
+
), c = new Uint8Array(_), S = new Uint8Array([
|
|
1403
|
+
$.sha256,
|
|
1404
|
+
G.rsa
|
|
1405
|
+
]), h = new Uint8Array([
|
|
1406
|
+
...a,
|
|
1436
1407
|
...S,
|
|
1437
1408
|
...I(c.length),
|
|
1438
1409
|
...c
|
|
1439
1410
|
]);
|
|
1440
1411
|
return new Uint8Array([
|
|
1441
1412
|
d.ServerKeyExchange,
|
|
1442
|
-
...
|
|
1443
|
-
...
|
|
1413
|
+
...y(h.length),
|
|
1414
|
+
...h
|
|
1444
1415
|
]);
|
|
1445
1416
|
}
|
|
1446
1417
|
/**
|
|
@@ -1482,31 +1453,18 @@ class K {
|
|
|
1482
1453
|
* +------------------------------------+
|
|
1483
1454
|
*/
|
|
1484
1455
|
static serverHello(e, t, r) {
|
|
1485
|
-
const
|
|
1486
|
-
switch (
|
|
1456
|
+
const n = e.extensions.map((_) => {
|
|
1457
|
+
switch (_.type) {
|
|
1487
1458
|
case "server_name":
|
|
1488
|
-
return
|
|
1489
|
-
case "supported_groups":
|
|
1490
|
-
return Se.encodeForClient(
|
|
1491
|
-
"secp256r1"
|
|
1492
|
-
);
|
|
1493
|
-
case "ec_point_formats":
|
|
1494
|
-
return le.encodeForClient(
|
|
1495
|
-
"uncompressed"
|
|
1496
|
-
);
|
|
1497
|
-
case "signature_algorithms":
|
|
1498
|
-
return Ae.encodeforClient(
|
|
1499
|
-
"sha256",
|
|
1500
|
-
"rsa"
|
|
1501
|
-
);
|
|
1459
|
+
return Ce.encodeForClient();
|
|
1502
1460
|
}
|
|
1503
|
-
}).filter((
|
|
1461
|
+
}).filter((_) => _ !== void 0), i = u(n), a = new Uint8Array([
|
|
1504
1462
|
// Version field – 0x03, 0x03 means TLS 1.2
|
|
1505
1463
|
...U,
|
|
1506
1464
|
...t,
|
|
1507
1465
|
e.session_id.length,
|
|
1508
1466
|
...e.session_id,
|
|
1509
|
-
...I(
|
|
1467
|
+
...I(he.TLS1_CK_ECDHE_RSA_WITH_AES_128_GCM_SHA256),
|
|
1510
1468
|
r,
|
|
1511
1469
|
// Extensions length (2 bytes)
|
|
1512
1470
|
...I(i.length),
|
|
@@ -1514,12 +1472,12 @@ class K {
|
|
|
1514
1472
|
]);
|
|
1515
1473
|
return new Uint8Array([
|
|
1516
1474
|
d.ServerHello,
|
|
1517
|
-
...
|
|
1518
|
-
...
|
|
1475
|
+
...y(a.length),
|
|
1476
|
+
...a
|
|
1519
1477
|
]);
|
|
1520
1478
|
}
|
|
1521
1479
|
static serverHelloDone() {
|
|
1522
|
-
return new Uint8Array([d.ServerHelloDone, ...
|
|
1480
|
+
return new Uint8Array([d.ServerHelloDone, ...y(0)]);
|
|
1523
1481
|
}
|
|
1524
1482
|
/**
|
|
1525
1483
|
* Server finished message.
|
|
@@ -1542,9 +1500,9 @@ class K {
|
|
|
1542
1500
|
static async createFinishedMessage(e, t) {
|
|
1543
1501
|
const r = await crypto.subtle.digest(
|
|
1544
1502
|
"SHA-256",
|
|
1545
|
-
|
|
1546
|
-
),
|
|
1547
|
-
await
|
|
1503
|
+
u(e)
|
|
1504
|
+
), n = new Uint8Array(
|
|
1505
|
+
await O(
|
|
1548
1506
|
t,
|
|
1549
1507
|
new TextEncoder().encode("server finished"),
|
|
1550
1508
|
r,
|
|
@@ -1554,33 +1512,33 @@ class K {
|
|
|
1554
1512
|
);
|
|
1555
1513
|
return new Uint8Array([
|
|
1556
1514
|
d.Finished,
|
|
1557
|
-
...
|
|
1558
|
-
...
|
|
1515
|
+
...y(n.length),
|
|
1516
|
+
...n
|
|
1559
1517
|
]);
|
|
1560
1518
|
}
|
|
1561
1519
|
static changeCipherSpec() {
|
|
1562
1520
|
return new Uint8Array([1]);
|
|
1563
1521
|
}
|
|
1564
1522
|
}
|
|
1565
|
-
function
|
|
1566
|
-
return
|
|
1523
|
+
function Ye(s, e) {
|
|
1524
|
+
return Ze.generateCertificate(s, e);
|
|
1567
1525
|
}
|
|
1568
|
-
function
|
|
1526
|
+
function yt(s) {
|
|
1569
1527
|
return `-----BEGIN CERTIFICATE-----
|
|
1570
1528
|
${fe(
|
|
1571
|
-
de(
|
|
1529
|
+
de(s.buffer)
|
|
1572
1530
|
)}
|
|
1573
1531
|
-----END CERTIFICATE-----`;
|
|
1574
1532
|
}
|
|
1575
|
-
async function
|
|
1576
|
-
const e = await crypto.subtle.exportKey("pkcs8",
|
|
1533
|
+
async function Lt(s) {
|
|
1534
|
+
const e = await crypto.subtle.exportKey("pkcs8", s);
|
|
1577
1535
|
return `-----BEGIN PRIVATE KEY-----
|
|
1578
1536
|
${fe(
|
|
1579
1537
|
de(e)
|
|
1580
1538
|
)}
|
|
1581
1539
|
-----END PRIVATE KEY-----`;
|
|
1582
1540
|
}
|
|
1583
|
-
class
|
|
1541
|
+
class Ze {
|
|
1584
1542
|
static async generateCertificate(e, t) {
|
|
1585
1543
|
const r = await crypto.subtle.generateKey(
|
|
1586
1544
|
{
|
|
@@ -1592,17 +1550,17 @@ class ke {
|
|
|
1592
1550
|
!0,
|
|
1593
1551
|
// extractable
|
|
1594
1552
|
["sign", "verify"]
|
|
1595
|
-
),
|
|
1553
|
+
), n = await this.signingRequest(
|
|
1596
1554
|
e,
|
|
1597
1555
|
r.publicKey
|
|
1598
1556
|
), i = await this.sign(
|
|
1599
|
-
|
|
1557
|
+
n,
|
|
1600
1558
|
(t == null ? void 0 : t.privateKey) ?? r.privateKey
|
|
1601
1559
|
);
|
|
1602
1560
|
return {
|
|
1603
1561
|
keyPair: r,
|
|
1604
1562
|
certificate: i,
|
|
1605
|
-
tbsCertificate:
|
|
1563
|
+
tbsCertificate: n,
|
|
1606
1564
|
tbsDescription: e
|
|
1607
1565
|
};
|
|
1608
1566
|
}
|
|
@@ -1659,16 +1617,16 @@ class ke {
|
|
|
1659
1617
|
}
|
|
1660
1618
|
static distinguishedName(e) {
|
|
1661
1619
|
const t = [];
|
|
1662
|
-
for (const [r,
|
|
1620
|
+
for (const [r, n] of Object.entries(e)) {
|
|
1663
1621
|
const i = [
|
|
1664
1622
|
o.objectIdentifier(w(r))
|
|
1665
1623
|
];
|
|
1666
1624
|
switch (r) {
|
|
1667
1625
|
case "countryName":
|
|
1668
|
-
i.push(o.printableString(
|
|
1626
|
+
i.push(o.printableString(n));
|
|
1669
1627
|
break;
|
|
1670
1628
|
default:
|
|
1671
|
-
i.push(o.utf8String(
|
|
1629
|
+
i.push(o.utf8String(n));
|
|
1672
1630
|
}
|
|
1673
1631
|
t.push(o.set([o.sequence(i)]));
|
|
1674
1632
|
}
|
|
@@ -1679,14 +1637,14 @@ class ke {
|
|
|
1679
1637
|
o.ASN1(
|
|
1680
1638
|
H.UTCTime,
|
|
1681
1639
|
new TextEncoder().encode(
|
|
1682
|
-
|
|
1640
|
+
ie((e == null ? void 0 : e.notBefore) ?? /* @__PURE__ */ new Date())
|
|
1683
1641
|
)
|
|
1684
1642
|
),
|
|
1685
1643
|
o.ASN1(
|
|
1686
1644
|
H.UTCTime,
|
|
1687
1645
|
new TextEncoder().encode(
|
|
1688
|
-
|
|
1689
|
-
(e == null ? void 0 : e.notAfter) ??
|
|
1646
|
+
ie(
|
|
1647
|
+
(e == null ? void 0 : e.notAfter) ?? Xe(/* @__PURE__ */ new Date(), 10)
|
|
1690
1648
|
)
|
|
1691
1649
|
)
|
|
1692
1650
|
)
|
|
@@ -1735,24 +1693,24 @@ class ke {
|
|
|
1735
1693
|
]);
|
|
1736
1694
|
}
|
|
1737
1695
|
static subjectAltName(e) {
|
|
1738
|
-
var i,
|
|
1739
|
-
const t = ((i = e.dnsNames) == null ? void 0 : i.map((
|
|
1740
|
-
const c = o.ia5String(
|
|
1696
|
+
var i, a;
|
|
1697
|
+
const t = ((i = e.dnsNames) == null ? void 0 : i.map((_) => {
|
|
1698
|
+
const c = o.ia5String(_);
|
|
1741
1699
|
return o.contextSpecific(2, c);
|
|
1742
|
-
})) || [], r = ((
|
|
1743
|
-
const c = o.ia5String(
|
|
1700
|
+
})) || [], r = ((a = e.ipAddresses) == null ? void 0 : a.map((_) => {
|
|
1701
|
+
const c = o.ia5String(_);
|
|
1744
1702
|
return o.contextSpecific(7, c);
|
|
1745
|
-
})) || [],
|
|
1703
|
+
})) || [], n = o.octetString(
|
|
1746
1704
|
o.sequence([...t, ...r])
|
|
1747
1705
|
);
|
|
1748
1706
|
return o.sequence([
|
|
1749
1707
|
o.objectIdentifier(w("subjectAltName")),
|
|
1750
1708
|
o.boolean(!0),
|
|
1751
|
-
|
|
1709
|
+
n
|
|
1752
1710
|
]);
|
|
1753
1711
|
}
|
|
1754
1712
|
}
|
|
1755
|
-
const
|
|
1713
|
+
const Je = {
|
|
1756
1714
|
// Algorithm OIDs
|
|
1757
1715
|
"1.2.840.113549.1.1.1": "rsaEncryption",
|
|
1758
1716
|
"1.2.840.113549.1.1.4": "md5WithRSAEncryption",
|
|
@@ -1862,45 +1820,25 @@ const Fe = {
|
|
|
1862
1820
|
"1.3.6.1.5.5.7.3.4": "emailProtection",
|
|
1863
1821
|
"1.3.6.1.5.5.7.3.8": "timeStamping"
|
|
1864
1822
|
};
|
|
1865
|
-
function w(
|
|
1866
|
-
for (const [e, t] of Object.entries(
|
|
1867
|
-
if (t ===
|
|
1823
|
+
function w(s) {
|
|
1824
|
+
for (const [e, t] of Object.entries(Je))
|
|
1825
|
+
if (t === s)
|
|
1868
1826
|
return e;
|
|
1869
|
-
throw new Error(`OID not found for name: ${
|
|
1827
|
+
throw new Error(`OID not found for name: ${s}`);
|
|
1870
1828
|
}
|
|
1871
|
-
const
|
|
1872
|
-
EOC: 0,
|
|
1829
|
+
const se = 32, H = {
|
|
1873
1830
|
Boolean: 1,
|
|
1874
1831
|
Integer: 2,
|
|
1875
1832
|
BitString: 3,
|
|
1876
1833
|
OctetString: 4,
|
|
1877
1834
|
Null: 5,
|
|
1878
1835
|
OID: 6,
|
|
1879
|
-
ObjectDescriptor: 7,
|
|
1880
|
-
External: 8,
|
|
1881
|
-
Real: 9,
|
|
1882
|
-
// float
|
|
1883
|
-
Enumeration: 10,
|
|
1884
|
-
PDV: 11,
|
|
1885
1836
|
Utf8String: 12,
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
Set: 17 | Q,
|
|
1889
|
-
NumericString: 18,
|
|
1837
|
+
Sequence: 16 | se,
|
|
1838
|
+
Set: 17 | se,
|
|
1890
1839
|
PrintableString: 19,
|
|
1891
|
-
T61String: 20,
|
|
1892
|
-
VideotexString: 21,
|
|
1893
1840
|
IA5String: 22,
|
|
1894
|
-
UTCTime: 23
|
|
1895
|
-
GeneralizedTime: 24,
|
|
1896
|
-
GraphicString: 25,
|
|
1897
|
-
VisibleString: 26,
|
|
1898
|
-
GeneralString: 28,
|
|
1899
|
-
UniversalString: 29,
|
|
1900
|
-
CharacterString: 30,
|
|
1901
|
-
BMPString: 31,
|
|
1902
|
-
Constructor: 32,
|
|
1903
|
-
Context: 128
|
|
1841
|
+
UTCTime: 23
|
|
1904
1842
|
};
|
|
1905
1843
|
class o {
|
|
1906
1844
|
// Helper functions for ASN.1 DER encoding
|
|
@@ -1912,16 +1850,16 @@ class o {
|
|
|
1912
1850
|
const r = [];
|
|
1913
1851
|
for (; t > 0; )
|
|
1914
1852
|
r.unshift(t & 255), t >>= 8;
|
|
1915
|
-
const
|
|
1916
|
-
i[0] = 128 |
|
|
1917
|
-
for (let
|
|
1918
|
-
i[
|
|
1853
|
+
const n = r.length, i = new Uint8Array(1 + n);
|
|
1854
|
+
i[0] = 128 | n;
|
|
1855
|
+
for (let a = 0; a < n; a++)
|
|
1856
|
+
i[a + 1] = r[a];
|
|
1919
1857
|
return i;
|
|
1920
1858
|
}
|
|
1921
1859
|
}
|
|
1922
1860
|
static ASN1(e, t) {
|
|
1923
|
-
const r = o.length_(t.length),
|
|
1924
|
-
return
|
|
1861
|
+
const r = o.length_(t.length), n = new Uint8Array(1 + r.length + t.length);
|
|
1862
|
+
return n[0] = e, n.set(r, 1), n.set(t, 1 + r.length), n;
|
|
1925
1863
|
}
|
|
1926
1864
|
static integer(e) {
|
|
1927
1865
|
if (e[0] > 127) {
|
|
@@ -1941,18 +1879,18 @@ class o {
|
|
|
1941
1879
|
return o.ASN1(H.Null, new Uint8Array(0));
|
|
1942
1880
|
}
|
|
1943
1881
|
static objectIdentifier(e) {
|
|
1944
|
-
const t = e.split(".").map(Number),
|
|
1882
|
+
const t = e.split(".").map(Number), n = [t[0] * 40 + t[1]];
|
|
1945
1883
|
for (let i = 2; i < t.length; i++) {
|
|
1946
|
-
let
|
|
1947
|
-
const
|
|
1884
|
+
let a = t[i];
|
|
1885
|
+
const _ = [];
|
|
1948
1886
|
do
|
|
1949
|
-
|
|
1950
|
-
while (
|
|
1951
|
-
for (let c = 0; c <
|
|
1952
|
-
|
|
1953
|
-
|
|
1887
|
+
_.unshift(a & 127), a >>= 7;
|
|
1888
|
+
while (a > 0);
|
|
1889
|
+
for (let c = 0; c < _.length - 1; c++)
|
|
1890
|
+
_[c] |= 128;
|
|
1891
|
+
n.push(..._);
|
|
1954
1892
|
}
|
|
1955
|
-
return o.ASN1(H.OID, new Uint8Array(
|
|
1893
|
+
return o.ASN1(H.OID, new Uint8Array(n));
|
|
1956
1894
|
}
|
|
1957
1895
|
static utf8String(e) {
|
|
1958
1896
|
const t = new TextEncoder().encode(e);
|
|
@@ -1963,18 +1901,18 @@ class o {
|
|
|
1963
1901
|
return o.ASN1(H.PrintableString, t);
|
|
1964
1902
|
}
|
|
1965
1903
|
static sequence(e) {
|
|
1966
|
-
return o.ASN1(H.Sequence,
|
|
1904
|
+
return o.ASN1(H.Sequence, u(e));
|
|
1967
1905
|
}
|
|
1968
1906
|
static set(e) {
|
|
1969
|
-
return o.ASN1(H.Set,
|
|
1907
|
+
return o.ASN1(H.Set, u(e));
|
|
1970
1908
|
}
|
|
1971
1909
|
static ia5String(e) {
|
|
1972
1910
|
const t = new TextEncoder().encode(e);
|
|
1973
1911
|
return o.ASN1(H.IA5String, t);
|
|
1974
1912
|
}
|
|
1975
1913
|
static contextSpecific(e, t, r = !1) {
|
|
1976
|
-
const
|
|
1977
|
-
return o.ASN1(
|
|
1914
|
+
const n = (r ? 160 : 128) | e;
|
|
1915
|
+
return o.ASN1(n, t);
|
|
1978
1916
|
}
|
|
1979
1917
|
static boolean(e) {
|
|
1980
1918
|
return o.ASN1(
|
|
@@ -1983,73 +1921,124 @@ class o {
|
|
|
1983
1921
|
);
|
|
1984
1922
|
}
|
|
1985
1923
|
}
|
|
1986
|
-
function de(
|
|
1987
|
-
return btoa(String.fromCodePoint(...new Uint8Array(
|
|
1924
|
+
function de(s) {
|
|
1925
|
+
return btoa(String.fromCodePoint(...new Uint8Array(s)));
|
|
1988
1926
|
}
|
|
1989
|
-
function fe(
|
|
1927
|
+
function fe(s) {
|
|
1990
1928
|
var e;
|
|
1991
|
-
return ((e =
|
|
1992
|
-
`)) ||
|
|
1929
|
+
return ((e = s.match(/.{1,64}/g)) == null ? void 0 : e.join(`
|
|
1930
|
+
`)) || s;
|
|
1993
1931
|
}
|
|
1994
|
-
function
|
|
1995
|
-
const e =
|
|
1996
|
-
return `${e}${t}${r}${
|
|
1932
|
+
function ie(s) {
|
|
1933
|
+
const e = s.getUTCFullYear().toString().substr(2), t = W(s.getUTCMonth() + 1), r = W(s.getUTCDate()), n = W(s.getUTCHours()), i = W(s.getUTCMinutes()), a = W(s.getUTCSeconds());
|
|
1934
|
+
return `${e}${t}${r}${n}${i}${a}Z`;
|
|
1997
1935
|
}
|
|
1998
|
-
function W(
|
|
1999
|
-
return
|
|
1936
|
+
function W(s) {
|
|
1937
|
+
return s.toString().padStart(2, "0");
|
|
2000
1938
|
}
|
|
2001
|
-
function
|
|
2002
|
-
const t = new Date(
|
|
1939
|
+
function Xe(s, e) {
|
|
1940
|
+
const t = new Date(s);
|
|
2003
1941
|
return t.setUTCFullYear(t.getUTCFullYear() + e), t;
|
|
2004
1942
|
}
|
|
2005
|
-
async function
|
|
2006
|
-
|
|
1943
|
+
async function Qe(s, e, t) {
|
|
1944
|
+
var a;
|
|
1945
|
+
const r = typeof s == "string" ? new Request(s, e) : s;
|
|
2007
1946
|
if (!t)
|
|
2008
|
-
return r;
|
|
1947
|
+
return await fetch(r);
|
|
1948
|
+
const [n, i] = await Ie(r);
|
|
2009
1949
|
try {
|
|
2010
|
-
return await
|
|
1950
|
+
return await fetch(n);
|
|
2011
1951
|
} catch {
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
url: `${t}${n.url}`
|
|
2018
|
-
});
|
|
2019
|
-
else
|
|
2020
|
-
throw new Error("Invalid input type for fetch");
|
|
2021
|
-
return fetch(s, e);
|
|
1952
|
+
const c = ((a = new Headers(i.headers).get("x-cors-proxy-allowed-request-headers")) == null ? void 0 : a.split(",")) || [], S = c.includes("authorization") || c.includes("cookie"), h = await De(i, {
|
|
1953
|
+
url: `${t}${r.url}`,
|
|
1954
|
+
...S && { credentials: "include" }
|
|
1955
|
+
});
|
|
1956
|
+
return await fetch(h, e);
|
|
2022
1957
|
}
|
|
2023
1958
|
}
|
|
2024
|
-
|
|
1959
|
+
class et extends TransformStream {
|
|
1960
|
+
constructor() {
|
|
1961
|
+
let e = new Uint8Array(0), t = "SCAN_CHUNK_SIZE", r = 0;
|
|
1962
|
+
super({
|
|
1963
|
+
transform(n, i) {
|
|
1964
|
+
for (e = u([e, n]); e.length > 0; )
|
|
1965
|
+
if (t === "SCAN_CHUNK_SIZE") {
|
|
1966
|
+
if (e.length < 3)
|
|
1967
|
+
return;
|
|
1968
|
+
let a = 0;
|
|
1969
|
+
for (; a < e.length; ) {
|
|
1970
|
+
const S = e[a];
|
|
1971
|
+
if (!(S >= 48 && S <= 57 || // 0-9
|
|
1972
|
+
S >= 97 && S <= 102 || // a-f
|
|
1973
|
+
S >= 65 && S <= 70)) break;
|
|
1974
|
+
a++;
|
|
1975
|
+
}
|
|
1976
|
+
if (a === 0)
|
|
1977
|
+
throw new Error("Invalid chunk size format");
|
|
1978
|
+
if (e.length < a + 2)
|
|
1979
|
+
return;
|
|
1980
|
+
if (e[a] !== 13 || // \r
|
|
1981
|
+
e[a + 1] !== 10)
|
|
1982
|
+
throw new Error(
|
|
1983
|
+
"Invalid chunk size format. Expected CRLF after chunk size"
|
|
1984
|
+
);
|
|
1985
|
+
const _ = new TextDecoder().decode(
|
|
1986
|
+
e.slice(0, a)
|
|
1987
|
+
), c = parseInt(_, 16);
|
|
1988
|
+
if (e = e.slice(a + 2), c === 0) {
|
|
1989
|
+
t = "SCAN_FINAL_CHUNK", i.terminate();
|
|
1990
|
+
return;
|
|
1991
|
+
}
|
|
1992
|
+
r = c, t = "SCAN_CHUNK_DATA";
|
|
1993
|
+
} else if (t === "SCAN_CHUNK_DATA") {
|
|
1994
|
+
const a = Math.min(
|
|
1995
|
+
r,
|
|
1996
|
+
e.length
|
|
1997
|
+
), _ = e.slice(0, a);
|
|
1998
|
+
e = e.slice(a), r -= a, i.enqueue(_), r === 0 && (t = "SCAN_CHUNK_TRAILER");
|
|
1999
|
+
} else if (t === "SCAN_CHUNK_TRAILER") {
|
|
2000
|
+
if (e.length < 2)
|
|
2001
|
+
return;
|
|
2002
|
+
if (e[0] !== 13 || e[1] !== 10)
|
|
2003
|
+
throw new Error(
|
|
2004
|
+
"Invalid chunk trailer format. Expected CRLF after chunk data"
|
|
2005
|
+
);
|
|
2006
|
+
e = e.slice(2), t = "SCAN_CHUNK_SIZE";
|
|
2007
|
+
}
|
|
2008
|
+
}
|
|
2009
|
+
});
|
|
2010
|
+
}
|
|
2011
|
+
}
|
|
2012
|
+
const tt = (s, e) => ({
|
|
2013
|
+
...s,
|
|
2025
2014
|
websocket: {
|
|
2026
|
-
url: (
|
|
2027
|
-
host:
|
|
2028
|
-
port:
|
|
2015
|
+
url: (t, r, n) => `ws://playground.internal/?${new URLSearchParams({
|
|
2016
|
+
host: r,
|
|
2017
|
+
port: n
|
|
2029
2018
|
}).toString()}`,
|
|
2030
2019
|
subprotocol: "binary",
|
|
2031
|
-
decorator: () => class extends
|
|
2032
|
-
constructor(
|
|
2033
|
-
super(
|
|
2034
|
-
CAroot:
|
|
2035
|
-
corsProxyUrl:
|
|
2020
|
+
decorator: () => class extends rt {
|
|
2021
|
+
constructor(t, r) {
|
|
2022
|
+
super(t, r, {
|
|
2023
|
+
CAroot: e.CAroot,
|
|
2024
|
+
corsProxyUrl: e.corsProxyUrl
|
|
2036
2025
|
});
|
|
2037
2026
|
}
|
|
2038
2027
|
}
|
|
2039
2028
|
}
|
|
2040
2029
|
});
|
|
2041
|
-
class
|
|
2030
|
+
class rt {
|
|
2042
2031
|
constructor(e, t, {
|
|
2043
2032
|
CAroot: r,
|
|
2044
|
-
corsProxyUrl:
|
|
2033
|
+
corsProxyUrl: n,
|
|
2045
2034
|
outputType: i = "messages"
|
|
2046
2035
|
} = {}) {
|
|
2047
|
-
this.
|
|
2048
|
-
const
|
|
2049
|
-
this.host =
|
|
2036
|
+
this.CONNECTING = 0, this.OPEN = 1, this.CLOSING = 2, this.CLOSED = 3, this.readyState = this.CONNECTING, this.binaryType = "blob", this.bufferedAmount = 0, this.extensions = "", this.protocol = "ws", this.host = "", this.port = 0, this.listeners = /* @__PURE__ */ new Map(), this.clientUpstream = new TransformStream(), this.clientUpstreamWriter = this.clientUpstream.writable.getWriter(), this.clientDownstream = new TransformStream(), this.fetchInitiated = !1, this.bufferedBytesFromClient = new Uint8Array(0), this.url = e, this.options = t;
|
|
2037
|
+
const a = new URL(e);
|
|
2038
|
+
this.host = a.searchParams.get("host"), this.port = parseInt(a.searchParams.get("port"), 10), this.binaryType = "arraybuffer", this.corsProxyUrl = n, this.CAroot = r, i === "messages" && this.clientDownstream.readable.pipeTo(
|
|
2050
2039
|
new WritableStream({
|
|
2051
|
-
write: (
|
|
2052
|
-
this.emit("message", { data:
|
|
2040
|
+
write: (_) => {
|
|
2041
|
+
this.emit("message", { data: _ });
|
|
2053
2042
|
},
|
|
2054
2043
|
abort: () => {
|
|
2055
2044
|
this.emit("error", new Error("ECONNREFUSED")), this.close();
|
|
@@ -2065,8 +2054,8 @@ class Ve {
|
|
|
2065
2054
|
this.addEventListener(e, t);
|
|
2066
2055
|
}
|
|
2067
2056
|
once(e, t) {
|
|
2068
|
-
const r = (
|
|
2069
|
-
t(
|
|
2057
|
+
const r = (n) => {
|
|
2058
|
+
t(n), this.removeEventListener(e, r);
|
|
2070
2059
|
};
|
|
2071
2060
|
this.addEventListener(e, r);
|
|
2072
2061
|
}
|
|
@@ -2084,8 +2073,8 @@ class Ve {
|
|
|
2084
2073
|
e === "message" ? this.onmessage(t) : e === "close" ? this.onclose(t) : e === "error" ? this.onerror(t) : e === "open" && this.onopen(t);
|
|
2085
2074
|
const r = this.listeners.get(e);
|
|
2086
2075
|
if (r)
|
|
2087
|
-
for (const
|
|
2088
|
-
|
|
2076
|
+
for (const n of r)
|
|
2077
|
+
n(t);
|
|
2089
2078
|
}
|
|
2090
2079
|
// Default event handlers that can be overridden by the user
|
|
2091
2080
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
@@ -2106,10 +2095,10 @@ class Ve {
|
|
|
2106
2095
|
*/
|
|
2107
2096
|
send(e) {
|
|
2108
2097
|
if (!(this.readyState === this.CLOSING || this.readyState === this.CLOSED) && (this.clientUpstreamWriter.write(new Uint8Array(e)), !this.fetchInitiated))
|
|
2109
|
-
switch (this.bufferedBytesFromClient =
|
|
2098
|
+
switch (this.bufferedBytesFromClient = u([
|
|
2110
2099
|
this.bufferedBytesFromClient,
|
|
2111
2100
|
new Uint8Array(e)
|
|
2112
|
-
]),
|
|
2101
|
+
]), st(this.port, this.bufferedBytesFromClient)) {
|
|
2113
2102
|
case !1:
|
|
2114
2103
|
return;
|
|
2115
2104
|
case "other":
|
|
@@ -2128,7 +2117,7 @@ class Ve {
|
|
|
2128
2117
|
throw new Error(
|
|
2129
2118
|
"TLS protocol is only supported when the TCPOverFetchWebsocket is instantiated with a CAroot"
|
|
2130
2119
|
);
|
|
2131
|
-
const e = await
|
|
2120
|
+
const e = await Ye(
|
|
2132
2121
|
{
|
|
2133
2122
|
subject: {
|
|
2134
2123
|
commonName: this.host,
|
|
@@ -2138,20 +2127,20 @@ class Ve {
|
|
|
2138
2127
|
issuer: this.CAroot.tbsDescription.subject
|
|
2139
2128
|
},
|
|
2140
2129
|
this.CAroot.keyPair
|
|
2141
|
-
), t = new
|
|
2130
|
+
), t = new ze();
|
|
2142
2131
|
this.clientUpstream.readable.pipeTo(t.clientEnd.upstream.writable).catch(() => {
|
|
2143
2132
|
}), t.clientEnd.downstream.readable.pipeTo(this.clientDownstream.writable).catch(() => {
|
|
2144
2133
|
}), await t.TLSHandshake(e.keyPair.privateKey, [
|
|
2145
2134
|
e.certificate,
|
|
2146
2135
|
this.CAroot.certificate
|
|
2147
2136
|
]);
|
|
2148
|
-
const r = await
|
|
2137
|
+
const r = await L.parseHttpRequest(
|
|
2149
2138
|
t.serverEnd.upstream.readable,
|
|
2150
2139
|
this.host,
|
|
2151
2140
|
"https"
|
|
2152
2141
|
);
|
|
2153
2142
|
try {
|
|
2154
|
-
await
|
|
2143
|
+
await L.fetchRawResponseBytes(
|
|
2155
2144
|
r,
|
|
2156
2145
|
this.corsProxyUrl
|
|
2157
2146
|
).pipeTo(t.serverEnd.downstream.writable);
|
|
@@ -2159,13 +2148,13 @@ class Ve {
|
|
|
2159
2148
|
}
|
|
2160
2149
|
}
|
|
2161
2150
|
async fetchOverHTTP() {
|
|
2162
|
-
const e = await
|
|
2151
|
+
const e = await L.parseHttpRequest(
|
|
2163
2152
|
this.clientUpstream.readable,
|
|
2164
2153
|
this.host,
|
|
2165
2154
|
"http"
|
|
2166
2155
|
);
|
|
2167
2156
|
try {
|
|
2168
|
-
await
|
|
2157
|
+
await L.fetchRawResponseBytes(
|
|
2169
2158
|
e,
|
|
2170
2159
|
this.corsProxyUrl
|
|
2171
2160
|
).pipeTo(this.clientDownstream.writable);
|
|
@@ -2176,7 +2165,7 @@ class Ve {
|
|
|
2176
2165
|
this.emit("message", { data: new Uint8Array(0) }), this.readyState = this.CLOSING, this.emit("close"), this.readyState = this.CLOSED;
|
|
2177
2166
|
}
|
|
2178
2167
|
}
|
|
2179
|
-
const
|
|
2168
|
+
const nt = [
|
|
2180
2169
|
"GET",
|
|
2181
2170
|
"POST",
|
|
2182
2171
|
"HEAD",
|
|
@@ -2186,30 +2175,30 @@ const ze = [
|
|
|
2186
2175
|
"PUT",
|
|
2187
2176
|
"TRACE"
|
|
2188
2177
|
];
|
|
2189
|
-
function
|
|
2178
|
+
function st(s, e) {
|
|
2190
2179
|
if (e.length < 8)
|
|
2191
2180
|
return !1;
|
|
2192
|
-
if (
|
|
2181
|
+
if (s === 443 && e[0] === C.Handshake && // TLS versions between 1.0 and 1.2
|
|
2193
2182
|
e[1] === 3 && e[2] >= 1 && e[2] <= 3)
|
|
2194
2183
|
return "tls";
|
|
2195
2184
|
const r = new TextDecoder("latin1", {
|
|
2196
2185
|
fatal: !0
|
|
2197
2186
|
}).decode(e);
|
|
2198
|
-
return
|
|
2187
|
+
return nt.some(
|
|
2199
2188
|
(i) => r.startsWith(i + " ")
|
|
2200
2189
|
) ? "http" : "other";
|
|
2201
2190
|
}
|
|
2202
|
-
class
|
|
2191
|
+
class L {
|
|
2203
2192
|
/**
|
|
2204
2193
|
* Streams a HTTP response including the status line and headers.
|
|
2205
2194
|
*/
|
|
2206
2195
|
static fetchRawResponseBytes(e, t) {
|
|
2207
2196
|
return new ReadableStream({
|
|
2208
2197
|
async start(r) {
|
|
2209
|
-
var
|
|
2210
|
-
let
|
|
2198
|
+
var _;
|
|
2199
|
+
let n;
|
|
2211
2200
|
try {
|
|
2212
|
-
|
|
2201
|
+
n = await Qe(
|
|
2213
2202
|
e,
|
|
2214
2203
|
void 0,
|
|
2215
2204
|
t
|
|
@@ -2225,21 +2214,21 @@ Content-Length: 0\r
|
|
|
2225
2214
|
), r.error(c);
|
|
2226
2215
|
return;
|
|
2227
2216
|
}
|
|
2228
|
-
r.enqueue(
|
|
2229
|
-
const i = (
|
|
2217
|
+
r.enqueue(L.headersAsBytes(n));
|
|
2218
|
+
const i = (_ = n.body) == null ? void 0 : _.getReader();
|
|
2230
2219
|
if (!i) {
|
|
2231
2220
|
r.close();
|
|
2232
2221
|
return;
|
|
2233
2222
|
}
|
|
2234
|
-
const
|
|
2223
|
+
const a = new TextEncoder();
|
|
2235
2224
|
for (; ; ) {
|
|
2236
2225
|
const { done: c, value: S } = await i.read();
|
|
2237
2226
|
if (S && (r.enqueue(
|
|
2238
|
-
|
|
2227
|
+
a.encode(`${S.length.toString(16)}\r
|
|
2239
2228
|
`)
|
|
2240
|
-
), r.enqueue(S), r.enqueue(
|
|
2229
|
+
), r.enqueue(S), r.enqueue(a.encode(`\r
|
|
2241
2230
|
`))), c) {
|
|
2242
|
-
r.enqueue(
|
|
2231
|
+
r.enqueue(a.encode(`0\r
|
|
2243
2232
|
\r
|
|
2244
2233
|
`)), r.close();
|
|
2245
2234
|
return;
|
|
@@ -2250,13 +2239,13 @@ Content-Length: 0\r
|
|
|
2250
2239
|
}
|
|
2251
2240
|
static headersAsBytes(e) {
|
|
2252
2241
|
const t = `HTTP/1.1 ${e.status} ${e.statusText}`, r = {};
|
|
2253
|
-
e.headers.forEach((
|
|
2254
|
-
r[
|
|
2242
|
+
e.headers.forEach((a, _) => {
|
|
2243
|
+
r[_.toLowerCase()] = a;
|
|
2255
2244
|
}), delete r["content-length"], r["transfer-encoding"] = "chunked";
|
|
2256
|
-
const
|
|
2257
|
-
for (const [
|
|
2258
|
-
|
|
2259
|
-
const i = [t, ...
|
|
2245
|
+
const n = [];
|
|
2246
|
+
for (const [a, _] of Object.entries(r))
|
|
2247
|
+
n.push(`${a}: ${_}`);
|
|
2248
|
+
const i = [t, ...n].join(`\r
|
|
2260
2249
|
`) + `\r
|
|
2261
2250
|
\r
|
|
2262
2251
|
`;
|
|
@@ -2267,45 +2256,56 @@ Content-Length: 0\r
|
|
|
2267
2256
|
* with known headers and a readable body stream.
|
|
2268
2257
|
*/
|
|
2269
2258
|
static async parseHttpRequest(e, t, r) {
|
|
2270
|
-
let
|
|
2271
|
-
const
|
|
2272
|
-
for (;
|
|
2273
|
-
const { done:
|
|
2274
|
-
if (
|
|
2259
|
+
let n = new Uint8Array(0), i = !1, a = -1;
|
|
2260
|
+
const _ = e.getReader();
|
|
2261
|
+
for (; a === -1; ) {
|
|
2262
|
+
const { done: x, value: P } = await _.read();
|
|
2263
|
+
if (x) {
|
|
2275
2264
|
i = !0;
|
|
2276
2265
|
break;
|
|
2277
2266
|
}
|
|
2278
|
-
|
|
2279
|
-
|
|
2267
|
+
n = u([n, P]), a = it(
|
|
2268
|
+
n,
|
|
2280
2269
|
new Uint8Array([13, 10, 13, 10])
|
|
2281
2270
|
);
|
|
2282
2271
|
}
|
|
2283
|
-
|
|
2284
|
-
const c =
|
|
2285
|
-
|
|
2272
|
+
_.releaseLock();
|
|
2273
|
+
const c = n.slice(0, a), S = L.parseRequestHeaders(c), h = S.headers.get("Transfer-Encoding") !== null ? "chunked" : "content-length", l = S.headers.get("Content-Length") !== null ? parseInt(S.headers.get("Content-Length"), 10) : void 0, A = n.slice(
|
|
2274
|
+
a + 4
|
|
2286
2275
|
/* Skip \r\n\r\n */
|
|
2287
2276
|
);
|
|
2288
|
-
let
|
|
2277
|
+
let f;
|
|
2289
2278
|
if (S.method !== "GET") {
|
|
2290
|
-
const
|
|
2291
|
-
A =
|
|
2292
|
-
|
|
2293
|
-
|
|
2279
|
+
const x = e.getReader();
|
|
2280
|
+
let P = A.length, k = A.slice(-6);
|
|
2281
|
+
const Ee = new TextEncoder().encode(`0\r
|
|
2282
|
+
\r
|
|
2283
|
+
`);
|
|
2284
|
+
f = new ReadableStream({
|
|
2285
|
+
async start(D) {
|
|
2286
|
+
A.length > 0 && D.enqueue(A), i && D.close();
|
|
2294
2287
|
},
|
|
2295
|
-
async pull(
|
|
2296
|
-
const { done: pe, value:
|
|
2297
|
-
if (
|
|
2298
|
-
|
|
2288
|
+
async pull(D) {
|
|
2289
|
+
const { done: pe, value: g } = await x.read();
|
|
2290
|
+
if (P += (g == null ? void 0 : g.length) || 0, g && (D.enqueue(g), k = u([
|
|
2291
|
+
k,
|
|
2292
|
+
g || new Uint8Array()
|
|
2293
|
+
]).slice(-5)), pe || h === "content-length" && l !== void 0 && P >= l || h === "chunked" && k.every(
|
|
2294
|
+
(we, ye) => we === Ee[ye]
|
|
2295
|
+
)) {
|
|
2296
|
+
D.close();
|
|
2299
2297
|
return;
|
|
2300
2298
|
}
|
|
2301
2299
|
}
|
|
2302
|
-
})
|
|
2300
|
+
}), h === "chunked" && (f = f.pipeThrough(
|
|
2301
|
+
new et()
|
|
2302
|
+
));
|
|
2303
2303
|
}
|
|
2304
|
-
const
|
|
2305
|
-
return
|
|
2304
|
+
const N = S.headers.get("Host") ?? t, z = new URL(S.path, r + "://" + N);
|
|
2305
|
+
return z.pathname = S.path, new Request(z.toString(), {
|
|
2306
2306
|
method: S.method,
|
|
2307
2307
|
headers: S.headers,
|
|
2308
|
-
body:
|
|
2308
|
+
body: f,
|
|
2309
2309
|
// In Node.js, duplex: 'half' is required when
|
|
2310
2310
|
// the body stream is provided.
|
|
2311
2311
|
// @ts-expect-error
|
|
@@ -2314,34 +2314,53 @@ Content-Length: 0\r
|
|
|
2314
2314
|
}
|
|
2315
2315
|
static parseRequestHeaders(e) {
|
|
2316
2316
|
const t = new TextDecoder().decode(e), r = t.split(`
|
|
2317
|
-
`)[0], [
|
|
2318
|
-
for (const
|
|
2317
|
+
`)[0], [n, i] = r.split(" "), a = new Headers();
|
|
2318
|
+
for (const _ of t.split(`\r
|
|
2319
2319
|
`).slice(1)) {
|
|
2320
|
-
if (
|
|
2320
|
+
if (_ === "")
|
|
2321
2321
|
break;
|
|
2322
|
-
const [c, S] =
|
|
2323
|
-
|
|
2322
|
+
const [c, S] = _.split(": ");
|
|
2323
|
+
a.set(c, S);
|
|
2324
2324
|
}
|
|
2325
|
-
return { method:
|
|
2325
|
+
return { method: n, path: i, headers: a };
|
|
2326
2326
|
}
|
|
2327
2327
|
}
|
|
2328
|
-
function
|
|
2329
|
-
const t =
|
|
2330
|
-
for (let i = 0; i <=
|
|
2331
|
-
let
|
|
2332
|
-
for (let
|
|
2333
|
-
if (
|
|
2334
|
-
|
|
2328
|
+
function it(s, e) {
|
|
2329
|
+
const t = s.length, r = e.length, n = t - r;
|
|
2330
|
+
for (let i = 0; i <= n; i++) {
|
|
2331
|
+
let a = !0;
|
|
2332
|
+
for (let _ = 0; _ < r; _++)
|
|
2333
|
+
if (s[i + _] !== e[_]) {
|
|
2334
|
+
a = !1;
|
|
2335
2335
|
break;
|
|
2336
2336
|
}
|
|
2337
|
-
if (
|
|
2337
|
+
if (a)
|
|
2338
2338
|
return i;
|
|
2339
2339
|
}
|
|
2340
2340
|
return -1;
|
|
2341
2341
|
}
|
|
2342
|
-
|
|
2342
|
+
async function at(s) {
|
|
2343
|
+
const e = "icudt74l.dat", t = (await import("./shared/icudt74l.js")).dataFilename, r = await (await fetch(t)).arrayBuffer();
|
|
2344
|
+
return {
|
|
2345
|
+
...s,
|
|
2346
|
+
ENV: {
|
|
2347
|
+
...s.ENV,
|
|
2348
|
+
ICU_DATA: "/internal/shared"
|
|
2349
|
+
},
|
|
2350
|
+
onRuntimeInitialized: (n) => {
|
|
2351
|
+
s.onRuntimeInitialized && s.onRuntimeInitialized(n), R.fileExists(
|
|
2352
|
+
n.FS,
|
|
2353
|
+
`${n.ENV.ICU_DATA}/${e}`
|
|
2354
|
+
) || (n.FS.mkdirTree(n.ENV.ICU_DATA), n.FS.writeFile(
|
|
2355
|
+
`${n.ENV.ICU_DATA}/${e}`,
|
|
2356
|
+
new Uint8Array(r)
|
|
2357
|
+
));
|
|
2358
|
+
}
|
|
2359
|
+
};
|
|
2360
|
+
}
|
|
2361
|
+
const _t = () => ({
|
|
2343
2362
|
websocket: {
|
|
2344
|
-
decorator: (
|
|
2363
|
+
decorator: (s) => class extends s {
|
|
2345
2364
|
constructor() {
|
|
2346
2365
|
try {
|
|
2347
2366
|
super();
|
|
@@ -2354,155 +2373,161 @@ const Xe = () => ({
|
|
|
2354
2373
|
}
|
|
2355
2374
|
}
|
|
2356
2375
|
});
|
|
2357
|
-
async function
|
|
2358
|
-
var
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
|
|
2376
|
+
async function gt(s, e = {}) {
|
|
2377
|
+
var i;
|
|
2378
|
+
let t = {
|
|
2379
|
+
..._t(),
|
|
2380
|
+
...e.emscriptenOptions || {}
|
|
2381
|
+
};
|
|
2382
|
+
e.tcpOverFetch && (t = tt(
|
|
2383
|
+
t,
|
|
2384
|
+
e.tcpOverFetch
|
|
2385
|
+
)), e.withICU && (t = at(t));
|
|
2386
|
+
const [r, n] = await Promise.all([
|
|
2387
|
+
Be(s),
|
|
2388
|
+
t
|
|
2389
|
+
]);
|
|
2390
|
+
return (i = e.onPhpLoaderModuleLoaded) == null || i.call(e, r), await ge(r, n);
|
|
2366
2391
|
}
|
|
2367
|
-
function
|
|
2392
|
+
function Kt(s, e) {
|
|
2368
2393
|
window.addEventListener("message", (t) => {
|
|
2369
|
-
t.source ===
|
|
2394
|
+
t.source === s.contentWindow && (e && t.origin !== e || typeof t.data != "object" || t.data.type !== "relay" || window.parent.postMessage(t.data, "*"));
|
|
2370
2395
|
}), window.addEventListener("message", (t) => {
|
|
2371
2396
|
var r;
|
|
2372
|
-
t.source === window.parent && (typeof t.data != "object" || t.data.type !== "relay" || (r =
|
|
2397
|
+
t.source === window.parent && (typeof t.data != "object" || t.data.type !== "relay" || (r = s == null ? void 0 : s.contentWindow) == null || r.postMessage(t.data));
|
|
2373
2398
|
});
|
|
2374
2399
|
}
|
|
2375
|
-
async function
|
|
2376
|
-
const e = new Worker(
|
|
2400
|
+
async function It(s) {
|
|
2401
|
+
const e = new Worker(s, { type: "module" });
|
|
2377
2402
|
return new Promise((t, r) => {
|
|
2378
2403
|
e.onerror = (i) => {
|
|
2379
|
-
const
|
|
2380
|
-
`WebWorker failed to load at ${
|
|
2404
|
+
const a = new Error(
|
|
2405
|
+
`WebWorker failed to load at ${s}. ${i.message ? `Original error: ${i.message}` : ""}`
|
|
2381
2406
|
);
|
|
2382
|
-
|
|
2407
|
+
a.filename = i.filename, r(a);
|
|
2383
2408
|
};
|
|
2384
|
-
function
|
|
2385
|
-
i.data === "worker-script-started" && (t(e), e.removeEventListener("message",
|
|
2409
|
+
function n(i) {
|
|
2410
|
+
i.data === "worker-script-started" && (t(e), e.removeEventListener("message", n));
|
|
2386
2411
|
}
|
|
2387
|
-
e.addEventListener("message",
|
|
2412
|
+
e.addEventListener("message", n);
|
|
2388
2413
|
});
|
|
2389
2414
|
}
|
|
2390
|
-
function
|
|
2415
|
+
function Dt(s, e = { initialSync: {} }) {
|
|
2391
2416
|
return e = {
|
|
2392
2417
|
...e,
|
|
2393
2418
|
initialSync: {
|
|
2394
2419
|
...e.initialSync,
|
|
2395
2420
|
direction: e.initialSync.direction ?? "opfs-to-memfs"
|
|
2396
2421
|
}
|
|
2397
|
-
}, async function(t, r,
|
|
2398
|
-
return e.initialSync.direction === "opfs-to-memfs" ? (
|
|
2422
|
+
}, async function(t, r, n) {
|
|
2423
|
+
return e.initialSync.direction === "opfs-to-memfs" ? (R.fileExists(r, n) && R.rmdir(r, n), R.mkdir(r, n), await ot(r, s, n)) : await Te(
|
|
2399
2424
|
r,
|
|
2400
|
-
n,
|
|
2401
2425
|
s,
|
|
2426
|
+
n,
|
|
2402
2427
|
e.initialSync.onProgress
|
|
2403
|
-
),
|
|
2428
|
+
), St(t, s, n);
|
|
2404
2429
|
};
|
|
2405
2430
|
}
|
|
2406
|
-
async function
|
|
2407
|
-
|
|
2408
|
-
const r = new
|
|
2431
|
+
async function ot(s, e, t) {
|
|
2432
|
+
R.mkdir(s, t);
|
|
2433
|
+
const r = new We({
|
|
2409
2434
|
concurrency: 40
|
|
2410
|
-
}),
|
|
2435
|
+
}), n = [], i = [
|
|
2411
2436
|
[e, t]
|
|
2412
2437
|
];
|
|
2413
2438
|
for (; i.length > 0; ) {
|
|
2414
|
-
const [
|
|
2415
|
-
for await (const c of
|
|
2439
|
+
const [a, _] = i.pop();
|
|
2440
|
+
for await (const c of a.values()) {
|
|
2416
2441
|
const S = r.run(async () => {
|
|
2417
|
-
const
|
|
2418
|
-
|
|
2442
|
+
const h = oe(
|
|
2443
|
+
_,
|
|
2419
2444
|
c.name
|
|
2420
2445
|
);
|
|
2421
2446
|
if (c.kind === "directory") {
|
|
2422
2447
|
try {
|
|
2423
|
-
|
|
2424
|
-
} catch (
|
|
2425
|
-
if ((
|
|
2426
|
-
throw
|
|
2448
|
+
s.mkdir(h);
|
|
2449
|
+
} catch (l) {
|
|
2450
|
+
if ((l == null ? void 0 : l.errno) !== 20)
|
|
2451
|
+
throw v.error(l), l;
|
|
2427
2452
|
}
|
|
2428
|
-
i.push([c,
|
|
2453
|
+
i.push([c, h]);
|
|
2429
2454
|
} else if (c.kind === "file") {
|
|
2430
|
-
const
|
|
2431
|
-
|
|
2432
|
-
|
|
2455
|
+
const l = await c.getFile(), A = new Uint8Array(await l.arrayBuffer());
|
|
2456
|
+
s.createDataFile(
|
|
2457
|
+
_,
|
|
2433
2458
|
c.name,
|
|
2434
|
-
|
|
2459
|
+
A,
|
|
2435
2460
|
!0,
|
|
2436
2461
|
!0,
|
|
2437
2462
|
!0
|
|
2438
2463
|
);
|
|
2439
2464
|
}
|
|
2440
|
-
|
|
2465
|
+
n.splice(n.indexOf(S), 1);
|
|
2441
2466
|
});
|
|
2442
|
-
|
|
2467
|
+
n.push(S);
|
|
2443
2468
|
}
|
|
2444
|
-
for (; i.length === 0 &&
|
|
2445
|
-
await Promise.any(
|
|
2469
|
+
for (; i.length === 0 && n.length > 0; )
|
|
2470
|
+
await Promise.any(n);
|
|
2446
2471
|
}
|
|
2447
2472
|
}
|
|
2448
|
-
async function
|
|
2449
|
-
|
|
2450
|
-
const
|
|
2451
|
-
async function i(
|
|
2473
|
+
async function Te(s, e, t, r) {
|
|
2474
|
+
s.mkdirTree(t);
|
|
2475
|
+
const n = [];
|
|
2476
|
+
async function i(h, l) {
|
|
2452
2477
|
await Promise.all(
|
|
2453
|
-
|
|
2454
|
-
(
|
|
2455
|
-
).map(async (
|
|
2456
|
-
const
|
|
2457
|
-
if (!
|
|
2458
|
-
|
|
2478
|
+
s.readdir(h).filter(
|
|
2479
|
+
(A) => A !== "." && A !== ".."
|
|
2480
|
+
).map(async (A) => {
|
|
2481
|
+
const f = oe(h, A);
|
|
2482
|
+
if (!ct(s, f)) {
|
|
2483
|
+
n.push([l, f, A]);
|
|
2459
2484
|
return;
|
|
2460
2485
|
}
|
|
2461
|
-
const
|
|
2486
|
+
const N = await l.getDirectoryHandle(A, {
|
|
2462
2487
|
create: !0
|
|
2463
2488
|
});
|
|
2464
|
-
return await i(
|
|
2489
|
+
return await i(f, N);
|
|
2465
2490
|
})
|
|
2466
2491
|
);
|
|
2467
2492
|
}
|
|
2468
2493
|
await i(t, e);
|
|
2469
|
-
let
|
|
2470
|
-
const
|
|
2494
|
+
let a = 0;
|
|
2495
|
+
const _ = r && lt(r, 100), c = 100, S = /* @__PURE__ */ new Set();
|
|
2471
2496
|
try {
|
|
2472
|
-
for (const [l, A
|
|
2473
|
-
const
|
|
2474
|
-
|
|
2475
|
-
|
|
2476
|
-
|
|
2477
|
-
|
|
2497
|
+
for (const [h, l, A] of n) {
|
|
2498
|
+
const f = F(
|
|
2499
|
+
h,
|
|
2500
|
+
A,
|
|
2501
|
+
s,
|
|
2502
|
+
l
|
|
2478
2503
|
).then(() => {
|
|
2479
|
-
|
|
2480
|
-
files:
|
|
2481
|
-
total:
|
|
2504
|
+
a++, S.delete(f), _ == null || _({
|
|
2505
|
+
files: a,
|
|
2506
|
+
total: n.length
|
|
2482
2507
|
});
|
|
2483
2508
|
});
|
|
2484
|
-
S.add(
|
|
2485
|
-
files:
|
|
2486
|
-
total:
|
|
2509
|
+
S.add(f), S.size >= c && (await Promise.race(S), _ == null || _({
|
|
2510
|
+
files: a,
|
|
2511
|
+
total: n.length
|
|
2487
2512
|
}));
|
|
2488
2513
|
}
|
|
2489
2514
|
} finally {
|
|
2490
2515
|
await Promise.allSettled(S);
|
|
2491
2516
|
}
|
|
2492
2517
|
}
|
|
2493
|
-
function
|
|
2494
|
-
return
|
|
2518
|
+
function ct(s, e) {
|
|
2519
|
+
return s.isDir(s.lookupPath(e, { follow: !0 }).node.mode);
|
|
2495
2520
|
}
|
|
2496
|
-
async function
|
|
2497
|
-
let
|
|
2521
|
+
async function F(s, e, t, r) {
|
|
2522
|
+
let n;
|
|
2498
2523
|
try {
|
|
2499
|
-
|
|
2524
|
+
n = t.readFile(r, {
|
|
2500
2525
|
encoding: "binary"
|
|
2501
2526
|
});
|
|
2502
2527
|
} catch {
|
|
2503
2528
|
return;
|
|
2504
2529
|
}
|
|
2505
|
-
const i = await
|
|
2530
|
+
const i = await s.getFileHandle(e, { create: !0 }), a = i.createWritable !== void 0 ? (
|
|
2506
2531
|
// Google Chrome, Firefox, probably more browsers
|
|
2507
2532
|
await i.createWritable()
|
|
2508
2533
|
) : (
|
|
@@ -2510,130 +2535,140 @@ async function Te(n, e, t, r) {
|
|
|
2510
2535
|
await i.createSyncAccessHandle()
|
|
2511
2536
|
);
|
|
2512
2537
|
try {
|
|
2513
|
-
await
|
|
2538
|
+
await a.truncate(0), await a.write(n);
|
|
2514
2539
|
} finally {
|
|
2515
|
-
await
|
|
2540
|
+
await a.close();
|
|
2516
2541
|
}
|
|
2517
2542
|
}
|
|
2518
|
-
function
|
|
2519
|
-
const r = [],
|
|
2520
|
-
r.push(
|
|
2521
|
-
}), i = new
|
|
2522
|
-
async function
|
|
2523
|
-
const
|
|
2543
|
+
function St(s, e, t) {
|
|
2544
|
+
const r = [], n = be(s, t, (_) => {
|
|
2545
|
+
r.push(_);
|
|
2546
|
+
}), i = new Ct(s, e, t);
|
|
2547
|
+
async function a() {
|
|
2548
|
+
const _ = await s.semaphore.acquire();
|
|
2524
2549
|
try {
|
|
2525
2550
|
for (; r.length; )
|
|
2526
2551
|
await i.processEntry(r.shift());
|
|
2527
2552
|
} finally {
|
|
2528
|
-
|
|
2553
|
+
_();
|
|
2529
2554
|
}
|
|
2530
2555
|
}
|
|
2531
|
-
return
|
|
2532
|
-
|
|
2556
|
+
return s.addEventListener("request.end", a), function() {
|
|
2557
|
+
n(), s.removeEventListener("request.end", a);
|
|
2533
2558
|
};
|
|
2534
2559
|
}
|
|
2535
|
-
class
|
|
2560
|
+
class Ct {
|
|
2536
2561
|
constructor(e, t, r) {
|
|
2537
|
-
this.php = e, this.opfs = t, this.memfsRoot =
|
|
2562
|
+
this.php = e, this.opfs = t, this.memfsRoot = ae(r);
|
|
2538
2563
|
}
|
|
2539
2564
|
toOpfsPath(e) {
|
|
2540
|
-
return
|
|
2565
|
+
return ae(e.substring(this.memfsRoot.length));
|
|
2541
2566
|
}
|
|
2542
2567
|
async processEntry(e) {
|
|
2543
2568
|
if (!e.path.startsWith(this.memfsRoot) || e.path === this.memfsRoot)
|
|
2544
2569
|
return;
|
|
2545
|
-
const t = this.toOpfsPath(e.path), r = await
|
|
2546
|
-
if (
|
|
2570
|
+
const t = this.toOpfsPath(e.path), r = await _e(this.opfs, t), n = ht(t);
|
|
2571
|
+
if (n)
|
|
2547
2572
|
try {
|
|
2548
2573
|
if (e.operation === "DELETE")
|
|
2549
2574
|
try {
|
|
2550
|
-
await r.removeEntry(
|
|
2575
|
+
await r.removeEntry(n, {
|
|
2551
2576
|
recursive: !0
|
|
2552
2577
|
});
|
|
2553
2578
|
} catch {
|
|
2554
2579
|
}
|
|
2555
2580
|
else if (e.operation === "CREATE")
|
|
2556
|
-
e.nodeType === "directory" ? await r.getDirectoryHandle(
|
|
2581
|
+
e.nodeType === "directory" ? await r.getDirectoryHandle(n, {
|
|
2557
2582
|
create: !0
|
|
2558
|
-
}) : await r.getFileHandle(
|
|
2583
|
+
}) : await r.getFileHandle(n, {
|
|
2559
2584
|
create: !0
|
|
2560
2585
|
});
|
|
2561
2586
|
else if (e.operation === "WRITE")
|
|
2562
|
-
await
|
|
2587
|
+
await F(
|
|
2563
2588
|
r,
|
|
2564
|
-
|
|
2565
|
-
this.php[
|
|
2589
|
+
n,
|
|
2590
|
+
this.php[q].FS,
|
|
2566
2591
|
e.path
|
|
2567
2592
|
);
|
|
2568
2593
|
else if (e.operation === "RENAME" && e.toPath.startsWith(this.memfsRoot)) {
|
|
2569
|
-
const i = this.toOpfsPath(e.toPath),
|
|
2594
|
+
const i = this.toOpfsPath(e.toPath), a = await _e(
|
|
2570
2595
|
this.opfs,
|
|
2571
2596
|
i
|
|
2572
|
-
)
|
|
2597
|
+
);
|
|
2573
2598
|
if (e.nodeType === "directory") {
|
|
2574
|
-
const
|
|
2575
|
-
|
|
2599
|
+
const _ = await a.getDirectoryHandle(
|
|
2600
|
+
n,
|
|
2576
2601
|
{
|
|
2577
2602
|
create: !0
|
|
2578
2603
|
}
|
|
2579
2604
|
);
|
|
2580
|
-
await
|
|
2581
|
-
this.php[
|
|
2582
|
-
|
|
2605
|
+
await Te(
|
|
2606
|
+
this.php[q].FS,
|
|
2607
|
+
_,
|
|
2583
2608
|
e.toPath
|
|
2584
|
-
), await r.removeEntry(
|
|
2609
|
+
), await r.removeEntry(n, {
|
|
2585
2610
|
recursive: !0
|
|
2586
2611
|
});
|
|
2587
|
-
} else
|
|
2588
|
-
|
|
2612
|
+
} else {
|
|
2613
|
+
try {
|
|
2614
|
+
await r.removeEntry(n);
|
|
2615
|
+
} catch {
|
|
2616
|
+
}
|
|
2617
|
+
await F(
|
|
2618
|
+
a,
|
|
2619
|
+
Re(i),
|
|
2620
|
+
this.php[q].FS,
|
|
2621
|
+
e.toPath
|
|
2622
|
+
);
|
|
2623
|
+
}
|
|
2589
2624
|
}
|
|
2590
2625
|
} catch (i) {
|
|
2591
|
-
throw
|
|
2626
|
+
throw v.log({ entry: e, name: n }), v.error(i), i;
|
|
2592
2627
|
}
|
|
2593
2628
|
}
|
|
2594
2629
|
}
|
|
2595
|
-
function
|
|
2596
|
-
return
|
|
2630
|
+
function ae(s) {
|
|
2631
|
+
return s.replace(/\/$/, "").replace(/\/\/+/g, "/");
|
|
2597
2632
|
}
|
|
2598
|
-
function
|
|
2599
|
-
return
|
|
2633
|
+
function ht(s) {
|
|
2634
|
+
return s.substring(s.lastIndexOf("/") + 1);
|
|
2600
2635
|
}
|
|
2601
|
-
async function
|
|
2636
|
+
async function _e(s, e) {
|
|
2602
2637
|
const t = e.replace(/^\/+|\/+$/g, "").replace(/\/+/, "/");
|
|
2603
2638
|
if (!t)
|
|
2604
|
-
return
|
|
2639
|
+
return s;
|
|
2605
2640
|
const r = t.split("/");
|
|
2606
|
-
let
|
|
2641
|
+
let n = s;
|
|
2607
2642
|
for (let i = 0; i < r.length - 1; i++) {
|
|
2608
|
-
const
|
|
2609
|
-
|
|
2643
|
+
const a = r[i];
|
|
2644
|
+
n = await n.getDirectoryHandle(a, { create: !0 });
|
|
2610
2645
|
}
|
|
2611
|
-
return
|
|
2646
|
+
return n;
|
|
2612
2647
|
}
|
|
2613
|
-
function
|
|
2614
|
-
let t = 0, r,
|
|
2615
|
-
return function(...
|
|
2616
|
-
|
|
2617
|
-
const
|
|
2648
|
+
function lt(s, e) {
|
|
2649
|
+
let t = 0, r, n;
|
|
2650
|
+
return function(...a) {
|
|
2651
|
+
n = a;
|
|
2652
|
+
const _ = Date.now() - t;
|
|
2618
2653
|
if (r === void 0) {
|
|
2619
|
-
const c = Math.max(0, e -
|
|
2654
|
+
const c = Math.max(0, e - _);
|
|
2620
2655
|
r = setTimeout(() => {
|
|
2621
|
-
r = void 0, t = Date.now(),
|
|
2656
|
+
r = void 0, t = Date.now(), s(...n);
|
|
2622
2657
|
}, c);
|
|
2623
2658
|
}
|
|
2624
2659
|
};
|
|
2625
2660
|
}
|
|
2626
2661
|
export {
|
|
2627
|
-
|
|
2628
|
-
|
|
2629
|
-
|
|
2630
|
-
|
|
2631
|
-
|
|
2632
|
-
|
|
2633
|
-
|
|
2634
|
-
|
|
2635
|
-
|
|
2636
|
-
|
|
2637
|
-
|
|
2662
|
+
yt as certificateToPEM,
|
|
2663
|
+
pt as consumeAPI,
|
|
2664
|
+
Dt as createDirectoryHandleMountHandler,
|
|
2665
|
+
wt as exposeAPI,
|
|
2666
|
+
Qe as fetchWithCorsProxy,
|
|
2667
|
+
Ye as generateCertificate,
|
|
2668
|
+
Be as getPHPLoaderModule,
|
|
2669
|
+
gt as loadWebRuntime,
|
|
2670
|
+
Lt as privateKeyToPEM,
|
|
2671
|
+
Kt as setupPostMessageRelay,
|
|
2672
|
+
It as spawnPHPWorkerThread
|
|
2638
2673
|
};
|
|
2639
2674
|
//# sourceMappingURL=index.js.map
|