@encharm/cws 4.3.0 → 4.4.1

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