@ai-ecoverse/slicc-kernel 1.135.7 → 1.136.1
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/README.md +9 -4
- package/dist/kernel-worker.js +1891 -1728
- package/dist/kernel-worker.js.map +4 -4
- package/dist/node-process-worker.js +2 -1
- package/dist/node-process-worker.js.map +2 -2
- package/dist/node.js +1891 -1728
- package/dist/node.js.map +4 -4
- package/dist/process-worker.js +2 -1
- package/dist/process-worker.js.map +2 -2
- package/dist/types/kernel/net/sealed-anchor.d.ts +9 -0
- package/dist/types/kernel/net/sealed-conn.d.ts +2 -0
- package/dist/types/kernel/net/tls-chain.d.ts +1 -0
- package/dist/types/kernel/net/tls-engine.d.ts +3 -1
- package/dist/types/kernel/net/tls-uplink.d.ts +1 -0
- package/dist/types/kernel/sealed-session.d.ts +24 -0
- package/dist/types/kernel/sealed.d.ts +3 -1
- package/dist/types/process/js/js-net.d.ts +1 -0
- package/package.json +3 -3
package/dist/kernel-worker.js
CHANGED
|
@@ -7098,7 +7098,7 @@ function satisfies(version, range2) {
|
|
|
7098
7098
|
}
|
|
7099
7099
|
|
|
7100
7100
|
// src/version.ts
|
|
7101
|
-
var KERNEL_VERSION = true ? "1.
|
|
7101
|
+
var KERNEL_VERSION = true ? "1.136.1" : "0.0.0-dev";
|
|
7102
7102
|
var OS_RELEASE = "6.0.0-slicc";
|
|
7103
7103
|
function procVersion() {
|
|
7104
7104
|
return `Linux version ${OS_RELEASE} (slicc-kernel ${KERNEL_VERSION}) #1 SMP PREEMPT_DYNAMIC
|
|
@@ -11655,8 +11655,8 @@ var MountFs = class _MountFs {
|
|
|
11655
11655
|
}
|
|
11656
11656
|
async across(from, to, redirects) {
|
|
11657
11657
|
const moved2 = [await this.through(from), await this.through(to)];
|
|
11658
|
-
const
|
|
11659
|
-
if (
|
|
11658
|
+
const same3 = moved2[0] === normalizePath(from) && moved2[1] === normalizePath(to);
|
|
11659
|
+
if (same3 || redirects >= MAX_LINKS7) throw errnoError("EXDEV", `${from} -> ${to}`);
|
|
11660
11660
|
return moved2;
|
|
11661
11661
|
}
|
|
11662
11662
|
async based(paths, redirects, run2, again) {
|
|
@@ -15356,27 +15356,27 @@ function name(dn) {
|
|
|
15356
15356
|
function extension(id2, critical, value2) {
|
|
15357
15357
|
return critical ? seq(oid(id2), TRUE, octets(value2)) : seq(oid(id2), octets(value2));
|
|
15358
15358
|
}
|
|
15359
|
-
function children(
|
|
15359
|
+
function children(der2) {
|
|
15360
15360
|
const out = [];
|
|
15361
|
-
const [, bodyStart, bodyEnd] = header(
|
|
15361
|
+
const [, bodyStart, bodyEnd] = header(der2, 0);
|
|
15362
15362
|
for (let at = bodyStart; at < bodyEnd; ) {
|
|
15363
|
-
const [, , end] = header(
|
|
15364
|
-
out.push(
|
|
15363
|
+
const [, , end] = header(der2, at);
|
|
15364
|
+
out.push(der2.subarray(at, end));
|
|
15365
15365
|
at = end;
|
|
15366
15366
|
}
|
|
15367
15367
|
return out;
|
|
15368
15368
|
}
|
|
15369
|
-
function header(
|
|
15370
|
-
const tag =
|
|
15371
|
-
let len =
|
|
15369
|
+
function header(der2, at) {
|
|
15370
|
+
const tag = der2[at];
|
|
15371
|
+
let len = der2[at + 1];
|
|
15372
15372
|
let start2 = at + 2;
|
|
15373
15373
|
if (len & 128) {
|
|
15374
15374
|
const count2 = len & 127;
|
|
15375
15375
|
len = 0;
|
|
15376
|
-
for (let i = 0; i < count2; i++) len = len * 256 +
|
|
15376
|
+
for (let i = 0; i < count2; i++) len = len * 256 + der2[start2 + i];
|
|
15377
15377
|
start2 += count2;
|
|
15378
15378
|
}
|
|
15379
|
-
if (start2 + len >
|
|
15379
|
+
if (start2 + len > der2.length) throw new Error("truncated DER");
|
|
15380
15380
|
return [tag, start2, start2 + len];
|
|
15381
15381
|
}
|
|
15382
15382
|
function contents(element) {
|
|
@@ -15465,12 +15465,12 @@ async function certificate(req) {
|
|
|
15465
15465
|
const signature = ecdsaDer(await req.sign(tbs));
|
|
15466
15466
|
return seq(tbs, ECDSA_SHA256, bits(signature));
|
|
15467
15467
|
}
|
|
15468
|
-
function pem(
|
|
15469
|
-
let
|
|
15470
|
-
for (let i = 0; i <
|
|
15471
|
-
|
|
15468
|
+
function pem(der2) {
|
|
15469
|
+
let b642 = "";
|
|
15470
|
+
for (let i = 0; i < der2.length; i += 32768) {
|
|
15471
|
+
b642 += String.fromCharCode(...der2.subarray(i, i + 32768));
|
|
15472
15472
|
}
|
|
15473
|
-
const lines2 = btoa(
|
|
15473
|
+
const lines2 = btoa(b642).match(/.{1,64}/g) ?? [];
|
|
15474
15474
|
return `-----BEGIN CERTIFICATE-----
|
|
15475
15475
|
${lines2.join("\n")}
|
|
15476
15476
|
-----END CERTIFICATE-----
|
|
@@ -15719,6 +15719,32 @@ var TlsEngine = class {
|
|
|
15719
15719
|
this.m._free(name2);
|
|
15720
15720
|
}
|
|
15721
15721
|
}
|
|
15722
|
+
get chainVerify() {
|
|
15723
|
+
return typeof this.m._tls_chain_verify === "function";
|
|
15724
|
+
}
|
|
15725
|
+
chainFlags(store, chain2, hostname) {
|
|
15726
|
+
const verify = this.m._tls_chain_verify;
|
|
15727
|
+
if (!verify || chain2.length === 0) return void 0;
|
|
15728
|
+
const joined4 = new Uint8Array(chain2.reduce((n, c) => n + c.length, 0));
|
|
15729
|
+
let at = 0;
|
|
15730
|
+
for (const der2 of chain2) {
|
|
15731
|
+
joined4.set(der2, at);
|
|
15732
|
+
at += der2.length;
|
|
15733
|
+
}
|
|
15734
|
+
const name2 = this.put(new TextEncoder().encode(hostname));
|
|
15735
|
+
try {
|
|
15736
|
+
return this.withBytes(joined4, (p) => {
|
|
15737
|
+
const out = this.scratch;
|
|
15738
|
+
this.m.HEAPU8.fill(255, out, out + 4);
|
|
15739
|
+
const ret = verify(store.ptr, p, joined4.length, name2, out);
|
|
15740
|
+
const flags2 = new DataView(this.m.HEAPU8.buffer, out, 4).getUint32(0, true);
|
|
15741
|
+
if (ret === 0) return flags2 === 0 ? 0 : void 0;
|
|
15742
|
+
return ret === 1 && flags2 !== 0 ? flags2 : void 0;
|
|
15743
|
+
});
|
|
15744
|
+
} finally {
|
|
15745
|
+
this.m._free(name2);
|
|
15746
|
+
}
|
|
15747
|
+
}
|
|
15722
15748
|
verifyInfo(flags2) {
|
|
15723
15749
|
const m = this.clientModule();
|
|
15724
15750
|
const n = m._tls_verify_info(flags2, this.scratch, SCRATCH);
|
|
@@ -15747,8 +15773,8 @@ var TlsStore = class {
|
|
|
15747
15773
|
this.m = m;
|
|
15748
15774
|
this.ptr = ptr;
|
|
15749
15775
|
}
|
|
15750
|
-
add(
|
|
15751
|
-
const ret = this.engine.withBytes(
|
|
15776
|
+
add(der2) {
|
|
15777
|
+
const ret = this.engine.withBytes(der2, (p) => this.m._tls_ca_add_der(this.ptr, p, der2.length));
|
|
15752
15778
|
if (ret !== 0) throw this.engine.error(ret, "trust store certificate");
|
|
15753
15779
|
}
|
|
15754
15780
|
addBundle(bytes) {
|
|
@@ -15777,10 +15803,10 @@ var TlsLeaf = class {
|
|
|
15777
15803
|
if (typeof out === "number") throw this.engine.error(out, "leaf public key");
|
|
15778
15804
|
return out;
|
|
15779
15805
|
}
|
|
15780
|
-
addCert(
|
|
15806
|
+
addCert(der2) {
|
|
15781
15807
|
const ret = this.engine.withBytes(
|
|
15782
|
-
|
|
15783
|
-
(ptr) => this.m._tls_leaf_add_cert(this.ptr, ptr,
|
|
15808
|
+
der2,
|
|
15809
|
+
(ptr) => this.m._tls_leaf_add_cert(this.ptr, ptr, der2.length)
|
|
15784
15810
|
);
|
|
15785
15811
|
if (ret !== 0) throw this.engine.error(ret, "leaf certificate");
|
|
15786
15812
|
}
|
|
@@ -15873,8 +15899,8 @@ var TlsSession = class {
|
|
|
15873
15899
|
const chain2 = [];
|
|
15874
15900
|
const count2 = this.c._tls_peer_count(this.ptr);
|
|
15875
15901
|
for (let i = 0; i < count2; i++) {
|
|
15876
|
-
const
|
|
15877
|
-
if (
|
|
15902
|
+
const der2 = this.engine.intoScratch((p, max) => this.c._tls_peer_der(this.ptr, i, p, max));
|
|
15903
|
+
if (der2 instanceof Uint8Array) chain2.push(der2);
|
|
15878
15904
|
}
|
|
15879
15905
|
return chain2;
|
|
15880
15906
|
}
|
|
@@ -17929,6 +17955,30 @@ var TARGET = /^[\x21-\x7e]+$/;
|
|
|
17929
17955
|
var SESSION_EXIT = /^(tailscale|device:[A-Za-z0-9._:-]+)$/;
|
|
17930
17956
|
var HOST = /^[a-z0-9.:-]+$/;
|
|
17931
17957
|
var UNSAFE = /[\r\n\0]/;
|
|
17958
|
+
var ANCHOR_ID = /^[A-Za-z0-9+/]{43}=$/;
|
|
17959
|
+
function verifiedByOk(f) {
|
|
17960
|
+
if (f.verifiedBy === void 0 || f.verifiedBy === "roots") return f.anchor === void 0;
|
|
17961
|
+
return f.verifiedBy === "anchored" && typeof f.anchor === "string" && ANCHOR_ID.test(f.anchor);
|
|
17962
|
+
}
|
|
17963
|
+
function anchorsAskable(f) {
|
|
17964
|
+
if (!Object.hasOwn(POSITIONS, f.protocol)) return false;
|
|
17965
|
+
if (typeof f.session !== "string" || !SESSION_ID.test(f.session) || !hostOk(f.host)) return false;
|
|
17966
|
+
if (!Number.isInteger(f.port) || f.port < 1 || f.port > 65535) return false;
|
|
17967
|
+
return typeof f.exit === "string" && SESSION_EXIT.test(f.exit);
|
|
17968
|
+
}
|
|
17969
|
+
function anchorsRequest(f) {
|
|
17970
|
+
return {
|
|
17971
|
+
v: 1,
|
|
17972
|
+
op: "sessionAnchors",
|
|
17973
|
+
caller: f.stamp,
|
|
17974
|
+
stamp: f.stamp,
|
|
17975
|
+
session: f.session,
|
|
17976
|
+
host: f.host,
|
|
17977
|
+
port: f.port,
|
|
17978
|
+
protocol: f.protocol,
|
|
17979
|
+
exit: f.exit
|
|
17980
|
+
};
|
|
17981
|
+
}
|
|
17932
17982
|
var POSITIONS = {
|
|
17933
17983
|
http1: (position) => HEADER.test(position),
|
|
17934
17984
|
smtp: (position) => position === "auth-plain" || position === "auth-login",
|
|
@@ -17967,7 +18017,8 @@ function sessionAskable(f, now) {
|
|
|
17967
18017
|
if (!Number.isInteger(f.port) || f.port < 1 || f.port > 65535) return false;
|
|
17968
18018
|
const age = now - f.handshakeAt;
|
|
17969
18019
|
if (!Number.isFinite(age) || age < 0 || age > SESSION_WINDOW_MS) return false;
|
|
17970
|
-
|
|
18020
|
+
const exitOk = typeof f.exit === "string" && SESSION_EXIT.test(f.exit);
|
|
18021
|
+
return exitOk && scramOk(f) && verifiedByOk(f) && headOk(f);
|
|
17971
18022
|
}
|
|
17972
18023
|
function sessionRequest(f) {
|
|
17973
18024
|
return {
|
|
@@ -17981,6 +18032,8 @@ function sessionRequest(f) {
|
|
|
17981
18032
|
protocol: f.protocol,
|
|
17982
18033
|
position: f.position,
|
|
17983
18034
|
verified: true,
|
|
18035
|
+
verifiedBy: f.verifiedBy ?? "roots",
|
|
18036
|
+
...f.verifiedBy === "anchored" ? { anchor: f.anchor } : {},
|
|
17984
18037
|
handshakeAt: f.handshakeAt,
|
|
17985
18038
|
exit: f.exit,
|
|
17986
18039
|
...f.placeholders ? { placeholders: [...f.placeholders] } : {},
|
|
@@ -18009,1852 +18062,1951 @@ function sessionValues(reply, asked) {
|
|
|
18009
18062
|
return Object.keys(out).length > 0 ? out : void 0;
|
|
18010
18063
|
}
|
|
18011
18064
|
|
|
18012
|
-
//
|
|
18013
|
-
var
|
|
18014
|
-
|
|
18015
|
-
|
|
18016
|
-
|
|
18017
|
-
|
|
18018
|
-
|
|
18019
|
-
|
|
18065
|
+
// src/kernel/net/tls-ciphers.ts
|
|
18066
|
+
var SUITES = [
|
|
18067
|
+
[4865, "TLS_AES_128_GCM_SHA256", "TLS_AES_128_GCM_SHA256", "TLSv1.3"],
|
|
18068
|
+
[4866, "TLS_AES_256_GCM_SHA384", "TLS_AES_256_GCM_SHA384", "TLSv1.3"],
|
|
18069
|
+
[4867, "TLS_CHACHA20_POLY1305_SHA256", "TLS_CHACHA20_POLY1305_SHA256", "TLSv1.3"],
|
|
18070
|
+
[4868, "TLS_AES_128_CCM_SHA256", "TLS_AES_128_CCM_SHA256", "TLSv1.3"],
|
|
18071
|
+
[4869, "TLS_AES_128_CCM_8_SHA256", "TLS_AES_128_CCM_8_SHA256", "TLSv1.3"],
|
|
18072
|
+
[49195, "ECDHE-ECDSA-AES128-GCM-SHA256", "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256", "TLSv1.2"],
|
|
18073
|
+
[49196, "ECDHE-ECDSA-AES256-GCM-SHA384", "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384", "TLSv1.2"],
|
|
18074
|
+
[49199, "ECDHE-RSA-AES128-GCM-SHA256", "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256", "TLSv1.2"],
|
|
18075
|
+
[49200, "ECDHE-RSA-AES256-GCM-SHA384", "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384", "TLSv1.2"],
|
|
18076
|
+
[52392, "ECDHE-RSA-CHACHA20-POLY1305", "TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256", "TLSv1.2"],
|
|
18077
|
+
[
|
|
18078
|
+
52393,
|
|
18079
|
+
"ECDHE-ECDSA-CHACHA20-POLY1305",
|
|
18080
|
+
"TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256",
|
|
18081
|
+
"TLSv1.2"
|
|
18082
|
+
],
|
|
18083
|
+
[49187, "ECDHE-ECDSA-AES128-SHA256", "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256", "TLSv1.2"],
|
|
18084
|
+
[49188, "ECDHE-ECDSA-AES256-SHA384", "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384", "TLSv1.2"],
|
|
18085
|
+
[49191, "ECDHE-RSA-AES128-SHA256", "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256", "TLSv1.2"],
|
|
18086
|
+
[49192, "ECDHE-RSA-AES256-SHA384", "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384", "TLSv1.2"],
|
|
18087
|
+
[49161, "ECDHE-ECDSA-AES128-SHA", "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA", "TLSv1.0"],
|
|
18088
|
+
[49162, "ECDHE-ECDSA-AES256-SHA", "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA", "TLSv1.0"],
|
|
18089
|
+
[49171, "ECDHE-RSA-AES128-SHA", "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA", "TLSv1.0"],
|
|
18090
|
+
[49172, "ECDHE-RSA-AES256-SHA", "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA", "TLSv1.0"],
|
|
18091
|
+
[156, "AES128-GCM-SHA256", "TLS_RSA_WITH_AES_128_GCM_SHA256", "TLSv1.2"],
|
|
18092
|
+
[157, "AES256-GCM-SHA384", "TLS_RSA_WITH_AES_256_GCM_SHA384", "TLSv1.2"],
|
|
18093
|
+
[158, "DHE-RSA-AES128-GCM-SHA256", "TLS_DHE_RSA_WITH_AES_128_GCM_SHA256", "TLSv1.2"],
|
|
18094
|
+
[159, "DHE-RSA-AES256-GCM-SHA384", "TLS_DHE_RSA_WITH_AES_256_GCM_SHA384", "TLSv1.2"]
|
|
18095
|
+
];
|
|
18096
|
+
function cipherOf(id2, protocol) {
|
|
18097
|
+
const known = SUITES.find(([n]) => n === id2);
|
|
18098
|
+
const hex4 = `0x${id2.toString(16).padStart(4, "0").toUpperCase()}`;
|
|
18099
|
+
return {
|
|
18100
|
+
name: known?.[1] ?? hex4,
|
|
18101
|
+
standardName: known?.[2] ?? hex4,
|
|
18102
|
+
version: known?.[3] ?? protocol
|
|
18103
|
+
};
|
|
18020
18104
|
}
|
|
18021
|
-
|
|
18022
|
-
|
|
18023
|
-
|
|
18024
|
-
|
|
18025
|
-
|
|
18026
|
-
|
|
18027
|
-
|
|
18028
|
-
|
|
18029
|
-
|
|
18030
|
-
|
|
18031
|
-
|
|
18032
|
-
|
|
18033
|
-
|
|
18105
|
+
|
|
18106
|
+
// src/kernel/net/tls-client.ts
|
|
18107
|
+
var WRITE_CHUNK = 16 * 1024;
|
|
18108
|
+
var BADCERT = [
|
|
18109
|
+
[8, "UNABLE_TO_GET_ISSUER_CERT_LOCALLY"],
|
|
18110
|
+
[1, "CERT_HAS_EXPIRED"],
|
|
18111
|
+
[512, "CERT_NOT_YET_VALID"],
|
|
18112
|
+
[2, "CERT_REVOKED"],
|
|
18113
|
+
[4, "ERR_TLS_CERT_ALTNAME_INVALID"],
|
|
18114
|
+
[2048, "INVALID_PURPOSE"],
|
|
18115
|
+
[4096, "INVALID_PURPOSE"]
|
|
18116
|
+
];
|
|
18117
|
+
function verifyCode(flags2) {
|
|
18118
|
+
if (flags2 === 0) return void 0;
|
|
18119
|
+
if (flags2 === -1) return "UNABLE_TO_VERIFY_LEAF_SIGNATURE";
|
|
18120
|
+
return BADCERT.find(([bit]) => (flags2 & bit) !== 0)?.[1] ?? "UNABLE_TO_VERIFY_LEAF_SIGNATURE";
|
|
18034
18121
|
}
|
|
18035
|
-
function
|
|
18036
|
-
return
|
|
18122
|
+
function isIP(name2) {
|
|
18123
|
+
return ipv4Bytes(name2) !== void 0 || name2.includes(":") && ipv6Groups(name2) !== void 0;
|
|
18037
18124
|
}
|
|
18038
|
-
function
|
|
18039
|
-
|
|
18040
|
-
for (const byte of bytes) out += byte.toString(16).padStart(2, "0");
|
|
18041
|
-
return out;
|
|
18125
|
+
function clientFlags(o) {
|
|
18126
|
+
return (o.insecure ? TLS_CLIENT_INSECURE_SKIP_VERIFY : 0) | (o.sni === false ? TLS_CLIENT_NO_SNI : 0) | (o.checkHostname === false ? TLS_CLIENT_VERIFY_CHAIN_ONLY : 0);
|
|
18042
18127
|
}
|
|
18043
|
-
function
|
|
18044
|
-
|
|
18045
|
-
shifted.set(bytes, offset);
|
|
18046
|
-
const encoded = base642(shifted);
|
|
18047
|
-
const first = Math.ceil(8 * offset / 6);
|
|
18048
|
-
const last = Math.floor(8 * (offset + bytes.length) / 6);
|
|
18049
|
-
return encoded.slice(first, last);
|
|
18128
|
+
function openSession(o) {
|
|
18129
|
+
return o.engine.clientSession(o.store, o.servername, o.alpn, clientFlags(o));
|
|
18050
18130
|
}
|
|
18051
|
-
|
|
18052
|
-
|
|
18053
|
-
|
|
18054
|
-
|
|
18055
|
-
|
|
18056
|
-
|
|
18057
|
-
|
|
18058
|
-
|
|
18059
|
-
out += `\\u${upper ? code.toUpperCase() : code}`;
|
|
18060
|
-
} else out += value2[i];
|
|
18131
|
+
var Ciphertext = class {
|
|
18132
|
+
queue = [];
|
|
18133
|
+
ended = false;
|
|
18134
|
+
conn;
|
|
18135
|
+
session;
|
|
18136
|
+
constructor(conn, session) {
|
|
18137
|
+
this.conn = conn;
|
|
18138
|
+
this.session = session;
|
|
18061
18139
|
}
|
|
18062
|
-
|
|
18063
|
-
|
|
18064
|
-
function percent(value2) {
|
|
18065
|
-
let component;
|
|
18066
|
-
try {
|
|
18067
|
-
component = encodeURIComponent(value2);
|
|
18068
|
-
} catch {
|
|
18069
|
-
return [];
|
|
18140
|
+
hand(bytes) {
|
|
18141
|
+
if (bytes.length > 0) this.queue.push(bytes);
|
|
18070
18142
|
}
|
|
18071
|
-
|
|
18072
|
-
|
|
18073
|
-
|
|
18074
|
-
|
|
18075
|
-
|
|
18076
|
-
|
|
18077
|
-
|
|
18078
|
-
|
|
18143
|
+
async more() {
|
|
18144
|
+
if (this.queue.length === 0 && !this.ended) {
|
|
18145
|
+
const bytes = await this.conn.read();
|
|
18146
|
+
if (bytes) this.queue.push(bytes);
|
|
18147
|
+
else this.ended = true;
|
|
18148
|
+
}
|
|
18149
|
+
if (this.queue.length === 0) {
|
|
18150
|
+
this.session.feedEnd();
|
|
18151
|
+
return false;
|
|
18152
|
+
}
|
|
18153
|
+
while (this.queue.length > 0) {
|
|
18154
|
+
const head = this.queue[0];
|
|
18155
|
+
const n = this.session.feed(head);
|
|
18156
|
+
if (n < head.length) {
|
|
18157
|
+
this.queue[0] = head.subarray(n);
|
|
18158
|
+
break;
|
|
18159
|
+
}
|
|
18160
|
+
this.queue.shift();
|
|
18161
|
+
}
|
|
18162
|
+
return true;
|
|
18163
|
+
}
|
|
18164
|
+
};
|
|
18165
|
+
async function send(conn, session) {
|
|
18166
|
+
for (; ; ) {
|
|
18167
|
+
const out = session.take();
|
|
18168
|
+
if (out.length === 0) return;
|
|
18169
|
+
for (let at = 0; at < out.length; ) {
|
|
18170
|
+
const n = await conn.write(out.subarray(at));
|
|
18171
|
+
if (!(n > 0)) throw new KernelError("EPIPE");
|
|
18172
|
+
at += n;
|
|
18173
|
+
}
|
|
18079
18174
|
}
|
|
18080
|
-
return [component, lower, plus, form];
|
|
18081
18175
|
}
|
|
18082
|
-
function
|
|
18083
|
-
|
|
18176
|
+
function refused2(engine, session, err) {
|
|
18177
|
+
const flags2 = session.verifyResult;
|
|
18178
|
+
const code = verifyCode(flags2);
|
|
18179
|
+
if (code && flags2 !== -1)
|
|
18180
|
+
return new KernelError("EPROTO", `${code}: ${engine.verifyInfo(flags2).trim()}`);
|
|
18181
|
+
const text = err instanceof TlsError ? err.message : String(err);
|
|
18182
|
+
return new KernelError("EPROTO", `ERR_SSL_HANDSHAKE_FAILURE: ${text}${alertOf(session)}`);
|
|
18084
18183
|
}
|
|
18085
|
-
function
|
|
18086
|
-
const
|
|
18087
|
-
|
|
18088
|
-
const run2 = embedded(bytes, offset);
|
|
18089
|
-
if (run2.length >= MIN_BASE64) standard.push(run2);
|
|
18090
|
-
}
|
|
18091
|
-
return [...standard, ...standard.map(urlSafe)];
|
|
18184
|
+
function alertOf(session) {
|
|
18185
|
+
const alert = session.lastAlert;
|
|
18186
|
+
return alert >= 0 ? ` (alert ${alert})` : "";
|
|
18092
18187
|
}
|
|
18093
|
-
function
|
|
18094
|
-
|
|
18095
|
-
|
|
18096
|
-
|
|
18097
|
-
|
|
18098
|
-
|
|
18099
|
-
|
|
18100
|
-
|
|
18101
|
-
|
|
18102
|
-
|
|
18103
|
-
|
|
18104
|
-
|
|
18105
|
-
|
|
18106
|
-
|
|
18107
|
-
|
|
18108
|
-
|
|
18109
|
-
|
|
18110
|
-
unicode(value2, false),
|
|
18111
|
-
unicode(value2, true)
|
|
18112
|
-
]) {
|
|
18113
|
-
add(text, "json");
|
|
18188
|
+
async function handshake(conn, o, session, inbox) {
|
|
18189
|
+
for (; ; ) {
|
|
18190
|
+
let done5;
|
|
18191
|
+
try {
|
|
18192
|
+
done5 = session.handshake();
|
|
18193
|
+
} catch (err) {
|
|
18194
|
+
await send(conn, session).catch(() => void 0);
|
|
18195
|
+
throw refused2(o.engine, session, err);
|
|
18196
|
+
}
|
|
18197
|
+
await send(conn, session);
|
|
18198
|
+
if (done5) return;
|
|
18199
|
+
if (!await inbox.more()) {
|
|
18200
|
+
throw new KernelError(
|
|
18201
|
+
"ECONNRESET",
|
|
18202
|
+
"the server closed the connection during the TLS handshake"
|
|
18203
|
+
);
|
|
18204
|
+
}
|
|
18114
18205
|
}
|
|
18115
|
-
for (const text of percent(value2)) add(text, "percent");
|
|
18116
|
-
for (const text of [html(value2, "'"), html(value2, "'")]) add(text, "html");
|
|
18117
|
-
for (const text of encodings(raw2)) add(text, "base64");
|
|
18118
|
-
add(hex2(raw2), "hex");
|
|
18119
|
-
add(hex2(raw2).toUpperCase(), "hex");
|
|
18120
|
-
return out;
|
|
18121
18206
|
}
|
|
18122
|
-
function
|
|
18123
|
-
|
|
18207
|
+
function insecureOf(session, chain2, shape) {
|
|
18208
|
+
const flags2 = session.verifyResult;
|
|
18209
|
+
const error = chainError(flags2, chain2, shape);
|
|
18210
|
+
return { hostnameMatches: nameMatches(flags2), ...error ? { chainError: error } : {} };
|
|
18124
18211
|
}
|
|
18125
|
-
|
|
18126
|
-
|
|
18127
|
-
|
|
18128
|
-
|
|
18129
|
-
|
|
18130
|
-
|
|
18131
|
-
|
|
18132
|
-
|
|
18133
|
-
|
|
18134
|
-
|
|
18135
|
-
|
|
18136
|
-
|
|
18137
|
-
|
|
18138
|
-
|
|
18139
|
-
|
|
18140
|
-
|
|
18141
|
-
|
|
18142
|
-
|
|
18143
|
-
|
|
18144
|
-
|
|
18145
|
-
|
|
18146
|
-
|
|
18147
|
-
|
|
18148
|
-
|
|
18149
|
-
|
|
18150
|
-
|
|
18151
|
-
|
|
18152
|
-
|
|
18153
|
-
|
|
18154
|
-
|
|
18155
|
-
|
|
18156
|
-
|
|
18157
|
-
|
|
18158
|
-
|
|
18159
|
-
|
|
18160
|
-
|
|
18161
|
-
|
|
18162
|
-
|
|
18163
|
-
|
|
18164
|
-
|
|
18165
|
-
|
|
18166
|
-
|
|
18167
|
-
|
|
18168
|
-
|
|
18169
|
-
|
|
18170
|
-
|
|
18171
|
-
|
|
18172
|
-
|
|
18173
|
-
|
|
18174
|
-
|
|
18212
|
+
function controlsOf(o, session, protocol, chain2, shape) {
|
|
18213
|
+
if (!o.engine.sessionControls) return {};
|
|
18214
|
+
const checked = o.checkHostname !== false && !o.insecure;
|
|
18215
|
+
return {
|
|
18216
|
+
cipher: cipherOf(session.ciphersuite, protocol),
|
|
18217
|
+
clientCertificate: o.clientCertificate === true,
|
|
18218
|
+
sni: o.sni !== false && !isIP(o.servername),
|
|
18219
|
+
hostnameChecked: checked,
|
|
18220
|
+
...o.insecure ? insecureOf(session, chain2, shape) : { hostnameMatches: checked || !session.nameMismatch }
|
|
18221
|
+
};
|
|
18222
|
+
}
|
|
18223
|
+
function verdictOf(o, session) {
|
|
18224
|
+
if (o.bundled !== true || isIP(o.servername) || session.verifyResult !== 0) return false;
|
|
18225
|
+
return o.checkHostname !== false || !session.nameMismatch;
|
|
18226
|
+
}
|
|
18227
|
+
async function infoOf(o, session) {
|
|
18228
|
+
const flags2 = session.verifyResult;
|
|
18229
|
+
const code = verifyCode(flags2);
|
|
18230
|
+
const protocol = session.version === 772 ? "TLSv1.3" : "TLSv1.2";
|
|
18231
|
+
const chain2 = session.peerChain();
|
|
18232
|
+
const shape = await chainShape(o.insecure ? chain2 : []);
|
|
18233
|
+
return {
|
|
18234
|
+
protocol,
|
|
18235
|
+
alpnProtocol: session.alpn ?? false,
|
|
18236
|
+
authorized: code === void 0,
|
|
18237
|
+
...code ? { authorizationError: code, authorizationText: o.engine.verifyInfo(flags2).trim() } : {},
|
|
18238
|
+
peerCertificates: chain2,
|
|
18239
|
+
...controlsOf(o, session, protocol, chain2, shape),
|
|
18240
|
+
verified: verdictOf(o, session),
|
|
18241
|
+
handshakeAt: Date.now()
|
|
18242
|
+
};
|
|
18243
|
+
}
|
|
18244
|
+
var FATAL_ALERT = -30592;
|
|
18245
|
+
function alerted(err, session) {
|
|
18246
|
+
if (err.code === FATAL_ALERT)
|
|
18247
|
+
return new KernelError(
|
|
18248
|
+
"EPROTO",
|
|
18249
|
+
`ERR_SSL_FATAL_ALERT: the server ended the session: ${err.message}${alertOf(session)}`
|
|
18250
|
+
);
|
|
18251
|
+
return new KernelError("EPROTO", `ERR_SSL_PROTOCOL_ERROR: ${err.message}`);
|
|
18252
|
+
}
|
|
18253
|
+
function plaintext(conn, session, inbox) {
|
|
18254
|
+
let freed = false;
|
|
18255
|
+
let writeClosed = false;
|
|
18256
|
+
const free = () => {
|
|
18257
|
+
if (freed) return;
|
|
18258
|
+
freed = true;
|
|
18259
|
+
session.free();
|
|
18260
|
+
};
|
|
18261
|
+
return {
|
|
18262
|
+
localAddr: conn.localAddr,
|
|
18263
|
+
remoteAddr: conn.remoteAddr,
|
|
18264
|
+
async read() {
|
|
18265
|
+
for (; ; ) {
|
|
18266
|
+
if (freed) return null;
|
|
18267
|
+
let got;
|
|
18268
|
+
try {
|
|
18269
|
+
got = session.read();
|
|
18270
|
+
} catch (err) {
|
|
18271
|
+
throw alerted(err, session);
|
|
18175
18272
|
}
|
|
18176
|
-
|
|
18177
|
-
|
|
18273
|
+
await send(conn, session);
|
|
18274
|
+
if (got instanceof Uint8Array) return got;
|
|
18275
|
+
if (got === "eof") return null;
|
|
18276
|
+
await inbox.more();
|
|
18178
18277
|
}
|
|
18278
|
+
},
|
|
18279
|
+
async write(bytes) {
|
|
18280
|
+
if (freed) throw new KernelError("EPIPE");
|
|
18281
|
+
for (; ; ) {
|
|
18282
|
+
const n = session.write(bytes.subarray(0, WRITE_CHUNK));
|
|
18283
|
+
await send(conn, session);
|
|
18284
|
+
if (n > 0) return n;
|
|
18285
|
+
}
|
|
18286
|
+
},
|
|
18287
|
+
closeWrite() {
|
|
18288
|
+
if (writeClosed || freed) return;
|
|
18289
|
+
writeClosed = true;
|
|
18290
|
+
session.close();
|
|
18291
|
+
void send(conn, session).catch(() => void 0).finally(() => conn.closeWrite());
|
|
18292
|
+
},
|
|
18293
|
+
close() {
|
|
18294
|
+
free();
|
|
18295
|
+
conn.close();
|
|
18179
18296
|
}
|
|
18297
|
+
};
|
|
18298
|
+
}
|
|
18299
|
+
async function tlsClient(conn, o, taken = new Uint8Array(0)) {
|
|
18300
|
+
const session = o.session ?? openSession(o);
|
|
18301
|
+
const inbox = new Ciphertext(conn, session);
|
|
18302
|
+
inbox.hand(taken);
|
|
18303
|
+
try {
|
|
18304
|
+
await handshake(conn, o, session, inbox);
|
|
18305
|
+
const info = await infoOf(o, session);
|
|
18306
|
+
return { conn: plaintext(conn, session, inbox), info };
|
|
18307
|
+
} catch (err) {
|
|
18308
|
+
session.free();
|
|
18309
|
+
throw err;
|
|
18180
18310
|
}
|
|
18181
|
-
|
|
18182
|
-
|
|
18183
|
-
|
|
18184
|
-
|
|
18185
|
-
|
|
18186
|
-
|
|
18187
|
-
|
|
18188
|
-
|
|
18189
|
-
|
|
18190
|
-
|
|
18191
|
-
|
|
18192
|
-
|
|
18193
|
-
|
|
18311
|
+
}
|
|
18312
|
+
|
|
18313
|
+
// src/kernel/net/tls-chain.ts
|
|
18314
|
+
var CN_MISMATCH = 4;
|
|
18315
|
+
var NOT_TRUSTED = 8;
|
|
18316
|
+
function tlv2(der2, at) {
|
|
18317
|
+
if (at + 2 > der2.length) return void 0;
|
|
18318
|
+
const first = der2[at + 1];
|
|
18319
|
+
let body = at + 2;
|
|
18320
|
+
let length2 = first;
|
|
18321
|
+
if (first & 128) {
|
|
18322
|
+
const n = first & 127;
|
|
18323
|
+
if (n === 0 || n > 4 || body + n > der2.length) return void 0;
|
|
18324
|
+
length2 = 0;
|
|
18325
|
+
for (let i = 0; i < n; i++) length2 = length2 * 256 + der2[body + i];
|
|
18326
|
+
body += n;
|
|
18194
18327
|
}
|
|
18195
|
-
|
|
18196
|
-
|
|
18197
|
-
|
|
18198
|
-
|
|
18328
|
+
const end = body + length2;
|
|
18329
|
+
return end > der2.length ? void 0 : { start: at, body, end };
|
|
18330
|
+
}
|
|
18331
|
+
function children2(der2, outer, max) {
|
|
18332
|
+
const fields = [];
|
|
18333
|
+
for (let at = outer.body; at < outer.end && fields.length < max; ) {
|
|
18334
|
+
const field4 = tlv2(der2, at);
|
|
18335
|
+
if (!field4) return void 0;
|
|
18336
|
+
fields.push(field4);
|
|
18337
|
+
at = field4.end;
|
|
18199
18338
|
}
|
|
18339
|
+
return fields;
|
|
18340
|
+
}
|
|
18341
|
+
function tbsFields(der2) {
|
|
18342
|
+
const outer = tlv2(der2, 0);
|
|
18343
|
+
const cert = outer && children2(der2, outer, 3);
|
|
18344
|
+
const tbs = cert?.[0] && children2(der2, cert[0], 8);
|
|
18345
|
+
if (!cert || !tbs) return void 0;
|
|
18346
|
+
return { cert, tbs: der2[tbs[0]?.start ?? 0] === 160 ? tbs.slice(1) : tbs };
|
|
18347
|
+
}
|
|
18348
|
+
var raw = (der2, t) => der2.subarray(t.start, t.end);
|
|
18349
|
+
function spkiOf(der2) {
|
|
18350
|
+
const spki = tbsFields(der2)?.tbs[5];
|
|
18351
|
+
return spki ? raw(der2, spki) : void 0;
|
|
18352
|
+
}
|
|
18353
|
+
function names(der2) {
|
|
18354
|
+
const fields = tbsFields(der2)?.tbs;
|
|
18355
|
+
const [, , issuer, , subject] = fields ?? [];
|
|
18356
|
+
if (!issuer || !subject) return void 0;
|
|
18357
|
+
return [raw(der2, issuer), raw(der2, subject)];
|
|
18358
|
+
}
|
|
18359
|
+
var hex2 = (bytes) => Array.from(bytes, (b) => b.toString(16).padStart(2, "0")).join("");
|
|
18360
|
+
var HASHES = {
|
|
18361
|
+
"2a864886f70d01010b": ["RSASSA-PKCS1-v1_5", "SHA-256"],
|
|
18362
|
+
"2a864886f70d01010c": ["RSASSA-PKCS1-v1_5", "SHA-384"],
|
|
18363
|
+
"2a864886f70d01010d": ["RSASSA-PKCS1-v1_5", "SHA-512"],
|
|
18364
|
+
"2a8648ce3d040302": ["ECDSA", "SHA-256"],
|
|
18365
|
+
"2a8648ce3d040303": ["ECDSA", "SHA-384"],
|
|
18366
|
+
"2a8648ce3d040304": ["ECDSA", "SHA-512"],
|
|
18367
|
+
"2b6570": ["Ed25519", ""],
|
|
18368
|
+
"2a864886f70d01010a": ["RSA-PSS", "SHA-1"]
|
|
18200
18369
|
};
|
|
18201
|
-
var
|
|
18202
|
-
|
|
18203
|
-
|
|
18204
|
-
|
|
18205
|
-
|
|
18206
|
-
html: 4,
|
|
18207
|
-
base64: 5,
|
|
18208
|
-
hex: 6,
|
|
18209
|
-
wrapped: 7
|
|
18370
|
+
var PSS_HASHES = {
|
|
18371
|
+
"2b0e03021a": "SHA-1",
|
|
18372
|
+
"608648016503040201": "SHA-256",
|
|
18373
|
+
"608648016503040202": "SHA-384",
|
|
18374
|
+
"608648016503040203": "SHA-512"
|
|
18210
18375
|
};
|
|
18211
|
-
|
|
18212
|
-
|
|
18213
|
-
|
|
18214
|
-
|
|
18215
|
-
const
|
|
18216
|
-
|
|
18217
|
-
|
|
18218
|
-
|
|
18219
|
-
|
|
18220
|
-
|
|
18376
|
+
function pssOf(der2, algorithm) {
|
|
18377
|
+
const params = children2(der2, algorithm, 2)?.[1];
|
|
18378
|
+
let hash = "SHA-1";
|
|
18379
|
+
let salt = 20;
|
|
18380
|
+
for (const field4 of params && der2[params.start] === 48 ? children2(der2, params, 3) ?? [] : []) {
|
|
18381
|
+
const inner = tlv2(der2, field4.body);
|
|
18382
|
+
if (!inner) return void 0;
|
|
18383
|
+
if (der2[field4.start] === 160) {
|
|
18384
|
+
const known = PSS_HASHES[oidOf(der2, inner) ?? ""];
|
|
18385
|
+
if (!known) return void 0;
|
|
18386
|
+
hash = known;
|
|
18387
|
+
} else if (der2[field4.start] === 162) {
|
|
18388
|
+
salt = der2.subarray(inner.body, inner.end).reduce((n, b) => n * 256 + b, 0);
|
|
18389
|
+
}
|
|
18221
18390
|
}
|
|
18222
|
-
|
|
18391
|
+
return { hash, salt };
|
|
18223
18392
|
}
|
|
18224
|
-
|
|
18225
|
-
|
|
18226
|
-
|
|
18227
|
-
|
|
18228
|
-
|
|
18229
|
-
|
|
18230
|
-
const
|
|
18231
|
-
const
|
|
18232
|
-
|
|
18233
|
-
if (typeof secret.value !== "string" || values[index].length < MIN_VALUE) {
|
|
18234
|
-
throw new RangeError(`the value of ${secret.name} is shorter than ${MIN_VALUE} bytes`);
|
|
18235
|
-
}
|
|
18236
|
-
for (const shape of shapes(secret.value)) {
|
|
18237
|
-
const source = { secret: index, form: shape.form, offset: shape.offset };
|
|
18238
|
-
register(main, sources, ids, shape.bytes, source);
|
|
18239
|
-
if (wrappable(shape.form)) register(wrap, wrapSources, wrapIds, shape.bytes, source);
|
|
18240
|
-
}
|
|
18241
|
-
});
|
|
18242
|
-
main.build();
|
|
18243
|
-
wrap.build();
|
|
18244
|
-
const replacements = secrets.map((secret) => [
|
|
18245
|
-
utf82(secret.placeholder),
|
|
18246
|
-
utf82(`[redacted:${secret.name}]`)
|
|
18247
|
-
]);
|
|
18248
|
-
return { secrets, values, main, wrap, sources, wrapSources, replacements };
|
|
18393
|
+
var CURVES = {
|
|
18394
|
+
"2a8648ce3d030107": ["P-256", 32],
|
|
18395
|
+
"2b81040022": ["P-384", 48],
|
|
18396
|
+
"2b81040023": ["P-521", 66]
|
|
18397
|
+
};
|
|
18398
|
+
function oidOf(der2, algorithm, index = 0) {
|
|
18399
|
+
const parts2 = children2(der2, algorithm, 2);
|
|
18400
|
+
const oid2 = parts2?.[index];
|
|
18401
|
+
return oid2 && der2[oid2.start] === 6 ? hex2(der2.subarray(oid2.body, oid2.end)) : void 0;
|
|
18249
18402
|
}
|
|
18250
|
-
function
|
|
18251
|
-
|
|
18252
|
-
|
|
18253
|
-
|
|
18254
|
-
return a.secret < b.secret;
|
|
18403
|
+
function curveOf(der2, spki) {
|
|
18404
|
+
const algorithm = children2(der2, spki, 1)?.[0];
|
|
18405
|
+
const curve = algorithm && oidOf(der2, algorithm, 1);
|
|
18406
|
+
return curve ? CURVES[curve] : void 0;
|
|
18255
18407
|
}
|
|
18256
|
-
function
|
|
18257
|
-
|
|
18258
|
-
|
|
18259
|
-
|
|
18260
|
-
|
|
18261
|
-
|
|
18262
|
-
|
|
18263
|
-
|
|
18264
|
-
|
|
18265
|
-
|
|
18266
|
-
}
|
|
18267
|
-
const value2 = c.values[source.secret];
|
|
18268
|
-
let stop = end;
|
|
18269
|
-
let at = source.offset + FRAGMENT;
|
|
18270
|
-
while (stop < input.length && at < value2.length && input[stop] === value2[at]) {
|
|
18271
|
-
stop++;
|
|
18272
|
-
at++;
|
|
18408
|
+
function fixedEcdsa(sig, size) {
|
|
18409
|
+
const outer = tlv2(sig, 0);
|
|
18410
|
+
const ints = outer && children2(sig, outer, 2);
|
|
18411
|
+
if (ints?.length !== 2) return void 0;
|
|
18412
|
+
const out = new Uint8Array(size * 2);
|
|
18413
|
+
for (const [i, int] of ints.entries()) {
|
|
18414
|
+
let value2 = sig.subarray(int.body, int.end);
|
|
18415
|
+
while (value2.length > size && value2[0] === 0) value2 = value2.subarray(1);
|
|
18416
|
+
if (value2.length > size) return void 0;
|
|
18417
|
+
out.set(value2, (i + 1) * size - value2.length);
|
|
18273
18418
|
}
|
|
18274
|
-
|
|
18275
|
-
const growing = stop === input.length && at < value2.length;
|
|
18276
|
-
return { start: start2, end: stop, secret: source.secret, form, rank: RANK[form], growing };
|
|
18419
|
+
return out;
|
|
18277
18420
|
}
|
|
18278
|
-
function
|
|
18279
|
-
|
|
18421
|
+
function signedOf(der2) {
|
|
18422
|
+
const parts2 = tbsFields(der2);
|
|
18423
|
+
const [tbs, algorithm, value2] = parts2?.cert ?? [];
|
|
18424
|
+
const spki = parts2?.tbs[5];
|
|
18425
|
+
if (!tbs || !algorithm || !value2 || !spki || der2[value2.start] !== 3) return void 0;
|
|
18426
|
+
const known = HASHES[oidOf(der2, algorithm) ?? ""];
|
|
18427
|
+
if (!known) return void 0;
|
|
18428
|
+
const [scheme] = known;
|
|
18429
|
+
const pss = scheme === "RSA-PSS" ? pssOf(der2, algorithm) : void 0;
|
|
18430
|
+
if (scheme === "RSA-PSS" && !pss) return void 0;
|
|
18431
|
+
const hash = pss?.hash ?? known[1];
|
|
18432
|
+
const curve = scheme === "ECDSA" ? curveOf(der2, spki) : void 0;
|
|
18433
|
+
if (scheme === "ECDSA" && !curve) return void 0;
|
|
18434
|
+
const signature = der2.subarray(value2.body + 1, value2.end);
|
|
18435
|
+
return {
|
|
18436
|
+
tbs: raw(der2, tbs),
|
|
18437
|
+
spki: raw(der2, spki),
|
|
18438
|
+
signature,
|
|
18439
|
+
scheme,
|
|
18440
|
+
hash,
|
|
18441
|
+
...curve ? { curve } : {},
|
|
18442
|
+
...pss ? { salt: pss.salt } : {}
|
|
18443
|
+
};
|
|
18280
18444
|
}
|
|
18281
|
-
function
|
|
18282
|
-
|
|
18283
|
-
|
|
18284
|
-
|
|
18285
|
-
|
|
18286
|
-
|
|
18287
|
-
|
|
18288
|
-
|
|
18289
|
-
|
|
18290
|
-
|
|
18291
|
-
}
|
|
18292
|
-
});
|
|
18293
|
-
}
|
|
18294
|
-
c.main.partials(state, input.length, (start2) => partials.push(start2));
|
|
18445
|
+
async function verifiesItself(s) {
|
|
18446
|
+
const name2 = s.curve?.[0];
|
|
18447
|
+
const algorithm = s.scheme === "ECDSA" ? { name: "ECDSA", namedCurve: name2 } : s.hash ? { name: s.scheme, hash: s.hash } : { name: s.scheme };
|
|
18448
|
+
const key = await crypto.subtle.importKey("spki", new Uint8Array(s.spki), algorithm, false, [
|
|
18449
|
+
"verify"
|
|
18450
|
+
]);
|
|
18451
|
+
const signature = s.curve ? fixedEcdsa(s.signature, s.curve[1]) : s.signature;
|
|
18452
|
+
if (!signature) return false;
|
|
18453
|
+
const params = s.scheme === "ECDSA" ? { name: "ECDSA", hash: s.hash } : s.salt === void 0 ? { name: s.scheme } : { name: s.scheme, saltLength: s.salt };
|
|
18454
|
+
return crypto.subtle.verify(params, key, new Uint8Array(signature), new Uint8Array(s.tbs));
|
|
18295
18455
|
}
|
|
18296
|
-
function
|
|
18297
|
-
|
|
18298
|
-
|
|
18299
|
-
if (
|
|
18300
|
-
|
|
18301
|
-
for (let v = 0; v < map.length; v++) {
|
|
18302
|
-
state = c.wrap.step(state, input[map[v]]);
|
|
18303
|
-
c.wrap.matches(state, (id2) => {
|
|
18304
|
-
const first = v + 1 - c.wrap.lengths[id2];
|
|
18305
|
-
const start2 = map[first];
|
|
18306
|
-
const end = map[v] + 1;
|
|
18307
|
-
const wrapped = end - start2 !== c.wrap.lengths[id2];
|
|
18308
|
-
for (const source of c.wrapSources[id2]) {
|
|
18309
|
-
const form = wrapped ? "wrapped" : source.form;
|
|
18310
|
-
keep(best, { start: start2, end, secret: source.secret, form, rank: RANK[form], growing: false });
|
|
18311
|
-
}
|
|
18312
|
-
});
|
|
18313
|
-
}
|
|
18314
|
-
c.wrap.partials(state, map.length, (start2) => partials.push(map[start2]));
|
|
18456
|
+
async function selfSigned(der2) {
|
|
18457
|
+
if (!selfIssued(der2)) return false;
|
|
18458
|
+
const signed = signedOf(der2);
|
|
18459
|
+
if (!signed) return false;
|
|
18460
|
+
return verifiesItself(signed).catch(() => false);
|
|
18315
18461
|
}
|
|
18316
|
-
function
|
|
18317
|
-
|
|
18318
|
-
|
|
18319
|
-
|
|
18320
|
-
|
|
18321
|
-
hits.set(key, hit);
|
|
18462
|
+
async function chainShape(chain2) {
|
|
18463
|
+
return {
|
|
18464
|
+
leafSelfSigned: chain2.length === 1 && await selfSigned(chain2[0]),
|
|
18465
|
+
topSelfSigned: chain2.length > 1 && await selfSigned(chain2.at(-1))
|
|
18466
|
+
};
|
|
18322
18467
|
}
|
|
18323
|
-
function
|
|
18324
|
-
|
|
18325
|
-
|
|
18326
|
-
const
|
|
18327
|
-
|
|
18328
|
-
for (const part of parts2) {
|
|
18329
|
-
out.set(part, at);
|
|
18330
|
-
at += part.length;
|
|
18331
|
-
}
|
|
18332
|
-
return out;
|
|
18468
|
+
function selfIssued(der2) {
|
|
18469
|
+
const pair = der2 && names(der2);
|
|
18470
|
+
if (!pair) return false;
|
|
18471
|
+
const [issuer, subject] = pair;
|
|
18472
|
+
return issuer.length === subject.length && issuer.every((b, i) => b === subject[i]);
|
|
18333
18473
|
}
|
|
18334
|
-
function
|
|
18335
|
-
|
|
18336
|
-
|
|
18337
|
-
scanMain(c, input, best, partials);
|
|
18338
|
-
scanWrapped(c, input, best, partials);
|
|
18339
|
-
const holds2 = final ? [] : [...new Set(partials)].sort((a, b) => a - b);
|
|
18340
|
-
const starts = [...best.keys()].sort((a, b) => a - b);
|
|
18341
|
-
const parts2 = [];
|
|
18342
|
-
const hits = /* @__PURE__ */ new Map();
|
|
18343
|
-
let pos = 0;
|
|
18344
|
-
let cut = input.length;
|
|
18345
|
-
let s = 0;
|
|
18346
|
-
let h = 0;
|
|
18347
|
-
for (; ; ) {
|
|
18348
|
-
while (s < starts.length && starts[s] < pos) s++;
|
|
18349
|
-
while (h < holds2.length && holds2[h] < pos) h++;
|
|
18350
|
-
const hold = h < holds2.length ? holds2[h] : Infinity;
|
|
18351
|
-
const next3 = s < starts.length ? starts[s] : Infinity;
|
|
18352
|
-
if (hold <= next3) {
|
|
18353
|
-
cut = Math.min(hold, input.length);
|
|
18354
|
-
break;
|
|
18355
|
-
}
|
|
18356
|
-
const candidate = best.get(next3);
|
|
18357
|
-
parts2.push(
|
|
18358
|
-
input.subarray(pos, next3),
|
|
18359
|
-
c.replacements[candidate.secret][candidate.form === "raw" ? 0 : 1]
|
|
18360
|
-
);
|
|
18361
|
-
count(c, hits, candidate);
|
|
18362
|
-
pos = candidate.end;
|
|
18474
|
+
function untrusted(chain2, shape) {
|
|
18475
|
+
if (chain2.length === 1) {
|
|
18476
|
+
return shape.leafSelfSigned ? "DEPTH_ZERO_SELF_SIGNED_CERT" : "UNABLE_TO_VERIFY_LEAF_SIGNATURE";
|
|
18363
18477
|
}
|
|
18364
|
-
|
|
18365
|
-
return { output: concat6(parts2), cut, hits };
|
|
18478
|
+
return shape.topSelfSigned ? "SELF_SIGNED_CERT_IN_CHAIN" : "UNABLE_TO_GET_ISSUER_CERT_LOCALLY";
|
|
18366
18479
|
}
|
|
18367
|
-
function
|
|
18368
|
-
|
|
18369
|
-
|
|
18370
|
-
|
|
18371
|
-
|
|
18372
|
-
|
|
18480
|
+
function chainError(flags2, chain2, shape) {
|
|
18481
|
+
if (flags2 === -1) return "UNABLE_TO_VERIFY_LEAF_SIGNATURE";
|
|
18482
|
+
const rest2 = flags2 & ~CN_MISMATCH;
|
|
18483
|
+
if (rest2 === 0) return void 0;
|
|
18484
|
+
if (rest2 & NOT_TRUSTED) return untrusted(chain2, shape);
|
|
18485
|
+
return verifyCode(rest2);
|
|
18373
18486
|
}
|
|
18374
|
-
function
|
|
18375
|
-
|
|
18376
|
-
const decoder4 = new TextDecoder();
|
|
18377
|
-
const idleMs = options.idleMs ?? 250;
|
|
18378
|
-
const scrubBytes = (input) => {
|
|
18379
|
-
if (c.secrets.length === 0) return { bytes: input.slice(), hits: [] };
|
|
18380
|
-
const result = pass(c, input, true);
|
|
18381
|
-
return { bytes: result.output, hits: [...result.hits.values()] };
|
|
18382
|
-
};
|
|
18383
|
-
return {
|
|
18384
|
-
version: options.version ?? 0,
|
|
18385
|
-
idleMs,
|
|
18386
|
-
size: c.main.lengths.length,
|
|
18387
|
-
bytes: scrubBytes,
|
|
18388
|
-
text(input) {
|
|
18389
|
-
const { bytes, hits } = scrubBytes(utf82(input));
|
|
18390
|
-
return { text: decoder4.decode(bytes), hits };
|
|
18391
|
-
},
|
|
18392
|
-
stream() {
|
|
18393
|
-
let pending = EMPTY3;
|
|
18394
|
-
const hits = /* @__PURE__ */ new Map();
|
|
18395
|
-
const run2 = (final) => {
|
|
18396
|
-
if (c.secrets.length === 0 || pending.length === 0) {
|
|
18397
|
-
const out = pending;
|
|
18398
|
-
pending = EMPTY3;
|
|
18399
|
-
return out;
|
|
18400
|
-
}
|
|
18401
|
-
const result = pass(c, pending, final);
|
|
18402
|
-
merge(hits, result.hits);
|
|
18403
|
-
pending = pending.slice(result.cut);
|
|
18404
|
-
return result.output;
|
|
18405
|
-
};
|
|
18406
|
-
return {
|
|
18407
|
-
push(chunk2) {
|
|
18408
|
-
pending = concat6([pending, chunk2]);
|
|
18409
|
-
return run2(false);
|
|
18410
|
-
},
|
|
18411
|
-
idle() {
|
|
18412
|
-
return pending.length < FRAGMENT ? run2(true) : EMPTY3;
|
|
18413
|
-
},
|
|
18414
|
-
end() {
|
|
18415
|
-
return run2(true);
|
|
18416
|
-
},
|
|
18417
|
-
get hits() {
|
|
18418
|
-
return [...hits.values()];
|
|
18419
|
-
}
|
|
18420
|
-
};
|
|
18421
|
-
}
|
|
18422
|
-
};
|
|
18487
|
+
function nameMatches(flags2) {
|
|
18488
|
+
return flags2 !== -1 && (flags2 & CN_MISMATCH) === 0;
|
|
18423
18489
|
}
|
|
18424
18490
|
|
|
18425
|
-
// src/kernel/
|
|
18426
|
-
var
|
|
18427
|
-
var
|
|
18428
|
-
var
|
|
18429
|
-
|
|
18430
|
-
|
|
18431
|
-
|
|
18491
|
+
// src/kernel/net/sealed-anchor.ts
|
|
18492
|
+
var ANCHORS_MAX = 64;
|
|
18493
|
+
var ANCHOR_BYTES_MAX = 8 * 1024;
|
|
18494
|
+
var NOT_TRUSTED2 = 8;
|
|
18495
|
+
var PIN = /^[A-Za-z0-9+/]{43}=$/;
|
|
18496
|
+
function b64(bytes) {
|
|
18497
|
+
let bin = "";
|
|
18498
|
+
for (const b of bytes) bin += String.fromCharCode(b);
|
|
18499
|
+
return btoa(bin);
|
|
18432
18500
|
}
|
|
18433
|
-
|
|
18434
|
-
|
|
18435
|
-
|
|
18501
|
+
function der(text) {
|
|
18502
|
+
if (typeof text !== "string" || text.length === 0 || text.length > ANCHOR_BYTES_MAX * 4 / 3 + 4)
|
|
18503
|
+
return void 0;
|
|
18504
|
+
try {
|
|
18505
|
+
return Uint8Array.from(atob(text), (c) => c.charCodeAt(0));
|
|
18506
|
+
} catch {
|
|
18507
|
+
return void 0;
|
|
18508
|
+
}
|
|
18436
18509
|
}
|
|
18437
|
-
function
|
|
18438
|
-
|
|
18439
|
-
|
|
18510
|
+
function anchorsOf(reply) {
|
|
18511
|
+
if (typeof reply !== "object" || reply === null || Array.isArray(reply)) return void 0;
|
|
18512
|
+
const r = reply;
|
|
18513
|
+
if (r.error !== void 0 || !Array.isArray(r.anchors) || !Array.isArray(r.pins))
|
|
18514
|
+
return void 0;
|
|
18515
|
+
if (r.anchors.length + r.pins.length > ANCHORS_MAX) return void 0;
|
|
18516
|
+
const anchors = r.anchors.map(der);
|
|
18517
|
+
if (anchors.some((a) => a === void 0)) return void 0;
|
|
18518
|
+
if (!r.pins.every((p) => typeof p === "string" && PIN.test(p))) return void 0;
|
|
18519
|
+
return { anchors, pins: r.pins };
|
|
18520
|
+
}
|
|
18521
|
+
async function sha2563(bytes) {
|
|
18522
|
+
return b64(
|
|
18523
|
+
new Uint8Array(await crypto.subtle.digest("SHA-256", bytes))
|
|
18524
|
+
);
|
|
18440
18525
|
}
|
|
18441
|
-
function
|
|
18442
|
-
|
|
18443
|
-
return code === "EINTR" || code === "EAGAIN";
|
|
18526
|
+
function same2(a, b) {
|
|
18527
|
+
return a.length === b.length && a.every((x, i) => x === b[i]);
|
|
18444
18528
|
}
|
|
18445
|
-
function
|
|
18446
|
-
const
|
|
18447
|
-
|
|
18448
|
-
|
|
18449
|
-
|
|
18450
|
-
|
|
18451
|
-
|
|
18452
|
-
|
|
18453
|
-
|
|
18454
|
-
|
|
18455
|
-
const wake = () => {
|
|
18456
|
-
for (const waiter of [...waiters]) waiter();
|
|
18457
|
-
};
|
|
18458
|
-
const raise = () => {
|
|
18459
|
-
if (failed3 === void 0) return;
|
|
18460
|
-
const err = failed3;
|
|
18461
|
-
failed3 = void 0;
|
|
18462
|
-
throw err;
|
|
18463
|
-
};
|
|
18464
|
-
const later = (bytes) => {
|
|
18465
|
-
if (bytes.length === 0) return;
|
|
18466
|
-
pending += 1;
|
|
18467
|
-
tail2 = tail2.then(() => writeAll3(file, bytes)).catch((err) => {
|
|
18468
|
-
if (failed3 === void 0) failed3 = err;
|
|
18469
|
-
}).finally(() => {
|
|
18470
|
-
pending -= 1;
|
|
18471
|
-
if (quiet2()) wake();
|
|
18472
|
-
});
|
|
18473
|
-
};
|
|
18474
|
-
const settling = (signal) => new Promise((resolve2, reject) => {
|
|
18475
|
-
const done5 = () => {
|
|
18476
|
-
waiters.delete(done5);
|
|
18477
|
-
signal?.removeEventListener("abort", stop);
|
|
18478
|
-
resolve2();
|
|
18479
|
-
};
|
|
18480
|
-
const stop = () => {
|
|
18481
|
-
waiters.delete(done5);
|
|
18482
|
-
reject(new KernelError("EINTR"));
|
|
18483
|
-
};
|
|
18484
|
-
if (signal?.aborted) return stop();
|
|
18485
|
-
waiters.add(done5);
|
|
18486
|
-
signal?.addEventListener("abort", stop, { once: true });
|
|
18487
|
-
});
|
|
18488
|
-
const settled = async () => {
|
|
18489
|
-
while (!quiet2()) await settling();
|
|
18490
|
-
};
|
|
18491
|
-
const changed = async (signal) => {
|
|
18492
|
-
const round = new AbortController();
|
|
18493
|
-
const stop = signal ? AbortSignal.any([signal, round.signal]) : round.signal;
|
|
18494
|
-
try {
|
|
18495
|
-
const own = settling(stop);
|
|
18496
|
-
await Promise.race(file.changed ? [own, file.changed(stop)] : [own]);
|
|
18497
|
-
} catch (err) {
|
|
18498
|
-
throw signal?.aborted ? new KernelError("EINTR") : err;
|
|
18499
|
-
} finally {
|
|
18500
|
-
round.abort();
|
|
18501
|
-
}
|
|
18502
|
-
};
|
|
18503
|
-
const turn = async (signal) => {
|
|
18504
|
-
for (let waited = false; ; waited = true) {
|
|
18505
|
-
if (quiet2() && (pollFile(file).writable || !file.changed)) {
|
|
18506
|
-
busy = true;
|
|
18507
|
-
return;
|
|
18508
|
-
}
|
|
18509
|
-
if (signal?.aborted) throw new KernelError(waited ? "EINTR" : "EAGAIN");
|
|
18510
|
-
await changed(signal);
|
|
18511
|
-
}
|
|
18512
|
-
};
|
|
18513
|
-
const send2 = async (out, signal) => {
|
|
18514
|
-
const write = file.write;
|
|
18515
|
-
for (let at = 0; at < out.length; ) {
|
|
18516
|
-
try {
|
|
18517
|
-
at += await write.call(file, out.subarray(at), signal);
|
|
18518
|
-
} catch (err) {
|
|
18519
|
-
if (!signal?.aborted || !interrupted2(err)) throw err;
|
|
18520
|
-
}
|
|
18521
|
-
if (at < out.length && signal?.aborted) return later(out.subarray(at));
|
|
18522
|
-
}
|
|
18523
|
-
};
|
|
18524
|
-
const release = () => {
|
|
18525
|
-
timer = void 0;
|
|
18526
|
-
later(stream.idle());
|
|
18527
|
-
};
|
|
18528
|
-
return new OpenFile({
|
|
18529
|
-
...bound(file, "read"),
|
|
18530
|
-
...bound(file, "peek"),
|
|
18531
|
-
...bound(file, "stat"),
|
|
18532
|
-
poll: () => {
|
|
18533
|
-
const state = pollFile(file);
|
|
18534
|
-
return quiet2() ? state : { ...state, writable: false };
|
|
18535
|
-
},
|
|
18536
|
-
changed,
|
|
18537
|
-
...file.tty ? { tty: file.tty } : {},
|
|
18538
|
-
identity: file.identity ?? file,
|
|
18539
|
-
...file.clipboard ? { clipboard: file.clipboard } : {},
|
|
18540
|
-
...file.write ? {
|
|
18541
|
-
write: async (bytes, signal) => {
|
|
18542
|
-
await turn(signal);
|
|
18543
|
-
const taken = signal?.aborted && bytes.length > SCRUB_NONBLOCK_MAX ? bytes.subarray(0, SCRUB_NONBLOCK_MAX) : bytes;
|
|
18544
|
-
try {
|
|
18545
|
-
raise();
|
|
18546
|
-
if (timer !== void 0) clearTimeout(timer);
|
|
18547
|
-
timer = void 0;
|
|
18548
|
-
await send2(stream.push(taken), signal);
|
|
18549
|
-
} finally {
|
|
18550
|
-
busy = false;
|
|
18551
|
-
if (quiet2()) wake();
|
|
18552
|
-
}
|
|
18553
|
-
timer = setTimeout(release, idleMs);
|
|
18554
|
-
return taken.length;
|
|
18555
|
-
}
|
|
18556
|
-
} : {},
|
|
18557
|
-
flush: async () => {
|
|
18558
|
-
await settled();
|
|
18559
|
-
raise();
|
|
18560
|
-
await file.flush?.();
|
|
18561
|
-
},
|
|
18562
|
-
close: async () => {
|
|
18563
|
-
if (timer !== void 0) clearTimeout(timer);
|
|
18564
|
-
let failure2;
|
|
18565
|
-
try {
|
|
18566
|
-
await settled();
|
|
18567
|
-
later(stream.end());
|
|
18568
|
-
await settled();
|
|
18569
|
-
raise();
|
|
18570
|
-
} catch (err) {
|
|
18571
|
-
failure2 = { err };
|
|
18572
|
-
}
|
|
18573
|
-
await inner.release();
|
|
18574
|
-
if (failure2) throw failure2.err;
|
|
18575
|
-
}
|
|
18576
|
-
});
|
|
18529
|
+
function flagsWith(engine, anchor, chain2, host) {
|
|
18530
|
+
const store = engine.store();
|
|
18531
|
+
try {
|
|
18532
|
+
if (anchor) store.add(anchor);
|
|
18533
|
+
return engine.chainFlags(store, chain2, host);
|
|
18534
|
+
} catch {
|
|
18535
|
+
return void 0;
|
|
18536
|
+
} finally {
|
|
18537
|
+
store.release();
|
|
18538
|
+
}
|
|
18577
18539
|
}
|
|
18578
|
-
function
|
|
18579
|
-
|
|
18540
|
+
function leafPinned(engine, leaf, host) {
|
|
18541
|
+
const flags2 = flagsWith(engine, void 0, [leaf], host);
|
|
18542
|
+
return flags2 !== void 0 && (flags2 & ~NOT_TRUSTED2) === 0;
|
|
18580
18543
|
}
|
|
18581
|
-
function
|
|
18582
|
-
|
|
18583
|
-
for (const fd of [1, 2]) {
|
|
18584
|
-
try {
|
|
18585
|
-
files.add(fds.get(fd));
|
|
18586
|
-
} catch {
|
|
18587
|
-
}
|
|
18588
|
-
}
|
|
18589
|
-
return files;
|
|
18544
|
+
function issuedBy(engine, anchor, chain2, host) {
|
|
18545
|
+
return flagsWith(engine, anchor, chain2, host) === 0;
|
|
18590
18546
|
}
|
|
18591
|
-
function
|
|
18592
|
-
const
|
|
18593
|
-
|
|
18594
|
-
for (const
|
|
18595
|
-
const
|
|
18596
|
-
if (
|
|
18597
|
-
const known = wrapped.get(original);
|
|
18598
|
-
const flags2 = fds.statusFlags(fd);
|
|
18599
|
-
const wrapper = known ? known.retain() : scrubbed(original.retain(), scrubber);
|
|
18600
|
-
wrapped.set(original, wrapper);
|
|
18601
|
-
fds.installAt(fd, wrapper);
|
|
18602
|
-
if (flags2 !== void 0) fds.setStatusFlags(fd, flags2);
|
|
18547
|
+
async function anchorFor(engine, chain2, host, found) {
|
|
18548
|
+
const leaf = chain2[0];
|
|
18549
|
+
if (!leaf || !engine.chainVerify) return void 0;
|
|
18550
|
+
for (const anchor of found.anchors) {
|
|
18551
|
+
const ok4 = same2(anchor, leaf) ? leafPinned(engine, leaf, host) : issuedBy(engine, anchor, chain2, host);
|
|
18552
|
+
if (ok4) return sha2563(anchor);
|
|
18603
18553
|
}
|
|
18554
|
+
for (const [i, cert] of chain2.entries()) {
|
|
18555
|
+
const spki = spkiOf(cert);
|
|
18556
|
+
if (!spki || !found.pins.includes(await sha2563(spki))) continue;
|
|
18557
|
+
const ok4 = i === 0 ? leafPinned(engine, leaf, host) : issuedBy(engine, cert, chain2, host);
|
|
18558
|
+
if (ok4) return sha2563(spki);
|
|
18559
|
+
}
|
|
18560
|
+
return void 0;
|
|
18604
18561
|
}
|
|
18605
18562
|
|
|
18606
|
-
//
|
|
18607
|
-
var
|
|
18608
|
-
|
|
18609
|
-
|
|
18610
|
-
|
|
18611
|
-
|
|
18612
|
-
|
|
18613
|
-
|
|
18614
|
-
|
|
18615
|
-
|
|
18616
|
-
"TRACE"
|
|
18617
|
-
];
|
|
18618
|
-
var HEAD_MAX = 16 * 1024;
|
|
18619
|
-
var ANY_PLACEHOLDER = /fnox_proxy_[0-9a-f]{24}/g;
|
|
18620
|
-
var REQUEST_LINE2 = /^([!#$%&'*+.^_`|~0-9A-Za-z-]+) ([\x21-\x7e]+) HTTP\/1\.[01]$/;
|
|
18621
|
-
var HEADER_LINE = /^([!#$%&'*+.^_`|~0-9A-Za-z-]+):[ \t]*(.*?)[ \t]*$/;
|
|
18622
|
-
var BASIC = /^(Basic[ \t]+)([A-Za-z0-9+/]+={0,2})$/i;
|
|
18623
|
-
var encoder7 = new TextEncoder();
|
|
18624
|
-
function binary(text) {
|
|
18563
|
+
// node_modules/@ai-ecoverse/slicc-scrub/dist/index.js
|
|
18564
|
+
var FRAGMENT = 16;
|
|
18565
|
+
var MIN_VALUE = 8;
|
|
18566
|
+
var MIN_BASE64 = 8;
|
|
18567
|
+
var encoder5 = new TextEncoder();
|
|
18568
|
+
var STD = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
18569
|
+
function utf82(text) {
|
|
18570
|
+
return encoder5.encode(text);
|
|
18571
|
+
}
|
|
18572
|
+
function base642(bytes, padded = true) {
|
|
18625
18573
|
let out = "";
|
|
18626
|
-
for (
|
|
18574
|
+
for (let i = 0; i < bytes.length; i += 3) {
|
|
18575
|
+
const a = bytes[i];
|
|
18576
|
+
const b = i + 1 < bytes.length ? bytes[i + 1] : 0;
|
|
18577
|
+
const c = i + 2 < bytes.length ? bytes[i + 2] : 0;
|
|
18578
|
+
const triple = a << 16 | b << 8 | c;
|
|
18579
|
+
const left = bytes.length - i;
|
|
18580
|
+
out += STD[triple >> 18 & 63] + STD[triple >> 12 & 63];
|
|
18581
|
+
out += left > 1 ? STD[triple >> 6 & 63] : padded ? "=" : "";
|
|
18582
|
+
out += left > 2 ? STD[triple & 63] : padded ? "=" : "";
|
|
18583
|
+
}
|
|
18627
18584
|
return out;
|
|
18628
18585
|
}
|
|
18629
|
-
function
|
|
18630
|
-
|
|
18631
|
-
|
|
18632
|
-
|
|
18633
|
-
|
|
18586
|
+
function urlSafe(text) {
|
|
18587
|
+
return text.replace(/\+/g, "-").replace(/\//g, "_");
|
|
18588
|
+
}
|
|
18589
|
+
function hex3(bytes) {
|
|
18590
|
+
let out = "";
|
|
18591
|
+
for (const byte of bytes) out += byte.toString(16).padStart(2, "0");
|
|
18592
|
+
return out;
|
|
18593
|
+
}
|
|
18594
|
+
function embedded(bytes, offset) {
|
|
18595
|
+
const shifted = new Uint8Array(offset + bytes.length);
|
|
18596
|
+
shifted.set(bytes, offset);
|
|
18597
|
+
const encoded = base642(shifted);
|
|
18598
|
+
const first = Math.ceil(8 * offset / 6);
|
|
18599
|
+
const last = Math.floor(8 * (offset + bytes.length) / 6);
|
|
18600
|
+
return encoded.slice(first, last);
|
|
18601
|
+
}
|
|
18602
|
+
function unicode(value2, upper) {
|
|
18603
|
+
let out = "";
|
|
18604
|
+
for (let i = 0; i < value2.length; i++) {
|
|
18605
|
+
const unit = value2.charCodeAt(i);
|
|
18606
|
+
if (unit === 34) out += '\\"';
|
|
18607
|
+
else if (unit === 92) out += "\\\\";
|
|
18608
|
+
else if (unit < 32 || unit > 126) {
|
|
18609
|
+
const code = unit.toString(16).padStart(4, "0");
|
|
18610
|
+
out += `\\u${upper ? code.toUpperCase() : code}`;
|
|
18611
|
+
} else out += value2[i];
|
|
18634
18612
|
}
|
|
18635
|
-
return
|
|
18613
|
+
return out;
|
|
18636
18614
|
}
|
|
18637
|
-
function
|
|
18638
|
-
|
|
18639
|
-
if (!m) return void 0;
|
|
18615
|
+
function percent(value2) {
|
|
18616
|
+
let component;
|
|
18640
18617
|
try {
|
|
18641
|
-
|
|
18618
|
+
component = encodeURIComponent(value2);
|
|
18642
18619
|
} catch {
|
|
18643
|
-
return
|
|
18620
|
+
return [];
|
|
18621
|
+
}
|
|
18622
|
+
const lower = component.replace(/%[0-9A-F]{2}/g, (escape) => escape.toLowerCase());
|
|
18623
|
+
const plus = component.replace(/%20/g, "+");
|
|
18624
|
+
let form = "";
|
|
18625
|
+
for (const byte of utf82(value2)) {
|
|
18626
|
+
const char = String.fromCharCode(byte);
|
|
18627
|
+
if (/[A-Za-z0-9*\-._]/.test(char)) form += char;
|
|
18628
|
+
else if (byte === 32) form += "+";
|
|
18629
|
+
else form += `%${byte.toString(16).toUpperCase().padStart(2, "0")}`;
|
|
18644
18630
|
}
|
|
18631
|
+
return [component, lower, plus, form];
|
|
18645
18632
|
}
|
|
18646
|
-
function
|
|
18647
|
-
return
|
|
18633
|
+
function html(value2, apostrophe) {
|
|
18634
|
+
return value2.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, apostrophe);
|
|
18648
18635
|
}
|
|
18649
|
-
function
|
|
18650
|
-
const
|
|
18651
|
-
for (
|
|
18652
|
-
const
|
|
18653
|
-
if (
|
|
18654
|
-
const value2 = m[2];
|
|
18655
|
-
const basic = basicOf(value2);
|
|
18656
|
-
const placeholders = placeholdersIn(basic ? basic.decoded : value2);
|
|
18657
|
-
if (placeholders.length > 0)
|
|
18658
|
-
found.push({ line: i, name: m[1].toLowerCase(), value: value2, basic, placeholders });
|
|
18636
|
+
function encodings(bytes) {
|
|
18637
|
+
const standard = [base642(bytes), base642(bytes, false)];
|
|
18638
|
+
for (const offset of [0, 1, 2]) {
|
|
18639
|
+
const run2 = embedded(bytes, offset);
|
|
18640
|
+
if (run2.length >= MIN_BASE64) standard.push(run2);
|
|
18659
18641
|
}
|
|
18660
|
-
return
|
|
18642
|
+
return [...standard, ...standard.map(urlSafe)];
|
|
18661
18643
|
}
|
|
18662
|
-
function
|
|
18663
|
-
|
|
18664
|
-
|
|
18644
|
+
function shapes(value2) {
|
|
18645
|
+
const raw2 = utf82(value2);
|
|
18646
|
+
const seen = /* @__PURE__ */ new Set([value2]);
|
|
18647
|
+
const out = [];
|
|
18648
|
+
if (raw2.length < FRAGMENT) out.push({ bytes: raw2, form: "raw" });
|
|
18649
|
+
for (let offset = 0; raw2.length >= FRAGMENT && offset + FRAGMENT <= raw2.length; offset++) {
|
|
18650
|
+
out.push({ bytes: raw2.subarray(offset, offset + FRAGMENT), form: "fragment", offset });
|
|
18651
|
+
}
|
|
18652
|
+
const add = (text, form) => {
|
|
18653
|
+
if (seen.has(text)) return;
|
|
18654
|
+
seen.add(text);
|
|
18655
|
+
out.push({ bytes: utf82(text), form });
|
|
18656
|
+
};
|
|
18657
|
+
const json5 = JSON.stringify(value2).slice(1, -1);
|
|
18658
|
+
for (const text of [
|
|
18659
|
+
json5,
|
|
18660
|
+
json5.replace(/\//g, "\\/"),
|
|
18661
|
+
unicode(value2, false),
|
|
18662
|
+
unicode(value2, true)
|
|
18663
|
+
]) {
|
|
18664
|
+
add(text, "json");
|
|
18665
|
+
}
|
|
18666
|
+
for (const text of percent(value2)) add(text, "percent");
|
|
18667
|
+
for (const text of [html(value2, "'"), html(value2, "'")]) add(text, "html");
|
|
18668
|
+
for (const text of encodings(raw2)) add(text, "base64");
|
|
18669
|
+
add(hex3(raw2), "hex");
|
|
18670
|
+
add(hex3(raw2).toUpperCase(), "hex");
|
|
18665
18671
|
return out;
|
|
18666
18672
|
}
|
|
18667
|
-
function
|
|
18668
|
-
|
|
18669
|
-
for (const [ph, value2] of Object.entries(values ?? {}))
|
|
18670
|
-
if (encoder7.encode(value2).length >= MIN_VALUE) out[ph] = value2;
|
|
18671
|
-
return out;
|
|
18673
|
+
function wrappable(form) {
|
|
18674
|
+
return form === "base64" || form === "hex";
|
|
18672
18675
|
}
|
|
18673
|
-
|
|
18674
|
-
|
|
18675
|
-
|
|
18676
|
-
|
|
18677
|
-
|
|
18678
|
-
|
|
18679
|
-
|
|
18680
|
-
|
|
18681
|
-
|
|
18682
|
-
|
|
18683
|
-
|
|
18684
|
-
|
|
18685
|
-
|
|
18686
|
-
|
|
18687
|
-
|
|
18688
|
-
|
|
18689
|
-
|
|
18690
|
-
|
|
18691
|
-
|
|
18692
|
-
|
|
18693
|
-
|
|
18694
|
-
|
|
18676
|
+
var Automaton = class {
|
|
18677
|
+
edges = /* @__PURE__ */ new Map();
|
|
18678
|
+
fail = [0];
|
|
18679
|
+
depth = [0];
|
|
18680
|
+
children = [0];
|
|
18681
|
+
out = [[]];
|
|
18682
|
+
dict = [-1];
|
|
18683
|
+
lengths = [];
|
|
18684
|
+
add(bytes) {
|
|
18685
|
+
let node = 0;
|
|
18686
|
+
for (const byte of bytes) {
|
|
18687
|
+
const key = node * 256 + byte;
|
|
18688
|
+
let next3 = this.edges.get(key);
|
|
18689
|
+
if (next3 === void 0) {
|
|
18690
|
+
next3 = this.depth.length;
|
|
18691
|
+
this.edges.set(key, next3);
|
|
18692
|
+
this.fail.push(0);
|
|
18693
|
+
this.depth.push(this.depth[node] + 1);
|
|
18694
|
+
this.children.push(0);
|
|
18695
|
+
this.children[node] += 1;
|
|
18696
|
+
this.out.push([]);
|
|
18697
|
+
this.dict.push(-1);
|
|
18698
|
+
}
|
|
18699
|
+
node = next3;
|
|
18700
|
+
}
|
|
18701
|
+
const id2 = this.lengths.length;
|
|
18702
|
+
this.lengths.push(bytes.length);
|
|
18703
|
+
this.out[node].push(id2);
|
|
18704
|
+
return id2;
|
|
18705
|
+
}
|
|
18706
|
+
build() {
|
|
18707
|
+
const queue = [];
|
|
18708
|
+
const byNode = /* @__PURE__ */ new Map();
|
|
18709
|
+
for (const [key, child] of this.edges) {
|
|
18710
|
+
const parent = Math.floor(key / 256);
|
|
18711
|
+
const list = byNode.get(parent) ?? [];
|
|
18712
|
+
list.push([key % 256, child]);
|
|
18713
|
+
byNode.set(parent, list);
|
|
18714
|
+
}
|
|
18715
|
+
for (const [, child] of byNode.get(0) ?? []) queue.push(child);
|
|
18716
|
+
for (let head = 0; head < queue.length; head++) {
|
|
18717
|
+
const node = queue[head];
|
|
18718
|
+
const fallback = this.fail[node];
|
|
18719
|
+
this.dict[node] = this.out[fallback].length > 0 ? fallback : this.dict[fallback];
|
|
18720
|
+
for (const [byte, child] of byNode.get(node) ?? []) {
|
|
18721
|
+
let state = fallback;
|
|
18722
|
+
let target = this.edges.get(state * 256 + byte);
|
|
18723
|
+
while (target === void 0 && state > 0) {
|
|
18724
|
+
state = this.fail[state];
|
|
18725
|
+
target = this.edges.get(state * 256 + byte);
|
|
18726
|
+
}
|
|
18727
|
+
this.fail[child] = target ?? 0;
|
|
18728
|
+
queue.push(child);
|
|
18729
|
+
}
|
|
18730
|
+
}
|
|
18731
|
+
}
|
|
18732
|
+
step(state, byte) {
|
|
18733
|
+
let current = state;
|
|
18734
|
+
for (; ; ) {
|
|
18735
|
+
const next3 = this.edges.get(current * 256 + byte);
|
|
18736
|
+
if (next3 !== void 0) return next3;
|
|
18737
|
+
if (current === 0) return 0;
|
|
18738
|
+
current = this.fail[current];
|
|
18739
|
+
}
|
|
18740
|
+
}
|
|
18741
|
+
matches(state, visit) {
|
|
18742
|
+
for (let node = state; node > 0; node = this.dict[node]) {
|
|
18743
|
+
for (const id2 of this.out[node]) visit(id2);
|
|
18744
|
+
}
|
|
18745
|
+
}
|
|
18746
|
+
partials(state, length2, visit) {
|
|
18747
|
+
for (let node = state; node > 0; node = this.fail[node]) {
|
|
18748
|
+
if (this.children[node] > 0) visit(length2 - this.depth[node]);
|
|
18749
|
+
}
|
|
18750
|
+
}
|
|
18751
|
+
};
|
|
18752
|
+
var RANK = {
|
|
18753
|
+
raw: 0,
|
|
18754
|
+
fragment: 1,
|
|
18755
|
+
json: 2,
|
|
18756
|
+
percent: 3,
|
|
18757
|
+
html: 4,
|
|
18758
|
+
base64: 5,
|
|
18759
|
+
hex: 6,
|
|
18760
|
+
wrapped: 7
|
|
18761
|
+
};
|
|
18762
|
+
var CR2 = 13;
|
|
18763
|
+
var LF2 = 10;
|
|
18764
|
+
var EMPTY3 = new Uint8Array(0);
|
|
18765
|
+
function register(automaton, sources, ids, bytes, source) {
|
|
18766
|
+
const key = Array.from(bytes).join(",");
|
|
18767
|
+
let id2 = ids.get(key);
|
|
18768
|
+
if (id2 === void 0) {
|
|
18769
|
+
id2 = automaton.add(bytes);
|
|
18770
|
+
ids.set(key, id2);
|
|
18771
|
+
sources[id2] = [];
|
|
18772
|
+
}
|
|
18773
|
+
sources[id2].push(source);
|
|
18695
18774
|
}
|
|
18696
|
-
|
|
18697
|
-
|
|
18698
|
-
|
|
18699
|
-
|
|
18700
|
-
|
|
18701
|
-
|
|
18775
|
+
function prepare(secrets) {
|
|
18776
|
+
const main = new Automaton();
|
|
18777
|
+
const wrap = new Automaton();
|
|
18778
|
+
const sources = [];
|
|
18779
|
+
const wrapSources = [];
|
|
18780
|
+
const ids = /* @__PURE__ */ new Map();
|
|
18781
|
+
const wrapIds = /* @__PURE__ */ new Map();
|
|
18782
|
+
const values = secrets.map((secret) => utf82(secret.value));
|
|
18783
|
+
secrets.forEach((secret, index) => {
|
|
18784
|
+
if (typeof secret.value !== "string" || values[index].length < MIN_VALUE) {
|
|
18785
|
+
throw new RangeError(`the value of ${secret.name} is shorter than ${MIN_VALUE} bytes`);
|
|
18786
|
+
}
|
|
18787
|
+
for (const shape of shapes(secret.value)) {
|
|
18788
|
+
const source = { secret: index, form: shape.form, offset: shape.offset };
|
|
18789
|
+
register(main, sources, ids, shape.bytes, source);
|
|
18790
|
+
if (wrappable(shape.form)) register(wrap, wrapSources, wrapIds, shape.bytes, source);
|
|
18791
|
+
}
|
|
18702
18792
|
});
|
|
18793
|
+
main.build();
|
|
18794
|
+
wrap.build();
|
|
18795
|
+
const replacements = secrets.map((secret) => [
|
|
18796
|
+
utf82(secret.placeholder),
|
|
18797
|
+
utf82(`[redacted:${secret.name}]`)
|
|
18798
|
+
]);
|
|
18799
|
+
return { secrets, values, main, wrap, sources, wrapSources, replacements };
|
|
18703
18800
|
}
|
|
18704
|
-
function
|
|
18705
|
-
|
|
18706
|
-
|
|
18707
|
-
|
|
18708
|
-
|
|
18709
|
-
const [from, to] = table[mid];
|
|
18710
|
-
if (code < from) hi = mid - 1;
|
|
18711
|
-
else if (code > to) lo = mid + 1;
|
|
18712
|
-
else return true;
|
|
18713
|
-
}
|
|
18714
|
-
return false;
|
|
18715
|
-
}
|
|
18716
|
-
var PROHIBITED_TEXT = "0-1F 7F-A0 340-341 6DD 70F 1680 180E 2000-200F 2028-202F 205F-2063 206A-206F 2FF0-2FFB 3000 D800-F8FF FDD0-FDEF FEFF FFF9-FFFF 1D173-1D17A 1FFFE-1FFFF 2FFFE-2FFFF 3FFFE-3FFFF 4FFFE-4FFFF 5FFFE-5FFFF 6FFFE-6FFFF 7FFFE-7FFFF 8FFFE-8FFFF 9FFFE-9FFFF AFFFE-AFFFF BFFFE-BFFFF CFFFE-CFFFF DFFFE-DFFFF E0001 E0020-E007F EFFFE-10FFFF";
|
|
18717
|
-
var UNASSIGNED_TEXT = "221 234-24F 2AE-2AF 2EF-2FF 350-35F 370-373 376-379 37B-37D 37F-383 38B 38D 3A2 3CF 3F7-3FF 487 4CF 4F6-4F7 4FA-4FF 510-530 557-558 560 588 58B-590 5A2 5BA 5C5-5CF 5EB-5EF 5F5-60B 60D-61A 61C-61E 620 63B-63F 656-65F 6EE-6EF 6FF 70E 72D-72F 74B-77F 7B2-900 904 93A-93B 94E-94F 955-957 971-980 984 98D-98E 991-992 9A9 9B1 9B3-9B5 9BA-9BB 9BD 9C5-9C6 9C9-9CA 9CE-9D6 9D8-9DB 9DE 9E4-9E5 9FB-A01 A03-A04 A0B-A0E A11-A12 A29 A31 A34 A37 A3A-A3B A3D A43-A46 A49-A4A A4E-A58 A5D A5F-A65 A75-A80 A84 A8C A8E A92 AA9 AB1 AB4 ABA-ABB AC6 ACA ACE-ACF AD1-ADF AE1-AE5 AF0-B00 B04 B0D-B0E B11-B12 B29 B31 B34-B35 B3A-B3B B44-B46 B49-B4A B4E-B55 B58-B5B B5E B62-B65 B71-B81 B84 B8B-B8D B91 B96-B98 B9B B9D BA0-BA2 BA5-BA7 BAB-BAD BB6 BBA-BBD BC3-BC5 BC9 BCE-BD6 BD8-BE6 BF3-C00 C04 C0D C11 C29 C34 C3A-C3D C45 C49 C4E-C54 C57-C5F C62-C65 C70-C81 C84 C8D C91 CA9 CB4 CBA-CBD CC5 CC9 CCE-CD4 CD7-CDD CDF CE2-CE5 CF0-D01 D04 D0D D11 D29 D3A-D3D D44-D45 D49 D4E-D56 D58-D5F D62-D65 D70-D81 D84 D97-D99 DB2 DBC DBE-DBF DC7-DC9 DCB-DCE DD5 DD7 DE0-DF1 DF5-E00 E3B-E3E E5C-E80 E83 E85-E86 E89 E8B-E8C E8E-E93 E98 EA0 EA4 EA6 EA8-EA9 EAC EBA EBE-EBF EC5 EC7 ECE-ECF EDA-EDB EDE-EFF F48 F6B-F70 F8C-F8F F98 FBD FCD-FCE FD0-FFF 1022 1028 102B 1033-1035 103A-103F 105A-109F 10C6-10CF 10F9-10FA 10FC-10FF 115A-115E 11A3-11A7 11FA-11FF 1207 1247 1249 124E-124F 1257 1259 125E-125F 1287 1289 128E-128F 12AF 12B1 12B6-12B7 12BF 12C1 12C6-12C7 12CF 12D7 12EF 130F 1311 1316-1317 131F 1347 135B-1360 137D-139F 13F5-1400 1677-167F 169D-169F 16F1-16FF 170D 1715-171F 1737-173F 1754-175F 176D 1771 1774-177F 17DD-17DF 17EA-17FF 180F 181A-181F 1878-187F 18AA-1DFF 1E9C-1E9F 1EFA-1EFF 1F16-1F17 1F1E-1F1F 1F46-1F47 1F4E-1F4F 1F58 1F5A 1F5C 1F5E 1F7E-1F7F 1FB5 1FC5 1FD4-1FD5 1FDC 1FF0-1FF1 1FF5 1FFF 2053-2056 2058-205E 2064-2069 2072-2073 208F-209F 20B2-20CF 20EB-20FF 213B-213C 214C-2152 2184-218F 23CF-23FF 2427-243F 244B-245F 24FF 2614-2615 2618 267E-267F 268A-2700 2705 270A-270B 2728 274C 274E 2753-2755 2757 275F-2760 2795-2797 27B0 27BF-27CF 27EC-27EF 2B00-2E7F 2E9A 2EF4-2EFF 2FD6-2FEF 2FFC-2FFF 3040 3097-3098 3100-3104 312D-3130 318F 31B8-31EF 321D-321F 3244-3250 327C-327E 32CC-32CF 32FF 3377-337A 33DE-33DF 33FF 4DB6-4DFF 9FA6-9FFF A48D-A48F A4C7-ABFF D7A4-D7FF FA2E-FA2F FA6B-FAFF FB07-FB12 FB18-FB1C FB37 FB3D FB3F FB42 FB45 FBB2-FBD2 FD40-FD4F FD90-FD91 FDC8-FDCF FDFD-FDFF FE10-FE1F FE24-FE2F FE47-FE48 FE53 FE67 FE6C-FE6F FE75 FEFD-FEFE FF00 FFBF-FFC1 FFC8-FFC9 FFD0-FFD1 FFD8-FFD9 FFDD-FFDF FFE7 FFEF-FFF8 10000-102FF 1031F 10324-1032F 1034B-103FF 10426-10427 1044E-1CFFF 1D0F6-1D0FF 1D127-1D129 1D1DE-1D3FF 1D455 1D49D 1D4A0-1D4A1 1D4A3-1D4A4 1D4A7-1D4A8 1D4AD 1D4BA 1D4BC 1D4C1 1D4C4 1D506 1D50B-1D50C 1D515 1D51D 1D53A 1D53F 1D545 1D547-1D549 1D551 1D6A4-1D6A7 1D7CA-1D7CD 1D800-1FFFD 2A6D7-2F7FF 2FA1E-2FFFD 30000-3FFFD 40000-4FFFD 50000-5FFFD 60000-6FFFD 70000-7FFFD 80000-8FFFD 90000-9FFFD A0000-AFFFD B0000-BFFFD C0000-CFFFD D0000-DFFFD E0000 E0002-E001F E0080-EFFFD";
|
|
18718
|
-
var RANDAL_TEXT = "5BE 5C0 5C3 5D0-5EA 5F0-5F4 61B 61F 621-63A 640-64A 66D-66F 671-6D5 6DD 6E5-6E6 6FA-6FE 700-70D 710 712-72C 780-7A5 7B1 200F FB1D FB1F-FB28 FB2A-FB36 FB38-FB3C FB3E FB40-FB41 FB43-FB44 FB46-FBB1 FBD3-FD3D FD50-FD8F FD92-FDC7 FDF0-FDFC FE70-FE74 FE76-FEFC";
|
|
18719
|
-
var LCAT_TEXT = "41-5A 61-7A AA B5 BA C0-D6 D8-F6 F8-220 222-233 250-2AD 2B0-2B8 2BB-2C1 2D0-2D1 2E0-2E4 2EE 37A 386 388-38A 38C 38E-3A1 3A3-3CE 3D0-3F5 400-482 48A-4CE 4D0-4F5 4F8-4F9 500-50F 531-556 559-55F 561-587 589 903 905-939 93D-940 949-94C 950 958-961 964-970 982-983 985-98C 98F-990 993-9A8 9AA-9B0 9B2 9B6-9B9 9BE-9C0 9C7-9C8 9CB-9CC 9D7 9DC-9DD 9DF-9E1 9E6-9F1 9F4-9FA A05-A0A A0F-A10 A13-A28 A2A-A30 A32-A33 A35-A36 A38-A39 A3E-A40 A59-A5C A5E A66-A6F A72-A74 A83 A85-A8B A8D A8F-A91 A93-AA8 AAA-AB0 AB2-AB3 AB5-AB9 ABD-AC0 AC9 ACB-ACC AD0 AE0 AE6-AEF B02-B03 B05-B0C B0F-B10 B13-B28 B2A-B30 B32-B33 B36-B39 B3D-B3E B40 B47-B48 B4B-B4C B57 B5C-B5D B5F-B61 B66-B70 B83 B85-B8A B8E-B90 B92-B95 B99-B9A B9C B9E-B9F BA3-BA4 BA8-BAA BAE-BB5 BB7-BB9 BBE-BBF BC1-BC2 BC6-BC8 BCA-BCC BD7 BE7-BF2 C01-C03 C05-C0C C0E-C10 C12-C28 C2A-C33 C35-C39 C41-C44 C60-C61 C66-C6F C82-C83 C85-C8C C8E-C90 C92-CA8 CAA-CB3 CB5-CB9 CBE CC0-CC4 CC7-CC8 CCA-CCB CD5-CD6 CDE CE0-CE1 CE6-CEF D02-D03 D05-D0C D0E-D10 D12-D28 D2A-D39 D3E-D40 D46-D48 D4A-D4C D57 D60-D61 D66-D6F D82-D83 D85-D96 D9A-DB1 DB3-DBB DBD DC0-DC6 DCF-DD1 DD8-DDF DF2-DF4 E01-E30 E32-E33 E40-E46 E4F-E5B E81-E82 E84 E87-E88 E8A E8D E94-E97 E99-E9F EA1-EA3 EA5 EA7 EAA-EAB EAD-EB0 EB2-EB3 EBD EC0-EC4 EC6 ED0-ED9 EDC-EDD F00-F17 F1A-F34 F36 F38 F3E-F47 F49-F6A F7F F85 F88-F8B FBE-FC5 FC7-FCC FCF 1000-1021 1023-1027 1029-102A 102C 1031 1038 1040-1057 10A0-10C5 10D0-10F8 10FB 1100-1159 115F-11A2 11A8-11F9 1200-1206 1208-1246 1248 124A-124D 1250-1256 1258 125A-125D 1260-1286 1288 128A-128D 1290-12AE 12B0 12B2-12B5 12B8-12BE 12C0 12C2-12C5 12C8-12CE 12D0-12D6 12D8-12EE 12F0-130E 1310 1312-1315 1318-131E 1320-1346 1348-135A 1361-137C 13A0-13F4 1401-1676 1681-169A 16A0-16F0 1700-170C 170E-1711 1720-1731 1735-1736 1740-1751 1760-176C 176E-1770 1780-17B6 17BE-17C5 17C7-17C8 17D4-17DA 17DC 17E0-17E9 1810-1819 1820-1877 1880-18A8 1E00-1E9B 1EA0-1EF9 1F00-1F15 1F18-1F1D 1F20-1F45 1F48-1F4D 1F50-1F57 1F59 1F5B 1F5D 1F5F-1F7D 1F80-1FB4 1FB6-1FBC 1FBE 1FC2-1FC4 1FC6-1FCC 1FD0-1FD3 1FD6-1FDB 1FE0-1FEC 1FF2-1FF4 1FF6-1FFC 200E 2071 207F 2102 2107 210A-2113 2115 2119-211D 2124 2126 2128 212A-212D 212F-2131 2133-2139 213D-213F 2145-2149 2160-2183 2336-237A 2395 249C-24E9 3005-3007 3021-3029 3031-3035 3038-303C 3041-3096 309D-309F 30A1-30FA 30FC-30FF 3105-312C 3131-318E 3190-31B7 31F0-321C 3220-3243 3260-327B 327F-32B0 32C0-32CB 32D0-32FE 3300-3376 337B-33DD 33E0-33FE 3400-4DB5 4E00-9FA5 A000-A48C AC00-D7A3 D800-FA2D FA30-FA6A FB00-FB06 FB13-FB17 FF21-FF3A FF41-FF5A FF66-FFBE FFC2-FFC7 FFCA-FFCF FFD2-FFD7 FFDA-FFDC 10300-1031E 10320-10323 10330-1034A 10400-10425 10428-1044D 1D000-1D0F5 1D100-1D126 1D12A-1D166 1D16A-1D172 1D183-1D184 1D18C-1D1A9 1D1AE-1D1DD 1D400-1D454 1D456-1D49C 1D49E-1D49F 1D4A2 1D4A5-1D4A6 1D4A9-1D4AC 1D4AE-1D4B9 1D4BB 1D4BD-1D4C0 1D4C2-1D4C3 1D4C5-1D505 1D507-1D50A 1D50D-1D514 1D516-1D51C 1D51E-1D539 1D53B-1D53E 1D540-1D544 1D546 1D54A-1D550 1D552-1D6A3 1D6A8-1D7C9 20000-2A6D6 2F800-2FA1D F0000-FFFFD 100000-10FFFD";
|
|
18720
|
-
var PROHIBITED = ranges(PROHIBITED_TEXT);
|
|
18721
|
-
var UNASSIGNED = ranges(UNASSIGNED_TEXT);
|
|
18722
|
-
var RANDAL = ranges(RANDAL_TEXT);
|
|
18723
|
-
var LCAT = ranges(LCAT_TEXT);
|
|
18724
|
-
function prepFails(prepared) {
|
|
18725
|
-
const codes = Array.from(prepared, (ch) => ch.codePointAt(0) ?? 0);
|
|
18726
|
-
if (codes.length === 0) return true;
|
|
18727
|
-
if (codes.some((c) => within7(PROHIBITED, c) || within7(UNASSIGNED, c))) return true;
|
|
18728
|
-
if (!codes.some((c) => within7(RANDAL, c))) return false;
|
|
18729
|
-
if (codes.some((c) => within7(LCAT, c))) return true;
|
|
18730
|
-
return !within7(RANDAL, codes[0] ?? 0) || !within7(RANDAL, codes.at(-1) ?? 0);
|
|
18801
|
+
function better(a, b) {
|
|
18802
|
+
if (!b) return true;
|
|
18803
|
+
if (a.end !== b.end) return a.end > b.end;
|
|
18804
|
+
if (a.rank !== b.rank) return a.rank < b.rank;
|
|
18805
|
+
return a.secret < b.secret;
|
|
18731
18806
|
}
|
|
18732
|
-
|
|
18733
|
-
|
|
18734
|
-
|
|
18735
|
-
|
|
18736
|
-
|
|
18737
|
-
|
|
18738
|
-
|
|
18739
|
-
|
|
18807
|
+
function resolve(c, input, start2, end, source) {
|
|
18808
|
+
if (source.form !== "fragment") {
|
|
18809
|
+
return {
|
|
18810
|
+
start: start2,
|
|
18811
|
+
end,
|
|
18812
|
+
secret: source.secret,
|
|
18813
|
+
form: source.form,
|
|
18814
|
+
rank: RANK[source.form],
|
|
18815
|
+
growing: false
|
|
18816
|
+
};
|
|
18817
|
+
}
|
|
18818
|
+
const value2 = c.values[source.secret];
|
|
18819
|
+
let stop = end;
|
|
18820
|
+
let at = source.offset + FRAGMENT;
|
|
18821
|
+
while (stop < input.length && at < value2.length && input[stop] === value2[at]) {
|
|
18822
|
+
stop++;
|
|
18823
|
+
at++;
|
|
18740
18824
|
}
|
|
18825
|
+
const form = source.offset === 0 && at === value2.length ? "raw" : "fragment";
|
|
18826
|
+
const growing = stop === input.length && at < value2.length;
|
|
18827
|
+
return { start: start2, end: stop, secret: source.secret, form, rank: RANK[form], growing };
|
|
18741
18828
|
}
|
|
18742
|
-
function
|
|
18743
|
-
|
|
18744
|
-
for (const b of bytes) bin += String.fromCharCode(b);
|
|
18745
|
-
return btoa(bin);
|
|
18829
|
+
function keep(best, candidate) {
|
|
18830
|
+
if (better(candidate, best.get(candidate.start))) best.set(candidate.start, candidate);
|
|
18746
18831
|
}
|
|
18747
|
-
function
|
|
18748
|
-
|
|
18749
|
-
|
|
18832
|
+
function scanMain(c, input, best, partials) {
|
|
18833
|
+
let state = 0;
|
|
18834
|
+
for (let i = 0; i < input.length; i++) {
|
|
18835
|
+
state = c.main.step(state, input[i]);
|
|
18836
|
+
c.main.matches(state, (id2) => {
|
|
18837
|
+
const start2 = i + 1 - c.main.lengths[id2];
|
|
18838
|
+
for (const source of c.sources[id2]) {
|
|
18839
|
+
const candidate = resolve(c, input, start2, i + 1, source);
|
|
18840
|
+
if (candidate.growing) partials.push(candidate.start);
|
|
18841
|
+
keep(best, candidate);
|
|
18842
|
+
}
|
|
18843
|
+
});
|
|
18844
|
+
}
|
|
18845
|
+
c.main.partials(state, input.length, (start2) => partials.push(start2));
|
|
18750
18846
|
}
|
|
18751
|
-
|
|
18752
|
-
|
|
18753
|
-
|
|
18754
|
-
|
|
18755
|
-
|
|
18756
|
-
|
|
18757
|
-
|
|
18758
|
-
|
|
18759
|
-
|
|
18760
|
-
|
|
18761
|
-
|
|
18762
|
-
|
|
18763
|
-
|
|
18764
|
-
|
|
18765
|
-
|
|
18766
|
-
|
|
18767
|
-
|
|
18768
|
-
|
|
18769
|
-
|
|
18770
|
-
serverFirst,
|
|
18771
|
-
clientFinalBare: fin[1],
|
|
18772
|
-
salt,
|
|
18773
|
-
iterations
|
|
18774
|
-
},
|
|
18775
|
-
proof
|
|
18776
|
-
};
|
|
18847
|
+
function scanWrapped(c, input, best, partials) {
|
|
18848
|
+
const map = [];
|
|
18849
|
+
for (let i = 0; i < input.length; i++) if (input[i] !== CR2 && input[i] !== LF2) map.push(i);
|
|
18850
|
+
if (map.length === input.length) return;
|
|
18851
|
+
let state = 0;
|
|
18852
|
+
for (let v = 0; v < map.length; v++) {
|
|
18853
|
+
state = c.wrap.step(state, input[map[v]]);
|
|
18854
|
+
c.wrap.matches(state, (id2) => {
|
|
18855
|
+
const first = v + 1 - c.wrap.lengths[id2];
|
|
18856
|
+
const start2 = map[first];
|
|
18857
|
+
const end = map[v] + 1;
|
|
18858
|
+
const wrapped = end - start2 !== c.wrap.lengths[id2];
|
|
18859
|
+
for (const source of c.wrapSources[id2]) {
|
|
18860
|
+
const form = wrapped ? "wrapped" : source.form;
|
|
18861
|
+
keep(best, { start: start2, end, secret: source.secret, form, rank: RANK[form], growing: false });
|
|
18862
|
+
}
|
|
18863
|
+
});
|
|
18864
|
+
}
|
|
18865
|
+
c.wrap.partials(state, map.length, (start2) => partials.push(map[start2]));
|
|
18777
18866
|
}
|
|
18778
|
-
|
|
18779
|
-
const
|
|
18780
|
-
|
|
18781
|
-
|
|
18782
|
-
|
|
18783
|
-
|
|
18784
|
-
["sign"]
|
|
18785
|
-
);
|
|
18786
|
-
return new Uint8Array(await crypto.subtle.sign("HMAC", k, data));
|
|
18867
|
+
function count(c, hits, candidate) {
|
|
18868
|
+
const name2 = c.secrets[candidate.secret].name;
|
|
18869
|
+
const key = `${name2}\0${candidate.form}`;
|
|
18870
|
+
const hit = hits.get(key) ?? { name: name2, form: candidate.form, count: 0 };
|
|
18871
|
+
hit.count += 1;
|
|
18872
|
+
hits.set(key, hit);
|
|
18787
18873
|
}
|
|
18788
|
-
|
|
18789
|
-
|
|
18790
|
-
|
|
18791
|
-
|
|
18792
|
-
|
|
18793
|
-
|
|
18794
|
-
|
|
18795
|
-
|
|
18796
|
-
|
|
18797
|
-
|
|
18798
|
-
iterations: x.iterations
|
|
18799
|
-
},
|
|
18800
|
-
base,
|
|
18801
|
-
256
|
|
18802
|
-
)
|
|
18803
|
-
);
|
|
18804
|
-
const clientKey = await hmac(salted, encoder8.encode("Client Key"));
|
|
18805
|
-
const stored = new Uint8Array(
|
|
18806
|
-
await crypto.subtle.digest("SHA-256", clientKey)
|
|
18807
|
-
);
|
|
18808
|
-
const auth = encoder8.encode(`${x.clientFirstBare},${x.serverFirst},${x.clientFinalBare}`);
|
|
18809
|
-
const signature = await hmac(stored, auth);
|
|
18810
|
-
const proof = clientKey.map((b, i) => b ^ signature[i]);
|
|
18811
|
-
const serverKey = await hmac(salted, encoder8.encode("Server Key"));
|
|
18812
|
-
const serverSignature = await hmac(serverKey, auth);
|
|
18813
|
-
for (const k of [salted, clientKey, stored, signature, serverKey]) k.fill(0);
|
|
18814
|
-
return { proof, serverSignature };
|
|
18874
|
+
function concat6(parts2) {
|
|
18875
|
+
let length2 = 0;
|
|
18876
|
+
for (const part of parts2) length2 += part.length;
|
|
18877
|
+
const out = new Uint8Array(length2);
|
|
18878
|
+
let at = 0;
|
|
18879
|
+
for (const part of parts2) {
|
|
18880
|
+
out.set(part, at);
|
|
18881
|
+
at += part.length;
|
|
18882
|
+
}
|
|
18883
|
+
return out;
|
|
18815
18884
|
}
|
|
18816
|
-
|
|
18817
|
-
|
|
18818
|
-
|
|
18819
|
-
|
|
18820
|
-
|
|
18821
|
-
|
|
18885
|
+
function pass(c, input, final) {
|
|
18886
|
+
const best = /* @__PURE__ */ new Map();
|
|
18887
|
+
const partials = [];
|
|
18888
|
+
scanMain(c, input, best, partials);
|
|
18889
|
+
scanWrapped(c, input, best, partials);
|
|
18890
|
+
const holds2 = final ? [] : [...new Set(partials)].sort((a, b) => a - b);
|
|
18891
|
+
const starts = [...best.keys()].sort((a, b) => a - b);
|
|
18892
|
+
const parts2 = [];
|
|
18893
|
+
const hits = /* @__PURE__ */ new Map();
|
|
18894
|
+
let pos = 0;
|
|
18895
|
+
let cut = input.length;
|
|
18896
|
+
let s = 0;
|
|
18897
|
+
let h = 0;
|
|
18898
|
+
for (; ; ) {
|
|
18899
|
+
while (s < starts.length && starts[s] < pos) s++;
|
|
18900
|
+
while (h < holds2.length && holds2[h] < pos) h++;
|
|
18901
|
+
const hold = h < holds2.length ? holds2[h] : Infinity;
|
|
18902
|
+
const next3 = s < starts.length ? starts[s] : Infinity;
|
|
18903
|
+
if (hold <= next3) {
|
|
18904
|
+
cut = Math.min(hold, input.length);
|
|
18905
|
+
break;
|
|
18906
|
+
}
|
|
18907
|
+
const candidate = best.get(next3);
|
|
18908
|
+
parts2.push(
|
|
18909
|
+
input.subarray(pos, next3),
|
|
18910
|
+
c.replacements[candidate.secret][candidate.form === "raw" ? 0 : 1]
|
|
18911
|
+
);
|
|
18912
|
+
count(c, hits, candidate);
|
|
18913
|
+
pos = candidate.end;
|
|
18914
|
+
}
|
|
18915
|
+
parts2.push(input.subarray(pos, cut));
|
|
18916
|
+
return { output: concat6(parts2), cut, hits };
|
|
18822
18917
|
}
|
|
18823
|
-
function
|
|
18824
|
-
|
|
18825
|
-
|
|
18826
|
-
|
|
18827
|
-
|
|
18918
|
+
function merge(into, from) {
|
|
18919
|
+
for (const [key, hit] of from) {
|
|
18920
|
+
const known = into.get(key);
|
|
18921
|
+
if (known) known.count += hit.count;
|
|
18922
|
+
else into.set(key, { ...hit });
|
|
18923
|
+
}
|
|
18924
|
+
}
|
|
18925
|
+
function compile(secrets, options = {}) {
|
|
18926
|
+
const c = prepare(secrets.map((secret) => ({ ...secret })));
|
|
18927
|
+
const decoder4 = new TextDecoder();
|
|
18928
|
+
const idleMs = options.idleMs ?? 250;
|
|
18929
|
+
const scrubBytes = (input) => {
|
|
18930
|
+
if (c.secrets.length === 0) return { bytes: input.slice(), hits: [] };
|
|
18931
|
+
const result = pass(c, input, true);
|
|
18932
|
+
return { bytes: result.output, hits: [...result.hits.values()] };
|
|
18933
|
+
};
|
|
18934
|
+
return {
|
|
18935
|
+
version: options.version ?? 0,
|
|
18936
|
+
idleMs,
|
|
18937
|
+
size: c.main.lengths.length,
|
|
18938
|
+
bytes: scrubBytes,
|
|
18939
|
+
text(input) {
|
|
18940
|
+
const { bytes, hits } = scrubBytes(utf82(input));
|
|
18941
|
+
return { text: decoder4.decode(bytes), hits };
|
|
18942
|
+
},
|
|
18943
|
+
stream() {
|
|
18944
|
+
let pending = EMPTY3;
|
|
18945
|
+
const hits = /* @__PURE__ */ new Map();
|
|
18946
|
+
const run2 = (final) => {
|
|
18947
|
+
if (c.secrets.length === 0 || pending.length === 0) {
|
|
18948
|
+
const out = pending;
|
|
18949
|
+
pending = EMPTY3;
|
|
18950
|
+
return out;
|
|
18951
|
+
}
|
|
18952
|
+
const result = pass(c, pending, final);
|
|
18953
|
+
merge(hits, result.hits);
|
|
18954
|
+
pending = pending.slice(result.cut);
|
|
18955
|
+
return result.output;
|
|
18956
|
+
};
|
|
18957
|
+
return {
|
|
18958
|
+
push(chunk2) {
|
|
18959
|
+
pending = concat6([pending, chunk2]);
|
|
18960
|
+
return run2(false);
|
|
18961
|
+
},
|
|
18962
|
+
idle() {
|
|
18963
|
+
return pending.length < FRAGMENT ? run2(true) : EMPTY3;
|
|
18964
|
+
},
|
|
18965
|
+
end() {
|
|
18966
|
+
return run2(true);
|
|
18967
|
+
},
|
|
18968
|
+
get hits() {
|
|
18969
|
+
return [...hits.values()];
|
|
18970
|
+
}
|
|
18971
|
+
};
|
|
18972
|
+
}
|
|
18973
|
+
};
|
|
18828
18974
|
}
|
|
18829
18975
|
|
|
18830
|
-
// src/kernel/
|
|
18831
|
-
var
|
|
18832
|
-
var
|
|
18833
|
-
var
|
|
18834
|
-
function
|
|
18835
|
-
|
|
18976
|
+
// src/kernel/scrub-file.ts
|
|
18977
|
+
var SCRUB_IDLE_MS = 50;
|
|
18978
|
+
var SCRUB_NONBLOCK_MAX = 64 * 1024;
|
|
18979
|
+
var encoder6 = new TextEncoder();
|
|
18980
|
+
function scrubberOf(secrets) {
|
|
18981
|
+
const usable2 = secrets.filter((s) => encoder6.encode(s.value).length >= MIN_VALUE);
|
|
18982
|
+
return usable2.length > 0 ? compile(usable2, { idleMs: SCRUB_IDLE_MS }) : void 0;
|
|
18836
18983
|
}
|
|
18837
|
-
function
|
|
18838
|
-
const
|
|
18839
|
-
|
|
18840
|
-
if (bytes.length < 8) return "more";
|
|
18841
|
-
const length2 = int32(bytes, 0);
|
|
18842
|
-
return length2 >= 8 && length2 <= PG_MESSAGE_MAX && int32(bytes, 4) === PROTOCOL_3 ? "yes" : "no";
|
|
18984
|
+
async function writeAll3(file, bytes) {
|
|
18985
|
+
const write = file.write;
|
|
18986
|
+
for (let at = 0; at < bytes.length; ) at += await write.call(file, bytes.subarray(at));
|
|
18843
18987
|
}
|
|
18844
|
-
|
|
18845
|
-
|
|
18846
|
-
|
|
18847
|
-
var SASL_FINAL = 12;
|
|
18848
|
-
function latin(bytes) {
|
|
18849
|
-
let out = "";
|
|
18850
|
-
for (const b of bytes) out += String.fromCharCode(b);
|
|
18851
|
-
return out;
|
|
18988
|
+
function bound(file, key) {
|
|
18989
|
+
const method = file[key];
|
|
18990
|
+
return typeof method === "function" ? { [key]: method.bind(file) } : {};
|
|
18852
18991
|
}
|
|
18853
|
-
|
|
18854
|
-
|
|
18855
|
-
|
|
18856
|
-
|
|
18857
|
-
|
|
18858
|
-
|
|
18859
|
-
|
|
18860
|
-
|
|
18861
|
-
|
|
18862
|
-
|
|
18863
|
-
|
|
18864
|
-
|
|
18865
|
-
|
|
18866
|
-
|
|
18867
|
-
|
|
18868
|
-
|
|
18869
|
-
|
|
18870
|
-
|
|
18871
|
-
|
|
18872
|
-
|
|
18873
|
-
|
|
18874
|
-
|
|
18875
|
-
}
|
|
18876
|
-
|
|
18877
|
-
|
|
18878
|
-
|
|
18879
|
-
|
|
18880
|
-
|
|
18881
|
-
|
|
18882
|
-
|
|
18883
|
-
|
|
18992
|
+
function interrupted2(err) {
|
|
18993
|
+
const code = err?.code;
|
|
18994
|
+
return code === "EINTR" || code === "EAGAIN";
|
|
18995
|
+
}
|
|
18996
|
+
function scrubbed(inner, scrubber, idleMs = SCRUB_IDLE_MS) {
|
|
18997
|
+
const file = inner.file;
|
|
18998
|
+
const stream = scrubber.stream();
|
|
18999
|
+
let tail2 = Promise.resolve();
|
|
19000
|
+
let pending = 0;
|
|
19001
|
+
let busy = false;
|
|
19002
|
+
let timer;
|
|
19003
|
+
let failed3;
|
|
19004
|
+
const waiters = /* @__PURE__ */ new Set();
|
|
19005
|
+
const quiet2 = () => !busy && pending === 0;
|
|
19006
|
+
const wake = () => {
|
|
19007
|
+
for (const waiter of [...waiters]) waiter();
|
|
19008
|
+
};
|
|
19009
|
+
const raise = () => {
|
|
19010
|
+
if (failed3 === void 0) return;
|
|
19011
|
+
const err = failed3;
|
|
19012
|
+
failed3 = void 0;
|
|
19013
|
+
throw err;
|
|
19014
|
+
};
|
|
19015
|
+
const later = (bytes) => {
|
|
19016
|
+
if (bytes.length === 0) return;
|
|
19017
|
+
pending += 1;
|
|
19018
|
+
tail2 = tail2.then(() => writeAll3(file, bytes)).catch((err) => {
|
|
19019
|
+
if (failed3 === void 0) failed3 = err;
|
|
19020
|
+
}).finally(() => {
|
|
19021
|
+
pending -= 1;
|
|
19022
|
+
if (quiet2()) wake();
|
|
19023
|
+
});
|
|
19024
|
+
};
|
|
19025
|
+
const settling = (signal) => new Promise((resolve2, reject) => {
|
|
19026
|
+
const done5 = () => {
|
|
19027
|
+
waiters.delete(done5);
|
|
19028
|
+
signal?.removeEventListener("abort", stop);
|
|
19029
|
+
resolve2();
|
|
19030
|
+
};
|
|
19031
|
+
const stop = () => {
|
|
19032
|
+
waiters.delete(done5);
|
|
19033
|
+
reject(new KernelError("EINTR"));
|
|
19034
|
+
};
|
|
19035
|
+
if (signal?.aborted) return stop();
|
|
19036
|
+
waiters.add(done5);
|
|
19037
|
+
signal?.addEventListener("abort", stop, { once: true });
|
|
19038
|
+
});
|
|
19039
|
+
const settled = async () => {
|
|
19040
|
+
while (!quiet2()) await settling();
|
|
19041
|
+
};
|
|
19042
|
+
const changed = async (signal) => {
|
|
19043
|
+
const round = new AbortController();
|
|
19044
|
+
const stop = signal ? AbortSignal.any([signal, round.signal]) : round.signal;
|
|
19045
|
+
try {
|
|
19046
|
+
const own = settling(stop);
|
|
19047
|
+
await Promise.race(file.changed ? [own, file.changed(stop)] : [own]);
|
|
19048
|
+
} catch (err) {
|
|
19049
|
+
throw signal?.aborted ? new KernelError("EINTR") : err;
|
|
19050
|
+
} finally {
|
|
19051
|
+
round.abort();
|
|
18884
19052
|
}
|
|
18885
|
-
|
|
18886
|
-
|
|
18887
|
-
|
|
18888
|
-
|
|
18889
|
-
|
|
18890
|
-
|
|
18891
|
-
if (this.expect) this.failed = true;
|
|
18892
|
-
this.expect = void 0;
|
|
18893
|
-
}
|
|
18894
|
-
filter(bytes) {
|
|
18895
|
-
if (this.lost) return bytes;
|
|
18896
|
-
const data = new Uint8Array(this.buffer.length + bytes.length);
|
|
18897
|
-
data.set(this.buffer);
|
|
18898
|
-
data.set(bytes, this.buffer.length);
|
|
18899
|
-
const out = [];
|
|
18900
|
-
let at = 0;
|
|
18901
|
-
for (; ; ) {
|
|
18902
|
-
const left = data.length - at;
|
|
18903
|
-
if (this.skip > 0) {
|
|
18904
|
-
const n = Math.min(this.skip, left);
|
|
18905
|
-
out.push(data.subarray(at, at + n));
|
|
18906
|
-
this.skip -= n;
|
|
18907
|
-
at += n;
|
|
18908
|
-
if (this.skip > 0) break;
|
|
18909
|
-
continue;
|
|
19053
|
+
};
|
|
19054
|
+
const turn = async (signal) => {
|
|
19055
|
+
for (let waited = false; ; waited = true) {
|
|
19056
|
+
if (quiet2() && (pollFile(file).writable || !file.changed)) {
|
|
19057
|
+
busy = true;
|
|
19058
|
+
return;
|
|
18910
19059
|
}
|
|
18911
|
-
if (
|
|
18912
|
-
|
|
18913
|
-
|
|
18914
|
-
|
|
18915
|
-
|
|
18916
|
-
|
|
18917
|
-
|
|
19060
|
+
if (signal?.aborted) throw new KernelError(waited ? "EINTR" : "EAGAIN");
|
|
19061
|
+
await changed(signal);
|
|
19062
|
+
}
|
|
19063
|
+
};
|
|
19064
|
+
const send2 = async (out, signal) => {
|
|
19065
|
+
const write = file.write;
|
|
19066
|
+
for (let at = 0; at < out.length; ) {
|
|
19067
|
+
try {
|
|
19068
|
+
at += await write.call(file, out.subarray(at), signal);
|
|
19069
|
+
} catch (err) {
|
|
19070
|
+
if (!signal?.aborted || !interrupted2(err)) throw err;
|
|
18918
19071
|
}
|
|
18919
|
-
if (
|
|
18920
|
-
|
|
18921
|
-
|
|
18922
|
-
|
|
19072
|
+
if (at < out.length && signal?.aborted) return later(out.subarray(at));
|
|
19073
|
+
}
|
|
19074
|
+
};
|
|
19075
|
+
const release = () => {
|
|
19076
|
+
timer = void 0;
|
|
19077
|
+
later(stream.idle());
|
|
19078
|
+
};
|
|
19079
|
+
return new OpenFile({
|
|
19080
|
+
...bound(file, "read"),
|
|
19081
|
+
...bound(file, "peek"),
|
|
19082
|
+
...bound(file, "stat"),
|
|
19083
|
+
poll: () => {
|
|
19084
|
+
const state = pollFile(file);
|
|
19085
|
+
return quiet2() ? state : { ...state, writable: false };
|
|
19086
|
+
},
|
|
19087
|
+
changed,
|
|
19088
|
+
...file.tty ? { tty: file.tty } : {},
|
|
19089
|
+
identity: file.identity ?? file,
|
|
19090
|
+
...file.clipboard ? { clipboard: file.clipboard } : {},
|
|
19091
|
+
...file.write ? {
|
|
19092
|
+
write: async (bytes, signal) => {
|
|
19093
|
+
await turn(signal);
|
|
19094
|
+
const taken = signal?.aborted && bytes.length > SCRUB_NONBLOCK_MAX ? bytes.subarray(0, SCRUB_NONBLOCK_MAX) : bytes;
|
|
19095
|
+
try {
|
|
19096
|
+
raise();
|
|
19097
|
+
if (timer !== void 0) clearTimeout(timer);
|
|
19098
|
+
timer = void 0;
|
|
19099
|
+
await send2(stream.push(taken), signal);
|
|
19100
|
+
} finally {
|
|
19101
|
+
busy = false;
|
|
19102
|
+
if (quiet2()) wake();
|
|
18923
19103
|
}
|
|
18924
|
-
|
|
18925
|
-
|
|
19104
|
+
timer = setTimeout(release, idleMs);
|
|
19105
|
+
return taken.length;
|
|
18926
19106
|
}
|
|
18927
|
-
|
|
18928
|
-
|
|
18929
|
-
|
|
19107
|
+
} : {},
|
|
19108
|
+
flush: async () => {
|
|
19109
|
+
await settled();
|
|
19110
|
+
raise();
|
|
19111
|
+
await file.flush?.();
|
|
19112
|
+
},
|
|
19113
|
+
close: async () => {
|
|
19114
|
+
if (timer !== void 0) clearTimeout(timer);
|
|
19115
|
+
let failure2;
|
|
19116
|
+
try {
|
|
19117
|
+
await settled();
|
|
19118
|
+
later(stream.end());
|
|
19119
|
+
await settled();
|
|
19120
|
+
raise();
|
|
19121
|
+
} catch (err) {
|
|
19122
|
+
failure2 = { err };
|
|
19123
|
+
}
|
|
19124
|
+
await inner.release();
|
|
19125
|
+
if (failure2) throw failure2.err;
|
|
18930
19126
|
}
|
|
18931
|
-
|
|
18932
|
-
|
|
18933
|
-
|
|
18934
|
-
|
|
18935
|
-
|
|
18936
|
-
|
|
19127
|
+
});
|
|
19128
|
+
}
|
|
19129
|
+
function scrubbedAll(file, scrubbers) {
|
|
19130
|
+
return scrubbers.reduce((inner, scrubber) => scrubbed(inner, scrubber), file);
|
|
19131
|
+
}
|
|
19132
|
+
function stdioFiles(fds) {
|
|
19133
|
+
const files = /* @__PURE__ */ new Set();
|
|
19134
|
+
for (const fd of [1, 2]) {
|
|
19135
|
+
try {
|
|
19136
|
+
files.add(fds.get(fd));
|
|
19137
|
+
} catch {
|
|
18937
19138
|
}
|
|
18938
|
-
return joined4;
|
|
18939
19139
|
}
|
|
18940
|
-
|
|
18941
|
-
function frame3(type, body) {
|
|
18942
|
-
const out = new Uint8Array(5 + body.length);
|
|
18943
|
-
out[0] = type;
|
|
18944
|
-
const length2 = 4 + body.length;
|
|
18945
|
-
out.set([length2 >>> 24 & 255, length2 >>> 16 & 255, length2 >>> 8 & 255, length2 & 255], 1);
|
|
18946
|
-
for (let i = 0; i < body.length; i++) out[5 + i] = body.charCodeAt(i);
|
|
18947
|
-
return out;
|
|
18948
|
-
}
|
|
18949
|
-
function pgLength(bytes, started) {
|
|
18950
|
-
const header3 = started ? 5 : 4;
|
|
18951
|
-
if (bytes.length < header3) return void 0;
|
|
18952
|
-
const length2 = int32(bytes, started ? 1 : 0);
|
|
18953
|
-
return started ? 1 + length2 : length2;
|
|
19140
|
+
return files;
|
|
18954
19141
|
}
|
|
18955
|
-
|
|
18956
|
-
|
|
18957
|
-
const
|
|
18958
|
-
|
|
18959
|
-
|
|
18960
|
-
|
|
18961
|
-
|
|
18962
|
-
|
|
18963
|
-
|
|
18964
|
-
|
|
18965
|
-
|
|
18966
|
-
|
|
19142
|
+
function scrubStdio(fds, scrubber) {
|
|
19143
|
+
const wrapped = /* @__PURE__ */ new Map();
|
|
19144
|
+
const stdio = stdioFiles(fds);
|
|
19145
|
+
for (const fd of fds.numbers()) {
|
|
19146
|
+
const original = fds.get(fd);
|
|
19147
|
+
if (!stdio.has(original) && !original.file.tty && !original.file.clipboard) continue;
|
|
19148
|
+
const known = wrapped.get(original);
|
|
19149
|
+
const flags2 = fds.statusFlags(fd);
|
|
19150
|
+
const wrapper = known ? known.retain() : scrubbed(original.retain(), scrubber);
|
|
19151
|
+
wrapped.set(original, wrapper);
|
|
19152
|
+
fds.installAt(fd, wrapper);
|
|
19153
|
+
if (flags2 !== void 0) fds.setStatusFlags(fd, flags2);
|
|
19154
|
+
}
|
|
18967
19155
|
}
|
|
18968
|
-
function initial(message3) {
|
|
18969
|
-
const body = latin(message3.subarray(5));
|
|
18970
|
-
const nul = body.indexOf("\0");
|
|
18971
|
-
if (nul < 0 || !MECHANISMS.has(body.slice(0, nul)) || body.length < nul + 5) return void 0;
|
|
18972
|
-
const data = message3.subarray(5 + nul + 5);
|
|
18973
|
-
return int32(message3, 5 + nul + 1) === data.length ? latin(data) : void 0;
|
|
18974
|
-
}
|
|
18975
|
-
var PgClient = class {
|
|
18976
|
-
clientFirst;
|
|
18977
|
-
server;
|
|
18978
|
-
asks;
|
|
18979
|
-
constructor(server, asks) {
|
|
18980
|
-
this.server = server;
|
|
18981
|
-
this.asks = asks;
|
|
18982
|
-
}
|
|
18983
|
-
async message(message3) {
|
|
18984
|
-
const server = this.server;
|
|
18985
|
-
if (message3[0] !== 112) return { bytes: message3, done: true };
|
|
18986
|
-
if (server.cleartext) {
|
|
18987
|
-
server.cleartext = false;
|
|
18988
|
-
return cleartext(message3, this.asks);
|
|
18989
|
-
}
|
|
18990
|
-
if (server.sasl && this.clientFirst === void 0) {
|
|
18991
|
-
this.clientFirst = initial(message3);
|
|
18992
|
-
return { bytes: message3, done: this.clientFirst === void 0 };
|
|
18993
|
-
}
|
|
18994
|
-
if (this.clientFirst !== void 0 && server.serverFirst !== void 0)
|
|
18995
|
-
return this.final(message3, this.clientFirst, server.serverFirst);
|
|
18996
|
-
return { bytes: message3, done: true };
|
|
18997
|
-
}
|
|
18998
|
-
async final(message3, first, serverFirst) {
|
|
18999
|
-
const got = exchangeOf(first, serverFirst, latin(message3.subarray(5)));
|
|
19000
|
-
if (!got) return { bytes: message3, done: true };
|
|
19001
|
-
const x = got.exchange;
|
|
19002
|
-
const values = usable(
|
|
19003
|
-
await this.asks.scram({
|
|
19004
|
-
clientFirstBare: x.clientFirstBare,
|
|
19005
|
-
serverFirst: x.serverFirst,
|
|
19006
|
-
clientFinalBare: x.clientFinalBare,
|
|
19007
|
-
proof: base64Of(got.proof)
|
|
19008
|
-
})
|
|
19009
|
-
);
|
|
19010
|
-
const [entry, ...more] = Object.entries(values);
|
|
19011
|
-
if (!entry || more.length > 0) return { bytes: message3, done: true };
|
|
19012
|
-
const [placeholder, value2] = entry;
|
|
19013
|
-
const fake = await scramKeys(placeholder, x);
|
|
19014
|
-
if (!sameBytes(fake.proof, got.proof)) return { bytes: message3, done: true };
|
|
19015
|
-
const real = await scramKeys(saslprep(value2), x);
|
|
19016
|
-
this.server.expect = {
|
|
19017
|
-
real: `v=${base64Of(real.serverSignature)}`,
|
|
19018
|
-
fake: `v=${base64Of(fake.serverSignature)}`
|
|
19019
|
-
};
|
|
19020
|
-
const bytes = frame3(112, `${x.clientFinalBare},p=${base64Of(real.proof)}`);
|
|
19021
|
-
for (const k of [real.proof, real.serverSignature, fake.proof, fake.serverSignature]) k.fill(0);
|
|
19022
|
-
return { bytes, values, done: true };
|
|
19023
|
-
}
|
|
19024
|
-
};
|
|
19025
19156
|
|
|
19026
|
-
// src/kernel/net/sealed-
|
|
19027
|
-
var
|
|
19028
|
-
|
|
19029
|
-
|
|
19030
|
-
|
|
19031
|
-
|
|
19032
|
-
|
|
19033
|
-
|
|
19157
|
+
// src/kernel/net/sealed-http1.ts
|
|
19158
|
+
var HTTP1_METHODS = [
|
|
19159
|
+
"GET",
|
|
19160
|
+
"HEAD",
|
|
19161
|
+
"POST",
|
|
19162
|
+
"PUT",
|
|
19163
|
+
"DELETE",
|
|
19164
|
+
"PATCH",
|
|
19165
|
+
"OPTIONS",
|
|
19166
|
+
"CONNECT",
|
|
19167
|
+
"TRACE"
|
|
19168
|
+
];
|
|
19169
|
+
var HEAD_MAX = 16 * 1024;
|
|
19170
|
+
var ANY_PLACEHOLDER = /fnox_proxy_[0-9a-f]{24}/g;
|
|
19171
|
+
var REQUEST_LINE2 = /^([!#$%&'*+.^_`|~0-9A-Za-z-]+) ([\x21-\x7e]+) HTTP\/1\.[01]$/;
|
|
19172
|
+
var HEADER_LINE = /^([!#$%&'*+.^_`|~0-9A-Za-z-]+):[ \t]*(.*?)[ \t]*$/;
|
|
19173
|
+
var BASIC = /^(Basic[ \t]+)([A-Za-z0-9+/]+={0,2})$/i;
|
|
19174
|
+
var encoder7 = new TextEncoder();
|
|
19175
|
+
function binary(text) {
|
|
19176
|
+
let out = "";
|
|
19177
|
+
for (const b of encoder7.encode(text)) out += String.fromCharCode(b);
|
|
19178
|
+
return out;
|
|
19179
|
+
}
|
|
19180
|
+
function sniffHttp1(start2) {
|
|
19181
|
+
for (const method of HTTP1_METHODS) {
|
|
19182
|
+
const word = `${method} `;
|
|
19183
|
+
if (start2.startsWith(word)) return "yes";
|
|
19184
|
+
if (word.startsWith(start2)) return "more";
|
|
19034
19185
|
}
|
|
19035
19186
|
return "no";
|
|
19036
19187
|
}
|
|
19037
|
-
function
|
|
19038
|
-
|
|
19188
|
+
function basicOf(value2) {
|
|
19189
|
+
const m = BASIC.exec(value2);
|
|
19190
|
+
if (!m) return void 0;
|
|
19039
19191
|
try {
|
|
19040
|
-
return atob(
|
|
19192
|
+
return { scheme: m[1], decoded: atob(m[2]) };
|
|
19041
19193
|
} catch {
|
|
19042
19194
|
return void 0;
|
|
19043
19195
|
}
|
|
19044
19196
|
}
|
|
19045
|
-
|
|
19046
|
-
|
|
19047
|
-
if (placeholders.length === 0 || placeholders.length > SESSION_PLACEHOLDERS) return void 0;
|
|
19048
|
-
const values = usable(await ask(position, placeholders));
|
|
19049
|
-
if (Object.keys(values).length === 0) return void 0;
|
|
19050
|
-
return { text: replaced(text, values), values };
|
|
19051
|
-
}
|
|
19052
|
-
async function plain2(b64, ask) {
|
|
19053
|
-
const text = decoded(b64);
|
|
19054
|
-
const fields = text?.split("\0");
|
|
19055
|
-
if (fields?.length !== 3) return { line: b64 };
|
|
19056
|
-
const [authz, user, pass2] = fields;
|
|
19057
|
-
if (placeholdersIn(authz + user).length > 0) return { line: b64 };
|
|
19058
|
-
const done5 = await swapped2(pass2, "auth-plain", ask);
|
|
19059
|
-
if (!done5) return { line: b64 };
|
|
19060
|
-
return { line: btoa(`${authz}\0${user}\0${done5.text}`), values: done5.values };
|
|
19061
|
-
}
|
|
19062
|
-
async function login(b64, ask) {
|
|
19063
|
-
const text = decoded(b64);
|
|
19064
|
-
const done5 = text === void 0 ? void 0 : await swapped2(text, "auth-login", ask);
|
|
19065
|
-
return done5 ? { line: btoa(done5.text), values: done5.values } : { line: b64 };
|
|
19197
|
+
function placeholdersIn(text) {
|
|
19198
|
+
return [...new Set(text.match(ANY_PLACEHOLDER) ?? [])];
|
|
19066
19199
|
}
|
|
19067
|
-
|
|
19068
|
-
|
|
19069
|
-
|
|
19070
|
-
|
|
19071
|
-
|
|
19072
|
-
|
|
19073
|
-
|
|
19074
|
-
|
|
19075
|
-
|
|
19076
|
-
|
|
19077
|
-
const state = this.state;
|
|
19078
|
-
if (state === "done") return { line: text };
|
|
19079
|
-
if (state === "plain" || state === "password") {
|
|
19080
|
-
this.state = "done";
|
|
19081
|
-
if (text === "*") return { line: text };
|
|
19082
|
-
return state === "plain" ? plain2(text, this.ask) : login(text, this.ask);
|
|
19083
|
-
}
|
|
19084
|
-
if (state === "user") {
|
|
19085
|
-
this.state = text === "*" ? "done" : "password";
|
|
19086
|
-
return { line: text };
|
|
19087
|
-
}
|
|
19088
|
-
return this.command(text);
|
|
19089
|
-
}
|
|
19090
|
-
async command(text) {
|
|
19091
|
-
const m = /^AUTH[ \t]+(PLAIN|LOGIN)(?:[ \t]+(\S+))?$/i.exec(text);
|
|
19092
|
-
if (!m) {
|
|
19093
|
-
if (/^(MAIL|RCPT|DATA|BDAT|AUTH)\b/i.test(text)) this.state = "done";
|
|
19094
|
-
return { line: text };
|
|
19095
|
-
}
|
|
19096
|
-
const mech = m[1].toUpperCase();
|
|
19097
|
-
const arg = m[2];
|
|
19098
|
-
if (mech === "LOGIN") {
|
|
19099
|
-
this.state = arg === void 0 ? "user" : "password";
|
|
19100
|
-
return { line: text };
|
|
19101
|
-
}
|
|
19102
|
-
if (arg === void 0) {
|
|
19103
|
-
this.state = "plain";
|
|
19104
|
-
return { line: text };
|
|
19105
|
-
}
|
|
19106
|
-
this.state = "done";
|
|
19107
|
-
const out = await plain2(arg, this.ask);
|
|
19108
|
-
return {
|
|
19109
|
-
line: `${text.slice(0, text.length - arg.length)}${out.line}`,
|
|
19110
|
-
...out.values ? { values: out.values } : {}
|
|
19111
|
-
};
|
|
19200
|
+
function scan(lines2) {
|
|
19201
|
+
const found = [];
|
|
19202
|
+
for (let i = 1; i < lines2.length; i++) {
|
|
19203
|
+
const m = HEADER_LINE.exec(lines2[i]);
|
|
19204
|
+
if (!m) return void 0;
|
|
19205
|
+
const value2 = m[2];
|
|
19206
|
+
const basic = basicOf(value2);
|
|
19207
|
+
const placeholders = placeholdersIn(basic ? basic.decoded : value2);
|
|
19208
|
+
if (placeholders.length > 0)
|
|
19209
|
+
found.push({ line: i, name: m[1].toLowerCase(), value: value2, basic, placeholders });
|
|
19112
19210
|
}
|
|
19113
|
-
|
|
19114
|
-
|
|
19115
|
-
// src/kernel/net/sealed-conn.ts
|
|
19116
|
-
var HEAD_IDLE_MS = 2e3;
|
|
19117
|
-
function substitutes(s) {
|
|
19118
|
-
return s.verified && s.alpn !== "h2" && s.broker.hook !== void 0 && typeof s.exit === "string" && SESSION_EXIT.test(s.exit);
|
|
19119
|
-
}
|
|
19120
|
-
function sessionId() {
|
|
19121
|
-
const bytes = crypto.getRandomValues(new Uint8Array(24));
|
|
19122
|
-
let bin = "";
|
|
19123
|
-
for (const b of bytes) bin += String.fromCharCode(b);
|
|
19124
|
-
return btoa(bin).replace(/\+/g, "-").replace(/\//g, "_");
|
|
19211
|
+
return found;
|
|
19125
19212
|
}
|
|
19126
|
-
function
|
|
19127
|
-
let out =
|
|
19128
|
-
for (const
|
|
19213
|
+
function replaced(text, values) {
|
|
19214
|
+
let out = text;
|
|
19215
|
+
for (const [ph, value2] of Object.entries(values)) out = out.split(ph).join(binary(value2));
|
|
19129
19216
|
return out;
|
|
19130
19217
|
}
|
|
19131
|
-
function
|
|
19132
|
-
const out =
|
|
19133
|
-
for (
|
|
19218
|
+
function usable(values) {
|
|
19219
|
+
const out = {};
|
|
19220
|
+
for (const [ph, value2] of Object.entries(values ?? {}))
|
|
19221
|
+
if (encoder7.encode(value2).length >= MIN_VALUE) out[ph] = value2;
|
|
19134
19222
|
return out;
|
|
19135
19223
|
}
|
|
19136
|
-
async function
|
|
19137
|
-
|
|
19138
|
-
|
|
19139
|
-
|
|
19140
|
-
|
|
19141
|
-
|
|
19142
|
-
|
|
19143
|
-
|
|
19144
|
-
return
|
|
19224
|
+
async function substituteHead(head, ask) {
|
|
19225
|
+
if (!head.endsWith("\r\n\r\n")) return void 0;
|
|
19226
|
+
const lines2 = head.slice(0, -4).split("\r\n");
|
|
19227
|
+
if (lines2.some((l) => l.includes("\n") || l.includes("\r"))) return void 0;
|
|
19228
|
+
const request3 = REQUEST_LINE2.exec(lines2[0]);
|
|
19229
|
+
const found = request3 ? scan(lines2) : void 0;
|
|
19230
|
+
if (!request3 || !found || found.length !== 1) return void 0;
|
|
19231
|
+
const at = found[0];
|
|
19232
|
+
if (at.placeholders.length > SESSION_PLACEHOLDERS) return void 0;
|
|
19233
|
+
const values = usable(
|
|
19234
|
+
await ask(`header:${at.name}`, at.placeholders, {
|
|
19235
|
+
method: request3[1],
|
|
19236
|
+
path: request3[2]
|
|
19237
|
+
})
|
|
19238
|
+
);
|
|
19239
|
+
if (Object.keys(values).length === 0) return void 0;
|
|
19240
|
+
const value2 = at.basic ? `${at.basic.scheme}${btoa(replaced(at.basic.decoded, values))}` : replaced(at.value, values);
|
|
19241
|
+
const out = [...lines2];
|
|
19242
|
+
out[at.line] = `${lines2[at.line].split(":")[0]}: ${value2}`;
|
|
19243
|
+
return { head: `${out.join("\r\n")}\r
|
|
19244
|
+
\r
|
|
19245
|
+
`, values };
|
|
19145
19246
|
}
|
|
19146
|
-
|
|
19147
|
-
|
|
19148
|
-
|
|
19149
|
-
|
|
19150
|
-
["
|
|
19151
|
-
|
|
19152
|
-
|
|
19153
|
-
if (hit) return hit[0];
|
|
19154
|
-
return sniffs.every(([, v]) => v === "no") ? "pass" : void 0;
|
|
19247
|
+
|
|
19248
|
+
// src/kernel/net/saslprep-tables.ts
|
|
19249
|
+
function ranges(text) {
|
|
19250
|
+
return text.split(" ").map((item) => {
|
|
19251
|
+
const [lo = "0", hi = lo] = item.split("-");
|
|
19252
|
+
return [Number.parseInt(lo, 16), Number.parseInt(hi, 16)];
|
|
19253
|
+
});
|
|
19155
19254
|
}
|
|
19156
|
-
function
|
|
19157
|
-
|
|
19158
|
-
|
|
19255
|
+
function within7(table, code) {
|
|
19256
|
+
let lo = 0;
|
|
19257
|
+
let hi = table.length - 1;
|
|
19258
|
+
while (lo <= hi) {
|
|
19259
|
+
const mid = lo + hi >> 1;
|
|
19260
|
+
const [from, to] = table[mid];
|
|
19261
|
+
if (code < from) hi = mid - 1;
|
|
19262
|
+
else if (code > to) lo = mid + 1;
|
|
19263
|
+
else return true;
|
|
19264
|
+
}
|
|
19265
|
+
return false;
|
|
19159
19266
|
}
|
|
19160
|
-
var
|
|
19161
|
-
|
|
19162
|
-
|
|
19163
|
-
|
|
19164
|
-
|
|
19165
|
-
|
|
19166
|
-
|
|
19167
|
-
|
|
19168
|
-
|
|
19169
|
-
|
|
19170
|
-
|
|
19171
|
-
|
|
19172
|
-
|
|
19173
|
-
|
|
19174
|
-
|
|
19175
|
-
|
|
19176
|
-
|
|
19177
|
-
|
|
19178
|
-
|
|
19179
|
-
|
|
19180
|
-
|
|
19181
|
-
|
|
19182
|
-
|
|
19183
|
-
|
|
19184
|
-
);
|
|
19185
|
-
}
|
|
19186
|
-
write(bytes) {
|
|
19187
|
-
const run2 = this.chain.then(() => this.take(bytes));
|
|
19188
|
-
this.chain = run2.then(
|
|
19189
|
-
() => void 0,
|
|
19190
|
-
() => void 0
|
|
19191
|
-
);
|
|
19192
|
-
return run2;
|
|
19193
|
-
}
|
|
19194
|
-
async ask(protocol, position, extra) {
|
|
19195
|
-
const s = this.s;
|
|
19196
|
-
const values = await s.broker.sessionMaterialize({
|
|
19197
|
-
stamp: await s.stamp(),
|
|
19198
|
-
session: this.session,
|
|
19199
|
-
host: s.host,
|
|
19200
|
-
port: s.port,
|
|
19201
|
-
protocol,
|
|
19202
|
-
position,
|
|
19203
|
-
verified: s.verified,
|
|
19204
|
-
handshakeAt: s.handshakeAt,
|
|
19205
|
-
exit: s.exit,
|
|
19206
|
-
...extra
|
|
19207
|
-
});
|
|
19208
|
-
return values;
|
|
19209
|
-
}
|
|
19210
|
-
remember(values) {
|
|
19211
|
-
this.scope.add(
|
|
19212
|
-
Object.entries(values).map(([placeholder, value2]) => ({ name: "sealed", value: value2, placeholder }))
|
|
19213
|
-
);
|
|
19214
|
-
}
|
|
19215
|
-
async take(bytes) {
|
|
19216
|
-
if (this.failed !== void 0) throw this.failed;
|
|
19217
|
-
if (this.mode === "pass") return this.conn.write(bytes);
|
|
19218
|
-
clearTimeout(this.timer);
|
|
19219
|
-
const joined4 = new Uint8Array(this.buffer.length + bytes.length);
|
|
19220
|
-
joined4.set(this.buffer);
|
|
19221
|
-
joined4.set(bytes, this.buffer.length);
|
|
19222
|
-
this.buffer.fill(0);
|
|
19223
|
-
this.buffer = joined4;
|
|
19224
|
-
if (this.mode === "sniff") this.mode = modeOf(latin12(joined4.subarray(0, 8))) ?? "sniff";
|
|
19225
|
-
if (this.mode === "pg") this.sawPg = true;
|
|
19226
|
-
if (this.mode === "pass") await this.release();
|
|
19227
|
-
else if (this.mode === "http1") await this.http1();
|
|
19228
|
-
else if (this.mode === "smtp") await this.lines();
|
|
19229
|
-
else if (this.mode === "pg") await this.messages();
|
|
19230
|
-
if (this.mode !== "pass" && this.buffer.length > 0)
|
|
19231
|
-
this.timer = setTimeout(() => this.idle(), HEAD_IDLE_MS);
|
|
19232
|
-
return bytes.length;
|
|
19233
|
-
}
|
|
19234
|
-
async http1() {
|
|
19235
|
-
const end = headEnd2(this.buffer);
|
|
19236
|
-
if (end > HEAD_MAX || end < 0 && this.buffer.length > HEAD_MAX) await this.release();
|
|
19237
|
-
else if (end >= 0) await this.substitute(end);
|
|
19238
|
-
}
|
|
19239
|
-
async lines() {
|
|
19240
|
-
for (; ; ) {
|
|
19241
|
-
const at = crlf(this.buffer);
|
|
19242
|
-
if (at < 0) break;
|
|
19243
|
-
if (at > SMTP_LINE_MAX) return this.release();
|
|
19244
|
-
const all = this.buffer;
|
|
19245
|
-
this.buffer = all.slice(at + 2);
|
|
19246
|
-
const out = await this.smtp.line(latin12(all.subarray(0, at))).catch(() => ({ line: latin12(all.subarray(0, at)) }));
|
|
19247
|
-
all.fill(0);
|
|
19248
|
-
if ("values" in out && out.values) this.remember(out.values);
|
|
19249
|
-
const line = bytesOf(`${out.line}\r
|
|
19250
|
-
`);
|
|
19251
|
-
try {
|
|
19252
|
-
await writeAll4(this.conn, line);
|
|
19253
|
-
} finally {
|
|
19254
|
-
line.fill(0);
|
|
19255
|
-
}
|
|
19256
|
-
if (this.smtp.done) return this.release();
|
|
19257
|
-
}
|
|
19258
|
-
if (this.buffer.length > SMTP_LINE_MAX) await this.release();
|
|
19259
|
-
}
|
|
19260
|
-
async messages() {
|
|
19261
|
-
for (; ; ) {
|
|
19262
|
-
const whole = pgLength(this.buffer, this.pgStarted);
|
|
19263
|
-
if (whole === void 0 || whole < 4 || whole > PG_MESSAGE_MAX) {
|
|
19264
|
-
if (whole !== void 0) await this.release();
|
|
19265
|
-
return;
|
|
19266
|
-
}
|
|
19267
|
-
if (this.buffer.length < whole) return;
|
|
19268
|
-
const message3 = this.buffer.slice(0, whole);
|
|
19269
|
-
this.buffer = this.buffer.slice(whole);
|
|
19270
|
-
const started = this.pgStarted;
|
|
19271
|
-
this.pgStarted = true;
|
|
19272
|
-
const out = started ? await this.pgClient.message(message3).catch(() => ({ bytes: message3, done: true })) : { bytes: message3, done: false };
|
|
19273
|
-
if ("values" in out && out.values) this.remember(out.values);
|
|
19274
|
-
try {
|
|
19275
|
-
await writeAll4(this.conn, out.bytes);
|
|
19276
|
-
} finally {
|
|
19277
|
-
out.bytes.fill(0);
|
|
19278
|
-
message3.fill(0);
|
|
19279
|
-
}
|
|
19280
|
-
if (out.done) return this.release();
|
|
19281
|
-
}
|
|
19267
|
+
var PROHIBITED_TEXT = "0-1F 7F-A0 340-341 6DD 70F 1680 180E 2000-200F 2028-202F 205F-2063 206A-206F 2FF0-2FFB 3000 D800-F8FF FDD0-FDEF FEFF FFF9-FFFF 1D173-1D17A 1FFFE-1FFFF 2FFFE-2FFFF 3FFFE-3FFFF 4FFFE-4FFFF 5FFFE-5FFFF 6FFFE-6FFFF 7FFFE-7FFFF 8FFFE-8FFFF 9FFFE-9FFFF AFFFE-AFFFF BFFFE-BFFFF CFFFE-CFFFF DFFFE-DFFFF E0001 E0020-E007F EFFFE-10FFFF";
|
|
19268
|
+
var UNASSIGNED_TEXT = "221 234-24F 2AE-2AF 2EF-2FF 350-35F 370-373 376-379 37B-37D 37F-383 38B 38D 3A2 3CF 3F7-3FF 487 4CF 4F6-4F7 4FA-4FF 510-530 557-558 560 588 58B-590 5A2 5BA 5C5-5CF 5EB-5EF 5F5-60B 60D-61A 61C-61E 620 63B-63F 656-65F 6EE-6EF 6FF 70E 72D-72F 74B-77F 7B2-900 904 93A-93B 94E-94F 955-957 971-980 984 98D-98E 991-992 9A9 9B1 9B3-9B5 9BA-9BB 9BD 9C5-9C6 9C9-9CA 9CE-9D6 9D8-9DB 9DE 9E4-9E5 9FB-A01 A03-A04 A0B-A0E A11-A12 A29 A31 A34 A37 A3A-A3B A3D A43-A46 A49-A4A A4E-A58 A5D A5F-A65 A75-A80 A84 A8C A8E A92 AA9 AB1 AB4 ABA-ABB AC6 ACA ACE-ACF AD1-ADF AE1-AE5 AF0-B00 B04 B0D-B0E B11-B12 B29 B31 B34-B35 B3A-B3B B44-B46 B49-B4A B4E-B55 B58-B5B B5E B62-B65 B71-B81 B84 B8B-B8D B91 B96-B98 B9B B9D BA0-BA2 BA5-BA7 BAB-BAD BB6 BBA-BBD BC3-BC5 BC9 BCE-BD6 BD8-BE6 BF3-C00 C04 C0D C11 C29 C34 C3A-C3D C45 C49 C4E-C54 C57-C5F C62-C65 C70-C81 C84 C8D C91 CA9 CB4 CBA-CBD CC5 CC9 CCE-CD4 CD7-CDD CDF CE2-CE5 CF0-D01 D04 D0D D11 D29 D3A-D3D D44-D45 D49 D4E-D56 D58-D5F D62-D65 D70-D81 D84 D97-D99 DB2 DBC DBE-DBF DC7-DC9 DCB-DCE DD5 DD7 DE0-DF1 DF5-E00 E3B-E3E E5C-E80 E83 E85-E86 E89 E8B-E8C E8E-E93 E98 EA0 EA4 EA6 EA8-EA9 EAC EBA EBE-EBF EC5 EC7 ECE-ECF EDA-EDB EDE-EFF F48 F6B-F70 F8C-F8F F98 FBD FCD-FCE FD0-FFF 1022 1028 102B 1033-1035 103A-103F 105A-109F 10C6-10CF 10F9-10FA 10FC-10FF 115A-115E 11A3-11A7 11FA-11FF 1207 1247 1249 124E-124F 1257 1259 125E-125F 1287 1289 128E-128F 12AF 12B1 12B6-12B7 12BF 12C1 12C6-12C7 12CF 12D7 12EF 130F 1311 1316-1317 131F 1347 135B-1360 137D-139F 13F5-1400 1677-167F 169D-169F 16F1-16FF 170D 1715-171F 1737-173F 1754-175F 176D 1771 1774-177F 17DD-17DF 17EA-17FF 180F 181A-181F 1878-187F 18AA-1DFF 1E9C-1E9F 1EFA-1EFF 1F16-1F17 1F1E-1F1F 1F46-1F47 1F4E-1F4F 1F58 1F5A 1F5C 1F5E 1F7E-1F7F 1FB5 1FC5 1FD4-1FD5 1FDC 1FF0-1FF1 1FF5 1FFF 2053-2056 2058-205E 2064-2069 2072-2073 208F-209F 20B2-20CF 20EB-20FF 213B-213C 214C-2152 2184-218F 23CF-23FF 2427-243F 244B-245F 24FF 2614-2615 2618 267E-267F 268A-2700 2705 270A-270B 2728 274C 274E 2753-2755 2757 275F-2760 2795-2797 27B0 27BF-27CF 27EC-27EF 2B00-2E7F 2E9A 2EF4-2EFF 2FD6-2FEF 2FFC-2FFF 3040 3097-3098 3100-3104 312D-3130 318F 31B8-31EF 321D-321F 3244-3250 327C-327E 32CC-32CF 32FF 3377-337A 33DE-33DF 33FF 4DB6-4DFF 9FA6-9FFF A48D-A48F A4C7-ABFF D7A4-D7FF FA2E-FA2F FA6B-FAFF FB07-FB12 FB18-FB1C FB37 FB3D FB3F FB42 FB45 FBB2-FBD2 FD40-FD4F FD90-FD91 FDC8-FDCF FDFD-FDFF FE10-FE1F FE24-FE2F FE47-FE48 FE53 FE67 FE6C-FE6F FE75 FEFD-FEFE FF00 FFBF-FFC1 FFC8-FFC9 FFD0-FFD1 FFD8-FFD9 FFDD-FFDF FFE7 FFEF-FFF8 10000-102FF 1031F 10324-1032F 1034B-103FF 10426-10427 1044E-1CFFF 1D0F6-1D0FF 1D127-1D129 1D1DE-1D3FF 1D455 1D49D 1D4A0-1D4A1 1D4A3-1D4A4 1D4A7-1D4A8 1D4AD 1D4BA 1D4BC 1D4C1 1D4C4 1D506 1D50B-1D50C 1D515 1D51D 1D53A 1D53F 1D545 1D547-1D549 1D551 1D6A4-1D6A7 1D7CA-1D7CD 1D800-1FFFD 2A6D7-2F7FF 2FA1E-2FFFD 30000-3FFFD 40000-4FFFD 50000-5FFFD 60000-6FFFD 70000-7FFFD 80000-8FFFD 90000-9FFFD A0000-AFFFD B0000-BFFFD C0000-CFFFD D0000-DFFFD E0000 E0002-E001F E0080-EFFFD";
|
|
19269
|
+
var RANDAL_TEXT = "5BE 5C0 5C3 5D0-5EA 5F0-5F4 61B 61F 621-63A 640-64A 66D-66F 671-6D5 6DD 6E5-6E6 6FA-6FE 700-70D 710 712-72C 780-7A5 7B1 200F FB1D FB1F-FB28 FB2A-FB36 FB38-FB3C FB3E FB40-FB41 FB43-FB44 FB46-FBB1 FBD3-FD3D FD50-FD8F FD92-FDC7 FDF0-FDFC FE70-FE74 FE76-FEFC";
|
|
19270
|
+
var LCAT_TEXT = "41-5A 61-7A AA B5 BA C0-D6 D8-F6 F8-220 222-233 250-2AD 2B0-2B8 2BB-2C1 2D0-2D1 2E0-2E4 2EE 37A 386 388-38A 38C 38E-3A1 3A3-3CE 3D0-3F5 400-482 48A-4CE 4D0-4F5 4F8-4F9 500-50F 531-556 559-55F 561-587 589 903 905-939 93D-940 949-94C 950 958-961 964-970 982-983 985-98C 98F-990 993-9A8 9AA-9B0 9B2 9B6-9B9 9BE-9C0 9C7-9C8 9CB-9CC 9D7 9DC-9DD 9DF-9E1 9E6-9F1 9F4-9FA A05-A0A A0F-A10 A13-A28 A2A-A30 A32-A33 A35-A36 A38-A39 A3E-A40 A59-A5C A5E A66-A6F A72-A74 A83 A85-A8B A8D A8F-A91 A93-AA8 AAA-AB0 AB2-AB3 AB5-AB9 ABD-AC0 AC9 ACB-ACC AD0 AE0 AE6-AEF B02-B03 B05-B0C B0F-B10 B13-B28 B2A-B30 B32-B33 B36-B39 B3D-B3E B40 B47-B48 B4B-B4C B57 B5C-B5D B5F-B61 B66-B70 B83 B85-B8A B8E-B90 B92-B95 B99-B9A B9C B9E-B9F BA3-BA4 BA8-BAA BAE-BB5 BB7-BB9 BBE-BBF BC1-BC2 BC6-BC8 BCA-BCC BD7 BE7-BF2 C01-C03 C05-C0C C0E-C10 C12-C28 C2A-C33 C35-C39 C41-C44 C60-C61 C66-C6F C82-C83 C85-C8C C8E-C90 C92-CA8 CAA-CB3 CB5-CB9 CBE CC0-CC4 CC7-CC8 CCA-CCB CD5-CD6 CDE CE0-CE1 CE6-CEF D02-D03 D05-D0C D0E-D10 D12-D28 D2A-D39 D3E-D40 D46-D48 D4A-D4C D57 D60-D61 D66-D6F D82-D83 D85-D96 D9A-DB1 DB3-DBB DBD DC0-DC6 DCF-DD1 DD8-DDF DF2-DF4 E01-E30 E32-E33 E40-E46 E4F-E5B E81-E82 E84 E87-E88 E8A E8D E94-E97 E99-E9F EA1-EA3 EA5 EA7 EAA-EAB EAD-EB0 EB2-EB3 EBD EC0-EC4 EC6 ED0-ED9 EDC-EDD F00-F17 F1A-F34 F36 F38 F3E-F47 F49-F6A F7F F85 F88-F8B FBE-FC5 FC7-FCC FCF 1000-1021 1023-1027 1029-102A 102C 1031 1038 1040-1057 10A0-10C5 10D0-10F8 10FB 1100-1159 115F-11A2 11A8-11F9 1200-1206 1208-1246 1248 124A-124D 1250-1256 1258 125A-125D 1260-1286 1288 128A-128D 1290-12AE 12B0 12B2-12B5 12B8-12BE 12C0 12C2-12C5 12C8-12CE 12D0-12D6 12D8-12EE 12F0-130E 1310 1312-1315 1318-131E 1320-1346 1348-135A 1361-137C 13A0-13F4 1401-1676 1681-169A 16A0-16F0 1700-170C 170E-1711 1720-1731 1735-1736 1740-1751 1760-176C 176E-1770 1780-17B6 17BE-17C5 17C7-17C8 17D4-17DA 17DC 17E0-17E9 1810-1819 1820-1877 1880-18A8 1E00-1E9B 1EA0-1EF9 1F00-1F15 1F18-1F1D 1F20-1F45 1F48-1F4D 1F50-1F57 1F59 1F5B 1F5D 1F5F-1F7D 1F80-1FB4 1FB6-1FBC 1FBE 1FC2-1FC4 1FC6-1FCC 1FD0-1FD3 1FD6-1FDB 1FE0-1FEC 1FF2-1FF4 1FF6-1FFC 200E 2071 207F 2102 2107 210A-2113 2115 2119-211D 2124 2126 2128 212A-212D 212F-2131 2133-2139 213D-213F 2145-2149 2160-2183 2336-237A 2395 249C-24E9 3005-3007 3021-3029 3031-3035 3038-303C 3041-3096 309D-309F 30A1-30FA 30FC-30FF 3105-312C 3131-318E 3190-31B7 31F0-321C 3220-3243 3260-327B 327F-32B0 32C0-32CB 32D0-32FE 3300-3376 337B-33DD 33E0-33FE 3400-4DB5 4E00-9FA5 A000-A48C AC00-D7A3 D800-FA2D FA30-FA6A FB00-FB06 FB13-FB17 FF21-FF3A FF41-FF5A FF66-FFBE FFC2-FFC7 FFCA-FFCF FFD2-FFD7 FFDA-FFDC 10300-1031E 10320-10323 10330-1034A 10400-10425 10428-1044D 1D000-1D0F5 1D100-1D126 1D12A-1D166 1D16A-1D172 1D183-1D184 1D18C-1D1A9 1D1AE-1D1DD 1D400-1D454 1D456-1D49C 1D49E-1D49F 1D4A2 1D4A5-1D4A6 1D4A9-1D4AC 1D4AE-1D4B9 1D4BB 1D4BD-1D4C0 1D4C2-1D4C3 1D4C5-1D505 1D507-1D50A 1D50D-1D514 1D516-1D51C 1D51E-1D539 1D53B-1D53E 1D540-1D544 1D546 1D54A-1D550 1D552-1D6A3 1D6A8-1D7C9 20000-2A6D6 2F800-2FA1D F0000-FFFFD 100000-10FFFD";
|
|
19271
|
+
var PROHIBITED = ranges(PROHIBITED_TEXT);
|
|
19272
|
+
var UNASSIGNED = ranges(UNASSIGNED_TEXT);
|
|
19273
|
+
var RANDAL = ranges(RANDAL_TEXT);
|
|
19274
|
+
var LCAT = ranges(LCAT_TEXT);
|
|
19275
|
+
function prepFails(prepared) {
|
|
19276
|
+
const codes = Array.from(prepared, (ch) => ch.codePointAt(0) ?? 0);
|
|
19277
|
+
if (codes.length === 0) return true;
|
|
19278
|
+
if (codes.some((c) => within7(PROHIBITED, c) || within7(UNASSIGNED, c))) return true;
|
|
19279
|
+
if (!codes.some((c) => within7(RANDAL, c))) return false;
|
|
19280
|
+
if (codes.some((c) => within7(LCAT, c))) return true;
|
|
19281
|
+
return !within7(RANDAL, codes[0] ?? 0) || !within7(RANDAL, codes.at(-1) ?? 0);
|
|
19282
|
+
}
|
|
19283
|
+
|
|
19284
|
+
// src/kernel/net/sealed-scram.ts
|
|
19285
|
+
var encoder8 = new TextEncoder();
|
|
19286
|
+
function base64Bytes(text) {
|
|
19287
|
+
try {
|
|
19288
|
+
return Uint8Array.from(atob(text), (c) => c.charCodeAt(0));
|
|
19289
|
+
} catch {
|
|
19290
|
+
return void 0;
|
|
19282
19291
|
}
|
|
19283
|
-
|
|
19284
|
-
|
|
19285
|
-
|
|
19286
|
-
|
|
19292
|
+
}
|
|
19293
|
+
function base64Of(bytes) {
|
|
19294
|
+
let bin = "";
|
|
19295
|
+
for (const b of bytes) bin += String.fromCharCode(b);
|
|
19296
|
+
return btoa(bin);
|
|
19297
|
+
}
|
|
19298
|
+
function clientFirstBare(message3) {
|
|
19299
|
+
const m = /^n,,(n=[^,]*,r=[^,]+)$/.exec(message3);
|
|
19300
|
+
return m ? m[1] : void 0;
|
|
19301
|
+
}
|
|
19302
|
+
var SERVER_FIRST = /^r=([^,]+),s=([^,]+),i=(\d{1,6})$/;
|
|
19303
|
+
var CLIENT_FINAL = /^(c=biws,r=([^,]+)),p=([^,]+)$/;
|
|
19304
|
+
var SCRAM_MAX = 1024;
|
|
19305
|
+
function exchangeOf(clientFirst, serverFirst, clientFinal) {
|
|
19306
|
+
const bare = clientFirstBare(clientFirst);
|
|
19307
|
+
const sf = SERVER_FIRST.exec(serverFirst);
|
|
19308
|
+
const fin = CLIENT_FINAL.exec(clientFinal);
|
|
19309
|
+
if (!bare || !sf || !fin || [bare, serverFirst, clientFinal].some((t) => t.length > SCRAM_MAX))
|
|
19310
|
+
return void 0;
|
|
19311
|
+
const cnonce = bare.slice(bare.indexOf(",r=") + 3);
|
|
19312
|
+
const nonce = sf[1];
|
|
19313
|
+
const salt = base64Bytes(sf[2]);
|
|
19314
|
+
const iterations = Number(sf[3]);
|
|
19315
|
+
const proof = base64Bytes(fin[3]);
|
|
19316
|
+
const ok4 = fin[2] === nonce && nonce.startsWith(cnonce) && iterations >= 1 && iterations <= 1e5 && salt !== void 0 && proof?.length === 32;
|
|
19317
|
+
if (!ok4) return void 0;
|
|
19318
|
+
return {
|
|
19319
|
+
exchange: {
|
|
19320
|
+
clientFirstBare: bare,
|
|
19321
|
+
serverFirst,
|
|
19322
|
+
clientFinalBare: fin[1],
|
|
19323
|
+
salt,
|
|
19324
|
+
iterations
|
|
19325
|
+
},
|
|
19326
|
+
proof
|
|
19327
|
+
};
|
|
19328
|
+
}
|
|
19329
|
+
async function hmac(key, data) {
|
|
19330
|
+
const k = await crypto.subtle.importKey(
|
|
19331
|
+
"raw",
|
|
19332
|
+
key,
|
|
19333
|
+
{ name: "HMAC", hash: "SHA-256" },
|
|
19334
|
+
false,
|
|
19335
|
+
["sign"]
|
|
19336
|
+
);
|
|
19337
|
+
return new Uint8Array(await crypto.subtle.sign("HMAC", k, data));
|
|
19338
|
+
}
|
|
19339
|
+
async function scramKeys(password, x) {
|
|
19340
|
+
const base = await crypto.subtle.importKey("raw", encoder8.encode(password), "PBKDF2", false, [
|
|
19341
|
+
"deriveBits"
|
|
19342
|
+
]);
|
|
19343
|
+
const salted = new Uint8Array(
|
|
19344
|
+
await crypto.subtle.deriveBits(
|
|
19345
|
+
{
|
|
19346
|
+
name: "PBKDF2",
|
|
19347
|
+
hash: "SHA-256",
|
|
19348
|
+
salt: x.salt,
|
|
19349
|
+
iterations: x.iterations
|
|
19350
|
+
},
|
|
19351
|
+
base,
|
|
19352
|
+
256
|
|
19353
|
+
)
|
|
19354
|
+
);
|
|
19355
|
+
const clientKey = await hmac(salted, encoder8.encode("Client Key"));
|
|
19356
|
+
const stored = new Uint8Array(
|
|
19357
|
+
await crypto.subtle.digest("SHA-256", clientKey)
|
|
19358
|
+
);
|
|
19359
|
+
const auth = encoder8.encode(`${x.clientFirstBare},${x.serverFirst},${x.clientFinalBare}`);
|
|
19360
|
+
const signature = await hmac(stored, auth);
|
|
19361
|
+
const proof = clientKey.map((b, i) => b ^ signature[i]);
|
|
19362
|
+
const serverKey = await hmac(salted, encoder8.encode("Server Key"));
|
|
19363
|
+
const serverSignature = await hmac(serverKey, auth);
|
|
19364
|
+
for (const k of [salted, clientKey, stored, signature, serverKey]) k.fill(0);
|
|
19365
|
+
return { proof, serverSignature };
|
|
19366
|
+
}
|
|
19367
|
+
var SPACES = /[\u00A0\u1680\u2000-\u200B\u202F\u205F\u3000]/g;
|
|
19368
|
+
var NOTHING2 = /\u00AD|\u034F|\u1806|[\u180B-\u180D]|\u200C|\u200D|\u2060|[\uFE00-\uFE0F]|\uFEFF/g;
|
|
19369
|
+
function saslprep(password) {
|
|
19370
|
+
if (/^[\x00-\x7f]*$/.test(password)) return password;
|
|
19371
|
+
const mapped = password.replace(SPACES, " ").replace(NOTHING2, "");
|
|
19372
|
+
return prepFails(mapped) ? password : mapped.normalize("NFKC");
|
|
19373
|
+
}
|
|
19374
|
+
function sameBytes(a, b) {
|
|
19375
|
+
if (a.length !== b.length) return false;
|
|
19376
|
+
let d = 0;
|
|
19377
|
+
for (let i = 0; i < a.length; i++) d |= a[i] ^ b[i];
|
|
19378
|
+
return d === 0;
|
|
19379
|
+
}
|
|
19380
|
+
|
|
19381
|
+
// src/kernel/net/sealed-pg.ts
|
|
19382
|
+
var PG_MESSAGE_MAX = 16 * 1024;
|
|
19383
|
+
var PROTOCOL_3 = 196608;
|
|
19384
|
+
var CLEARTEXT = 3;
|
|
19385
|
+
function int32(bytes, at) {
|
|
19386
|
+
return bytes[at] << 24 | bytes[at + 1] << 16 | bytes[at + 2] << 8 | bytes[at + 3];
|
|
19387
|
+
}
|
|
19388
|
+
function sniffPg(start2) {
|
|
19389
|
+
const bytes = Uint8Array.from(start2, (c) => c.charCodeAt(0));
|
|
19390
|
+
if (bytes.length === 0 || bytes[0] !== 0) return bytes.length === 0 ? "more" : "no";
|
|
19391
|
+
if (bytes.length < 8) return "more";
|
|
19392
|
+
const length2 = int32(bytes, 0);
|
|
19393
|
+
return length2 >= 8 && length2 <= PG_MESSAGE_MAX && int32(bytes, 4) === PROTOCOL_3 ? "yes" : "no";
|
|
19394
|
+
}
|
|
19395
|
+
var PLUS = "SCRAM-SHA-256-PLUS";
|
|
19396
|
+
var SASL = 10;
|
|
19397
|
+
var SASL_CONTINUE = 11;
|
|
19398
|
+
var SASL_FINAL = 12;
|
|
19399
|
+
function latin(bytes) {
|
|
19400
|
+
let out = "";
|
|
19401
|
+
for (const b of bytes) out += String.fromCharCode(b);
|
|
19402
|
+
return out;
|
|
19403
|
+
}
|
|
19404
|
+
var PgServer = class {
|
|
19405
|
+
buffer = new Uint8Array(0);
|
|
19406
|
+
skip = 0;
|
|
19407
|
+
cleartext = false;
|
|
19408
|
+
sasl = false;
|
|
19409
|
+
serverFirst;
|
|
19410
|
+
expect;
|
|
19411
|
+
failed = false;
|
|
19412
|
+
lost = false;
|
|
19413
|
+
auth(message3) {
|
|
19414
|
+
const code = message3.length >= 9 ? int32(message3, 5) : -1;
|
|
19415
|
+
if (this.expect && code !== SASL_FINAL) this.failed = true;
|
|
19416
|
+
this.cleartext = message3.length === 9 && code === CLEARTEXT;
|
|
19417
|
+
if (code === SASL) return this.mechanisms(message3);
|
|
19418
|
+
else if (code === SASL_CONTINUE) this.serverFirst = latin(message3.subarray(9));
|
|
19419
|
+
else if (code === SASL_FINAL) this.final(message3);
|
|
19420
|
+
return message3;
|
|
19287
19421
|
}
|
|
19288
|
-
|
|
19289
|
-
this.
|
|
19290
|
-
const
|
|
19291
|
-
|
|
19292
|
-
try {
|
|
19293
|
-
await writeAll4(this.conn, out);
|
|
19294
|
-
} finally {
|
|
19295
|
-
out.fill(0);
|
|
19296
|
-
}
|
|
19422
|
+
mechanisms(message3) {
|
|
19423
|
+
this.sasl = true;
|
|
19424
|
+
const names2 = latin(message3.subarray(9)).split("\0").filter((n) => n !== "" && n !== PLUS);
|
|
19425
|
+
return frame3(82, `${latin(message3.subarray(5, 9))}${names2.map((n) => `${n}\0`).join("")}\0`);
|
|
19297
19426
|
}
|
|
19298
|
-
|
|
19299
|
-
|
|
19300
|
-
|
|
19301
|
-
this.
|
|
19302
|
-
const
|
|
19303
|
-
|
|
19304
|
-
|
|
19305
|
-
|
|
19306
|
-
const head = done5 ? bytesOf(done5.head) : all.subarray(0, end);
|
|
19307
|
-
if (done5) this.remember(done5.values);
|
|
19308
|
-
try {
|
|
19309
|
-
await writeAll4(this.conn, head);
|
|
19310
|
-
await writeAll4(this.conn, all.subarray(end));
|
|
19311
|
-
} finally {
|
|
19312
|
-
head.fill(0);
|
|
19313
|
-
all.fill(0);
|
|
19427
|
+
final(message3) {
|
|
19428
|
+
const expect = this.expect;
|
|
19429
|
+
if (!expect) return;
|
|
19430
|
+
this.expect = void 0;
|
|
19431
|
+
const data = latin(message3.subarray(9));
|
|
19432
|
+
if (data !== expect.real || expect.fake.length !== expect.real.length) {
|
|
19433
|
+
this.failed = true;
|
|
19434
|
+
return;
|
|
19314
19435
|
}
|
|
19436
|
+
for (let i = 0; i < expect.fake.length; i++) message3[9 + i] = expect.fake.charCodeAt(i);
|
|
19315
19437
|
}
|
|
19316
|
-
|
|
19317
|
-
|
|
19318
|
-
this.
|
|
19319
|
-
|
|
19320
|
-
|
|
19321
|
-
|
|
19322
|
-
clearTimeout(this.timer);
|
|
19323
|
-
this.buffer.fill(0);
|
|
19324
|
-
this.buffer = new Uint8Array(0);
|
|
19325
|
-
this.mode = "pass";
|
|
19326
|
-
}
|
|
19327
|
-
};
|
|
19328
|
-
var IDLE2 = /* @__PURE__ */ Symbol("idle");
|
|
19329
|
-
var ScrubReader = class {
|
|
19330
|
-
stream;
|
|
19331
|
-
version = 0;
|
|
19332
|
-
next;
|
|
19333
|
-
held = false;
|
|
19334
|
-
ended = false;
|
|
19335
|
-
conn;
|
|
19336
|
-
scope;
|
|
19337
|
-
constructor(conn, scope) {
|
|
19338
|
-
this.conn = conn;
|
|
19339
|
-
this.scope = scope;
|
|
19340
|
-
}
|
|
19341
|
-
current() {
|
|
19342
|
-
const scrub = this.scope.of();
|
|
19343
|
-
if (!scrub || scrub.version === this.version) return new Uint8Array(0);
|
|
19344
|
-
const tail2 = this.stream?.end() ?? new Uint8Array(0);
|
|
19345
|
-
const stream = scrub.scrubber.stream();
|
|
19346
|
-
this.stream = stream;
|
|
19347
|
-
this.version = scrub.version;
|
|
19348
|
-
this.held = tail2.length > 0;
|
|
19349
|
-
return tail2.length > 0 ? stream.push(tail2) : tail2;
|
|
19438
|
+
lose() {
|
|
19439
|
+
this.lost = true;
|
|
19440
|
+
this.cleartext = false;
|
|
19441
|
+
this.sasl = false;
|
|
19442
|
+
if (this.expect) this.failed = true;
|
|
19443
|
+
this.expect = void 0;
|
|
19350
19444
|
}
|
|
19351
|
-
|
|
19445
|
+
filter(bytes) {
|
|
19446
|
+
if (this.lost) return bytes;
|
|
19447
|
+
const data = new Uint8Array(this.buffer.length + bytes.length);
|
|
19448
|
+
data.set(this.buffer);
|
|
19449
|
+
data.set(bytes, this.buffer.length);
|
|
19450
|
+
const out = [];
|
|
19451
|
+
let at = 0;
|
|
19352
19452
|
for (; ; ) {
|
|
19353
|
-
|
|
19354
|
-
|
|
19355
|
-
|
|
19356
|
-
|
|
19357
|
-
|
|
19358
|
-
|
|
19359
|
-
|
|
19360
|
-
this.next = next3;
|
|
19361
|
-
this.held = false;
|
|
19362
|
-
const out2 = this.stream.idle();
|
|
19363
|
-
if (out2.length > 0) return out2;
|
|
19453
|
+
const left = data.length - at;
|
|
19454
|
+
if (this.skip > 0) {
|
|
19455
|
+
const n = Math.min(this.skip, left);
|
|
19456
|
+
out.push(data.subarray(at, at + n));
|
|
19457
|
+
this.skip -= n;
|
|
19458
|
+
at += n;
|
|
19459
|
+
if (this.skip > 0) break;
|
|
19364
19460
|
continue;
|
|
19365
19461
|
}
|
|
19366
|
-
|
|
19367
|
-
const
|
|
19368
|
-
if (
|
|
19369
|
-
|
|
19370
|
-
|
|
19371
|
-
|
|
19372
|
-
|
|
19373
|
-
|
|
19374
|
-
|
|
19375
|
-
|
|
19376
|
-
|
|
19377
|
-
|
|
19378
|
-
return out2.length > 0 ? out2 : null;
|
|
19379
|
-
}
|
|
19380
|
-
const out = stream.push(got);
|
|
19381
|
-
this.held = true;
|
|
19382
|
-
return out.length > 0 ? out : void 0;
|
|
19383
|
-
}
|
|
19384
|
-
};
|
|
19385
|
-
function joined3(a, b) {
|
|
19386
|
-
if (!b) return a;
|
|
19387
|
-
const out = new Uint8Array(a.length + b.length);
|
|
19388
|
-
out.set(a);
|
|
19389
|
-
out.set(b, a.length);
|
|
19390
|
-
return out;
|
|
19391
|
-
}
|
|
19392
|
-
function idle() {
|
|
19393
|
-
return new Promise((resolve2) => setTimeout(() => resolve2(IDLE2), SCRUB_IDLE_MS));
|
|
19394
|
-
}
|
|
19395
|
-
function sealedConn(conn, s) {
|
|
19396
|
-
const pg = new PgServer();
|
|
19397
|
-
const scope = s.broker.sessions.scope(s.pid, s.host);
|
|
19398
|
-
const writer = substitutes(s) ? new SessionWriter(conn, s, pg, scope) : void 0;
|
|
19399
|
-
const observed = {
|
|
19400
|
-
...conn,
|
|
19401
|
-
read: async () => {
|
|
19402
|
-
for (; ; ) {
|
|
19403
|
-
const bytes = await conn.read();
|
|
19404
|
-
if (!bytes) return bytes;
|
|
19405
|
-
const out = writer?.sawPg ? pg.filter(bytes) : bytes;
|
|
19406
|
-
if (pg.failed) {
|
|
19407
|
-
conn.close();
|
|
19408
|
-
throw new KernelError(
|
|
19409
|
-
"EPROTO",
|
|
19410
|
-
"ERR_SSL_PROTOCOL_ERROR: the pg server failed the SCRAM proof"
|
|
19411
|
-
);
|
|
19462
|
+
if (left < 5) break;
|
|
19463
|
+
const whole = 1 + int32(data, at + 1);
|
|
19464
|
+
if (whole < 5 || data[at] === 82 && whole > PG_MESSAGE_MAX) {
|
|
19465
|
+
this.lose();
|
|
19466
|
+
out.push(data.subarray(at));
|
|
19467
|
+
at = data.length;
|
|
19468
|
+
break;
|
|
19469
|
+
}
|
|
19470
|
+
if (data[at] !== 82) {
|
|
19471
|
+
if (this.expect) {
|
|
19472
|
+
this.failed = true;
|
|
19473
|
+
break;
|
|
19412
19474
|
}
|
|
19413
|
-
|
|
19475
|
+
this.skip = whole;
|
|
19476
|
+
continue;
|
|
19414
19477
|
}
|
|
19478
|
+
if (left < whole) break;
|
|
19479
|
+
out.push(this.auth(data.slice(at, at + whole)));
|
|
19480
|
+
at += whole;
|
|
19415
19481
|
}
|
|
19416
|
-
|
|
19417
|
-
|
|
19418
|
-
|
|
19419
|
-
|
|
19420
|
-
|
|
19421
|
-
|
|
19422
|
-
|
|
19423
|
-
|
|
19424
|
-
if (!writer) return conn.closeWrite();
|
|
19425
|
-
void writer.flushed().then(
|
|
19426
|
-
() => conn.closeWrite(),
|
|
19427
|
-
() => conn.closeWrite()
|
|
19428
|
-
);
|
|
19429
|
-
},
|
|
19430
|
-
close() {
|
|
19431
|
-
writer?.drop();
|
|
19432
|
-
conn.close();
|
|
19433
|
-
}
|
|
19434
|
-
};
|
|
19435
|
-
}
|
|
19436
|
-
|
|
19437
|
-
// src/kernel/net/tls-chain.ts
|
|
19438
|
-
var CN_MISMATCH = 4;
|
|
19439
|
-
var NOT_TRUSTED = 8;
|
|
19440
|
-
function tlv2(der, at) {
|
|
19441
|
-
if (at + 2 > der.length) return void 0;
|
|
19442
|
-
const first = der[at + 1];
|
|
19443
|
-
let body = at + 2;
|
|
19444
|
-
let length2 = first;
|
|
19445
|
-
if (first & 128) {
|
|
19446
|
-
const n = first & 127;
|
|
19447
|
-
if (n === 0 || n > 4 || body + n > der.length) return void 0;
|
|
19448
|
-
length2 = 0;
|
|
19449
|
-
for (let i = 0; i < n; i++) length2 = length2 * 256 + der[body + i];
|
|
19450
|
-
body += n;
|
|
19482
|
+
this.buffer = data.slice(at);
|
|
19483
|
+
const joined4 = new Uint8Array(out.reduce((n, b) => n + b.length, 0));
|
|
19484
|
+
let to = 0;
|
|
19485
|
+
for (const b of out) {
|
|
19486
|
+
joined4.set(b, to);
|
|
19487
|
+
to += b.length;
|
|
19488
|
+
}
|
|
19489
|
+
return joined4;
|
|
19451
19490
|
}
|
|
19452
|
-
|
|
19453
|
-
|
|
19491
|
+
};
|
|
19492
|
+
function frame3(type, body) {
|
|
19493
|
+
const out = new Uint8Array(5 + body.length);
|
|
19494
|
+
out[0] = type;
|
|
19495
|
+
const length2 = 4 + body.length;
|
|
19496
|
+
out.set([length2 >>> 24 & 255, length2 >>> 16 & 255, length2 >>> 8 & 255, length2 & 255], 1);
|
|
19497
|
+
for (let i = 0; i < body.length; i++) out[5 + i] = body.charCodeAt(i);
|
|
19498
|
+
return out;
|
|
19454
19499
|
}
|
|
19455
|
-
function
|
|
19456
|
-
const
|
|
19457
|
-
|
|
19458
|
-
|
|
19459
|
-
|
|
19460
|
-
fields.push(field4);
|
|
19461
|
-
at = field4.end;
|
|
19462
|
-
}
|
|
19463
|
-
return fields;
|
|
19500
|
+
function pgLength(bytes, started) {
|
|
19501
|
+
const header3 = started ? 5 : 4;
|
|
19502
|
+
if (bytes.length < header3) return void 0;
|
|
19503
|
+
const length2 = int32(bytes, started ? 1 : 0);
|
|
19504
|
+
return started ? 1 + length2 : length2;
|
|
19464
19505
|
}
|
|
19465
|
-
|
|
19466
|
-
|
|
19467
|
-
const
|
|
19468
|
-
|
|
19469
|
-
|
|
19470
|
-
|
|
19506
|
+
var MECHANISMS = /* @__PURE__ */ new Set(["SCRAM-SHA-256"]);
|
|
19507
|
+
async function cleartext(message3, asks) {
|
|
19508
|
+
const body = latin(message3.subarray(5));
|
|
19509
|
+
if (!body.endsWith("\0") || body.indexOf("\0") !== body.length - 1)
|
|
19510
|
+
return { bytes: message3, done: true };
|
|
19511
|
+
const password = body.slice(0, -1);
|
|
19512
|
+
const placeholders = placeholdersIn(password);
|
|
19513
|
+
if (placeholders.length === 0 || placeholders.length > SESSION_PLACEHOLDERS)
|
|
19514
|
+
return { bytes: message3, done: true };
|
|
19515
|
+
const values = usable(await asks.cleartext(placeholders));
|
|
19516
|
+
if (Object.keys(values).length === 0) return { bytes: message3, done: true };
|
|
19517
|
+
return { bytes: frame3(112, `${replaced(password, values)}\0`), values, done: true };
|
|
19471
19518
|
}
|
|
19472
|
-
|
|
19473
|
-
|
|
19474
|
-
const
|
|
19475
|
-
|
|
19476
|
-
|
|
19477
|
-
return
|
|
19519
|
+
function initial(message3) {
|
|
19520
|
+
const body = latin(message3.subarray(5));
|
|
19521
|
+
const nul = body.indexOf("\0");
|
|
19522
|
+
if (nul < 0 || !MECHANISMS.has(body.slice(0, nul)) || body.length < nul + 5) return void 0;
|
|
19523
|
+
const data = message3.subarray(5 + nul + 5);
|
|
19524
|
+
return int32(message3, 5 + nul + 1) === data.length ? latin(data) : void 0;
|
|
19478
19525
|
}
|
|
19479
|
-
var
|
|
19480
|
-
|
|
19481
|
-
|
|
19482
|
-
|
|
19483
|
-
|
|
19484
|
-
|
|
19485
|
-
|
|
19486
|
-
|
|
19487
|
-
|
|
19488
|
-
|
|
19489
|
-
};
|
|
19490
|
-
|
|
19491
|
-
|
|
19492
|
-
|
|
19493
|
-
|
|
19494
|
-
|
|
19495
|
-
|
|
19496
|
-
|
|
19497
|
-
const params = children2(der, algorithm, 2)?.[1];
|
|
19498
|
-
let hash = "SHA-1";
|
|
19499
|
-
let salt = 20;
|
|
19500
|
-
for (const field4 of params && der[params.start] === 48 ? children2(der, params, 3) ?? [] : []) {
|
|
19501
|
-
const inner = tlv2(der, field4.body);
|
|
19502
|
-
if (!inner) return void 0;
|
|
19503
|
-
if (der[field4.start] === 160) {
|
|
19504
|
-
const known = PSS_HASHES[oidOf(der, inner) ?? ""];
|
|
19505
|
-
if (!known) return void 0;
|
|
19506
|
-
hash = known;
|
|
19507
|
-
} else if (der[field4.start] === 162) {
|
|
19508
|
-
salt = der.subarray(inner.body, inner.end).reduce((n, b) => n * 256 + b, 0);
|
|
19526
|
+
var PgClient = class {
|
|
19527
|
+
clientFirst;
|
|
19528
|
+
server;
|
|
19529
|
+
asks;
|
|
19530
|
+
constructor(server, asks) {
|
|
19531
|
+
this.server = server;
|
|
19532
|
+
this.asks = asks;
|
|
19533
|
+
}
|
|
19534
|
+
async message(message3) {
|
|
19535
|
+
const server = this.server;
|
|
19536
|
+
if (message3[0] !== 112) return { bytes: message3, done: true };
|
|
19537
|
+
if (server.cleartext) {
|
|
19538
|
+
server.cleartext = false;
|
|
19539
|
+
return cleartext(message3, this.asks);
|
|
19540
|
+
}
|
|
19541
|
+
if (server.sasl && this.clientFirst === void 0) {
|
|
19542
|
+
this.clientFirst = initial(message3);
|
|
19543
|
+
return { bytes: message3, done: this.clientFirst === void 0 };
|
|
19509
19544
|
}
|
|
19545
|
+
if (this.clientFirst !== void 0 && server.serverFirst !== void 0)
|
|
19546
|
+
return this.final(message3, this.clientFirst, server.serverFirst);
|
|
19547
|
+
return { bytes: message3, done: true };
|
|
19548
|
+
}
|
|
19549
|
+
async final(message3, first, serverFirst) {
|
|
19550
|
+
const got = exchangeOf(first, serverFirst, latin(message3.subarray(5)));
|
|
19551
|
+
if (!got) return { bytes: message3, done: true };
|
|
19552
|
+
const x = got.exchange;
|
|
19553
|
+
const values = usable(
|
|
19554
|
+
await this.asks.scram({
|
|
19555
|
+
clientFirstBare: x.clientFirstBare,
|
|
19556
|
+
serverFirst: x.serverFirst,
|
|
19557
|
+
clientFinalBare: x.clientFinalBare,
|
|
19558
|
+
proof: base64Of(got.proof)
|
|
19559
|
+
})
|
|
19560
|
+
);
|
|
19561
|
+
const [entry, ...more] = Object.entries(values);
|
|
19562
|
+
if (!entry || more.length > 0) return { bytes: message3, done: true };
|
|
19563
|
+
const [placeholder, value2] = entry;
|
|
19564
|
+
const fake = await scramKeys(placeholder, x);
|
|
19565
|
+
if (!sameBytes(fake.proof, got.proof)) return { bytes: message3, done: true };
|
|
19566
|
+
const real = await scramKeys(saslprep(value2), x);
|
|
19567
|
+
this.server.expect = {
|
|
19568
|
+
real: `v=${base64Of(real.serverSignature)}`,
|
|
19569
|
+
fake: `v=${base64Of(fake.serverSignature)}`
|
|
19570
|
+
};
|
|
19571
|
+
const bytes = frame3(112, `${x.clientFinalBare},p=${base64Of(real.proof)}`);
|
|
19572
|
+
for (const k of [real.proof, real.serverSignature, fake.proof, fake.serverSignature]) k.fill(0);
|
|
19573
|
+
return { bytes, values, done: true };
|
|
19510
19574
|
}
|
|
19511
|
-
return { hash, salt };
|
|
19512
|
-
}
|
|
19513
|
-
var CURVES = {
|
|
19514
|
-
"2a8648ce3d030107": ["P-256", 32],
|
|
19515
|
-
"2b81040022": ["P-384", 48],
|
|
19516
|
-
"2b81040023": ["P-521", 66]
|
|
19517
19575
|
};
|
|
19518
|
-
|
|
19519
|
-
|
|
19520
|
-
|
|
19521
|
-
|
|
19522
|
-
|
|
19523
|
-
|
|
19524
|
-
const
|
|
19525
|
-
|
|
19526
|
-
|
|
19527
|
-
}
|
|
19528
|
-
function fixedEcdsa(sig, size) {
|
|
19529
|
-
const outer = tlv2(sig, 0);
|
|
19530
|
-
const ints = outer && children2(sig, outer, 2);
|
|
19531
|
-
if (ints?.length !== 2) return void 0;
|
|
19532
|
-
const out = new Uint8Array(size * 2);
|
|
19533
|
-
for (const [i, int] of ints.entries()) {
|
|
19534
|
-
let value2 = sig.subarray(int.body, int.end);
|
|
19535
|
-
while (value2.length > size && value2[0] === 0) value2 = value2.subarray(1);
|
|
19536
|
-
if (value2.length > size) return void 0;
|
|
19537
|
-
out.set(value2, (i + 1) * size - value2.length);
|
|
19576
|
+
|
|
19577
|
+
// src/kernel/net/sealed-smtp.ts
|
|
19578
|
+
var SMTP_LINE_MAX = 4096;
|
|
19579
|
+
var GREETING = ["EHLO ", "HELO "];
|
|
19580
|
+
function sniffSmtp(start2) {
|
|
19581
|
+
const upper = start2.toUpperCase();
|
|
19582
|
+
for (const word of GREETING) {
|
|
19583
|
+
if (upper.startsWith(word)) return "yes";
|
|
19584
|
+
if (word.startsWith(upper)) return "more";
|
|
19538
19585
|
}
|
|
19539
|
-
return
|
|
19540
|
-
}
|
|
19541
|
-
function signedOf(der) {
|
|
19542
|
-
const parts2 = tbsFields(der);
|
|
19543
|
-
const [tbs, algorithm, value2] = parts2?.cert ?? [];
|
|
19544
|
-
const spki = parts2?.tbs[5];
|
|
19545
|
-
if (!tbs || !algorithm || !value2 || !spki || der[value2.start] !== 3) return void 0;
|
|
19546
|
-
const known = HASHES[oidOf(der, algorithm) ?? ""];
|
|
19547
|
-
if (!known) return void 0;
|
|
19548
|
-
const [scheme] = known;
|
|
19549
|
-
const pss = scheme === "RSA-PSS" ? pssOf(der, algorithm) : void 0;
|
|
19550
|
-
if (scheme === "RSA-PSS" && !pss) return void 0;
|
|
19551
|
-
const hash = pss?.hash ?? known[1];
|
|
19552
|
-
const curve = scheme === "ECDSA" ? curveOf(der, spki) : void 0;
|
|
19553
|
-
if (scheme === "ECDSA" && !curve) return void 0;
|
|
19554
|
-
const signature = der.subarray(value2.body + 1, value2.end);
|
|
19555
|
-
return {
|
|
19556
|
-
tbs: raw(der, tbs),
|
|
19557
|
-
spki: raw(der, spki),
|
|
19558
|
-
signature,
|
|
19559
|
-
scheme,
|
|
19560
|
-
hash,
|
|
19561
|
-
...curve ? { curve } : {},
|
|
19562
|
-
...pss ? { salt: pss.salt } : {}
|
|
19563
|
-
};
|
|
19586
|
+
return "no";
|
|
19564
19587
|
}
|
|
19565
|
-
|
|
19566
|
-
|
|
19567
|
-
|
|
19568
|
-
|
|
19569
|
-
|
|
19570
|
-
|
|
19571
|
-
|
|
19572
|
-
if (!signature) return false;
|
|
19573
|
-
const params = s.scheme === "ECDSA" ? { name: "ECDSA", hash: s.hash } : s.salt === void 0 ? { name: s.scheme } : { name: s.scheme, saltLength: s.salt };
|
|
19574
|
-
return crypto.subtle.verify(params, key, new Uint8Array(signature), new Uint8Array(s.tbs));
|
|
19588
|
+
function decoded(b642) {
|
|
19589
|
+
if (!/^[A-Za-z0-9+/]+={0,2}$/.test(b642)) return void 0;
|
|
19590
|
+
try {
|
|
19591
|
+
return atob(b642);
|
|
19592
|
+
} catch {
|
|
19593
|
+
return void 0;
|
|
19594
|
+
}
|
|
19575
19595
|
}
|
|
19576
|
-
async function
|
|
19577
|
-
|
|
19578
|
-
|
|
19579
|
-
|
|
19580
|
-
|
|
19596
|
+
async function swapped2(text, position, ask) {
|
|
19597
|
+
const placeholders = placeholdersIn(text);
|
|
19598
|
+
if (placeholders.length === 0 || placeholders.length > SESSION_PLACEHOLDERS) return void 0;
|
|
19599
|
+
const values = usable(await ask(position, placeholders));
|
|
19600
|
+
if (Object.keys(values).length === 0) return void 0;
|
|
19601
|
+
return { text: replaced(text, values), values };
|
|
19581
19602
|
}
|
|
19582
|
-
async function
|
|
19583
|
-
|
|
19584
|
-
|
|
19585
|
-
|
|
19586
|
-
|
|
19603
|
+
async function plain2(b642, ask) {
|
|
19604
|
+
const text = decoded(b642);
|
|
19605
|
+
const fields = text?.split("\0");
|
|
19606
|
+
if (fields?.length !== 3) return { line: b642 };
|
|
19607
|
+
const [authz, user, pass2] = fields;
|
|
19608
|
+
if (placeholdersIn(authz + user).length > 0) return { line: b642 };
|
|
19609
|
+
const done5 = await swapped2(pass2, "auth-plain", ask);
|
|
19610
|
+
if (!done5) return { line: b642 };
|
|
19611
|
+
return { line: btoa(`${authz}\0${user}\0${done5.text}`), values: done5.values };
|
|
19587
19612
|
}
|
|
19588
|
-
function
|
|
19589
|
-
const
|
|
19590
|
-
|
|
19591
|
-
|
|
19592
|
-
return issuer.length === subject.length && issuer.every((b, i) => b === subject[i]);
|
|
19613
|
+
async function login(b642, ask) {
|
|
19614
|
+
const text = decoded(b642);
|
|
19615
|
+
const done5 = text === void 0 ? void 0 : await swapped2(text, "auth-login", ask);
|
|
19616
|
+
return done5 ? { line: btoa(done5.text), values: done5.values } : { line: b642 };
|
|
19593
19617
|
}
|
|
19594
|
-
|
|
19595
|
-
|
|
19596
|
-
|
|
19618
|
+
var SmtpClient = class {
|
|
19619
|
+
state = "command";
|
|
19620
|
+
ask;
|
|
19621
|
+
constructor(ask) {
|
|
19622
|
+
this.ask = ask;
|
|
19597
19623
|
}
|
|
19598
|
-
|
|
19624
|
+
get done() {
|
|
19625
|
+
return this.state === "done";
|
|
19626
|
+
}
|
|
19627
|
+
async line(text) {
|
|
19628
|
+
const state = this.state;
|
|
19629
|
+
if (state === "done") return { line: text };
|
|
19630
|
+
if (state === "plain" || state === "password") {
|
|
19631
|
+
this.state = "done";
|
|
19632
|
+
if (text === "*") return { line: text };
|
|
19633
|
+
return state === "plain" ? plain2(text, this.ask) : login(text, this.ask);
|
|
19634
|
+
}
|
|
19635
|
+
if (state === "user") {
|
|
19636
|
+
this.state = text === "*" ? "done" : "password";
|
|
19637
|
+
return { line: text };
|
|
19638
|
+
}
|
|
19639
|
+
return this.command(text);
|
|
19640
|
+
}
|
|
19641
|
+
async command(text) {
|
|
19642
|
+
const m = /^AUTH[ \t]+(PLAIN|LOGIN)(?:[ \t]+(\S+))?$/i.exec(text);
|
|
19643
|
+
if (!m) {
|
|
19644
|
+
if (/^(MAIL|RCPT|DATA|BDAT|AUTH)\b/i.test(text)) this.state = "done";
|
|
19645
|
+
return { line: text };
|
|
19646
|
+
}
|
|
19647
|
+
const mech = m[1].toUpperCase();
|
|
19648
|
+
const arg = m[2];
|
|
19649
|
+
if (mech === "LOGIN") {
|
|
19650
|
+
this.state = arg === void 0 ? "user" : "password";
|
|
19651
|
+
return { line: text };
|
|
19652
|
+
}
|
|
19653
|
+
if (arg === void 0) {
|
|
19654
|
+
this.state = "plain";
|
|
19655
|
+
return { line: text };
|
|
19656
|
+
}
|
|
19657
|
+
this.state = "done";
|
|
19658
|
+
const out = await plain2(arg, this.ask);
|
|
19659
|
+
return {
|
|
19660
|
+
line: `${text.slice(0, text.length - arg.length)}${out.line}`,
|
|
19661
|
+
...out.values ? { values: out.values } : {}
|
|
19662
|
+
};
|
|
19663
|
+
}
|
|
19664
|
+
};
|
|
19665
|
+
|
|
19666
|
+
// src/kernel/net/sealed-conn.ts
|
|
19667
|
+
var HEAD_IDLE_MS = 2e3;
|
|
19668
|
+
function substitutes(s) {
|
|
19669
|
+
return (s.verified || s.anchoring !== void 0) && s.alpn !== "h2" && s.broker.hook !== void 0 && typeof s.exit === "string" && SESSION_EXIT.test(s.exit);
|
|
19599
19670
|
}
|
|
19600
|
-
function
|
|
19601
|
-
|
|
19602
|
-
|
|
19603
|
-
|
|
19604
|
-
|
|
19605
|
-
return verifyCode(rest2);
|
|
19671
|
+
function sessionId() {
|
|
19672
|
+
const bytes = crypto.getRandomValues(new Uint8Array(24));
|
|
19673
|
+
let bin = "";
|
|
19674
|
+
for (const b of bytes) bin += String.fromCharCode(b);
|
|
19675
|
+
return btoa(bin).replace(/\+/g, "-").replace(/\//g, "_");
|
|
19606
19676
|
}
|
|
19607
|
-
function
|
|
19608
|
-
|
|
19677
|
+
function latin12(bytes) {
|
|
19678
|
+
let out = "";
|
|
19679
|
+
for (const b of bytes) out += String.fromCharCode(b);
|
|
19680
|
+
return out;
|
|
19609
19681
|
}
|
|
19610
|
-
|
|
19611
|
-
|
|
19612
|
-
|
|
19613
|
-
|
|
19614
|
-
[4866, "TLS_AES_256_GCM_SHA384", "TLS_AES_256_GCM_SHA384", "TLSv1.3"],
|
|
19615
|
-
[4867, "TLS_CHACHA20_POLY1305_SHA256", "TLS_CHACHA20_POLY1305_SHA256", "TLSv1.3"],
|
|
19616
|
-
[4868, "TLS_AES_128_CCM_SHA256", "TLS_AES_128_CCM_SHA256", "TLSv1.3"],
|
|
19617
|
-
[4869, "TLS_AES_128_CCM_8_SHA256", "TLS_AES_128_CCM_8_SHA256", "TLSv1.3"],
|
|
19618
|
-
[49195, "ECDHE-ECDSA-AES128-GCM-SHA256", "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256", "TLSv1.2"],
|
|
19619
|
-
[49196, "ECDHE-ECDSA-AES256-GCM-SHA384", "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384", "TLSv1.2"],
|
|
19620
|
-
[49199, "ECDHE-RSA-AES128-GCM-SHA256", "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256", "TLSv1.2"],
|
|
19621
|
-
[49200, "ECDHE-RSA-AES256-GCM-SHA384", "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384", "TLSv1.2"],
|
|
19622
|
-
[52392, "ECDHE-RSA-CHACHA20-POLY1305", "TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256", "TLSv1.2"],
|
|
19623
|
-
[
|
|
19624
|
-
52393,
|
|
19625
|
-
"ECDHE-ECDSA-CHACHA20-POLY1305",
|
|
19626
|
-
"TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256",
|
|
19627
|
-
"TLSv1.2"
|
|
19628
|
-
],
|
|
19629
|
-
[49187, "ECDHE-ECDSA-AES128-SHA256", "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256", "TLSv1.2"],
|
|
19630
|
-
[49188, "ECDHE-ECDSA-AES256-SHA384", "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384", "TLSv1.2"],
|
|
19631
|
-
[49191, "ECDHE-RSA-AES128-SHA256", "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256", "TLSv1.2"],
|
|
19632
|
-
[49192, "ECDHE-RSA-AES256-SHA384", "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384", "TLSv1.2"],
|
|
19633
|
-
[49161, "ECDHE-ECDSA-AES128-SHA", "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA", "TLSv1.0"],
|
|
19634
|
-
[49162, "ECDHE-ECDSA-AES256-SHA", "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA", "TLSv1.0"],
|
|
19635
|
-
[49171, "ECDHE-RSA-AES128-SHA", "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA", "TLSv1.0"],
|
|
19636
|
-
[49172, "ECDHE-RSA-AES256-SHA", "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA", "TLSv1.0"],
|
|
19637
|
-
[156, "AES128-GCM-SHA256", "TLS_RSA_WITH_AES_128_GCM_SHA256", "TLSv1.2"],
|
|
19638
|
-
[157, "AES256-GCM-SHA384", "TLS_RSA_WITH_AES_256_GCM_SHA384", "TLSv1.2"],
|
|
19639
|
-
[158, "DHE-RSA-AES128-GCM-SHA256", "TLS_DHE_RSA_WITH_AES_128_GCM_SHA256", "TLSv1.2"],
|
|
19640
|
-
[159, "DHE-RSA-AES256-GCM-SHA384", "TLS_DHE_RSA_WITH_AES_256_GCM_SHA384", "TLSv1.2"]
|
|
19641
|
-
];
|
|
19642
|
-
function cipherOf(id2, protocol) {
|
|
19643
|
-
const known = SUITES.find(([n]) => n === id2);
|
|
19644
|
-
const hex4 = `0x${id2.toString(16).padStart(4, "0").toUpperCase()}`;
|
|
19645
|
-
return {
|
|
19646
|
-
name: known?.[1] ?? hex4,
|
|
19647
|
-
standardName: known?.[2] ?? hex4,
|
|
19648
|
-
version: known?.[3] ?? protocol
|
|
19649
|
-
};
|
|
19682
|
+
function bytesOf(text) {
|
|
19683
|
+
const out = new Uint8Array(text.length);
|
|
19684
|
+
for (let i = 0; i < text.length; i++) out[i] = text.charCodeAt(i);
|
|
19685
|
+
return out;
|
|
19650
19686
|
}
|
|
19651
|
-
|
|
19652
|
-
|
|
19653
|
-
var WRITE_CHUNK = 16 * 1024;
|
|
19654
|
-
var BADCERT = [
|
|
19655
|
-
[8, "UNABLE_TO_GET_ISSUER_CERT_LOCALLY"],
|
|
19656
|
-
[1, "CERT_HAS_EXPIRED"],
|
|
19657
|
-
[512, "CERT_NOT_YET_VALID"],
|
|
19658
|
-
[2, "CERT_REVOKED"],
|
|
19659
|
-
[4, "ERR_TLS_CERT_ALTNAME_INVALID"],
|
|
19660
|
-
[2048, "INVALID_PURPOSE"],
|
|
19661
|
-
[4096, "INVALID_PURPOSE"]
|
|
19662
|
-
];
|
|
19663
|
-
function verifyCode(flags2) {
|
|
19664
|
-
if (flags2 === 0) return void 0;
|
|
19665
|
-
if (flags2 === -1) return "UNABLE_TO_VERIFY_LEAF_SIGNATURE";
|
|
19666
|
-
return BADCERT.find(([bit]) => (flags2 & bit) !== 0)?.[1] ?? "UNABLE_TO_VERIFY_LEAF_SIGNATURE";
|
|
19687
|
+
async function writeAll4(conn, bytes) {
|
|
19688
|
+
for (let at = 0; at < bytes.length; ) at += await conn.write(bytes.subarray(at));
|
|
19667
19689
|
}
|
|
19668
|
-
|
|
19669
|
-
|
|
19690
|
+
var CRLF2 = [13, 10, 13, 10];
|
|
19691
|
+
function headEnd2(bytes) {
|
|
19692
|
+
for (let i = 0; i + 3 < bytes.length; i++) {
|
|
19693
|
+
if (CRLF2.every((b, k) => bytes[i + k] === b)) return i + 4;
|
|
19694
|
+
}
|
|
19695
|
+
return -1;
|
|
19670
19696
|
}
|
|
19671
|
-
function
|
|
19672
|
-
|
|
19697
|
+
function modeOf(start2) {
|
|
19698
|
+
const sniffs = [
|
|
19699
|
+
["http1", sniffHttp1(start2)],
|
|
19700
|
+
["smtp", sniffSmtp(start2)],
|
|
19701
|
+
["pg", sniffPg(start2)]
|
|
19702
|
+
];
|
|
19703
|
+
const hit = sniffs.find(([, v]) => v === "yes");
|
|
19704
|
+
if (hit) return hit[0];
|
|
19705
|
+
return sniffs.every(([, v]) => v === "no") ? "pass" : void 0;
|
|
19673
19706
|
}
|
|
19674
|
-
function
|
|
19675
|
-
|
|
19707
|
+
function crlf(bytes) {
|
|
19708
|
+
for (let i = 0; i + 1 < bytes.length; i++) if (bytes[i] === 13 && bytes[i + 1] === 10) return i;
|
|
19709
|
+
return -1;
|
|
19676
19710
|
}
|
|
19677
|
-
var
|
|
19678
|
-
|
|
19711
|
+
var SessionWriter = class {
|
|
19712
|
+
buffer = new Uint8Array(0);
|
|
19713
|
+
mode = "sniff";
|
|
19714
|
+
timer;
|
|
19715
|
+
chain = Promise.resolve();
|
|
19716
|
+
failed;
|
|
19717
|
+
session = sessionId();
|
|
19718
|
+
smtp;
|
|
19719
|
+
pgStarted = false;
|
|
19720
|
+
sawPg = false;
|
|
19721
|
+
conn;
|
|
19722
|
+
s;
|
|
19723
|
+
pgClient;
|
|
19724
|
+
scope;
|
|
19725
|
+
constructor(conn, s, pg, scope) {
|
|
19726
|
+
this.conn = conn;
|
|
19727
|
+
this.s = s;
|
|
19728
|
+
this.scope = scope;
|
|
19729
|
+
this.pgClient = new PgClient(pg, {
|
|
19730
|
+
cleartext: (placeholders) => this.ask("pg", "password-cleartext", { placeholders }),
|
|
19731
|
+
scram: (scram) => this.ask("pg", "scram-sha-256", { scram })
|
|
19732
|
+
});
|
|
19733
|
+
this.smtp = new SmtpClient(
|
|
19734
|
+
(position, placeholders) => this.ask("smtp", position, { placeholders })
|
|
19735
|
+
);
|
|
19736
|
+
}
|
|
19737
|
+
write(bytes) {
|
|
19738
|
+
const run2 = this.chain.then(() => this.take(bytes));
|
|
19739
|
+
this.chain = run2.then(
|
|
19740
|
+
() => void 0,
|
|
19741
|
+
() => void 0
|
|
19742
|
+
);
|
|
19743
|
+
return run2;
|
|
19744
|
+
}
|
|
19745
|
+
proven;
|
|
19746
|
+
proof(protocol) {
|
|
19747
|
+
this.proven ??= this.prove(protocol).catch(() => void 0);
|
|
19748
|
+
return this.proven;
|
|
19749
|
+
}
|
|
19750
|
+
async prove(protocol) {
|
|
19751
|
+
const s = this.s;
|
|
19752
|
+
if (s.anchoring) {
|
|
19753
|
+
const found = await s.broker.sessionAnchors({
|
|
19754
|
+
stamp: await s.stamp(),
|
|
19755
|
+
session: this.session,
|
|
19756
|
+
host: s.host,
|
|
19757
|
+
port: s.port,
|
|
19758
|
+
protocol,
|
|
19759
|
+
exit: s.exit
|
|
19760
|
+
});
|
|
19761
|
+
const anchor = found ? await s.anchoring(found) : void 0;
|
|
19762
|
+
if (anchor) return { anchor };
|
|
19763
|
+
}
|
|
19764
|
+
return s.verified ? {} : void 0;
|
|
19765
|
+
}
|
|
19766
|
+
async ask(protocol, position, extra) {
|
|
19767
|
+
const s = this.s;
|
|
19768
|
+
const proof = await this.proof(protocol);
|
|
19769
|
+
if (!proof) return void 0;
|
|
19770
|
+
return s.broker.sessionMaterialize({
|
|
19771
|
+
stamp: await s.stamp(),
|
|
19772
|
+
session: this.session,
|
|
19773
|
+
host: s.host,
|
|
19774
|
+
port: s.port,
|
|
19775
|
+
protocol,
|
|
19776
|
+
position,
|
|
19777
|
+
verified: true,
|
|
19778
|
+
...proof.anchor ? { verifiedBy: "anchored", anchor: proof.anchor } : { verifiedBy: "roots" },
|
|
19779
|
+
handshakeAt: s.handshakeAt,
|
|
19780
|
+
exit: s.exit,
|
|
19781
|
+
...extra
|
|
19782
|
+
});
|
|
19783
|
+
}
|
|
19784
|
+
remember(values) {
|
|
19785
|
+
this.scope.add(
|
|
19786
|
+
Object.entries(values).map(([placeholder, value2]) => ({ name: "sealed", value: value2, placeholder }))
|
|
19787
|
+
);
|
|
19788
|
+
}
|
|
19789
|
+
async take(bytes) {
|
|
19790
|
+
if (this.failed !== void 0) throw this.failed;
|
|
19791
|
+
if (this.mode === "pass") return this.conn.write(bytes);
|
|
19792
|
+
clearTimeout(this.timer);
|
|
19793
|
+
const joined4 = new Uint8Array(this.buffer.length + bytes.length);
|
|
19794
|
+
joined4.set(this.buffer);
|
|
19795
|
+
joined4.set(bytes, this.buffer.length);
|
|
19796
|
+
this.buffer.fill(0);
|
|
19797
|
+
this.buffer = joined4;
|
|
19798
|
+
if (this.mode === "sniff") this.mode = modeOf(latin12(joined4.subarray(0, 8))) ?? "sniff";
|
|
19799
|
+
if (this.mode === "pg") this.sawPg = true;
|
|
19800
|
+
if (this.mode === "pass") await this.release();
|
|
19801
|
+
else if (this.mode === "http1") await this.http1();
|
|
19802
|
+
else if (this.mode === "smtp") await this.lines();
|
|
19803
|
+
else if (this.mode === "pg") await this.messages();
|
|
19804
|
+
if (this.mode !== "pass" && this.buffer.length > 0)
|
|
19805
|
+
this.timer = setTimeout(() => this.idle(), HEAD_IDLE_MS);
|
|
19806
|
+
return bytes.length;
|
|
19807
|
+
}
|
|
19808
|
+
async http1() {
|
|
19809
|
+
const end = headEnd2(this.buffer);
|
|
19810
|
+
if (end > HEAD_MAX || end < 0 && this.buffer.length > HEAD_MAX) await this.release();
|
|
19811
|
+
else if (end >= 0) await this.substitute(end);
|
|
19812
|
+
}
|
|
19813
|
+
async lines() {
|
|
19814
|
+
for (; ; ) {
|
|
19815
|
+
const at = crlf(this.buffer);
|
|
19816
|
+
if (at < 0) break;
|
|
19817
|
+
if (at > SMTP_LINE_MAX) return this.release();
|
|
19818
|
+
const all = this.buffer;
|
|
19819
|
+
this.buffer = all.slice(at + 2);
|
|
19820
|
+
const out = await this.smtp.line(latin12(all.subarray(0, at))).catch(() => ({ line: latin12(all.subarray(0, at)) }));
|
|
19821
|
+
all.fill(0);
|
|
19822
|
+
if ("values" in out && out.values) this.remember(out.values);
|
|
19823
|
+
const line = bytesOf(`${out.line}\r
|
|
19824
|
+
`);
|
|
19825
|
+
try {
|
|
19826
|
+
await writeAll4(this.conn, line);
|
|
19827
|
+
} finally {
|
|
19828
|
+
line.fill(0);
|
|
19829
|
+
}
|
|
19830
|
+
if (this.smtp.done) return this.release();
|
|
19831
|
+
}
|
|
19832
|
+
if (this.buffer.length > SMTP_LINE_MAX) await this.release();
|
|
19833
|
+
}
|
|
19834
|
+
async messages() {
|
|
19835
|
+
for (; ; ) {
|
|
19836
|
+
const whole = pgLength(this.buffer, this.pgStarted);
|
|
19837
|
+
if (whole === void 0 || whole < 4 || whole > PG_MESSAGE_MAX) {
|
|
19838
|
+
if (whole !== void 0) await this.release();
|
|
19839
|
+
return;
|
|
19840
|
+
}
|
|
19841
|
+
if (this.buffer.length < whole) return;
|
|
19842
|
+
const message3 = this.buffer.slice(0, whole);
|
|
19843
|
+
this.buffer = this.buffer.slice(whole);
|
|
19844
|
+
const started = this.pgStarted;
|
|
19845
|
+
this.pgStarted = true;
|
|
19846
|
+
const out = started ? await this.pgClient.message(message3).catch(() => ({ bytes: message3, done: true })) : { bytes: message3, done: false };
|
|
19847
|
+
if ("values" in out && out.values) this.remember(out.values);
|
|
19848
|
+
try {
|
|
19849
|
+
await writeAll4(this.conn, out.bytes);
|
|
19850
|
+
} finally {
|
|
19851
|
+
out.bytes.fill(0);
|
|
19852
|
+
message3.fill(0);
|
|
19853
|
+
}
|
|
19854
|
+
if (out.done) return this.release();
|
|
19855
|
+
}
|
|
19856
|
+
}
|
|
19857
|
+
idle() {
|
|
19858
|
+
this.chain = this.chain.then(() => this.release()).catch((err) => {
|
|
19859
|
+
this.failed ??= err;
|
|
19860
|
+
});
|
|
19861
|
+
}
|
|
19862
|
+
async release() {
|
|
19863
|
+
this.mode = "pass";
|
|
19864
|
+
const out = this.buffer;
|
|
19865
|
+
this.buffer = new Uint8Array(0);
|
|
19866
|
+
try {
|
|
19867
|
+
await writeAll4(this.conn, out);
|
|
19868
|
+
} finally {
|
|
19869
|
+
out.fill(0);
|
|
19870
|
+
}
|
|
19871
|
+
}
|
|
19872
|
+
async substitute(end) {
|
|
19873
|
+
this.mode = "pass";
|
|
19874
|
+
const all = this.buffer;
|
|
19875
|
+
this.buffer = new Uint8Array(0);
|
|
19876
|
+
const done5 = await substituteHead(
|
|
19877
|
+
latin12(all.subarray(0, end)),
|
|
19878
|
+
(position, placeholders, head2) => this.ask("http1", position, { placeholders, head: head2 })
|
|
19879
|
+
).catch(() => void 0);
|
|
19880
|
+
const head = done5 ? bytesOf(done5.head) : all.subarray(0, end);
|
|
19881
|
+
if (done5) this.remember(done5.values);
|
|
19882
|
+
try {
|
|
19883
|
+
await writeAll4(this.conn, head);
|
|
19884
|
+
await writeAll4(this.conn, all.subarray(end));
|
|
19885
|
+
} finally {
|
|
19886
|
+
head.fill(0);
|
|
19887
|
+
all.fill(0);
|
|
19888
|
+
}
|
|
19889
|
+
}
|
|
19890
|
+
flushed() {
|
|
19891
|
+
clearTimeout(this.timer);
|
|
19892
|
+
this.chain = this.chain.then(() => this.mode === "pass" ? void 0 : this.release());
|
|
19893
|
+
return this.chain;
|
|
19894
|
+
}
|
|
19895
|
+
drop() {
|
|
19896
|
+
clearTimeout(this.timer);
|
|
19897
|
+
this.buffer.fill(0);
|
|
19898
|
+
this.buffer = new Uint8Array(0);
|
|
19899
|
+
this.mode = "pass";
|
|
19900
|
+
}
|
|
19901
|
+
};
|
|
19902
|
+
var IDLE2 = /* @__PURE__ */ Symbol("idle");
|
|
19903
|
+
var ScrubReader = class {
|
|
19904
|
+
stream;
|
|
19905
|
+
version = 0;
|
|
19906
|
+
next;
|
|
19907
|
+
held = false;
|
|
19679
19908
|
ended = false;
|
|
19680
19909
|
conn;
|
|
19681
|
-
|
|
19682
|
-
constructor(conn,
|
|
19910
|
+
scope;
|
|
19911
|
+
constructor(conn, scope) {
|
|
19683
19912
|
this.conn = conn;
|
|
19684
|
-
this.
|
|
19913
|
+
this.scope = scope;
|
|
19685
19914
|
}
|
|
19686
|
-
|
|
19687
|
-
|
|
19915
|
+
current() {
|
|
19916
|
+
const scrub = this.scope.of();
|
|
19917
|
+
if (!scrub || scrub.version === this.version) return new Uint8Array(0);
|
|
19918
|
+
const tail2 = this.stream?.end() ?? new Uint8Array(0);
|
|
19919
|
+
const stream = scrub.scrubber.stream();
|
|
19920
|
+
this.stream = stream;
|
|
19921
|
+
this.version = scrub.version;
|
|
19922
|
+
this.held = tail2.length > 0;
|
|
19923
|
+
return tail2.length > 0 ? stream.push(tail2) : tail2;
|
|
19688
19924
|
}
|
|
19689
|
-
async
|
|
19690
|
-
|
|
19691
|
-
|
|
19692
|
-
|
|
19693
|
-
|
|
19694
|
-
|
|
19695
|
-
|
|
19696
|
-
this.
|
|
19697
|
-
|
|
19698
|
-
|
|
19699
|
-
|
|
19700
|
-
|
|
19701
|
-
|
|
19702
|
-
|
|
19703
|
-
this.queue[0] = head.subarray(n);
|
|
19704
|
-
break;
|
|
19925
|
+
async read() {
|
|
19926
|
+
for (; ; ) {
|
|
19927
|
+
if (this.ended) return null;
|
|
19928
|
+
const tail2 = this.current();
|
|
19929
|
+
if (tail2.length > 0) return tail2;
|
|
19930
|
+
const next3 = this.next ?? this.conn.read();
|
|
19931
|
+
this.next = void 0;
|
|
19932
|
+
const got = this.held ? await Promise.race([next3, idle()]) : await next3;
|
|
19933
|
+
if (got === IDLE2) {
|
|
19934
|
+
this.next = next3;
|
|
19935
|
+
this.held = false;
|
|
19936
|
+
const out2 = this.stream.idle();
|
|
19937
|
+
if (out2.length > 0) return out2;
|
|
19938
|
+
continue;
|
|
19705
19939
|
}
|
|
19706
|
-
this.
|
|
19940
|
+
const before = this.current();
|
|
19941
|
+
const out = this.through(got);
|
|
19942
|
+
if (before.length === 0 && out !== void 0) return out;
|
|
19943
|
+
if (before.length > 0) return joined3(before, out);
|
|
19707
19944
|
}
|
|
19708
|
-
return true;
|
|
19709
19945
|
}
|
|
19710
|
-
|
|
19711
|
-
|
|
19712
|
-
|
|
19713
|
-
|
|
19714
|
-
|
|
19715
|
-
|
|
19716
|
-
|
|
19717
|
-
if (!(n > 0)) throw new KernelError("EPIPE");
|
|
19718
|
-
at += n;
|
|
19946
|
+
through(got) {
|
|
19947
|
+
const stream = this.stream;
|
|
19948
|
+
if (!stream) return got;
|
|
19949
|
+
if (got === null) {
|
|
19950
|
+
this.ended = true;
|
|
19951
|
+
const out2 = stream.end();
|
|
19952
|
+
return out2.length > 0 ? out2 : null;
|
|
19719
19953
|
}
|
|
19954
|
+
const out = stream.push(got);
|
|
19955
|
+
this.held = true;
|
|
19956
|
+
return out.length > 0 ? out : void 0;
|
|
19720
19957
|
}
|
|
19958
|
+
};
|
|
19959
|
+
function joined3(a, b) {
|
|
19960
|
+
if (!b) return a;
|
|
19961
|
+
const out = new Uint8Array(a.length + b.length);
|
|
19962
|
+
out.set(a);
|
|
19963
|
+
out.set(b, a.length);
|
|
19964
|
+
return out;
|
|
19721
19965
|
}
|
|
19722
|
-
function
|
|
19723
|
-
|
|
19724
|
-
const code = verifyCode(flags2);
|
|
19725
|
-
if (code && flags2 !== -1)
|
|
19726
|
-
return new KernelError("EPROTO", `${code}: ${engine.verifyInfo(flags2).trim()}`);
|
|
19727
|
-
const text = err instanceof TlsError ? err.message : String(err);
|
|
19728
|
-
return new KernelError("EPROTO", `ERR_SSL_HANDSHAKE_FAILURE: ${text}${alertOf(session)}`);
|
|
19729
|
-
}
|
|
19730
|
-
function alertOf(session) {
|
|
19731
|
-
const alert = session.lastAlert;
|
|
19732
|
-
return alert >= 0 ? ` (alert ${alert})` : "";
|
|
19966
|
+
function idle() {
|
|
19967
|
+
return new Promise((resolve2) => setTimeout(() => resolve2(IDLE2), SCRUB_IDLE_MS));
|
|
19733
19968
|
}
|
|
19734
|
-
|
|
19735
|
-
|
|
19736
|
-
|
|
19737
|
-
|
|
19738
|
-
|
|
19739
|
-
|
|
19740
|
-
|
|
19741
|
-
|
|
19742
|
-
|
|
19743
|
-
|
|
19744
|
-
|
|
19745
|
-
|
|
19746
|
-
|
|
19747
|
-
|
|
19748
|
-
|
|
19749
|
-
|
|
19969
|
+
function sealedConn(conn, s) {
|
|
19970
|
+
const pg = new PgServer();
|
|
19971
|
+
const scope = s.broker.sessions.scope(s.pid, s.host);
|
|
19972
|
+
const writer = substitutes(s) ? new SessionWriter(conn, s, pg, scope) : void 0;
|
|
19973
|
+
const observed = {
|
|
19974
|
+
...conn,
|
|
19975
|
+
read: async () => {
|
|
19976
|
+
for (; ; ) {
|
|
19977
|
+
const bytes = await conn.read();
|
|
19978
|
+
if (!bytes) return bytes;
|
|
19979
|
+
const out = writer?.sawPg ? pg.filter(bytes) : bytes;
|
|
19980
|
+
if (pg.failed) {
|
|
19981
|
+
conn.close();
|
|
19982
|
+
throw new KernelError(
|
|
19983
|
+
"EPROTO",
|
|
19984
|
+
"ERR_SSL_PROTOCOL_ERROR: the pg server failed the SCRAM proof"
|
|
19985
|
+
);
|
|
19986
|
+
}
|
|
19987
|
+
if (out.length > 0) return out;
|
|
19988
|
+
}
|
|
19750
19989
|
}
|
|
19751
|
-
}
|
|
19752
|
-
}
|
|
19753
|
-
function insecureOf(session, chain2, shape) {
|
|
19754
|
-
const flags2 = session.verifyResult;
|
|
19755
|
-
const error = chainError(flags2, chain2, shape);
|
|
19756
|
-
return { hostnameMatches: nameMatches(flags2), ...error ? { chainError: error } : {} };
|
|
19757
|
-
}
|
|
19758
|
-
function controlsOf(o, session, protocol, chain2, shape) {
|
|
19759
|
-
if (!o.engine.sessionControls) return {};
|
|
19760
|
-
const checked = o.checkHostname !== false && !o.insecure;
|
|
19761
|
-
return {
|
|
19762
|
-
cipher: cipherOf(session.ciphersuite, protocol),
|
|
19763
|
-
clientCertificate: o.clientCertificate === true,
|
|
19764
|
-
sni: o.sni !== false && !isIP(o.servername),
|
|
19765
|
-
hostnameChecked: checked,
|
|
19766
|
-
...o.insecure ? insecureOf(session, chain2, shape) : { hostnameMatches: checked || !session.nameMismatch }
|
|
19767
|
-
};
|
|
19768
|
-
}
|
|
19769
|
-
function verdictOf(o, session) {
|
|
19770
|
-
if (o.bundled !== true || isIP(o.servername) || session.verifyResult !== 0) return false;
|
|
19771
|
-
return o.checkHostname !== false || !session.nameMismatch;
|
|
19772
|
-
}
|
|
19773
|
-
async function infoOf(o, session) {
|
|
19774
|
-
const flags2 = session.verifyResult;
|
|
19775
|
-
const code = verifyCode(flags2);
|
|
19776
|
-
const protocol = session.version === 772 ? "TLSv1.3" : "TLSv1.2";
|
|
19777
|
-
const chain2 = session.peerChain();
|
|
19778
|
-
const shape = await chainShape(o.insecure ? chain2 : []);
|
|
19779
|
-
return {
|
|
19780
|
-
protocol,
|
|
19781
|
-
alpnProtocol: session.alpn ?? false,
|
|
19782
|
-
authorized: code === void 0,
|
|
19783
|
-
...code ? { authorizationError: code, authorizationText: o.engine.verifyInfo(flags2).trim() } : {},
|
|
19784
|
-
peerCertificates: chain2,
|
|
19785
|
-
...controlsOf(o, session, protocol, chain2, shape),
|
|
19786
|
-
verified: verdictOf(o, session),
|
|
19787
|
-
handshakeAt: Date.now()
|
|
19788
|
-
};
|
|
19789
|
-
}
|
|
19790
|
-
var FATAL_ALERT = -30592;
|
|
19791
|
-
function alerted(err, session) {
|
|
19792
|
-
if (err.code === FATAL_ALERT)
|
|
19793
|
-
return new KernelError(
|
|
19794
|
-
"EPROTO",
|
|
19795
|
-
`ERR_SSL_FATAL_ALERT: the server ended the session: ${err.message}${alertOf(session)}`
|
|
19796
|
-
);
|
|
19797
|
-
return new KernelError("EPROTO", `ERR_SSL_PROTOCOL_ERROR: ${err.message}`);
|
|
19798
|
-
}
|
|
19799
|
-
function plaintext(conn, session, inbox) {
|
|
19800
|
-
let freed = false;
|
|
19801
|
-
let writeClosed = false;
|
|
19802
|
-
const free = () => {
|
|
19803
|
-
if (freed) return;
|
|
19804
|
-
freed = true;
|
|
19805
|
-
session.free();
|
|
19806
19990
|
};
|
|
19991
|
+
const reader = new ScrubReader(writer ? observed : conn, scope);
|
|
19807
19992
|
return {
|
|
19808
19993
|
localAddr: conn.localAddr,
|
|
19809
19994
|
remoteAddr: conn.remoteAddr,
|
|
19810
|
-
|
|
19811
|
-
|
|
19812
|
-
if (freed) return null;
|
|
19813
|
-
let got;
|
|
19814
|
-
try {
|
|
19815
|
-
got = session.read();
|
|
19816
|
-
} catch (err) {
|
|
19817
|
-
throw alerted(err, session);
|
|
19818
|
-
}
|
|
19819
|
-
await send(conn, session);
|
|
19820
|
-
if (got instanceof Uint8Array) return got;
|
|
19821
|
-
if (got === "eof") return null;
|
|
19822
|
-
await inbox.more();
|
|
19823
|
-
}
|
|
19824
|
-
},
|
|
19825
|
-
async write(bytes) {
|
|
19826
|
-
if (freed) throw new KernelError("EPIPE");
|
|
19827
|
-
for (; ; ) {
|
|
19828
|
-
const n = session.write(bytes.subarray(0, WRITE_CHUNK));
|
|
19829
|
-
await send(conn, session);
|
|
19830
|
-
if (n > 0) return n;
|
|
19831
|
-
}
|
|
19832
|
-
},
|
|
19995
|
+
read: () => reader.read(),
|
|
19996
|
+
write: (bytes) => writer ? writer.write(bytes) : conn.write(bytes),
|
|
19833
19997
|
closeWrite() {
|
|
19834
|
-
if (
|
|
19835
|
-
|
|
19836
|
-
|
|
19837
|
-
|
|
19998
|
+
if (!writer) return conn.closeWrite();
|
|
19999
|
+
void writer.flushed().then(
|
|
20000
|
+
() => conn.closeWrite(),
|
|
20001
|
+
() => conn.closeWrite()
|
|
20002
|
+
);
|
|
19838
20003
|
},
|
|
19839
20004
|
close() {
|
|
19840
|
-
|
|
20005
|
+
writer?.drop();
|
|
19841
20006
|
conn.close();
|
|
19842
20007
|
}
|
|
19843
20008
|
};
|
|
19844
20009
|
}
|
|
19845
|
-
async function tlsClient(conn, o, taken = new Uint8Array(0)) {
|
|
19846
|
-
const session = o.session ?? openSession(o);
|
|
19847
|
-
const inbox = new Ciphertext(conn, session);
|
|
19848
|
-
inbox.hand(taken);
|
|
19849
|
-
try {
|
|
19850
|
-
await handshake(conn, o, session, inbox);
|
|
19851
|
-
const info = await infoOf(o, session);
|
|
19852
|
-
return { conn: plaintext(conn, session, inbox), info };
|
|
19853
|
-
} catch (err) {
|
|
19854
|
-
session.free();
|
|
19855
|
-
throw err;
|
|
19856
|
-
}
|
|
19857
|
-
}
|
|
19858
20010
|
|
|
19859
20011
|
// src/kernel/net/tls-uplink.ts
|
|
19860
20012
|
var isIP2 = (text) => ipv4Bytes(text) !== void 0 || text.includes(":") && ipv6Groups(text) !== void 0;
|
|
@@ -19903,6 +20055,7 @@ function sessionOf(info, servername) {
|
|
|
19903
20055
|
path: "kernel",
|
|
19904
20056
|
substitutes: info.substitutes === true,
|
|
19905
20057
|
verified: info.verified,
|
|
20058
|
+
verifiedBy: info.verified ? "bundled" : "none",
|
|
19906
20059
|
protocol: info.protocol,
|
|
19907
20060
|
alpnProtocol: info.alpnProtocol,
|
|
19908
20061
|
authorized: info.authorized,
|
|
@@ -19975,9 +20128,9 @@ function takeCert(req) {
|
|
|
19975
20128
|
}
|
|
19976
20129
|
const chain2 = new Uint8Array(ders.reduce((n, d) => n + d.length, 0));
|
|
19977
20130
|
let at = 0;
|
|
19978
|
-
for (const
|
|
19979
|
-
chain2.set(
|
|
19980
|
-
at +=
|
|
20131
|
+
for (const der2 of ders) {
|
|
20132
|
+
chain2.set(der2, at);
|
|
20133
|
+
at += der2.length;
|
|
19981
20134
|
}
|
|
19982
20135
|
const pass2 = new TextEncoder().encode(cert.passphrase ?? "");
|
|
19983
20136
|
return { chain: chain2, key, pass: pass2 };
|
|
@@ -20004,7 +20157,7 @@ async function setUp(support, req) {
|
|
|
20004
20157
|
throw new KernelError("EINVAL", "ERR_INVALID_ARG_VALUE: ca has no certificate");
|
|
20005
20158
|
const own = engine.store();
|
|
20006
20159
|
try {
|
|
20007
|
-
for (const
|
|
20160
|
+
for (const der2 of custom) own.add(base64Der(der2));
|
|
20008
20161
|
} catch (err) {
|
|
20009
20162
|
own.release();
|
|
20010
20163
|
throw new KernelError("EINVAL", `ERR_INVALID_ARG_VALUE: ca: ${err.message}`);
|
|
@@ -20056,6 +20209,13 @@ async function prepareWith(support, req, servername, cert) {
|
|
|
20056
20209
|
throw err;
|
|
20057
20210
|
}
|
|
20058
20211
|
}
|
|
20212
|
+
function anchoringOf(seal, info, servername) {
|
|
20213
|
+
const engine = seal.engine;
|
|
20214
|
+
if (!engine?.chainVerify || isIP2(servername) || info.peerCertificates.length === 0) return {};
|
|
20215
|
+
return {
|
|
20216
|
+
anchoring: (found) => anchorFor(engine, info.peerCertificates, servername, found)
|
|
20217
|
+
};
|
|
20218
|
+
}
|
|
20059
20219
|
function sealing(seal, raw2, info, servername) {
|
|
20060
20220
|
const { proc } = seal;
|
|
20061
20221
|
const broker = proc.sealed;
|
|
@@ -20070,7 +20230,8 @@ function sealing(seal, raw2, info, servername) {
|
|
|
20070
20230
|
exit: raw2.exit,
|
|
20071
20231
|
verified: info.verified,
|
|
20072
20232
|
handshakeAt: info.handshakeAt,
|
|
20073
|
-
alpn: info.alpnProtocol
|
|
20233
|
+
alpn: info.alpnProtocol,
|
|
20234
|
+
...anchoringOf(seal, info, servername)
|
|
20074
20235
|
};
|
|
20075
20236
|
return session;
|
|
20076
20237
|
}
|
|
@@ -20080,7 +20241,8 @@ function secure(prepared, seal) {
|
|
|
20080
20241
|
ran = true;
|
|
20081
20242
|
try {
|
|
20082
20243
|
const made2 = await tlsClient(raw2, prepared.options);
|
|
20083
|
-
const
|
|
20244
|
+
const engine = prepared.options.engine;
|
|
20245
|
+
const session = sealing({ ...seal, engine }, raw2, made2.info, prepared.options.servername);
|
|
20084
20246
|
if (!session) return made2;
|
|
20085
20247
|
made2.info.substitutes = substitutes(session);
|
|
20086
20248
|
return { conn: sealedConn(made2.conn, session), info: made2.info };
|
|
@@ -20999,9 +21161,9 @@ var VfsNodes = class {
|
|
|
20999
21161
|
}
|
|
21000
21162
|
open(path, pin, writable2 = false, id2, ino) {
|
|
21001
21163
|
const found = this.named(path, id2);
|
|
21002
|
-
const
|
|
21003
|
-
if (found && !
|
|
21004
|
-
const node = (
|
|
21164
|
+
const same3 = !found || ino === void 0 || found.ino === void 0 || found.ino === ino;
|
|
21165
|
+
if (found && !same3) this.orphan(found);
|
|
21166
|
+
const node = (same3 ? found : void 0) ?? this.create(path, id2, new VfsNode(this.fs, path, void 0, false, false, pin));
|
|
21005
21167
|
node.ino ??= ino;
|
|
21006
21168
|
node.opens++;
|
|
21007
21169
|
if (writable2) node.writers++;
|
|
@@ -24716,6 +24878,10 @@ var SealedBroker = class {
|
|
|
24716
24878
|
const req = sessionRequest(fields);
|
|
24717
24879
|
return this.ask(req, (reply) => sessionValues(reply, req.placeholders));
|
|
24718
24880
|
}
|
|
24881
|
+
async sessionAnchors(fields) {
|
|
24882
|
+
if (!anchorsAskable(fields)) return void 0;
|
|
24883
|
+
return this.ask(anchorsRequest(fields), anchorsOf);
|
|
24884
|
+
}
|
|
24719
24885
|
async ask(req, parse) {
|
|
24720
24886
|
const { hook } = this;
|
|
24721
24887
|
if (!hook) return void 0;
|
|
@@ -25525,14 +25691,14 @@ function hostfsHandlers(current, againMs = RESTORE_AGAIN_MS) {
|
|
|
25525
25691
|
return fresh2(remote);
|
|
25526
25692
|
};
|
|
25527
25693
|
const call = (op, body = {}) => current().call(op, body);
|
|
25528
|
-
const
|
|
25694
|
+
const same3 = (was, mode, seen) => seen?.mode === (mode | 128) && (was.ino !== void 0 && seen.ino !== void 0 ? seen.ino === was.ino : seen.size === was.size && seen.mtime === was.mtime);
|
|
25529
25695
|
const settle3 = (client, { was, ...restore }) => client.call("setattr", restore).catch((err) => {
|
|
25530
25696
|
if (!client.gone || !client.cleanup) throw err;
|
|
25531
25697
|
void client.cleanup("setattr", restore).catch(() => {
|
|
25532
25698
|
});
|
|
25533
25699
|
const timer = setTimeout(async () => {
|
|
25534
25700
|
const seen = await client.cleanup?.("stat", { path: restore.path }).catch(() => null);
|
|
25535
|
-
if (
|
|
25701
|
+
if (same3(was, restore.mode, seen))
|
|
25536
25702
|
void client.cleanup?.("setattr", restore).catch(() => {
|
|
25537
25703
|
});
|
|
25538
25704
|
}, againMs);
|
|
@@ -27640,9 +27806,9 @@ var Launcher = class {
|
|
|
27640
27806
|
const known = this.sameFiles.get(`${a}|${b}`);
|
|
27641
27807
|
if (known?.stamp === stamp) return known.same;
|
|
27642
27808
|
const [p, q] = await Promise.all([this.base.readFileBuffer(a), this.base.readFileBuffer(b)]);
|
|
27643
|
-
const
|
|
27644
|
-
this.sameFiles.set(`${a}|${b}`, { stamp, same:
|
|
27645
|
-
return
|
|
27809
|
+
const same3 = p.length === q.length && p.every((byte, i) => byte === q[i]);
|
|
27810
|
+
this.sameFiles.set(`${a}|${b}`, { stamp, same: same3 });
|
|
27811
|
+
return same3;
|
|
27646
27812
|
}
|
|
27647
27813
|
async wasmOwner(wasm, name2, scope) {
|
|
27648
27814
|
const leaf = baseName2(wasm);
|
|
@@ -27709,11 +27875,12 @@ var Launcher = class {
|
|
|
27709
27875
|
asked: named
|
|
27710
27876
|
};
|
|
27711
27877
|
}
|
|
27712
|
-
async plan(file, argv, cwd, scope, argv0) {
|
|
27878
|
+
async plan(file, argv, cwd, scope, argv0, catalogOnly = false) {
|
|
27713
27879
|
const found = await this.resolve(file, argv[0] ?? file, cwd, scope);
|
|
27714
27880
|
const named = typeof argv0 === "string" && found && !found.fixed;
|
|
27715
27881
|
const direct = named ? { ...found, argv0 } : found;
|
|
27716
27882
|
if (direct) return { target: direct, args: [...direct.prefix ?? [], ...argv.slice(1)] };
|
|
27883
|
+
if (catalogOnly && !await this.scriptCommand(file, cwd, scope)) return void 0;
|
|
27717
27884
|
const script = await this.interpreted(file, argv, cwd, scope);
|
|
27718
27885
|
return script && { ...script, script: true };
|
|
27719
27886
|
}
|
|
@@ -27752,16 +27919,12 @@ var Launcher = class {
|
|
|
27752
27919
|
}
|
|
27753
27920
|
async planOrSearch(req, ctx) {
|
|
27754
27921
|
const bare = !req.file.includes("/") && !COMMAND2.test(req.file);
|
|
27755
|
-
|
|
27756
|
-
return await this.planOne(req, ctx);
|
|
27757
|
-
} catch (err) {
|
|
27758
|
-
const code = codeOf8(err);
|
|
27759
|
-
const searched = bare && req.search !== false && (code === "ENOENT" || code === "ENOEXEC");
|
|
27760
|
-
if (!searched || await this.commandAt(req.file, ctx.scope)) throw err;
|
|
27922
|
+
if (bare && req.search !== false && !await this.commandAt(req.file, ctx.scope)) {
|
|
27761
27923
|
const found = await this.onPath(req, ctx);
|
|
27762
27924
|
if (found) return found;
|
|
27763
|
-
throw
|
|
27925
|
+
throw new SpawnError("ENOENT");
|
|
27764
27926
|
}
|
|
27927
|
+
return this.planOne(req, ctx, bare && req.search !== false);
|
|
27765
27928
|
}
|
|
27766
27929
|
async onPath(req, ctx) {
|
|
27767
27930
|
const path = req.env.PATH;
|
|
@@ -27780,15 +27943,15 @@ var Launcher = class {
|
|
|
27780
27943
|
if (denied2) throw new SpawnError("EACCES");
|
|
27781
27944
|
return void 0;
|
|
27782
27945
|
}
|
|
27783
|
-
async planOne(req, { ppid, cred, scope }) {
|
|
27946
|
+
async planOne(req, { ppid, cred, scope }, catalogOnly = false) {
|
|
27784
27947
|
const refused3 = (err) => {
|
|
27785
27948
|
throw codeOf8(err) === "EACCES" ? new SpawnError("EACCES") : err;
|
|
27786
27949
|
};
|
|
27787
27950
|
const file = await this.execFile(req.file, req.cwd, this.execGuard(cred, ppid)).catch(refused3);
|
|
27788
|
-
const planned = await this.plan(file, req.argv, req.cwd, scope, req.argv0);
|
|
27951
|
+
const planned = await this.plan(file, req.argv, req.cwd, scope, req.argv0, catalogOnly);
|
|
27789
27952
|
await this.mayExec(cred, { ...req, file, pid: ppid }, planned).catch(refused3);
|
|
27790
27953
|
if (planned) return planned;
|
|
27791
|
-
throw new SpawnError(await this.unrunnable(file, req.cwd, scope));
|
|
27954
|
+
throw new SpawnError(catalogOnly ? "ENOENT" : await this.unrunnable(file, req.cwd, scope));
|
|
27792
27955
|
}
|
|
27793
27956
|
async enterable(g, cwd) {
|
|
27794
27957
|
if (!g) return;
|