@encharm/cws 4.3.0 → 4.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -7
- package/dist/bindings/cws_darwin_arm64_node108.node +0 -0
- package/dist/bindings/cws_darwin_arm64_node115.node +0 -0
- package/dist/bindings/cws_darwin_arm64_node83.node +0 -0
- package/dist/bindings/cws_darwin_arm64_node93.node +0 -0
- package/dist/bindings/cws_darwin_x64_node108.node +0 -0
- package/dist/bindings/cws_darwin_x64_node115.node +0 -0
- package/dist/bindings/cws_darwin_x64_node83.node +0 -0
- package/dist/bindings/cws_darwin_x64_node93.node +0 -0
- package/dist/bindings/cws_linux_arm64_node108.node +0 -0
- package/dist/bindings/cws_linux_arm64_node115.node +0 -0
- package/dist/bindings/cws_linux_arm64_node83.node +0 -0
- package/dist/bindings/cws_linux_arm64_node93.node +0 -0
- package/dist/bindings/cws_linux_x64_node108.node +0 -0
- package/dist/bindings/cws_linux_x64_node115.node +0 -0
- package/dist/bindings/cws_linux_x64_node83.node +0 -0
- package/dist/bindings/cws_linux_x64_node93.node +0 -0
- package/dist/bindings/cws_win32_x64_node108.node +0 -0
- package/dist/bindings/cws_win32_x64_node115.node +0 -0
- package/dist/bindings/cws_win32_x64_node83.node +0 -0
- package/dist/bindings/cws_win32_x64_node93.node +0 -0
- package/dist/shared.js +1 -1
- package/package.json +5 -5
- package/src/Addon.cpp +4 -12
- package/src/Addon.h +55 -90
- package/src/Socket.h +1 -0
- package/src/cSNode.cpp +3 -8
- package/src/headers/20/acorn_version.h +6 -0
- package/src/headers/20/aliased_buffer-inl.h +243 -0
- package/src/headers/20/aliased_buffer.h +206 -0
- package/src/headers/20/aliased_struct-inl.h +54 -0
- package/src/headers/20/aliased_struct.h +63 -0
- package/src/headers/20/async_wrap-inl.h +93 -0
- package/src/headers/20/async_wrap.h +252 -0
- package/src/headers/20/base64-inl.h +193 -0
- package/src/headers/20/base64.h +53 -0
- package/src/headers/20/base64_version.h +6 -0
- package/src/headers/20/base_object-inl.h +316 -0
- package/src/headers/20/base_object.h +320 -0
- package/src/headers/20/base_object_types.h +73 -0
- package/src/headers/20/blob_serializer_deserializer-inl.h +361 -0
- package/src/headers/20/blob_serializer_deserializer.h +132 -0
- package/src/headers/20/callback_queue-inl.h +97 -0
- package/src/headers/20/callback_queue.h +79 -0
- package/src/headers/20/cares_wrap.h +524 -0
- package/src/headers/20/cjs_module_lexer_version.h +6 -0
- package/src/headers/20/cleanup_queue-inl.h +62 -0
- package/src/headers/20/cleanup_queue.h +85 -0
- package/src/headers/20/connect_wrap.h +26 -0
- package/src/headers/20/connection_wrap.h +29 -0
- package/src/headers/20/cppgc/DEPS +8 -0
- package/src/headers/20/cppgc/OWNERS +2 -0
- package/src/headers/20/cppgc/README.md +135 -0
- package/src/headers/20/cppgc/allocation.h +310 -0
- package/src/headers/20/cppgc/common.h +28 -0
- package/src/headers/20/cppgc/cross-thread-persistent.h +466 -0
- package/src/headers/20/cppgc/custom-space.h +97 -0
- package/src/headers/20/cppgc/default-platform.h +67 -0
- package/src/headers/20/cppgc/ephemeron-pair.h +30 -0
- package/src/headers/20/cppgc/explicit-management.h +100 -0
- package/src/headers/20/cppgc/garbage-collected.h +106 -0
- package/src/headers/20/cppgc/heap-consistency.h +309 -0
- package/src/headers/20/cppgc/heap-handle.h +48 -0
- package/src/headers/20/cppgc/heap-state.h +82 -0
- package/src/headers/20/cppgc/heap-statistics.h +120 -0
- package/src/headers/20/cppgc/heap.h +202 -0
- package/src/headers/20/cppgc/internal/api-constants.h +68 -0
- package/src/headers/20/cppgc/internal/atomic-entry-flag.h +48 -0
- package/src/headers/20/cppgc/internal/base-page-handle.h +45 -0
- package/src/headers/20/cppgc/internal/caged-heap-local-data.h +111 -0
- package/src/headers/20/cppgc/internal/caged-heap.h +61 -0
- package/src/headers/20/cppgc/internal/compiler-specific.h +38 -0
- package/src/headers/20/cppgc/internal/finalizer-trait.h +93 -0
- package/src/headers/20/cppgc/internal/gc-info.h +157 -0
- package/src/headers/20/cppgc/internal/logging.h +50 -0
- package/src/headers/20/cppgc/internal/member-storage.h +248 -0
- package/src/headers/20/cppgc/internal/name-trait.h +137 -0
- package/src/headers/20/cppgc/internal/persistent-node.h +214 -0
- package/src/headers/20/cppgc/internal/pointer-policies.h +243 -0
- package/src/headers/20/cppgc/internal/write-barrier.h +487 -0
- package/src/headers/20/cppgc/liveness-broker.h +78 -0
- package/src/headers/20/cppgc/macros.h +35 -0
- package/src/headers/20/cppgc/member.h +604 -0
- package/src/headers/20/cppgc/name-provider.h +65 -0
- package/src/headers/20/cppgc/object-size-trait.h +58 -0
- package/src/headers/20/cppgc/persistent.h +373 -0
- package/src/headers/20/cppgc/platform.h +158 -0
- package/src/headers/20/cppgc/prefinalizer.h +75 -0
- package/src/headers/20/cppgc/process-heap-statistics.h +36 -0
- package/src/headers/20/cppgc/sentinel-pointer.h +32 -0
- package/src/headers/20/cppgc/source-location.h +92 -0
- package/src/headers/20/cppgc/testing.h +106 -0
- package/src/headers/20/cppgc/trace-trait.h +120 -0
- package/src/headers/20/cppgc/type-traits.h +250 -0
- package/src/headers/20/cppgc/visitor.h +426 -0
- package/src/headers/20/crypto/crypto_clienthello.h +131 -0
- package/src/headers/20/crypto/crypto_context.h +160 -0
- package/src/headers/20/crypto/crypto_keys.h +416 -0
- package/src/headers/20/crypto/crypto_tls.h +295 -0
- package/src/headers/20/crypto/crypto_util.h +805 -0
- package/src/headers/20/crypto_clienthello.h +131 -0
- package/src/headers/20/debug_utils-inl.h +226 -0
- package/src/headers/20/debug_utils.h +188 -0
- package/src/headers/20/diagnosticfilename-inl.h +33 -0
- package/src/headers/20/encoding_binding.h +59 -0
- package/src/headers/20/env-inl.h +923 -0
- package/src/headers/20/env.h +1193 -0
- package/src/headers/20/env_properties.h +444 -0
- package/src/headers/20/handle_wrap.h +123 -0
- package/src/headers/20/histogram-inl.h +107 -0
- package/src/headers/20/histogram.h +240 -0
- package/src/headers/20/inspector_agent.h +144 -0
- package/src/headers/20/inspector_io.h +78 -0
- package/src/headers/20/inspector_profiler.h +149 -0
- package/src/headers/20/inspector_socket.h +60 -0
- package/src/headers/20/inspector_socket_server.h +110 -0
- package/src/headers/20/js_native_api.h +591 -0
- package/src/headers/20/js_native_api_types.h +168 -0
- package/src/headers/20/js_native_api_v8.h +426 -0
- package/src/headers/20/js_native_api_v8_internals.h +39 -0
- package/src/headers/20/js_stream.h +52 -0
- package/src/headers/20/json_parser.h +38 -0
- package/src/headers/20/json_utils.h +172 -0
- package/src/headers/20/memory_tracker-inl.h +356 -0
- package/src/headers/20/memory_tracker.h +289 -0
- package/src/headers/20/module_wrap.h +117 -0
- package/src/headers/20/node.h +1514 -0
- package/src/headers/20/node_api.h +260 -0
- package/src/headers/20/node_api_internals.h +42 -0
- package/src/headers/20/node_api_types.h +52 -0
- package/src/headers/20/node_binding.h +142 -0
- package/src/headers/20/node_blob.h +159 -0
- package/src/headers/20/node_bob-inl.h +36 -0
- package/src/headers/20/node_bob.h +107 -0
- package/src/headers/20/node_buffer.h +92 -0
- package/src/headers/20/node_builtins.h +197 -0
- package/src/headers/20/node_constants.h +79 -0
- package/src/headers/20/node_context_data.h +98 -0
- package/src/headers/20/node_contextify.h +182 -0
- package/src/headers/20/node_crypto.h +56 -0
- package/src/headers/20/node_dir.h +52 -0
- package/src/headers/20/node_dotenv.h +37 -0
- package/src/headers/20/node_errors.h +313 -0
- package/src/headers/20/node_exit_code.h +54 -0
- package/src/headers/20/node_external_reference.h +172 -0
- package/src/headers/20/node_file-inl.h +357 -0
- package/src/headers/20/node_file.h +524 -0
- package/src/headers/20/node_http2.h +1146 -0
- package/src/headers/20/node_http2_state.h +147 -0
- package/src/headers/20/node_http_common-inl.h +201 -0
- package/src/headers/20/node_http_common.h +532 -0
- package/src/headers/20/node_i18n.h +145 -0
- package/src/headers/20/node_internals.h +443 -0
- package/src/headers/20/node_main_instance.h +67 -0
- package/src/headers/20/node_mem-inl.h +112 -0
- package/src/headers/20/node_mem.h +45 -0
- package/src/headers/20/node_messaging.h +377 -0
- package/src/headers/20/node_metadata.h +138 -0
- package/src/headers/20/node_mutex.h +323 -0
- package/src/headers/20/node_object_wrap.h +132 -0
- package/src/headers/20/node_options-inl.h +478 -0
- package/src/headers/20/node_options.h +538 -0
- package/src/headers/20/node_perf.h +166 -0
- package/src/headers/20/node_perf_common.h +98 -0
- package/src/headers/20/node_platform.h +195 -0
- package/src/headers/20/node_process-inl.h +26 -0
- package/src/headers/20/node_process.h +99 -0
- package/src/headers/20/node_realm-inl.h +139 -0
- package/src/headers/20/node_realm.h +184 -0
- package/src/headers/20/node_report.h +42 -0
- package/src/headers/20/node_revert.h +82 -0
- package/src/headers/20/node_root_certs.h +3443 -0
- package/src/headers/20/node_sea.h +56 -0
- package/src/headers/20/node_shadow_realm.h +46 -0
- package/src/headers/20/node_snapshot_builder.h +54 -0
- package/src/headers/20/node_snapshotable.h +164 -0
- package/src/headers/20/node_sockaddr-inl.h +266 -0
- package/src/headers/20/node_sockaddr.h +405 -0
- package/src/headers/20/node_stat_watcher.h +73 -0
- package/src/headers/20/node_threadsafe_cow-inl.h +54 -0
- package/src/headers/20/node_threadsafe_cow.h +105 -0
- package/src/headers/20/node_union_bytes.h +81 -0
- package/src/headers/20/node_url.h +92 -0
- package/src/headers/20/node_v8.h +77 -0
- package/src/headers/20/node_v8_platform-inl.h +205 -0
- package/src/headers/20/node_version.h +109 -0
- package/src/headers/20/node_wasi.h +184 -0
- package/src/headers/20/node_wasm_web_api.h +55 -0
- package/src/headers/20/node_watchdog.h +154 -0
- package/src/headers/20/node_worker.h +151 -0
- package/src/headers/20/permission/child_process_permission.h +28 -0
- package/src/headers/20/permission/fs_permission.h +152 -0
- package/src/headers/20/permission/permission.h +71 -0
- package/src/headers/20/permission/permission_base.h +49 -0
- package/src/headers/20/permission/worker_permission.h +28 -0
- package/src/headers/20/pipe_wrap.h +80 -0
- package/src/headers/20/req_wrap-inl.h +171 -0
- package/src/headers/20/req_wrap.h +77 -0
- package/src/headers/20/spawn_sync.h +242 -0
- package/src/headers/20/stream_base-inl.h +173 -0
- package/src/headers/20/stream_base.h +469 -0
- package/src/headers/20/stream_pipe.h +76 -0
- package/src/headers/20/stream_wrap.h +131 -0
- package/src/headers/20/string_bytes.h +120 -0
- package/src/headers/20/string_decoder-inl.h +37 -0
- package/src/headers/20/string_decoder.h +50 -0
- package/src/headers/20/string_search.h +638 -0
- package/src/headers/20/tcp_wrap.h +105 -0
- package/src/headers/20/threadpoolwork-inl.h +70 -0
- package/src/headers/20/timer_wrap-inl.h +32 -0
- package/src/headers/20/timer_wrap.h +85 -0
- package/src/headers/20/timers.h +70 -0
- package/src/headers/20/tracing/agent.h +195 -0
- package/src/headers/20/tracing/trace_event.h +720 -0
- package/src/headers/20/tracing/trace_event_common.h +1109 -0
- package/src/headers/20/tty_wrap.h +65 -0
- package/src/headers/20/udp_wrap.h +227 -0
- package/src/headers/20/undici_version.h +6 -0
- package/src/headers/20/util-inl.h +623 -0
- package/src/headers/20/util.h +988 -0
- package/src/headers/20/v8-cppgc.h +245 -0
- package/src/headers/20/v8-fast-api-calls.h +957 -0
- package/dist/bindings/cws_darwin_arm64_node64.node +0 -0
- package/dist/bindings/cws_darwin_arm64_node72.node +0 -0
- package/dist/bindings/cws_darwin_arm64_node79.node +0 -0
- package/dist/bindings/cws_darwin_x64_node64.node +0 -0
- package/dist/bindings/cws_darwin_x64_node72.node +0 -0
- package/dist/bindings/cws_darwin_x64_node79.node +0 -0
- package/dist/bindings/cws_linux_x64_node64.node +0 -0
- package/dist/bindings/cws_linux_x64_node72.node +0 -0
- package/dist/bindings/cws_linux_x64_node79.node +0 -0
- package/dist/bindings/cws_win32_x64_node64.node +0 -0
- package/dist/bindings/cws_win32_x64_node72.node +0 -0
- package/dist/bindings/cws_win32_x64_node79.node +0 -0
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
#ifndef SRC_CRYPTO_CRYPTO_CONTEXT_H_
|
|
2
|
+
#define SRC_CRYPTO_CRYPTO_CONTEXT_H_
|
|
3
|
+
|
|
4
|
+
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
5
|
+
|
|
6
|
+
#include "base_object.h"
|
|
7
|
+
#include "crypto/crypto_keys.h"
|
|
8
|
+
#include "crypto/crypto_util.h"
|
|
9
|
+
#include "env.h"
|
|
10
|
+
#include "memory_tracker.h"
|
|
11
|
+
#include "v8.h"
|
|
12
|
+
|
|
13
|
+
namespace node {
|
|
14
|
+
namespace crypto {
|
|
15
|
+
// A maxVersion of 0 means "any", but OpenSSL may support TLS versions that
|
|
16
|
+
// Node.js doesn't, so pin the max to what we do support.
|
|
17
|
+
constexpr int kMaxSupportedVersion = TLS1_3_VERSION;
|
|
18
|
+
|
|
19
|
+
void GetRootCertificates(
|
|
20
|
+
const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
21
|
+
|
|
22
|
+
void IsExtraRootCertsFileLoaded(
|
|
23
|
+
const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
24
|
+
|
|
25
|
+
X509_STORE* NewRootCertStore();
|
|
26
|
+
|
|
27
|
+
BIOPointer LoadBIO(Environment* env, v8::Local<v8::Value> v);
|
|
28
|
+
|
|
29
|
+
class SecureContext final : public BaseObject {
|
|
30
|
+
public:
|
|
31
|
+
using GetSessionCb = SSL_SESSION* (*)(SSL*, const unsigned char*, int, int*);
|
|
32
|
+
using KeylogCb = void (*)(const SSL*, const char*);
|
|
33
|
+
using NewSessionCb = int (*)(SSL*, SSL_SESSION*);
|
|
34
|
+
using SelectSNIContextCb = int (*)(SSL*, int*, void*);
|
|
35
|
+
|
|
36
|
+
~SecureContext() override;
|
|
37
|
+
|
|
38
|
+
static bool HasInstance(Environment* env, const v8::Local<v8::Value>& value);
|
|
39
|
+
static v8::Local<v8::FunctionTemplate> GetConstructorTemplate(
|
|
40
|
+
Environment* env);
|
|
41
|
+
static void Initialize(Environment* env, v8::Local<v8::Object> target);
|
|
42
|
+
static void RegisterExternalReferences(ExternalReferenceRegistry* registry);
|
|
43
|
+
static SecureContext* Create(Environment* env);
|
|
44
|
+
|
|
45
|
+
const SSLCtxPointer& ctx() const { return ctx_; }
|
|
46
|
+
|
|
47
|
+
// Non-const ctx() that allows for non-default initialization of
|
|
48
|
+
// the SecureContext.
|
|
49
|
+
SSLCtxPointer& ctx() { return ctx_; }
|
|
50
|
+
|
|
51
|
+
SSLPointer CreateSSL();
|
|
52
|
+
|
|
53
|
+
void SetGetSessionCallback(GetSessionCb cb);
|
|
54
|
+
void SetKeylogCallback(KeylogCb cb);
|
|
55
|
+
void SetNewSessionCallback(NewSessionCb cb);
|
|
56
|
+
void SetSelectSNIContextCallback(SelectSNIContextCb cb);
|
|
57
|
+
|
|
58
|
+
inline const X509Pointer& issuer() const { return issuer_; }
|
|
59
|
+
inline const X509Pointer& cert() const { return cert_; }
|
|
60
|
+
|
|
61
|
+
v8::Maybe<bool> AddCert(Environment* env, BIOPointer&& bio);
|
|
62
|
+
v8::Maybe<bool> SetCRL(Environment* env, const BIOPointer& bio);
|
|
63
|
+
v8::Maybe<bool> UseKey(Environment* env, std::shared_ptr<KeyObjectData> key);
|
|
64
|
+
|
|
65
|
+
void SetCACert(const BIOPointer& bio);
|
|
66
|
+
void SetRootCerts();
|
|
67
|
+
|
|
68
|
+
// TODO(joyeecheung): track the memory used by OpenSSL types
|
|
69
|
+
SET_NO_MEMORY_INFO()
|
|
70
|
+
SET_MEMORY_INFO_NAME(SecureContext)
|
|
71
|
+
SET_SELF_SIZE(SecureContext)
|
|
72
|
+
|
|
73
|
+
static const int kMaxSessionSize = 10 * 1024;
|
|
74
|
+
|
|
75
|
+
// See TicketKeyCallback
|
|
76
|
+
static const int kTicketKeyReturnIndex = 0;
|
|
77
|
+
static const int kTicketKeyHMACIndex = 1;
|
|
78
|
+
static const int kTicketKeyAESIndex = 2;
|
|
79
|
+
static const int kTicketKeyNameIndex = 3;
|
|
80
|
+
static const int kTicketKeyIVIndex = 4;
|
|
81
|
+
|
|
82
|
+
protected:
|
|
83
|
+
// OpenSSL structures are opaque. This is sizeof(SSL_CTX) for OpenSSL 1.1.1b:
|
|
84
|
+
static const int64_t kExternalSize = 1024;
|
|
85
|
+
|
|
86
|
+
static void New(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
87
|
+
static void Init(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
88
|
+
static void SetKey(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
89
|
+
#ifndef OPENSSL_NO_ENGINE
|
|
90
|
+
static void SetEngineKey(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
91
|
+
#endif // !OPENSSL_NO_ENGINE
|
|
92
|
+
static void SetCert(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
93
|
+
static void AddCACert(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
94
|
+
static void AddCRL(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
95
|
+
static void AddRootCerts(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
96
|
+
static void SetCipherSuites(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
97
|
+
static void SetCiphers(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
98
|
+
static void SetSigalgs(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
99
|
+
static void SetECDHCurve(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
100
|
+
static void SetDHParam(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
101
|
+
static void SetOptions(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
102
|
+
static void SetSessionIdContext(
|
|
103
|
+
const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
104
|
+
static void SetSessionTimeout(
|
|
105
|
+
const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
106
|
+
static void SetMinProto(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
107
|
+
static void SetMaxProto(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
108
|
+
static void GetMinProto(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
109
|
+
static void GetMaxProto(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
110
|
+
static void Close(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
111
|
+
static void LoadPKCS12(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
112
|
+
#ifndef OPENSSL_NO_ENGINE
|
|
113
|
+
static void SetClientCertEngine(
|
|
114
|
+
const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
115
|
+
#endif // !OPENSSL_NO_ENGINE
|
|
116
|
+
static void GetTicketKeys(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
117
|
+
static void SetTicketKeys(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
118
|
+
static void EnableTicketKeyCallback(
|
|
119
|
+
const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
120
|
+
static void CtxGetter(const v8::FunctionCallbackInfo<v8::Value>& info);
|
|
121
|
+
|
|
122
|
+
template <bool primary>
|
|
123
|
+
static void GetCertificate(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
124
|
+
|
|
125
|
+
static int TicketKeyCallback(SSL* ssl,
|
|
126
|
+
unsigned char* name,
|
|
127
|
+
unsigned char* iv,
|
|
128
|
+
EVP_CIPHER_CTX* ectx,
|
|
129
|
+
HMAC_CTX* hctx,
|
|
130
|
+
int enc);
|
|
131
|
+
|
|
132
|
+
static int TicketCompatibilityCallback(SSL* ssl,
|
|
133
|
+
unsigned char* name,
|
|
134
|
+
unsigned char* iv,
|
|
135
|
+
EVP_CIPHER_CTX* ectx,
|
|
136
|
+
HMAC_CTX* hctx,
|
|
137
|
+
int enc);
|
|
138
|
+
|
|
139
|
+
SecureContext(Environment* env, v8::Local<v8::Object> wrap);
|
|
140
|
+
void Reset();
|
|
141
|
+
|
|
142
|
+
private:
|
|
143
|
+
SSLCtxPointer ctx_;
|
|
144
|
+
X509Pointer cert_;
|
|
145
|
+
X509Pointer issuer_;
|
|
146
|
+
#ifndef OPENSSL_NO_ENGINE
|
|
147
|
+
bool client_cert_engine_provided_ = false;
|
|
148
|
+
EnginePointer private_key_engine_;
|
|
149
|
+
#endif // !OPENSSL_NO_ENGINE
|
|
150
|
+
|
|
151
|
+
unsigned char ticket_key_name_[16];
|
|
152
|
+
unsigned char ticket_key_aes_[16];
|
|
153
|
+
unsigned char ticket_key_hmac_[16];
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
} // namespace crypto
|
|
157
|
+
} // namespace node
|
|
158
|
+
|
|
159
|
+
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
160
|
+
#endif // SRC_CRYPTO_CRYPTO_CONTEXT_H_
|
|
@@ -0,0 +1,416 @@
|
|
|
1
|
+
#ifndef SRC_CRYPTO_CRYPTO_KEYS_H_
|
|
2
|
+
#define SRC_CRYPTO_CRYPTO_KEYS_H_
|
|
3
|
+
|
|
4
|
+
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
5
|
+
|
|
6
|
+
#include "crypto/crypto_util.h"
|
|
7
|
+
#include "base_object.h"
|
|
8
|
+
#include "env.h"
|
|
9
|
+
#include "memory_tracker.h"
|
|
10
|
+
#include "node_buffer.h"
|
|
11
|
+
#include "node_worker.h"
|
|
12
|
+
#include "v8.h"
|
|
13
|
+
|
|
14
|
+
#include <openssl/evp.h>
|
|
15
|
+
|
|
16
|
+
#include <memory>
|
|
17
|
+
#include <string>
|
|
18
|
+
|
|
19
|
+
namespace node {
|
|
20
|
+
namespace crypto {
|
|
21
|
+
enum PKEncodingType {
|
|
22
|
+
// RSAPublicKey / RSAPrivateKey according to PKCS#1.
|
|
23
|
+
kKeyEncodingPKCS1,
|
|
24
|
+
// PrivateKeyInfo or EncryptedPrivateKeyInfo according to PKCS#8.
|
|
25
|
+
kKeyEncodingPKCS8,
|
|
26
|
+
// SubjectPublicKeyInfo according to X.509.
|
|
27
|
+
kKeyEncodingSPKI,
|
|
28
|
+
// ECPrivateKey according to SEC1.
|
|
29
|
+
kKeyEncodingSEC1
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
enum PKFormatType {
|
|
33
|
+
kKeyFormatDER,
|
|
34
|
+
kKeyFormatPEM,
|
|
35
|
+
kKeyFormatJWK
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
enum KeyType {
|
|
39
|
+
kKeyTypeSecret,
|
|
40
|
+
kKeyTypePublic,
|
|
41
|
+
kKeyTypePrivate
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
enum KeyEncodingContext {
|
|
45
|
+
kKeyContextInput,
|
|
46
|
+
kKeyContextExport,
|
|
47
|
+
kKeyContextGenerate
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
enum class ParseKeyResult {
|
|
51
|
+
kParseKeyOk,
|
|
52
|
+
kParseKeyNotRecognized,
|
|
53
|
+
kParseKeyNeedPassphrase,
|
|
54
|
+
kParseKeyFailed
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
struct AsymmetricKeyEncodingConfig {
|
|
58
|
+
bool output_key_object_ = false;
|
|
59
|
+
PKFormatType format_ = kKeyFormatDER;
|
|
60
|
+
v8::Maybe<PKEncodingType> type_ = v8::Nothing<PKEncodingType>();
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
using PublicKeyEncodingConfig = AsymmetricKeyEncodingConfig;
|
|
64
|
+
|
|
65
|
+
struct PrivateKeyEncodingConfig : public AsymmetricKeyEncodingConfig {
|
|
66
|
+
const EVP_CIPHER* cipher_;
|
|
67
|
+
// The ByteSource alone is not enough to distinguish between "no passphrase"
|
|
68
|
+
// and a zero-length passphrase (which can be a null pointer), therefore, we
|
|
69
|
+
// use a NonCopyableMaybe.
|
|
70
|
+
NonCopyableMaybe<ByteSource> passphrase_;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
// This uses the built-in reference counter of OpenSSL to manage an EVP_PKEY
|
|
74
|
+
// which is slightly more efficient than using a shared pointer and easier to
|
|
75
|
+
// use.
|
|
76
|
+
class ManagedEVPPKey : public MemoryRetainer {
|
|
77
|
+
public:
|
|
78
|
+
ManagedEVPPKey() : mutex_(std::make_shared<Mutex>()) {}
|
|
79
|
+
explicit ManagedEVPPKey(EVPKeyPointer&& pkey);
|
|
80
|
+
ManagedEVPPKey(const ManagedEVPPKey& that);
|
|
81
|
+
ManagedEVPPKey& operator=(const ManagedEVPPKey& that);
|
|
82
|
+
|
|
83
|
+
operator bool() const;
|
|
84
|
+
EVP_PKEY* get() const;
|
|
85
|
+
Mutex* mutex() const;
|
|
86
|
+
|
|
87
|
+
void MemoryInfo(MemoryTracker* tracker) const override;
|
|
88
|
+
SET_MEMORY_INFO_NAME(ManagedEVPPKey)
|
|
89
|
+
SET_SELF_SIZE(ManagedEVPPKey)
|
|
90
|
+
|
|
91
|
+
static PublicKeyEncodingConfig GetPublicKeyEncodingFromJs(
|
|
92
|
+
const v8::FunctionCallbackInfo<v8::Value>& args,
|
|
93
|
+
unsigned int* offset,
|
|
94
|
+
KeyEncodingContext context);
|
|
95
|
+
|
|
96
|
+
static NonCopyableMaybe<PrivateKeyEncodingConfig> GetPrivateKeyEncodingFromJs(
|
|
97
|
+
const v8::FunctionCallbackInfo<v8::Value>& args,
|
|
98
|
+
unsigned int* offset,
|
|
99
|
+
KeyEncodingContext context);
|
|
100
|
+
|
|
101
|
+
static ManagedEVPPKey GetParsedKey(Environment* env,
|
|
102
|
+
EVPKeyPointer&& pkey,
|
|
103
|
+
ParseKeyResult ret,
|
|
104
|
+
const char* default_msg);
|
|
105
|
+
|
|
106
|
+
static ManagedEVPPKey GetPublicOrPrivateKeyFromJs(
|
|
107
|
+
const v8::FunctionCallbackInfo<v8::Value>& args,
|
|
108
|
+
unsigned int* offset);
|
|
109
|
+
|
|
110
|
+
static ManagedEVPPKey GetPrivateKeyFromJs(
|
|
111
|
+
const v8::FunctionCallbackInfo<v8::Value>& args,
|
|
112
|
+
unsigned int* offset,
|
|
113
|
+
bool allow_key_object);
|
|
114
|
+
|
|
115
|
+
v8::Maybe<bool> ToEncodedPublicKey(Environment* env,
|
|
116
|
+
const PublicKeyEncodingConfig& config,
|
|
117
|
+
v8::Local<v8::Value>* out);
|
|
118
|
+
|
|
119
|
+
v8::Maybe<bool> ToEncodedPrivateKey(Environment* env,
|
|
120
|
+
const PrivateKeyEncodingConfig& config,
|
|
121
|
+
v8::Local<v8::Value>* out);
|
|
122
|
+
|
|
123
|
+
private:
|
|
124
|
+
size_t size_of_private_key() const;
|
|
125
|
+
size_t size_of_public_key() const;
|
|
126
|
+
|
|
127
|
+
EVPKeyPointer pkey_;
|
|
128
|
+
std::shared_ptr<Mutex> mutex_;
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
// Objects of this class can safely be shared among threads.
|
|
132
|
+
class KeyObjectData : public MemoryRetainer {
|
|
133
|
+
public:
|
|
134
|
+
static std::shared_ptr<KeyObjectData> CreateSecret(ByteSource key);
|
|
135
|
+
|
|
136
|
+
static std::shared_ptr<KeyObjectData> CreateAsymmetric(
|
|
137
|
+
KeyType type,
|
|
138
|
+
const ManagedEVPPKey& pkey);
|
|
139
|
+
|
|
140
|
+
KeyType GetKeyType() const;
|
|
141
|
+
|
|
142
|
+
// These functions allow unprotected access to the raw key material and should
|
|
143
|
+
// only be used to implement cryptographic operations requiring the key.
|
|
144
|
+
ManagedEVPPKey GetAsymmetricKey() const;
|
|
145
|
+
const char* GetSymmetricKey() const;
|
|
146
|
+
size_t GetSymmetricKeySize() const;
|
|
147
|
+
|
|
148
|
+
void MemoryInfo(MemoryTracker* tracker) const override;
|
|
149
|
+
SET_MEMORY_INFO_NAME(KeyObjectData)
|
|
150
|
+
SET_SELF_SIZE(KeyObjectData)
|
|
151
|
+
|
|
152
|
+
private:
|
|
153
|
+
explicit KeyObjectData(ByteSource symmetric_key);
|
|
154
|
+
|
|
155
|
+
KeyObjectData(
|
|
156
|
+
KeyType type,
|
|
157
|
+
const ManagedEVPPKey& pkey);
|
|
158
|
+
|
|
159
|
+
const KeyType key_type_;
|
|
160
|
+
const ByteSource symmetric_key_;
|
|
161
|
+
const ManagedEVPPKey asymmetric_key_;
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
class KeyObjectHandle : public BaseObject {
|
|
165
|
+
public:
|
|
166
|
+
static bool HasInstance(Environment* env, v8::Local<v8::Value> value);
|
|
167
|
+
static v8::Local<v8::Function> Initialize(Environment* env);
|
|
168
|
+
static void RegisterExternalReferences(ExternalReferenceRegistry* registry);
|
|
169
|
+
|
|
170
|
+
static v8::MaybeLocal<v8::Object> Create(Environment* env,
|
|
171
|
+
std::shared_ptr<KeyObjectData> data);
|
|
172
|
+
|
|
173
|
+
// TODO(tniessen): track the memory used by OpenSSL types
|
|
174
|
+
SET_NO_MEMORY_INFO()
|
|
175
|
+
SET_MEMORY_INFO_NAME(KeyObjectHandle)
|
|
176
|
+
SET_SELF_SIZE(KeyObjectHandle)
|
|
177
|
+
|
|
178
|
+
const std::shared_ptr<KeyObjectData>& Data();
|
|
179
|
+
|
|
180
|
+
protected:
|
|
181
|
+
static void New(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
182
|
+
|
|
183
|
+
static void Init(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
184
|
+
static void InitECRaw(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
185
|
+
static void InitEDRaw(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
186
|
+
static void InitJWK(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
187
|
+
static void GetKeyDetail(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
188
|
+
static void Equals(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
189
|
+
|
|
190
|
+
static void ExportJWK(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
191
|
+
|
|
192
|
+
static void GetAsymmetricKeyType(
|
|
193
|
+
const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
194
|
+
v8::Local<v8::Value> GetAsymmetricKeyType() const;
|
|
195
|
+
|
|
196
|
+
static void GetSymmetricKeySize(
|
|
197
|
+
const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
198
|
+
|
|
199
|
+
static void Export(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
200
|
+
|
|
201
|
+
v8::MaybeLocal<v8::Value> ExportSecretKey() const;
|
|
202
|
+
v8::MaybeLocal<v8::Value> ExportPublicKey(
|
|
203
|
+
const PublicKeyEncodingConfig& config) const;
|
|
204
|
+
v8::MaybeLocal<v8::Value> ExportPrivateKey(
|
|
205
|
+
const PrivateKeyEncodingConfig& config) const;
|
|
206
|
+
|
|
207
|
+
KeyObjectHandle(Environment* env,
|
|
208
|
+
v8::Local<v8::Object> wrap);
|
|
209
|
+
|
|
210
|
+
private:
|
|
211
|
+
std::shared_ptr<KeyObjectData> data_;
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
class NativeKeyObject : public BaseObject {
|
|
215
|
+
public:
|
|
216
|
+
static void Initialize(Environment* env, v8::Local<v8::Object> target);
|
|
217
|
+
static void RegisterExternalReferences(ExternalReferenceRegistry* registry);
|
|
218
|
+
|
|
219
|
+
static void New(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
220
|
+
static void CreateNativeKeyObjectClass(
|
|
221
|
+
const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
222
|
+
|
|
223
|
+
SET_NO_MEMORY_INFO()
|
|
224
|
+
SET_MEMORY_INFO_NAME(NativeKeyObject)
|
|
225
|
+
SET_SELF_SIZE(NativeKeyObject)
|
|
226
|
+
|
|
227
|
+
class KeyObjectTransferData : public worker::TransferData {
|
|
228
|
+
public:
|
|
229
|
+
explicit KeyObjectTransferData(const std::shared_ptr<KeyObjectData>& data)
|
|
230
|
+
: data_(data) {}
|
|
231
|
+
|
|
232
|
+
BaseObjectPtr<BaseObject> Deserialize(
|
|
233
|
+
Environment* env,
|
|
234
|
+
v8::Local<v8::Context> context,
|
|
235
|
+
std::unique_ptr<worker::TransferData> self) override;
|
|
236
|
+
|
|
237
|
+
SET_MEMORY_INFO_NAME(KeyObjectTransferData)
|
|
238
|
+
SET_SELF_SIZE(KeyObjectTransferData)
|
|
239
|
+
SET_NO_MEMORY_INFO()
|
|
240
|
+
|
|
241
|
+
private:
|
|
242
|
+
std::shared_ptr<KeyObjectData> data_;
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
BaseObject::TransferMode GetTransferMode() const override;
|
|
246
|
+
std::unique_ptr<worker::TransferData> CloneForMessaging() const override;
|
|
247
|
+
|
|
248
|
+
private:
|
|
249
|
+
NativeKeyObject(Environment* env,
|
|
250
|
+
v8::Local<v8::Object> wrap,
|
|
251
|
+
const std::shared_ptr<KeyObjectData>& handle_data)
|
|
252
|
+
: BaseObject(env, wrap),
|
|
253
|
+
handle_data_(handle_data) {
|
|
254
|
+
MakeWeak();
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
std::shared_ptr<KeyObjectData> handle_data_;
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
enum WebCryptoKeyFormat {
|
|
261
|
+
kWebCryptoKeyFormatRaw,
|
|
262
|
+
kWebCryptoKeyFormatPKCS8,
|
|
263
|
+
kWebCryptoKeyFormatSPKI,
|
|
264
|
+
kWebCryptoKeyFormatJWK
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
enum class WebCryptoKeyExportStatus {
|
|
268
|
+
OK,
|
|
269
|
+
INVALID_KEY_TYPE,
|
|
270
|
+
FAILED
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
template <typename KeyExportTraits>
|
|
274
|
+
class KeyExportJob final : public CryptoJob<KeyExportTraits> {
|
|
275
|
+
public:
|
|
276
|
+
using AdditionalParams = typename KeyExportTraits::AdditionalParameters;
|
|
277
|
+
|
|
278
|
+
static void New(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
|
279
|
+
Environment* env = Environment::GetCurrent(args);
|
|
280
|
+
CHECK(args.IsConstructCall());
|
|
281
|
+
|
|
282
|
+
CryptoJobMode mode = GetCryptoJobMode(args[0]);
|
|
283
|
+
|
|
284
|
+
CHECK(args[1]->IsUint32()); // Export Type
|
|
285
|
+
CHECK(args[2]->IsObject()); // KeyObject
|
|
286
|
+
|
|
287
|
+
WebCryptoKeyFormat format =
|
|
288
|
+
static_cast<WebCryptoKeyFormat>(args[1].As<v8::Uint32>()->Value());
|
|
289
|
+
|
|
290
|
+
KeyObjectHandle* key;
|
|
291
|
+
ASSIGN_OR_RETURN_UNWRAP(&key, args[2]);
|
|
292
|
+
|
|
293
|
+
CHECK_NOT_NULL(key);
|
|
294
|
+
|
|
295
|
+
AdditionalParams params;
|
|
296
|
+
if (KeyExportTraits::AdditionalConfig(args, 3, ¶ms).IsNothing()) {
|
|
297
|
+
// The KeyExportTraits::AdditionalConfig is responsible for
|
|
298
|
+
// calling an appropriate THROW_CRYPTO_* variant reporting
|
|
299
|
+
// whatever error caused initialization to fail.
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
new KeyExportJob<KeyExportTraits>(
|
|
304
|
+
env,
|
|
305
|
+
args.This(),
|
|
306
|
+
mode,
|
|
307
|
+
key->Data(),
|
|
308
|
+
format,
|
|
309
|
+
std::move(params));
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
static void Initialize(
|
|
313
|
+
Environment* env,
|
|
314
|
+
v8::Local<v8::Object> target) {
|
|
315
|
+
CryptoJob<KeyExportTraits>::Initialize(New, env, target);
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
static void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
|
|
319
|
+
CryptoJob<KeyExportTraits>::RegisterExternalReferences(New, registry);
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
KeyExportJob(
|
|
323
|
+
Environment* env,
|
|
324
|
+
v8::Local<v8::Object> object,
|
|
325
|
+
CryptoJobMode mode,
|
|
326
|
+
std::shared_ptr<KeyObjectData> key,
|
|
327
|
+
WebCryptoKeyFormat format,
|
|
328
|
+
AdditionalParams&& params)
|
|
329
|
+
: CryptoJob<KeyExportTraits>(
|
|
330
|
+
env,
|
|
331
|
+
object,
|
|
332
|
+
AsyncWrap::PROVIDER_KEYEXPORTREQUEST,
|
|
333
|
+
mode,
|
|
334
|
+
std::move(params)),
|
|
335
|
+
key_(key),
|
|
336
|
+
format_(format) {}
|
|
337
|
+
|
|
338
|
+
WebCryptoKeyFormat format() const { return format_; }
|
|
339
|
+
|
|
340
|
+
void DoThreadPoolWork() override {
|
|
341
|
+
const WebCryptoKeyExportStatus status =
|
|
342
|
+
KeyExportTraits::DoExport(
|
|
343
|
+
key_,
|
|
344
|
+
format_,
|
|
345
|
+
*CryptoJob<KeyExportTraits>::params(),
|
|
346
|
+
&out_);
|
|
347
|
+
if (status == WebCryptoKeyExportStatus::OK) {
|
|
348
|
+
// Success!
|
|
349
|
+
return;
|
|
350
|
+
}
|
|
351
|
+
CryptoErrorStore* errors = CryptoJob<KeyExportTraits>::errors();
|
|
352
|
+
errors->Capture();
|
|
353
|
+
if (errors->Empty()) {
|
|
354
|
+
switch (status) {
|
|
355
|
+
case WebCryptoKeyExportStatus::OK:
|
|
356
|
+
UNREACHABLE();
|
|
357
|
+
break;
|
|
358
|
+
case WebCryptoKeyExportStatus::INVALID_KEY_TYPE:
|
|
359
|
+
errors->Insert(NodeCryptoError::INVALID_KEY_TYPE);
|
|
360
|
+
break;
|
|
361
|
+
case WebCryptoKeyExportStatus::FAILED:
|
|
362
|
+
errors->Insert(NodeCryptoError::CIPHER_JOB_FAILED);
|
|
363
|
+
break;
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
v8::Maybe<bool> ToResult(
|
|
369
|
+
v8::Local<v8::Value>* err,
|
|
370
|
+
v8::Local<v8::Value>* result) override {
|
|
371
|
+
Environment* env = AsyncWrap::env();
|
|
372
|
+
CryptoErrorStore* errors = CryptoJob<KeyExportTraits>::errors();
|
|
373
|
+
if (out_.size() > 0) {
|
|
374
|
+
CHECK(errors->Empty());
|
|
375
|
+
*err = v8::Undefined(env->isolate());
|
|
376
|
+
*result = out_.ToArrayBuffer(env);
|
|
377
|
+
return v8::Just(!result->IsEmpty());
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
if (errors->Empty())
|
|
381
|
+
errors->Capture();
|
|
382
|
+
CHECK(!errors->Empty());
|
|
383
|
+
*result = v8::Undefined(env->isolate());
|
|
384
|
+
return v8::Just(errors->ToException(env).ToLocal(err));
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
SET_SELF_SIZE(KeyExportJob)
|
|
388
|
+
void MemoryInfo(MemoryTracker* tracker) const override {
|
|
389
|
+
tracker->TrackFieldWithSize("out", out_.size());
|
|
390
|
+
CryptoJob<KeyExportTraits>::MemoryInfo(tracker);
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
private:
|
|
394
|
+
std::shared_ptr<KeyObjectData> key_;
|
|
395
|
+
WebCryptoKeyFormat format_;
|
|
396
|
+
ByteSource out_;
|
|
397
|
+
};
|
|
398
|
+
|
|
399
|
+
WebCryptoKeyExportStatus PKEY_SPKI_Export(
|
|
400
|
+
KeyObjectData* key_data,
|
|
401
|
+
ByteSource* out);
|
|
402
|
+
|
|
403
|
+
WebCryptoKeyExportStatus PKEY_PKCS8_Export(
|
|
404
|
+
KeyObjectData* key_data,
|
|
405
|
+
ByteSource* out);
|
|
406
|
+
|
|
407
|
+
namespace Keys {
|
|
408
|
+
void Initialize(Environment* env, v8::Local<v8::Object> target);
|
|
409
|
+
void RegisterExternalReferences(ExternalReferenceRegistry* registry);
|
|
410
|
+
} // namespace Keys
|
|
411
|
+
|
|
412
|
+
} // namespace crypto
|
|
413
|
+
} // namespace node
|
|
414
|
+
|
|
415
|
+
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
416
|
+
#endif // SRC_CRYPTO_CRYPTO_KEYS_H_
|