nish 0.49.1 → 0.50.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +27 -21
- package/docs/AI.md +233 -159
- package/docs/INSTALL.md +1 -1
- package/package.json +12 -12
- package/runtime/gfx/nish-gfx.h +373 -61
- package/runtime/nish.d.ts +12 -9
- package/std/README.md +8 -5
- package/std/base64.ts +74 -1
- package/std/bytes.ts +201 -93
- package/std/compress/deflate.ts +20 -15
- package/std/crypto/base64url.ts +93 -66
- package/std/crypto/bcrypt.ts +25 -21
- package/std/crypto/hmac.ts +1 -1
- package/std/crypto/jwt.ts +32 -19
- package/std/crypto/p256.ts +9 -12
- package/std/crypto/pki-roots.ts +7 -4
- package/std/crypto/pki.ts +43 -55
- package/std/crypto/rsa-sign.ts +1632 -0
- package/std/crypto/rsa.ts +26 -4
- package/std/crypto/sha256.ts +135 -68
- package/std/crypto/x25519.ts +12 -11
- package/std/crypto/x509.ts +164 -40
- package/std/gpu/sys.ts +490 -0
- package/std/json-equal.ts +33 -18
- package/std/json-format.ts +39 -8
- package/std/json-number.ts +15 -3
- package/std/json-tokenizer.ts +4 -3
- package/std/json-typed.ts +12 -6
- package/std/json-value.ts +222 -104
- package/std/json.ts +81 -46
- package/std/net/dns-config.ts +18 -5
- package/std/net/dns-message.ts +60 -27
- package/std/net/dns-resolver.ts +35 -16
- package/std/net/dns.ts +3 -2
- package/std/net/fetch.ts +120 -38
- package/std/net/handler.ts +178 -66
- package/std/net/hpack.ts +192 -98
- package/std/net/http-compress.ts +83 -30
- package/std/net/http-fields.ts +327 -31
- package/std/net/http-server.ts +317 -20
- package/std/net/http1-client-codec.ts +137 -40
- package/std/net/http1-codec.ts +391 -202
- package/std/net/http1-server.ts +220 -38
- package/std/net/http2-cleartext.ts +10 -4
- package/std/net/http2-frame.ts +2 -2
- package/std/net/http2-tls.ts +3 -3
- package/std/net/http2.ts +69 -15
- package/std/net/http3-frame.ts +11 -14
- package/std/net/http3-server.ts +12 -15
- package/std/net/http3.ts +41 -29
- package/std/net/multipart.ts +592 -0
- package/std/net/outbound.ts +24 -8
- package/std/net/postgres-async.ts +92 -54
- package/std/net/postgres-carrier.ts +28 -4
- package/std/net/postgres.ts +166 -65
- package/std/net/prefork.ts +86 -5
- package/std/net/protobuf.ts +6 -2
- package/std/net/qpack.ts +66 -25
- package/std/net/quic-conn-ack.ts +27 -7
- package/std/net/quic-conn-cid.ts +13 -7
- package/std/net/quic-datagram.ts +6 -5
- package/std/net/quic-frame.ts +67 -23
- package/std/net/quic-listener.ts +19 -12
- package/std/net/quic-recovery.ts +11 -9
- package/std/net/quic-stream.ts +7 -5
- package/std/net/quic.ts +36 -31
- package/std/net/router.ts +136 -24
- package/std/net/serve.ts +59 -5
- package/std/net/static.ts +81 -33
- package/std/net/tls/record.ts +26 -13
- package/std/net/tls/ticket.ts +6 -5
- package/std/net/tls-tcp.ts +69 -30
- package/std/net/tls.ts +152 -38
- package/std/net/upstream.ts +65 -19
- package/std/net/url.ts +97 -78
- package/std/net/websocket.ts +16 -9
- package/std/net/webtransport.ts +28 -12
- package/std/regex.ts +600 -388
- package/std/sqlite.ts +37 -19
- package/std/sync/ring.ts +232 -115
- package/std/sync/shm.ts +11 -4
- package/std/temporal.ts +232 -133
- package/std/term-io.ts +12 -6
- package/std/term-pixels.ts +158 -22
- package/std/term-rate.ts +8 -3
- package/std/term.ts +4 -4
- package/std/text.ts +33 -11
- package/std/yaml-json.ts +238 -106
- package/std/yaml-lines.ts +47 -27
- package/std/yaml-write.ts +58 -24
- package/std/yaml.ts +808 -395
package/std/crypto/pki.ts
CHANGED
|
@@ -282,18 +282,20 @@ const pkiFoldEqualAt = (a: string, aAt: i32, b: string, bAt: i32, n: i32): boole
|
|
|
282
282
|
if (aAt < 0 || bAt < 0 || n < 0 || n > toI32(a.length) - aAt || n > toI32(b.length) - bAt) {
|
|
283
283
|
return false
|
|
284
284
|
}
|
|
285
|
+
let x: i32 = aAt
|
|
286
|
+
let y: i32 = bAt
|
|
285
287
|
for (let i: i32 = 0; i < n; i++) {
|
|
286
|
-
// Unsigned: aAt + i < a.length and bAt + i < b.length, so neither wraps.
|
|
287
|
-
const x: i32 = toI32(toU32(aAt) + toU32(i))
|
|
288
|
-
const y: i32 = toI32(toU32(bAt) + toU32(i))
|
|
289
288
|
// Restates the range checked above for the index proof, which does not
|
|
290
|
-
// carry it through the
|
|
289
|
+
// carry it through `aAt + i`; past it, each step to the next index is
|
|
290
|
+
// proven.
|
|
291
291
|
if (x < 0 || y < 0 || x >= toI32(a.length) || y >= toI32(b.length)) {
|
|
292
292
|
return false
|
|
293
293
|
}
|
|
294
294
|
if (pkiLower(toI32(a.charCodeAt(x))) !== pkiLower(toI32(b.charCodeAt(y)))) {
|
|
295
295
|
return false
|
|
296
296
|
}
|
|
297
|
+
x = x + 1
|
|
298
|
+
y = y + 1
|
|
297
299
|
}
|
|
298
300
|
return true
|
|
299
301
|
}
|
|
@@ -341,17 +343,6 @@ const pkiValidDns = (s: string): boolean => {
|
|
|
341
343
|
return label > 0
|
|
342
344
|
}
|
|
343
345
|
|
|
344
|
-
const pkiLabelCount = (s: string): i32 => {
|
|
345
|
-
let count: i32 = 1
|
|
346
|
-
for (let i: i32 = 0; i < toI32(s.length); i++) {
|
|
347
|
-
if (toI32(s.charCodeAt(i)) === 46) {
|
|
348
|
-
// Unsigned: count is at most i + 1, below s.length, so it cannot wrap.
|
|
349
|
-
count = toI32(toU32(count) + 1)
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
return count
|
|
353
|
-
}
|
|
354
|
-
|
|
355
346
|
// ---------------------------------------------------------------------------
|
|
356
347
|
// Address literals (RFC 3986 §3.2.2, RFC 4291 §2.2)
|
|
357
348
|
// ---------------------------------------------------------------------------
|
|
@@ -396,8 +387,9 @@ const pkiParseIpv4 = (s: string, start: i32, end: i32): u8[] | null => {
|
|
|
396
387
|
if (d < 0 || digits >= 3 || value > 25 || (digits > 0 && value === 0)) {
|
|
397
388
|
return null
|
|
398
389
|
}
|
|
399
|
-
//
|
|
400
|
-
|
|
390
|
+
// The masks keep what the check above holds (`value` at most 25, `d` a
|
|
391
|
+
// digit) and let src/bounds.ts prove the sum.
|
|
392
|
+
value = (value & 31) * 10 + (d & 15)
|
|
401
393
|
digits++
|
|
402
394
|
if (value > 255) {
|
|
403
395
|
return null
|
|
@@ -549,15 +541,12 @@ const pkiDnsMatch = (san: string, host: string): boolean => {
|
|
|
549
541
|
const rest: string = name.substring(2, n)
|
|
550
542
|
const dot: i32 = toI32(host.indexOf("."))
|
|
551
543
|
const restLength: i32 = n - 2
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
toI32(toU32(dot) + toU32(restLength) + 1) === toI32(host.length) &&
|
|
559
|
-
pkiFoldEqualAt(host, toI32(toU32(dot) + 1), rest, 0, restLength)
|
|
560
|
-
)
|
|
544
|
+
// `indexOf` answers below the length; the bound restated proves `dot + 1`.
|
|
545
|
+
// A valid `rest` with a dot has the two labels or more a wildcard needs.
|
|
546
|
+
if (dot <= 0 || dot >= toI32(host.length) || !pkiValidDns(rest) || toI32(rest.indexOf(".")) < 0) {
|
|
547
|
+
return false
|
|
548
|
+
}
|
|
549
|
+
return restLength === toI32(host.length) - 1 - dot && pkiFoldEqualAt(host, dot + 1, rest, 0, restLength)
|
|
561
550
|
}
|
|
562
551
|
return pkiValidDns(name) && n === toI32(host.length) && pkiFoldEqualAt(name, 0, host, 0, n)
|
|
563
552
|
}
|
|
@@ -943,32 +932,30 @@ const pkiConstraintsCode = (s: PkiSearch, issuer: X509Certificate): i32 => {
|
|
|
943
932
|
}
|
|
944
933
|
// Each name below the issuer, the host's included, against each subtree.
|
|
945
934
|
// Past PKI_MAX_NAME_CHECKS names, one subtree is already over the budget.
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
935
|
+
// In `u64` throughout: `names` is at most PKI_MAX_NAME_CHECKS before each
|
|
936
|
+
// add and each length below 2^32, and `subtrees` is below 2^33, so no sum
|
|
937
|
+
// or product here comes near 2^64.
|
|
938
|
+
const subtrees: u64 = toU64(issuer.ncPermitted.length) + toU64(issuer.ncExcluded.length)
|
|
939
|
+
const budget: u64 = toU64(PKI_MAX_NAME_CHECKS)
|
|
940
|
+
let cost: u64 = toU64(0)
|
|
941
|
+
if (subtrees > toU64(0)) {
|
|
942
|
+
let names: u64 = toU64(1)
|
|
950
943
|
for (const c of s.path) {
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
names = toI64(toU64(names) + toU64(toI64(c.sanDns.length)) + toU64(toI64(c.sanIp.length)) + 1)
|
|
954
|
-
if (names > toI64(PKI_MAX_NAME_CHECKS)) {
|
|
944
|
+
names = names + toU64(c.sanDns.length) + toU64(c.sanIp.length) + toU64(1)
|
|
945
|
+
if (names > budget) {
|
|
955
946
|
s.spent = true
|
|
956
947
|
return PKI_ERR_BUDGET
|
|
957
948
|
}
|
|
958
949
|
}
|
|
959
|
-
|
|
960
|
-
// so the product stays below 2^51.
|
|
961
|
-
cost = toI64(toU64(names) * toU64(subtrees))
|
|
950
|
+
cost = names * subtrees
|
|
962
951
|
}
|
|
963
952
|
const used: i32 = s.nameChecks
|
|
964
|
-
if (
|
|
953
|
+
if (used < 0 || cost > budget) {
|
|
965
954
|
s.spent = true
|
|
966
955
|
return PKI_ERR_BUDGET
|
|
967
956
|
}
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
const total: i64 = toI64(toU64(toI64(used)) + toU64(cost))
|
|
971
|
-
if (total > toI64(PKI_MAX_NAME_CHECKS)) {
|
|
957
|
+
const total: u64 = toU64(used) + cost
|
|
958
|
+
if (total > budget) {
|
|
972
959
|
s.spent = true
|
|
973
960
|
return PKI_ERR_BUDGET
|
|
974
961
|
}
|
|
@@ -1081,14 +1068,15 @@ const pkiIssuerCode = (s: PkiSearch, child: X509Certificate, cand: X509Certifica
|
|
|
1081
1068
|
return PKI_ERR_EXT_KEY_USAGE
|
|
1082
1069
|
}
|
|
1083
1070
|
if (cand.bcPathLen >= 0) {
|
|
1084
|
-
|
|
1071
|
+
// A `u32` count of the path's certificates, which cannot come near 2^32;
|
|
1072
|
+
// `bcPathLen` is not negative here, so its `u32` is its value.
|
|
1073
|
+
let below: u32 = toU32(0)
|
|
1085
1074
|
for (let i: i32 = 1; i < toI32(s.path.length); i++) {
|
|
1086
1075
|
if (!pkiSelfIssued(s.path[i])) {
|
|
1087
|
-
|
|
1088
|
-
below = toI32(toU32(below) + 1)
|
|
1076
|
+
below = below + toU32(1)
|
|
1089
1077
|
}
|
|
1090
1078
|
}
|
|
1091
|
-
if (below > cand.bcPathLen) {
|
|
1079
|
+
if (below > toU32(cand.bcPathLen)) {
|
|
1092
1080
|
return PKI_ERR_PATH_LENGTH
|
|
1093
1081
|
}
|
|
1094
1082
|
}
|
|
@@ -1141,10 +1129,10 @@ const pkiCandidate = (s: PkiSearch, child: X509Certificate, cand: X509Certificat
|
|
|
1141
1129
|
*/
|
|
1142
1130
|
const pkiExtend = (s: PkiSearch, child: X509Certificate): boolean => {
|
|
1143
1131
|
const depth: i32 = toI32(s.path.length)
|
|
1144
|
-
//
|
|
1145
|
-
//
|
|
1146
|
-
const above: i32 =
|
|
1147
|
-
const atRoot: i32 =
|
|
1132
|
+
// pkiIssuerCode keeps the path to PKI_MAX_PATH (8) certificates, which the
|
|
1133
|
+
// mask keeps: it lets src/bounds.ts prove both positions.
|
|
1134
|
+
const above: i32 = (depth & 15) + 1
|
|
1135
|
+
const atRoot: i32 = PKI_AT_ROOT + above
|
|
1148
1136
|
if (toI32(child.issuer.length) > 2) {
|
|
1149
1137
|
const roots: X509Certificate[] | undefined = s.store.bySubject.get(pkiHex(child.issuer))
|
|
1150
1138
|
if (roots !== undefined) {
|
|
@@ -1399,12 +1387,12 @@ export const pkiVerifyServer = (
|
|
|
1399
1387
|
if (count > PKI_MAX_CHAIN_CERTS) {
|
|
1400
1388
|
return new PkiResult(PKI_ERR_CHAIN_TOO_LONG, none)
|
|
1401
1389
|
}
|
|
1402
|
-
|
|
1390
|
+
// In `u64`: at most PKI_MAX_CHAIN_BYTES before each add, and a length below
|
|
1391
|
+
// 2^32, so the sum comes nowhere near 2^64.
|
|
1392
|
+
let bytes: u64 = toU64(0)
|
|
1403
1393
|
for (const der of chain) {
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
bytes = toI64(toU64(bytes) + toU64(toI64(der.length)))
|
|
1407
|
-
if (bytes > toI64(PKI_MAX_CHAIN_BYTES)) {
|
|
1394
|
+
bytes = bytes + toU64(der.length)
|
|
1395
|
+
if (bytes > toU64(PKI_MAX_CHAIN_BYTES)) {
|
|
1408
1396
|
return new PkiResult(PKI_ERR_CHAIN_TOO_LONG, none)
|
|
1409
1397
|
}
|
|
1410
1398
|
}
|