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.
Files changed (354) hide show
  1. package/README.md +143 -140
  2. package/dist/cache/groups.d.ts +75 -0
  3. package/dist/cache/groups.d.ts.map +1 -0
  4. package/dist/cache/groups.js +118 -0
  5. package/dist/cache/groups.js.map +1 -0
  6. package/dist/cache/no-vary-search.d.ts +33 -0
  7. package/dist/cache/no-vary-search.d.ts.map +1 -0
  8. package/dist/cache/no-vary-search.js +148 -0
  9. package/dist/cache/no-vary-search.js.map +1 -0
  10. package/dist/cache/range.d.ts +120 -0
  11. package/dist/cache/range.d.ts.map +1 -0
  12. package/dist/cache/range.js +193 -0
  13. package/dist/cache/range.js.map +1 -0
  14. package/dist/cache/store.d.ts +111 -0
  15. package/dist/cache/store.d.ts.map +1 -0
  16. package/dist/cache/store.js +414 -0
  17. package/dist/cache/store.js.map +1 -0
  18. package/dist/cache/types.d.ts +69 -0
  19. package/dist/cache/types.d.ts.map +1 -0
  20. package/dist/cache/types.js +2 -0
  21. package/dist/cache/types.js.map +1 -0
  22. package/dist/cli/args.d.ts +4 -37
  23. package/dist/cli/args.d.ts.map +1 -1
  24. package/dist/cli/args.js +3 -4
  25. package/dist/cli/args.js.map +1 -1
  26. package/dist/cli/index.d.ts +0 -5
  27. package/dist/cli/index.d.ts.map +1 -1
  28. package/dist/cli/index.js +1 -6
  29. package/dist/cli/index.js.map +1 -1
  30. package/dist/cli/output.d.ts +14 -20
  31. package/dist/cli/output.d.ts.map +1 -1
  32. package/dist/cli/output.js +14 -20
  33. package/dist/cli/output.js.map +1 -1
  34. package/dist/cookies/jar.d.ts +33 -31
  35. package/dist/cookies/jar.d.ts.map +1 -1
  36. package/dist/cookies/jar.js +69 -33
  37. package/dist/cookies/jar.js.map +1 -1
  38. package/dist/cookies/parser.d.ts +14 -16
  39. package/dist/cookies/parser.d.ts.map +1 -1
  40. package/dist/cookies/parser.js +30 -13
  41. package/dist/cookies/parser.js.map +1 -1
  42. package/dist/cookies/psl-data.d.ts +1 -1
  43. package/dist/cookies/psl-data.js +1 -1
  44. package/dist/cookies/public-suffix.d.ts +5 -27
  45. package/dist/cookies/public-suffix.d.ts.map +1 -1
  46. package/dist/cookies/public-suffix.js +5 -37
  47. package/dist/cookies/public-suffix.js.map +1 -1
  48. package/dist/core/auth.d.ts +30 -0
  49. package/dist/core/auth.d.ts.map +1 -0
  50. package/dist/core/auth.js +34 -0
  51. package/dist/core/auth.js.map +1 -0
  52. package/dist/core/client.d.ts +28 -40
  53. package/dist/core/client.d.ts.map +1 -1
  54. package/dist/core/client.js +34 -41
  55. package/dist/core/client.js.map +1 -1
  56. package/dist/core/errors.d.ts +64 -88
  57. package/dist/core/errors.d.ts.map +1 -1
  58. package/dist/core/errors.js +64 -88
  59. package/dist/core/errors.js.map +1 -1
  60. package/dist/core/request.d.ts +63 -85
  61. package/dist/core/request.d.ts.map +1 -1
  62. package/dist/core/response.d.ts +64 -59
  63. package/dist/core/response.d.ts.map +1 -1
  64. package/dist/core/response.js +70 -52
  65. package/dist/core/response.js.map +1 -1
  66. package/dist/core/session.d.ts +81 -70
  67. package/dist/core/session.d.ts.map +1 -1
  68. package/dist/core/session.js +198 -71
  69. package/dist/core/session.js.map +1 -1
  70. package/dist/core/validation.d.ts +44 -42
  71. package/dist/core/validation.d.ts.map +1 -1
  72. package/dist/core/validation.js +47 -58
  73. package/dist/core/validation.js.map +1 -1
  74. package/dist/dns/cache.d.ts +59 -0
  75. package/dist/dns/cache.d.ts.map +1 -0
  76. package/dist/dns/cache.js +99 -0
  77. package/dist/dns/cache.js.map +1 -0
  78. package/dist/dns/codec.d.ts +39 -0
  79. package/dist/dns/codec.d.ts.map +1 -0
  80. package/dist/dns/codec.js +238 -0
  81. package/dist/dns/codec.js.map +1 -0
  82. package/dist/dns/doh-resolver.d.ts +38 -0
  83. package/dist/dns/doh-resolver.d.ts.map +1 -0
  84. package/dist/dns/doh-resolver.js +191 -0
  85. package/dist/dns/doh-resolver.js.map +1 -0
  86. package/dist/dns/dot-resolver.d.ts +89 -0
  87. package/dist/dns/dot-resolver.d.ts.map +1 -0
  88. package/dist/dns/dot-resolver.js +158 -0
  89. package/dist/dns/dot-resolver.js.map +1 -0
  90. package/dist/dns/https-rr.d.ts +40 -0
  91. package/dist/dns/https-rr.d.ts.map +1 -0
  92. package/dist/dns/https-rr.js +109 -0
  93. package/dist/dns/https-rr.js.map +1 -0
  94. package/dist/dns/types.d.ts +82 -0
  95. package/dist/dns/types.d.ts.map +1 -0
  96. package/dist/dns/types.js +23 -0
  97. package/dist/dns/types.js.map +1 -0
  98. package/dist/fingerprints/akamai.d.ts +3 -11
  99. package/dist/fingerprints/akamai.d.ts.map +1 -1
  100. package/dist/fingerprints/akamai.js +3 -11
  101. package/dist/fingerprints/akamai.js.map +1 -1
  102. package/dist/fingerprints/database.d.ts +6 -14
  103. package/dist/fingerprints/database.d.ts.map +1 -1
  104. package/dist/fingerprints/database.js +6 -14
  105. package/dist/fingerprints/database.js.map +1 -1
  106. package/dist/fingerprints/extensions.d.ts +56 -71
  107. package/dist/fingerprints/extensions.d.ts.map +1 -1
  108. package/dist/fingerprints/extensions.js +58 -71
  109. package/dist/fingerprints/extensions.js.map +1 -1
  110. package/dist/fingerprints/ja3.d.ts +12 -30
  111. package/dist/fingerprints/ja3.d.ts.map +1 -1
  112. package/dist/fingerprints/ja3.js +12 -30
  113. package/dist/fingerprints/ja3.js.map +1 -1
  114. package/dist/fingerprints/ja4.d.ts +18 -0
  115. package/dist/fingerprints/ja4.d.ts.map +1 -0
  116. package/dist/fingerprints/ja4.js +83 -0
  117. package/dist/fingerprints/ja4.js.map +1 -0
  118. package/dist/fingerprints/profiles/chrome.d.ts +18 -21
  119. package/dist/fingerprints/profiles/chrome.d.ts.map +1 -1
  120. package/dist/fingerprints/profiles/chrome.js +35 -31
  121. package/dist/fingerprints/profiles/chrome.js.map +1 -1
  122. package/dist/fingerprints/profiles/edge.d.ts +7 -10
  123. package/dist/fingerprints/profiles/edge.d.ts.map +1 -1
  124. package/dist/fingerprints/profiles/edge.js +7 -10
  125. package/dist/fingerprints/profiles/edge.js.map +1 -1
  126. package/dist/fingerprints/profiles/firefox.d.ts +8 -11
  127. package/dist/fingerprints/profiles/firefox.d.ts.map +1 -1
  128. package/dist/fingerprints/profiles/firefox.js +8 -11
  129. package/dist/fingerprints/profiles/firefox.js.map +1 -1
  130. package/dist/fingerprints/profiles/safari.d.ts +11 -14
  131. package/dist/fingerprints/profiles/safari.d.ts.map +1 -1
  132. package/dist/fingerprints/profiles/safari.js +11 -14
  133. package/dist/fingerprints/profiles/safari.js.map +1 -1
  134. package/dist/fingerprints/profiles/tor.d.ts +5 -8
  135. package/dist/fingerprints/profiles/tor.d.ts.map +1 -1
  136. package/dist/fingerprints/profiles/tor.js +5 -8
  137. package/dist/fingerprints/profiles/tor.js.map +1 -1
  138. package/dist/fingerprints/types.d.ts +42 -73
  139. package/dist/fingerprints/types.d.ts.map +1 -1
  140. package/dist/hsts/store.d.ts +39 -0
  141. package/dist/hsts/store.d.ts.map +1 -0
  142. package/dist/hsts/store.js +163 -0
  143. package/dist/hsts/store.js.map +1 -0
  144. package/dist/hsts/types.d.ts +24 -0
  145. package/dist/hsts/types.d.ts.map +1 -0
  146. package/dist/hsts/types.js +2 -0
  147. package/dist/hsts/types.js.map +1 -0
  148. package/dist/http/alt-svc.d.ts +67 -0
  149. package/dist/http/alt-svc.d.ts.map +1 -0
  150. package/dist/http/alt-svc.js +186 -0
  151. package/dist/http/alt-svc.js.map +1 -0
  152. package/dist/http/early-hints.d.ts +23 -0
  153. package/dist/http/early-hints.d.ts.map +1 -0
  154. package/dist/http/early-hints.js +33 -0
  155. package/dist/http/early-hints.js.map +1 -0
  156. package/dist/http/form-data.d.ts +17 -35
  157. package/dist/http/form-data.d.ts.map +1 -1
  158. package/dist/http/form-data.js +12 -34
  159. package/dist/http/form-data.js.map +1 -1
  160. package/dist/http/h1/client.d.ts +14 -26
  161. package/dist/http/h1/client.d.ts.map +1 -1
  162. package/dist/http/h1/client.js +29 -22
  163. package/dist/http/h1/client.js.map +1 -1
  164. package/dist/http/h1/encoder.d.ts +10 -17
  165. package/dist/http/h1/encoder.d.ts.map +1 -1
  166. package/dist/http/h1/encoder.js +10 -17
  167. package/dist/http/h1/encoder.js.map +1 -1
  168. package/dist/http/h1/parser.d.ts +22 -59
  169. package/dist/http/h1/parser.d.ts.map +1 -1
  170. package/dist/http/h1/parser.js +15 -47
  171. package/dist/http/h1/parser.js.map +1 -1
  172. package/dist/http/h2/client.d.ts +18 -59
  173. package/dist/http/h2/client.d.ts.map +1 -1
  174. package/dist/http/h2/client.js +29 -64
  175. package/dist/http/h2/client.js.map +1 -1
  176. package/dist/http/h2/frames.d.ts +53 -84
  177. package/dist/http/h2/frames.d.ts.map +1 -1
  178. package/dist/http/h2/frames.js +48 -76
  179. package/dist/http/h2/frames.js.map +1 -1
  180. package/dist/http/h2/hpack.d.ts +16 -35
  181. package/dist/http/h2/hpack.d.ts.map +1 -1
  182. package/dist/http/h2/hpack.js +16 -35
  183. package/dist/http/h2/hpack.js.map +1 -1
  184. package/dist/http/h3/detection.d.ts +15 -0
  185. package/dist/http/h3/detection.d.ts.map +1 -0
  186. package/dist/http/h3/detection.js +41 -0
  187. package/dist/http/h3/detection.js.map +1 -0
  188. package/dist/http/negotiator.d.ts +43 -33
  189. package/dist/http/negotiator.d.ts.map +1 -1
  190. package/dist/http/negotiator.js +99 -41
  191. package/dist/http/negotiator.js.map +1 -1
  192. package/dist/http/pool.d.ts +34 -64
  193. package/dist/http/pool.d.ts.map +1 -1
  194. package/dist/http/pool.js +22 -41
  195. package/dist/http/pool.js.map +1 -1
  196. package/dist/http/resumable-upload.d.ts +76 -0
  197. package/dist/http/resumable-upload.d.ts.map +1 -0
  198. package/dist/http/resumable-upload.js +104 -0
  199. package/dist/http/resumable-upload.js.map +1 -0
  200. package/dist/http/trailers.d.ts +29 -0
  201. package/dist/http/trailers.d.ts.map +1 -0
  202. package/dist/http/trailers.js +57 -0
  203. package/dist/http/trailers.js.map +1 -0
  204. package/dist/index.d.ts +36 -8
  205. package/dist/index.d.ts.map +1 -1
  206. package/dist/index.js +32 -1
  207. package/dist/index.js.map +1 -1
  208. package/dist/middleware/interceptor.d.ts +13 -32
  209. package/dist/middleware/interceptor.d.ts.map +1 -1
  210. package/dist/middleware/interceptor.js +11 -16
  211. package/dist/middleware/interceptor.js.map +1 -1
  212. package/dist/middleware/rate-limiter.d.ts +8 -17
  213. package/dist/middleware/rate-limiter.d.ts.map +1 -1
  214. package/dist/middleware/rate-limiter.js +15 -12
  215. package/dist/middleware/rate-limiter.js.map +1 -1
  216. package/dist/middleware/retry-after.d.ts +15 -0
  217. package/dist/middleware/retry-after.d.ts.map +1 -0
  218. package/dist/middleware/retry-after.js +36 -0
  219. package/dist/middleware/retry-after.js.map +1 -0
  220. package/dist/middleware/retry.d.ts +9 -18
  221. package/dist/middleware/retry.d.ts.map +1 -1
  222. package/dist/middleware/retry.js +12 -9
  223. package/dist/middleware/retry.js.map +1 -1
  224. package/dist/proxy/auth.d.ts +73 -0
  225. package/dist/proxy/auth.d.ts.map +1 -0
  226. package/dist/proxy/auth.js +128 -0
  227. package/dist/proxy/auth.js.map +1 -0
  228. package/dist/proxy/env-proxy.d.ts +11 -0
  229. package/dist/proxy/env-proxy.d.ts.map +1 -0
  230. package/dist/proxy/env-proxy.js +56 -0
  231. package/dist/proxy/env-proxy.js.map +1 -0
  232. package/dist/proxy/http-proxy.d.ts +13 -18
  233. package/dist/proxy/http-proxy.d.ts.map +1 -1
  234. package/dist/proxy/http-proxy.js +24 -14
  235. package/dist/proxy/http-proxy.js.map +1 -1
  236. package/dist/proxy/socks.d.ts +13 -20
  237. package/dist/proxy/socks.d.ts.map +1 -1
  238. package/dist/proxy/socks.js +6 -9
  239. package/dist/proxy/socks.js.map +1 -1
  240. package/dist/sse/parser.d.ts +47 -0
  241. package/dist/sse/parser.d.ts.map +1 -0
  242. package/dist/sse/parser.js +139 -0
  243. package/dist/sse/parser.js.map +1 -0
  244. package/dist/tls/constants.d.ts +15 -74
  245. package/dist/tls/constants.d.ts.map +1 -1
  246. package/dist/tls/constants.js +15 -74
  247. package/dist/tls/constants.js.map +1 -1
  248. package/dist/tls/ct.d.ts +78 -0
  249. package/dist/tls/ct.d.ts.map +1 -0
  250. package/dist/tls/ct.js +175 -0
  251. package/dist/tls/ct.js.map +1 -0
  252. package/dist/tls/early-data.d.ts +45 -0
  253. package/dist/tls/early-data.d.ts.map +1 -0
  254. package/dist/tls/early-data.js +46 -0
  255. package/dist/tls/early-data.js.map +1 -0
  256. package/dist/tls/ech.d.ts +130 -0
  257. package/dist/tls/ech.d.ts.map +1 -0
  258. package/dist/tls/ech.js +353 -0
  259. package/dist/tls/ech.js.map +1 -0
  260. package/dist/tls/keylog.d.ts +34 -0
  261. package/dist/tls/keylog.d.ts.map +1 -0
  262. package/dist/tls/keylog.js +64 -0
  263. package/dist/tls/keylog.js.map +1 -0
  264. package/dist/tls/node-engine.d.ts +15 -14
  265. package/dist/tls/node-engine.d.ts.map +1 -1
  266. package/dist/tls/node-engine.js +54 -14
  267. package/dist/tls/node-engine.js.map +1 -1
  268. package/dist/tls/ocsp.d.ts +55 -0
  269. package/dist/tls/ocsp.d.ts.map +1 -0
  270. package/dist/tls/ocsp.js +131 -0
  271. package/dist/tls/ocsp.js.map +1 -0
  272. package/dist/tls/pin-verification.d.ts +10 -0
  273. package/dist/tls/pin-verification.d.ts.map +1 -0
  274. package/dist/tls/pin-verification.js +28 -0
  275. package/dist/tls/pin-verification.js.map +1 -0
  276. package/dist/tls/session-cache.d.ts +58 -0
  277. package/dist/tls/session-cache.d.ts.map +1 -0
  278. package/dist/tls/session-cache.js +76 -0
  279. package/dist/tls/session-cache.js.map +1 -0
  280. package/dist/tls/stealth/client-hello.d.ts +34 -32
  281. package/dist/tls/stealth/client-hello.d.ts.map +1 -1
  282. package/dist/tls/stealth/client-hello.js +116 -11
  283. package/dist/tls/stealth/client-hello.js.map +1 -1
  284. package/dist/tls/stealth/engine.d.ts +5 -15
  285. package/dist/tls/stealth/engine.d.ts.map +1 -1
  286. package/dist/tls/stealth/engine.js +163 -47
  287. package/dist/tls/stealth/engine.js.map +1 -1
  288. package/dist/tls/stealth/handshake.d.ts +23 -32
  289. package/dist/tls/stealth/handshake.d.ts.map +1 -1
  290. package/dist/tls/stealth/handshake.js +112 -27
  291. package/dist/tls/stealth/handshake.js.map +1 -1
  292. package/dist/tls/stealth/key-schedule.d.ts +59 -86
  293. package/dist/tls/stealth/key-schedule.d.ts.map +1 -1
  294. package/dist/tls/stealth/key-schedule.js +46 -58
  295. package/dist/tls/stealth/key-schedule.js.map +1 -1
  296. package/dist/tls/stealth/record-layer.d.ts +52 -75
  297. package/dist/tls/stealth/record-layer.d.ts.map +1 -1
  298. package/dist/tls/stealth/record-layer.js +47 -63
  299. package/dist/tls/stealth/record-layer.js.map +1 -1
  300. package/dist/tls/stealth/tls12-handshake.d.ts +30 -0
  301. package/dist/tls/stealth/tls12-handshake.d.ts.map +1 -0
  302. package/dist/tls/stealth/tls12-handshake.js +470 -0
  303. package/dist/tls/stealth/tls12-handshake.js.map +1 -0
  304. package/dist/tls/types.d.ts +46 -48
  305. package/dist/tls/types.d.ts.map +1 -1
  306. package/dist/utils/buffer-reader.d.ts +26 -81
  307. package/dist/utils/buffer-reader.d.ts.map +1 -1
  308. package/dist/utils/buffer-reader.js +26 -81
  309. package/dist/utils/buffer-reader.js.map +1 -1
  310. package/dist/utils/buffer-writer.d.ts +30 -66
  311. package/dist/utils/buffer-writer.d.ts.map +1 -1
  312. package/dist/utils/buffer-writer.js +30 -66
  313. package/dist/utils/buffer-writer.js.map +1 -1
  314. package/dist/utils/compression.d.ts +18 -0
  315. package/dist/utils/compression.d.ts.map +1 -0
  316. package/dist/utils/compression.js +34 -0
  317. package/dist/utils/compression.js.map +1 -0
  318. package/dist/utils/dictionary-transport.d.ts +97 -0
  319. package/dist/utils/dictionary-transport.d.ts.map +1 -0
  320. package/dist/utils/dictionary-transport.js +171 -0
  321. package/dist/utils/dictionary-transport.js.map +1 -0
  322. package/dist/utils/encoding.d.ts +12 -28
  323. package/dist/utils/encoding.d.ts.map +1 -1
  324. package/dist/utils/encoding.js +77 -40
  325. package/dist/utils/encoding.js.map +1 -1
  326. package/dist/utils/happy-eyeballs.d.ts +20 -7
  327. package/dist/utils/happy-eyeballs.d.ts.map +1 -1
  328. package/dist/utils/happy-eyeballs.js +57 -25
  329. package/dist/utils/happy-eyeballs.js.map +1 -1
  330. package/dist/utils/logger.d.ts +54 -81
  331. package/dist/utils/logger.d.ts.map +1 -1
  332. package/dist/utils/logger.js +92 -64
  333. package/dist/utils/logger.js.map +1 -1
  334. package/dist/utils/tcp-fast-open.d.ts +30 -0
  335. package/dist/utils/tcp-fast-open.d.ts.map +1 -0
  336. package/dist/utils/tcp-fast-open.js +36 -0
  337. package/dist/utils/tcp-fast-open.js.map +1 -0
  338. package/dist/utils/url.d.ts +18 -25
  339. package/dist/utils/url.d.ts.map +1 -1
  340. package/dist/utils/url.js +18 -25
  341. package/dist/utils/url.js.map +1 -1
  342. package/dist/ws/client.d.ts +35 -52
  343. package/dist/ws/client.d.ts.map +1 -1
  344. package/dist/ws/client.js +92 -37
  345. package/dist/ws/client.js.map +1 -1
  346. package/dist/ws/frame.d.ts +27 -42
  347. package/dist/ws/frame.d.ts.map +1 -1
  348. package/dist/ws/frame.js +25 -37
  349. package/dist/ws/frame.js.map +1 -1
  350. package/dist/ws/permessage-deflate.d.ts +53 -0
  351. package/dist/ws/permessage-deflate.d.ts.map +1 -0
  352. package/dist/ws/permessage-deflate.js +140 -0
  353. package/dist/ws/permessage-deflate.js.map +1 -0
  354. package/package.json +62 -62
