@encharm/cws 4.5.3 → 4.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 (305) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/CLAUDE.md +83 -0
  3. package/README.md +20 -4
  4. package/binding.gyp +8 -2
  5. package/dist/bindings/cws_darwin_arm64_node115.node +0 -0
  6. package/dist/bindings/cws_darwin_arm64_node127.node +0 -0
  7. package/dist/bindings/cws_darwin_arm64_node137.node +0 -0
  8. package/dist/bindings/cws_darwin_arm64_node147.node +0 -0
  9. package/dist/bindings/cws_linux_arm64_node115.node +0 -0
  10. package/dist/bindings/cws_linux_arm64_node127.node +0 -0
  11. package/dist/bindings/cws_linux_arm64_node137.node +0 -0
  12. package/dist/bindings/cws_linux_arm64_node147.node +0 -0
  13. package/dist/bindings/cws_linux_x64_node115.node +0 -0
  14. package/dist/bindings/cws_linux_x64_node127.node +0 -0
  15. package/dist/bindings/cws_linux_x64_node137.node +0 -0
  16. package/dist/bindings/cws_linux_x64_node147.node +0 -0
  17. package/dist/bindings/cws_win32_x64_node115.node +0 -0
  18. package/dist/bindings/cws_win32_x64_node127.node +0 -0
  19. package/dist/bindings/cws_win32_x64_node137.node +0 -0
  20. package/dist/bindings/cws_win32_x64_node147.node +0 -0
  21. package/dist/client.d.ts +1 -0
  22. package/dist/client.js +15 -1
  23. package/dist/index.d.ts +6 -1
  24. package/dist/index.js +2 -0
  25. package/dist/server.d.ts +1 -0
  26. package/dist/server.js +16 -2
  27. package/dist/shared.d.ts +1 -0
  28. package/dist/shared.js +3 -2
  29. package/package.json +1 -1
  30. package/src/Addon.cpp +4 -1
  31. package/src/Addon.h +80 -15
  32. package/src/Extensions.cpp +7 -1
  33. package/src/Extensions.h +2 -1
  34. package/src/Group.cpp +1 -1
  35. package/src/Group.h +4 -1
  36. package/src/HTTPSocket.cpp +1 -1
  37. package/src/Hub.cpp +11 -76
  38. package/src/Hub.h +12 -10
  39. package/src/Networking.h +11 -0
  40. package/src/Socket.h +201 -6
  41. package/src/WebSocket.cpp +8 -5
  42. package/src/Zlib.cpp +138 -0
  43. package/src/Zlib.h +38 -0
  44. package/src/cSNode.cpp +2 -0
  45. package/src/cSNode.h +4 -0
  46. package/src/headers/26/acorn_version.h +6 -0
  47. package/src/headers/26/aliased_buffer-inl.h +264 -0
  48. package/src/headers/26/aliased_buffer.h +205 -0
  49. package/src/headers/26/aliased_struct-inl.h +143 -0
  50. package/src/headers/26/aliased_struct.h +248 -0
  51. package/src/headers/26/amaro_version.h +6 -0
  52. package/src/headers/26/async_context_frame.h +33 -0
  53. package/src/headers/26/async_wrap-inl.h +123 -0
  54. package/src/headers/26/async_wrap.h +254 -0
  55. package/src/headers/26/base_object-inl.h +333 -0
  56. package/src/headers/26/base_object.h +339 -0
  57. package/src/headers/26/base_object_types.h +76 -0
  58. package/src/headers/26/blob_serializer_deserializer-inl.h +385 -0
  59. package/src/headers/26/blob_serializer_deserializer.h +142 -0
  60. package/src/headers/26/builtin_info.h +57 -0
  61. package/src/headers/26/callback_queue-inl.h +97 -0
  62. package/src/headers/26/callback_queue.h +79 -0
  63. package/src/headers/26/cares_wrap.h +475 -0
  64. package/src/headers/26/cleanup_queue-inl.h +36 -0
  65. package/src/headers/26/cleanup_queue.h +79 -0
  66. package/src/headers/26/compile_cache.h +134 -0
  67. package/src/headers/26/connect_wrap.h +26 -0
  68. package/src/headers/26/connection_wrap.h +30 -0
  69. package/src/headers/26/cppgc_helpers-inl.h +69 -0
  70. package/src/headers/26/cppgc_helpers.h +162 -0
  71. package/src/headers/26/crypto/crypto_aes.h +107 -0
  72. package/src/headers/26/crypto/crypto_argon2.h +88 -0
  73. package/src/headers/26/crypto/crypto_bio.h +193 -0
  74. package/src/headers/26/crypto/crypto_chacha20_poly1305.h +62 -0
  75. package/src/headers/26/crypto/crypto_cipher.h +291 -0
  76. package/src/headers/26/crypto/crypto_common.h +48 -0
  77. package/src/headers/26/crypto/crypto_context.h +219 -0
  78. package/src/headers/26/crypto/crypto_dh.h +104 -0
  79. package/src/headers/26/crypto/crypto_dsa.h +50 -0
  80. package/src/headers/26/crypto/crypto_ec.h +102 -0
  81. package/src/headers/26/crypto/crypto_hash.h +157 -0
  82. package/src/headers/26/crypto/crypto_hkdf.h +62 -0
  83. package/src/headers/26/crypto/crypto_hmac.h +92 -0
  84. package/src/headers/26/crypto/crypto_kem.h +131 -0
  85. package/src/headers/26/crypto/crypto_keygen.h +382 -0
  86. package/src/headers/26/crypto/crypto_keys.h +366 -0
  87. package/src/headers/26/crypto/crypto_kmac.h +79 -0
  88. package/src/headers/26/crypto/crypto_pbkdf2.h +76 -0
  89. package/src/headers/26/crypto/crypto_pqc.h +39 -0
  90. package/src/headers/26/crypto/crypto_random.h +127 -0
  91. package/src/headers/26/crypto/crypto_rsa.h +108 -0
  92. package/src/headers/26/crypto/crypto_scrypt.h +85 -0
  93. package/src/headers/26/crypto/crypto_sig.h +159 -0
  94. package/src/headers/26/crypto/crypto_spkac.h +21 -0
  95. package/src/headers/26/crypto/crypto_timing.h +20 -0
  96. package/src/headers/26/crypto/crypto_tls.h +342 -0
  97. package/src/headers/26/crypto/crypto_turboshake.h +105 -0
  98. package/src/headers/26/crypto/crypto_util.h +775 -0
  99. package/src/headers/26/crypto/crypto_x509.h +140 -0
  100. package/src/headers/26/dataqueue/queue.h +311 -0
  101. package/src/headers/26/debug_utils-inl.h +291 -0
  102. package/src/headers/26/debug_utils.h +200 -0
  103. package/src/headers/26/diagnosticfilename-inl.h +33 -0
  104. package/src/headers/26/embedded_data.h +17 -0
  105. package/src/headers/26/encoding_binding.h +59 -0
  106. package/src/headers/26/env-inl.h +956 -0
  107. package/src/headers/26/env.h +1294 -0
  108. package/src/headers/26/env_properties.h +562 -0
  109. package/src/headers/26/ffi/data.h +30 -0
  110. package/src/headers/26/ffi/fast.h +96 -0
  111. package/src/headers/26/ffi/jit_memory.h +26 -0
  112. package/src/headers/26/ffi/types.h +99 -0
  113. package/src/headers/26/handle_wrap.h +123 -0
  114. package/src/headers/26/histogram-inl.h +211 -0
  115. package/src/headers/26/histogram.h +474 -0
  116. package/src/headers/26/inspector/dom_storage_agent.h +68 -0
  117. package/src/headers/26/inspector/inspector_object_utils.h +38 -0
  118. package/src/headers/26/inspector/io_agent.h +30 -0
  119. package/src/headers/26/inspector/main_thread_interface.h +116 -0
  120. package/src/headers/26/inspector/network_agent.h +110 -0
  121. package/src/headers/26/inspector/network_inspector.h +45 -0
  122. package/src/headers/26/inspector/network_requests_buffer.h +195 -0
  123. package/src/headers/26/inspector/network_resource_manager.h +29 -0
  124. package/src/headers/26/inspector/node_json.h +24 -0
  125. package/src/headers/26/inspector/node_string.h +101 -0
  126. package/src/headers/26/inspector/notification_emitter.h +38 -0
  127. package/src/headers/26/inspector/protocol_helper.h +27 -0
  128. package/src/headers/26/inspector/runtime_agent.h +41 -0
  129. package/src/headers/26/inspector/storage_agent.h +33 -0
  130. package/src/headers/26/inspector/target_agent.h +59 -0
  131. package/src/headers/26/inspector/target_manager.h +70 -0
  132. package/src/headers/26/inspector/tracing_agent.h +43 -0
  133. package/src/headers/26/inspector/worker_agent.h +40 -0
  134. package/src/headers/26/inspector/worker_inspector.h +124 -0
  135. package/src/headers/26/inspector_agent.h +168 -0
  136. package/src/headers/26/inspector_io.h +78 -0
  137. package/src/headers/26/inspector_profiler.h +149 -0
  138. package/src/headers/26/inspector_socket.h +60 -0
  139. package/src/headers/26/inspector_socket_server.h +110 -0
  140. package/src/headers/26/js_native_api.h +634 -0
  141. package/src/headers/26/js_native_api_types.h +244 -0
  142. package/src/headers/26/js_native_api_v8.h +485 -0
  143. package/src/headers/26/js_native_api_v8_internals.h +45 -0
  144. package/src/headers/26/js_stream.h +57 -0
  145. package/src/headers/26/json_utils.h +172 -0
  146. package/src/headers/26/large_pages/node_large_page.h +34 -0
  147. package/src/headers/26/lru_cache-inl.h +69 -0
  148. package/src/headers/26/memory_tracker-inl.h +461 -0
  149. package/src/headers/26/memory_tracker.h +341 -0
  150. package/src/headers/26/module_wrap.h +231 -0
  151. package/src/headers/26/ncrypto.h +2008 -0
  152. package/src/headers/26/node.h +1693 -0
  153. package/src/headers/26/node_api.h +265 -0
  154. package/src/headers/26/node_api_internals.h +48 -0
  155. package/src/headers/26/node_api_types.h +58 -0
  156. package/src/headers/26/node_binding.h +170 -0
  157. package/src/headers/26/node_blob.h +160 -0
  158. package/src/headers/26/node_bob-inl.h +36 -0
  159. package/src/headers/26/node_bob.h +107 -0
  160. package/src/headers/26/node_buffer.h +92 -0
  161. package/src/headers/26/node_builtins.h +239 -0
  162. package/src/headers/26/node_concepts.h +46 -0
  163. package/src/headers/26/node_config_file.h +77 -0
  164. package/src/headers/26/node_constants.h +82 -0
  165. package/src/headers/26/node_context_data.h +171 -0
  166. package/src/headers/26/node_contextify.h +261 -0
  167. package/src/headers/26/node_crypto.h +66 -0
  168. package/src/headers/26/node_debug.h +30 -0
  169. package/src/headers/26/node_diagnostics_channel.h +121 -0
  170. package/src/headers/26/node_dir.h +52 -0
  171. package/src/headers/26/node_dotenv.h +45 -0
  172. package/src/headers/26/node_errors.h +378 -0
  173. package/src/headers/26/node_exit_code.h +54 -0
  174. package/src/headers/26/node_external_reference.h +171 -0
  175. package/src/headers/26/node_ffi.h +212 -0
  176. package/src/headers/26/node_file-inl.h +421 -0
  177. package/src/headers/26/node_file.h +561 -0
  178. package/src/headers/26/node_file_utils.h +39 -0
  179. package/src/headers/26/node_hash.h +212 -0
  180. package/src/headers/26/node_http2.h +1202 -0
  181. package/src/headers/26/node_http2_state.h +159 -0
  182. package/src/headers/26/node_http_common-inl.h +199 -0
  183. package/src/headers/26/node_http_common.h +535 -0
  184. package/src/headers/26/node_i18n.h +132 -0
  185. package/src/headers/26/node_internals.h +485 -0
  186. package/src/headers/26/node_locks.h +184 -0
  187. package/src/headers/26/node_main_instance.h +67 -0
  188. package/src/headers/26/node_mem-inl.h +113 -0
  189. package/src/headers/26/node_mem.h +45 -0
  190. package/src/headers/26/node_messaging.h +389 -0
  191. package/src/headers/26/node_metadata.h +172 -0
  192. package/src/headers/26/node_modules.h +102 -0
  193. package/src/headers/26/node_mutex.h +323 -0
  194. package/src/headers/26/node_object_wrap.h +145 -0
  195. package/src/headers/26/node_options-inl.h +524 -0
  196. package/src/headers/26/node_options.h +710 -0
  197. package/src/headers/26/node_perf.h +167 -0
  198. package/src/headers/26/node_perf_common.h +103 -0
  199. package/src/headers/26/node_platform.h +290 -0
  200. package/src/headers/26/node_process-inl.h +26 -0
  201. package/src/headers/26/node_process.h +112 -0
  202. package/src/headers/26/node_profiling.h +38 -0
  203. package/src/headers/26/node_realm-inl.h +156 -0
  204. package/src/headers/26/node_realm.h +236 -0
  205. package/src/headers/26/node_report.h +43 -0
  206. package/src/headers/26/node_revert.h +82 -0
  207. package/src/headers/26/node_root_certs.h +2937 -0
  208. package/src/headers/26/node_sea.h +101 -0
  209. package/src/headers/26/node_shadow_realm.h +46 -0
  210. package/src/headers/26/node_snapshot_builder.h +57 -0
  211. package/src/headers/26/node_snapshotable.h +167 -0
  212. package/src/headers/26/node_sockaddr-inl.h +248 -0
  213. package/src/headers/26/node_sockaddr.h +459 -0
  214. package/src/headers/26/node_sqlite.h +607 -0
  215. package/src/headers/26/node_stat_watcher.h +73 -0
  216. package/src/headers/26/node_task_runner.h +92 -0
  217. package/src/headers/26/node_threadsafe_cow-inl.h +54 -0
  218. package/src/headers/26/node_threadsafe_cow.h +105 -0
  219. package/src/headers/26/node_union_bytes.h +81 -0
  220. package/src/headers/26/node_url.h +101 -0
  221. package/src/headers/26/node_url_pattern.h +118 -0
  222. package/src/headers/26/node_v8.h +78 -0
  223. package/src/headers/26/node_v8_embedder.h +26 -0
  224. package/src/headers/26/node_v8_platform-inl.h +96 -0
  225. package/src/headers/26/node_version.h +116 -0
  226. package/src/headers/26/node_wasi.h +184 -0
  227. package/src/headers/26/node_wasm_web_api.h +55 -0
  228. package/src/headers/26/node_watchdog.h +164 -0
  229. package/src/headers/26/node_webstorage.h +62 -0
  230. package/src/headers/26/node_worker.h +162 -0
  231. package/src/headers/26/path.h +36 -0
  232. package/src/headers/26/permission/boolean_permission.h +50 -0
  233. package/src/headers/26/permission/fs_permission.h +192 -0
  234. package/src/headers/26/permission/permission.h +155 -0
  235. package/src/headers/26/permission/permission_base.h +79 -0
  236. package/src/headers/26/pipe_wrap.h +80 -0
  237. package/src/headers/26/quic/application.h +279 -0
  238. package/src/headers/26/quic/arena.h +373 -0
  239. package/src/headers/26/quic/bindingdata.h +440 -0
  240. package/src/headers/26/quic/cid.h +127 -0
  241. package/src/headers/26/quic/data.h +358 -0
  242. package/src/headers/26/quic/defs.h +417 -0
  243. package/src/headers/26/quic/endpoint.h +519 -0
  244. package/src/headers/26/quic/guard.h +5 -0
  245. package/src/headers/26/quic/http3.h +25 -0
  246. package/src/headers/26/quic/packet.h +166 -0
  247. package/src/headers/26/quic/preferredaddress.h +72 -0
  248. package/src/headers/26/quic/session.h +770 -0
  249. package/src/headers/26/quic/session_manager.h +107 -0
  250. package/src/headers/26/quic/sessionticket.h +110 -0
  251. package/src/headers/26/quic/streams.h +518 -0
  252. package/src/headers/26/quic/tlscontext.h +353 -0
  253. package/src/headers/26/quic/tokens.h +263 -0
  254. package/src/headers/26/quic/transportparams.h +184 -0
  255. package/src/headers/26/req_wrap-inl.h +175 -0
  256. package/src/headers/26/req_wrap.h +79 -0
  257. package/src/headers/26/spawn_sync.h +243 -0
  258. package/src/headers/26/stream_base-inl.h +170 -0
  259. package/src/headers/26/stream_base.h +487 -0
  260. package/src/headers/26/stream_pipe.h +76 -0
  261. package/src/headers/26/stream_wrap.h +137 -0
  262. package/src/headers/26/string_bytes.h +114 -0
  263. package/src/headers/26/string_decoder-inl.h +31 -0
  264. package/src/headers/26/string_decoder.h +49 -0
  265. package/src/headers/26/tcp_wrap.h +138 -0
  266. package/src/headers/26/threadpoolwork-inl.h +70 -0
  267. package/src/headers/26/timer_wrap-inl.h +32 -0
  268. package/src/headers/26/timer_wrap.h +87 -0
  269. package/src/headers/26/timers.h +70 -0
  270. package/src/headers/26/tracing/agent.h +125 -0
  271. package/src/headers/26/tracing/agent_legacy.h +146 -0
  272. package/src/headers/26/tracing/agent_perfetto.h +145 -0
  273. package/src/headers/26/tracing/node_trace_buffer.h +91 -0
  274. package/src/headers/26/tracing/node_trace_writer.h +79 -0
  275. package/src/headers/26/tracing/trace_event.h +27 -0
  276. package/src/headers/26/tracing/trace_event_helper.h +40 -0
  277. package/src/headers/26/tracing/trace_event_legacy.h +1113 -0
  278. package/src/headers/26/tracing/trace_event_legacy_inl.h +711 -0
  279. package/src/headers/26/tracing/trace_event_perfetto.h +47 -0
  280. package/src/headers/26/tracing/traced_value.h +167 -0
  281. package/src/headers/26/tty_wrap.h +65 -0
  282. package/src/headers/26/udp_wrap.h +231 -0
  283. package/src/headers/26/undici_version.h +6 -0
  284. package/src/headers/26/util-inl.h +788 -0
  285. package/src/headers/26/util.h +1207 -0
  286. package/src/headers/26/v8-cpp-heap-external.h +56 -0
  287. package/src/headers/26/v8-external-memory-accounter.h +60 -0
  288. package/src/headers/26/v8-fast-api-calls.h +784 -0
  289. package/src/headers/26/v8-inspector-protocol.h +13 -0
  290. package/src/headers/26/v8-inspector.h +458 -0
  291. package/src/headers/26/v8-metrics.h +273 -0
  292. package/src/headers/26/v8-trace-categories.h +28 -0
  293. package/src/headers/26/v8-unwinder-state.h +30 -0
  294. package/src/headers/26/v8-util.h +549 -0
  295. package/src/headers/26/v8-value-serializer-version.h +24 -0
  296. package/src/headers/26/v8-version-string.h +38 -0
  297. package/src/headers/26/v8-wasm-trap-handler-posix.h +31 -0
  298. package/src/headers/26/v8-wasm-trap-handler-win.h +28 -0
  299. package/src/headers/26/zlib_version.h +6 -0
  300. package/dist/bindings/cws_darwin_arm64_node115.node.dSYM/Contents/Info.plist +0 -20
  301. package/dist/bindings/cws_darwin_arm64_node115.node.dSYM/Contents/Resources/DWARF/cws_darwin_arm64_node115.node +0 -0
  302. package/dist/bindings/cws_darwin_arm64_node115.node.dSYM/Contents/Resources/Relocations/aarch64/cws_darwin_arm64_node115.node.yml +0 -931
  303. package/dist/bindings/cws_darwin_arm64_node127.node.dSYM/Contents/Info.plist +0 -20
  304. package/dist/bindings/cws_darwin_arm64_node127.node.dSYM/Contents/Resources/DWARF/cws_darwin_arm64_node127.node +0 -0
  305. package/dist/bindings/cws_darwin_arm64_node127.node.dSYM/Contents/Resources/Relocations/aarch64/cws_darwin_arm64_node127.node.yml +0 -931
