nish 0.36.0 → 0.37.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/docs/AI.md +43 -4
- package/docs/INSTALL.md +67 -58
- package/package.json +9 -5
- package/runtime/async.d.mts +2 -0
- package/runtime/async.mjs +7 -0
- package/runtime/nish.d.ts +736 -499
- package/runtime/nish.h +25 -0
- package/runtime/page.d.ts +53 -0
- package/runtime/page.mjs +146 -0
- package/runtime/runtime-async.c +557 -0
- package/runtime/runtime-wasm.c +63 -7
- package/scripts/build.sh +147 -5
- package/scripts/fuzz.sh +1 -0
- package/scripts/undocumented.txt +14 -0
- package/std/README.md +107 -82
- package/std/bytes.ts +23 -19
- package/std/compress/checksum.ts +1 -1
- package/std/crypto/aes.ts +48 -43
- package/std/crypto/base64url.ts +7 -5
- package/std/crypto/bcrypt-batch.ts +13 -13
- package/std/crypto/bcrypt.ts +33 -27
- package/std/crypto/chacha20poly1305.ts +16 -14
- package/std/crypto/ed25519.ts +19 -16
- package/std/crypto/hmac.ts +7 -6
- package/std/crypto/jwt.ts +23 -20
- package/std/crypto/p256.ts +63 -56
- package/std/crypto/p384.ts +23 -20
- package/std/crypto/pki.ts +18 -15
- package/std/crypto/rsa.ts +23 -19
- package/std/crypto/x25519.ts +11 -10
- package/std/crypto/x509.ts +69 -62
- package/std/host/ring.ts +124 -0
- package/std/json-equal.ts +12 -11
- package/std/json-number.ts +12 -12
- package/std/json-tokenizer.ts +26 -22
- package/std/json-typed.ts +92 -78
- package/std/json-value.ts +38 -33
- package/std/json.ts +32 -28
- package/std/net/fetch.ts +1117 -230
- package/std/net/handler.ts +18 -0
- package/std/net/hpack.ts +29 -26
- package/std/net/http-compress.ts +27 -21
- package/std/net/http1-client-codec.ts +29 -25
- package/std/net/http1-codec.ts +44 -87
- package/std/net/http1-server.ts +66 -54
- package/std/net/http2-frame.ts +17 -16
- package/std/net/http2-tls.ts +17 -15
- package/std/net/http2.ts +67 -54
- package/std/net/http3-frame.ts +11 -10
- package/std/net/http3-server.ts +36 -35
- package/std/net/http3.ts +70 -58
- package/std/net/postgres.ts +178 -160
- package/std/net/prefork.ts +38 -34
- package/std/net/qpack.ts +15 -14
- package/std/net/quic-conn-ack.ts +1 -0
- package/std/net/quic-conn-cid.ts +11 -0
- package/std/net/quic-conn-params.ts +41 -14
- package/std/net/quic-datagram.ts +7 -0
- package/std/net/quic-frame.ts +48 -12
- package/std/net/quic-listener.ts +61 -44
- package/std/net/quic-packet.ts +71 -52
- package/std/net/quic-recovery.ts +59 -21
- package/std/net/quic-stream.ts +83 -55
- package/std/net/quic.ts +204 -152
- package/std/net/tls/client.ts +1 -0
- package/std/net/tls/codec.ts +81 -12
- package/std/net/tls/record-client.ts +30 -18
- package/std/net/tls/record-server.ts +74 -46
- package/std/net/tls/record.ts +33 -24
- package/std/net/tls/ticket.ts +2 -0
- package/std/net/tls/verify.ts +8 -7
- package/std/net/tls-tcp.ts +58 -50
- package/std/net/tls.ts +55 -43
- package/std/net/url.ts +12 -9
- package/std/net/websocket.ts +23 -19
- package/std/net/webtransport.ts +24 -18
- package/std/random.ts +8 -6
- package/std/regex.ts +70 -59
- package/std/sync/ring.ts +24 -21
- package/std/sync/shm.ts +9 -7
- package/std/term-io.ts +17 -14
- package/std/term-probe.ts +11 -10
- package/std/term-rate.ts +71 -61
- package/std/term.ts +73 -59
- package/std/text.ts +11 -10
- package/std/threads.ts +19 -15
- package/std/yaml-json.ts +17 -15
- package/std/yaml-write.ts +21 -14
package/std/net/tls/ticket.ts
CHANGED
|
@@ -195,7 +195,9 @@ export class TlsTicketState {
|
|
|
195
195
|
suite: i32
|
|
196
196
|
/** The ticket's lifetime in seconds, at most `TLS_TICKET_LIFETIME_SECONDS`. */
|
|
197
197
|
lifetime: i32
|
|
198
|
+
/** How many bytes of `serverName` the name fills, 0 to `TLS_TICKET_SERVER_NAME_MAX`; 0 when the client sent no name. */
|
|
198
199
|
serverNameLength: i32
|
|
200
|
+
/** How many bytes of `psk` the PSK fills: 32 or 48, the suite's hash length. */
|
|
199
201
|
pskLength: i32
|
|
200
202
|
|
|
201
203
|
/**
|
package/std/net/tls/verify.ts
CHANGED
|
@@ -12,13 +12,14 @@
|
|
|
12
12
|
* SHA-256 on a P-256 key, ECDSA P-384 with SHA-384 on a P-384 key, RSA-PSS
|
|
13
13
|
* (rsae, salt as long as the hash) on an RSA key of at least 2048 bits — and
|
|
14
14
|
* the signature must verify over `TlsClient.verifyContent()` under that key
|
|
15
|
-
* (RFC 8446 §4.4.3). Then the chain, from the leaf the server sent to a root
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
15
|
+
* (RFC 8446 §4.4.3). Then the chain, from the leaf the server sent to a root in
|
|
16
|
+
* `trust`, for the name the caller dialled.
|
|
17
|
+
*
|
|
18
|
+
* A server with no certificate or a leaf that does not parse is
|
|
19
|
+
* `bad_certificate`, as is a leaf whose key is of any other kind (Ed25519, a
|
|
20
|
+
* short RSA modulus); a signature that does not verify, or a scheme that does
|
|
21
|
+
* not fit the key, is `decrypt_error`. The signature goes first so a forged
|
|
22
|
+
* CertificateVerify reads as what it is whatever the chain would have said.
|
|
22
23
|
*
|
|
23
24
|
* **The chain is `nish/crypto/pki`'s.** `pkiVerifyServer` builds a path from
|
|
24
25
|
* the leaf to a root of `trust`'s store and checks every certificate on it —
|
package/std/net/tls-tcp.ts
CHANGED
|
@@ -29,36 +29,40 @@
|
|
|
29
29
|
* stops asking to be written. An event with the hang-up bit (4) goes to
|
|
30
30
|
* `readable`, which is where a closed or failed socket is noticed.
|
|
31
31
|
*
|
|
32
|
-
* **Slots, built on first use; record buffers, borrowed.** The pool's size
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
* `docs/security/tls.md`). When every
|
|
44
|
-
* accepted and closed at once, so the listener
|
|
45
|
-
* program sees `TLS_TCP_POOL_FULL`.
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
32
|
+
* **Slots, built on first use; record buffers, borrowed.** The pool's size is a
|
|
33
|
+
* cap: the constructor builds no slot, and the first `accept` into a slot
|
|
34
|
+
* builds its handshake state and keys (TLS-3) and keeps them, so a pool sized
|
|
35
|
+
* for its peak costs at start-up only what does not depend on the size.
|
|
36
|
+
* `accept` hands the next connection the slot closed last, or failing that the
|
|
37
|
+
* next never used, and reuses it once the program `close`s it (WP34 N9).
|
|
38
|
+
*
|
|
39
|
+
* The record buffers — the bytes to send, the plaintext waiting for the
|
|
40
|
+
* program, the record being opened and the record being read — are borrowed
|
|
41
|
+
* from pools this server owns while a connection uses the slot, and given back
|
|
42
|
+
* zeroed (`BufferPool.giveSecret`) when it ends, so a free slot holds none of
|
|
43
|
+
* them ("What moves between connections" in `docs/security/tls.md`). When every
|
|
44
|
+
* slot is busy a new connection is accepted and closed at once, so the listener
|
|
45
|
+
* does not stay readable; the program sees `TLS_TCP_POOL_FULL`.
|
|
46
|
+
*
|
|
47
|
+
* Each slot keeps its own `TlsServer`, which `accept` restarts for the
|
|
48
|
+
* connection, so neither the handshake nor application data allocates anything
|
|
49
|
+
* that outlives a call: a thousand connections through one slot leave
|
|
50
|
+
* `Arena.mark()` where the first left it, under every suite (TLS-3 in
|
|
51
|
+
* `docs/security/tls.md`, `tests/link/net_tls_memory`).
|
|
50
52
|
*
|
|
51
53
|
* **Randomness is the caller's.** `accept` takes the 32-byte server random and
|
|
52
54
|
* the 32-byte x25519 private key the handshake uses, as `TlsServer` does, so a
|
|
53
55
|
* test replays RFC 8448's trace and a server draws them with
|
|
54
56
|
* `crypto.getRandomValues`. `accept` copies both into the slot and wipes the
|
|
55
57
|
* caller's key array, so one buffer of each refilled for every `accept` is
|
|
56
|
-
* safe, and refuses either when it is not 32 bytes before taking a
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
58
|
+
* safe, and refuses either when it is not 32 bytes before taking a connection;
|
|
59
|
+
* the slot's copy of the key is wiped once the ServerHello is written, when the
|
|
60
|
+
* handshake fails, or when the slot is closed.
|
|
61
|
+
*
|
|
62
|
+
* **Signing is the caller's**, as `TlsServer`'s is: `signP256` signs the
|
|
63
|
+
* CertificateVerify with a P-256 key the caller holds as a `Secret` and borrows
|
|
64
|
+
* for the call, and `signatureInput` / `sign` hand the input out and take any
|
|
65
|
+
* signature back.
|
|
62
66
|
*
|
|
63
67
|
* **Resumption is opt-in, and its keys are the caller's.** After
|
|
64
68
|
* `enableTickets`, a slot whose interest says `TLS_RECORD_TICKET` waits on
|
|
@@ -75,23 +79,25 @@
|
|
|
75
79
|
* `close` frees the slot at once; `shutdown` sends the `close_notify` as the
|
|
76
80
|
* socket takes it, and the slot is done when its interest says so.
|
|
77
81
|
*
|
|
78
|
-
* **A closed connection lingers until the client hangs up.** Once a
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
* the
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
82
|
+
* **A closed connection lingers until the client hangs up.** Once a connection
|
|
83
|
+
* the server closed has sent everything, the slot shuts the socket's write side
|
|
84
|
+
* — the client reads the response, the `close_notify` and then the end of the
|
|
85
|
+
* stream — and reads and throws away what the client still sends, until its own
|
|
86
|
+
* end of stream, before its interest says `TLS_RECORD_DONE` (RFC 9112 §9.6's
|
|
87
|
+
* staged close).
|
|
88
|
+
*
|
|
89
|
+
* A socket closed with the client's bytes unread, or that the client writes to
|
|
90
|
+
* after the close, answers with a TCP reset, and a client may report that reset
|
|
91
|
+
* instead of the response it was sent: Chromium's `ERR_CONNECTION_RESET` after
|
|
92
|
+
* an HTTP/2 `GOAWAY`, when its SETTINGS acknowledgement crossed the server's
|
|
93
|
+
* close. A lingering slot holds no key and no record buffer, asks only to be
|
|
94
|
+
* read, and gives up past `TLS_TCP_LINGER_LIMIT` bytes.
|
|
95
|
+
*
|
|
96
|
+
* A connection that failed, whose client sent its own `close_notify` (it writes
|
|
97
|
+
* nothing after it, RFC 8446 §6.1) or whose client's stream had already ended,
|
|
98
|
+
* is done at once. A client that never hangs up keeps its slot, as one that
|
|
99
|
+
* never sends does: how long a slot may wait is the program's
|
|
100
|
+
* (`docs/security/tls.md`, TLS-6 and TLS-4).
|
|
95
101
|
*
|
|
96
102
|
* Written from RFC 8446 and docs/LANGUAGE.md's `nish:net`, not ported from
|
|
97
103
|
* another implementation.
|
|
@@ -863,6 +869,7 @@ export class TlsTcpServer {
|
|
|
863
869
|
* connect leaves the client done, its failure in `failure()`.
|
|
864
870
|
*/
|
|
865
871
|
export class TlsTcpClient {
|
|
872
|
+
/** The TLS record layer over the socket: its `tls` is the handshake, read for the negotiated suite and `alpnChosen`. */
|
|
866
873
|
conn: TlsRecordClient
|
|
867
874
|
private trust: TlsClientTrust
|
|
868
875
|
/** The socket, -1 once `close` has run or when `tcpConnect` refused at once. */
|
|
@@ -1316,17 +1323,18 @@ const tlsTcpDeadline = (timeoutMs: i32): i64 => monotonicNanos() + toI64(timeout
|
|
|
1316
1323
|
|
|
1317
1324
|
/**
|
|
1318
1325
|
* Opens a TLS 1.3 connection to the server at `addr` (`nish:net`'s 18-byte
|
|
1319
|
-
* form) for `serverName`, offering `alpn`, authenticated against the
|
|
1320
|
-
*
|
|
1321
|
-
*
|
|
1322
|
-
*
|
|
1323
|
-
*
|
|
1324
|
-
*
|
|
1325
|
-
*
|
|
1326
|
+
* form) for `serverName`, offering `alpn`, authenticated against the system's
|
|
1327
|
+
* roots, and waits in a loop of its own until the handshake is done and the
|
|
1328
|
+
* client's last flight sent, or it fails, or `timeoutMs` milliseconds pass,
|
|
1329
|
+
* reading the roots included. Answers the client either way: `open()` says
|
|
1330
|
+
* whether it opened; otherwise `failure()` says why — the TCP failure, the
|
|
1331
|
+
* alert, or `TLS_TCP_TIMED_OUT`, the client closed.
|
|
1332
|
+
*
|
|
1333
|
+
* Nothing is looked up: to reach a name, resolve it first with `nish/net/dns`'s
|
|
1326
1334
|
* `resolveHost`; the name the certificate must carry is always `serverName`,
|
|
1327
1335
|
* never one taken from `addr`. The open client's socket is in no loop: the
|
|
1328
|
-
* program adds it to its own, or uses `writeAll` and `readWait`. The roots
|
|
1329
|
-
*
|
|
1336
|
+
* program adds it to its own, or uses `writeAll` and `readWait`. The roots are
|
|
1337
|
+
* read on every call; a program that connects often reads them once with
|
|
1330
1338
|
* `tlsClientSystemTrust` and passes them to `tlsConnectWith`.
|
|
1331
1339
|
*
|
|
1332
1340
|
* @param addr The server's address and port in `nish:net`'s 18-byte form.
|
package/std/net/tls.ts
CHANGED
|
@@ -42,36 +42,38 @@
|
|
|
42
42
|
* says the carrier is QUIC. 0-RTT and client authentication are not here:
|
|
43
43
|
* an early-data offer is ignored.
|
|
44
44
|
*
|
|
45
|
-
* **Resumption.** A server the carrier calls `enableTickets` on, over TCP
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
45
|
+
* **Resumption.** A server the carrier calls `enableTickets` on, over TCP only,
|
|
46
|
+
* resumes with a session ticket in `psk_dhe_ke` mode (RFC 8446 §2.2, §4.2.11)
|
|
47
|
+
* and issues one after each handshake. The ticket keys and the strike register
|
|
48
|
+
* are the program's, lent to each call and never kept: a ClientHello that
|
|
49
|
+
* offers a ticket stops at `TLS_STATE_WAIT_TICKET`, and `resume` reads the
|
|
50
|
+
* identities in the client's order, verifies the binder of the one it selects,
|
|
51
|
+
* records its id, and answers a resumed flight — or a full handshake when no
|
|
52
|
+
* identity can be used (`docs/security/tls.md`, "Resumption").
|
|
53
|
+
*
|
|
54
|
+
* Once connected, `issue` writes one NewSessionTicket at the Application level.
|
|
55
|
+
* Sealing draws the ticket's nonce and `issue` the `ticket_age_add` from the
|
|
56
|
+
* random device; nothing else here does. Over QUIC the hand-off is never
|
|
57
|
+
* called, so a PSK offer gets a full handshake.
|
|
57
58
|
*
|
|
58
59
|
* **Refusals are alerts.** `receive` and `sign` answer 0 or a TLS alert
|
|
59
60
|
* description (`TLS_ALERT_*` in `nish/net/tls/codec`); after one the server
|
|
60
61
|
* is in `TLS_STATE_FAILED` and answers the same alert to every call. Nothing
|
|
61
62
|
* the peer sends can make it panic.
|
|
62
63
|
*
|
|
63
|
-
* **Secrets.** Every secret the server holds is a `Secret` (`nish:secret`):
|
|
64
|
-
*
|
|
64
|
+
* **Secrets.** Every secret the server holds is a `Secret` (`nish:secret`): the
|
|
65
|
+
* ECDHE secret and the words it is computed in, wiped on every path; the
|
|
65
66
|
* ephemeral key, copied into the `ephemeral` field by `restart` with the
|
|
66
67
|
* caller's array zeroed; and the handshake, traffic, exporter and resumption
|
|
67
68
|
* secrets, and a resumed handshake's PSK, early secret and binder key, fields
|
|
68
69
|
* of the two `TlsSecretPool`s, read only inside `expose`.
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
* secret
|
|
74
|
-
*
|
|
70
|
+
*
|
|
71
|
+
* `wipe` zeroes them all, and `restart` calls it before the next connection;
|
|
72
|
+
* the carriers call it when a connection ends, and `wipeSecret` and
|
|
73
|
+
* `wipeEphemeral` as each secret's work is done. `fail` wipes the resumption
|
|
74
|
+
* master secret and the PSK's secrets, and `issue` the resumption master secret
|
|
75
|
+
* once the ticket is sealed (CLAUDE.md §Security; TLS-1 in
|
|
76
|
+
* `docs/security/tls.md`).
|
|
75
77
|
*
|
|
76
78
|
* **Memory.** A `TlsServer` keeps its state in buffers it allocates once —
|
|
77
79
|
* the messages in and out, the transcript, the secrets, the HKDF scratch —
|
|
@@ -727,10 +729,15 @@ const TLS_CERTIFICATE_VERIFY_PREFIX: i32 = 98
|
|
|
727
729
|
* `wipe` zeroes them too (TLS-1).
|
|
728
730
|
*/
|
|
729
731
|
export class TlsSecretPool {
|
|
732
|
+
/** `handshake_secret` (RFC 8446 §7.1), hash-length bytes; read it inside `expose`. */
|
|
730
733
|
readonly handshake: Secret<u8[]>
|
|
734
|
+
/** `client_handshake_traffic_secret` (RFC 8446 §7.1), hash-length bytes; read it inside `expose`. */
|
|
731
735
|
readonly clientHandshake: Secret<u8[]>
|
|
736
|
+
/** `server_handshake_traffic_secret` (RFC 8446 §7.1), hash-length bytes; read it inside `expose`. */
|
|
732
737
|
readonly serverHandshake: Secret<u8[]>
|
|
738
|
+
/** `client_application_traffic_secret_0` (RFC 8446 §7.1), hash-length bytes; read it inside `expose`. */
|
|
733
739
|
readonly clientApplication: Secret<u8[]>
|
|
740
|
+
/** `server_application_traffic_secret_0` (RFC 8446 §7.1), hash-length bytes; read it inside `expose`. */
|
|
734
741
|
readonly serverApplication: Secret<u8[]>
|
|
735
742
|
/** `exporter_master_secret` (RFC 8446 §7.5), for a caller's own exporters. */
|
|
736
743
|
readonly exporter: Secret<u8[]>
|
|
@@ -933,20 +940,22 @@ const tlsServerTicketCapacity = (state: TlsTicketState): i32 => {
|
|
|
933
940
|
*
|
|
934
941
|
* **What it allocates.** Everything it keeps is allocated by the constructor
|
|
935
942
|
* and reused by `restart`: the input and output buffers, the transcript's
|
|
936
|
-
* hashers, the HKDF scratch, the ephemeral key's 32 bytes, and HashLen bytes
|
|
937
|
-
* under each hash, which each derivation writes over in place
|
|
938
|
-
* zeroes before the next connection starts. `receive` and
|
|
939
|
-
*
|
|
940
|
-
*
|
|
941
|
-
*
|
|
942
|
-
*
|
|
943
|
-
* the
|
|
944
|
-
* the
|
|
945
|
-
*
|
|
946
|
-
*
|
|
947
|
-
* are
|
|
943
|
+
* hashers, the HKDF scratch, the ephemeral key's 32 bytes, and HashLen bytes
|
|
944
|
+
* for every secret under each hash, which each derivation writes over in place
|
|
945
|
+
* and `wipe` zeroes before the next connection starts. `receive` and `sign` do
|
|
946
|
+
* their work inside `using a = arena()` blocks, so the compiler has proved that
|
|
947
|
+
* what they allocate on the way dies before they return.
|
|
948
|
+
*
|
|
949
|
+
* Four things grow or are made outside those blocks: the input buffer, doubled
|
|
950
|
+
* up to the largest message when a ClientHello does not fit (once per slot);
|
|
951
|
+
* the Handshake-level output, when a signature is longer than an ECDSA one; the
|
|
952
|
+
* `serverName` string, made when the client's host name differs from the last
|
|
953
|
+
* one this server held; and, over QUIC only, the array the client's transport
|
|
954
|
+
* parameters are copied into, which grows only when a client's are longer than
|
|
955
|
+
* any before (TLS-3).
|
|
948
956
|
*/
|
|
949
957
|
export class TlsServer {
|
|
958
|
+
/** The configuration this server was built with: its certificate chain, ALPN list and QUIC transport parameters. */
|
|
950
959
|
config: TlsServerConfig
|
|
951
960
|
private serverRandom: u8[]
|
|
952
961
|
/** The connection's x25519 private key, copied in by `restart` and wiped by the record layer once the ServerHello is written. */
|
|
@@ -980,6 +989,7 @@ export class TlsServer {
|
|
|
980
989
|
private none: u8[]
|
|
981
990
|
/** The secrets under each hash (`TlsSecretPool`); `secrets()` answers the negotiated hash's. */
|
|
982
991
|
secrets256: TlsSecretPool
|
|
992
|
+
/** The secrets under SHA-384, for TLS_AES_256_GCM_SHA384. */
|
|
983
993
|
secrets384: TlsSecretPool
|
|
984
994
|
/** The ClientHello last read, as windows into `input`. */
|
|
985
995
|
private hello: TlsClientHelloView
|
|
@@ -1022,6 +1032,7 @@ export class TlsServer {
|
|
|
1022
1032
|
* bit, since its place is still the one it was derived into.
|
|
1023
1033
|
*/
|
|
1024
1034
|
held: i32 = 0
|
|
1035
|
+
/** Where the handshake stands: one of the `TLS_STATE_*` constants, `TLS_STATE_CONNECTED` once it is done and `TLS_STATE_FAILED` after an alert. */
|
|
1025
1036
|
state: i32 = 0
|
|
1026
1037
|
/** The alert the server failed with, or 0. */
|
|
1027
1038
|
alert: i32 = 0
|
|
@@ -2180,17 +2191,18 @@ export class TlsServer {
|
|
|
2180
2191
|
}
|
|
2181
2192
|
|
|
2182
2193
|
/**
|
|
2183
|
-
* Once the handshake is done, at most once a connection: seals a ticket
|
|
2184
|
-
*
|
|
2185
|
-
*
|
|
2186
|
-
*
|
|
2187
|
-
*
|
|
2188
|
-
*
|
|
2189
|
-
*
|
|
2190
|
-
*
|
|
2191
|
-
*
|
|
2192
|
-
*
|
|
2193
|
-
*
|
|
2194
|
+
* Once the handshake is done, at most once a connection: seals a ticket for
|
|
2195
|
+
* it under `key`, which `info` describes, and writes the NewSessionTicket
|
|
2196
|
+
* carrying it at the Application level, for the carrier to send under the
|
|
2197
|
+
* server's application keys. Answers whether one was written: none is when
|
|
2198
|
+
* tickets are off, the client did not list `psk_dhe_ke`, or the key does not
|
|
2199
|
+
* seal. On a connected connection's first call the resumption master secret
|
|
2200
|
+
* is wiped before it returns, written or not, so a carrier that issues no
|
|
2201
|
+
* ticket still calls this, or `wipeResumption`.
|
|
2202
|
+
*
|
|
2203
|
+
* Before the handshake is done, or on a second call, it answers false and
|
|
2204
|
+
* touches nothing: a secret wiped then would leave no ticket to issue, and
|
|
2205
|
+
* one wiped already has nothing left to wipe.
|
|
2194
2206
|
*
|
|
2195
2207
|
* @param key The current ticket key, lent: read only inside `exposeWith`, and still the carrier's to wipe.
|
|
2196
2208
|
* @param info The key's record, which counts the ticket when one is sealed.
|
package/std/net/url.ts
CHANGED
|
@@ -1057,15 +1057,18 @@ const urlFinish = (u: Url): Url | null => {
|
|
|
1057
1057
|
|
|
1058
1058
|
/**
|
|
1059
1059
|
* The absolute URL `s` split into its parts, or null when it is not one this
|
|
1060
|
-
* module accepts.
|
|
1061
|
-
*
|
|
1062
|
-
*
|
|
1063
|
-
*
|
|
1064
|
-
*
|
|
1065
|
-
*
|
|
1066
|
-
*
|
|
1067
|
-
*
|
|
1068
|
-
*
|
|
1060
|
+
* module accepts.
|
|
1061
|
+
*
|
|
1062
|
+
* `s` is refused when it has no scheme, holds a byte outside printable ASCII (a
|
|
1063
|
+
* control byte, a space, DEL or anything past 0x7F), a backslash or a `%` not
|
|
1064
|
+
* followed by two hex digits, or its authority has more than one `@`, a host
|
|
1065
|
+
* with a byte outside RFC 3986's unreserved set (so a percent-encoded one), a
|
|
1066
|
+
* host whose last label is numeric but that is not a dotted-decimal IPv4
|
|
1067
|
+
* address, a malformed IPv6 literal or a port that is not digits or is
|
|
1068
|
+
* above 65535. An http, https, ws or wss URL needs a non-empty host.
|
|
1069
|
+
*
|
|
1070
|
+
* The path's dot segments are removed, as RFC 3986 §5.2.2 removes them from a
|
|
1071
|
+
* reference with a scheme. Nothing is decoded. It allocates its answer.
|
|
1069
1072
|
*
|
|
1070
1073
|
* @param s The absolute URL, such as `https://example.com/a?b#c`.
|
|
1071
1074
|
* @returns The URL's parts, still percent-encoded, `scheme` and `host` lower-cased; or null when `s` is refused.
|
package/std/net/websocket.ts
CHANGED
|
@@ -657,13 +657,15 @@ export const websocketFrameSize = (len: i32, masked: boolean): i32 => {
|
|
|
657
657
|
* `payload[off .. off + len)` and, when `mask` is not null, masked with that
|
|
658
658
|
* 4-byte key. A client masks every frame with a fresh key from
|
|
659
659
|
* `crypto.getRandomValues` (§5.3); a server passes null. The length takes the
|
|
660
|
-
* shortest of its three forms.
|
|
661
|
-
*
|
|
662
|
-
*
|
|
663
|
-
*
|
|
664
|
-
*
|
|
665
|
-
*
|
|
666
|
-
*
|
|
660
|
+
* shortest of its three forms.
|
|
661
|
+
*
|
|
662
|
+
* Answers where the frame ends, `WS_NO_ROOM` when it does not fit, or
|
|
663
|
+
* `WS_REFUSED` for an opcode RFC 6455 does not define, a control frame that is
|
|
664
|
+
* not FIN or is longer than 125 bytes, and a mask that is not 4 bytes; on
|
|
665
|
+
* either refusal `out` is untouched. A window outside `payload` panics, and so
|
|
666
|
+
* does a payload longer than 2^31 - 15 bytes. A text frame's payload is not
|
|
667
|
+
* checked here, because a fragment may end inside a character;
|
|
668
|
+
* `websocketIsUtf8` checks a whole message.
|
|
667
669
|
*
|
|
668
670
|
* @param out The buffer the frame is written into.
|
|
669
671
|
* @param at The index in `out` the frame starts at; one outside `out` answers `WS_NO_ROOM`.
|
|
@@ -1127,18 +1129,20 @@ export class WsHandshake {
|
|
|
1127
1129
|
/**
|
|
1128
1130
|
* Reads the server's answer to `websocketUpgradeRequest(…, key, offered)`
|
|
1129
1131
|
* (§4.1, the client's checks of the response): call it at the parser's
|
|
1130
|
-
* `HTTP1_HEAD`.
|
|
1131
|
-
*
|
|
1132
|
-
*
|
|
1133
|
-
*
|
|
1134
|
-
*
|
|
1135
|
-
*
|
|
1136
|
-
* `
|
|
1137
|
-
*
|
|
1138
|
-
*
|
|
1139
|
-
*
|
|
1140
|
-
*
|
|
1141
|
-
*
|
|
1132
|
+
* `HTTP1_HEAD`.
|
|
1133
|
+
*
|
|
1134
|
+
* It fails closed, and the connection is closed on any failure: a status other
|
|
1135
|
+
* than 101 (`WS_HS_STATUS`; a redirect is not followed), a version other than
|
|
1136
|
+
* HTTP/1.1, `Upgrade` absent, repeated or not `websocket`, no `Connection`
|
|
1137
|
+
* listing `upgrade`, `Sec-WebSocket-Accept` absent, repeated or not
|
|
1138
|
+
* `websocketAcceptKey(key)` (a forged or replayed answer, or any answer when
|
|
1139
|
+
* `key` is not a valid key), any `Sec-WebSocket-Extensions` (this client offers
|
|
1140
|
+
* none, so none may be in use), and a `Sec-WebSocket-Protocol` that is present
|
|
1141
|
+
* when nothing was offered, repeated, a list, or not one of `offered`.
|
|
1142
|
+
*
|
|
1143
|
+
* On `WS_HS_OK` the parser's next events are `HTTP1_END` and `HTTP1_UPGRADE`;
|
|
1144
|
+
* its `tunnelBytes()` go to `WsDecoder(false, …)`, and every frame the client
|
|
1145
|
+
* sends is masked with a fresh mask key from `crypto.getRandomValues` (§5.3).
|
|
1142
1146
|
*
|
|
1143
1147
|
* @param response The client's parser, at the `HTTP1_HEAD` of the response.
|
|
1144
1148
|
* @param key The key the request sent, from `websocketClientKey`.
|
package/std/net/webtransport.ts
CHANGED
|
@@ -27,24 +27,30 @@
|
|
|
27
27
|
* }
|
|
28
28
|
* };
|
|
29
29
|
*
|
|
30
|
-
* **Events.**
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
* `
|
|
35
|
-
* `
|
|
36
|
-
* `
|
|
37
|
-
* `
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
* `
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
30
|
+
* **Events.**
|
|
31
|
+
*
|
|
32
|
+
* `next()` answers a `WT_*` event, or one of `nish/net/http3`'s for a plain
|
|
33
|
+
* request, which passes through untouched so one connection can serve both:
|
|
34
|
+
* - `WT_SESSION` (a session asked for: `sessionId`, the CONNECT stream's ID,
|
|
35
|
+
* and `fields`; the program `accept`s or `refuse`s it),
|
|
36
|
+
* - `WT_DATAGRAM` (a datagram of an accepted session, a window onto `data`),
|
|
37
|
+
* - `WT_STREAM` (the client opened a stream of an accepted session: `stream`,
|
|
38
|
+
* `bidirectional`),
|
|
39
|
+
* - `WT_STREAM_DATA` (its bytes, a window onto `data`),
|
|
40
|
+
* - `WT_STREAM_END` (its FIN),
|
|
41
|
+
* - `WT_STREAM_RESET` (the client reset its side: `errorCode`, the HTTP/3 code,
|
|
42
|
+
* and `appCode`, the WebTransport code it maps to or -1),
|
|
43
|
+
* - `WT_STREAM_STOPPED` (the client asked this side to stop writing: the same
|
|
44
|
+
* two codes),
|
|
45
|
+
* - `WT_WRITABLE` (a stream, or a CONNECT stream whose capsule was held back,
|
|
46
|
+
* can take more),
|
|
47
|
+
* - `WT_DRAIN` (the client sent DRAIN_WEBTRANSPORT_SESSION) and `WT_CLOSED`
|
|
48
|
+
* (the session is over: `errorCode`, the CLOSE capsule's code or 0, the
|
|
49
|
+
* reason a window onto `data`, and `closedByPeer`).
|
|
50
|
+
*
|
|
51
|
+
* Each event names its session in `sessionId` and in `session`, its index in
|
|
52
|
+
* the table, `0 .. webtransportSessions - 1`, for a program's own per-session
|
|
53
|
+
* arrays. A window is valid until the next call.
|
|
48
54
|
*
|
|
49
55
|
* **Writes.** `sendDatagram` (the quarter stream ID, then the payload, one
|
|
50
56
|
* QUIC DATAGRAM frame; `maxDatagramPayload` says how much fits), `openStream`,
|
package/std/random.ts
CHANGED
|
@@ -27,12 +27,14 @@
|
|
|
27
27
|
* two's-complement wrap natively and answer `(a + b) | 0` and `Math.imul(a, b)`
|
|
28
28
|
* under Node (docs/LANGUAGE.md, "nish:unsafe"); every shift has a constant
|
|
29
29
|
* count, and `^` and `>>> 16` answer the same 32 bits in JavaScript as in the
|
|
30
|
-
* compiled program.
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
30
|
+
* compiled program.
|
|
31
|
+
*
|
|
32
|
+
* `nextInt` reads its span and its draws as unsigned counts with no `u32`
|
|
33
|
+
* (whose conversions saturate under Node): the sign bit flipped orders them
|
|
34
|
+
* under a signed compare, and the remainder is taken in pieces that stay below
|
|
35
|
+
* 2^31. `nextF64` builds its double from integers below 2^53, so its products
|
|
36
|
+
* and sums are exact both ways. The program a test prints under Node is the one
|
|
37
|
+
* it prints compiled (docs/RUN_UNDER_NODE.md).
|
|
36
38
|
*
|
|
37
39
|
* **It is not for cryptography**: a key or a nonce comes from
|
|
38
40
|
* `crypto.getRandomValues`.
|