@encharm/cws 4.0.2 → 4.3.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 (410) hide show
  1. package/CHANGELOG.md +3 -0
  2. package/LICENSE +3 -2
  3. package/README.md +9 -2
  4. package/binding.gyp +2 -2
  5. package/dist/bindings/cws_darwin_arm64_node108.node +0 -0
  6. package/dist/bindings/cws_darwin_arm64_node64.node +0 -0
  7. package/dist/bindings/cws_darwin_arm64_node72.node +0 -0
  8. package/dist/bindings/cws_darwin_arm64_node79.node +0 -0
  9. package/dist/bindings/cws_darwin_arm64_node83.node +0 -0
  10. package/dist/bindings/cws_darwin_arm64_node93.node +0 -0
  11. package/dist/bindings/cws_darwin_x64_node108.node +0 -0
  12. package/dist/bindings/cws_darwin_x64_node64.node +0 -0
  13. package/dist/bindings/cws_darwin_x64_node72.node +0 -0
  14. package/dist/bindings/cws_darwin_x64_node79.node +0 -0
  15. package/dist/bindings/cws_darwin_x64_node83.node +0 -0
  16. package/dist/bindings/cws_darwin_x64_node93.node +0 -0
  17. package/dist/bindings/cws_linux_x64_node108.node +0 -0
  18. package/dist/bindings/cws_linux_x64_node64.node +0 -0
  19. package/dist/bindings/cws_linux_x64_node72.node +0 -0
  20. package/dist/bindings/cws_linux_x64_node79.node +0 -0
  21. package/dist/bindings/cws_linux_x64_node83.node +0 -0
  22. package/dist/bindings/cws_linux_x64_node93.node +0 -0
  23. package/dist/bindings/cws_win32_x64_node108.node +0 -0
  24. package/dist/bindings/cws_win32_x64_node64.node +0 -0
  25. package/dist/bindings/cws_win32_x64_node72.node +0 -0
  26. package/dist/bindings/cws_win32_x64_node79.node +0 -0
  27. package/dist/bindings/cws_win32_x64_node83.node +0 -0
  28. package/dist/bindings/cws_win32_x64_node93.node +0 -0
  29. package/dist/client.d.ts +1 -0
  30. package/dist/client.js +4 -0
  31. package/dist/index.js +3 -2
  32. package/dist/server.js +1 -0
  33. package/dist/shared.js +2 -1
  34. package/package.json +1 -1
  35. package/src/Addon.cpp +1 -0
  36. package/src/Addon.h +35 -2
  37. package/src/HTTPSocket.cpp +1 -1
  38. package/src/LICENSE +4 -0
  39. package/src/Socket.h +12 -3
  40. package/src/headers/{13 → 18}/aliased_buffer.h +61 -9
  41. package/src/headers/18/aliased_struct-inl.h +54 -0
  42. package/src/headers/18/aliased_struct.h +63 -0
  43. package/src/headers/{12 → 18}/async_wrap-inl.h +0 -0
  44. package/src/headers/{12 → 18}/async_wrap.h +26 -2
  45. package/src/headers/{12/base64.h → 18/base64-inl.h} +78 -86
  46. package/src/headers/18/base64.h +69 -0
  47. package/src/headers/{12 → 18}/base_object-inl.h +46 -25
  48. package/src/headers/{12 → 18}/base_object.h +82 -17
  49. package/src/headers/{12 → 18}/callback_queue-inl.h +9 -9
  50. package/src/headers/{12 → 18}/callback_queue.h +13 -5
  51. package/src/headers/18/cares_wrap.h +523 -0
  52. package/src/headers/{12 → 18}/connect_wrap.h +0 -0
  53. package/src/headers/{12 → 18}/connection_wrap.h +0 -0
  54. package/src/headers/18/crypto/crypto_aes.h +89 -0
  55. package/src/headers/{13/node_crypto_bio.h → 18/crypto/crypto_bio.h} +3 -4
  56. package/src/headers/18/crypto/crypto_cipher.h +291 -0
  57. package/src/headers/{13/node_crypto_clienthello-inl.h → 18/crypto/crypto_clienthello-inl.h} +4 -5
  58. package/src/headers/{13/node_crypto_clienthello.h → 18/crypto/crypto_clienthello.h} +3 -4
  59. package/src/headers/{12/node_crypto_common.h → 18/crypto/crypto_common.h} +49 -36
  60. package/src/headers/18/crypto/crypto_context.h +147 -0
  61. package/src/headers/18/crypto/crypto_dh.h +156 -0
  62. package/src/headers/18/crypto/crypto_dsa.h +77 -0
  63. package/src/headers/18/crypto/crypto_ec.h +170 -0
  64. package/src/headers/{12/node_crypto_groups.h → 18/crypto/crypto_groups.h} +3 -3
  65. package/src/headers/18/crypto/crypto_hash.h +89 -0
  66. package/src/headers/18/crypto/crypto_hkdf.h +65 -0
  67. package/src/headers/18/crypto/crypto_hmac.h +94 -0
  68. package/src/headers/18/crypto/crypto_keygen.h +305 -0
  69. package/src/headers/18/crypto/crypto_keys.h +420 -0
  70. package/src/headers/18/crypto/crypto_pbkdf2.h +76 -0
  71. package/src/headers/18/crypto/crypto_random.h +130 -0
  72. package/src/headers/18/crypto/crypto_rsa.h +141 -0
  73. package/src/headers/18/crypto/crypto_scrypt.h +87 -0
  74. package/src/headers/18/crypto/crypto_sig.h +168 -0
  75. package/src/headers/18/crypto/crypto_spkac.h +21 -0
  76. package/src/headers/18/crypto/crypto_timing.h +20 -0
  77. package/src/headers/{12/tls_wrap.h → 18/crypto/crypto_tls.h} +137 -66
  78. package/src/headers/18/crypto/crypto_util.h +791 -0
  79. package/src/headers/18/crypto/crypto_x509.h +143 -0
  80. package/src/headers/{12 → 18}/debug_utils-inl.h +0 -0
  81. package/src/headers/{13 → 18}/debug_utils.h +7 -4
  82. package/src/headers/{12 → 18}/diagnosticfilename-inl.h +0 -0
  83. package/src/headers/{12 → 18}/env-inl.h +397 -304
  84. package/src/headers/{12 → 18}/env.h +397 -172
  85. package/src/headers/{12 → 18}/handle_wrap.h +7 -3
  86. package/src/headers/18/histogram-inl.h +107 -0
  87. package/src/headers/18/histogram.h +239 -0
  88. package/src/headers/{13 → 18}/inspector_agent.h +4 -7
  89. package/src/headers/{12 → 18}/inspector_io.h +0 -0
  90. package/src/headers/{13 → 18}/inspector_profiler.h +17 -5
  91. package/src/headers/{12 → 18}/inspector_socket.h +0 -0
  92. package/src/headers/{12 → 18}/inspector_socket_server.h +0 -0
  93. package/src/headers/18/js_native_api.h +571 -0
  94. package/src/headers/{13 → 18}/js_native_api_types.h +30 -7
  95. package/src/headers/{12 → 18}/js_native_api_v8.h +220 -83
  96. package/src/headers/{12 → 18}/js_native_api_v8_internals.h +6 -5
  97. package/src/headers/{12 → 18}/js_stream.h +0 -0
  98. package/src/headers/{12 → 18}/json_utils.h +0 -0
  99. package/src/headers/{13 → 18}/memory_tracker-inl.h +6 -5
  100. package/src/headers/{13 → 18}/memory_tracker.h +0 -7
  101. package/src/headers/{13 → 18}/module_wrap.h +24 -7
  102. package/src/headers/{13 → 18}/node.h +329 -68
  103. package/src/headers/18/node_api.h +288 -0
  104. package/src/headers/18/node_api_internals.h +38 -0
  105. package/src/headers/{12 → 18}/node_api_types.h +12 -9
  106. package/src/headers/{12 → 18}/node_binding.h +0 -0
  107. package/src/headers/18/node_blob.h +191 -0
  108. package/src/headers/18/node_bob-inl.h +37 -0
  109. package/src/headers/18/node_bob.h +111 -0
  110. package/src/headers/{13 → 18}/node_buffer.h +0 -0
  111. package/src/headers/{13 → 18}/node_constants.h +5 -1
  112. package/src/headers/{12 → 18}/node_context_data.h +5 -0
  113. package/src/headers/{12 → 18}/node_contextify.h +37 -2
  114. package/src/headers/{10/node_javascript.h → 18/node_crypto.h} +30 -14
  115. package/src/headers/{12 → 18}/node_dir.h +0 -0
  116. package/src/headers/{12 → 18}/node_dtrace.h +0 -0
  117. package/src/headers/{12 → 18}/node_errors.h +90 -24
  118. package/src/headers/18/node_external_reference.h +145 -0
  119. package/src/headers/{13 → 18}/node_file-inl.h +38 -21
  120. package/src/headers/{12 → 18}/node_file.h +74 -13
  121. package/src/headers/{13 → 18}/node_http2.h +365 -269
  122. package/src/headers/{12 → 18}/node_http2_state.h +40 -50
  123. package/src/headers/{13 → 18}/node_http_common-inl.h +25 -5
  124. package/src/headers/{13 → 18}/node_http_common.h +24 -20
  125. package/src/headers/{13 → 18}/node_i18n.h +2 -1
  126. package/src/headers/{12 → 18}/node_internals.h +39 -41
  127. package/src/headers/{12 → 18}/node_main_instance.h +15 -18
  128. package/src/headers/{12 → 18}/node_mem-inl.h +0 -0
  129. package/src/headers/{12 → 18}/node_mem.h +1 -1
  130. package/src/headers/{13 → 18}/node_messaging.h +170 -23
  131. package/src/headers/{12 → 18}/node_metadata.h +17 -4
  132. package/src/headers/{12 → 18}/node_mutex.h +77 -1
  133. package/src/headers/{12 → 18}/node_native_module.h +11 -1
  134. package/src/headers/{12 → 18}/node_native_module_env.h +14 -8
  135. package/src/headers/{12 → 18}/node_object_wrap.h +0 -0
  136. package/src/headers/{13 → 18}/node_options-inl.h +51 -21
  137. package/src/headers/{13 → 18}/node_options.h +46 -14
  138. package/src/headers/18/node_perf.h +168 -0
  139. package/src/headers/{12 → 18}/node_perf_common.h +16 -22
  140. package/src/headers/{12 → 18}/node_platform.h +21 -16
  141. package/src/headers/18/node_process-inl.h +26 -0
  142. package/src/headers/18/node_process.h +97 -0
  143. package/src/headers/{13 → 18}/node_report.h +2 -2
  144. package/src/headers/{13 → 18}/node_revert.h +10 -0
  145. package/src/headers/{12 → 18}/node_root_certs.h +439 -651
  146. package/src/headers/18/node_snapshot_builder.h +43 -0
  147. package/src/headers/18/node_snapshotable.h +130 -0
  148. package/src/headers/{12 → 18}/node_sockaddr-inl.h +100 -4
  149. package/src/headers/18/node_sockaddr.h +405 -0
  150. package/src/headers/{13 → 18}/node_stat_watcher.h +7 -1
  151. package/src/headers/{12 → 18}/node_union_bytes.h +0 -0
  152. package/src/headers/{13 → 18}/node_url.h +18 -1
  153. package/src/headers/18/node_v8.h +41 -0
  154. package/src/headers/{12 → 18}/node_v8_platform-inl.h +10 -0
  155. package/src/headers/{13 → 18}/node_version.h +7 -7
  156. package/src/headers/{12 → 18}/node_wasi.h +0 -0
  157. package/src/headers/18/node_wasm_web_api.h +55 -0
  158. package/src/headers/{13 → 18}/node_watchdog.h +0 -0
  159. package/src/headers/{10 → 18}/node_win32_etw_provider-inl.h +7 -6
  160. package/src/headers/{10 → 18}/node_win32_etw_provider.h +0 -0
  161. package/src/headers/{13 → 18}/node_worker.h +24 -17
  162. package/src/headers/{12 → 18}/pipe_wrap.h +2 -0
  163. package/src/headers/{12 → 18}/req_wrap-inl.h +0 -0
  164. package/src/headers/{13 → 18}/req_wrap.h +1 -1
  165. package/src/headers/{12 → 18}/spawn_sync.h +0 -0
  166. package/src/headers/{13 → 18}/stream_base-inl.h +58 -22
  167. package/src/headers/{13 → 18}/stream_base.h +29 -3
  168. package/src/headers/{13 → 18}/stream_pipe.h +8 -3
  169. package/src/headers/{12 → 18}/stream_wrap.h +4 -1
  170. package/src/headers/{13 → 18}/string_bytes.h +0 -7
  171. package/src/headers/{12 → 18}/string_decoder-inl.h +0 -0
  172. package/src/headers/{10 → 18}/string_decoder.h +0 -0
  173. package/src/headers/{13 → 18}/string_search.h +2 -2
  174. package/src/headers/{12 → 18}/tcp_wrap.h +4 -0
  175. package/src/headers/{12 → 18}/threadpoolwork-inl.h +0 -0
  176. package/src/headers/18/timer_wrap-inl.h +32 -0
  177. package/src/headers/18/timer_wrap.h +85 -0
  178. package/src/headers/{13 → 18}/tracing/agent.h +1 -1
  179. package/src/headers/{12 → 18}/tracing/node_trace_buffer.h +0 -0
  180. package/src/headers/{12 → 18}/tracing/node_trace_writer.h +0 -0
  181. package/src/headers/{13 → 18}/tracing/trace_event.h +23 -13
  182. package/src/headers/{12 → 18}/tracing/trace_event_common.h +0 -0
  183. package/src/headers/{12 → 18}/tracing/traced_value.h +0 -0
  184. package/src/headers/{13 → 18}/tty_wrap.h +2 -1
  185. package/src/headers/{13 → 18}/udp_wrap.h +5 -0
  186. package/src/headers/{13 → 18}/util-inl.h +69 -15
  187. package/src/headers/{13 → 18}/util.h +93 -31
  188. package/src/headers/18/v8-fast-api-calls.h +939 -0
  189. package/src/headers/{12 → 18}/v8abbr.h +2 -2
  190. package/dist/bindings/cws_darwin_64.node +0 -0
  191. package/dist/bindings/cws_darwin_72.node +0 -0
  192. package/dist/bindings/cws_darwin_79.node +0 -0
  193. package/dist/bindings/cws_darwin_83.node +0 -0
  194. package/dist/bindings/cws_darwin_93.node +0 -0
  195. package/dist/bindings/cws_linux_64.node +0 -0
  196. package/dist/bindings/cws_linux_72.node +0 -0
  197. package/dist/bindings/cws_linux_79.node +0 -0
  198. package/dist/bindings/cws_linux_83.node +0 -0
  199. package/dist/bindings/cws_linux_93.node +0 -0
  200. package/dist/bindings/cws_win32_64.node +0 -0
  201. package/dist/bindings/cws_win32_72.node +0 -0
  202. package/dist/bindings/cws_win32_79.node +0 -0
  203. package/dist/bindings/cws_win32_83.node +0 -0
  204. package/dist/bindings/cws_win32_93.node +0 -0
  205. package/src/headers/10/aliased_buffer.h +0 -241
  206. package/src/headers/10/async_wrap-inl.h +0 -106
  207. package/src/headers/10/async_wrap.h +0 -218
  208. package/src/headers/10/base64.h +0 -197
  209. package/src/headers/10/base_object-inl.h +0 -132
  210. package/src/headers/10/base_object.h +0 -115
  211. package/src/headers/10/connect_wrap.h +0 -28
  212. package/src/headers/10/connection_wrap.h +0 -30
  213. package/src/headers/10/debug_utils.h +0 -128
  214. package/src/headers/10/env-inl.h +0 -906
  215. package/src/headers/10/env.h +0 -1046
  216. package/src/headers/10/handle_wrap.h +0 -114
  217. package/src/headers/10/inspector_agent.h +0 -137
  218. package/src/headers/10/inspector_io.h +0 -97
  219. package/src/headers/10/inspector_socket.h +0 -59
  220. package/src/headers/10/inspector_socket_server.h +0 -104
  221. package/src/headers/10/js_stream.h +0 -57
  222. package/src/headers/10/memory_tracker-inl.h +0 -318
  223. package/src/headers/10/memory_tracker.h +0 -246
  224. package/src/headers/10/module_wrap.h +0 -100
  225. package/src/headers/10/node.h +0 -863
  226. package/src/headers/10/node_api.h +0 -752
  227. package/src/headers/10/node_api_types.h +0 -171
  228. package/src/headers/10/node_buffer.h +0 -90
  229. package/src/headers/10/node_code_cache.h +0 -17
  230. package/src/headers/10/node_constants.h +0 -74
  231. package/src/headers/10/node_context_data.h +0 -39
  232. package/src/headers/10/node_contextify.h +0 -141
  233. package/src/headers/10/node_counters.h +0 -59
  234. package/src/headers/10/node_crypto.h +0 -699
  235. package/src/headers/10/node_crypto_bio.h +0 -177
  236. package/src/headers/10/node_crypto_clienthello-inl.h +0 -92
  237. package/src/headers/10/node_crypto_clienthello.h +0 -131
  238. package/src/headers/10/node_crypto_groups.h +0 -416
  239. package/src/headers/10/node_dtrace.h +0 -84
  240. package/src/headers/10/node_errors.h +0 -118
  241. package/src/headers/10/node_file.h +0 -373
  242. package/src/headers/10/node_http2.h +0 -1304
  243. package/src/headers/10/node_http2_state.h +0 -158
  244. package/src/headers/10/node_i18n.h +0 -69
  245. package/src/headers/10/node_internals.h +0 -952
  246. package/src/headers/10/node_messaging.h +0 -219
  247. package/src/headers/10/node_mutex.h +0 -191
  248. package/src/headers/10/node_object_wrap.h +0 -130
  249. package/src/headers/10/node_options-inl.h +0 -444
  250. package/src/headers/10/node_options.h +0 -397
  251. package/src/headers/10/node_perf.h +0 -134
  252. package/src/headers/10/node_perf_common.h +0 -96
  253. package/src/headers/10/node_persistent.h +0 -30
  254. package/src/headers/10/node_platform.h +0 -170
  255. package/src/headers/10/node_revert.h +0 -75
  256. package/src/headers/10/node_root_certs.h +0 -3393
  257. package/src/headers/10/node_stat_watcher.h +0 -65
  258. package/src/headers/10/node_url.h +0 -193
  259. package/src/headers/10/node_version.h +0 -120
  260. package/src/headers/10/node_watchdog.h +0 -114
  261. package/src/headers/10/node_win32_perfctr_provider.h +0 -58
  262. package/src/headers/10/node_worker.h +0 -94
  263. package/src/headers/10/pipe_wrap.h +0 -76
  264. package/src/headers/10/req_wrap-inl.h +0 -166
  265. package/src/headers/10/req_wrap.h +0 -61
  266. package/src/headers/10/sharedarraybuffer_metadata.h +0 -67
  267. package/src/headers/10/spawn_sync.h +0 -240
  268. package/src/headers/10/stream_base-inl.h +0 -458
  269. package/src/headers/10/stream_base.h +0 -378
  270. package/src/headers/10/stream_pipe.h +0 -72
  271. package/src/headers/10/stream_wrap.h +0 -130
  272. package/src/headers/10/string_bytes.h +0 -126
  273. package/src/headers/10/string_decoder-inl.h +0 -38
  274. package/src/headers/10/string_search.h +0 -620
  275. package/src/headers/10/tcp_wrap.h +0 -99
  276. package/src/headers/10/tls_wrap.h +0 -195
  277. package/src/headers/10/tracing/agent.h +0 -178
  278. package/src/headers/10/tracing/node_trace_buffer.h +0 -83
  279. package/src/headers/10/tracing/node_trace_writer.h +0 -75
  280. package/src/headers/10/tracing/trace_event.h +0 -706
  281. package/src/headers/10/tracing/trace_event_common.h +0 -1102
  282. package/src/headers/10/tracing/traced_value.h +0 -68
  283. package/src/headers/10/tty_wrap.h +0 -63
  284. package/src/headers/10/udp_wrap.h +0 -102
  285. package/src/headers/10/util-inl.h +0 -459
  286. package/src/headers/10/util.h +0 -508
  287. package/src/headers/10/v8abbr.h +0 -121
  288. package/src/headers/12/aliased_buffer.h +0 -263
  289. package/src/headers/12/debug_utils.h +0 -181
  290. package/src/headers/12/histogram-inl.h +0 -83
  291. package/src/headers/12/histogram.h +0 -98
  292. package/src/headers/12/http_parser_adaptor.h +0 -24
  293. package/src/headers/12/inspector_agent.h +0 -147
  294. package/src/headers/12/inspector_profiler.h +0 -137
  295. package/src/headers/12/js_native_api.h +0 -541
  296. package/src/headers/12/js_native_api_types.h +0 -139
  297. package/src/headers/12/memory_tracker-inl.h +0 -339
  298. package/src/headers/12/memory_tracker.h +0 -283
  299. package/src/headers/12/module_wrap.h +0 -99
  300. package/src/headers/12/node.h +0 -887
  301. package/src/headers/12/node_api.h +0 -239
  302. package/src/headers/12/node_buffer.h +0 -92
  303. package/src/headers/12/node_constants.h +0 -80
  304. package/src/headers/12/node_crypto.h +0 -800
  305. package/src/headers/12/node_crypto_bio.h +0 -195
  306. package/src/headers/12/node_crypto_clienthello-inl.h +0 -91
  307. package/src/headers/12/node_crypto_clienthello.h +0 -132
  308. package/src/headers/12/node_file-inl.h +0 -289
  309. package/src/headers/12/node_http2.h +0 -1311
  310. package/src/headers/12/node_http_parser_impl.h +0 -994
  311. package/src/headers/12/node_i18n.h +0 -144
  312. package/src/headers/12/node_messaging.h +0 -227
  313. package/src/headers/12/node_options-inl.h +0 -447
  314. package/src/headers/12/node_options.h +0 -479
  315. package/src/headers/12/node_perf.h +0 -181
  316. package/src/headers/12/node_process.h +0 -41
  317. package/src/headers/12/node_report.h +0 -47
  318. package/src/headers/12/node_revert.h +0 -78
  319. package/src/headers/12/node_sockaddr.h +0 -123
  320. package/src/headers/12/node_stat_watcher.h +0 -66
  321. package/src/headers/12/node_url.h +0 -188
  322. package/src/headers/12/node_version.h +0 -98
  323. package/src/headers/12/node_watchdog.h +0 -152
  324. package/src/headers/12/node_win32_etw_provider-inl.h +0 -287
  325. package/src/headers/12/node_win32_etw_provider.h +0 -99
  326. package/src/headers/12/node_worker.h +0 -142
  327. package/src/headers/12/req_wrap.h +0 -77
  328. package/src/headers/12/sharedarraybuffer_metadata.h +0 -72
  329. package/src/headers/12/stream_base-inl.h +0 -323
  330. package/src/headers/12/stream_base.h +0 -431
  331. package/src/headers/12/stream_pipe.h +0 -72
  332. package/src/headers/12/string_bytes.h +0 -142
  333. package/src/headers/12/string_decoder.h +0 -50
  334. package/src/headers/12/string_search.h +0 -638
  335. package/src/headers/12/tracing/agent.h +0 -195
  336. package/src/headers/12/tracing/trace_event.h +0 -710
  337. package/src/headers/12/tty_wrap.h +0 -64
  338. package/src/headers/12/udp_wrap.h +0 -222
  339. package/src/headers/12/util-inl.h +0 -529
  340. package/src/headers/12/util.h +0 -765
  341. package/src/headers/13/async_wrap-inl.h +0 -94
  342. package/src/headers/13/async_wrap.h +0 -224
  343. package/src/headers/13/base64.h +0 -197
  344. package/src/headers/13/base_object-inl.h +0 -353
  345. package/src/headers/13/base_object.h +0 -229
  346. package/src/headers/13/connect_wrap.h +0 -26
  347. package/src/headers/13/connection_wrap.h +0 -30
  348. package/src/headers/13/debug_utils-inl.h +0 -223
  349. package/src/headers/13/diagnosticfilename-inl.h +0 -33
  350. package/src/headers/13/env-inl.h +0 -1293
  351. package/src/headers/13/env.h +0 -1469
  352. package/src/headers/13/handle_wrap.h +0 -117
  353. package/src/headers/13/histogram-inl.h +0 -83
  354. package/src/headers/13/histogram.h +0 -98
  355. package/src/headers/13/inspector_io.h +0 -78
  356. package/src/headers/13/inspector_socket.h +0 -60
  357. package/src/headers/13/inspector_socket_server.h +0 -110
  358. package/src/headers/13/js_native_api.h +0 -541
  359. package/src/headers/13/js_native_api_v8.h +0 -303
  360. package/src/headers/13/js_native_api_v8_internals.h +0 -38
  361. package/src/headers/13/js_stream.h +0 -52
  362. package/src/headers/13/json_utils.h +0 -160
  363. package/src/headers/13/node_api.h +0 -239
  364. package/src/headers/13/node_api_types.h +0 -44
  365. package/src/headers/13/node_binding.h +0 -99
  366. package/src/headers/13/node_context_data.h +0 -39
  367. package/src/headers/13/node_contextify.h +0 -161
  368. package/src/headers/13/node_crypto.h +0 -800
  369. package/src/headers/13/node_crypto_common.h +0 -138
  370. package/src/headers/13/node_crypto_groups.h +0 -415
  371. package/src/headers/13/node_dir.h +0 -52
  372. package/src/headers/13/node_dtrace.h +0 -86
  373. package/src/headers/13/node_errors.h +0 -210
  374. package/src/headers/13/node_file.h +0 -364
  375. package/src/headers/13/node_http2_state.h +0 -144
  376. package/src/headers/13/node_internals.h +0 -405
  377. package/src/headers/13/node_main_instance.h +0 -97
  378. package/src/headers/13/node_mem-inl.h +0 -112
  379. package/src/headers/13/node_mem.h +0 -41
  380. package/src/headers/13/node_metadata.h +0 -109
  381. package/src/headers/13/node_mutex.h +0 -247
  382. package/src/headers/13/node_native_module.h +0 -99
  383. package/src/headers/13/node_native_module_env.h +0 -65
  384. package/src/headers/13/node_object_wrap.h +0 -132
  385. package/src/headers/13/node_perf.h +0 -181
  386. package/src/headers/13/node_perf_common.h +0 -97
  387. package/src/headers/13/node_platform.h +0 -190
  388. package/src/headers/13/node_process.h +0 -41
  389. package/src/headers/13/node_root_certs.h +0 -3424
  390. package/src/headers/13/node_sockaddr-inl.h +0 -170
  391. package/src/headers/13/node_sockaddr.h +0 -123
  392. package/src/headers/13/node_union_bytes.h +0 -103
  393. package/src/headers/13/node_v8_platform-inl.h +0 -184
  394. package/src/headers/13/node_wasi.h +0 -108
  395. package/src/headers/13/node_win32_etw_provider-inl.h +0 -287
  396. package/src/headers/13/node_win32_etw_provider.h +0 -99
  397. package/src/headers/13/pipe_wrap.h +0 -78
  398. package/src/headers/13/req_wrap-inl.h +0 -170
  399. package/src/headers/13/spawn_sync.h +0 -242
  400. package/src/headers/13/stream_wrap.h +0 -130
  401. package/src/headers/13/string_decoder-inl.h +0 -37
  402. package/src/headers/13/string_decoder.h +0 -50
  403. package/src/headers/13/tcp_wrap.h +0 -101
  404. package/src/headers/13/threadpoolwork-inl.h +0 -57
  405. package/src/headers/13/tls_wrap.h +0 -221
  406. package/src/headers/13/tracing/node_trace_buffer.h +0 -83
  407. package/src/headers/13/tracing/node_trace_writer.h +0 -75
  408. package/src/headers/13/tracing/trace_event_common.h +0 -1109
  409. package/src/headers/13/tracing/traced_value.h +0 -70
  410. package/src/headers/13/v8abbr.h +0 -124
