nlcurl 0.6.0 → 0.8.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 +143 -140
- package/dist/cache/groups.d.ts +75 -0
- package/dist/cache/groups.d.ts.map +1 -0
- package/dist/cache/groups.js +118 -0
- package/dist/cache/groups.js.map +1 -0
- package/dist/cache/no-vary-search.d.ts +33 -0
- package/dist/cache/no-vary-search.d.ts.map +1 -0
- package/dist/cache/no-vary-search.js +148 -0
- package/dist/cache/no-vary-search.js.map +1 -0
- package/dist/cache/range.d.ts +120 -0
- package/dist/cache/range.d.ts.map +1 -0
- package/dist/cache/range.js +193 -0
- package/dist/cache/range.js.map +1 -0
- package/dist/cache/store.d.ts +111 -0
- package/dist/cache/store.d.ts.map +1 -0
- package/dist/cache/store.js +414 -0
- package/dist/cache/store.js.map +1 -0
- package/dist/cache/types.d.ts +69 -0
- package/dist/cache/types.d.ts.map +1 -0
- package/dist/cache/types.js +2 -0
- package/dist/cache/types.js.map +1 -0
- package/dist/cli/args.d.ts +4 -37
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +3 -4
- package/dist/cli/args.js.map +1 -1
- package/dist/cli/index.d.ts +0 -5
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +1 -6
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/output.d.ts +14 -20
- package/dist/cli/output.d.ts.map +1 -1
- package/dist/cli/output.js +14 -20
- package/dist/cli/output.js.map +1 -1
- package/dist/cookies/jar.d.ts +33 -31
- package/dist/cookies/jar.d.ts.map +1 -1
- package/dist/cookies/jar.js +69 -33
- package/dist/cookies/jar.js.map +1 -1
- package/dist/cookies/parser.d.ts +14 -16
- package/dist/cookies/parser.d.ts.map +1 -1
- package/dist/cookies/parser.js +30 -13
- package/dist/cookies/parser.js.map +1 -1
- package/dist/cookies/psl-data.d.ts +1 -1
- package/dist/cookies/psl-data.js +1 -1
- package/dist/cookies/public-suffix.d.ts +5 -27
- package/dist/cookies/public-suffix.d.ts.map +1 -1
- package/dist/cookies/public-suffix.js +5 -37
- package/dist/cookies/public-suffix.js.map +1 -1
- package/dist/core/auth.d.ts +30 -0
- package/dist/core/auth.d.ts.map +1 -0
- package/dist/core/auth.js +34 -0
- package/dist/core/auth.js.map +1 -0
- package/dist/core/client.d.ts +28 -40
- package/dist/core/client.d.ts.map +1 -1
- package/dist/core/client.js +34 -41
- package/dist/core/client.js.map +1 -1
- package/dist/core/errors.d.ts +64 -88
- package/dist/core/errors.d.ts.map +1 -1
- package/dist/core/errors.js +64 -88
- package/dist/core/errors.js.map +1 -1
- package/dist/core/request.d.ts +63 -85
- package/dist/core/request.d.ts.map +1 -1
- package/dist/core/response.d.ts +64 -59
- package/dist/core/response.d.ts.map +1 -1
- package/dist/core/response.js +70 -52
- package/dist/core/response.js.map +1 -1
- package/dist/core/session.d.ts +81 -70
- package/dist/core/session.d.ts.map +1 -1
- package/dist/core/session.js +198 -71
- package/dist/core/session.js.map +1 -1
- package/dist/core/validation.d.ts +44 -42
- package/dist/core/validation.d.ts.map +1 -1
- package/dist/core/validation.js +47 -58
- package/dist/core/validation.js.map +1 -1
- package/dist/dns/cache.d.ts +59 -0
- package/dist/dns/cache.d.ts.map +1 -0
- package/dist/dns/cache.js +99 -0
- package/dist/dns/cache.js.map +1 -0
- package/dist/dns/codec.d.ts +39 -0
- package/dist/dns/codec.d.ts.map +1 -0
- package/dist/dns/codec.js +238 -0
- package/dist/dns/codec.js.map +1 -0
- package/dist/dns/doh-resolver.d.ts +38 -0
- package/dist/dns/doh-resolver.d.ts.map +1 -0
- package/dist/dns/doh-resolver.js +191 -0
- package/dist/dns/doh-resolver.js.map +1 -0
- package/dist/dns/dot-resolver.d.ts +89 -0
- package/dist/dns/dot-resolver.d.ts.map +1 -0
- package/dist/dns/dot-resolver.js +158 -0
- package/dist/dns/dot-resolver.js.map +1 -0
- package/dist/dns/https-rr.d.ts +40 -0
- package/dist/dns/https-rr.d.ts.map +1 -0
- package/dist/dns/https-rr.js +109 -0
- package/dist/dns/https-rr.js.map +1 -0
- package/dist/dns/types.d.ts +82 -0
- package/dist/dns/types.d.ts.map +1 -0
- package/dist/dns/types.js +23 -0
- package/dist/dns/types.js.map +1 -0
- package/dist/fingerprints/akamai.d.ts +3 -11
- package/dist/fingerprints/akamai.d.ts.map +1 -1
- package/dist/fingerprints/akamai.js +3 -11
- package/dist/fingerprints/akamai.js.map +1 -1
- package/dist/fingerprints/database.d.ts +6 -14
- package/dist/fingerprints/database.d.ts.map +1 -1
- package/dist/fingerprints/database.js +6 -14
- package/dist/fingerprints/database.js.map +1 -1
- package/dist/fingerprints/extensions.d.ts +56 -71
- package/dist/fingerprints/extensions.d.ts.map +1 -1
- package/dist/fingerprints/extensions.js +58 -71
- package/dist/fingerprints/extensions.js.map +1 -1
- package/dist/fingerprints/ja3.d.ts +12 -30
- package/dist/fingerprints/ja3.d.ts.map +1 -1
- package/dist/fingerprints/ja3.js +12 -30
- package/dist/fingerprints/ja3.js.map +1 -1
- package/dist/fingerprints/ja4.d.ts +18 -0
- package/dist/fingerprints/ja4.d.ts.map +1 -0
- package/dist/fingerprints/ja4.js +83 -0
- package/dist/fingerprints/ja4.js.map +1 -0
- package/dist/fingerprints/profiles/chrome.d.ts +18 -21
- package/dist/fingerprints/profiles/chrome.d.ts.map +1 -1
- package/dist/fingerprints/profiles/chrome.js +35 -31
- package/dist/fingerprints/profiles/chrome.js.map +1 -1
- package/dist/fingerprints/profiles/edge.d.ts +7 -10
- package/dist/fingerprints/profiles/edge.d.ts.map +1 -1
- package/dist/fingerprints/profiles/edge.js +7 -10
- package/dist/fingerprints/profiles/edge.js.map +1 -1
- package/dist/fingerprints/profiles/firefox.d.ts +8 -11
- package/dist/fingerprints/profiles/firefox.d.ts.map +1 -1
- package/dist/fingerprints/profiles/firefox.js +8 -11
- package/dist/fingerprints/profiles/firefox.js.map +1 -1
- package/dist/fingerprints/profiles/safari.d.ts +11 -14
- package/dist/fingerprints/profiles/safari.d.ts.map +1 -1
- package/dist/fingerprints/profiles/safari.js +11 -14
- package/dist/fingerprints/profiles/safari.js.map +1 -1
- package/dist/fingerprints/profiles/tor.d.ts +5 -8
- package/dist/fingerprints/profiles/tor.d.ts.map +1 -1
- package/dist/fingerprints/profiles/tor.js +5 -8
- package/dist/fingerprints/profiles/tor.js.map +1 -1
- package/dist/fingerprints/types.d.ts +42 -73
- package/dist/fingerprints/types.d.ts.map +1 -1
- package/dist/hsts/store.d.ts +39 -0
- package/dist/hsts/store.d.ts.map +1 -0
- package/dist/hsts/store.js +163 -0
- package/dist/hsts/store.js.map +1 -0
- package/dist/hsts/types.d.ts +24 -0
- package/dist/hsts/types.d.ts.map +1 -0
- package/dist/hsts/types.js +2 -0
- package/dist/hsts/types.js.map +1 -0
- package/dist/http/alt-svc.d.ts +67 -0
- package/dist/http/alt-svc.d.ts.map +1 -0
- package/dist/http/alt-svc.js +186 -0
- package/dist/http/alt-svc.js.map +1 -0
- package/dist/http/early-hints.d.ts +23 -0
- package/dist/http/early-hints.d.ts.map +1 -0
- package/dist/http/early-hints.js +33 -0
- package/dist/http/early-hints.js.map +1 -0
- package/dist/http/form-data.d.ts +17 -35
- package/dist/http/form-data.d.ts.map +1 -1
- package/dist/http/form-data.js +12 -34
- package/dist/http/form-data.js.map +1 -1
- package/dist/http/h1/client.d.ts +14 -26
- package/dist/http/h1/client.d.ts.map +1 -1
- package/dist/http/h1/client.js +29 -22
- package/dist/http/h1/client.js.map +1 -1
- package/dist/http/h1/encoder.d.ts +10 -17
- package/dist/http/h1/encoder.d.ts.map +1 -1
- package/dist/http/h1/encoder.js +10 -17
- package/dist/http/h1/encoder.js.map +1 -1
- package/dist/http/h1/parser.d.ts +22 -59
- package/dist/http/h1/parser.d.ts.map +1 -1
- package/dist/http/h1/parser.js +15 -47
- package/dist/http/h1/parser.js.map +1 -1
- package/dist/http/h2/client.d.ts +18 -59
- package/dist/http/h2/client.d.ts.map +1 -1
- package/dist/http/h2/client.js +29 -64
- package/dist/http/h2/client.js.map +1 -1
- package/dist/http/h2/frames.d.ts +53 -84
- package/dist/http/h2/frames.d.ts.map +1 -1
- package/dist/http/h2/frames.js +48 -76
- package/dist/http/h2/frames.js.map +1 -1
- package/dist/http/h2/hpack.d.ts +16 -35
- package/dist/http/h2/hpack.d.ts.map +1 -1
- package/dist/http/h2/hpack.js +16 -35
- package/dist/http/h2/hpack.js.map +1 -1
- package/dist/http/h3/detection.d.ts +15 -0
- package/dist/http/h3/detection.d.ts.map +1 -0
- package/dist/http/h3/detection.js +41 -0
- package/dist/http/h3/detection.js.map +1 -0
- package/dist/http/negotiator.d.ts +43 -33
- package/dist/http/negotiator.d.ts.map +1 -1
- package/dist/http/negotiator.js +99 -41
- package/dist/http/negotiator.js.map +1 -1
- package/dist/http/pool.d.ts +34 -64
- package/dist/http/pool.d.ts.map +1 -1
- package/dist/http/pool.js +22 -41
- package/dist/http/pool.js.map +1 -1
- package/dist/http/resumable-upload.d.ts +76 -0
- package/dist/http/resumable-upload.d.ts.map +1 -0
- package/dist/http/resumable-upload.js +104 -0
- package/dist/http/resumable-upload.js.map +1 -0
- package/dist/http/trailers.d.ts +29 -0
- package/dist/http/trailers.d.ts.map +1 -0
- package/dist/http/trailers.js +57 -0
- package/dist/http/trailers.js.map +1 -0
- package/dist/index.d.ts +36 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +32 -1
- package/dist/index.js.map +1 -1
- package/dist/middleware/interceptor.d.ts +13 -32
- package/dist/middleware/interceptor.d.ts.map +1 -1
- package/dist/middleware/interceptor.js +11 -16
- package/dist/middleware/interceptor.js.map +1 -1
- package/dist/middleware/rate-limiter.d.ts +8 -17
- package/dist/middleware/rate-limiter.d.ts.map +1 -1
- package/dist/middleware/rate-limiter.js +15 -12
- package/dist/middleware/rate-limiter.js.map +1 -1
- package/dist/middleware/retry-after.d.ts +15 -0
- package/dist/middleware/retry-after.d.ts.map +1 -0
- package/dist/middleware/retry-after.js +36 -0
- package/dist/middleware/retry-after.js.map +1 -0
- package/dist/middleware/retry.d.ts +9 -18
- package/dist/middleware/retry.d.ts.map +1 -1
- package/dist/middleware/retry.js +12 -9
- package/dist/middleware/retry.js.map +1 -1
- package/dist/proxy/auth.d.ts +73 -0
- package/dist/proxy/auth.d.ts.map +1 -0
- package/dist/proxy/auth.js +128 -0
- package/dist/proxy/auth.js.map +1 -0
- package/dist/proxy/env-proxy.d.ts +11 -0
- package/dist/proxy/env-proxy.d.ts.map +1 -0
- package/dist/proxy/env-proxy.js +56 -0
- package/dist/proxy/env-proxy.js.map +1 -0
- package/dist/proxy/http-proxy.d.ts +13 -18
- package/dist/proxy/http-proxy.d.ts.map +1 -1
- package/dist/proxy/http-proxy.js +24 -14
- package/dist/proxy/http-proxy.js.map +1 -1
- package/dist/proxy/socks.d.ts +13 -20
- package/dist/proxy/socks.d.ts.map +1 -1
- package/dist/proxy/socks.js +6 -9
- package/dist/proxy/socks.js.map +1 -1
- package/dist/sse/parser.d.ts +47 -0
- package/dist/sse/parser.d.ts.map +1 -0
- package/dist/sse/parser.js +139 -0
- package/dist/sse/parser.js.map +1 -0
- package/dist/tls/constants.d.ts +15 -74
- package/dist/tls/constants.d.ts.map +1 -1
- package/dist/tls/constants.js +15 -74
- package/dist/tls/constants.js.map +1 -1
- package/dist/tls/ct.d.ts +78 -0
- package/dist/tls/ct.d.ts.map +1 -0
- package/dist/tls/ct.js +175 -0
- package/dist/tls/ct.js.map +1 -0
- package/dist/tls/early-data.d.ts +45 -0
- package/dist/tls/early-data.d.ts.map +1 -0
- package/dist/tls/early-data.js +46 -0
- package/dist/tls/early-data.js.map +1 -0
- package/dist/tls/ech.d.ts +130 -0
- package/dist/tls/ech.d.ts.map +1 -0
- package/dist/tls/ech.js +353 -0
- package/dist/tls/ech.js.map +1 -0
- package/dist/tls/keylog.d.ts +34 -0
- package/dist/tls/keylog.d.ts.map +1 -0
- package/dist/tls/keylog.js +64 -0
- package/dist/tls/keylog.js.map +1 -0
- package/dist/tls/node-engine.d.ts +15 -14
- package/dist/tls/node-engine.d.ts.map +1 -1
- package/dist/tls/node-engine.js +54 -14
- package/dist/tls/node-engine.js.map +1 -1
- package/dist/tls/ocsp.d.ts +55 -0
- package/dist/tls/ocsp.d.ts.map +1 -0
- package/dist/tls/ocsp.js +131 -0
- package/dist/tls/ocsp.js.map +1 -0
- package/dist/tls/pin-verification.d.ts +10 -0
- package/dist/tls/pin-verification.d.ts.map +1 -0
- package/dist/tls/pin-verification.js +28 -0
- package/dist/tls/pin-verification.js.map +1 -0
- package/dist/tls/session-cache.d.ts +58 -0
- package/dist/tls/session-cache.d.ts.map +1 -0
- package/dist/tls/session-cache.js +76 -0
- package/dist/tls/session-cache.js.map +1 -0
- package/dist/tls/stealth/client-hello.d.ts +34 -32
- package/dist/tls/stealth/client-hello.d.ts.map +1 -1
- package/dist/tls/stealth/client-hello.js +116 -11
- package/dist/tls/stealth/client-hello.js.map +1 -1
- package/dist/tls/stealth/engine.d.ts +5 -15
- package/dist/tls/stealth/engine.d.ts.map +1 -1
- package/dist/tls/stealth/engine.js +163 -47
- package/dist/tls/stealth/engine.js.map +1 -1
- package/dist/tls/stealth/handshake.d.ts +23 -32
- package/dist/tls/stealth/handshake.d.ts.map +1 -1
- package/dist/tls/stealth/handshake.js +112 -27
- package/dist/tls/stealth/handshake.js.map +1 -1
- package/dist/tls/stealth/key-schedule.d.ts +59 -86
- package/dist/tls/stealth/key-schedule.d.ts.map +1 -1
- package/dist/tls/stealth/key-schedule.js +46 -58
- package/dist/tls/stealth/key-schedule.js.map +1 -1
- package/dist/tls/stealth/record-layer.d.ts +52 -75
- package/dist/tls/stealth/record-layer.d.ts.map +1 -1
- package/dist/tls/stealth/record-layer.js +47 -63
- package/dist/tls/stealth/record-layer.js.map +1 -1
- package/dist/tls/stealth/tls12-handshake.d.ts +30 -0
- package/dist/tls/stealth/tls12-handshake.d.ts.map +1 -0
- package/dist/tls/stealth/tls12-handshake.js +470 -0
- package/dist/tls/stealth/tls12-handshake.js.map +1 -0
- package/dist/tls/types.d.ts +46 -48
- package/dist/tls/types.d.ts.map +1 -1
- package/dist/utils/buffer-reader.d.ts +26 -81
- package/dist/utils/buffer-reader.d.ts.map +1 -1
- package/dist/utils/buffer-reader.js +26 -81
- package/dist/utils/buffer-reader.js.map +1 -1
- package/dist/utils/buffer-writer.d.ts +30 -66
- package/dist/utils/buffer-writer.d.ts.map +1 -1
- package/dist/utils/buffer-writer.js +30 -66
- package/dist/utils/buffer-writer.js.map +1 -1
- package/dist/utils/compression.d.ts +18 -0
- package/dist/utils/compression.d.ts.map +1 -0
- package/dist/utils/compression.js +34 -0
- package/dist/utils/compression.js.map +1 -0
- package/dist/utils/dictionary-transport.d.ts +97 -0
- package/dist/utils/dictionary-transport.d.ts.map +1 -0
- package/dist/utils/dictionary-transport.js +171 -0
- package/dist/utils/dictionary-transport.js.map +1 -0
- package/dist/utils/encoding.d.ts +12 -28
- package/dist/utils/encoding.d.ts.map +1 -1
- package/dist/utils/encoding.js +77 -40
- package/dist/utils/encoding.js.map +1 -1
- package/dist/utils/happy-eyeballs.d.ts +20 -7
- package/dist/utils/happy-eyeballs.d.ts.map +1 -1
- package/dist/utils/happy-eyeballs.js +57 -25
- package/dist/utils/happy-eyeballs.js.map +1 -1
- package/dist/utils/logger.d.ts +54 -81
- package/dist/utils/logger.d.ts.map +1 -1
- package/dist/utils/logger.js +92 -64
- package/dist/utils/logger.js.map +1 -1
- package/dist/utils/tcp-fast-open.d.ts +30 -0
- package/dist/utils/tcp-fast-open.d.ts.map +1 -0
- package/dist/utils/tcp-fast-open.js +36 -0
- package/dist/utils/tcp-fast-open.js.map +1 -0
- package/dist/utils/url.d.ts +18 -25
- package/dist/utils/url.d.ts.map +1 -1
- package/dist/utils/url.js +18 -25
- package/dist/utils/url.js.map +1 -1
- package/dist/ws/client.d.ts +35 -52
- package/dist/ws/client.d.ts.map +1 -1
- package/dist/ws/client.js +92 -37
- package/dist/ws/client.js.map +1 -1
- package/dist/ws/frame.d.ts +27 -42
- package/dist/ws/frame.d.ts.map +1 -1
- package/dist/ws/frame.js +25 -37
- package/dist/ws/frame.js.map +1 -1
- package/dist/ws/permessage-deflate.d.ts +53 -0
- package/dist/ws/permessage-deflate.d.ts.map +1 -0
- package/dist/ws/permessage-deflate.js +140 -0
- package/dist/ws/permessage-deflate.js.map +1 -0
- package/package.json +62 -62
|
@@ -1,35 +1,33 @@
|
|
|
1
1
|
import { createHmac, createHash as _createHash } from "node:crypto";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* Return the digest output length for the given hash algorithm.
|
|
4
4
|
*
|
|
5
|
-
* @param {HashAlgorithm} alg - Hash algorithm
|
|
6
|
-
* @returns {number}
|
|
5
|
+
* @param {HashAlgorithm} alg - Hash algorithm.
|
|
6
|
+
* @returns {number} Length in bytes.
|
|
7
7
|
*/
|
|
8
8
|
export function hashLength(alg) {
|
|
9
9
|
return alg === "sha256" ? 32 : 48;
|
|
10
10
|
}
|
|
11
11
|
/**
|
|
12
|
-
*
|
|
12
|
+
* HKDF-Extract as defined in RFC 5869.
|
|
13
13
|
*
|
|
14
|
-
* @param {HashAlgorithm} alg
|
|
15
|
-
* @param {Buffer}
|
|
16
|
-
* @param {Buffer}
|
|
17
|
-
* @returns {Buffer} Pseudorandom key
|
|
14
|
+
* @param {HashAlgorithm} alg - Hash algorithm.
|
|
15
|
+
* @param {Buffer} salt - Salt value.
|
|
16
|
+
* @param {Buffer} ikm - Input keying material.
|
|
17
|
+
* @returns {Buffer} Pseudorandom key.
|
|
18
18
|
*/
|
|
19
19
|
export function hkdfExtract(alg, salt, ikm) {
|
|
20
20
|
return Buffer.from(createHmac(alg, salt).update(ikm).digest());
|
|
21
21
|
}
|
|
22
22
|
/**
|
|
23
|
-
*
|
|
24
|
-
* deriving a key of `length` bytes from `secret` using the given label
|
|
25
|
-
* and context hash.
|
|
23
|
+
* HKDF-Expand-Label as defined in TLS 1.3 (RFC 8446 §7.1).
|
|
26
24
|
*
|
|
27
|
-
* @param {HashAlgorithm} alg
|
|
28
|
-
* @param {Buffer}
|
|
29
|
-
* @param {string}
|
|
30
|
-
* @param {Buffer}
|
|
31
|
-
* @param {number}
|
|
32
|
-
* @returns {Buffer} Derived key material
|
|
25
|
+
* @param {HashAlgorithm} alg - Hash algorithm.
|
|
26
|
+
* @param {Buffer} secret - Input secret.
|
|
27
|
+
* @param {string} label - Label string (without the "tls13 " prefix).
|
|
28
|
+
* @param {Buffer} context - Context hash.
|
|
29
|
+
* @param {number} length - Desired output length in bytes.
|
|
30
|
+
* @returns {Buffer} Derived key material.
|
|
33
31
|
*/
|
|
34
32
|
export function hkdfExpandLabel(alg, secret, label, context, length) {
|
|
35
33
|
const fullLabel = Buffer.from("tls13 " + label, "ascii");
|
|
@@ -60,36 +58,32 @@ function hkdfExpand(alg, prk, info, length) {
|
|
|
60
58
|
return okm.subarray(0, length);
|
|
61
59
|
}
|
|
62
60
|
/**
|
|
63
|
-
*
|
|
64
|
-
* (RFC 8446 §7.1). This is the canonical `Derive-Secret` function of the
|
|
65
|
-
* TLS 1.3 key schedule.
|
|
61
|
+
* Derive a TLS 1.3 secret from an intermediate secret and transcript hash.
|
|
66
62
|
*
|
|
67
|
-
* @param {HashAlgorithm} alg
|
|
68
|
-
* @param {Buffer}
|
|
69
|
-
* @param {string}
|
|
70
|
-
* @param {Buffer}
|
|
71
|
-
* @returns {Buffer} Derived secret
|
|
63
|
+
* @param {HashAlgorithm} alg - Hash algorithm.
|
|
64
|
+
* @param {Buffer} secret - Base secret.
|
|
65
|
+
* @param {string} label - Derivation label.
|
|
66
|
+
* @param {Buffer} transcriptHash - Current transcript hash.
|
|
67
|
+
* @returns {Buffer} Derived secret.
|
|
72
68
|
*/
|
|
73
69
|
export function deriveSecret(alg, secret, label, transcriptHash) {
|
|
74
70
|
return hkdfExpandLabel(alg, secret, label, transcriptHash, hashLength(alg));
|
|
75
71
|
}
|
|
76
72
|
export { _createHash as createHash };
|
|
77
73
|
/**
|
|
78
|
-
*
|
|
79
|
-
* `alg` — used as the IKM or salt argument in HKDF-Extract calls that
|
|
80
|
-
* require a zero-length secret at the start of the TLS 1.3 key schedule.
|
|
74
|
+
* Return an all-zero key of the hash's digest length.
|
|
81
75
|
*
|
|
82
|
-
* @param {HashAlgorithm} alg - Hash algorithm
|
|
83
|
-
* @returns {Buffer} Zero-filled buffer
|
|
76
|
+
* @param {HashAlgorithm} alg - Hash algorithm.
|
|
77
|
+
* @returns {Buffer} Zero-filled buffer.
|
|
84
78
|
*/
|
|
85
79
|
export function zeroKey(alg) {
|
|
86
80
|
return Buffer.alloc(hashLength(alg));
|
|
87
81
|
}
|
|
88
82
|
/**
|
|
89
|
-
*
|
|
83
|
+
* Determine key and IV lengths for a TLS cipher suite.
|
|
90
84
|
*
|
|
91
|
-
* @param {string} cipherName -
|
|
92
|
-
* @returns {{ keyLen: number; ivLen: number }} Key
|
|
85
|
+
* @param {string} cipherName - Cipher suite name string.
|
|
86
|
+
* @returns {{ keyLen: number; ivLen: number }} Key and IV lengths in bytes.
|
|
93
87
|
*/
|
|
94
88
|
export function keyIVLengths(cipherName) {
|
|
95
89
|
if (cipherName.includes("AES_128")) {
|
|
@@ -101,16 +95,14 @@ export function keyIVLengths(cipherName) {
|
|
|
101
95
|
return { keyLen: 16, ivLen: 12 };
|
|
102
96
|
}
|
|
103
97
|
/**
|
|
104
|
-
*
|
|
105
|
-
* the transcript hash of the ClientHello and ServerHello messages
|
|
106
|
-
* (RFC 8446 §7.1).
|
|
98
|
+
* Derive TLS 1.3 handshake traffic keys from the shared secret.
|
|
107
99
|
*
|
|
108
|
-
* @param {HashAlgorithm} alg
|
|
109
|
-
* @param {Buffer}
|
|
110
|
-
* @param {Buffer}
|
|
111
|
-
* @param {number}
|
|
112
|
-
* @param {number}
|
|
113
|
-
* @returns {HandshakeKeys}
|
|
100
|
+
* @param {HashAlgorithm} alg - Hash algorithm.
|
|
101
|
+
* @param {Buffer} sharedSecret - ECDHE shared secret.
|
|
102
|
+
* @param {Buffer} helloHash - Transcript hash up to and including ServerHello.
|
|
103
|
+
* @param {number} keyLen - Desired key length in bytes.
|
|
104
|
+
* @param {number} ivLen - Desired IV length in bytes.
|
|
105
|
+
* @returns {HandshakeKeys} Handshake keys and intermediate secrets.
|
|
114
106
|
*/
|
|
115
107
|
export function deriveHandshakeKeys(alg, sharedSecret, helloHash, keyLen, ivLen) {
|
|
116
108
|
const earlySecret = hkdfExtract(alg, Buffer.alloc(hashLength(alg)), zeroKey(alg));
|
|
@@ -134,16 +126,14 @@ export function deriveHandshakeKeys(alg, sharedSecret, helloHash, keyLen, ivLen)
|
|
|
134
126
|
};
|
|
135
127
|
}
|
|
136
128
|
/**
|
|
137
|
-
*
|
|
138
|
-
* full handshake transcript hash (RFC 8446 §7.1). These keys are used to
|
|
139
|
-
* encrypt and decrypt all application data after the handshake completes.
|
|
129
|
+
* Derive TLS 1.3 application traffic keys from the master secret.
|
|
140
130
|
*
|
|
141
|
-
* @param {HashAlgorithm} alg
|
|
142
|
-
* @param {Buffer}
|
|
143
|
-
* @param {Buffer}
|
|
144
|
-
* @param {number}
|
|
145
|
-
* @param {number}
|
|
146
|
-
* @returns {ApplicationKeys}
|
|
131
|
+
* @param {HashAlgorithm} alg - Hash algorithm.
|
|
132
|
+
* @param {Buffer} masterSecret - Master secret from the key schedule.
|
|
133
|
+
* @param {Buffer} handshakeHash - Transcript hash up to and including server Finished.
|
|
134
|
+
* @param {number} keyLen - Desired key length in bytes.
|
|
135
|
+
* @param {number} ivLen - Desired IV length in bytes.
|
|
136
|
+
* @returns {ApplicationKeys} Application traffic encryption keys.
|
|
147
137
|
*/
|
|
148
138
|
export function deriveApplicationKeys(alg, masterSecret, handshakeHash, keyLen, ivLen) {
|
|
149
139
|
const clientSecret = deriveSecret(alg, masterSecret, "c ap traffic", handshakeHash);
|
|
@@ -159,14 +149,12 @@ function emptyHash(alg) {
|
|
|
159
149
|
return _createHash(alg).digest();
|
|
160
150
|
}
|
|
161
151
|
/**
|
|
162
|
-
*
|
|
163
|
-
* as `HMAC(finished_key, transcript_hash)`, where `finished_key` is derived
|
|
164
|
-
* from the base traffic secret using HKDF-Expand-Label.
|
|
152
|
+
* Compute the Finished verify_data for the TLS 1.3 handshake.
|
|
165
153
|
*
|
|
166
|
-
* @param {HashAlgorithm} alg
|
|
167
|
-
* @param {Buffer}
|
|
168
|
-
* @param {Buffer}
|
|
169
|
-
* @returns {Buffer}
|
|
154
|
+
* @param {HashAlgorithm} alg - Hash algorithm.
|
|
155
|
+
* @param {Buffer} baseSecret - Handshake traffic secret.
|
|
156
|
+
* @param {Buffer} transcriptHash - Current transcript hash.
|
|
157
|
+
* @returns {Buffer} HMAC verify data bytes.
|
|
170
158
|
*/
|
|
171
159
|
export function computeFinishedVerifyData(alg, baseSecret, transcriptHash) {
|
|
172
160
|
const finishedKey = hkdfExpandLabel(alg, baseSecret, "finished", Buffer.alloc(0), hashLength(alg));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"key-schedule.js","sourceRoot":"","sources":["../../../src/tls/stealth/key-schedule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,UAAU,IAAI,WAAW,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"key-schedule.js","sourceRoot":"","sources":["../../../src/tls/stealth/key-schedule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,UAAU,IAAI,WAAW,EAAE,MAAM,aAAa,CAAC;AAKpE;;;;;GAKG;AACH,MAAM,UAAU,UAAU,CAAC,GAAkB;IAC3C,OAAO,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;AACpC,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,WAAW,CAAC,GAAkB,EAAE,IAAY,EAAE,GAAW;IACvE,OAAO,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,MAAM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,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC;KAC3E,CAAC;AACJ,CAAC;AAED,SAAS,SAAS,CAAC,GAAkB;IACnC,OAAO,WAAW,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC;AACnC,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,yBAAyB,CAAC,GAAkB,EAAE,UAAkB,EAAE,cAAsB;IACtG,MAAM,WAAW,GAAG,eAAe,CAAC,GAAG,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC;IACnG,OAAO,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,EAAE,WAAW,CAAC,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC;AACnF,CAAC"}
|
|
@@ -1,122 +1,99 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A single parsed TLS record as defined in RFC 8446 ¥5.1.
|
|
3
|
-
*
|
|
4
|
-
* @typedef {Object} TLSRecord
|
|
5
|
-
* @property {number} type - Content type byte (see {@link RecordType}).
|
|
6
|
-
* @property {number} version - Legacy record version (e.g. `0x0303` for TLS 1.2 compatibility).
|
|
7
|
-
* @property {Buffer} fragment - Raw payload bytes of the record.
|
|
8
|
-
*/
|
|
1
|
+
/** Parsed TLS record with type, version, and payload fragment. */
|
|
9
2
|
export interface TLSRecord {
|
|
3
|
+
/** Record content type. */
|
|
10
4
|
type: number;
|
|
5
|
+
/** Protocol version from the record header. */
|
|
11
6
|
version: number;
|
|
7
|
+
/** Record payload bytes. */
|
|
12
8
|
fragment: Buffer;
|
|
13
9
|
}
|
|
14
10
|
/**
|
|
15
|
-
*
|
|
16
|
-
* Returns `null` without consuming the buffer if fewer than 5 bytes are
|
|
17
|
-
* available or the payload has not been fully received yet.
|
|
11
|
+
* Read a single TLS record from a buffer at the given offset.
|
|
18
12
|
*
|
|
19
|
-
* @param {Buffer} data
|
|
20
|
-
* @param {number} offset - Byte offset
|
|
21
|
-
* @returns {{ record: TLSRecord; bytesRead: number } | null} Parsed record and
|
|
13
|
+
* @param {Buffer} data - Buffer containing one or more TLS records.
|
|
14
|
+
* @param {number} offset - Byte offset to start reading from.
|
|
15
|
+
* @returns {{ record: TLSRecord; bytesRead: number } | null} Parsed record and bytes consumed, or `null` if incomplete.
|
|
22
16
|
*/
|
|
23
17
|
export declare function readRecord(data: Buffer, offset: number): {
|
|
24
18
|
record: TLSRecord;
|
|
25
19
|
bytesRead: number;
|
|
26
20
|
} | null;
|
|
27
21
|
/**
|
|
28
|
-
*
|
|
22
|
+
* Write a TLS record with the given type, version, and payload.
|
|
29
23
|
*
|
|
30
|
-
* @param {number} type
|
|
31
|
-
* @param {number} version -
|
|
32
|
-
* @param {Buffer} payload - Record payload
|
|
33
|
-
* @returns {Buffer}
|
|
24
|
+
* @param {number} type - Record content type.
|
|
25
|
+
* @param {number} version - Protocol version.
|
|
26
|
+
* @param {Buffer} payload - Record payload.
|
|
27
|
+
* @returns {Buffer} Serialized TLS record buffer.
|
|
34
28
|
*/
|
|
35
29
|
export declare function writeRecord(type: number, version: number, payload: Buffer): Buffer;
|
|
36
|
-
/**
|
|
37
|
-
* AEAD algorithm identifiers supported by the record layer. Corresponds to
|
|
38
|
-
* the TLS 1.3 mandatory cipher suites.
|
|
39
|
-
*
|
|
40
|
-
* @typedef {'aes-128-gcm'|'aes-256-gcm'|'chacha20-poly1305'} AEADAlgorithm
|
|
41
|
-
*/
|
|
30
|
+
/** AEAD algorithm identifiers for TLS record encryption. */
|
|
42
31
|
export type AEADAlgorithm = "aes-128-gcm" | "aes-256-gcm" | "chacha20-poly1305";
|
|
43
32
|
/**
|
|
44
|
-
*
|
|
45
|
-
* identifier used by the record layer.
|
|
33
|
+
* Determine the AEAD algorithm from a cipher suite name.
|
|
46
34
|
*
|
|
47
|
-
* @param {string} cipherName - Cipher suite
|
|
48
|
-
* @returns {AEADAlgorithm}
|
|
49
|
-
* @throws {TLSError} If the cipher name does not correspond to a supported AEAD algorithm.
|
|
35
|
+
* @param {string} cipherName - Cipher suite or algorithm name.
|
|
36
|
+
* @returns {AEADAlgorithm} Corresponding AEAD algorithm identifier.
|
|
50
37
|
*/
|
|
51
38
|
export declare function aeadFromCipher(cipherName: string): AEADAlgorithm;
|
|
52
39
|
/**
|
|
53
|
-
*
|
|
54
|
-
* big-endian 64-bit sequence number (RFC 8446 ¥5.3).
|
|
40
|
+
* Build a per-record nonce by XORing the IV with a sequence number.
|
|
55
41
|
*
|
|
56
|
-
* @param {Buffer} iv
|
|
57
|
-
* @param {bigint} sequenceNumber - Record sequence number
|
|
58
|
-
* @returns {Buffer}
|
|
42
|
+
* @param {Buffer} iv - Base initialization vector.
|
|
43
|
+
* @param {bigint} sequenceNumber - Record sequence number.
|
|
44
|
+
* @returns {Buffer} Nonce buffer for AEAD encryption.
|
|
59
45
|
*/
|
|
60
46
|
export declare function buildNonce(iv: Buffer, sequenceNumber: bigint): Buffer;
|
|
61
47
|
/**
|
|
62
|
-
*
|
|
63
|
-
* ciphertext with an appended 16-byte authentication tag.
|
|
48
|
+
* Encrypt a TLS record payload using AEAD.
|
|
64
49
|
*
|
|
65
|
-
* @param {AEADAlgorithm} algorithm
|
|
66
|
-
* @param {Buffer}
|
|
67
|
-
* @param {Buffer}
|
|
68
|
-
* @param {Buffer}
|
|
69
|
-
* @param {Buffer}
|
|
70
|
-
* @returns {Buffer} Ciphertext
|
|
50
|
+
* @param {AEADAlgorithm} algorithm - AEAD algorithm.
|
|
51
|
+
* @param {Buffer} key - Encryption key.
|
|
52
|
+
* @param {Buffer} nonce - Per-record nonce.
|
|
53
|
+
* @param {Buffer} plaintext - Plaintext payload.
|
|
54
|
+
* @param {Buffer} additionalData - Associated data for authentication.
|
|
55
|
+
* @returns {Buffer} Ciphertext with appended authentication tag.
|
|
71
56
|
*/
|
|
72
57
|
export declare function encryptRecord(algorithm: AEADAlgorithm, key: Buffer, nonce: Buffer, plaintext: Buffer, additionalData: Buffer): Buffer;
|
|
73
58
|
/**
|
|
74
|
-
*
|
|
75
|
-
* The last 16 bytes of `ciphertext` are treated as the authentication tag.
|
|
59
|
+
* Decrypt a TLS record payload using AEAD.
|
|
76
60
|
*
|
|
77
|
-
* @param {AEADAlgorithm} algorithm
|
|
78
|
-
* @param {Buffer}
|
|
79
|
-
* @param {Buffer}
|
|
80
|
-
* @param {Buffer}
|
|
81
|
-
* @param {Buffer}
|
|
82
|
-
* @returns {Buffer} Decrypted plaintext
|
|
83
|
-
* @throws {TLSError} If the ciphertext is too short or authentication fails.
|
|
61
|
+
* @param {AEADAlgorithm} algorithm - AEAD algorithm.
|
|
62
|
+
* @param {Buffer} key - Decryption key.
|
|
63
|
+
* @param {Buffer} nonce - Per-record nonce.
|
|
64
|
+
* @param {Buffer} ciphertext - Ciphertext with authentication tag.
|
|
65
|
+
* @param {Buffer} additionalData - Associated data for verification.
|
|
66
|
+
* @returns {Buffer} Decrypted plaintext.
|
|
84
67
|
*/
|
|
85
68
|
export declare function decryptRecord(algorithm: AEADAlgorithm, key: Buffer, nonce: Buffer, ciphertext: Buffer, additionalData: Buffer): Buffer;
|
|
86
69
|
/**
|
|
87
|
-
*
|
|
88
|
-
* data record, encoded as a 5-byte pseudo-record header per RFC 8446 ¥5.2.
|
|
70
|
+
* Build the additional authenticated data (AAD) for a TLS 1.3 record.
|
|
89
71
|
*
|
|
90
|
-
* @param {number} ciphertextLength -
|
|
72
|
+
* @param {number} ciphertextLength - Length of the ciphertext including the tag.
|
|
91
73
|
* @returns {Buffer} 5-byte AAD buffer.
|
|
92
74
|
*/
|
|
93
75
|
export declare function buildAdditionalData(ciphertextLength: number): Buffer;
|
|
94
76
|
/**
|
|
95
|
-
*
|
|
96
|
-
* wraps it in an encrypted TLS record with the appropriate AAD, following
|
|
97
|
-
* RFC 8446 ¥5.2.
|
|
77
|
+
* Encrypt and wrap a plaintext payload into a TLS 1.3 application data record.
|
|
98
78
|
*
|
|
99
|
-
* @param {AEADAlgorithm} algorithm
|
|
100
|
-
* @param {Buffer}
|
|
101
|
-
* @param {Buffer}
|
|
102
|
-
* @param {bigint}
|
|
103
|
-
* @param {number}
|
|
104
|
-
* @param {Buffer}
|
|
105
|
-
* @returns {Buffer}
|
|
79
|
+
* @param {AEADAlgorithm} algorithm - AEAD algorithm.
|
|
80
|
+
* @param {Buffer} key - Client write key.
|
|
81
|
+
* @param {Buffer} iv - Client write IV.
|
|
82
|
+
* @param {bigint} sequenceNumber - Current sequence number.
|
|
83
|
+
* @param {number} contentType - Inner record content type.
|
|
84
|
+
* @param {Buffer} plaintext - Plaintext payload.
|
|
85
|
+
* @returns {Buffer} Serialized encrypted TLS record.
|
|
106
86
|
*/
|
|
107
87
|
export declare function wrapEncryptedRecord(algorithm: AEADAlgorithm, key: Buffer, iv: Buffer, sequenceNumber: bigint, contentType: number, plaintext: Buffer): Buffer;
|
|
108
88
|
/**
|
|
109
|
-
*
|
|
110
|
-
* recovers the true content type embedded as the last non-zero byte of the
|
|
111
|
-
* inner plaintext (RFC 8446 ¥5.2).
|
|
89
|
+
* Decrypt and unwrap a TLS 1.3 encrypted record.
|
|
112
90
|
*
|
|
113
|
-
* @param {AEADAlgorithm} algorithm
|
|
114
|
-
* @param {Buffer}
|
|
115
|
-
* @param {Buffer}
|
|
116
|
-
* @param {bigint}
|
|
117
|
-
* @param {TLSRecord}
|
|
118
|
-
* @returns {{ contentType: number; plaintext: Buffer }}
|
|
119
|
-
* @throws {TLSError} If decryption or authentication fails, or the record is empty after unpadding.
|
|
91
|
+
* @param {AEADAlgorithm} algorithm - AEAD algorithm.
|
|
92
|
+
* @param {Buffer} key - Server write key.
|
|
93
|
+
* @param {Buffer} iv - Server write IV.
|
|
94
|
+
* @param {bigint} sequenceNumber - Current sequence number.
|
|
95
|
+
* @param {TLSRecord} record - Encrypted TLS record.
|
|
96
|
+
* @returns {{ contentType: number; plaintext: Buffer }} Decrypted content type and plaintext.
|
|
120
97
|
*/
|
|
121
98
|
export declare function unwrapEncryptedRecord(algorithm: AEADAlgorithm, key: Buffer, iv: Buffer, sequenceNumber: bigint, record: TLSRecord): {
|
|
122
99
|
contentType: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"record-layer.d.ts","sourceRoot":"","sources":["../../../src/tls/stealth/record-layer.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"record-layer.d.ts","sourceRoot":"","sources":["../../../src/tls/stealth/record-layer.ts"],"names":[],"mappings":"AAKA,kEAAkE;AAClE,MAAM,WAAW,SAAS;IACxB,2BAA2B;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,+CAA+C;IAC/C,OAAO,EAAE,MAAM,CAAC;IAChB,4BAA4B;IAC5B,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG;IAAE,MAAM,EAAE,SAAS,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAexG;AAED;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAOlF;AAED,4DAA4D;AAC5D,MAAM,MAAM,aAAa,GAAG,aAAa,GAAG,aAAa,GAAG,mBAAmB,CAAC;AAEhF;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,UAAU,EAAE,MAAM,GAAG,aAAa,CAWhE;AAID;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,EAAE,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,GAAG,MAAM,CAQrE;AAED;;;;;;;;;GASG;AACH,wBAAgB,aAAa,CAAC,SAAS,EAAE,aAAa,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,GAAG,MAAM,CAOrI;AAED;;;;;;;;;GASG;AACH,wBAAgB,aAAa,CAAC,SAAS,EAAE,aAAa,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,GAAG,MAAM,CAkBtI;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,gBAAgB,EAAE,MAAM,GAAG,MAAM,CAMpE;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,mBAAmB,CAAC,SAAS,EAAE,aAAa,EAAE,GAAG,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAW7J;AAED;;;;;;;;;GASG;AACH,wBAAgB,qBAAqB,CAAC,SAAS,EAAE,aAAa,EAAE,GAAG,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,GAAG;IAAE,WAAW,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,CAe9K"}
|
|
@@ -2,16 +2,12 @@ import { createCipheriv, createDecipheriv } from "node:crypto";
|
|
|
2
2
|
import { BufferWriter } from "../../utils/buffer-writer.js";
|
|
3
3
|
import { RecordType, ProtocolVersion } from "../constants.js";
|
|
4
4
|
import { TLSError } from "../../core/errors.js";
|
|
5
|
-
const MAX_RECORD_PAYLOAD = 16384;
|
|
6
|
-
const MAX_CIPHERTEXT_OVERHEAD = 256;
|
|
7
5
|
/**
|
|
8
|
-
*
|
|
9
|
-
* Returns `null` without consuming the buffer if fewer than 5 bytes are
|
|
10
|
-
* available or the payload has not been fully received yet.
|
|
6
|
+
* Read a single TLS record from a buffer at the given offset.
|
|
11
7
|
*
|
|
12
|
-
* @param {Buffer} data
|
|
13
|
-
* @param {number} offset - Byte offset
|
|
14
|
-
* @returns {{ record: TLSRecord; bytesRead: number } | null} Parsed record and
|
|
8
|
+
* @param {Buffer} data - Buffer containing one or more TLS records.
|
|
9
|
+
* @param {number} offset - Byte offset to start reading from.
|
|
10
|
+
* @returns {{ record: TLSRecord; bytesRead: number } | null} Parsed record and bytes consumed, or `null` if incomplete.
|
|
15
11
|
*/
|
|
16
12
|
export function readRecord(data, offset) {
|
|
17
13
|
if (data.length - offset < 5)
|
|
@@ -28,12 +24,12 @@ export function readRecord(data, offset) {
|
|
|
28
24
|
};
|
|
29
25
|
}
|
|
30
26
|
/**
|
|
31
|
-
*
|
|
27
|
+
* Write a TLS record with the given type, version, and payload.
|
|
32
28
|
*
|
|
33
|
-
* @param {number} type
|
|
34
|
-
* @param {number} version -
|
|
35
|
-
* @param {Buffer} payload - Record payload
|
|
36
|
-
* @returns {Buffer}
|
|
29
|
+
* @param {number} type - Record content type.
|
|
30
|
+
* @param {number} version - Protocol version.
|
|
31
|
+
* @param {Buffer} payload - Record payload.
|
|
32
|
+
* @returns {Buffer} Serialized TLS record buffer.
|
|
37
33
|
*/
|
|
38
34
|
export function writeRecord(type, version, payload) {
|
|
39
35
|
const w = new BufferWriter(5 + payload.length);
|
|
@@ -44,12 +40,10 @@ export function writeRecord(type, version, payload) {
|
|
|
44
40
|
return w.toBuffer();
|
|
45
41
|
}
|
|
46
42
|
/**
|
|
47
|
-
*
|
|
48
|
-
* identifier used by the record layer.
|
|
43
|
+
* Determine the AEAD algorithm from a cipher suite name.
|
|
49
44
|
*
|
|
50
|
-
* @param {string} cipherName - Cipher suite
|
|
51
|
-
* @returns {AEADAlgorithm}
|
|
52
|
-
* @throws {TLSError} If the cipher name does not correspond to a supported AEAD algorithm.
|
|
45
|
+
* @param {string} cipherName - Cipher suite or algorithm name.
|
|
46
|
+
* @returns {AEADAlgorithm} Corresponding AEAD algorithm identifier.
|
|
53
47
|
*/
|
|
54
48
|
export function aeadFromCipher(cipherName) {
|
|
55
49
|
if (cipherName.includes("AES_128_GCM") || cipherName.includes("aes-128-gcm")) {
|
|
@@ -65,12 +59,11 @@ export function aeadFromCipher(cipherName) {
|
|
|
65
59
|
}
|
|
66
60
|
const TAG_SIZE = 16;
|
|
67
61
|
/**
|
|
68
|
-
*
|
|
69
|
-
* big-endian 64-bit sequence number (RFC 8446 ¥5.3).
|
|
62
|
+
* Build a per-record nonce by XORing the IV with a sequence number.
|
|
70
63
|
*
|
|
71
|
-
* @param {Buffer} iv
|
|
72
|
-
* @param {bigint} sequenceNumber - Record sequence number
|
|
73
|
-
* @returns {Buffer}
|
|
64
|
+
* @param {Buffer} iv - Base initialization vector.
|
|
65
|
+
* @param {bigint} sequenceNumber - Record sequence number.
|
|
66
|
+
* @returns {Buffer} Nonce buffer for AEAD encryption.
|
|
74
67
|
*/
|
|
75
68
|
export function buildNonce(iv, sequenceNumber) {
|
|
76
69
|
const nonce = Buffer.from(iv);
|
|
@@ -82,15 +75,14 @@ export function buildNonce(iv, sequenceNumber) {
|
|
|
82
75
|
return nonce;
|
|
83
76
|
}
|
|
84
77
|
/**
|
|
85
|
-
*
|
|
86
|
-
* ciphertext with an appended 16-byte authentication tag.
|
|
78
|
+
* Encrypt a TLS record payload using AEAD.
|
|
87
79
|
*
|
|
88
|
-
* @param {AEADAlgorithm} algorithm
|
|
89
|
-
* @param {Buffer}
|
|
90
|
-
* @param {Buffer}
|
|
91
|
-
* @param {Buffer}
|
|
92
|
-
* @param {Buffer}
|
|
93
|
-
* @returns {Buffer} Ciphertext
|
|
80
|
+
* @param {AEADAlgorithm} algorithm - AEAD algorithm.
|
|
81
|
+
* @param {Buffer} key - Encryption key.
|
|
82
|
+
* @param {Buffer} nonce - Per-record nonce.
|
|
83
|
+
* @param {Buffer} plaintext - Plaintext payload.
|
|
84
|
+
* @param {Buffer} additionalData - Associated data for authentication.
|
|
85
|
+
* @returns {Buffer} Ciphertext with appended authentication tag.
|
|
94
86
|
*/
|
|
95
87
|
export function encryptRecord(algorithm, key, nonce, plaintext, additionalData) {
|
|
96
88
|
const cipher = createCipheriv(algorithm, key, nonce, { authTagLength: TAG_SIZE });
|
|
@@ -101,16 +93,14 @@ export function encryptRecord(algorithm, key, nonce, plaintext, additionalData)
|
|
|
101
93
|
return Buffer.concat([encrypted, final, tag]);
|
|
102
94
|
}
|
|
103
95
|
/**
|
|
104
|
-
*
|
|
105
|
-
* The last 16 bytes of `ciphertext` are treated as the authentication tag.
|
|
96
|
+
* Decrypt a TLS record payload using AEAD.
|
|
106
97
|
*
|
|
107
|
-
* @param {AEADAlgorithm} algorithm
|
|
108
|
-
* @param {Buffer}
|
|
109
|
-
* @param {Buffer}
|
|
110
|
-
* @param {Buffer}
|
|
111
|
-
* @param {Buffer}
|
|
112
|
-
* @returns {Buffer} Decrypted plaintext
|
|
113
|
-
* @throws {TLSError} If the ciphertext is too short or authentication fails.
|
|
98
|
+
* @param {AEADAlgorithm} algorithm - AEAD algorithm.
|
|
99
|
+
* @param {Buffer} key - Decryption key.
|
|
100
|
+
* @param {Buffer} nonce - Per-record nonce.
|
|
101
|
+
* @param {Buffer} ciphertext - Ciphertext with authentication tag.
|
|
102
|
+
* @param {Buffer} additionalData - Associated data for verification.
|
|
103
|
+
* @returns {Buffer} Decrypted plaintext.
|
|
114
104
|
*/
|
|
115
105
|
export function decryptRecord(algorithm, key, nonce, ciphertext, additionalData) {
|
|
116
106
|
if (ciphertext.length < TAG_SIZE) {
|
|
@@ -131,10 +121,9 @@ export function decryptRecord(algorithm, key, nonce, ciphertext, additionalData)
|
|
|
131
121
|
}
|
|
132
122
|
}
|
|
133
123
|
/**
|
|
134
|
-
*
|
|
135
|
-
* data record, encoded as a 5-byte pseudo-record header per RFC 8446 ¥5.2.
|
|
124
|
+
* Build the additional authenticated data (AAD) for a TLS 1.3 record.
|
|
136
125
|
*
|
|
137
|
-
* @param {number} ciphertextLength -
|
|
126
|
+
* @param {number} ciphertextLength - Length of the ciphertext including the tag.
|
|
138
127
|
* @returns {Buffer} 5-byte AAD buffer.
|
|
139
128
|
*/
|
|
140
129
|
export function buildAdditionalData(ciphertextLength) {
|
|
@@ -145,17 +134,15 @@ export function buildAdditionalData(ciphertextLength) {
|
|
|
145
134
|
return w.toBuffer();
|
|
146
135
|
}
|
|
147
136
|
/**
|
|
148
|
-
*
|
|
149
|
-
* wraps it in an encrypted TLS record with the appropriate AAD, following
|
|
150
|
-
* RFC 8446 ¥5.2.
|
|
137
|
+
* Encrypt and wrap a plaintext payload into a TLS 1.3 application data record.
|
|
151
138
|
*
|
|
152
|
-
* @param {AEADAlgorithm} algorithm
|
|
153
|
-
* @param {Buffer}
|
|
154
|
-
* @param {Buffer}
|
|
155
|
-
* @param {bigint}
|
|
156
|
-
* @param {number}
|
|
157
|
-
* @param {Buffer}
|
|
158
|
-
* @returns {Buffer}
|
|
139
|
+
* @param {AEADAlgorithm} algorithm - AEAD algorithm.
|
|
140
|
+
* @param {Buffer} key - Client write key.
|
|
141
|
+
* @param {Buffer} iv - Client write IV.
|
|
142
|
+
* @param {bigint} sequenceNumber - Current sequence number.
|
|
143
|
+
* @param {number} contentType - Inner record content type.
|
|
144
|
+
* @param {Buffer} plaintext - Plaintext payload.
|
|
145
|
+
* @returns {Buffer} Serialized encrypted TLS record.
|
|
159
146
|
*/
|
|
160
147
|
export function wrapEncryptedRecord(algorithm, key, iv, sequenceNumber, contentType, plaintext) {
|
|
161
148
|
const inner = Buffer.alloc(plaintext.length + 1);
|
|
@@ -168,17 +155,14 @@ export function wrapEncryptedRecord(algorithm, key, iv, sequenceNumber, contentT
|
|
|
168
155
|
return writeRecord(RecordType.APPLICATION_DATA, ProtocolVersion.TLS_1_2, ciphertext);
|
|
169
156
|
}
|
|
170
157
|
/**
|
|
171
|
-
*
|
|
172
|
-
* recovers the true content type embedded as the last non-zero byte of the
|
|
173
|
-
* inner plaintext (RFC 8446 ¥5.2).
|
|
158
|
+
* Decrypt and unwrap a TLS 1.3 encrypted record.
|
|
174
159
|
*
|
|
175
|
-
* @param {AEADAlgorithm} algorithm
|
|
176
|
-
* @param {Buffer}
|
|
177
|
-
* @param {Buffer}
|
|
178
|
-
* @param {bigint}
|
|
179
|
-
* @param {TLSRecord}
|
|
180
|
-
* @returns {{ contentType: number; plaintext: Buffer }}
|
|
181
|
-
* @throws {TLSError} If decryption or authentication fails, or the record is empty after unpadding.
|
|
160
|
+
* @param {AEADAlgorithm} algorithm - AEAD algorithm.
|
|
161
|
+
* @param {Buffer} key - Server write key.
|
|
162
|
+
* @param {Buffer} iv - Server write IV.
|
|
163
|
+
* @param {bigint} sequenceNumber - Current sequence number.
|
|
164
|
+
* @param {TLSRecord} record - Encrypted TLS record.
|
|
165
|
+
* @returns {{ contentType: number; plaintext: Buffer }} Decrypted content type and plaintext.
|
|
182
166
|
*/
|
|
183
167
|
export function unwrapEncryptedRecord(algorithm, key, iv, sequenceNumber, record) {
|
|
184
168
|
const nonce = buildNonce(iv, sequenceNumber);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"record-layer.js","sourceRoot":"","sources":["../../../src/tls/stealth/record-layer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAuB,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"record-layer.js","sourceRoot":"","sources":["../../../src/tls/stealth/record-layer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAuB,MAAM,aAAa,CAAC;AACpF,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAC9D,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAYhD;;;;;;GAMG;AACH,MAAM,UAAU,UAAU,CAAC,IAAY,EAAE,MAAc;IACrD,IAAI,IAAI,CAAC,MAAM,GAAG,MAAM,GAAG,CAAC;QAAE,OAAO,IAAI,CAAC;IAE1C,MAA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G,aAAa,CAAC,SAAS,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;IAEzE,IAAI,CAAC,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC;IACzB,OAAO,CAAC,IAAI,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC;QAAE,CAAC,EAAE,CAAC;IACrC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;QACV,MAAM,IAAI,QAAQ,CAAC,wBAAwB,CAAC,CAAC;IAC/C,CAAC;IAED,MAAM,WAAW,GAAG,KAAK,CAAC,CAAC,CAAE,CAAC;IAC9B,MAAM,SAAS,GAAG,KAAK,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAEvC,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,CAAC;AACpC,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import * as net from "node:net";
|
|
2
|
+
import type { KeyShareEntry } from "./client-hello.js";
|
|
3
|
+
import type { HandshakeResult } from "./handshake.js";
|
|
4
|
+
/** Context state for a TLS 1.2 handshake. */
|
|
5
|
+
export interface TLS12HandshakeContext {
|
|
6
|
+
/** Client random bytes from the ClientHello. */
|
|
7
|
+
clientRandom: Buffer;
|
|
8
|
+
/** Server random bytes from the ServerHello. */
|
|
9
|
+
serverRandom: Buffer;
|
|
10
|
+
/** Negotiated cipher suite identifier. */
|
|
11
|
+
cipherSuite: number;
|
|
12
|
+
/** Key share entries generated during ClientHello construction. */
|
|
13
|
+
keyShares: KeyShareEntry[];
|
|
14
|
+
/** Server hostname for SNI and certificate verification. */
|
|
15
|
+
hostname: string;
|
|
16
|
+
/** Skip certificate chain validation. */
|
|
17
|
+
insecure: boolean;
|
|
18
|
+
/** Optional SPKI pin(s) for public-key pinning. */
|
|
19
|
+
pinnedPublicKey?: string | string[];
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Complete a TLS 1.2 handshake using ECDHE key exchange.
|
|
23
|
+
*
|
|
24
|
+
* @param {net.Socket} socket - Connected TCP socket.
|
|
25
|
+
* @param {TLS12HandshakeContext} ctx - Handshake context from the ServerHello.
|
|
26
|
+
* @param {Buffer[]} handshakeMessages - Accumulated handshake messages so far.
|
|
27
|
+
* @returns {Promise<HandshakeResult>} Handshake result with negotiated keys and metadata.
|
|
28
|
+
*/
|
|
29
|
+
export declare function performTLS12Handshake(socket: net.Socket, ctx: TLS12HandshakeContext, handshakeMessages: Buffer[]): Promise<HandshakeResult>;
|
|
30
|
+
//# sourceMappingURL=tls12-handshake.d.ts.map
|