@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,193 @@
|
|
|
1
|
+
// Copyright Joyent, Inc. and other Node contributors.
|
|
2
|
+
//
|
|
3
|
+
// Permission is hereby granted, free of charge, to any person obtaining a
|
|
4
|
+
// copy of this software and associated documentation files (the
|
|
5
|
+
// "Software"), to deal in the Software without restriction, including
|
|
6
|
+
// without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
+
// distribute, sublicense, and/or sell copies of the Software, and to permit
|
|
8
|
+
// persons to whom the Software is furnished to do so, subject to the
|
|
9
|
+
// following conditions:
|
|
10
|
+
//
|
|
11
|
+
// The above copyright notice and this permission notice shall be included
|
|
12
|
+
// in all copies or substantial portions of the Software.
|
|
13
|
+
//
|
|
14
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
15
|
+
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
+
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
|
17
|
+
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
18
|
+
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
19
|
+
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
|
20
|
+
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
21
|
+
|
|
22
|
+
#ifndef SRC_CRYPTO_CRYPTO_BIO_H_
|
|
23
|
+
#define SRC_CRYPTO_CRYPTO_BIO_H_
|
|
24
|
+
|
|
25
|
+
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
26
|
+
|
|
27
|
+
#include "node_crypto.h"
|
|
28
|
+
#include "openssl/bio.h"
|
|
29
|
+
#include "util.h"
|
|
30
|
+
#include "v8.h"
|
|
31
|
+
|
|
32
|
+
namespace node {
|
|
33
|
+
|
|
34
|
+
class Environment;
|
|
35
|
+
|
|
36
|
+
namespace crypto {
|
|
37
|
+
// This class represents buffers for OpenSSL I/O, implemented as a singly-linked
|
|
38
|
+
// list of chunks. It can be used either for writing data from Node to OpenSSL,
|
|
39
|
+
// or for reading data back, but not both.
|
|
40
|
+
// The structure is only accessed, and owned by, the OpenSSL BIOPointer
|
|
41
|
+
// (a.k.a. std::unique_ptr<BIO>).
|
|
42
|
+
class NodeBIO : public MemoryRetainer {
|
|
43
|
+
public:
|
|
44
|
+
~NodeBIO() override;
|
|
45
|
+
|
|
46
|
+
static ncrypto::BIOPointer New(Environment* env = nullptr);
|
|
47
|
+
|
|
48
|
+
// NewFixed takes a copy of `len` bytes from `data` and returns a BIO that,
|
|
49
|
+
// when read from, returns those bytes followed by EOF.
|
|
50
|
+
static ncrypto::BIOPointer NewFixed(const char* data,
|
|
51
|
+
size_t len,
|
|
52
|
+
Environment* env = nullptr);
|
|
53
|
+
|
|
54
|
+
// Move read head to next buffer if needed
|
|
55
|
+
void TryMoveReadHead();
|
|
56
|
+
|
|
57
|
+
// Allocate new buffer for write if needed
|
|
58
|
+
void TryAllocateForWrite(size_t hint);
|
|
59
|
+
|
|
60
|
+
// Read `len` bytes maximum into `out`, return actual number of read bytes
|
|
61
|
+
size_t Read(char* out, size_t size);
|
|
62
|
+
|
|
63
|
+
// Memory optimization:
|
|
64
|
+
// Deallocate children of write head's child if they're empty
|
|
65
|
+
void FreeEmpty();
|
|
66
|
+
|
|
67
|
+
// Return pointer to internal data and amount of
|
|
68
|
+
// contiguous data available to read
|
|
69
|
+
char* Peek(size_t* size);
|
|
70
|
+
|
|
71
|
+
// Return pointers and sizes of multiple internal data chunks available for
|
|
72
|
+
// reading
|
|
73
|
+
size_t PeekMultiple(char** out, size_t* size, size_t* count);
|
|
74
|
+
|
|
75
|
+
// Find first appearance of `delim` in buffer or `limit` if `delim`
|
|
76
|
+
// wasn't found.
|
|
77
|
+
size_t IndexOf(char delim, size_t limit);
|
|
78
|
+
|
|
79
|
+
// Discard all available data
|
|
80
|
+
void Reset();
|
|
81
|
+
|
|
82
|
+
// Put `len` bytes from `data` into buffer
|
|
83
|
+
void Write(const char* data, size_t size);
|
|
84
|
+
|
|
85
|
+
// Return pointer to contiguous block of reserved data and the size available
|
|
86
|
+
// for future writes. Call Commit() once the write is complete.
|
|
87
|
+
char* PeekWritable(size_t* size);
|
|
88
|
+
|
|
89
|
+
// Specify how much data was written into the block returned by
|
|
90
|
+
// PeekWritable().
|
|
91
|
+
void Commit(size_t size);
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
// Return size of buffer in bytes
|
|
95
|
+
inline size_t Length() const {
|
|
96
|
+
return length_;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// Provide a hint about the size of the next pending set of writes. TLS
|
|
100
|
+
// writes records of a maximum length of 16k of data plus a 5-byte header,
|
|
101
|
+
// a MAC (up to 20 bytes for SSLv3, TLS 1.0, TLS 1.1, and up to 32 bytes
|
|
102
|
+
// for TLS 1.2), and padding if a block cipher is used. If there is a
|
|
103
|
+
// large write this will result in potentially many buffers being
|
|
104
|
+
// allocated and gc'ed which can cause long pauses. By providing a
|
|
105
|
+
// guess about the amount of buffer space that will be needed in the
|
|
106
|
+
// next allocation this overhead is removed.
|
|
107
|
+
inline void set_allocate_tls_hint(size_t size) {
|
|
108
|
+
constexpr size_t kThreshold = 16 * 1024;
|
|
109
|
+
if (size >= kThreshold) {
|
|
110
|
+
allocate_hint_ = (size / kThreshold + 1) * (kThreshold + 5 + 32);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
inline void set_eof_return(int num) {
|
|
115
|
+
eof_return_ = num;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
inline int eof_return() {
|
|
119
|
+
return eof_return_;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
inline void set_initial(size_t initial) {
|
|
123
|
+
initial_ = initial;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
static NodeBIO* FromBIO(BIO* bio);
|
|
127
|
+
|
|
128
|
+
void MemoryInfo(MemoryTracker* tracker) const override {
|
|
129
|
+
tracker->TrackFieldWithSize("buffer", length_, "NodeBIO::Buffer");
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
SET_MEMORY_INFO_NAME(NodeBIO)
|
|
133
|
+
SET_SELF_SIZE(NodeBIO)
|
|
134
|
+
|
|
135
|
+
private:
|
|
136
|
+
static int New(BIO* bio);
|
|
137
|
+
static int Free(BIO* bio);
|
|
138
|
+
static int Read(BIO* bio, char* out, int len);
|
|
139
|
+
static int Write(BIO* bio, const char* data, int len);
|
|
140
|
+
static int Puts(BIO* bio, const char* str);
|
|
141
|
+
static int Gets(BIO* bio, char* out, int size);
|
|
142
|
+
static long Ctrl(BIO* bio, int cmd, long num, // NOLINT(runtime/int)
|
|
143
|
+
void* ptr);
|
|
144
|
+
|
|
145
|
+
static const BIO_METHOD* GetMethod();
|
|
146
|
+
|
|
147
|
+
// Enough to handle the most of the client hellos
|
|
148
|
+
static const size_t kInitialBufferLength = 1024;
|
|
149
|
+
static const size_t kThroughputBufferLength = 16384;
|
|
150
|
+
|
|
151
|
+
class Buffer {
|
|
152
|
+
public:
|
|
153
|
+
Buffer(Environment* env, size_t len) : env_(env),
|
|
154
|
+
read_pos_(0),
|
|
155
|
+
write_pos_(0),
|
|
156
|
+
len_(len),
|
|
157
|
+
next_(nullptr) {
|
|
158
|
+
data_ = new char[len];
|
|
159
|
+
if (env_ != nullptr)
|
|
160
|
+
env_->isolate()->AdjustAmountOfExternalAllocatedMemory(len);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
~Buffer() {
|
|
164
|
+
delete[] data_;
|
|
165
|
+
if (env_ != nullptr) {
|
|
166
|
+
const int64_t len = static_cast<int64_t>(len_);
|
|
167
|
+
env_->isolate()->AdjustAmountOfExternalAllocatedMemory(-len);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
Environment* env_;
|
|
172
|
+
size_t read_pos_;
|
|
173
|
+
size_t write_pos_;
|
|
174
|
+
size_t len_;
|
|
175
|
+
Buffer* next_;
|
|
176
|
+
char* data_;
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
Environment* env_ = nullptr;
|
|
180
|
+
size_t initial_ = kInitialBufferLength;
|
|
181
|
+
size_t length_ = 0;
|
|
182
|
+
size_t allocate_hint_ = 0;
|
|
183
|
+
int eof_return_ = -1;
|
|
184
|
+
Buffer* read_head_ = nullptr;
|
|
185
|
+
Buffer* write_head_ = nullptr;
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
} // namespace crypto
|
|
189
|
+
} // namespace node
|
|
190
|
+
|
|
191
|
+
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
192
|
+
|
|
193
|
+
#endif // SRC_CRYPTO_CRYPTO_BIO_H_
|
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
#ifndef SRC_CRYPTO_CRYPTO_CIPHER_H_
|
|
2
|
+
#define SRC_CRYPTO_CRYPTO_CIPHER_H_
|
|
3
|
+
|
|
4
|
+
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
5
|
+
|
|
6
|
+
#include "crypto/crypto_keys.h"
|
|
7
|
+
#include "crypto/crypto_util.h"
|
|
8
|
+
#include "base_object.h"
|
|
9
|
+
#include "env.h"
|
|
10
|
+
#include "memory_tracker.h"
|
|
11
|
+
#include "v8.h"
|
|
12
|
+
|
|
13
|
+
#include <string>
|
|
14
|
+
|
|
15
|
+
namespace node {
|
|
16
|
+
namespace crypto {
|
|
17
|
+
class CipherBase : public BaseObject {
|
|
18
|
+
public:
|
|
19
|
+
static void GetSSLCiphers(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
20
|
+
static void GetCiphers(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
21
|
+
|
|
22
|
+
static void Initialize(Environment* env, v8::Local<v8::Object> target);
|
|
23
|
+
static void RegisterExternalReferences(ExternalReferenceRegistry* registry);
|
|
24
|
+
|
|
25
|
+
void MemoryInfo(MemoryTracker* tracker) const override;
|
|
26
|
+
SET_MEMORY_INFO_NAME(CipherBase)
|
|
27
|
+
SET_SELF_SIZE(CipherBase)
|
|
28
|
+
|
|
29
|
+
protected:
|
|
30
|
+
enum CipherKind {
|
|
31
|
+
kCipher,
|
|
32
|
+
kDecipher
|
|
33
|
+
};
|
|
34
|
+
enum UpdateResult {
|
|
35
|
+
kSuccess,
|
|
36
|
+
kErrorMessageSize,
|
|
37
|
+
kErrorState
|
|
38
|
+
};
|
|
39
|
+
enum AuthTagState {
|
|
40
|
+
kAuthTagUnknown,
|
|
41
|
+
kAuthTagKnown,
|
|
42
|
+
kAuthTagPassedToOpenSSL
|
|
43
|
+
};
|
|
44
|
+
static const unsigned kNoAuthTagLength = static_cast<unsigned>(-1);
|
|
45
|
+
|
|
46
|
+
void CommonInit(const char* cipher_type,
|
|
47
|
+
const ncrypto::Cipher& cipher,
|
|
48
|
+
const unsigned char* key,
|
|
49
|
+
int key_len,
|
|
50
|
+
const unsigned char* iv,
|
|
51
|
+
int iv_len,
|
|
52
|
+
unsigned int auth_tag_len);
|
|
53
|
+
void Init(const char* cipher_type,
|
|
54
|
+
const ArrayBufferOrViewContents<unsigned char>& key_buf,
|
|
55
|
+
unsigned int auth_tag_len);
|
|
56
|
+
void InitIv(const char* cipher_type,
|
|
57
|
+
const ByteSource& key_buf,
|
|
58
|
+
const ArrayBufferOrViewContents<unsigned char>& iv_buf,
|
|
59
|
+
unsigned int auth_tag_len);
|
|
60
|
+
bool InitAuthenticated(const char* cipher_type, int iv_len,
|
|
61
|
+
unsigned int auth_tag_len);
|
|
62
|
+
bool CheckCCMMessageLength(int message_len);
|
|
63
|
+
UpdateResult Update(const char* data, size_t len,
|
|
64
|
+
std::unique_ptr<v8::BackingStore>* out);
|
|
65
|
+
bool Final(std::unique_ptr<v8::BackingStore>* out);
|
|
66
|
+
bool SetAutoPadding(bool auto_padding);
|
|
67
|
+
|
|
68
|
+
bool IsAuthenticatedMode() const;
|
|
69
|
+
bool SetAAD(
|
|
70
|
+
const ArrayBufferOrViewContents<unsigned char>& data,
|
|
71
|
+
int plaintext_len);
|
|
72
|
+
bool MaybePassAuthTagToOpenSSL();
|
|
73
|
+
|
|
74
|
+
static void New(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
75
|
+
static void Init(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
76
|
+
static void InitIv(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
77
|
+
static void Update(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
78
|
+
static void Final(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
79
|
+
static void SetAutoPadding(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
80
|
+
|
|
81
|
+
static void GetAuthTag(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
82
|
+
static void SetAuthTag(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
83
|
+
static void SetAAD(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
84
|
+
|
|
85
|
+
CipherBase(Environment* env, v8::Local<v8::Object> wrap, CipherKind kind);
|
|
86
|
+
|
|
87
|
+
private:
|
|
88
|
+
ncrypto::CipherCtxPointer ctx_;
|
|
89
|
+
const CipherKind kind_;
|
|
90
|
+
AuthTagState auth_tag_state_;
|
|
91
|
+
unsigned int auth_tag_len_;
|
|
92
|
+
char auth_tag_[EVP_GCM_TLS_TAG_LEN];
|
|
93
|
+
bool pending_auth_failed_;
|
|
94
|
+
int max_message_size_;
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
class PublicKeyCipher {
|
|
98
|
+
public:
|
|
99
|
+
typedef int (*EVP_PKEY_cipher_init_t)(EVP_PKEY_CTX* ctx);
|
|
100
|
+
typedef int (*EVP_PKEY_cipher_t)(EVP_PKEY_CTX* ctx,
|
|
101
|
+
unsigned char* out, size_t* outlen,
|
|
102
|
+
const unsigned char* in, size_t inlen);
|
|
103
|
+
|
|
104
|
+
enum Operation {
|
|
105
|
+
kPublic,
|
|
106
|
+
kPrivate
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
template <Operation operation,
|
|
110
|
+
EVP_PKEY_cipher_init_t EVP_PKEY_cipher_init,
|
|
111
|
+
EVP_PKEY_cipher_t EVP_PKEY_cipher>
|
|
112
|
+
static bool Cipher(Environment* env,
|
|
113
|
+
const ncrypto::EVPKeyPointer& pkey,
|
|
114
|
+
int padding,
|
|
115
|
+
const EVP_MD* digest,
|
|
116
|
+
const ArrayBufferOrViewContents<unsigned char>& oaep_label,
|
|
117
|
+
const ArrayBufferOrViewContents<unsigned char>& data,
|
|
118
|
+
std::unique_ptr<v8::BackingStore>* out);
|
|
119
|
+
|
|
120
|
+
template <Operation operation,
|
|
121
|
+
EVP_PKEY_cipher_init_t EVP_PKEY_cipher_init,
|
|
122
|
+
EVP_PKEY_cipher_t EVP_PKEY_cipher>
|
|
123
|
+
static void Cipher(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
enum WebCryptoCipherMode {
|
|
127
|
+
kWebCryptoCipherEncrypt,
|
|
128
|
+
kWebCryptoCipherDecrypt
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
enum class WebCryptoCipherStatus {
|
|
132
|
+
OK,
|
|
133
|
+
INVALID_KEY_TYPE,
|
|
134
|
+
FAILED
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
// CipherJob is a base implementation class for implementations of
|
|
138
|
+
// one-shot sync and async ciphers. It has been added primarily to
|
|
139
|
+
// support the AES and RSA ciphers underlying the WebCrypt API.
|
|
140
|
+
//
|
|
141
|
+
// See the crypto_aes and crypto_rsa headers for examples of how to
|
|
142
|
+
// use CipherJob.
|
|
143
|
+
template <typename CipherTraits>
|
|
144
|
+
class CipherJob final : public CryptoJob<CipherTraits> {
|
|
145
|
+
public:
|
|
146
|
+
using AdditionalParams = typename CipherTraits::AdditionalParameters;
|
|
147
|
+
|
|
148
|
+
static void New(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
|
149
|
+
Environment* env = Environment::GetCurrent(args);
|
|
150
|
+
CHECK(args.IsConstructCall());
|
|
151
|
+
|
|
152
|
+
CryptoJobMode mode = GetCryptoJobMode(args[0]);
|
|
153
|
+
|
|
154
|
+
CHECK(args[1]->IsUint32()); // Cipher Mode
|
|
155
|
+
|
|
156
|
+
uint32_t cmode = args[1].As<v8::Uint32>()->Value();
|
|
157
|
+
CHECK_LE(cmode, WebCryptoCipherMode::kWebCryptoCipherDecrypt);
|
|
158
|
+
WebCryptoCipherMode cipher_mode = static_cast<WebCryptoCipherMode>(cmode);
|
|
159
|
+
|
|
160
|
+
CHECK(args[2]->IsObject()); // KeyObject
|
|
161
|
+
KeyObjectHandle* key;
|
|
162
|
+
ASSIGN_OR_RETURN_UNWRAP(&key, args[2]);
|
|
163
|
+
CHECK_NOT_NULL(key);
|
|
164
|
+
|
|
165
|
+
ArrayBufferOrViewContents<char> data(args[3]); // data to operate on
|
|
166
|
+
if (!data.CheckSizeInt32())
|
|
167
|
+
return THROW_ERR_OUT_OF_RANGE(env, "data is too large");
|
|
168
|
+
|
|
169
|
+
AdditionalParams params;
|
|
170
|
+
if (CipherTraits::AdditionalConfig(mode, args, 4, cipher_mode, ¶ms)
|
|
171
|
+
.IsNothing()) {
|
|
172
|
+
// The CipherTraits::AdditionalConfig is responsible for
|
|
173
|
+
// calling an appropriate THROW_CRYPTO_* variant reporting
|
|
174
|
+
// whatever error caused initialization to fail.
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
new CipherJob<CipherTraits>(
|
|
179
|
+
env,
|
|
180
|
+
args.This(),
|
|
181
|
+
mode,
|
|
182
|
+
key,
|
|
183
|
+
cipher_mode,
|
|
184
|
+
data,
|
|
185
|
+
std::move(params));
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
static void Initialize(
|
|
189
|
+
Environment* env,
|
|
190
|
+
v8::Local<v8::Object> target) {
|
|
191
|
+
CryptoJob<CipherTraits>::Initialize(New, env, target);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
static void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
|
|
195
|
+
CryptoJob<CipherTraits>::RegisterExternalReferences(New, registry);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
CipherJob(Environment* env,
|
|
199
|
+
v8::Local<v8::Object> object,
|
|
200
|
+
CryptoJobMode mode,
|
|
201
|
+
KeyObjectHandle* key,
|
|
202
|
+
WebCryptoCipherMode cipher_mode,
|
|
203
|
+
const ArrayBufferOrViewContents<char>& data,
|
|
204
|
+
AdditionalParams&& params)
|
|
205
|
+
: CryptoJob<CipherTraits>(env,
|
|
206
|
+
object,
|
|
207
|
+
AsyncWrap::PROVIDER_CIPHERREQUEST,
|
|
208
|
+
mode,
|
|
209
|
+
std::move(params)),
|
|
210
|
+
key_(key->Data().addRef()),
|
|
211
|
+
cipher_mode_(cipher_mode),
|
|
212
|
+
in_(mode == kCryptoJobAsync ? data.ToCopy() : data.ToByteSource()) {}
|
|
213
|
+
|
|
214
|
+
const KeyObjectData& key() const { return key_; }
|
|
215
|
+
|
|
216
|
+
WebCryptoCipherMode cipher_mode() const { return cipher_mode_; }
|
|
217
|
+
|
|
218
|
+
void DoThreadPoolWork() override {
|
|
219
|
+
const WebCryptoCipherStatus status =
|
|
220
|
+
CipherTraits::DoCipher(
|
|
221
|
+
AsyncWrap::env(),
|
|
222
|
+
key(),
|
|
223
|
+
cipher_mode_,
|
|
224
|
+
*CryptoJob<CipherTraits>::params(),
|
|
225
|
+
in_,
|
|
226
|
+
&out_);
|
|
227
|
+
if (status == WebCryptoCipherStatus::OK) {
|
|
228
|
+
// Success!
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
CryptoErrorStore* errors = CryptoJob<CipherTraits>::errors();
|
|
232
|
+
errors->Capture();
|
|
233
|
+
if (errors->Empty()) {
|
|
234
|
+
switch (status) {
|
|
235
|
+
case WebCryptoCipherStatus::OK:
|
|
236
|
+
UNREACHABLE();
|
|
237
|
+
break;
|
|
238
|
+
case WebCryptoCipherStatus::INVALID_KEY_TYPE:
|
|
239
|
+
errors->Insert(NodeCryptoError::INVALID_KEY_TYPE);
|
|
240
|
+
break;
|
|
241
|
+
case WebCryptoCipherStatus::FAILED:
|
|
242
|
+
errors->Insert(NodeCryptoError::CIPHER_JOB_FAILED);
|
|
243
|
+
break;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
v8::Maybe<void> ToResult(v8::Local<v8::Value>* err,
|
|
249
|
+
v8::Local<v8::Value>* result) override {
|
|
250
|
+
Environment* env = AsyncWrap::env();
|
|
251
|
+
CryptoErrorStore* errors = CryptoJob<CipherTraits>::errors();
|
|
252
|
+
|
|
253
|
+
if (errors->Empty())
|
|
254
|
+
errors->Capture();
|
|
255
|
+
|
|
256
|
+
if (out_.size() > 0 || errors->Empty()) {
|
|
257
|
+
CHECK(errors->Empty());
|
|
258
|
+
*err = v8::Undefined(env->isolate());
|
|
259
|
+
*result = out_.ToArrayBuffer(env);
|
|
260
|
+
if (result->IsEmpty()) {
|
|
261
|
+
return v8::Nothing<void>();
|
|
262
|
+
}
|
|
263
|
+
} else {
|
|
264
|
+
*result = v8::Undefined(env->isolate());
|
|
265
|
+
if (!errors->ToException(env).ToLocal(err)) {
|
|
266
|
+
return v8::Nothing<void>();
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
CHECK(!result->IsEmpty());
|
|
270
|
+
CHECK(!err->IsEmpty());
|
|
271
|
+
return v8::JustVoid();
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
SET_SELF_SIZE(CipherJob)
|
|
275
|
+
void MemoryInfo(MemoryTracker* tracker) const override {
|
|
276
|
+
if (CryptoJob<CipherTraits>::mode() == kCryptoJobAsync)
|
|
277
|
+
tracker->TrackFieldWithSize("in", in_.size());
|
|
278
|
+
tracker->TrackFieldWithSize("out", out_.size());
|
|
279
|
+
CryptoJob<CipherTraits>::MemoryInfo(tracker);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
private:
|
|
283
|
+
KeyObjectData key_;
|
|
284
|
+
WebCryptoCipherMode cipher_mode_;
|
|
285
|
+
ByteSource in_;
|
|
286
|
+
ByteSource out_;
|
|
287
|
+
};
|
|
288
|
+
|
|
289
|
+
} // namespace crypto
|
|
290
|
+
} // namespace node
|
|
291
|
+
|
|
292
|
+
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
293
|
+
#endif // SRC_CRYPTO_CRYPTO_CIPHER_H_
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
// Copyright Joyent, Inc. and other Node contributors.
|
|
2
|
+
//
|
|
3
|
+
// Permission is hereby granted, free of charge, to any person obtaining a
|
|
4
|
+
// copy of this software and associated documentation files (the
|
|
5
|
+
// "Software"), to deal in the Software without restriction, including
|
|
6
|
+
// without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
+
// distribute, sublicense, and/or sell copies of the Software, and to permit
|
|
8
|
+
// persons to whom the Software is furnished to do so, subject to the
|
|
9
|
+
// following conditions:
|
|
10
|
+
//
|
|
11
|
+
// The above copyright notice and this permission notice shall be included
|
|
12
|
+
// in all copies or substantial portions of the Software.
|
|
13
|
+
//
|
|
14
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
15
|
+
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
+
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
|
17
|
+
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
18
|
+
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
19
|
+
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
|
20
|
+
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
21
|
+
|
|
22
|
+
#ifndef SRC_CRYPTO_CRYPTO_CLIENTHELLO_INL_H_
|
|
23
|
+
#define SRC_CRYPTO_CRYPTO_CLIENTHELLO_INL_H_
|
|
24
|
+
|
|
25
|
+
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
26
|
+
|
|
27
|
+
#include "crypto/crypto_clienthello.h"
|
|
28
|
+
#include "util.h"
|
|
29
|
+
|
|
30
|
+
namespace node {
|
|
31
|
+
namespace crypto {
|
|
32
|
+
inline ClientHelloParser::ClientHelloParser()
|
|
33
|
+
: state_(kEnded),
|
|
34
|
+
onhello_cb_(nullptr),
|
|
35
|
+
onend_cb_(nullptr),
|
|
36
|
+
cb_arg_(nullptr) {
|
|
37
|
+
Reset();
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
inline void ClientHelloParser::Reset() {
|
|
41
|
+
frame_len_ = 0;
|
|
42
|
+
body_offset_ = 0;
|
|
43
|
+
extension_offset_ = 0;
|
|
44
|
+
session_size_ = 0;
|
|
45
|
+
session_id_ = nullptr;
|
|
46
|
+
tls_ticket_size_ = -1;
|
|
47
|
+
tls_ticket_ = nullptr;
|
|
48
|
+
servername_size_ = 0;
|
|
49
|
+
servername_ = nullptr;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
inline void ClientHelloParser::Start(ClientHelloParser::OnHelloCb onhello_cb,
|
|
53
|
+
ClientHelloParser::OnEndCb onend_cb,
|
|
54
|
+
void* cb_arg) {
|
|
55
|
+
if (!IsEnded())
|
|
56
|
+
return;
|
|
57
|
+
Reset();
|
|
58
|
+
|
|
59
|
+
CHECK_NOT_NULL(onhello_cb);
|
|
60
|
+
|
|
61
|
+
state_ = kWaiting;
|
|
62
|
+
onhello_cb_ = onhello_cb;
|
|
63
|
+
onend_cb_ = onend_cb;
|
|
64
|
+
cb_arg_ = cb_arg;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
inline void ClientHelloParser::End() {
|
|
68
|
+
if (state_ == kEnded)
|
|
69
|
+
return;
|
|
70
|
+
state_ = kEnded;
|
|
71
|
+
if (onend_cb_ != nullptr) {
|
|
72
|
+
onend_cb_(cb_arg_);
|
|
73
|
+
onend_cb_ = nullptr;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
inline bool ClientHelloParser::IsEnded() const {
|
|
78
|
+
return state_ == kEnded;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
inline bool ClientHelloParser::IsPaused() const {
|
|
82
|
+
return state_ == kPaused;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
} // namespace crypto
|
|
86
|
+
} // namespace node
|
|
87
|
+
|
|
88
|
+
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
89
|
+
|
|
90
|
+
#endif // SRC_CRYPTO_CRYPTO_CLIENTHELLO_INL_H_
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
// Copyright Joyent, Inc. and other Node contributors.
|
|
2
|
+
//
|
|
3
|
+
// Permission is hereby granted, free of charge, to any person obtaining a
|
|
4
|
+
// copy of this software and associated documentation files (the
|
|
5
|
+
// "Software"), to deal in the Software without restriction, including
|
|
6
|
+
// without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
+
// distribute, sublicense, and/or sell copies of the Software, and to permit
|
|
8
|
+
// persons to whom the Software is furnished to do so, subject to the
|
|
9
|
+
// following conditions:
|
|
10
|
+
//
|
|
11
|
+
// The above copyright notice and this permission notice shall be included
|
|
12
|
+
// in all copies or substantial portions of the Software.
|
|
13
|
+
//
|
|
14
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
15
|
+
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
+
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
|
17
|
+
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
18
|
+
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
19
|
+
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
|
20
|
+
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
21
|
+
|
|
22
|
+
#ifndef SRC_CRYPTO_CRYPTO_CLIENTHELLO_H_
|
|
23
|
+
#define SRC_CRYPTO_CRYPTO_CLIENTHELLO_H_
|
|
24
|
+
|
|
25
|
+
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
26
|
+
|
|
27
|
+
#include <cstddef> // size_t
|
|
28
|
+
#include <cstdint>
|
|
29
|
+
|
|
30
|
+
namespace node {
|
|
31
|
+
namespace crypto {
|
|
32
|
+
// Parse the client hello so we can do async session resumption. OpenSSL's
|
|
33
|
+
// session resumption uses synchronous callbacks, see SSL_CTX_sess_set_get_cb
|
|
34
|
+
// and get_session_cb.
|
|
35
|
+
//
|
|
36
|
+
// TLS1.3 handshakes masquerade as TLS1.2 session resumption, and to do this,
|
|
37
|
+
// they always include a session_id in the ClientHello, making up a bogus value
|
|
38
|
+
// if necessary. The parser can't know if its a bogus id, and will cause a
|
|
39
|
+
// 'newSession' event to be emitted. This should do no harm, the id won't be
|
|
40
|
+
// found, and the handshake will continue.
|
|
41
|
+
class ClientHelloParser {
|
|
42
|
+
public:
|
|
43
|
+
inline ClientHelloParser();
|
|
44
|
+
|
|
45
|
+
class ClientHello {
|
|
46
|
+
public:
|
|
47
|
+
inline uint8_t session_size() const { return session_size_; }
|
|
48
|
+
inline const uint8_t* session_id() const { return session_id_; }
|
|
49
|
+
inline bool has_ticket() const { return has_ticket_; }
|
|
50
|
+
inline uint8_t servername_size() const { return servername_size_; }
|
|
51
|
+
inline const uint8_t* servername() const { return servername_; }
|
|
52
|
+
|
|
53
|
+
private:
|
|
54
|
+
uint8_t session_size_;
|
|
55
|
+
const uint8_t* session_id_;
|
|
56
|
+
bool has_ticket_;
|
|
57
|
+
uint8_t servername_size_;
|
|
58
|
+
const uint8_t* servername_;
|
|
59
|
+
|
|
60
|
+
friend class ClientHelloParser;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
typedef void (*OnHelloCb)(void* arg, const ClientHello& hello);
|
|
64
|
+
typedef void (*OnEndCb)(void* arg);
|
|
65
|
+
|
|
66
|
+
void Parse(const uint8_t* data, size_t avail);
|
|
67
|
+
|
|
68
|
+
inline void Reset();
|
|
69
|
+
inline void Start(OnHelloCb onhello_cb, OnEndCb onend_cb, void* cb_arg);
|
|
70
|
+
inline void End();
|
|
71
|
+
inline bool IsPaused() const;
|
|
72
|
+
inline bool IsEnded() const;
|
|
73
|
+
|
|
74
|
+
private:
|
|
75
|
+
static const size_t kMaxTLSFrameLen = 16 * 1024 + 5;
|
|
76
|
+
static const size_t kMaxSSLExFrameLen = 32 * 1024;
|
|
77
|
+
static const uint8_t kServernameHostname = 0;
|
|
78
|
+
static const size_t kMinStatusRequestSize = 5;
|
|
79
|
+
|
|
80
|
+
enum ParseState {
|
|
81
|
+
kWaiting,
|
|
82
|
+
kTLSHeader,
|
|
83
|
+
kPaused,
|
|
84
|
+
kEnded
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
enum FrameType {
|
|
88
|
+
kChangeCipherSpec = 20,
|
|
89
|
+
kAlert = 21,
|
|
90
|
+
kHandshake = 22,
|
|
91
|
+
kApplicationData = 23,
|
|
92
|
+
kOther = 255
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
enum HandshakeType {
|
|
96
|
+
kClientHello = 1
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
enum ExtensionType {
|
|
100
|
+
kServerName = 0,
|
|
101
|
+
kTLSSessionTicket = 35
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
bool ParseRecordHeader(const uint8_t* data, size_t avail);
|
|
105
|
+
void ParseHeader(const uint8_t* data, size_t avail);
|
|
106
|
+
void ParseExtension(const uint16_t type,
|
|
107
|
+
const uint8_t* data,
|
|
108
|
+
size_t len);
|
|
109
|
+
bool ParseTLSClientHello(const uint8_t* data, size_t avail);
|
|
110
|
+
|
|
111
|
+
ParseState state_;
|
|
112
|
+
OnHelloCb onhello_cb_;
|
|
113
|
+
OnEndCb onend_cb_;
|
|
114
|
+
void* cb_arg_;
|
|
115
|
+
size_t frame_len_ = 0;
|
|
116
|
+
size_t body_offset_ = 0;
|
|
117
|
+
size_t extension_offset_ = 0;
|
|
118
|
+
uint8_t session_size_ = 0;
|
|
119
|
+
const uint8_t* session_id_ = nullptr;
|
|
120
|
+
uint16_t servername_size_ = 0;
|
|
121
|
+
const uint8_t* servername_ = nullptr;
|
|
122
|
+
uint16_t tls_ticket_size_ = -1;
|
|
123
|
+
const uint8_t* tls_ticket_ = nullptr;
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
} // namespace crypto
|
|
127
|
+
} // namespace node
|
|
128
|
+
|
|
129
|
+
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
130
|
+
|
|
131
|
+
#endif // SRC_CRYPTO_CRYPTO_CLIENTHELLO_H_
|