@@ -1,35 +1,33 @@
1
1
  import { createHmac, createHash as _createHash } from "node:crypto";
2
2
  /**
3
- * Returns the output length in bytes for the given hash algorithm.
3
+ * Return the digest output length for the given hash algorithm.
4
4
  *
5
- * @param {HashAlgorithm} alg - Hash algorithm identifier.
6
- * @returns {number} Output length: `32` for `sha256`, `48` for `sha384`.
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
- * Performs the HKDF-Extract step (RFC 5869 §2.2): computes `HMAC-Hash(salt, IKM)`.
12
+ * HKDF-Extract as defined in RFC 5869.
13
13
  *
14
- * @param {HashAlgorithm} alg - Hash algorithm for the HMAC computation.
15
- * @param {Buffer} salt - Salt value (used as HMAC key).
16
- * @param {Buffer} ikm - Input keying material.
17
- * @returns {Buffer} Pseudorandom key (PRK) of length `hashLength(alg)`.
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
- * Performs the TLS 1.3 HKDF-Expand-Label operation (RFC 8446 §7.1),
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 - Hash algorithm for HKDF.
28
- * @param {Buffer} secret - Input secret (PRK from HKDF-Extract).
29
- * @param {string} label - TLS 1.3 label string (without the `"tls13 "` prefix).
30
- * @param {Buffer} context - Transcript hash, or empty buffer for simple derivations.
31
- * @param {number} length - Desired output length in bytes.
32
- * @returns {Buffer} Derived key material of the specified length.
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
- * Derives a secret with a transcript hash context using HKDF-Expand-Label
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 - Hash algorithm for HKDF.
68
- * @param {Buffer} secret - Input PRK.
69
- * @param {string} label - TLS 1.3 label string.
70
- * @param {Buffer} transcriptHash - Current transcript hash value.
71
- * @returns {Buffer} Derived secret of length `hashLength(alg)`.
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
- * Returns a zero-filled `Buffer` whose length equals the output size of
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 that determines buffer length.
83
- * @returns {Buffer} Zero-filled buffer of `hashLength(alg)` bytes.
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
- * Returns the key and IV byte lengths for the given AEAD cipher name.
83
+ * Determine key and IV lengths for a TLS cipher suite.
90
84
  *
91
- * @param {string} cipherName - AEAD cipher name (e.g. `"TLS_AES_128_GCM_SHA256"`).
92
- * @returns {{ keyLen: number; ivLen: number }} Key length and IV length in bytes.
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
- * Derives TLS 1.3 handshake traffic keys from the ECDH shared secret and
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 - Hash algorithm specified by the negotiated cipher suite.
109
- * @param {Buffer} sharedSecret - ECDH shared secret from key exchange.
110
- * @param {Buffer} helloHash - Transcript hash over ClientHello..ServerHello.
111
- * @param {number} keyLen - Required key byte length.
112
- * @param {number} ivLen - Required IV byte length.
113
- * @returns {HandshakeKeys} Derived handshake keys and intermediate secrets.
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
- * Derives TLS 1.3 application traffic keys from the master secret and the
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 - Hash algorithm specified by the negotiated cipher suite.
142
- * @param {Buffer} masterSecret - TLS 1.3 master secret from {@link deriveHandshakeKeys}.
143
- * @param {Buffer} handshakeHash - Transcript hash over the complete handshake.
144
- * @param {number} keyLen - Required key byte length.
145
- * @param {number} ivLen - Required IV byte length.
146
- * @returns {ApplicationKeys} Derived application traffic keys.
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
- * Computes the `verify_data` for a TLS 1.3 Finished message (RFC 8446 §4.4.4)
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 - Hash algorithm for HMAC.
167
- * @param {Buffer} baseSecret - Base traffic secret (client or server handshake secret).
168
- * @param {Buffer} transcriptHash - Current transcript hash at the point of Finished.
169
- * @returns {Buffer} The `verify_data` bytes to include in or validate against the Finished message.
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;AASpE;;;;;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,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC;AACjE,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,eAAe,CAAC,GAAkB,EAAE,MAAc,EAAE,KAAa,EAAE,OAAe,EAAE,MAAc;IAChH,MAAM,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC,QAAQ,GAAG,KAAK,EAAE,OAAO,CAAC,CAAC;IACzD,MAAM,SAAS,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC,MAAM,GAAG,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAC9E,IAAI,MAAM,GAAG,CAAC,CAAC;IACf,SAAS,CAAC,aAAa,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACxC,MAAM,IAAI,CAAC,CAAC;IACZ,SAAS,CAAC,MAAM,EAAE,CAAC,GAAG,SAAS,CAAC,MAAM,CAAC;IACvC,SAAS,CAAC,IAAI,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;IAClC,MAAM,IAAI,SAAS,CAAC,MA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AAS,EAAE,eAAe,CAAC,GAAG,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC;QAC7E,QAAQ,EAAE,eAAe,CAAC,GAAG,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC;QAC1E,SAAS,EAAE,eAAe,CAAC,GAAG,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC;QAC7E,QAAQ,EAAE,eAAe,CAAC,GAAG,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
- * Attempts to parse a single TLS record from `data` beginning at `offset`.
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 - Buffer containing one or more TLS records.
20
- * @param {number} offset - Byte offset within `data` to begin parsing.
21
- * @returns {{ record: TLSRecord; bytesRead: number } | null} Parsed record and byte count, or `null` if more data is needed.
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
- * Serializes a TLS record into its 5-byte header plus payload binary form.
22
+ * Write a TLS record with the given type, version, and payload.
29
23
  *
30
- * @param {number} type - TLS content type byte.
31
- * @param {number} version - TLS record version (e.g. `0x0303`).
32
- * @param {Buffer} payload - Record payload bytes.
33
- * @returns {Buffer} The complete serialized TLS record.
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
- * Maps a cipher suite name string to the corresponding AEAD algorithm
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 name from {@link TLSConnectionInfo} (e.g. `"TLS_AES_128_GCM_SHA256"`).
48
- * @returns {AEADAlgorithm} The corresponding AEAD algorithm identifier.
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
- * Constructs the per-record nonce by XOR-ing the static IV with the
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 - Static IV of length matching the AEAD algorithm.
57
- * @param {bigint} sequenceNumber - Record sequence number (starts at 0, increments by 1).
58
- * @returns {Buffer} The per-record nonce.
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
- * Encrypts `plaintext` using the specified AEAD algorithm and returns the
63
- * ciphertext with an appended 16-byte authentication tag.
48
+ * Encrypt a TLS record payload using AEAD.
64
49
  *
65
- * @param {AEADAlgorithm} algorithm - AEAD algorithm identifier.
66
- * @param {Buffer} key - Encryption key.
67
- * @param {Buffer} nonce - Per-record nonce.
68
- * @param {Buffer} plaintext - Data to encrypt.
69
- * @param {Buffer} additionalData - Additional authenticated data (AAD).
70
- * @returns {Buffer} Ciphertext followed by the 16-byte authentication tag.
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
- * Decrypts and authenticates `ciphertext` using the specified AEAD algorithm.
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 - AEAD algorithm identifier.
78
- * @param {Buffer} key - Decryption key.
79
- * @param {Buffer} nonce - Per-record nonce.
80
- * @param {Buffer} ciphertext - Ciphertext including the 16-byte authentication tag.
81
- * @param {Buffer} additionalData - Additional authenticated data (AAD) for tag verification.
82
- * @returns {Buffer} Decrypted plaintext bytes.
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
- * Builds the additional authenticated data (AAD) for a TLS 1.3 application
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 - Total length of the ciphertext including the AEAD tag.
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
- * Encodes a TLS 1.3 inner plaintext (content bytes + content type byte) and
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 - AEAD algorithm identifier.
100
- * @param {Buffer} key - Application traffic key.
101
- * @param {Buffer} iv - Application traffic IV.
102
- * @param {bigint} sequenceNumber - Sequence number for nonce derivation.
103
- * @param {number} contentType - True content type byte to embed in the inner plaintext.
104
- * @param {Buffer} plaintext - Application data to encrypt.
105
- * @returns {Buffer} The complete TLS application_data record ready to send.
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
- * Decrypts a TLS 1.3 application_data record, strips the zero-padding, and
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 - AEAD algorithm identifier.
114
- * @param {Buffer} key - Application traffic key.
115
- * @param {Buffer} iv - Application traffic IV.
116
- * @param {bigint} sequenceNumber - Sequence number for nonce derivation.
117
- * @param {TLSRecord} record - Encrypted TLS record received from the remote party.
118
- * @returns {{ contentType: number; plaintext: Buffer }} Recovered content type and decrypted payload.
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":"AAUA;;;;;;;GAOG;AACH,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;;;GAQG;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;;;;;GAKG;AACH,MAAM,MAAM,aAAa,GAAG,aAAa,GAAG,aAAa,GAAG,mBAAmB,CAAC;AAEhF;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,UAAU,EAAE,MAAM,GAAG,aAAa,CAWhE;AAID;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,EAAE,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,GAAG,MAAM,CAQrE;AAED;;;;;;;;;;GAUG;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;;;;;;;;;;;GAWG;AAC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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
- * Attempts to parse a single TLS record from `data` beginning at `offset`.
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 - Buffer containing one or more TLS records.
13
- * @param {number} offset - Byte offset within `data` to begin parsing.
14
- * @returns {{ record: TLSRecord; bytesRead: number } | null} Parsed record and byte count, or `null` if more data is needed.
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
- * Serializes a TLS record into its 5-byte header plus payload binary form.
27
+ * Write a TLS record with the given type, version, and payload.
32
28
  *
33
- * @param {number} type - TLS content type byte.
34
- * @param {number} version - TLS record version (e.g. `0x0303`).
35
- * @param {Buffer} payload - Record payload bytes.
36
- * @returns {Buffer} The complete serialized TLS record.
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
- * Maps a cipher suite name string to the corresponding AEAD algorithm
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 name from {@link TLSConnectionInfo} (e.g. `"TLS_AES_128_GCM_SHA256"`).
51
- * @returns {AEADAlgorithm} The corresponding AEAD algorithm identifier.
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
- * Constructs the per-record nonce by XOR-ing the static IV with the
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 - Static IV of length matching the AEAD algorithm.
72
- * @param {bigint} sequenceNumber - Record sequence number (starts at 0, increments by 1).
73
- * @returns {Buffer} The per-record nonce.
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
- * Encrypts `plaintext` using the specified AEAD algorithm and returns the
86
- * ciphertext with an appended 16-byte authentication tag.
78
+ * Encrypt a TLS record payload using AEAD.
87
79
  *
88
- * @param {AEADAlgorithm} algorithm - AEAD algorithm identifier.
89
- * @param {Buffer} key - Encryption key.
90
- * @param {Buffer} nonce - Per-record nonce.
91
- * @param {Buffer} plaintext - Data to encrypt.
92
- * @param {Buffer} additionalData - Additional authenticated data (AAD).
93
- * @returns {Buffer} Ciphertext followed by the 16-byte authentication tag.
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
- * Decrypts and authenticates `ciphertext` using the specified AEAD algorithm.
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 - AEAD algorithm identifier.
108
- * @param {Buffer} key - Decryption key.
109
- * @param {Buffer} nonce - Per-record nonce.
110
- * @param {Buffer} ciphertext - Ciphertext including the 16-byte authentication tag.
111
- * @param {Buffer} additionalData - Additional authenticated data (AAD) for tag verification.
112
- * @returns {Buffer} Decrypted plaintext bytes.
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
- * Builds the additional authenticated data (AAD) for a TLS 1.3 application
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 - Total length of the ciphertext including the AEAD tag.
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
- * Encodes a TLS 1.3 inner plaintext (content bytes + content type byte) and
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 - AEAD algorithm identifier.
153
- * @param {Buffer} key - Application traffic key.
154
- * @param {Buffer} iv - Application traffic IV.
155
- * @param {bigint} sequenceNumber - Sequence number for nonce derivation.
156
- * @param {number} contentType - True content type byte to embed in the inner plaintext.
157
- * @param {Buffer} plaintext - Application data to encrypt.
158
- * @returns {Buffer} The complete TLS application_data record ready to send.
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
- * Decrypts a TLS 1.3 application_data record, strips the zero-padding, and
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 - AEAD algorithm identifier.
176
- * @param {Buffer} key - Application traffic key.
177
- * @param {Buffer} iv - Application traffic IV.
178
- * @param {bigint} sequenceNumber - Sequence number for nonce derivation.
179
- * @param {TLSRecord} record - Encrypted TLS record received from the remote party.
180
- * @returns {{ contentType: number; plaintext: Buffer }} Recovered content type and decrypted payload.
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;AAEpF,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;AAEhD,MAAM,kBAAkB,GAAG,KAAK,CAAC;AAEjC,MAAM,uBAAuB,GAAG,GAAG,CAAC;AAgBpC;;;;;;;;GAQG;AACH,MAAM,UAAU,UAAU,CAAC,IAAY,EAAE,MAAc;IACrD,IAAI,IAAI,CAAC,MAAM,GAAG,MAAM,GAAG,CAAC;QAAE,OAAO,IAAI,CAAC;IAE1C,MAAM,IAAI,GAAG,IAAI,CAAC,MAAM,CAAE,CA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AAC,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