@@ -0,0 +1,219 @@
1
+ #ifndef SRC_CRYPTO_CRYPTO_CONTEXT_H_
2
+ #define SRC_CRYPTO_CRYPTO_CONTEXT_H_
3
+
4
+ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
+
6
+ #include "base_object.h"
7
+ #include "crypto/crypto_keys.h"
8
+ #include "crypto/crypto_util.h"
9
+ #include "env.h"
10
+ #include "memory_tracker.h"
11
+ #include "v8.h"
12
+
13
+ #ifdef NODE_OPENSSL_HAS_CERT_COMP
14
+ #include <vector>
15
+ #endif
16
+
17
+ namespace node {
18
+ namespace crypto {
19
+ // A maxVersion of 0 means "any", but OpenSSL may support TLS versions that
20
+ // Node.js doesn't, so pin the max to what we do support.
21
+ constexpr int kMaxSupportedVersion = TLS1_3_VERSION;
22
+
23
+ void GetRootCertificates(
24
+ const v8::FunctionCallbackInfo<v8::Value>& args);
25
+
26
+ X509_STORE* NewRootCertStore(Environment* env);
27
+
28
+ X509_STORE* GetOrCreateRootCertStore(Environment* env);
29
+
30
+ ncrypto::BIOPointer LoadBIO(Environment* env, v8::Local<v8::Value> v);
31
+
32
+ class SecureContext final : public BaseObject {
33
+ public:
34
+ using GetSessionCb = SSL_SESSION* (*)(SSL*, const unsigned char*, int, int*);
35
+ using KeylogCb = void (*)(const SSL*, const char*);
36
+ using NewSessionCb = int (*)(SSL*, SSL_SESSION*);
37
+ using SelectSNIContextCb = int (*)(SSL*, int*, void*);
38
+ #ifdef OPENSSL_IS_BORINGSSL
39
+ using ClientHelloCb = ssl_select_cert_result_t (*)(const SSL_CLIENT_HELLO*);
40
+ #else
41
+ using ClientHelloCb = int (*)(SSL*, int*, void*);
42
+ #endif
43
+
44
+ ~SecureContext() override;
45
+
46
+ static bool HasInstance(Environment* env, const v8::Local<v8::Value>& value);
47
+ static v8::Local<v8::FunctionTemplate> GetConstructorTemplate(
48
+ Environment* env);
49
+ static void Initialize(Environment* env, v8::Local<v8::Object> target);
50
+ static void RegisterExternalReferences(ExternalReferenceRegistry* registry);
51
+ static SecureContext* Create(Environment* env);
52
+
53
+ const ncrypto::SSLCtxPointer& ctx() const { return ctx_; }
54
+
55
+ // Non-const ctx() that allows for non-default initialization of
56
+ // the SecureContext.
57
+ ncrypto::SSLCtxPointer& ctx() { return ctx_; }
58
+
59
+ #ifdef NODE_OPENSSL_HAS_CERT_COMP
60
+ bool HasCertCompression() const {
61
+ return cert_comp_prefs_len_ > 0;
62
+ }
63
+ int* CertCompPrefs() {
64
+ return cert_comp_prefs_;
65
+ }
66
+ size_t CertCompPrefsLen() const {
67
+ return cert_comp_prefs_len_;
68
+ }
69
+
70
+ struct CompressedCertData {
71
+ int algorithm;
72
+ std::vector<unsigned char> data;
73
+ size_t orig_length;
74
+ };
75
+ const std::vector<CompressedCertData>& CompressedCerts() const {
76
+ return compressed_certs_;
77
+ }
78
+ #endif
79
+
80
+ ncrypto::SSLPointer CreateSSL();
81
+
82
+ void SetClientHelloCallback(ClientHelloCb cb);
83
+ void SetGetSessionCallback(GetSessionCb cb);
84
+ void SetKeylogCallback(KeylogCb cb);
85
+ void SetNewSessionCallback(NewSessionCb cb);
86
+ void SetSelectSNIContextCallback(SelectSNIContextCb cb);
87
+
88
+ inline const ncrypto::X509Pointer& issuer() const { return issuer_; }
89
+ inline const ncrypto::X509Pointer& cert() const { return cert_; }
90
+
91
+ v8::Maybe<void> AddCert(Environment* env, ncrypto::BIOPointer&& bio);
92
+ v8::Maybe<void> SetCRL(Environment* env, const ncrypto::BIOPointer& bio);
93
+ v8::Maybe<void> UseKey(Environment* env, const KeyObjectData& key);
94
+
95
+ void SetCACert(const ncrypto::BIOPointer& bio);
96
+ void SetRootCerts();
97
+
98
+ void SetX509StoreFlag(unsigned long flags); // NOLINT(runtime/int)
99
+ X509_STORE* GetCertStoreOwnedByThisSecureContext();
100
+
101
+ void MemoryInfo(MemoryTracker* tracker) const override;
102
+ SET_MEMORY_INFO_NAME(SecureContext)
103
+ SET_SELF_SIZE(SecureContext)
104
+
105
+ static const int kMaxSessionSize = 10 * 1024;
106
+
107
+ // See TicketKeyCallback
108
+ static const int kTicketKeyReturnIndex = 0;
109
+ static const int kTicketKeyHMACIndex = 1;
110
+ static const int kTicketKeyAESIndex = 2;
111
+ static const int kTicketKeyNameIndex = 3;
112
+ static const int kTicketKeyIVIndex = 4;
113
+
114
+ protected:
115
+ // OpenSSL structures are opaque. This is sizeof(SSL_CTX) for OpenSSL 1.1.1b:
116
+ static const int64_t kExternalSize = 1024;
117
+
118
+ static void New(const v8::FunctionCallbackInfo<v8::Value>& args);
119
+ static void Init(const v8::FunctionCallbackInfo<v8::Value>& args);
120
+ static void SetKey(const v8::FunctionCallbackInfo<v8::Value>& args);
121
+ #ifndef OPENSSL_NO_ENGINE
122
+ static void SetEngineKey(const v8::FunctionCallbackInfo<v8::Value>& args);
123
+ #endif // !OPENSSL_NO_ENGINE
124
+ static void SetCert(const v8::FunctionCallbackInfo<v8::Value>& args);
125
+ static void AddCACert(const v8::FunctionCallbackInfo<v8::Value>& args);
126
+ static void SetAllowPartialTrustChain(
127
+ const v8::FunctionCallbackInfo<v8::Value>& args);
128
+ static void AddCRL(const v8::FunctionCallbackInfo<v8::Value>& args);
129
+ static void AddRootCerts(const v8::FunctionCallbackInfo<v8::Value>& args);
130
+ static void SetCipherSuites(const v8::FunctionCallbackInfo<v8::Value>& args);
131
+ static void SetCiphers(const v8::FunctionCallbackInfo<v8::Value>& args);
132
+ static void SetSigalgs(const v8::FunctionCallbackInfo<v8::Value>& args);
133
+ static void SetECDHCurve(const v8::FunctionCallbackInfo<v8::Value>& args);
134
+ static void SetDHParam(const v8::FunctionCallbackInfo<v8::Value>& args);
135
+ static void SetOptions(const v8::FunctionCallbackInfo<v8::Value>& args);
136
+ static void SetSessionIdContext(
137
+ const v8::FunctionCallbackInfo<v8::Value>& args);
138
+ static void SetSessionTimeout(
139
+ const v8::FunctionCallbackInfo<v8::Value>& args);
140
+ static void SetCertificateCompression(
141
+ const v8::FunctionCallbackInfo<v8::Value>& args);
142
+ static void GetCertificateCompressionAlgorithms(
143
+ const v8::FunctionCallbackInfo<v8::Value>& args);
144
+ static void SetMinProto(const v8::FunctionCallbackInfo<v8::Value>& args);
145
+ static void SetMaxProto(const v8::FunctionCallbackInfo<v8::Value>& args);
146
+ static void GetMinProto(const v8::FunctionCallbackInfo<v8::Value>& args);
147
+ static void GetMaxProto(const v8::FunctionCallbackInfo<v8::Value>& args);
148
+ static void Close(const v8::FunctionCallbackInfo<v8::Value>& args);
149
+ static void LoadPKCS12(const v8::FunctionCallbackInfo<v8::Value>& args);
150
+ #ifndef OPENSSL_NO_ENGINE
151
+ static void SetClientCertEngine(
152
+ const v8::FunctionCallbackInfo<v8::Value>& args);
153
+ #endif // !OPENSSL_NO_ENGINE
154
+ static void GetTicketKeys(const v8::FunctionCallbackInfo<v8::Value>& args);
155
+ static void SetTicketKeys(const v8::FunctionCallbackInfo<v8::Value>& args);
156
+ static void EnableTicketKeyCallback(
157
+ const v8::FunctionCallbackInfo<v8::Value>& args);
158
+ static void CtxGetter(const v8::FunctionCallbackInfo<v8::Value>& info);
159
+
160
+ template <bool primary>
161
+ static void GetCertificate(const v8::FunctionCallbackInfo<v8::Value>& args);
162
+
163
+ static int TicketKeyCallback(SSL* ssl,
164
+ unsigned char* name,
165
+ unsigned char* iv,
166
+ EVP_CIPHER_CTX* ectx,
167
+ #if NCRYPTO_USE_OPENSSL3_PROVIDER
168
+ EVP_MAC_CTX* hctx,
169
+ #else
170
+ HMAC_CTX* hctx,
171
+ #endif
172
+ int enc);
173
+
174
+ static int TicketCompatibilityCallback(SSL* ssl,
175
+ unsigned char* name,
176
+ unsigned char* iv,
177
+ EVP_CIPHER_CTX* ectx,
178
+ #if NCRYPTO_USE_OPENSSL3_PROVIDER
179
+ EVP_MAC_CTX* hctx,
180
+ #else
181
+ HMAC_CTX* hctx,
182
+ #endif
183
+ int enc);
184
+
185
+ SecureContext(Environment* env, v8::Local<v8::Object> wrap);
186
+ void Reset();
187
+
188
+ private:
189
+ ncrypto::SSLCtxPointer ctx_;
190
+ ncrypto::X509Pointer cert_;
191
+ ncrypto::X509Pointer issuer_;
192
+ // Non-owning cache for SSL_CTX_get_cert_store(ctx_.get())
193
+ X509_STORE* own_cert_store_cache_ = nullptr;
194
+ #ifndef OPENSSL_NO_ENGINE
195
+ bool client_cert_engine_provided_ = false;
196
+ ncrypto::EnginePointer private_key_engine_;
197
+ #endif // !OPENSSL_NO_ENGINE
198
+
199
+ unsigned char ticket_key_name_[16];
200
+ unsigned char ticket_key_aes_[16];
201
+ unsigned char ticket_key_hmac_[16];
202
+
203
+ #ifdef NODE_OPENSSL_HAS_CERT_COMP
204
+ int cert_comp_prefs_[TLSEXT_comp_cert_limit] = {};
205
+ size_t cert_comp_prefs_len_ = 0;
206
+ std::vector<CompressedCertData> compressed_certs_;
207
+ #endif
208
+ };
209
+
210
+ int SSL_CTX_use_certificate_chain(SSL_CTX* ctx,
211
+ ncrypto::BIOPointer&& in,
212
+ ncrypto::X509Pointer* cert,
213
+ ncrypto::X509Pointer* issuer);
214
+
215
+ } // namespace crypto
216
+ } // namespace node
217
+
218
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
219
+ #endif // SRC_CRYPTO_CRYPTO_CONTEXT_H_
@@ -0,0 +1,104 @@
1
+ #ifndef SRC_CRYPTO_CRYPTO_DH_H_
2
+ #define SRC_CRYPTO_CRYPTO_DH_H_
3
+
4
+ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
+
6
+ #include "crypto/crypto_keys.h"
7
+ #include "crypto/crypto_keygen.h"
8
+ #include "crypto/crypto_util.h"
9
+ #include "env.h"
10
+ #include "memory_tracker.h"
11
+ #include "v8.h"
12
+
13
+ #include <variant>
14
+
15
+ namespace node {
16
+ namespace crypto {
17
+ class DiffieHellman final : public BaseObject {
18
+ public:
19
+ static void Initialize(Environment* env, v8::Local<v8::Object> target);
20
+ static void RegisterExternalReferences(ExternalReferenceRegistry* registry);
21
+
22
+ DiffieHellman(Environment* env,
23
+ v8::Local<v8::Object> wrap,
24
+ ncrypto::DHPointer dh);
25
+ operator ncrypto::DHPointer&() { return dh_; }
26
+
27
+ void MemoryInfo(MemoryTracker* tracker) const override;
28
+ SET_MEMORY_INFO_NAME(DiffieHellman)
29
+ SET_SELF_SIZE(DiffieHellman)
30
+
31
+ private:
32
+ ncrypto::DHPointer dh_;
33
+ };
34
+
35
+ struct DhKeyPairParams final : public MemoryRetainer {
36
+ // Diffie-Hellman can either generate keys using a fixed prime, or by first
37
+ // generating a random prime of a given size (in bits). Only one of both
38
+ // options may be specified.
39
+ std::variant<ncrypto::BignumPointer, int> prime;
40
+ unsigned int generator;
41
+ SET_NO_MEMORY_INFO()
42
+ SET_MEMORY_INFO_NAME(DhKeyPairParams)
43
+ SET_SELF_SIZE(DhKeyPairParams)
44
+ };
45
+
46
+ using DhKeyPairGenConfig = KeyPairGenConfig<DhKeyPairParams>;
47
+
48
+ struct DhKeyGenTraits final {
49
+ using AdditionalParameters = DhKeyPairGenConfig;
50
+ static constexpr const char* JobName = "DhKeyPairGenJob";
51
+
52
+ static ncrypto::EVPKeyCtxPointer Setup(DhKeyPairGenConfig* params);
53
+
54
+ static v8::Maybe<void> AdditionalConfig(
55
+ CryptoJobMode mode,
56
+ const v8::FunctionCallbackInfo<v8::Value>& args,
57
+ unsigned int* offset,
58
+ DhKeyPairGenConfig* params);
59
+ };
60
+
61
+ using DHKeyPairGenJob = KeyGenJob<KeyPairGenTraits<DhKeyGenTraits>>;
62
+
63
+ struct DHBitsConfig final : public MemoryRetainer {
64
+ KeyObjectData private_key;
65
+ KeyObjectData public_key;
66
+ SET_NO_MEMORY_INFO()
67
+ SET_MEMORY_INFO_NAME(DHBitsConfig)
68
+ SET_SELF_SIZE(DHBitsConfig)
69
+ };
70
+
71
+ struct DHBitsTraits final {
72
+ using AdditionalParameters = DHBitsConfig;
73
+ static constexpr const char* JobName = "DHBitsJob";
74
+ static constexpr AsyncWrap::ProviderType Provider =
75
+ AsyncWrap::PROVIDER_DERIVEBITSREQUEST;
76
+
77
+ static v8::Maybe<void> AdditionalConfig(
78
+ CryptoJobMode mode,
79
+ const v8::FunctionCallbackInfo<v8::Value>& args,
80
+ unsigned int offset,
81
+ DHBitsConfig* params);
82
+
83
+ static bool DeriveBits(Environment* env,
84
+ const DHBitsConfig& params,
85
+ ByteSource* out_,
86
+ CryptoJobMode mode,
87
+ CryptoErrorStore* errors);
88
+
89
+ static v8::MaybeLocal<v8::Value> EncodeOutput(Environment* env,
90
+ const DHBitsConfig& params,
91
+ ByteSource* out);
92
+ };
93
+
94
+ using DHBitsJob = DeriveBitsJob<DHBitsTraits>;
95
+
96
+ bool GetDhKeyDetail(Environment* env,
97
+ const KeyObjectData& key,
98
+ v8::Local<v8::Object> target);
99
+
100
+ } // namespace crypto
101
+ } // namespace node
102
+
103
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
104
+ #endif // SRC_CRYPTO_CRYPTO_DH_H_
@@ -0,0 +1,50 @@
1
+ #ifndef SRC_CRYPTO_CRYPTO_DSA_H_
2
+ #define SRC_CRYPTO_CRYPTO_DSA_H_
3
+
4
+ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
+
6
+ #include "crypto/crypto_keys.h"
7
+ #include "crypto/crypto_keygen.h"
8
+ #include "crypto/crypto_util.h"
9
+ #include "env.h"
10
+ #include "memory_tracker.h"
11
+ #include "v8.h"
12
+
13
+ namespace node::crypto {
14
+ struct DsaKeyPairParams final : public MemoryRetainer {
15
+ unsigned int modulus_bits;
16
+ int divisor_bits;
17
+ SET_NO_MEMORY_INFO()
18
+ SET_MEMORY_INFO_NAME(DsaKeyPairParams)
19
+ SET_SELF_SIZE(DsaKeyPairParams)
20
+ };
21
+
22
+ using DsaKeyPairGenConfig = KeyPairGenConfig<DsaKeyPairParams>;
23
+
24
+ struct DsaKeyGenTraits final {
25
+ using AdditionalParameters = DsaKeyPairGenConfig;
26
+ static constexpr const char* JobName = "DsaKeyPairGenJob";
27
+
28
+ static ncrypto::EVPKeyCtxPointer Setup(DsaKeyPairGenConfig* params);
29
+
30
+ static v8::Maybe<void> AdditionalConfig(
31
+ CryptoJobMode mode,
32
+ const v8::FunctionCallbackInfo<v8::Value>& args,
33
+ unsigned int* offset,
34
+ DsaKeyPairGenConfig* params);
35
+ };
36
+
37
+ using DsaKeyPairGenJob = KeyGenJob<KeyPairGenTraits<DsaKeyGenTraits>>;
38
+
39
+ bool GetDsaKeyDetail(Environment* env,
40
+ const KeyObjectData& key,
41
+ v8::Local<v8::Object> target);
42
+
43
+ namespace DSAAlg {
44
+ void Initialize(Environment* env, v8::Local<v8::Object> target);
45
+ void RegisterExternalReferences(ExternalReferenceRegistry* registry);
46
+ } // namespace DSAAlg
47
+ } // namespace node::crypto
48
+
49
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
50
+ #endif // SRC_CRYPTO_CRYPTO_DSA_H_
@@ -0,0 +1,102 @@
1
+ #ifndef SRC_CRYPTO_CRYPTO_EC_H_
2
+ #define SRC_CRYPTO_CRYPTO_EC_H_
3
+
4
+ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
+
6
+ #include "async_wrap.h"
7
+ #include "base_object.h"
8
+ #include "crypto/crypto_keygen.h"
9
+ #include "crypto/crypto_keys.h"
10
+ #include "crypto/crypto_util.h"
11
+ #include "env.h"
12
+ #include "memory_tracker.h"
13
+ #include "node_internals.h"
14
+ #include "v8.h"
15
+
16
+ namespace node {
17
+ namespace crypto {
18
+
19
+ class ECDH final : public BaseObject {
20
+ public:
21
+ ~ECDH() override = default;
22
+
23
+ static void Initialize(Environment* env, v8::Local<v8::Object> target);
24
+ static void RegisterExternalReferences(ExternalReferenceRegistry* registry);
25
+
26
+ static ncrypto::ECPointPointer BufferToPoint(Environment* env,
27
+ const EC_GROUP* group,
28
+ v8::Local<v8::Value> buf);
29
+
30
+ void MemoryInfo(MemoryTracker* tracker) const override;
31
+ SET_MEMORY_INFO_NAME(ECDH)
32
+ SET_SELF_SIZE(ECDH)
33
+
34
+ static void ConvertKey(const v8::FunctionCallbackInfo<v8::Value>& args);
35
+
36
+ static void GetCurves(const v8::FunctionCallbackInfo<v8::Value>& args);
37
+
38
+ protected:
39
+ ECDH(Environment* env,
40
+ v8::Local<v8::Object> wrap,
41
+ ncrypto::ECKeyPointer&& key);
42
+
43
+ static void New(const v8::FunctionCallbackInfo<v8::Value>& args);
44
+ static void GenerateKeys(const v8::FunctionCallbackInfo<v8::Value>& args);
45
+ static void ComputeSecret(const v8::FunctionCallbackInfo<v8::Value>& args);
46
+ static void GetPrivateKey(const v8::FunctionCallbackInfo<v8::Value>& args);
47
+ static void SetPrivateKey(const v8::FunctionCallbackInfo<v8::Value>& args);
48
+ static void GetPublicKey(const v8::FunctionCallbackInfo<v8::Value>& args);
49
+ static void SetPublicKey(const v8::FunctionCallbackInfo<v8::Value>& args);
50
+
51
+ bool IsKeyPairValid();
52
+ bool IsKeyValidForCurve(const ncrypto::BignumPointer& private_key);
53
+
54
+ ncrypto::ECKeyPointer key_;
55
+ const EC_GROUP* group_;
56
+ };
57
+
58
+ struct EcKeyPairParams final : public MemoryRetainer {
59
+ int curve_nid;
60
+ int param_encoding;
61
+ SET_NO_MEMORY_INFO()
62
+ SET_MEMORY_INFO_NAME(EcKeyPairParams)
63
+ SET_SELF_SIZE(EcKeyPairParams)
64
+ };
65
+
66
+ using EcKeyPairGenConfig = KeyPairGenConfig<EcKeyPairParams>;
67
+
68
+ struct EcKeyGenTraits final {
69
+ using AdditionalParameters = EcKeyPairGenConfig;
70
+ static constexpr const char* JobName = "EcKeyPairGenJob";
71
+
72
+ static ncrypto::EVPKeyCtxPointer Setup(EcKeyPairGenConfig* params);
73
+
74
+ static v8::Maybe<void> AdditionalConfig(
75
+ CryptoJobMode mode,
76
+ const v8::FunctionCallbackInfo<v8::Value>& args,
77
+ unsigned int* offset,
78
+ EcKeyPairGenConfig* params);
79
+ };
80
+
81
+ using ECKeyPairGenJob = KeyGenJob<KeyPairGenTraits<EcKeyGenTraits>>;
82
+
83
+ bool ExportJWKEcKey(Environment* env,
84
+ const KeyObjectData& key,
85
+ v8::Local<v8::Object> target);
86
+
87
+ bool ExportJWKEdKey(Environment* env,
88
+ const KeyObjectData& key,
89
+ v8::Local<v8::Object> target);
90
+
91
+ KeyObjectData ImportJWKEdKey(Environment* env, v8::Local<v8::Object> jwk);
92
+
93
+ KeyObjectData ImportJWKEcKey(Environment* env, v8::Local<v8::Object> jwk);
94
+
95
+ bool GetEcKeyDetail(Environment* env,
96
+ const KeyObjectData& key,
97
+ v8::Local<v8::Object> target);
98
+ } // namespace crypto
99
+ } // namespace node
100
+
101
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
102
+ #endif // SRC_CRYPTO_CRYPTO_EC_H_
@@ -0,0 +1,157 @@
1
+ #ifndef SRC_CRYPTO_CRYPTO_HASH_H_
2
+ #define SRC_CRYPTO_CRYPTO_HASH_H_
3
+
4
+ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
+
6
+ #include "base_object.h"
7
+ #include "crypto/crypto_keys.h"
8
+ #include "crypto/crypto_util.h"
9
+ #include "env.h"
10
+ #include "memory_tracker.h"
11
+ #include "v8.h"
12
+
13
+ namespace node {
14
+ namespace crypto {
15
+ class Hash final : public BaseObject {
16
+ public:
17
+ static void Initialize(Environment* env, v8::Local<v8::Object> target);
18
+ static void RegisterExternalReferences(ExternalReferenceRegistry* registry);
19
+
20
+ void MemoryInfo(MemoryTracker* tracker) const override;
21
+ SET_MEMORY_INFO_NAME(Hash)
22
+ SET_SELF_SIZE(Hash)
23
+
24
+ bool HashInit(const EVP_MD* md, v8::Maybe<unsigned int> xof_md_len);
25
+ bool HashUpdate(const char* data, size_t len);
26
+
27
+ static void GetHashes(const v8::FunctionCallbackInfo<v8::Value>& args);
28
+ static void GetCachedAliases(const v8::FunctionCallbackInfo<v8::Value>& args);
29
+ static void OneShotDigest(const v8::FunctionCallbackInfo<v8::Value>& args);
30
+
31
+ protected:
32
+ static void New(const v8::FunctionCallbackInfo<v8::Value>& args);
33
+ static void HashUpdate(const v8::FunctionCallbackInfo<v8::Value>& args);
34
+ static void HashDigest(const v8::FunctionCallbackInfo<v8::Value>& args);
35
+
36
+ Hash(Environment* env, v8::Local<v8::Object> wrap);
37
+
38
+ private:
39
+ ncrypto::EVPMDCtxPointer mdctx_{};
40
+ unsigned int md_len_ = 0;
41
+ ByteSource digest_;
42
+ };
43
+
44
+ struct HashConfig final : public MemoryRetainer {
45
+ ByteSource in;
46
+ const EVP_MD* digest;
47
+ unsigned int length;
48
+
49
+ HashConfig() = default;
50
+
51
+ explicit HashConfig(HashConfig&& other) noexcept;
52
+
53
+ HashConfig& operator=(HashConfig&& other) noexcept;
54
+
55
+ void MemoryInfo(MemoryTracker* tracker) const override;
56
+ SET_MEMORY_INFO_NAME(HashConfig)
57
+ SET_SELF_SIZE(HashConfig)
58
+ };
59
+
60
+ struct HashTraits final {
61
+ using AdditionalParameters = HashConfig;
62
+ static constexpr const char* JobName = "HashJob";
63
+ static constexpr AsyncWrap::ProviderType Provider =
64
+ AsyncWrap::PROVIDER_HASHREQUEST;
65
+
66
+ static v8::Maybe<void> AdditionalConfig(
67
+ CryptoJobMode mode,
68
+ const v8::FunctionCallbackInfo<v8::Value>& args,
69
+ unsigned int offset,
70
+ HashConfig* params);
71
+
72
+ static bool DeriveBits(Environment* env,
73
+ const HashConfig& params,
74
+ ByteSource* out,
75
+ CryptoJobMode mode,
76
+ CryptoErrorStore* errors);
77
+
78
+ static v8::MaybeLocal<v8::Value> EncodeOutput(Environment* env,
79
+ const HashConfig& params,
80
+ ByteSource* out);
81
+ };
82
+
83
+ using HashJob = DeriveBitsJob<HashTraits>;
84
+
85
+ #if OPENSSL_WITH_EVP_MAC
86
+ enum class CShakeVariant { CSHAKE128, CSHAKE256 };
87
+
88
+ struct CShakeBytepadInput final {
89
+ const void* data;
90
+ size_t byte_length;
91
+ size_t bit_length;
92
+ };
93
+
94
+ struct CShakeParams final {
95
+ CShakeVariant variant;
96
+ const void* function_name_data;
97
+ size_t function_name_size;
98
+ const void* customization_data;
99
+ size_t customization_size;
100
+ const CShakeBytepadInput* bytepad_input;
101
+ const void* input_data;
102
+ size_t input_size;
103
+ bool append_output_length;
104
+ uint32_t length; // Output length in bits
105
+ };
106
+
107
+ bool DeriveCShakeBits(const CShakeParams& params, ByteSource* out);
108
+
109
+ struct CShakeConfig final : public MemoryRetainer {
110
+ ByteSource in;
111
+ ByteSource function_name;
112
+ ByteSource customization;
113
+ CShakeVariant variant;
114
+ uint32_t length; // Output length in bits
115
+
116
+ CShakeConfig() = default;
117
+
118
+ explicit CShakeConfig(CShakeConfig&& other) noexcept;
119
+
120
+ CShakeConfig& operator=(CShakeConfig&& other) noexcept;
121
+
122
+ void MemoryInfo(MemoryTracker* tracker) const override;
123
+ SET_MEMORY_INFO_NAME(CShakeConfig)
124
+ SET_SELF_SIZE(CShakeConfig)
125
+ };
126
+
127
+ struct CShakeTraits final {
128
+ using AdditionalParameters = CShakeConfig;
129
+ static constexpr const char* JobName = "CShakeJob";
130
+ static constexpr AsyncWrap::ProviderType Provider =
131
+ AsyncWrap::PROVIDER_HASHREQUEST;
132
+
133
+ static v8::Maybe<void> AdditionalConfig(
134
+ CryptoJobMode mode,
135
+ const v8::FunctionCallbackInfo<v8::Value>& args,
136
+ unsigned int offset,
137
+ CShakeConfig* params);
138
+
139
+ static bool DeriveBits(Environment* env,
140
+ const CShakeConfig& params,
141
+ ByteSource* out,
142
+ CryptoJobMode mode,
143
+ CryptoErrorStore* errors);
144
+
145
+ static v8::MaybeLocal<v8::Value> EncodeOutput(Environment* env,
146
+ const CShakeConfig& params,
147
+ ByteSource* out);
148
+ };
149
+
150
+ using CShakeJob = DeriveBitsJob<CShakeTraits>;
151
+ #endif // OPENSSL_WITH_EVP_MAC
152
+
153
+ } // namespace crypto
154
+ } // namespace node
155
+
156
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
157
+ #endif // SRC_CRYPTO_CRYPTO_HASH_H_
@@ -0,0 +1,62 @@
1
+ #ifndef SRC_CRYPTO_CRYPTO_HKDF_H_
2
+ #define SRC_CRYPTO_CRYPTO_HKDF_H_
3
+
4
+ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
+
6
+ #include "async_wrap.h"
7
+ #include "base_object.h"
8
+ #include "crypto/crypto_keys.h"
9
+ #include "crypto/crypto_util.h"
10
+ #include "v8.h"
11
+
12
+ namespace node {
13
+ namespace crypto {
14
+ struct HKDFConfig final : public MemoryRetainer {
15
+ size_t length;
16
+ ncrypto::Digest digest;
17
+ KeyObjectData key;
18
+ ByteSource key_data;
19
+ ByteSource salt;
20
+ ByteSource info;
21
+
22
+ HKDFConfig() = default;
23
+
24
+ explicit HKDFConfig(HKDFConfig&& other) noexcept;
25
+
26
+ HKDFConfig& operator=(HKDFConfig&& other) noexcept;
27
+
28
+ void MemoryInfo(MemoryTracker* tracker) const override;
29
+ SET_MEMORY_INFO_NAME(HKDFConfig)
30
+ SET_SELF_SIZE(HKDFConfig)
31
+ };
32
+
33
+ struct HKDFTraits final {
34
+ using AdditionalParameters = HKDFConfig;
35
+ static constexpr const char* JobName = "HKDFJob";
36
+ static constexpr AsyncWrap::ProviderType Provider =
37
+ AsyncWrap::PROVIDER_DERIVEBITSREQUEST;
38
+
39
+ static v8::Maybe<void> AdditionalConfig(
40
+ CryptoJobMode mode,
41
+ const v8::FunctionCallbackInfo<v8::Value>& args,
42
+ unsigned int offset,
43
+ HKDFConfig* params);
44
+
45
+ static bool DeriveBits(Environment* env,
46
+ const HKDFConfig& params,
47
+ ByteSource* out,
48
+ CryptoJobMode mode,
49
+ CryptoErrorStore* errors);
50
+
51
+ static v8::MaybeLocal<v8::Value> EncodeOutput(Environment* env,
52
+ const HKDFConfig& params,
53
+ ByteSource* out);
54
+ };
55
+
56
+ using HKDFJob = DeriveBitsJob<HKDFTraits>;
57
+
58
+ } // namespace crypto
59
+ } // namespace node
60
+
61
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
62
+ #endif // SRC_CRYPTO_CRYPTO_HKDF_H_