@@ -0,0 +1,791 @@
1
+ #ifndef SRC_CRYPTO_CRYPTO_UTIL_H_
2
+ #define SRC_CRYPTO_CRYPTO_UTIL_H_
3
+
4
+ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
+
6
+ #include "async_wrap.h"
7
+ #include "env.h"
8
+ #include "node_errors.h"
9
+ #include "node_external_reference.h"
10
+ #include "node_internals.h"
11
+ #include "string_bytes.h"
12
+ #include "util.h"
13
+ #include "v8.h"
14
+
15
+ #include <openssl/err.h>
16
+ #include <openssl/evp.h>
17
+ #include <openssl/ec.h>
18
+ #include <openssl/kdf.h>
19
+ #include <openssl/rsa.h>
20
+ #include <openssl/dsa.h>
21
+ #include <openssl/ssl.h>
22
+ #ifndef OPENSSL_NO_ENGINE
23
+ # include <openssl/engine.h>
24
+ #endif // !OPENSSL_NO_ENGINE
25
+ // The FIPS-related functions are only available
26
+ // when the OpenSSL itself was compiled with FIPS support.
27
+ #if defined(OPENSSL_FIPS) && OPENSSL_VERSION_MAJOR < 3
28
+ # include <openssl/fips.h>
29
+ #endif // OPENSSL_FIPS
30
+
31
+ #include <algorithm>
32
+ #include <memory>
33
+ #include <string>
34
+ #include <vector>
35
+ #include <climits>
36
+ #include <cstdio>
37
+
38
+ namespace node {
39
+ namespace crypto {
40
+ // Currently known sizes of commonly used OpenSSL struct sizes.
41
+ // OpenSSL considers it's various structs to be opaque and the
42
+ // sizes may change from one version of OpenSSL to another, so
43
+ // these values should not be trusted to remain static. These
44
+ // are provided to allow for some close to reasonable memory
45
+ // tracking.
46
+ constexpr size_t kSizeOf_DH = 144;
47
+ constexpr size_t kSizeOf_EC_KEY = 80;
48
+ constexpr size_t kSizeOf_EVP_CIPHER_CTX = 168;
49
+ constexpr size_t kSizeOf_EVP_MD_CTX = 48;
50
+ constexpr size_t kSizeOf_EVP_PKEY = 72;
51
+ constexpr size_t kSizeOf_EVP_PKEY_CTX = 80;
52
+ constexpr size_t kSizeOf_HMAC_CTX = 32;
53
+
54
+ // Define smart pointers for the most commonly used OpenSSL types:
55
+ using X509Pointer = DeleteFnPtr<X509, X509_free>;
56
+ using BIOPointer = DeleteFnPtr<BIO, BIO_free_all>;
57
+ using SSLCtxPointer = DeleteFnPtr<SSL_CTX, SSL_CTX_free>;
58
+ using SSLSessionPointer = DeleteFnPtr<SSL_SESSION, SSL_SESSION_free>;
59
+ using SSLPointer = DeleteFnPtr<SSL, SSL_free>;
60
+ using PKCS8Pointer = DeleteFnPtr<PKCS8_PRIV_KEY_INFO, PKCS8_PRIV_KEY_INFO_free>;
61
+ using EVPKeyPointer = DeleteFnPtr<EVP_PKEY, EVP_PKEY_free>;
62
+ using EVPKeyCtxPointer = DeleteFnPtr<EVP_PKEY_CTX, EVP_PKEY_CTX_free>;
63
+ using EVPMDPointer = DeleteFnPtr<EVP_MD_CTX, EVP_MD_CTX_free>;
64
+ using RSAPointer = DeleteFnPtr<RSA, RSA_free>;
65
+ using ECPointer = DeleteFnPtr<EC_KEY, EC_KEY_free>;
66
+ using BignumPointer = DeleteFnPtr<BIGNUM, BN_free>;
67
+ using BignumCtxPointer = DeleteFnPtr<BN_CTX, BN_CTX_free>;
68
+ using NetscapeSPKIPointer = DeleteFnPtr<NETSCAPE_SPKI, NETSCAPE_SPKI_free>;
69
+ using ECGroupPointer = DeleteFnPtr<EC_GROUP, EC_GROUP_free>;
70
+ using ECPointPointer = DeleteFnPtr<EC_POINT, EC_POINT_free>;
71
+ using ECKeyPointer = DeleteFnPtr<EC_KEY, EC_KEY_free>;
72
+ using DHPointer = DeleteFnPtr<DH, DH_free>;
73
+ using ECDSASigPointer = DeleteFnPtr<ECDSA_SIG, ECDSA_SIG_free>;
74
+ using HMACCtxPointer = DeleteFnPtr<HMAC_CTX, HMAC_CTX_free>;
75
+ using CipherCtxPointer = DeleteFnPtr<EVP_CIPHER_CTX, EVP_CIPHER_CTX_free>;
76
+ using RsaPointer = DeleteFnPtr<RSA, RSA_free>;
77
+ using DsaPointer = DeleteFnPtr<DSA, DSA_free>;
78
+ using DsaSigPointer = DeleteFnPtr<DSA_SIG, DSA_SIG_free>;
79
+
80
+ // Our custom implementation of the certificate verify callback
81
+ // used when establishing a TLS handshake. Because we cannot perform
82
+ // I/O quickly enough with X509_STORE_CTX_ APIs in this callback,
83
+ // we ignore preverify_ok errors here and let the handshake continue.
84
+ // In other words, this VerifyCallback is a non-op. It is imperative
85
+ // that the user user Connection::VerifyError after the `secure`
86
+ // callback has been made.
87
+ extern int VerifyCallback(int preverify_ok, X509_STORE_CTX* ctx);
88
+
89
+ bool ProcessFipsOptions();
90
+
91
+ bool InitCryptoOnce(v8::Isolate* isolate);
92
+ void InitCryptoOnce();
93
+
94
+ void InitCrypto(v8::Local<v8::Object> target);
95
+
96
+ extern void UseExtraCaCerts(const std::string& file);
97
+
98
+ // Forcibly clear OpenSSL's error stack on return. This stops stale errors
99
+ // from popping up later in the lifecycle of crypto operations where they
100
+ // would cause spurious failures. It's a rather blunt method, though.
101
+ // ERR_clear_error() isn't necessarily cheap either.
102
+ struct ClearErrorOnReturn {
103
+ ~ClearErrorOnReturn() { ERR_clear_error(); }
104
+ };
105
+
106
+ // Pop errors from OpenSSL's error stack that were added
107
+ // between when this was constructed and destructed.
108
+ struct MarkPopErrorOnReturn {
109
+ MarkPopErrorOnReturn() { ERR_set_mark(); }
110
+ ~MarkPopErrorOnReturn() { ERR_pop_to_mark(); }
111
+ };
112
+
113
+ // Ensure that OpenSSL has enough entropy (at least 256 bits) for its PRNG.
114
+ // The entropy pool starts out empty and needs to fill up before the PRNG
115
+ // can be used securely. Once the pool is filled, it never dries up again;
116
+ // its contents is stirred and reused when necessary.
117
+ //
118
+ // OpenSSL normally fills the pool automatically but not when someone starts
119
+ // generating random numbers before the pool is full: in that case OpenSSL
120
+ // keeps lowering the entropy estimate to thwart attackers trying to guess
121
+ // the initial state of the PRNG.
122
+ //
123
+ // When that happens, we will have to wait until enough entropy is available.
124
+ // That should normally never take longer than a few milliseconds.
125
+ //
126
+ // OpenSSL draws from /dev/random and /dev/urandom. While /dev/random may
127
+ // block pending "true" randomness, /dev/urandom is a CSPRNG that doesn't
128
+ // block under normal circumstances.
129
+ //
130
+ // The only time when /dev/urandom may conceivably block is right after boot,
131
+ // when the whole system is still low on entropy. That's not something we can
132
+ // do anything about.
133
+ void CheckEntropy();
134
+
135
+ // Generate length bytes of random data. If this returns false, the data
136
+ // may not be truly random but it's still generally good enough.
137
+ bool EntropySource(unsigned char* buffer, size_t length);
138
+
139
+ int PasswordCallback(char* buf, int size, int rwflag, void* u);
140
+
141
+ int NoPasswordCallback(char* buf, int size, int rwflag, void* u);
142
+
143
+ // Decode is used by the various stream-based crypto utilities to decode
144
+ // string input.
145
+ template <typename T>
146
+ void Decode(const v8::FunctionCallbackInfo<v8::Value>& args,
147
+ void (*callback)(T*, const v8::FunctionCallbackInfo<v8::Value>&,
148
+ const char*, size_t)) {
149
+ T* ctx;
150
+ ASSIGN_OR_RETURN_UNWRAP(&ctx, args.Holder());
151
+
152
+ if (args[0]->IsString()) {
153
+ StringBytes::InlineDecoder decoder;
154
+ Environment* env = Environment::GetCurrent(args);
155
+ enum encoding enc = ParseEncoding(env->isolate(), args[1], UTF8);
156
+ if (decoder.Decode(env, args[0].As<v8::String>(), enc).IsNothing())
157
+ return;
158
+ callback(ctx, args, decoder.out(), decoder.size());
159
+ } else {
160
+ ArrayBufferViewContents<char> buf(args[0]);
161
+ callback(ctx, args, buf.data(), buf.length());
162
+ }
163
+ }
164
+
165
+ #define NODE_CRYPTO_ERROR_CODES_MAP(V) \
166
+ V(CIPHER_JOB_FAILED, "Cipher job failed") \
167
+ V(DERIVING_BITS_FAILED, "Deriving bits failed") \
168
+ V(ENGINE_NOT_FOUND, "Engine \"%s\" was not found") \
169
+ V(INVALID_KEY_TYPE, "Invalid key type") \
170
+ V(KEY_GENERATION_JOB_FAILED, "Key generation job failed") \
171
+ V(OK, "Ok") \
172
+
173
+ enum class NodeCryptoError {
174
+ #define V(CODE, DESCRIPTION) CODE,
175
+ NODE_CRYPTO_ERROR_CODES_MAP(V)
176
+ #undef V
177
+ };
178
+
179
+ // Utility struct used to harvest error information from openssl's error stack
180
+ struct CryptoErrorStore final : public MemoryRetainer {
181
+ public:
182
+ void Capture();
183
+
184
+ bool Empty() const;
185
+
186
+ template <typename... Args>
187
+ void Insert(const NodeCryptoError error, Args&&... args);
188
+
189
+ v8::MaybeLocal<v8::Value> ToException(
190
+ Environment* env,
191
+ v8::Local<v8::String> exception_string = v8::Local<v8::String>()) const;
192
+
193
+ SET_NO_MEMORY_INFO()
194
+ SET_MEMORY_INFO_NAME(CryptoErrorStore)
195
+ SET_SELF_SIZE(CryptoErrorStore)
196
+
197
+ private:
198
+ std::vector<std::string> errors_;
199
+ };
200
+
201
+ template <typename... Args>
202
+ void CryptoErrorStore::Insert(const NodeCryptoError error, Args&&... args) {
203
+ const char* error_string = nullptr;
204
+ switch (error) {
205
+ #define V(CODE, DESCRIPTION) \
206
+ case NodeCryptoError::CODE: error_string = DESCRIPTION; break;
207
+ NODE_CRYPTO_ERROR_CODES_MAP(V)
208
+ #undef V
209
+ }
210
+ errors_.emplace_back(SPrintF(error_string,
211
+ std::forward<Args>(args)...));
212
+ }
213
+
214
+ template <typename T>
215
+ T* MallocOpenSSL(size_t count) {
216
+ void* mem = OPENSSL_malloc(MultiplyWithOverflowCheck(count, sizeof(T)));
217
+ CHECK_IMPLIES(mem == nullptr, count == 0);
218
+ return static_cast<T*>(mem);
219
+ }
220
+
221
+ template <typename T>
222
+ T* ReallocOpenSSL(T* buf, size_t count) {
223
+ void* mem = OPENSSL_realloc(buf, MultiplyWithOverflowCheck(count, sizeof(T)));
224
+ CHECK_IMPLIES(mem == nullptr, count == 0);
225
+ return static_cast<T*>(mem);
226
+ }
227
+
228
+ // A helper class representing a read-only byte array. When deallocated, its
229
+ // contents are zeroed.
230
+ class ByteSource {
231
+ public:
232
+ ByteSource() = default;
233
+ ByteSource(ByteSource&& other) noexcept;
234
+ ~ByteSource();
235
+
236
+ ByteSource& operator=(ByteSource&& other) noexcept;
237
+
238
+ const char* get() const;
239
+
240
+ template <typename T>
241
+ const T* data() const { return reinterpret_cast<const T*>(get()); }
242
+
243
+ size_t size() const;
244
+
245
+ operator bool() const { return data_ != nullptr; }
246
+
247
+ BignumPointer ToBN() const {
248
+ return BignumPointer(BN_bin2bn(
249
+ reinterpret_cast<const unsigned char*>(get()),
250
+ size(),
251
+ nullptr));
252
+ }
253
+
254
+ // Creates a v8::BackingStore that takes over responsibility for
255
+ // any allocated data. The ByteSource will be reset with size = 0
256
+ // after being called.
257
+ std::unique_ptr<v8::BackingStore> ReleaseToBackingStore();
258
+
259
+ v8::Local<v8::ArrayBuffer> ToArrayBuffer(Environment* env);
260
+
261
+ v8::MaybeLocal<v8::Uint8Array> ToBuffer(Environment* env);
262
+
263
+ void reset();
264
+
265
+ // Allows an Allocated ByteSource to be truncated.
266
+ void Resize(size_t newsize) {
267
+ CHECK_LE(newsize, size_);
268
+ CHECK_NOT_NULL(allocated_data_);
269
+ char* new_data_ = ReallocOpenSSL<char>(allocated_data_, newsize);
270
+ data_ = allocated_data_ = new_data_;
271
+ size_ = newsize;
272
+ }
273
+
274
+ static ByteSource Allocated(char* data, size_t size);
275
+ static ByteSource Foreign(const char* data, size_t size);
276
+
277
+ static ByteSource FromEncodedString(Environment* env,
278
+ v8::Local<v8::String> value,
279
+ enum encoding enc = BASE64);
280
+
281
+ static ByteSource FromStringOrBuffer(Environment* env,
282
+ v8::Local<v8::Value> value);
283
+
284
+ static ByteSource FromString(Environment* env,
285
+ v8::Local<v8::String> str,
286
+ bool ntc = false);
287
+
288
+ static ByteSource FromBuffer(v8::Local<v8::Value> buffer,
289
+ bool ntc = false);
290
+
291
+ static ByteSource FromBIO(const BIOPointer& bio);
292
+
293
+ static ByteSource NullTerminatedCopy(Environment* env,
294
+ v8::Local<v8::Value> value);
295
+
296
+ static ByteSource FromSymmetricKeyObjectHandle(v8::Local<v8::Value> handle);
297
+
298
+ ByteSource(const ByteSource&) = delete;
299
+ ByteSource& operator=(const ByteSource&) = delete;
300
+
301
+ static ByteSource FromSecretKeyBytes(
302
+ Environment* env, v8::Local<v8::Value> value);
303
+
304
+ private:
305
+ const char* data_ = nullptr;
306
+ char* allocated_data_ = nullptr;
307
+ size_t size_ = 0;
308
+
309
+ ByteSource(const char* data, char* allocated_data, size_t size);
310
+ };
311
+
312
+ enum CryptoJobMode {
313
+ kCryptoJobAsync,
314
+ kCryptoJobSync
315
+ };
316
+
317
+ CryptoJobMode GetCryptoJobMode(v8::Local<v8::Value> args);
318
+
319
+ template <typename CryptoJobTraits>
320
+ class CryptoJob : public AsyncWrap, public ThreadPoolWork {
321
+ public:
322
+ using AdditionalParams = typename CryptoJobTraits::AdditionalParameters;
323
+
324
+ explicit CryptoJob(
325
+ Environment* env,
326
+ v8::Local<v8::Object> object,
327
+ AsyncWrap::ProviderType type,
328
+ CryptoJobMode mode,
329
+ AdditionalParams&& params)
330
+ : AsyncWrap(env, object, type),
331
+ ThreadPoolWork(env),
332
+ mode_(mode),
333
+ params_(std::move(params)) {
334
+ // If the CryptoJob is async, then the instance will be
335
+ // cleaned up when AfterThreadPoolWork is called.
336
+ if (mode == kCryptoJobSync) MakeWeak();
337
+ }
338
+
339
+ bool IsNotIndicativeOfMemoryLeakAtExit() const override {
340
+ // CryptoJobs run a work in the libuv thread pool and may still
341
+ // exist when the event loop empties and starts to exit.
342
+ return true;
343
+ }
344
+
345
+ void AfterThreadPoolWork(int status) override {
346
+ Environment* env = AsyncWrap::env();
347
+ CHECK_EQ(mode_, kCryptoJobAsync);
348
+ CHECK(status == 0 || status == UV_ECANCELED);
349
+ std::unique_ptr<CryptoJob> ptr(this);
350
+ // If the job was canceled do not execute the callback.
351
+ // TODO(@jasnell): We should likely revisit skipping the
352
+ // callback on cancel as that could leave the JS in a pending
353
+ // state (e.g. unresolved promises...)
354
+ if (status == UV_ECANCELED) return;
355
+ v8::HandleScope handle_scope(env->isolate());
356
+ v8::Context::Scope context_scope(env->context());
357
+
358
+ // TODO(tniessen): Remove the exception handling logic here as soon as we
359
+ // can verify that no code path in ToResult will ever throw an exception.
360
+ v8::Local<v8::Value> exception;
361
+ v8::Local<v8::Value> args[2];
362
+ {
363
+ node::errors::TryCatchScope try_catch(env);
364
+ v8::Maybe<bool> ret = ptr->ToResult(&args[0], &args[1]);
365
+ if (!ret.IsJust()) {
366
+ CHECK(try_catch.HasCaught());
367
+ exception = try_catch.Exception();
368
+ } else if (!ret.FromJust()) {
369
+ return;
370
+ }
371
+ }
372
+
373
+ if (exception.IsEmpty()) {
374
+ ptr->MakeCallback(env->ondone_string(), arraysize(args), args);
375
+ } else {
376
+ ptr->MakeCallback(env->ondone_string(), 1, &exception);
377
+ }
378
+ }
379
+
380
+ virtual v8::Maybe<bool> ToResult(
381
+ v8::Local<v8::Value>* err,
382
+ v8::Local<v8::Value>* result) = 0;
383
+
384
+ CryptoJobMode mode() const { return mode_; }
385
+
386
+ CryptoErrorStore* errors() { return &errors_; }
387
+
388
+ AdditionalParams* params() { return &params_; }
389
+
390
+ std::string MemoryInfoName() const override {
391
+ return CryptoJobTraits::JobName;
392
+ }
393
+
394
+ void MemoryInfo(MemoryTracker* tracker) const override {
395
+ tracker->TrackField("params", params_);
396
+ tracker->TrackField("errors", errors_);
397
+ }
398
+
399
+ static void Run(const v8::FunctionCallbackInfo<v8::Value>& args) {
400
+ Environment* env = Environment::GetCurrent(args);
401
+
402
+ CryptoJob<CryptoJobTraits>* job;
403
+ ASSIGN_OR_RETURN_UNWRAP(&job, args.Holder());
404
+ if (job->mode() == kCryptoJobAsync)
405
+ return job->ScheduleWork();
406
+
407
+ v8::Local<v8::Value> ret[2];
408
+ env->PrintSyncTrace();
409
+ job->DoThreadPoolWork();
410
+ v8::Maybe<bool> result = job->ToResult(&ret[0], &ret[1]);
411
+ if (result.IsJust() && result.FromJust()) {
412
+ args.GetReturnValue().Set(
413
+ v8::Array::New(env->isolate(), ret, arraysize(ret)));
414
+ }
415
+ }
416
+
417
+ static void Initialize(
418
+ v8::FunctionCallback new_fn,
419
+ Environment* env,
420
+ v8::Local<v8::Object> target) {
421
+ v8::Local<v8::FunctionTemplate> job = env->NewFunctionTemplate(new_fn);
422
+ job->Inherit(AsyncWrap::GetConstructorTemplate(env));
423
+ job->InstanceTemplate()->SetInternalFieldCount(
424
+ AsyncWrap::kInternalFieldCount);
425
+ env->SetProtoMethod(job, "run", Run);
426
+ env->SetConstructorFunction(target, CryptoJobTraits::JobName, job);
427
+ }
428
+
429
+ static void RegisterExternalReferences(v8::FunctionCallback new_fn,
430
+ ExternalReferenceRegistry* registry) {
431
+ registry->Register(new_fn);
432
+ registry->Register(Run);
433
+ }
434
+
435
+ private:
436
+ const CryptoJobMode mode_;
437
+ CryptoErrorStore errors_;
438
+ AdditionalParams params_;
439
+ };
440
+
441
+ template <typename DeriveBitsTraits>
442
+ class DeriveBitsJob final : public CryptoJob<DeriveBitsTraits> {
443
+ public:
444
+ using AdditionalParams = typename DeriveBitsTraits::AdditionalParameters;
445
+
446
+ static void New(const v8::FunctionCallbackInfo<v8::Value>& args) {
447
+ Environment* env = Environment::GetCurrent(args);
448
+
449
+ CryptoJobMode mode = GetCryptoJobMode(args[0]);
450
+
451
+ AdditionalParams params;
452
+ if (DeriveBitsTraits::AdditionalConfig(mode, args, 1, &params)
453
+ .IsNothing()) {
454
+ // The DeriveBitsTraits::AdditionalConfig is responsible for
455
+ // calling an appropriate THROW_CRYPTO_* variant reporting
456
+ // whatever error caused initialization to fail.
457
+ return;
458
+ }
459
+
460
+ new DeriveBitsJob(env, args.This(), mode, std::move(params));
461
+ }
462
+
463
+ static void Initialize(
464
+ Environment* env,
465
+ v8::Local<v8::Object> target) {
466
+ CryptoJob<DeriveBitsTraits>::Initialize(New, env, target);
467
+ }
468
+
469
+ static void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
470
+ CryptoJob<DeriveBitsTraits>::RegisterExternalReferences(New, registry);
471
+ }
472
+
473
+ DeriveBitsJob(
474
+ Environment* env,
475
+ v8::Local<v8::Object> object,
476
+ CryptoJobMode mode,
477
+ AdditionalParams&& params)
478
+ : CryptoJob<DeriveBitsTraits>(
479
+ env,
480
+ object,
481
+ DeriveBitsTraits::Provider,
482
+ mode,
483
+ std::move(params)) {}
484
+
485
+ void DoThreadPoolWork() override {
486
+ if (!DeriveBitsTraits::DeriveBits(
487
+ AsyncWrap::env(),
488
+ *CryptoJob<DeriveBitsTraits>::params(), &out_)) {
489
+ CryptoErrorStore* errors = CryptoJob<DeriveBitsTraits>::errors();
490
+ errors->Capture();
491
+ if (errors->Empty())
492
+ errors->Insert(NodeCryptoError::DERIVING_BITS_FAILED);
493
+ return;
494
+ }
495
+ success_ = true;
496
+ }
497
+
498
+ v8::Maybe<bool> ToResult(
499
+ v8::Local<v8::Value>* err,
500
+ v8::Local<v8::Value>* result) override {
501
+ Environment* env = AsyncWrap::env();
502
+ CryptoErrorStore* errors = CryptoJob<DeriveBitsTraits>::errors();
503
+ if (success_) {
504
+ CHECK(errors->Empty());
505
+ *err = v8::Undefined(env->isolate());
506
+ return DeriveBitsTraits::EncodeOutput(
507
+ env,
508
+ *CryptoJob<DeriveBitsTraits>::params(),
509
+ &out_,
510
+ result);
511
+ }
512
+
513
+ if (errors->Empty())
514
+ errors->Capture();
515
+ CHECK(!errors->Empty());
516
+ *result = v8::Undefined(env->isolate());
517
+ return v8::Just(errors->ToException(env).ToLocal(err));
518
+ }
519
+
520
+ SET_SELF_SIZE(DeriveBitsJob)
521
+ void MemoryInfo(MemoryTracker* tracker) const override {
522
+ tracker->TrackFieldWithSize("out", out_.size());
523
+ CryptoJob<DeriveBitsTraits>::MemoryInfo(tracker);
524
+ }
525
+
526
+ private:
527
+ ByteSource out_;
528
+ bool success_ = false;
529
+ };
530
+
531
+ void ThrowCryptoError(Environment* env,
532
+ unsigned long err, // NOLINT(runtime/int)
533
+ const char* message = nullptr);
534
+
535
+ #ifndef OPENSSL_NO_ENGINE
536
+ struct EnginePointer {
537
+ ENGINE* engine = nullptr;
538
+ bool finish_on_exit = false;
539
+
540
+ inline EnginePointer() = default;
541
+
542
+ inline explicit EnginePointer(ENGINE* engine_, bool finish_on_exit_ = false)
543
+ : engine(engine_),
544
+ finish_on_exit(finish_on_exit_) {}
545
+
546
+ inline EnginePointer(EnginePointer&& other) noexcept
547
+ : engine(other.engine),
548
+ finish_on_exit(other.finish_on_exit) {
549
+ other.release();
550
+ }
551
+
552
+ inline ~EnginePointer() { reset(); }
553
+
554
+ inline EnginePointer& operator=(EnginePointer&& other) noexcept {
555
+ if (this == &other) return *this;
556
+ this->~EnginePointer();
557
+ return *new (this) EnginePointer(std::move(other));
558
+ }
559
+
560
+ inline operator bool() const { return engine != nullptr; }
561
+
562
+ inline ENGINE* get() { return engine; }
563
+
564
+ inline void reset(ENGINE* engine_ = nullptr, bool finish_on_exit_ = false) {
565
+ if (engine != nullptr) {
566
+ if (finish_on_exit) {
567
+ // This also does the equivalent of ENGINE_free.
568
+ CHECK_EQ(ENGINE_finish(engine), 1);
569
+ } else {
570
+ CHECK_EQ(ENGINE_free(engine), 1);
571
+ }
572
+ }
573
+ engine = engine_;
574
+ finish_on_exit = finish_on_exit_;
575
+ }
576
+
577
+ inline ENGINE* release() {
578
+ ENGINE* ret = engine;
579
+ engine = nullptr;
580
+ finish_on_exit = false;
581
+ return ret;
582
+ }
583
+ };
584
+
585
+ EnginePointer LoadEngineById(const char* id, CryptoErrorStore* errors);
586
+
587
+ bool SetEngine(
588
+ const char* id,
589
+ uint32_t flags,
590
+ CryptoErrorStore* errors = nullptr);
591
+
592
+ void SetEngine(const v8::FunctionCallbackInfo<v8::Value>& args);
593
+ #endif // !OPENSSL_NO_ENGINE
594
+
595
+ void GetFipsCrypto(const v8::FunctionCallbackInfo<v8::Value>& args);
596
+
597
+ void SetFipsCrypto(const v8::FunctionCallbackInfo<v8::Value>& args);
598
+
599
+ void TestFipsCrypto(const v8::FunctionCallbackInfo<v8::Value>& args);
600
+
601
+ class CipherPushContext {
602
+ public:
603
+ inline explicit CipherPushContext(Environment* env) : env_(env) {}
604
+
605
+ inline void push_back(const char* str) {
606
+ list_.emplace_back(OneByteString(env_->isolate(), str));
607
+ }
608
+
609
+ inline v8::Local<v8::Array> ToJSArray() {
610
+ return v8::Array::New(env_->isolate(), list_.data(), list_.size());
611
+ }
612
+
613
+ private:
614
+ std::vector<v8::Local<v8::Value>> list_;
615
+ Environment* env_;
616
+ };
617
+
618
+ #if OPENSSL_VERSION_MAJOR >= 3
619
+ template <class TypeName,
620
+ TypeName* fetch_type(OSSL_LIB_CTX*, const char*, const char*),
621
+ void free_type(TypeName*),
622
+ const TypeName* getbyname(const char*),
623
+ const char* getname(const TypeName*)>
624
+ void array_push_back(const TypeName* evp_ref,
625
+ const char* from,
626
+ const char* to,
627
+ void* arg) {
628
+ if (!from)
629
+ return;
630
+
631
+ const TypeName* real_instance = getbyname(from);
632
+ if (!real_instance)
633
+ return;
634
+
635
+ const char* real_name = getname(real_instance);
636
+ if (!real_name)
637
+ return;
638
+
639
+ // EVP_*_fetch() does not support alias names, so we need to pass it the
640
+ // real/original algorithm name.
641
+ // We use EVP_*_fetch() as a filter here because it will only return an
642
+ // instance if the algorithm is supported by the public OpenSSL APIs (some
643
+ // algorithms are used internally by OpenSSL and are also passed to this
644
+ // callback).
645
+ TypeName* fetched = fetch_type(nullptr, real_name, nullptr);
646
+ if (!fetched)
647
+ return;
648
+
649
+ free_type(fetched);
650
+ static_cast<CipherPushContext*>(arg)->push_back(from);
651
+ }
652
+ #else
653
+ template <class TypeName>
654
+ void array_push_back(const TypeName* evp_ref,
655
+ const char* from,
656
+ const char* to,
657
+ void* arg) {
658
+ if (!from)
659
+ return;
660
+ static_cast<CipherPushContext*>(arg)->push_back(from);
661
+ }
662
+ #endif
663
+
664
+ inline bool IsAnyByteSource(v8::Local<v8::Value> arg) {
665
+ return arg->IsArrayBufferView() ||
666
+ arg->IsArrayBuffer() ||
667
+ arg->IsSharedArrayBuffer();
668
+ }
669
+
670
+ template <typename T>
671
+ class ArrayBufferOrViewContents {
672
+ public:
673
+ ArrayBufferOrViewContents() = default;
674
+
675
+ inline explicit ArrayBufferOrViewContents(v8::Local<v8::Value> buf) {
676
+ CHECK(IsAnyByteSource(buf));
677
+ if (buf->IsArrayBufferView()) {
678
+ auto view = buf.As<v8::ArrayBufferView>();
679
+ offset_ = view->ByteOffset();
680
+ length_ = view->ByteLength();
681
+ store_ = view->Buffer()->GetBackingStore();
682
+ } else if (buf->IsArrayBuffer()) {
683
+ auto ab = buf.As<v8::ArrayBuffer>();
684
+ offset_ = 0;
685
+ length_ = ab->ByteLength();
686
+ store_ = ab->GetBackingStore();
687
+ } else {
688
+ auto sab = buf.As<v8::SharedArrayBuffer>();
689
+ offset_ = 0;
690
+ length_ = sab->ByteLength();
691
+ store_ = sab->GetBackingStore();
692
+ }
693
+ }
694
+
695
+ inline const T* data() const {
696
+ // Ideally, these would return nullptr if IsEmpty() or length_ is zero,
697
+ // but some of the openssl API react badly if given a nullptr even when
698
+ // length is zero, so we have to return something.
699
+ if (size() == 0)
700
+ return &buf;
701
+ return reinterpret_cast<T*>(store_->Data()) + offset_;
702
+ }
703
+
704
+ inline T* data() {
705
+ // Ideally, these would return nullptr if IsEmpty() or length_ is zero,
706
+ // but some of the openssl API react badly if given a nullptr even when
707
+ // length is zero, so we have to return something.
708
+ if (size() == 0)
709
+ return &buf;
710
+ return reinterpret_cast<T*>(store_->Data()) + offset_;
711
+ }
712
+
713
+ inline size_t size() const { return length_; }
714
+
715
+ // In most cases, input buffer sizes passed in to openssl need to
716
+ // be limited to <= INT_MAX. This utility method helps us check.
717
+ inline bool CheckSizeInt32() { return size() <= INT_MAX; }
718
+
719
+ inline ByteSource ToByteSource() const {
720
+ return ByteSource::Foreign(data(), size());
721
+ }
722
+
723
+ inline ByteSource ToCopy() const {
724
+ if (size() == 0) return ByteSource();
725
+ char* buf = MallocOpenSSL<char>(size());
726
+ CHECK_NOT_NULL(buf);
727
+ memcpy(buf, data(), size());
728
+ return ByteSource::Allocated(buf, size());
729
+ }
730
+
731
+ inline ByteSource ToNullTerminatedCopy() const {
732
+ if (size() == 0) return ByteSource();
733
+ char* buf = MallocOpenSSL<char>(size() + 1);
734
+ CHECK_NOT_NULL(buf);
735
+ buf[size()] = 0;
736
+ memcpy(buf, data(), size());
737
+ return ByteSource::Allocated(buf, size());
738
+ }
739
+
740
+ template <typename M>
741
+ void CopyTo(M* dest, size_t len) const {
742
+ static_assert(sizeof(M) == 1, "sizeof(M) must equal 1");
743
+ len = std::min(len, size());
744
+ if (len > 0 && data() != nullptr)
745
+ memcpy(dest, data(), len);
746
+ }
747
+
748
+ private:
749
+ T buf = 0;
750
+ size_t offset_ = 0;
751
+ size_t length_ = 0;
752
+ std::shared_ptr<v8::BackingStore> store_;
753
+ };
754
+
755
+ template <typename T>
756
+ std::vector<T> CopyBuffer(const ArrayBufferOrViewContents<T>& buf) {
757
+ std::vector<T> vec;
758
+ vec->resize(buf.size());
759
+ if (vec->size() > 0 && buf.data() != nullptr)
760
+ memcpy(vec->data(), buf.data(), vec->size());
761
+ return vec;
762
+ }
763
+
764
+ template <typename T>
765
+ std::vector<T> CopyBuffer(v8::Local<v8::Value> buf) {
766
+ return CopyBuffer(ArrayBufferOrViewContents<T>(buf));
767
+ }
768
+
769
+ v8::MaybeLocal<v8::Value> EncodeBignum(
770
+ Environment* env,
771
+ const BIGNUM* bn,
772
+ int size,
773
+ v8::Local<v8::Value>* error);
774
+
775
+ v8::Maybe<bool> SetEncodedValue(
776
+ Environment* env,
777
+ v8::Local<v8::Object> target,
778
+ v8::Local<v8::String> name,
779
+ const BIGNUM* bn,
780
+ int size = 0);
781
+
782
+ namespace Util {
783
+ void Initialize(Environment* env, v8::Local<v8::Object> target);
784
+ void RegisterExternalReferences(ExternalReferenceRegistry* registry);
785
+ } // namespace Util
786
+
787
+ } // namespace crypto
788
+ } // namespace node
789
+
790
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
791
+ #endif // SRC_CRYPTO_CRYPTO_UTIL_H_