@kungfu-tech/libnode-win32-x64 0.0.0-bootstrap.0 → 22.22.3-kf.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.
- package/LICENSE +201 -0
- package/README.md +3 -0
- package/dist/node/include/acorn_version.h +6 -0
- package/dist/node/include/aliased_buffer-inl.h +244 -0
- package/dist/node/include/aliased_buffer.h +206 -0
- package/dist/node/include/aliased_struct-inl.h +54 -0
- package/dist/node/include/aliased_struct.h +63 -0
- package/dist/node/include/amaro_version.h +6 -0
- package/dist/node/include/async_context_frame.h +33 -0
- package/dist/node/include/async_wrap-inl.h +96 -0
- package/dist/node/include/async_wrap.h +243 -0
- package/dist/node/include/base_object-inl.h +335 -0
- package/dist/node/include/base_object.h +342 -0
- package/dist/node/include/base_object_types.h +74 -0
- package/dist/node/include/blob_serializer_deserializer-inl.h +385 -0
- package/dist/node/include/blob_serializer_deserializer.h +132 -0
- package/dist/node/include/callback_queue-inl.h +97 -0
- package/dist/node/include/callback_queue.h +79 -0
- package/dist/node/include/cares_wrap.h +447 -0
- package/dist/node/include/cjs_module_lexer_version.h +6 -0
- package/dist/node/include/cleanup_queue-inl.h +36 -0
- package/dist/node/include/cleanup_queue.h +79 -0
- package/dist/node/include/compile_cache.h +104 -0
- package/dist/node/include/connect_wrap.h +26 -0
- package/dist/node/include/connection_wrap.h +30 -0
- package/dist/node/include/cppgc/allocation.h +310 -0
- package/dist/node/include/cppgc/common.h +28 -0
- package/dist/node/include/cppgc/cross-thread-persistent.h +466 -0
- package/dist/node/include/cppgc/custom-space.h +97 -0
- package/dist/node/include/cppgc/default-platform.h +67 -0
- package/dist/node/include/cppgc/ephemeron-pair.h +30 -0
- package/dist/node/include/cppgc/explicit-management.h +100 -0
- package/dist/node/include/cppgc/garbage-collected.h +106 -0
- package/dist/node/include/cppgc/heap-consistency.h +309 -0
- package/dist/node/include/cppgc/heap-handle.h +48 -0
- package/dist/node/include/cppgc/heap-state.h +82 -0
- package/dist/node/include/cppgc/heap-statistics.h +120 -0
- package/dist/node/include/cppgc/heap.h +202 -0
- package/dist/node/include/cppgc/internal/api-constants.h +87 -0
- package/dist/node/include/cppgc/internal/atomic-entry-flag.h +48 -0
- package/dist/node/include/cppgc/internal/base-page-handle.h +45 -0
- package/dist/node/include/cppgc/internal/caged-heap-local-data.h +121 -0
- package/dist/node/include/cppgc/internal/caged-heap.h +68 -0
- package/dist/node/include/cppgc/internal/compiler-specific.h +38 -0
- package/dist/node/include/cppgc/internal/finalizer-trait.h +93 -0
- package/dist/node/include/cppgc/internal/gc-info.h +148 -0
- package/dist/node/include/cppgc/internal/logging.h +50 -0
- package/dist/node/include/cppgc/internal/member-storage.h +256 -0
- package/dist/node/include/cppgc/internal/name-trait.h +137 -0
- package/dist/node/include/cppgc/internal/persistent-node.h +214 -0
- package/dist/node/include/cppgc/internal/pointer-policies.h +243 -0
- package/dist/node/include/cppgc/internal/write-barrier.h +487 -0
- package/dist/node/include/cppgc/liveness-broker.h +78 -0
- package/dist/node/include/cppgc/macros.h +35 -0
- package/dist/node/include/cppgc/member.h +629 -0
- package/dist/node/include/cppgc/name-provider.h +65 -0
- package/dist/node/include/cppgc/object-size-trait.h +58 -0
- package/dist/node/include/cppgc/persistent.h +377 -0
- package/dist/node/include/cppgc/platform.h +163 -0
- package/dist/node/include/cppgc/prefinalizer.h +75 -0
- package/dist/node/include/cppgc/process-heap-statistics.h +36 -0
- package/dist/node/include/cppgc/sentinel-pointer.h +39 -0
- package/dist/node/include/cppgc/source-location.h +16 -0
- package/dist/node/include/cppgc/testing.h +106 -0
- package/dist/node/include/cppgc/trace-trait.h +128 -0
- package/dist/node/include/cppgc/type-traits.h +271 -0
- package/dist/node/include/cppgc/visitor.h +504 -0
- package/dist/node/include/crypto/crypto_aes.h +88 -0
- package/dist/node/include/crypto/crypto_bio.h +193 -0
- package/dist/node/include/crypto/crypto_cipher.h +293 -0
- package/dist/node/include/crypto/crypto_clienthello-inl.h +90 -0
- package/dist/node/include/crypto/crypto_clienthello.h +131 -0
- package/dist/node/include/crypto/crypto_common.h +64 -0
- package/dist/node/include/crypto/crypto_context.h +171 -0
- package/dist/node/include/crypto/crypto_dh.h +126 -0
- package/dist/node/include/crypto/crypto_dsa.h +52 -0
- package/dist/node/include/crypto/crypto_ec.h +164 -0
- package/dist/node/include/crypto/crypto_hash.h +91 -0
- package/dist/node/include/crypto/crypto_hkdf.h +61 -0
- package/dist/node/include/crypto/crypto_hmac.h +92 -0
- package/dist/node/include/crypto/crypto_keygen.h +299 -0
- package/dist/node/include/crypto/crypto_keys.h +392 -0
- package/dist/node/include/crypto/crypto_pbkdf2.h +74 -0
- package/dist/node/include/crypto/crypto_random.h +124 -0
- package/dist/node/include/crypto/crypto_rsa.h +136 -0
- package/dist/node/include/crypto/crypto_scrypt.h +85 -0
- package/dist/node/include/crypto/crypto_sig.h +165 -0
- package/dist/node/include/crypto/crypto_spkac.h +21 -0
- package/dist/node/include/crypto/crypto_timing.h +20 -0
- package/dist/node/include/crypto/crypto_tls.h +305 -0
- package/dist/node/include/crypto/crypto_util.h +725 -0
- package/dist/node/include/crypto/crypto_x509.h +140 -0
- package/dist/node/include/dataqueue/queue.h +306 -0
- package/dist/node/include/debug_utils-inl.h +278 -0
- package/dist/node/include/debug_utils.h +196 -0
- package/dist/node/include/diagnosticfilename-inl.h +33 -0
- package/dist/node/include/embedded_data.h +17 -0
- package/dist/node/include/encoding_binding.h +61 -0
- package/dist/node/include/env-inl.h +984 -0
- package/dist/node/include/env.h +1287 -0
- package/dist/node/include/env_properties.h +540 -0
- package/dist/node/include/handle_wrap.h +123 -0
- package/dist/node/include/histogram-inl.h +107 -0
- package/dist/node/include/histogram.h +279 -0
- package/dist/node/include/inspector/io_agent.h +30 -0
- package/dist/node/include/inspector/main_thread_interface.h +116 -0
- package/dist/node/include/inspector/network_agent.h +94 -0
- package/dist/node/include/inspector/network_inspector.h +45 -0
- package/dist/node/include/inspector/network_requests_buffer.h +195 -0
- package/dist/node/include/inspector/network_resource_manager.h +29 -0
- package/dist/node/include/inspector/node_json.h +24 -0
- package/dist/node/include/inspector/node_string.h +101 -0
- package/dist/node/include/inspector/protocol_helper.h +27 -0
- package/dist/node/include/inspector/runtime_agent.h +41 -0
- package/dist/node/include/inspector/target_agent.h +75 -0
- package/dist/node/include/inspector/tracing_agent.h +43 -0
- package/dist/node/include/inspector/worker_agent.h +40 -0
- package/dist/node/include/inspector/worker_inspector.h +124 -0
- package/dist/node/include/inspector_agent.h +165 -0
- package/dist/node/include/inspector_io.h +78 -0
- package/dist/node/include/inspector_profiler.h +149 -0
- package/dist/node/include/inspector_socket.h +60 -0
- package/dist/node/include/inspector_socket_server.h +110 -0
- package/dist/node/include/js_native_api.h +607 -0
- package/dist/node/include/js_native_api_types.h +226 -0
- package/dist/node/include/js_native_api_v8.h +485 -0
- package/dist/node/include/js_native_api_v8_internals.h +45 -0
- package/dist/node/include/js_stream.h +52 -0
- package/dist/node/include/json_utils.h +172 -0
- package/dist/node/include/large_pages/node_large_page.h +34 -0
- package/dist/node/include/libplatform/libplatform-export.h +29 -0
- package/dist/node/include/libplatform/libplatform.h +112 -0
- package/dist/node/include/libplatform/v8-tracing.h +333 -0
- package/dist/node/include/memory_tracker-inl.h +359 -0
- package/dist/node/include/memory_tracker.h +289 -0
- package/dist/node/include/module_wrap.h +216 -0
- package/dist/node/include/node.h +1593 -0
- package/dist/node/include/node_api.h +265 -0
- package/dist/node/include/node_api_internals.h +48 -0
- package/dist/node/include/node_api_types.h +56 -0
- package/dist/node/include/node_binding.h +161 -0
- package/dist/node/include/node_blob.h +159 -0
- package/dist/node/include/node_bob-inl.h +36 -0
- package/dist/node/include/node_bob.h +107 -0
- package/dist/node/include/node_buffer.h +92 -0
- package/dist/node/include/node_builtins.h +220 -0
- package/dist/node/include/node_config_file.h +46 -0
- package/dist/node/include/node_constants.h +82 -0
- package/dist/node/include/node_context_data.h +168 -0
- package/dist/node/include/node_contextify.h +204 -0
- package/dist/node/include/node_crypto.h +56 -0
- package/dist/node/include/node_debug.h +30 -0
- package/dist/node/include/node_dir.h +52 -0
- package/dist/node/include/node_dotenv.h +45 -0
- package/dist/node/include/node_errors.h +380 -0
- package/dist/node/include/node_exit_code.h +54 -0
- package/dist/node/include/node_external_reference.h +165 -0
- package/dist/node/include/node_file-inl.h +406 -0
- package/dist/node/include/node_file.h +537 -0
- package/dist/node/include/node_http2.h +1177 -0
- package/dist/node/include/node_http2_state.h +159 -0
- package/dist/node/include/node_http_common-inl.h +202 -0
- package/dist/node/include/node_http_common.h +535 -0
- package/dist/node/include/node_i18n.h +132 -0
- package/dist/node/include/node_internals.h +483 -0
- package/dist/node/include/node_main_instance.h +67 -0
- package/dist/node/include/node_mem-inl.h +113 -0
- package/dist/node/include/node_mem.h +45 -0
- package/dist/node/include/node_messaging.h +389 -0
- package/dist/node/include/node_metadata.h +164 -0
- package/dist/node/include/node_modules.h +91 -0
- package/dist/node/include/node_mutex.h +323 -0
- package/dist/node/include/node_object_wrap.h +132 -0
- package/dist/node/include/node_options-inl.h +490 -0
- package/dist/node/include/node_options.h +615 -0
- package/dist/node/include/node_perf.h +166 -0
- package/dist/node/include/node_perf_common.h +102 -0
- package/dist/node/include/node_platform.h +238 -0
- package/dist/node/include/node_process-inl.h +26 -0
- package/dist/node/include/node_process.h +112 -0
- package/dist/node/include/node_realm-inl.h +151 -0
- package/dist/node/include/node_realm.h +183 -0
- package/dist/node/include/node_report.h +43 -0
- package/dist/node/include/node_revert.h +82 -0
- package/dist/node/include/node_root_certs.h +3520 -0
- package/dist/node/include/node_sea.h +74 -0
- package/dist/node/include/node_shadow_realm.h +46 -0
- package/dist/node/include/node_snapshot_builder.h +57 -0
- package/dist/node/include/node_snapshotable.h +174 -0
- package/dist/node/include/node_sockaddr-inl.h +257 -0
- package/dist/node/include/node_sockaddr.h +394 -0
- package/dist/node/include/node_sqlite.h +270 -0
- package/dist/node/include/node_stat_watcher.h +73 -0
- package/dist/node/include/node_task_runner.h +92 -0
- package/dist/node/include/node_threadsafe_cow-inl.h +54 -0
- package/dist/node/include/node_threadsafe_cow.h +105 -0
- package/dist/node/include/node_union_bytes.h +81 -0
- package/dist/node/include/node_url.h +96 -0
- package/dist/node/include/node_v8.h +77 -0
- package/dist/node/include/node_v8_platform-inl.h +185 -0
- package/dist/node/include/node_version.h +110 -0
- package/dist/node/include/node_wasi.h +184 -0
- package/dist/node/include/node_wasm_web_api.h +55 -0
- package/dist/node/include/node_watchdog.h +154 -0
- package/dist/node/include/node_webstorage.h +60 -0
- package/dist/node/include/node_worker.h +158 -0
- package/dist/node/include/path.h +33 -0
- package/dist/node/include/permission/addon_permission.h +31 -0
- package/dist/node/include/permission/child_process_permission.h +31 -0
- package/dist/node/include/permission/fs_permission.h +167 -0
- package/dist/node/include/permission/inspector_permission.h +31 -0
- package/dist/node/include/permission/permission.h +138 -0
- package/dist/node/include/permission/permission_base.h +65 -0
- package/dist/node/include/permission/wasi_permission.h +31 -0
- package/dist/node/include/permission/worker_permission.h +31 -0
- package/dist/node/include/pipe_wrap.h +80 -0
- package/dist/node/include/quic/application.h +159 -0
- package/dist/node/include/quic/bindingdata.h +272 -0
- package/dist/node/include/quic/cid.h +127 -0
- package/dist/node/include/quic/data.h +148 -0
- package/dist/node/include/quic/defs.h +245 -0
- package/dist/node/include/quic/endpoint.h +458 -0
- package/dist/node/include/quic/http3.h +15 -0
- package/dist/node/include/quic/logstream.h +81 -0
- package/dist/node/include/quic/packet.h +152 -0
- package/dist/node/include/quic/preferredaddress.h +72 -0
- package/dist/node/include/quic/session.h +443 -0
- package/dist/node/include/quic/sessionticket.h +108 -0
- package/dist/node/include/quic/streams.h +232 -0
- package/dist/node/include/quic/tlscontext.h +227 -0
- package/dist/node/include/quic/tokens.h +256 -0
- package/dist/node/include/quic/transportparams.h +165 -0
- package/dist/node/include/req_wrap-inl.h +171 -0
- package/dist/node/include/req_wrap.h +77 -0
- package/dist/node/include/spawn_sync.h +243 -0
- package/dist/node/include/stream_base-inl.h +173 -0
- package/dist/node/include/stream_base.h +478 -0
- package/dist/node/include/stream_pipe.h +76 -0
- package/dist/node/include/stream_wrap.h +132 -0
- package/dist/node/include/string_bytes.h +113 -0
- package/dist/node/include/string_decoder-inl.h +31 -0
- package/dist/node/include/string_decoder.h +49 -0
- package/dist/node/include/tcp_wrap.h +105 -0
- package/dist/node/include/threadpoolwork-inl.h +70 -0
- package/dist/node/include/timer_wrap-inl.h +32 -0
- package/dist/node/include/timer_wrap.h +85 -0
- package/dist/node/include/timers.h +70 -0
- package/dist/node/include/tracing/agent.h +195 -0
- package/dist/node/include/tracing/node_trace_buffer.h +83 -0
- package/dist/node/include/tracing/node_trace_writer.h +75 -0
- package/dist/node/include/tracing/trace_event.h +722 -0
- package/dist/node/include/tracing/trace_event_common.h +1109 -0
- package/dist/node/include/tracing/traced_value.h +129 -0
- package/dist/node/include/tty_wrap.h +65 -0
- package/dist/node/include/udp_wrap.h +230 -0
- package/dist/node/include/undici_version.h +6 -0
- package/dist/node/include/util-inl.h +700 -0
- package/dist/node/include/util.h +1021 -0
- package/dist/node/include/uv/aix.h +32 -0
- package/dist/node/include/uv/bsd.h +34 -0
- package/dist/node/include/uv/darwin.h +61 -0
- package/dist/node/include/uv/errno.h +483 -0
- package/dist/node/include/uv/linux.h +34 -0
- package/dist/node/include/uv/os390.h +33 -0
- package/dist/node/include/uv/posix.h +31 -0
- package/dist/node/include/uv/sunos.h +44 -0
- package/dist/node/include/uv/threadpool.h +37 -0
- package/dist/node/include/uv/tree.h +521 -0
- package/dist/node/include/uv/unix.h +512 -0
- package/dist/node/include/uv/version.h +43 -0
- package/dist/node/include/uv/win.h +698 -0
- package/dist/node/include/uv.h +1990 -0
- package/dist/node/include/v8-array-buffer.h +525 -0
- package/dist/node/include/v8-callbacks.h +462 -0
- package/dist/node/include/v8-container.h +183 -0
- package/dist/node/include/v8-context.h +485 -0
- package/dist/node/include/v8-cppgc.h +245 -0
- package/dist/node/include/v8-data.h +80 -0
- package/dist/node/include/v8-date.h +48 -0
- package/dist/node/include/v8-debug.h +168 -0
- package/dist/node/include/v8-embedder-heap.h +82 -0
- package/dist/node/include/v8-embedder-state-scope.h +52 -0
- package/dist/node/include/v8-exception.h +223 -0
- package/dist/node/include/v8-extension.h +62 -0
- package/dist/node/include/v8-external.h +37 -0
- package/dist/node/include/v8-fast-api-calls.h +984 -0
- package/dist/node/include/v8-forward.h +82 -0
- package/dist/node/include/v8-function-callback.h +607 -0
- package/dist/node/include/v8-function.h +140 -0
- package/dist/node/include/v8-handle-base.h +137 -0
- package/dist/node/include/v8-initialization.h +289 -0
- package/dist/node/include/v8-inspector-protocol.h +13 -0
- package/dist/node/include/v8-inspector.h +419 -0
- package/dist/node/include/v8-internal.h +1397 -0
- package/dist/node/include/v8-isolate.h +1767 -0
- package/dist/node/include/v8-json.h +47 -0
- package/dist/node/include/v8-local-handle.h +758 -0
- package/dist/node/include/v8-locker.h +138 -0
- package/dist/node/include/v8-maybe.h +160 -0
- package/dist/node/include/v8-memory-span.h +198 -0
- package/dist/node/include/v8-message.h +233 -0
- package/dist/node/include/v8-metrics.h +264 -0
- package/dist/node/include/v8-microtask-queue.h +157 -0
- package/dist/node/include/v8-microtask.h +28 -0
- package/dist/node/include/v8-object.h +824 -0
- package/dist/node/include/v8-persistent-handle.h +582 -0
- package/dist/node/include/v8-platform.h +1358 -0
- package/dist/node/include/v8-primitive-object.h +118 -0
- package/dist/node/include/v8-primitive.h +877 -0
- package/dist/node/include/v8-profiler.h +1302 -0
- package/dist/node/include/v8-promise.h +174 -0
- package/dist/node/include/v8-proxy.h +50 -0
- package/dist/node/include/v8-regexp.h +106 -0
- package/dist/node/include/v8-script.h +904 -0
- package/dist/node/include/v8-snapshot.h +266 -0
- package/dist/node/include/v8-source-location.h +92 -0
- package/dist/node/include/v8-statistics.h +238 -0
- package/dist/node/include/v8-template.h +1297 -0
- package/dist/node/include/v8-traced-handle.h +432 -0
- package/dist/node/include/v8-typed-array.h +390 -0
- package/dist/node/include/v8-unwinder-state.h +31 -0
- package/dist/node/include/v8-unwinder.h +132 -0
- package/dist/node/include/v8-util.h +665 -0
- package/dist/node/include/v8-value-serializer-version.h +24 -0
- package/dist/node/include/v8-value-serializer.h +316 -0
- package/dist/node/include/v8-value.h +655 -0
- package/dist/node/include/v8-version-string.h +38 -0
- package/dist/node/include/v8-version.h +20 -0
- package/dist/node/include/v8-wasm-trap-handler-posix.h +31 -0
- package/dist/node/include/v8-wasm-trap-handler-win.h +28 -0
- package/dist/node/include/v8-wasm.h +201 -0
- package/dist/node/include/v8-weak-callback-info.h +80 -0
- package/dist/node/include/v8.h +88 -0
- package/dist/node/include/v8config.h +981 -0
- package/dist/node/include/zlib_version.h +6 -0
- package/dist/node/libnode.dll +0 -0
- package/dist/node/libnode.lib +0 -0
- package/dist/node/libnodebuildinfo.json +10 -0
- package/dist/node/link_node.lib +0 -0
- package/dist/node/link_node.node +0 -0
- package/index.js +5 -0
- package/libnode.release.json +8 -0
- package/package.json +29 -1
|
@@ -0,0 +1,725 @@
|
|
|
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 "ncrypto.h"
|
|
16
|
+
|
|
17
|
+
#include <openssl/dsa.h>
|
|
18
|
+
#include <openssl/ec.h>
|
|
19
|
+
#include <openssl/err.h>
|
|
20
|
+
#include <openssl/evp.h>
|
|
21
|
+
#include <openssl/hmac.h>
|
|
22
|
+
#include <openssl/kdf.h>
|
|
23
|
+
#include <openssl/rsa.h>
|
|
24
|
+
#include <openssl/ssl.h>
|
|
25
|
+
|
|
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
|
+
|
|
42
|
+
namespace crypto {
|
|
43
|
+
// Currently known sizes of commonly used OpenSSL struct sizes.
|
|
44
|
+
// OpenSSL considers it's various structs to be opaque and the
|
|
45
|
+
// sizes may change from one version of OpenSSL to another, so
|
|
46
|
+
// these values should not be trusted to remain static. These
|
|
47
|
+
// are provided to allow for some close to reasonable memory
|
|
48
|
+
// tracking.
|
|
49
|
+
constexpr size_t kSizeOf_DH = 144;
|
|
50
|
+
constexpr size_t kSizeOf_EC_KEY = 80;
|
|
51
|
+
constexpr size_t kSizeOf_EVP_CIPHER_CTX = 168;
|
|
52
|
+
constexpr size_t kSizeOf_EVP_MD_CTX = 48;
|
|
53
|
+
constexpr size_t kSizeOf_EVP_PKEY = 72;
|
|
54
|
+
constexpr size_t kSizeOf_EVP_PKEY_CTX = 80;
|
|
55
|
+
constexpr size_t kSizeOf_HMAC_CTX = 32;
|
|
56
|
+
|
|
57
|
+
bool ProcessFipsOptions();
|
|
58
|
+
|
|
59
|
+
bool InitCryptoOnce(v8::Isolate* isolate);
|
|
60
|
+
void InitCryptoOnce();
|
|
61
|
+
|
|
62
|
+
void InitCrypto(v8::Local<v8::Object> target);
|
|
63
|
+
|
|
64
|
+
extern void UseExtraCaCerts(const std::string& file);
|
|
65
|
+
void CleanupCachedRootCertificates();
|
|
66
|
+
|
|
67
|
+
int PasswordCallback(char* buf, int size, int rwflag, void* u);
|
|
68
|
+
|
|
69
|
+
int NoPasswordCallback(char* buf, int size, int rwflag, void* u);
|
|
70
|
+
|
|
71
|
+
// Decode is used by the various stream-based crypto utilities to decode
|
|
72
|
+
// string input.
|
|
73
|
+
template <typename T>
|
|
74
|
+
void Decode(const v8::FunctionCallbackInfo<v8::Value>& args,
|
|
75
|
+
void (*callback)(T*, const v8::FunctionCallbackInfo<v8::Value>&,
|
|
76
|
+
const char*, size_t)) {
|
|
77
|
+
T* ctx;
|
|
78
|
+
ASSIGN_OR_RETURN_UNWRAP(&ctx, args.This());
|
|
79
|
+
|
|
80
|
+
if (args[0]->IsString()) {
|
|
81
|
+
StringBytes::InlineDecoder decoder;
|
|
82
|
+
Environment* env = Environment::GetCurrent(args);
|
|
83
|
+
enum encoding enc = ParseEncoding(env->isolate(), args[1], UTF8);
|
|
84
|
+
if (decoder.Decode(env, args[0].As<v8::String>(), enc).IsNothing())
|
|
85
|
+
return;
|
|
86
|
+
callback(ctx, args, decoder.out(), decoder.size());
|
|
87
|
+
} else {
|
|
88
|
+
ArrayBufferViewContents<char> buf(args[0]);
|
|
89
|
+
callback(ctx, args, buf.data(), buf.length());
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
#define NODE_CRYPTO_ERROR_CODES_MAP(V) \
|
|
94
|
+
V(CIPHER_JOB_FAILED, "Cipher job failed") \
|
|
95
|
+
V(DERIVING_BITS_FAILED, "Deriving bits failed") \
|
|
96
|
+
V(ENGINE_NOT_FOUND, "Engine \"%s\" was not found") \
|
|
97
|
+
V(INVALID_KEY_TYPE, "Invalid key type") \
|
|
98
|
+
V(KEY_GENERATION_JOB_FAILED, "Key generation job failed") \
|
|
99
|
+
V(OK, "Ok") \
|
|
100
|
+
|
|
101
|
+
enum class NodeCryptoError {
|
|
102
|
+
#define V(CODE, DESCRIPTION) CODE,
|
|
103
|
+
NODE_CRYPTO_ERROR_CODES_MAP(V)
|
|
104
|
+
#undef V
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
template <typename... Args>
|
|
108
|
+
std::string getNodeCryptoErrorString(const NodeCryptoError error,
|
|
109
|
+
Args&&... args) {
|
|
110
|
+
const char* error_string = nullptr;
|
|
111
|
+
switch (error) {
|
|
112
|
+
#define V(CODE, DESCRIPTION) \
|
|
113
|
+
case NodeCryptoError::CODE: \
|
|
114
|
+
error_string = DESCRIPTION; \
|
|
115
|
+
break;
|
|
116
|
+
NODE_CRYPTO_ERROR_CODES_MAP(V)
|
|
117
|
+
#undef V
|
|
118
|
+
}
|
|
119
|
+
return SPrintF(error_string, std::forward<Args>(args)...);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// Utility struct used to harvest error information from openssl's error stack
|
|
123
|
+
struct CryptoErrorStore final : public MemoryRetainer {
|
|
124
|
+
public:
|
|
125
|
+
void Capture();
|
|
126
|
+
|
|
127
|
+
bool Empty() const;
|
|
128
|
+
|
|
129
|
+
template <typename... Args>
|
|
130
|
+
void Insert(const NodeCryptoError error, Args&&... args);
|
|
131
|
+
|
|
132
|
+
v8::MaybeLocal<v8::Value> ToException(
|
|
133
|
+
Environment* env,
|
|
134
|
+
v8::Local<v8::String> exception_string = v8::Local<v8::String>()) const;
|
|
135
|
+
|
|
136
|
+
SET_NO_MEMORY_INFO()
|
|
137
|
+
SET_MEMORY_INFO_NAME(CryptoErrorStore)
|
|
138
|
+
SET_SELF_SIZE(CryptoErrorStore)
|
|
139
|
+
|
|
140
|
+
private:
|
|
141
|
+
std::vector<std::string> errors_;
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
template <typename... Args>
|
|
145
|
+
void CryptoErrorStore::Insert(const NodeCryptoError error, Args&&... args) {
|
|
146
|
+
const char* error_string = nullptr;
|
|
147
|
+
switch (error) {
|
|
148
|
+
#define V(CODE, DESCRIPTION) \
|
|
149
|
+
case NodeCryptoError::CODE: error_string = DESCRIPTION; break;
|
|
150
|
+
NODE_CRYPTO_ERROR_CODES_MAP(V)
|
|
151
|
+
#undef V
|
|
152
|
+
}
|
|
153
|
+
errors_.emplace_back(SPrintF(error_string,
|
|
154
|
+
std::forward<Args>(args)...));
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
v8::MaybeLocal<v8::Value> cryptoErrorListToException(
|
|
158
|
+
Environment* env, const ncrypto::CryptoErrorList& errors);
|
|
159
|
+
|
|
160
|
+
template <typename T>
|
|
161
|
+
T* MallocOpenSSL(size_t count) {
|
|
162
|
+
void* mem = OPENSSL_malloc(MultiplyWithOverflowCheck(count, sizeof(T)));
|
|
163
|
+
CHECK_IMPLIES(mem == nullptr, count == 0);
|
|
164
|
+
return static_cast<T*>(mem);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// A helper class representing a read-only byte array. When deallocated, its
|
|
168
|
+
// contents are zeroed.
|
|
169
|
+
class ByteSource {
|
|
170
|
+
public:
|
|
171
|
+
class Builder {
|
|
172
|
+
public:
|
|
173
|
+
// Allocates memory using OpenSSL's memory allocator.
|
|
174
|
+
explicit Builder(size_t size)
|
|
175
|
+
: data_(MallocOpenSSL<char>(size)), size_(size) {}
|
|
176
|
+
|
|
177
|
+
Builder(Builder&& other) = delete;
|
|
178
|
+
Builder& operator=(Builder&& other) = delete;
|
|
179
|
+
Builder(const Builder&) = delete;
|
|
180
|
+
Builder& operator=(const Builder&) = delete;
|
|
181
|
+
|
|
182
|
+
~Builder() { OPENSSL_clear_free(data_, size_); }
|
|
183
|
+
|
|
184
|
+
// Returns the underlying non-const pointer.
|
|
185
|
+
template <typename T>
|
|
186
|
+
T* data() {
|
|
187
|
+
return reinterpret_cast<T*>(data_);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// Returns the (allocated) size in bytes.
|
|
191
|
+
size_t size() const { return size_; }
|
|
192
|
+
|
|
193
|
+
// Returns if (allocated) size is zero.
|
|
194
|
+
bool empty() const { return size_ == 0; }
|
|
195
|
+
|
|
196
|
+
// Finalizes the Builder and returns a read-only view that is optionally
|
|
197
|
+
// truncated.
|
|
198
|
+
ByteSource release(std::optional<size_t> resize = std::nullopt) && {
|
|
199
|
+
if (resize) {
|
|
200
|
+
CHECK_LE(*resize, size_);
|
|
201
|
+
if (*resize == 0) {
|
|
202
|
+
OPENSSL_clear_free(data_, size_);
|
|
203
|
+
data_ = nullptr;
|
|
204
|
+
}
|
|
205
|
+
size_ = *resize;
|
|
206
|
+
}
|
|
207
|
+
ByteSource out = ByteSource::Allocated(data_, size_);
|
|
208
|
+
data_ = nullptr;
|
|
209
|
+
size_ = 0;
|
|
210
|
+
return out;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
private:
|
|
214
|
+
void* data_;
|
|
215
|
+
size_t size_;
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
ByteSource() = default;
|
|
219
|
+
ByteSource(ByteSource&& other) noexcept;
|
|
220
|
+
~ByteSource();
|
|
221
|
+
|
|
222
|
+
ByteSource& operator=(ByteSource&& other) noexcept;
|
|
223
|
+
|
|
224
|
+
ByteSource(const ByteSource&) = delete;
|
|
225
|
+
ByteSource& operator=(const ByteSource&) = delete;
|
|
226
|
+
|
|
227
|
+
template <typename T = void>
|
|
228
|
+
const T* data() const {
|
|
229
|
+
return reinterpret_cast<const T*>(data_);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
size_t size() const { return size_; }
|
|
233
|
+
|
|
234
|
+
bool empty() const { return size_ == 0; }
|
|
235
|
+
|
|
236
|
+
operator bool() const { return data_ != nullptr; }
|
|
237
|
+
|
|
238
|
+
ncrypto::BignumPointer ToBN() const {
|
|
239
|
+
return ncrypto::BignumPointer(data<unsigned char>(), size());
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
// Creates a v8::BackingStore that takes over responsibility for
|
|
243
|
+
// any allocated data. The ByteSource will be reset with size = 0
|
|
244
|
+
// after being called.
|
|
245
|
+
std::unique_ptr<v8::BackingStore> ReleaseToBackingStore();
|
|
246
|
+
|
|
247
|
+
v8::Local<v8::ArrayBuffer> ToArrayBuffer(Environment* env);
|
|
248
|
+
|
|
249
|
+
v8::MaybeLocal<v8::Uint8Array> ToBuffer(Environment* env);
|
|
250
|
+
|
|
251
|
+
static ByteSource Allocated(void* data, size_t size);
|
|
252
|
+
|
|
253
|
+
template <typename T>
|
|
254
|
+
static ByteSource Allocated(const ncrypto::Buffer<T>& buffer) {
|
|
255
|
+
return Allocated(buffer.data, buffer.len);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
static ByteSource Foreign(const void* data, size_t size);
|
|
259
|
+
|
|
260
|
+
static ByteSource FromEncodedString(Environment* env,
|
|
261
|
+
v8::Local<v8::String> value,
|
|
262
|
+
enum encoding enc = BASE64);
|
|
263
|
+
|
|
264
|
+
static ByteSource FromStringOrBuffer(Environment* env,
|
|
265
|
+
v8::Local<v8::Value> value);
|
|
266
|
+
|
|
267
|
+
static ByteSource FromString(Environment* env,
|
|
268
|
+
v8::Local<v8::String> str,
|
|
269
|
+
bool ntc = false);
|
|
270
|
+
|
|
271
|
+
static ByteSource FromBuffer(v8::Local<v8::Value> buffer,
|
|
272
|
+
bool ntc = false);
|
|
273
|
+
|
|
274
|
+
static ByteSource FromBIO(const ncrypto::BIOPointer& bio);
|
|
275
|
+
|
|
276
|
+
static ByteSource NullTerminatedCopy(Environment* env,
|
|
277
|
+
v8::Local<v8::Value> value);
|
|
278
|
+
|
|
279
|
+
static ByteSource FromSymmetricKeyObjectHandle(v8::Local<v8::Value> handle);
|
|
280
|
+
|
|
281
|
+
static ByteSource FromSecretKeyBytes(
|
|
282
|
+
Environment* env, v8::Local<v8::Value> value);
|
|
283
|
+
|
|
284
|
+
private:
|
|
285
|
+
const void* data_ = nullptr;
|
|
286
|
+
void* allocated_data_ = nullptr;
|
|
287
|
+
size_t size_ = 0;
|
|
288
|
+
|
|
289
|
+
ByteSource(const void* data, void* allocated_data, size_t size)
|
|
290
|
+
: data_(data), allocated_data_(allocated_data), size_(size) {}
|
|
291
|
+
};
|
|
292
|
+
|
|
293
|
+
enum CryptoJobMode {
|
|
294
|
+
kCryptoJobAsync,
|
|
295
|
+
kCryptoJobSync
|
|
296
|
+
};
|
|
297
|
+
|
|
298
|
+
CryptoJobMode GetCryptoJobMode(v8::Local<v8::Value> args);
|
|
299
|
+
|
|
300
|
+
template <typename CryptoJobTraits>
|
|
301
|
+
class CryptoJob : public AsyncWrap, public ThreadPoolWork {
|
|
302
|
+
public:
|
|
303
|
+
using AdditionalParams = typename CryptoJobTraits::AdditionalParameters;
|
|
304
|
+
|
|
305
|
+
explicit CryptoJob(Environment* env,
|
|
306
|
+
v8::Local<v8::Object> object,
|
|
307
|
+
AsyncWrap::ProviderType type,
|
|
308
|
+
CryptoJobMode mode,
|
|
309
|
+
AdditionalParams&& params)
|
|
310
|
+
: AsyncWrap(env, object, type),
|
|
311
|
+
ThreadPoolWork(env, "crypto"),
|
|
312
|
+
mode_(mode),
|
|
313
|
+
params_(std::move(params)) {
|
|
314
|
+
// If the CryptoJob is async, then the instance will be
|
|
315
|
+
// cleaned up when AfterThreadPoolWork is called.
|
|
316
|
+
if (mode == kCryptoJobSync) MakeWeak();
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
bool IsNotIndicativeOfMemoryLeakAtExit() const override {
|
|
320
|
+
// CryptoJobs run a work in the libuv thread pool and may still
|
|
321
|
+
// exist when the event loop empties and starts to exit.
|
|
322
|
+
return true;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
void AfterThreadPoolWork(int status) override {
|
|
326
|
+
Environment* env = AsyncWrap::env();
|
|
327
|
+
CHECK_EQ(mode_, kCryptoJobAsync);
|
|
328
|
+
CHECK(status == 0 || status == UV_ECANCELED);
|
|
329
|
+
std::unique_ptr<CryptoJob> ptr(this);
|
|
330
|
+
// If the job was canceled do not execute the callback.
|
|
331
|
+
// TODO(@jasnell): We should likely revisit skipping the
|
|
332
|
+
// callback on cancel as that could leave the JS in a pending
|
|
333
|
+
// state (e.g. unresolved promises...)
|
|
334
|
+
if (status == UV_ECANCELED) return;
|
|
335
|
+
v8::HandleScope handle_scope(env->isolate());
|
|
336
|
+
v8::Context::Scope context_scope(env->context());
|
|
337
|
+
|
|
338
|
+
v8::Local<v8::Value> exception;
|
|
339
|
+
v8::Local<v8::Value> args[2];
|
|
340
|
+
{
|
|
341
|
+
node::errors::TryCatchScope try_catch(env);
|
|
342
|
+
// If ToResult returns Nothing, then an exception should have been
|
|
343
|
+
// thrown and we should have caught it. Otherwise, args[0] and args[1]
|
|
344
|
+
// both should have been set to a value, even if the value is undefined.
|
|
345
|
+
if (ptr->ToResult(&args[0], &args[1]).IsNothing()) {
|
|
346
|
+
CHECK(try_catch.HasCaught());
|
|
347
|
+
CHECK(try_catch.CanContinue());
|
|
348
|
+
exception = try_catch.Exception();
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
if (!exception.IsEmpty()) {
|
|
353
|
+
ptr->MakeCallback(env->ondone_string(), 1, &exception);
|
|
354
|
+
} else {
|
|
355
|
+
CHECK(!args[0].IsEmpty());
|
|
356
|
+
CHECK(!args[1].IsEmpty());
|
|
357
|
+
ptr->MakeCallback(env->ondone_string(), arraysize(args), args);
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
virtual v8::Maybe<void> ToResult(v8::Local<v8::Value>* err,
|
|
362
|
+
v8::Local<v8::Value>* result) = 0;
|
|
363
|
+
|
|
364
|
+
CryptoJobMode mode() const { return mode_; }
|
|
365
|
+
|
|
366
|
+
CryptoErrorStore* errors() { return &errors_; }
|
|
367
|
+
|
|
368
|
+
AdditionalParams* params() { return ¶ms_; }
|
|
369
|
+
|
|
370
|
+
const char* MemoryInfoName() const override {
|
|
371
|
+
return CryptoJobTraits::JobName;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
void MemoryInfo(MemoryTracker* tracker) const override {
|
|
375
|
+
tracker->TrackField("params", params_);
|
|
376
|
+
tracker->TrackField("errors", errors_);
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
static void Run(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
|
380
|
+
Environment* env = Environment::GetCurrent(args);
|
|
381
|
+
|
|
382
|
+
CryptoJob<CryptoJobTraits>* job;
|
|
383
|
+
ASSIGN_OR_RETURN_UNWRAP(&job, args.This());
|
|
384
|
+
if (job->mode() == kCryptoJobAsync)
|
|
385
|
+
return job->ScheduleWork();
|
|
386
|
+
|
|
387
|
+
v8::Local<v8::Value> ret[2];
|
|
388
|
+
env->PrintSyncTrace();
|
|
389
|
+
job->DoThreadPoolWork();
|
|
390
|
+
if (job->ToResult(&ret[0], &ret[1]).IsJust()) {
|
|
391
|
+
CHECK(!ret[0].IsEmpty());
|
|
392
|
+
CHECK(!ret[1].IsEmpty());
|
|
393
|
+
args.GetReturnValue().Set(
|
|
394
|
+
v8::Array::New(env->isolate(), ret, arraysize(ret)));
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
static void Initialize(
|
|
399
|
+
v8::FunctionCallback new_fn,
|
|
400
|
+
Environment* env,
|
|
401
|
+
v8::Local<v8::Object> target) {
|
|
402
|
+
v8::Isolate* isolate = env->isolate();
|
|
403
|
+
v8::HandleScope scope(isolate);
|
|
404
|
+
v8::Local<v8::Context> context = env->context();
|
|
405
|
+
v8::Local<v8::FunctionTemplate> job = NewFunctionTemplate(isolate, new_fn);
|
|
406
|
+
job->Inherit(AsyncWrap::GetConstructorTemplate(env));
|
|
407
|
+
job->InstanceTemplate()->SetInternalFieldCount(
|
|
408
|
+
AsyncWrap::kInternalFieldCount);
|
|
409
|
+
SetProtoMethod(isolate, job, "run", Run);
|
|
410
|
+
SetConstructorFunction(context, target, CryptoJobTraits::JobName, job);
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
static void RegisterExternalReferences(v8::FunctionCallback new_fn,
|
|
414
|
+
ExternalReferenceRegistry* registry) {
|
|
415
|
+
registry->Register(new_fn);
|
|
416
|
+
registry->Register(Run);
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
private:
|
|
420
|
+
const CryptoJobMode mode_;
|
|
421
|
+
CryptoErrorStore errors_;
|
|
422
|
+
AdditionalParams params_;
|
|
423
|
+
};
|
|
424
|
+
|
|
425
|
+
template <typename DeriveBitsTraits>
|
|
426
|
+
class DeriveBitsJob final : public CryptoJob<DeriveBitsTraits> {
|
|
427
|
+
public:
|
|
428
|
+
using AdditionalParams = typename DeriveBitsTraits::AdditionalParameters;
|
|
429
|
+
|
|
430
|
+
static void New(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
|
431
|
+
Environment* env = Environment::GetCurrent(args);
|
|
432
|
+
|
|
433
|
+
CryptoJobMode mode = GetCryptoJobMode(args[0]);
|
|
434
|
+
|
|
435
|
+
AdditionalParams params;
|
|
436
|
+
if (DeriveBitsTraits::AdditionalConfig(mode, args, 1, ¶ms)
|
|
437
|
+
.IsNothing()) {
|
|
438
|
+
// The DeriveBitsTraits::AdditionalConfig is responsible for
|
|
439
|
+
// calling an appropriate THROW_CRYPTO_* variant reporting
|
|
440
|
+
// whatever error caused initialization to fail.
|
|
441
|
+
return;
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
new DeriveBitsJob(env, args.This(), mode, std::move(params));
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
static void Initialize(
|
|
448
|
+
Environment* env,
|
|
449
|
+
v8::Local<v8::Object> target) {
|
|
450
|
+
CryptoJob<DeriveBitsTraits>::Initialize(New, env, target);
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
static void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
|
|
454
|
+
CryptoJob<DeriveBitsTraits>::RegisterExternalReferences(New, registry);
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
DeriveBitsJob(
|
|
458
|
+
Environment* env,
|
|
459
|
+
v8::Local<v8::Object> object,
|
|
460
|
+
CryptoJobMode mode,
|
|
461
|
+
AdditionalParams&& params)
|
|
462
|
+
: CryptoJob<DeriveBitsTraits>(
|
|
463
|
+
env,
|
|
464
|
+
object,
|
|
465
|
+
DeriveBitsTraits::Provider,
|
|
466
|
+
mode,
|
|
467
|
+
std::move(params)) {}
|
|
468
|
+
|
|
469
|
+
void DoThreadPoolWork() override {
|
|
470
|
+
ncrypto::ClearErrorOnReturn clear_error_on_return;
|
|
471
|
+
if (!DeriveBitsTraits::DeriveBits(AsyncWrap::env(),
|
|
472
|
+
*CryptoJob<DeriveBitsTraits>::params(),
|
|
473
|
+
&out_,
|
|
474
|
+
this->mode())) {
|
|
475
|
+
CryptoErrorStore* errors = CryptoJob<DeriveBitsTraits>::errors();
|
|
476
|
+
errors->Capture();
|
|
477
|
+
if (errors->Empty())
|
|
478
|
+
errors->Insert(NodeCryptoError::DERIVING_BITS_FAILED);
|
|
479
|
+
return;
|
|
480
|
+
}
|
|
481
|
+
success_ = true;
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
v8::Maybe<void> ToResult(v8::Local<v8::Value>* err,
|
|
485
|
+
v8::Local<v8::Value>* result) override {
|
|
486
|
+
Environment* env = AsyncWrap::env();
|
|
487
|
+
CryptoErrorStore* errors = CryptoJob<DeriveBitsTraits>::errors();
|
|
488
|
+
if (success_) {
|
|
489
|
+
CHECK(errors->Empty());
|
|
490
|
+
*err = v8::Undefined(env->isolate());
|
|
491
|
+
if (!DeriveBitsTraits::EncodeOutput(
|
|
492
|
+
env, *CryptoJob<DeriveBitsTraits>::params(), &out_)
|
|
493
|
+
.ToLocal(result)) {
|
|
494
|
+
return v8::Nothing<void>();
|
|
495
|
+
}
|
|
496
|
+
} else {
|
|
497
|
+
if (errors->Empty()) errors->Capture();
|
|
498
|
+
CHECK(!errors->Empty());
|
|
499
|
+
*result = v8::Undefined(env->isolate());
|
|
500
|
+
if (!errors->ToException(env).ToLocal(err)) {
|
|
501
|
+
return v8::Nothing<void>();
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
CHECK(!result->IsEmpty());
|
|
505
|
+
CHECK(!err->IsEmpty());
|
|
506
|
+
return v8::JustVoid();
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
SET_SELF_SIZE(DeriveBitsJob)
|
|
510
|
+
void MemoryInfo(MemoryTracker* tracker) const override {
|
|
511
|
+
tracker->TrackFieldWithSize("out", out_.size());
|
|
512
|
+
CryptoJob<DeriveBitsTraits>::MemoryInfo(tracker);
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
private:
|
|
516
|
+
ByteSource out_;
|
|
517
|
+
bool success_ = false;
|
|
518
|
+
};
|
|
519
|
+
|
|
520
|
+
void ThrowCryptoError(Environment* env,
|
|
521
|
+
unsigned long err, // NOLINT(runtime/int)
|
|
522
|
+
const char* message = nullptr);
|
|
523
|
+
|
|
524
|
+
class CipherPushContext {
|
|
525
|
+
public:
|
|
526
|
+
inline explicit CipherPushContext(Environment* env)
|
|
527
|
+
: list_(env->isolate()), env_(env) {}
|
|
528
|
+
|
|
529
|
+
inline void push_back(const char* str) {
|
|
530
|
+
list_.emplace_back(OneByteString(env_->isolate(), str));
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
inline v8::Local<v8::Array> ToJSArray() {
|
|
534
|
+
return v8::Array::New(env_->isolate(), list_.data(), list_.size());
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
private:
|
|
538
|
+
v8::LocalVector<v8::Value> list_;
|
|
539
|
+
Environment* env_;
|
|
540
|
+
};
|
|
541
|
+
|
|
542
|
+
#if OPENSSL_VERSION_MAJOR >= 3
|
|
543
|
+
template <class TypeName,
|
|
544
|
+
TypeName* fetch_type(OSSL_LIB_CTX*, const char*, const char*),
|
|
545
|
+
void free_type(TypeName*),
|
|
546
|
+
const TypeName* getbyname(const char*),
|
|
547
|
+
const char* getname(const TypeName*)>
|
|
548
|
+
void array_push_back(const TypeName* evp_ref,
|
|
549
|
+
const char* from,
|
|
550
|
+
const char* to,
|
|
551
|
+
void* arg) {
|
|
552
|
+
if (!from)
|
|
553
|
+
return;
|
|
554
|
+
|
|
555
|
+
const TypeName* real_instance = getbyname(from);
|
|
556
|
+
if (!real_instance)
|
|
557
|
+
return;
|
|
558
|
+
|
|
559
|
+
const char* real_name = getname(real_instance);
|
|
560
|
+
if (!real_name)
|
|
561
|
+
return;
|
|
562
|
+
|
|
563
|
+
// EVP_*_fetch() does not support alias names, so we need to pass it the
|
|
564
|
+
// real/original algorithm name.
|
|
565
|
+
// We use EVP_*_fetch() as a filter here because it will only return an
|
|
566
|
+
// instance if the algorithm is supported by the public OpenSSL APIs (some
|
|
567
|
+
// algorithms are used internally by OpenSSL and are also passed to this
|
|
568
|
+
// callback).
|
|
569
|
+
TypeName* fetched = fetch_type(nullptr, real_name, nullptr);
|
|
570
|
+
if (!fetched)
|
|
571
|
+
return;
|
|
572
|
+
|
|
573
|
+
free_type(fetched);
|
|
574
|
+
static_cast<CipherPushContext*>(arg)->push_back(from);
|
|
575
|
+
}
|
|
576
|
+
#else
|
|
577
|
+
template <class TypeName>
|
|
578
|
+
void array_push_back(const TypeName* evp_ref,
|
|
579
|
+
const char* from,
|
|
580
|
+
const char* to,
|
|
581
|
+
void* arg) {
|
|
582
|
+
if (!from)
|
|
583
|
+
return;
|
|
584
|
+
static_cast<CipherPushContext*>(arg)->push_back(from);
|
|
585
|
+
}
|
|
586
|
+
#endif
|
|
587
|
+
|
|
588
|
+
// WebIDL AllowSharedBufferSource.
|
|
589
|
+
inline bool IsAnyBufferSource(v8::Local<v8::Value> arg) {
|
|
590
|
+
return arg->IsArrayBufferView() ||
|
|
591
|
+
arg->IsArrayBuffer() ||
|
|
592
|
+
arg->IsSharedArrayBuffer();
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
template <typename T>
|
|
596
|
+
class ArrayBufferOrViewContents {
|
|
597
|
+
public:
|
|
598
|
+
ArrayBufferOrViewContents() = default;
|
|
599
|
+
ArrayBufferOrViewContents(const ArrayBufferOrViewContents&) = delete;
|
|
600
|
+
void operator=(const ArrayBufferOrViewContents&) = delete;
|
|
601
|
+
|
|
602
|
+
inline explicit ArrayBufferOrViewContents(v8::Local<v8::Value> buf) {
|
|
603
|
+
if (buf.IsEmpty()) {
|
|
604
|
+
return;
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
CHECK(IsAnyBufferSource(buf));
|
|
608
|
+
if (buf->IsArrayBufferView()) {
|
|
609
|
+
auto view = buf.As<v8::ArrayBufferView>();
|
|
610
|
+
offset_ = view->ByteOffset();
|
|
611
|
+
length_ = view->ByteLength();
|
|
612
|
+
data_ = view->Buffer()->Data();
|
|
613
|
+
} else if (buf->IsArrayBuffer()) {
|
|
614
|
+
auto ab = buf.As<v8::ArrayBuffer>();
|
|
615
|
+
offset_ = 0;
|
|
616
|
+
length_ = ab->ByteLength();
|
|
617
|
+
data_ = ab->Data();
|
|
618
|
+
} else {
|
|
619
|
+
auto sab = buf.As<v8::SharedArrayBuffer>();
|
|
620
|
+
offset_ = 0;
|
|
621
|
+
length_ = sab->ByteLength();
|
|
622
|
+
data_ = sab->Data();
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
inline const T* data() const {
|
|
627
|
+
// Ideally, these would return nullptr if IsEmpty() or length_ is zero,
|
|
628
|
+
// but some of the openssl API react badly if given a nullptr even when
|
|
629
|
+
// length is zero, so we have to return something.
|
|
630
|
+
if (empty()) return &buf;
|
|
631
|
+
return reinterpret_cast<T*>(data_) + offset_;
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
inline T* data() {
|
|
635
|
+
// Ideally, these would return nullptr if IsEmpty() or length_ is zero,
|
|
636
|
+
// but some of the openssl API react badly if given a nullptr even when
|
|
637
|
+
// length is zero, so we have to return something.
|
|
638
|
+
if (empty()) return &buf;
|
|
639
|
+
return reinterpret_cast<T*>(data_) + offset_;
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
inline size_t size() const { return length_; }
|
|
643
|
+
|
|
644
|
+
inline bool empty() const { return length_ == 0; }
|
|
645
|
+
|
|
646
|
+
// In most cases, input buffer sizes passed in to openssl need to
|
|
647
|
+
// be limited to <= INT_MAX. This utility method helps us check.
|
|
648
|
+
inline bool CheckSizeInt32() { return size() <= INT_MAX; }
|
|
649
|
+
|
|
650
|
+
inline ByteSource ToByteSource() const {
|
|
651
|
+
return ByteSource::Foreign(data(), size());
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
inline ByteSource ToCopy() const {
|
|
655
|
+
if (empty()) return ByteSource();
|
|
656
|
+
ByteSource::Builder buf(size());
|
|
657
|
+
memcpy(buf.data<void>(), data(), size());
|
|
658
|
+
return std::move(buf).release();
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
inline ByteSource ToNullTerminatedCopy() const {
|
|
662
|
+
if (empty()) return ByteSource();
|
|
663
|
+
ByteSource::Builder buf(size() + 1);
|
|
664
|
+
memcpy(buf.data<void>(), data(), size());
|
|
665
|
+
buf.data<char>()[size()] = 0;
|
|
666
|
+
return std::move(buf).release(size());
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
inline ncrypto::DataPointer ToDataPointer() const {
|
|
670
|
+
if (empty()) return {};
|
|
671
|
+
if (auto dp = ncrypto::DataPointer::Alloc(size())) {
|
|
672
|
+
memcpy(dp.get(), data(), size());
|
|
673
|
+
return dp;
|
|
674
|
+
}
|
|
675
|
+
return {};
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
template <typename M>
|
|
679
|
+
void CopyTo(M* dest, size_t len) const {
|
|
680
|
+
static_assert(sizeof(M) == 1, "sizeof(M) must equal 1");
|
|
681
|
+
len = std::min(len, size());
|
|
682
|
+
if (len > 0 && data() != nullptr) {
|
|
683
|
+
memcpy(dest, data(), len);
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
private:
|
|
688
|
+
T buf = 0;
|
|
689
|
+
size_t offset_ = 0;
|
|
690
|
+
size_t length_ = 0;
|
|
691
|
+
void* data_ = nullptr;
|
|
692
|
+
|
|
693
|
+
// Declaring operator new and delete as deleted is not spec compliant.
|
|
694
|
+
// Therefore declare them private instead to disable dynamic alloc
|
|
695
|
+
void* operator new(size_t);
|
|
696
|
+
void* operator new[](size_t);
|
|
697
|
+
void operator delete(void*);
|
|
698
|
+
void operator delete[](void*);
|
|
699
|
+
};
|
|
700
|
+
|
|
701
|
+
v8::MaybeLocal<v8::Value> EncodeBignum(
|
|
702
|
+
Environment* env,
|
|
703
|
+
const BIGNUM* bn,
|
|
704
|
+
int size,
|
|
705
|
+
v8::Local<v8::Value>* error);
|
|
706
|
+
|
|
707
|
+
v8::Maybe<void> SetEncodedValue(Environment* env,
|
|
708
|
+
v8::Local<v8::Object> target,
|
|
709
|
+
v8::Local<v8::String> name,
|
|
710
|
+
const BIGNUM* bn,
|
|
711
|
+
int size = 0);
|
|
712
|
+
|
|
713
|
+
bool SetRsaOaepLabel(const ncrypto::EVPKeyCtxPointer& rsa,
|
|
714
|
+
const ByteSource& label);
|
|
715
|
+
|
|
716
|
+
namespace Util {
|
|
717
|
+
void Initialize(Environment* env, v8::Local<v8::Object> target);
|
|
718
|
+
void RegisterExternalReferences(ExternalReferenceRegistry* registry);
|
|
719
|
+
} // namespace Util
|
|
720
|
+
|
|
721
|
+
} // namespace crypto
|
|
722
|
+
} // namespace node
|
|
723
|
+
|
|
724
|
+
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
725
|
+
#endif // SRC_CRYPTO_CRYPTO_UTIL_H_
|