@amritk/nish-aarch64-linux 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/INSTALL.md +67 -58
- package/bin/nish +0 -0
- package/docs/AI.md +43 -4
- package/package.json +1 -1
- 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/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/codec.ts
CHANGED
|
@@ -299,44 +299,59 @@ export class TlsClientHelloView {
|
|
|
299
299
|
reader: TlsReader
|
|
300
300
|
/** 0 when the message parsed, or the alert it earns: `decode_error` or `illegal_parameter`. */
|
|
301
301
|
alert: i32 = 0
|
|
302
|
+
/** `legacy_version` as sent; TLS 1.3 fixes it at 0x0303 and negotiates the real version in `supported_versions` (§4.1.2). */
|
|
302
303
|
legacyVersion: i32 = 0
|
|
304
|
+
/** Where the client's 32-byte `random` starts in `data`; its length is always 32. */
|
|
303
305
|
randomAt: i32 = 0
|
|
304
306
|
/** `legacy_session_id`, which a server echoes (§4.1.3). */
|
|
305
307
|
sessionIdAt: i32 = 0
|
|
308
|
+
/** The `legacy_session_id`'s length in bytes, 0 to 32. */
|
|
306
309
|
sessionIdLength: i32 = 0
|
|
307
310
|
/** `cipher_suites`, 16-bit values in the client's order. */
|
|
308
311
|
suitesAt: i32 = 0
|
|
312
|
+
/** The `cipher_suites` window's length in bytes, two a suite. */
|
|
309
313
|
suitesLength: i32 = 0
|
|
310
314
|
/** `supported_versions`, 16-bit values. */
|
|
311
315
|
versionsAt: i32 = 0
|
|
316
|
+
/** The `supported_versions` window's length in bytes, two a version; 0 when the extension was absent. */
|
|
312
317
|
versionsLength: i32 = 0
|
|
313
318
|
/** `supported_groups`, 16-bit values. */
|
|
314
319
|
groupsAt: i32 = 0
|
|
320
|
+
/** The `supported_groups` window's length in bytes, two a group; 0 when the extension was absent. */
|
|
315
321
|
groupsLength: i32 = 0
|
|
316
322
|
/** `signature_algorithms`, 16-bit values. */
|
|
317
323
|
schemesAt: i32 = 0
|
|
324
|
+
/** The `signature_algorithms` window's length in bytes, two a scheme; 0 when the extension was absent. */
|
|
318
325
|
schemesLength: i32 = 0
|
|
319
326
|
/** The `client_shares` list of `key_share`, every entry in it. */
|
|
320
327
|
sharesAt: i32 = 0
|
|
328
|
+
/** The `client_shares` window's length in bytes; 0 when `key_share` was absent. */
|
|
321
329
|
sharesLength: i32 = 0
|
|
322
330
|
/** The x25519 share's key_exchange, as sent; its length is the server's to check. */
|
|
323
331
|
x25519ShareAt: i32 = 0
|
|
332
|
+
/** The x25519 share's length in bytes as sent, 0 when none was offered; a usable share is 32. */
|
|
324
333
|
x25519ShareLength: i32 = 0
|
|
325
334
|
/** The `host_name` of `server_name`, or empty. */
|
|
326
335
|
serverNameAt: i32 = 0
|
|
336
|
+
/** The `host_name`'s length in bytes, 0 when `server_name` was absent. */
|
|
327
337
|
serverNameLength: i32 = 0
|
|
328
338
|
/** ALPN's `protocol_name_list`, each name a length byte and its bytes (RFC 7301 §3.1). */
|
|
329
339
|
alpnAt: i32 = 0
|
|
340
|
+
/** The ALPN list's length in bytes, its length bytes included; 0 when ALPN was absent. */
|
|
330
341
|
alpnLength: i32 = 0
|
|
331
342
|
/** The client's `quic_transport_parameters`, opaque (RFC 9001 §8.2). */
|
|
332
343
|
quicAt: i32 = 0
|
|
344
|
+
/** The QUIC transport parameters' length in bytes, 0 when the extension was absent. */
|
|
333
345
|
quicLength: i32 = 0
|
|
334
346
|
/** The extensions block, every extension in it. */
|
|
335
347
|
extensionsAt: i32 = 0
|
|
348
|
+
/** The extensions block's length in bytes, 0 for a hello with none. */
|
|
336
349
|
extensionsLength: i32 = 0
|
|
337
350
|
/** `pre_shared_key`'s `identities` list (§4.2.11): each an identity<1..2^16-1> and a 32-bit obfuscated age. */
|
|
338
351
|
pskIdentitiesAt: i32 = 0
|
|
352
|
+
/** The `identities` window's length in bytes, 0 when `pre_shared_key` was absent. */
|
|
339
353
|
pskIdentitiesLength: i32 = 0
|
|
354
|
+
/** How many identities `identities` holds; the binder count must match it (§4.2.11). */
|
|
340
355
|
pskIdentityCount: i32 = 0
|
|
341
356
|
/**
|
|
342
357
|
* Where `binders`' two-byte length starts: the ClientHello up to here, its
|
|
@@ -346,31 +361,50 @@ export class TlsClientHelloView {
|
|
|
346
361
|
pskBindersPrefixAt: i32 = 0
|
|
347
362
|
/** `pre_shared_key`'s `binders` list: each a PskBinderEntry<32..255>. */
|
|
348
363
|
pskBindersAt: i32 = 0
|
|
364
|
+
/** The `binders` window's length in bytes, 0 when `pre_shared_key` was absent. */
|
|
349
365
|
pskBindersLength: i32 = 0
|
|
366
|
+
/** How many binders `binders` holds, one an identity. */
|
|
350
367
|
pskBinderCount: i32 = 0
|
|
351
368
|
/** `psk_key_exchange_modes`' `ke_modes`, one byte a mode (§4.2.9). */
|
|
352
369
|
pskModesAt: i32 = 0
|
|
370
|
+
/** The `ke_modes` window's length in bytes, one a mode; 0 when the extension was absent. */
|
|
353
371
|
pskModesLength: i32 = 0
|
|
354
372
|
/** The identity `tlsSelectPskIdentity` last chose: its bytes and its obfuscated ticket age. */
|
|
355
373
|
pskIdentityAt: i32 = 0
|
|
374
|
+
/** The chosen identity's length in bytes, 0 until `tlsSelectPskIdentity` chooses one. */
|
|
356
375
|
pskIdentityLength: i32 = 0
|
|
376
|
+
/** The chosen identity's `obfuscated_ticket_age`, as sent: the ticket's age in milliseconds plus its `ticket_age_add`, modulo 2^32 (§4.2.11.1). */
|
|
357
377
|
pskTicketAge: u32 = 0
|
|
358
378
|
/** That identity's binder, the entry of the same index in `binders`. */
|
|
359
379
|
pskBinderAt: i32 = 0
|
|
380
|
+
/**
|
|
381
|
+
* The chosen binder's length in bytes, 32 to 255: `tlsReadPreSharedKey` refuses a shorter one
|
|
382
|
+
* when it parses the extension. It must equal the suite's hash length.
|
|
383
|
+
*/
|
|
360
384
|
pskBinderLength: i32 = 0
|
|
361
385
|
/** Whether `ke_modes` lists `psk_dhe_ke`, the one mode the server resumes in. */
|
|
362
386
|
pskDheKe: boolean = false
|
|
363
387
|
/** Whether `legacy_compression_methods` is the single null method TLS 1.3 requires (§4.1.2). */
|
|
364
388
|
nullCompressionOnly: boolean = false
|
|
389
|
+
/** Whether the hello carried `supported_versions`: without it the client does not offer TLS 1.3 (§4.2.1). */
|
|
365
390
|
hasSupportedVersions: boolean = false
|
|
391
|
+
/** Whether the hello carried `supported_groups`. */
|
|
366
392
|
hasSupportedGroups: boolean = false
|
|
393
|
+
/** Whether the hello carried `key_share`, even an empty one. */
|
|
367
394
|
hasKeyShare: boolean = false
|
|
395
|
+
/** Whether `key_share` offered an x25519 share, so `x25519ShareAt` names one. */
|
|
368
396
|
hasX25519Share: boolean = false
|
|
397
|
+
/** Whether the hello carried `signature_algorithms`. */
|
|
369
398
|
hasSignatureAlgorithms: boolean = false
|
|
399
|
+
/** Whether the hello carried `server_name` with a `host_name` in it. */
|
|
370
400
|
hasServerName: boolean = false
|
|
401
|
+
/** Whether the hello carried ALPN. */
|
|
371
402
|
hasAlpn: boolean = false
|
|
403
|
+
/** Whether the hello carried `quic_transport_parameters`, which a QUIC handshake requires (RFC 9001 §8.2). */
|
|
372
404
|
hasQuicTransportParameters: boolean = false
|
|
405
|
+
/** Whether the hello carried `pre_shared_key`, which must be its last extension (§4.2.11). */
|
|
373
406
|
hasPreSharedKey: boolean = false
|
|
407
|
+
/** Whether the hello carried `psk_key_exchange_modes`, without which a server must not resume (§4.2.9). */
|
|
374
408
|
hasPskModes: boolean = false
|
|
375
409
|
|
|
376
410
|
/**
|
|
@@ -708,19 +742,21 @@ const tlsReadExtension = (r: TlsReader, type: i32, end: i32, hello: TlsClientHel
|
|
|
708
742
|
}
|
|
709
743
|
|
|
710
744
|
/**
|
|
711
|
-
* Reads the ClientHello body `data[off .. off + len)` — the message without
|
|
712
|
-
*
|
|
713
|
-
*
|
|
714
|
-
*
|
|
715
|
-
*
|
|
716
|
-
*
|
|
717
|
-
*
|
|
718
|
-
*
|
|
719
|
-
*
|
|
720
|
-
*
|
|
745
|
+
* Reads the ClientHello body `data[off .. off + len)` — the message without its
|
|
746
|
+
* four-byte handshake header — into `hello`, which forgets the last one first.
|
|
747
|
+
* Its `alert` is 0 when the body parsed; otherwise the first fault decides it:
|
|
748
|
+
* `decode_error` for a length past its bytes, a vector out of its bounds or
|
|
749
|
+
* bytes left over, and `illegal_parameter` for an extension sent twice (§4.2),
|
|
750
|
+
* a `pre_shared_key` that is not the last extension (§4.2.11), two shares for
|
|
751
|
+
* one group, or a bad `server_name`. A window outside `data` is `decode_error`
|
|
752
|
+
* too, rather than a panic.
|
|
753
|
+
*
|
|
754
|
+
* A hello that parses but offers `pre_shared_key` with a different number of
|
|
755
|
+
* identities and binders is `illegal_parameter`, and one that offers it without
|
|
721
756
|
* `psk_key_exchange_modes` is `missing_extension` (§4.2.9): rows 10 to 13 of
|
|
722
|
-
* the fallback table in `docs/security/tls.md`, "Resumption". Nothing is
|
|
723
|
-
* point into `data`, which must outlive the use made of
|
|
757
|
+
* the fallback table in `docs/security/tls.md`, "Resumption". Nothing is
|
|
758
|
+
* copied: the windows point into `data`, which must outlive the use made of
|
|
759
|
+
* them.
|
|
724
760
|
*
|
|
725
761
|
* @param hello The view to read into, cleared first; its `alert` is the verdict.
|
|
726
762
|
* @param data The buffer that holds the message, which the view's windows then point into.
|
|
@@ -864,9 +900,11 @@ export const tlsSelectPskIdentity = (hello: TlsClientHelloView, index: i32): boo
|
|
|
864
900
|
* says so.
|
|
865
901
|
*/
|
|
866
902
|
export class TlsClientHello {
|
|
903
|
+
/** The client's 32-byte `random`. */
|
|
867
904
|
random: u8[]
|
|
868
905
|
/** `legacy_session_id`, which a server echoes (§4.1.3). */
|
|
869
906
|
sessionId: u8[]
|
|
907
|
+
/** `cipher_suites`, 16-bit values in the client's order. */
|
|
870
908
|
cipherSuites: i32[]
|
|
871
909
|
/** `supported_versions`, in the client's order. */
|
|
872
910
|
versions: i32[]
|
|
@@ -888,6 +926,7 @@ export class TlsClientHello {
|
|
|
888
926
|
extensionTypes: i32[]
|
|
889
927
|
/** `pre_shared_key`'s identities, in the client's order, and each one's obfuscated ticket age (§4.2.11). */
|
|
890
928
|
pskIdentities: u8[][]
|
|
929
|
+
/** Each identity's `obfuscated_ticket_age`, as sent: entry `i` belongs to `pskIdentities[i]`. */
|
|
891
930
|
pskTicketAges: u32[]
|
|
892
931
|
/** `pre_shared_key`'s binders, one an identity. */
|
|
893
932
|
pskBinders: u8[][]
|
|
@@ -901,18 +940,29 @@ export class TlsClientHello {
|
|
|
901
940
|
pskBindersPrefix: i32 = 0
|
|
902
941
|
/** 0 when the message parsed, or the alert it earns: `decode_error` or `illegal_parameter`. */
|
|
903
942
|
alert: i32 = 0
|
|
943
|
+
/** `legacy_version` as sent; TLS 1.3 fixes it at 0x0303 and negotiates the real version in `supported_versions` (§4.1.2). */
|
|
904
944
|
legacyVersion: i32 = 0
|
|
905
945
|
/** Whether `legacy_compression_methods` is the single null method TLS 1.3 requires (§4.1.2). */
|
|
906
946
|
nullCompressionOnly: boolean = false
|
|
947
|
+
/** Whether the hello carried `supported_versions`: without it the client does not offer TLS 1.3 (§4.2.1). */
|
|
907
948
|
hasSupportedVersions: boolean = false
|
|
949
|
+
/** Whether the hello carried `supported_groups`. */
|
|
908
950
|
hasSupportedGroups: boolean = false
|
|
951
|
+
/** Whether the hello carried `key_share`, even an empty one. */
|
|
909
952
|
hasKeyShare: boolean = false
|
|
953
|
+
/** Whether `key_share` offered an x25519 share, so `x25519Share` holds one. */
|
|
910
954
|
hasX25519Share: boolean = false
|
|
955
|
+
/** Whether the hello carried `signature_algorithms`. */
|
|
911
956
|
hasSignatureAlgorithms: boolean = false
|
|
957
|
+
/** Whether the hello carried `server_name` with a `host_name` in it. */
|
|
912
958
|
hasServerName: boolean = false
|
|
959
|
+
/** Whether the hello carried ALPN. */
|
|
913
960
|
hasAlpn: boolean = false
|
|
961
|
+
/** Whether the hello carried `quic_transport_parameters`, which a QUIC handshake requires (RFC 9001 §8.2). */
|
|
914
962
|
hasQuicTransportParameters: boolean = false
|
|
963
|
+
/** Whether the hello carried `pre_shared_key`, which must be its last extension (§4.2.11). */
|
|
915
964
|
hasPreSharedKey: boolean = false
|
|
965
|
+
/** Whether the hello carried `psk_key_exchange_modes`, without which a server must not resume (§4.2.9). */
|
|
916
966
|
hasPskModes: boolean = false
|
|
917
967
|
/** Whether `psk_key_exchange_modes` lists `psk_dhe_ke`. */
|
|
918
968
|
pskDheKe: boolean = false
|
|
@@ -2011,38 +2061,57 @@ export class TlsServerFlightView {
|
|
|
2011
2061
|
alert: i32 = 0
|
|
2012
2062
|
/** 0 when the extensions are ones this message may carry, else `illegal_parameter` or `unsupported_extension`. */
|
|
2013
2063
|
extensionAlert: i32 = 0
|
|
2064
|
+
/** ServerHello's `legacy_version` as sent; a TLS 1.3 server sends 0x0303 and names 1.3 in `supported_versions` (§4.1.3). */
|
|
2014
2065
|
legacyVersion: i32 = 0
|
|
2066
|
+
/** Where the server's 32-byte `random` starts in `data`; the client checks it for the downgrade sentinel (§4.1.3). */
|
|
2015
2067
|
randomAt: i32 = 0
|
|
2068
|
+
/** `legacy_session_id_echo`, which must equal the session id the client sent (§4.1.3). */
|
|
2016
2069
|
sessionIdAt: i32 = 0
|
|
2070
|
+
/** The echoed session id's length in bytes, 0 to 32. */
|
|
2017
2071
|
sessionIdLength: i32 = 0
|
|
2072
|
+
/** The cipher suite the server chose, a 16-bit value. */
|
|
2018
2073
|
suite: i32 = 0
|
|
2074
|
+
/** `legacy_compression_method`, which must be 0 (§4.1.3). */
|
|
2019
2075
|
compression: i32 = 0
|
|
2076
|
+
/** `supported_versions`' `selected_version`, 0 when the extension was absent; 0x0304 for TLS 1.3. */
|
|
2020
2077
|
selectedVersion: i32 = 0
|
|
2021
2078
|
/** `key_share`: a ServerHello's entry, or a HelloRetryRequest's `selected_group` with an empty share. */
|
|
2022
2079
|
shareGroup: i32 = 0
|
|
2080
|
+
/** Where the ServerHello's key_exchange starts in `data`. */
|
|
2023
2081
|
shareAt: i32 = 0
|
|
2082
|
+
/** The key_exchange's length in bytes as sent, 0 for a HelloRetryRequest; an x25519 share is 32. */
|
|
2024
2083
|
shareLength: i32 = 0
|
|
2025
2084
|
/** A HelloRetryRequest's `cookie`, which the second ClientHello echoes (§4.2.2). */
|
|
2026
2085
|
cookieAt: i32 = 0
|
|
2086
|
+
/** The cookie's length in bytes, 0 when none was sent. */
|
|
2027
2087
|
cookieLength: i32 = 0
|
|
2028
2088
|
/** EncryptedExtensions' ALPN: the one protocol the server chose (RFC 7301 §3.1). */
|
|
2029
2089
|
alpnAt: i32 = 0
|
|
2090
|
+
/** The chosen protocol name's length in bytes, 0 when ALPN was absent. */
|
|
2030
2091
|
alpnLength: i32 = 0
|
|
2031
2092
|
/** Certificate's `certificate_request_context`, which must be empty for a server's (§4.4.2). */
|
|
2032
2093
|
contextLength: i32 = 0
|
|
2033
2094
|
/** Certificate's `certificate_list`, every entry in it, and how many there are. */
|
|
2034
2095
|
certificatesAt: i32 = 0
|
|
2096
|
+
/** The `certificate_list` window's length in bytes. */
|
|
2035
2097
|
certificatesLength: i32 = 0
|
|
2098
|
+
/** How many entries `certificate_list` holds; the first is the server's own certificate. */
|
|
2036
2099
|
certificateCount: i32 = 0
|
|
2037
2100
|
/** CertificateVerify's scheme and signature (§4.4.3). */
|
|
2038
2101
|
scheme: i32 = 0
|
|
2102
|
+
/** Where CertificateVerify's signature starts in `data`. */
|
|
2039
2103
|
signatureAt: i32 = 0
|
|
2104
|
+
/** The signature's length in bytes. */
|
|
2040
2105
|
signatureLength: i32 = 0
|
|
2041
2106
|
/** A ServerHello whose `random` is the HelloRetryRequest value (§4.1.3). */
|
|
2042
2107
|
isRetry: boolean = false
|
|
2108
|
+
/** Whether the message carried `supported_versions`: a TLS 1.3 ServerHello must (§4.2.1). */
|
|
2043
2109
|
hasSupportedVersions: boolean = false
|
|
2110
|
+
/** Whether the message carried `key_share`. */
|
|
2044
2111
|
hasKeyShare: boolean = false
|
|
2112
|
+
/** Whether a HelloRetryRequest carried `cookie`. */
|
|
2045
2113
|
hasCookie: boolean = false
|
|
2114
|
+
/** Whether EncryptedExtensions carried ALPN. */
|
|
2046
2115
|
hasAlpn: boolean = false
|
|
2047
2116
|
/** EncryptedExtensions' empty `server_name`, the acknowledgement of RFC 6066 §3. */
|
|
2048
2117
|
serverNameAcknowledged: boolean = false
|
|
@@ -14,24 +14,25 @@
|
|
|
14
14
|
* }
|
|
15
15
|
* const got: i32 = conn.read(buf, 0, buf.length); // application data
|
|
16
16
|
*
|
|
17
|
-
* **What it adds to `TlsClient`.** Records around the handshake messages:
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
* `
|
|
31
|
-
*
|
|
32
|
-
* `
|
|
33
|
-
*
|
|
34
|
-
*
|
|
17
|
+
* **What it adds to `TlsClient`.** Records around the handshake messages: the
|
|
18
|
+
* ClientHello in the clear, then the client's Finished under the handshake
|
|
19
|
+
* keys, and every key installed at the record boundary RFC 8446 §5.1 puts it
|
|
20
|
+
* on. The middlebox-compatibility `change_cipher_spec` of §D.4, which a client
|
|
21
|
+
* that sends a session id (this one always does) owes: one, in the clear,
|
|
22
|
+
* before its second ClientHello after a HelloRetryRequest, or else before its
|
|
23
|
+
* first protected record; the server's is dropped from its first handshake
|
|
24
|
+
* record until its Finished.
|
|
25
|
+
*
|
|
26
|
+
* Alerts (§6) both ways, as the server has them: `close_notify` ends the
|
|
27
|
+
* server's stream, `user_canceled` is passed over, any other alert ends the
|
|
28
|
+
* connection, and a refusal of this module's or of `TlsClient`'s is sent as a
|
|
29
|
+
* fatal alert under whatever keys the client writes with. KeyUpdate (§4.6.3)
|
|
30
|
+
* both ways, with the server's limits: `TLS_RECORD_IDLE_LIMIT` records in a row
|
|
31
|
+
* that carry nothing, and `TLS_RECORD_MAX_KEY_UPDATES` KeyUpdates. A
|
|
32
|
+
* NewSessionTicket is handed to `TlsClient`, which checks and drops it; any
|
|
33
|
+
* other post-handshake message is `unexpected_message` (no client certificate
|
|
34
|
+
* is offered, so no CertificateRequest). A stream that ends without
|
|
35
|
+
* `close_notify` is truncation.
|
|
35
36
|
*
|
|
36
37
|
* **Authentication is the caller's.** At `TlsClient`'s `WAIT_AUTH` the
|
|
37
38
|
* records after the server's CertificateVerify stay in the reader and
|
|
@@ -186,10 +187,13 @@ const tlsClientAdvanceHeld = (protection: TlsRecordProtection, held: Secret<u8[]
|
|
|
186
187
|
* record the client writes carries after its content type (§5.4).
|
|
187
188
|
*/
|
|
188
189
|
export class TlsRecordClient {
|
|
190
|
+
/** The handshake underneath: read it for the suite, ALPN, the server's certificates and the exporter secret. */
|
|
189
191
|
tls: TlsClient
|
|
190
192
|
/** @internal Read by `net/fetch.ts`. */
|
|
191
193
|
reader: TlsRecordReader
|
|
194
|
+
/** Opens the server's records; its sequence number counts the records read at the current keys. */
|
|
192
195
|
readProtection: TlsRecordProtection
|
|
196
|
+
/** Seals the client's records; its sequence number counts the records written at the current keys. */
|
|
193
197
|
writeProtection: TlsRecordProtection
|
|
194
198
|
/** Never installed: seals the compatibility record in the clear once the write side is protected. */
|
|
195
199
|
private clearProtection: TlsRecordProtection
|
|
@@ -208,15 +212,21 @@ export class TlsRecordClient {
|
|
|
208
212
|
private writeHash: i32 = 0
|
|
209
213
|
/** The header of a post-handshake message the server has sent part of, and a KeyUpdate's body. */
|
|
210
214
|
private postHandshake: u8[]
|
|
215
|
+
/** Where the connection stands: one of the `TLS_RECORD_STATE_*` constants. */
|
|
211
216
|
state: i32 = 0
|
|
217
|
+
/** The alert this client sent, or 0. */
|
|
212
218
|
alert: i32 = 0
|
|
219
|
+
/** The error alert the server sent, or -1 when it sent none. */
|
|
213
220
|
peerAlert: i32 = -1
|
|
221
|
+
/** How many zero bytes each protected record the client writes carries after its content type (§5.4). */
|
|
214
222
|
padding: i32 = 0
|
|
215
223
|
/** The `TLS_LEVEL_*` the server's records are read at. */
|
|
216
224
|
private readLevel: i32 = 0
|
|
217
225
|
/** The `TLS_LEVEL_*` the client's records are written at. */
|
|
218
226
|
private writeLevel: i32 = 0
|
|
227
|
+
/** The index in `output` of the first byte still to send; `consume(sent)` moves it on. */
|
|
219
228
|
outputStart: i32 = 0
|
|
229
|
+
/** One past the last byte still to send in `output`; `outputStart` when nothing is pending. */
|
|
220
230
|
outputEnd: i32 = 0
|
|
221
231
|
/** @internal Read by `net/fetch.ts`. */
|
|
222
232
|
plainStart: i32 = 0
|
|
@@ -231,7 +241,9 @@ export class TlsRecordClient {
|
|
|
231
241
|
/** How many body bytes of a NewSessionTicket are still to come, handed to `TlsClient` as they arrive. */
|
|
232
242
|
private ticketLeft: i32 = 0
|
|
233
243
|
private idleRecords: i32 = 0
|
|
244
|
+
/** How many KeyUpdates from the server this client has taken, up to `TLS_RECORD_MAX_KEY_UPDATES`. */
|
|
234
245
|
keyUpdates: i32 = 0
|
|
246
|
+
/** True once the server's `close_notify` has arrived. */
|
|
235
247
|
peerClosed: boolean = false
|
|
236
248
|
/** @internal Read by `net/fetch.ts`. */
|
|
237
249
|
ended: boolean = false
|
|
@@ -15,59 +15,66 @@
|
|
|
15
15
|
* **What it adds to `TlsServer`.** Records around the handshake messages:
|
|
16
16
|
* ServerHello (or HelloRetryRequest) in the clear, the rest of the server's
|
|
17
17
|
* flight — EncryptedExtensions through Finished — in as few records as fit
|
|
18
|
-
* under the handshake keys once it is signed, which is one record for RFC
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
* server
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
* the
|
|
32
|
-
*
|
|
33
|
-
*
|
|
18
|
+
* under the handshake keys once it is signed, which is one record for RFC 8448
|
|
19
|
+
* §3's trace, and every key installed at the record boundary RFC 8446 §5.1 puts
|
|
20
|
+
* it on.
|
|
21
|
+
*
|
|
22
|
+
* The middlebox-compatibility `change_cipher_spec` of §D.4: the server sends
|
|
23
|
+
* one right after its first handshake message when the client sent a session
|
|
24
|
+
* id, and drops the client's from its first ClientHello until its Finished.
|
|
25
|
+
* Alerts (§6) both ways: `close_notify` ends the client's stream,
|
|
26
|
+
* `user_canceled` is passed over, any other alert ends the connection, and a
|
|
27
|
+
* refusal of this module's or of `TlsServer`'s is sent as a fatal alert under
|
|
28
|
+
* whatever keys the server writes with.
|
|
29
|
+
*
|
|
30
|
+
* KeyUpdate (§4.6.3) both ways: the client's moves the read keys on and, when
|
|
31
|
+
* it asks, the server answers with its own; `keyUpdate` sends one, and the
|
|
32
|
+
* writer sends one by itself before a key has protected
|
|
33
|
+
* `TLS_KEY_UPDATE_RECORDS` records. More than `TLS_RECORD_IDLE_LIMIT` records
|
|
34
|
+
* in a row that carry nothing for the caller — KeyUpdates among them, which
|
|
35
|
+
* each cost two key derivations — are refused. A stream that ends without
|
|
36
|
+
* `close_notify` is truncation, but only once the records still waiting for the
|
|
37
|
+
* caller have been read.
|
|
34
38
|
*
|
|
35
39
|
* **Borrowed buffers.** The record being read, the record being opened, the
|
|
36
|
-
* bytes to send and the application data waiting for the caller each live in
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
* `BufferPool.giveSecret` when it ends (`start`, `wipe`, `release`), so a
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
* `TlsServer`
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
40
|
+
* bytes to send and the application data waiting for the caller each live in an
|
|
41
|
+
* array borrowed from a `TlsRecordPools` when the connection first needs it,
|
|
42
|
+
* kept while the connection lasts, and given back zeroed with
|
|
43
|
+
* `BufferPool.giveSecret` when it ends (`start`, `wipe`, `release`), so a slot
|
|
44
|
+
* with no connection holds none of them, a connection that has finished its
|
|
45
|
+
* handshake allocates nothing that outlives a record, and a slot can be handed
|
|
46
|
+
* the next connection with `start`.
|
|
47
|
+
*
|
|
48
|
+
* Each give-back zeroes the whole buffer, so it happens once a connection
|
|
49
|
+
* rather than once a record. The handshake's messages are sealed straight out
|
|
50
|
+
* of `TlsServer`'s own buffers, and the application secrets are copied into
|
|
51
|
+
* this slot's fields, so a slot that hands its `TlsServer` the next connection
|
|
52
|
+
* with `restart` runs every handshake after the first without moving the arena,
|
|
53
|
+
* whichever suite it negotiates; a KeyUpdate's key install leaves nothing
|
|
54
|
+
* either (TLS-3 in `docs/security/tls.md`). When the caller leaves application
|
|
55
|
+
* data unread for long enough to fill its buffer, records stay in the reader
|
|
56
|
+
* and `interest` stops asking for reads, which is how the peer is made to wait.
|
|
52
57
|
*
|
|
53
58
|
* **Secrets.** Each traffic secret is a `Secret<u8[]>` (`nish:secret`):
|
|
54
59
|
* `TlsServer` holds the handshake's in its `TlsSecretPool`s, and this slot
|
|
55
60
|
* holds the two application traffic secrets in four readonly fields, one per
|
|
56
61
|
* direction and hash length, with `readHash` and `writeHash` saying which of
|
|
57
|
-
* each pair is live (0 when neither is).
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
* the
|
|
69
|
-
*
|
|
70
|
-
*
|
|
62
|
+
* each pair is live (0 when neither is).
|
|
63
|
+
*
|
|
64
|
+
* A secret is copied out of `TlsServer` as it is installed and the server's
|
|
65
|
+
* copy is zeroed, as are the handshake secret once the flight is signed and the
|
|
66
|
+
* ephemeral key once the ServerHello is written, or the handshake fails; a
|
|
67
|
+
* KeyUpdate overwrites the live field in place with the next secret.
|
|
68
|
+
*
|
|
69
|
+
* Every way the connection ends wipes what it holds: a failure of any kind
|
|
70
|
+
* (`fail`, the client's error alert, a truncated stream, `abort`) wipes both
|
|
71
|
+
* directions' keys, both secrets and everything `TlsServer` still holds once
|
|
72
|
+
* the last alert is sealed; the server's `close_notify`, once sealed, wipes the
|
|
73
|
+
* write direction, the client's the read direction, and `close` the resumption
|
|
74
|
+
* master secret; and `wipe` (which `wipeKeys` calls when the carrier closes the
|
|
75
|
+
* slot) and `start` wipe the rest. No secret leaves either object but through
|
|
76
|
+
* `expose`, so a secret cannot be logged or kept outside this module and
|
|
77
|
+
* `nish/net/tls` (TLS-1 in `docs/security/tls.md`).
|
|
71
78
|
*
|
|
72
79
|
* Refusals are alerts, never panics. Written from RFC 8446 §4.6.3, §5, §6
|
|
73
80
|
* and §D.4, not ported from another implementation.
|
|
@@ -180,9 +187,13 @@ const TLS_RECORD_SCRATCH_SIZE: i32 = TLS_MAX_PLAINTEXT
|
|
|
180
187
|
* (`BufferPool.giveSecret`): it held plaintext, or handshake bytes.
|
|
181
188
|
*/
|
|
182
189
|
export class TlsRecordPools {
|
|
190
|
+
/** Lends each slot its `output` buffer, where sealed records wait to be sent. */
|
|
183
191
|
output: BufferPool
|
|
192
|
+
/** Lends each slot its `plain` buffer, where opened application data waits to be read. */
|
|
184
193
|
plain: BufferPool
|
|
194
|
+
/** Lends each slot the buffer a record's content is opened into. */
|
|
185
195
|
scratch: BufferPool
|
|
196
|
+
/** Lends each slot its record reader's buffer. */
|
|
186
197
|
reader: BufferPool
|
|
187
198
|
|
|
188
199
|
/**
|
|
@@ -299,9 +310,12 @@ const tlsAdvanceHeld = (protection: TlsRecordProtection, held: Secret<u8[]>): bo
|
|
|
299
310
|
* caller sets it.
|
|
300
311
|
*/
|
|
301
312
|
export class TlsRecordServer {
|
|
313
|
+
/** The handshake underneath: read it for the suite, ALPN, server name and exporter secret. */
|
|
302
314
|
tls: TlsServer
|
|
303
315
|
private reader: TlsRecordReader
|
|
316
|
+
/** Opens the client's records; its sequence number counts the records read at the current keys. */
|
|
304
317
|
readProtection: TlsRecordProtection
|
|
318
|
+
/** Seals the server's records; its sequence number counts the records written at the current keys. */
|
|
305
319
|
writeProtection: TlsRecordProtection
|
|
306
320
|
/** Bytes to send are `output[outputStart .. outputEnd)`; `empty` until a record is sealed. */
|
|
307
321
|
output: u8[]
|
|
@@ -319,26 +333,39 @@ export class TlsRecordServer {
|
|
|
319
333
|
* say which of a pair holds the secret, and are 0 before it is known.
|
|
320
334
|
*/
|
|
321
335
|
readonly readTraffic256: Secret<u8[]>
|
|
336
|
+
/** The client's current application traffic secret when the hash is SHA-384, 48 bytes. */
|
|
322
337
|
readonly readTraffic384: Secret<u8[]>
|
|
338
|
+
/** The server's current application traffic secret when the hash is SHA-256, 32 bytes. */
|
|
323
339
|
readonly writeTraffic256: Secret<u8[]>
|
|
340
|
+
/** The server's current application traffic secret when the hash is SHA-384, 48 bytes. */
|
|
324
341
|
readonly writeTraffic384: Secret<u8[]>
|
|
342
|
+
/** The hash length of the client's traffic secret in bytes (32 or 48), or 0 before it is known. */
|
|
325
343
|
readHash: i32 = 0
|
|
344
|
+
/** The hash length of the server's traffic secret in bytes (32 or 48), or 0 before it is known. */
|
|
326
345
|
writeHash: i32 = 0
|
|
327
346
|
/** A post-handshake message the client has sent part of. */
|
|
328
347
|
private postHandshake: u8[]
|
|
348
|
+
/** Where the connection stands: one of the `TLS_RECORD_STATE_*` constants. */
|
|
329
349
|
state: i32 = 0
|
|
350
|
+
/** The alert this server sent, or 0. */
|
|
330
351
|
alert: i32 = 0
|
|
352
|
+
/** The error alert the client sent, or -1 when it sent none. */
|
|
331
353
|
peerAlert: i32 = -1
|
|
354
|
+
/** How many zero bytes each protected record the server writes carries after its content type (§5.4); 0 unless the caller sets it. */
|
|
332
355
|
padding: i32 = 0
|
|
333
356
|
/** The `TLS_LEVEL_*` the client's records are read at: Initial in the clear, then Handshake, then Application. */
|
|
334
357
|
private readLevel: i32 = 0
|
|
335
358
|
/** The `TLS_LEVEL_*` the server's records are written at. */
|
|
336
359
|
writeLevel: i32 = 0
|
|
360
|
+
/** The index in `output` of the first byte still to send; `consume(sent)` moves it on. */
|
|
337
361
|
outputStart: i32 = 0
|
|
362
|
+
/** One past the last byte still to send in `output`; `outputStart` when nothing is pending. */
|
|
338
363
|
outputEnd: i32 = 0
|
|
339
364
|
/** How far into `output` this borrowing has written, which says whether its give-back zeroes. */
|
|
340
365
|
private outputUsed: i32 = 0
|
|
366
|
+
/** The index in `plain` of the first byte of application data the caller has not read. */
|
|
341
367
|
plainStart: i32 = 0
|
|
368
|
+
/** One past the last unread byte in `plain`; `plainStart` when none is pending. */
|
|
342
369
|
plainEnd: i32 = 0
|
|
343
370
|
/** How far into `plain` this borrowing has written. */
|
|
344
371
|
private plainUsed: i32 = 0
|
|
@@ -355,6 +382,7 @@ export class TlsRecordServer {
|
|
|
355
382
|
keyUpdates: i32 = 0
|
|
356
383
|
/** The server's flight is signed and finished, so its Handshake-level output may be sealed. */
|
|
357
384
|
private flightReady: boolean = false
|
|
385
|
+
/** True once the client's `close_notify` has arrived. */
|
|
358
386
|
peerClosed: boolean = false
|
|
359
387
|
/**
|
|
360
388
|
* The client's TCP stream ended. Without a `close_notify` before it, that is truncation and the connection failed.
|
package/std/net/tls/record.ts
CHANGED
|
@@ -23,14 +23,16 @@
|
|
|
23
23
|
* cleartext until `install` gives it a suite and a traffic secret, then
|
|
24
24
|
* TLSCiphertext (§5.2) under the AEAD the suite names. Each record's nonce is
|
|
25
25
|
* the traffic IV XORed with the 64-bit record sequence number (§5.3), and its
|
|
26
|
-
* additional data is the record's own header.
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
* padding
|
|
31
|
-
*
|
|
32
|
-
* the
|
|
33
|
-
*
|
|
26
|
+
* additional data is the record's own header.
|
|
27
|
+
*
|
|
28
|
+
* Inside, the content is followed by its real type and by zero padding (§5.4);
|
|
29
|
+
* `open` finds the type by reading every byte of the decrypted record whatever
|
|
30
|
+
* the padding is, so how much padding there was is not in its timing, and
|
|
31
|
+
* refuses a record that is padding and nothing else. Both `seal` and `open`
|
|
32
|
+
* write into a buffer the caller owns and answer a count, and what they
|
|
33
|
+
* allocate on the way dies with the call (docs/LANGUAGE.md, "Memory model"), so
|
|
34
|
+
* a connection that has finished its handshake moves records without moving the
|
|
35
|
+
* arena.
|
|
34
36
|
*
|
|
35
37
|
* **Refusals are alerts.** Every function that can refuse answers the alert to
|
|
36
38
|
* send, negated, as a negative count: `-TLS_ALERT_BAD_RECORD_MAC` for a record
|
|
@@ -41,17 +43,20 @@
|
|
|
41
43
|
* sends can make it panic.
|
|
42
44
|
*
|
|
43
45
|
* **Secrets.** A traffic secret arrives as plain bytes, since that is how
|
|
44
|
-
* `nish/net/tls` hands it over.
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
46
|
+
* `nish/net/tls` hands it over.
|
|
47
|
+
*
|
|
48
|
+
* The key, the IV and the AES key schedule derived from it are held in the
|
|
49
|
+
* protection's fields, because a `Secret` may not be one (NL2430), in arrays
|
|
50
|
+
* the protection reuses for every key it is given, and are zeroed when it is
|
|
51
|
+
* installed again or cleared — the key and IV with `secureZero`, the schedule
|
|
52
|
+
* with `aesKeyWipe`, the volatile `wipe` of its round keys (the kernels' powers
|
|
53
|
+
* of H included) and of H. The key and IV are derived straight into place, in
|
|
54
|
+
* an HKDF scratch that is wiped after each derivation, and the schedule is
|
|
55
|
+
* expanded into place by `aesKeyInto` (TLS-2 in `docs/security/tls.md`).
|
|
56
|
+
*
|
|
57
|
+
* A caller that holds the traffic secret as a `Secret` installs it with
|
|
58
|
+
* `installHeld` and ratchets it in place with `advanceHeld`, so the secret
|
|
59
|
+
* itself is never plain outside `exposeWith`.
|
|
55
60
|
*
|
|
56
61
|
* The record layer is sans-IO: `nish/net/tls/record-server` runs it over a
|
|
57
62
|
* stream for `TlsServer`, and `nish/net/tls-tcp` puts that on a socket.
|
|
@@ -390,8 +395,11 @@ export class TlsRecordProtection {
|
|
|
390
395
|
contentType: i32 = 0
|
|
391
396
|
/** The arrays `key` and `aes` point into: AES-128's and ChaCha20's or AES-256's. */
|
|
392
397
|
key16: u8[]
|
|
398
|
+
/** The 32-byte key array `key` points into for ChaCha20-Poly1305 and AES-256-GCM; `clear` zeroes it. */
|
|
393
399
|
key32: u8[]
|
|
400
|
+
/** The expanded AES-128 key schedule `aes` points to under AES-128-GCM, 10 rounds; `clear` wipes it. */
|
|
394
401
|
aes128: AesKey
|
|
402
|
+
/** The expanded AES-256 key schedule `aes` points to under AES-256-GCM, 14 rounds; `clear` wipes it. */
|
|
395
403
|
aes256: AesKey
|
|
396
404
|
/** Where `advance` derives the next traffic secret: HashLen bytes of it. */
|
|
397
405
|
next: u8[]
|
|
@@ -700,14 +708,15 @@ export class TlsRecordProtection {
|
|
|
700
708
|
* `contentType`. Cleartext, the content is the body and the type the
|
|
701
709
|
* header's: `application_data` is `unexpected_message`, since it is never
|
|
702
710
|
* sent in the clear, and a body over 2^14 bytes is `record_overflow`.
|
|
711
|
+
*
|
|
703
712
|
* Protected, the header's type must be `application_data`
|
|
704
713
|
* (`unexpected_message` otherwise), the body must authenticate under this
|
|
705
714
|
* record's nonce with the header as additional data (`bad_record_mac`), the
|
|
706
|
-
* decrypted record may be no longer than 2^14 + 1 bytes
|
|
707
|
-
*
|
|
708
|
-
*
|
|
709
|
-
*
|
|
710
|
-
*
|
|
715
|
+
* decrypted record may be no longer than 2^14 + 1 bytes (`record_overflow`),
|
|
716
|
+
* and its last non-zero byte is the real type — one that is all zeros is
|
|
717
|
+
* `unexpected_message` (§5.4). Every refusal is the alert negated; a window
|
|
718
|
+
* outside `record`, a `len` that is not the header's, or too little room at
|
|
719
|
+
* `out[at]` is `-TLS_ALERT_INTERNAL_ERROR`.
|
|
711
720
|
*
|
|
712
721
|
* A protected record that fails to authenticate leaves the sequence number
|
|
713
722
|
* where it was; one that authenticates spends its number even when its
|