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 "crypto/crypto_util.h" |
7 |
|
|
#include "base_object.h" |
8 |
|
|
#include "env.h" |
9 |
|
|
#include "memory_tracker.h" |
10 |
|
|
#include "v8.h" |
11 |
|
|
|
12 |
|
|
namespace node { |
13 |
|
|
namespace crypto { |
14 |
|
|
// A maxVersion of 0 means "any", but OpenSSL may support TLS versions that |
15 |
|
|
// Node.js doesn't, so pin the max to what we do support. |
16 |
|
|
constexpr int kMaxSupportedVersion = TLS1_3_VERSION; |
17 |
|
|
|
18 |
|
|
void GetRootCertificates( |
19 |
|
|
const v8::FunctionCallbackInfo<v8::Value>& args); |
20 |
|
|
|
21 |
|
|
void IsExtraRootCertsFileLoaded( |
22 |
|
|
const v8::FunctionCallbackInfo<v8::Value>& args); |
23 |
|
|
|
24 |
|
|
X509_STORE* NewRootCertStore(); |
25 |
|
|
|
26 |
|
|
BIOPointer LoadBIO(Environment* env, v8::Local<v8::Value> v); |
27 |
|
|
|
28 |
|
|
class SecureContext final : public BaseObject { |
29 |
|
|
public: |
30 |
|
|
using GetSessionCb = SSL_SESSION* (*)(SSL*, const unsigned char*, int, int*); |
31 |
|
|
using KeylogCb = void (*)(const SSL*, const char*); |
32 |
|
|
using NewSessionCb = int (*)(SSL*, SSL_SESSION*); |
33 |
|
|
using SelectSNIContextCb = int (*)(SSL*, int*, void*); |
34 |
|
|
|
35 |
|
|
~SecureContext() override; |
36 |
|
|
|
37 |
|
|
static bool HasInstance(Environment* env, const v8::Local<v8::Value>& value); |
38 |
|
|
static v8::Local<v8::FunctionTemplate> GetConstructorTemplate( |
39 |
|
|
Environment* env); |
40 |
|
|
static void Initialize(Environment* env, v8::Local<v8::Object> target); |
41 |
|
|
static void RegisterExternalReferences(ExternalReferenceRegistry* registry); |
42 |
|
|
static SecureContext* Create(Environment* env); |
43 |
|
|
|
44 |
|
24832 |
const SSLCtxPointer& ctx() const { return ctx_; } |
45 |
|
|
|
46 |
|
|
SSLPointer CreateSSL(); |
47 |
|
|
|
48 |
|
|
void SetGetSessionCallback(GetSessionCb cb); |
49 |
|
|
void SetKeylogCallback(KeylogCb cb); |
50 |
|
|
void SetNewSessionCallback(NewSessionCb cb); |
51 |
|
|
void SetSelectSNIContextCallback(SelectSNIContextCb cb); |
52 |
|
|
|
53 |
|
|
// TODO(joyeecheung): track the memory used by OpenSSL types |
54 |
|
1 |
SET_NO_MEMORY_INFO() |
55 |
|
1 |
SET_MEMORY_INFO_NAME(SecureContext) |
56 |
|
1 |
SET_SELF_SIZE(SecureContext) |
57 |
|
|
|
58 |
|
|
static const int kMaxSessionSize = 10 * 1024; |
59 |
|
|
|
60 |
|
|
// See TicketKeyCallback |
61 |
|
|
static const int kTicketKeyReturnIndex = 0; |
62 |
|
|
static const int kTicketKeyHMACIndex = 1; |
63 |
|
|
static const int kTicketKeyAESIndex = 2; |
64 |
|
|
static const int kTicketKeyNameIndex = 3; |
65 |
|
|
static const int kTicketKeyIVIndex = 4; |
66 |
|
|
|
67 |
|
|
protected: |
68 |
|
|
// OpenSSL structures are opaque. This is sizeof(SSL_CTX) for OpenSSL 1.1.1b: |
69 |
|
|
static const int64_t kExternalSize = 1024; |
70 |
|
|
|
71 |
|
|
static void New(const v8::FunctionCallbackInfo<v8::Value>& args); |
72 |
|
|
static void Init(const v8::FunctionCallbackInfo<v8::Value>& args); |
73 |
|
|
static void SetKey(const v8::FunctionCallbackInfo<v8::Value>& args); |
74 |
|
|
#ifndef OPENSSL_NO_ENGINE |
75 |
|
|
static void SetEngineKey(const v8::FunctionCallbackInfo<v8::Value>& args); |
76 |
|
|
#endif // !OPENSSL_NO_ENGINE |
77 |
|
|
static void SetCert(const v8::FunctionCallbackInfo<v8::Value>& args); |
78 |
|
|
static void AddCACert(const v8::FunctionCallbackInfo<v8::Value>& args); |
79 |
|
|
static void AddCRL(const v8::FunctionCallbackInfo<v8::Value>& args); |
80 |
|
|
static void AddRootCerts(const v8::FunctionCallbackInfo<v8::Value>& args); |
81 |
|
|
static void SetCipherSuites(const v8::FunctionCallbackInfo<v8::Value>& args); |
82 |
|
|
static void SetCiphers(const v8::FunctionCallbackInfo<v8::Value>& args); |
83 |
|
|
static void SetSigalgs(const v8::FunctionCallbackInfo<v8::Value>& args); |
84 |
|
|
static void SetECDHCurve(const v8::FunctionCallbackInfo<v8::Value>& args); |
85 |
|
|
static void SetDHParam(const v8::FunctionCallbackInfo<v8::Value>& args); |
86 |
|
|
static void SetOptions(const v8::FunctionCallbackInfo<v8::Value>& args); |
87 |
|
|
static void SetSessionIdContext( |
88 |
|
|
const v8::FunctionCallbackInfo<v8::Value>& args); |
89 |
|
|
static void SetSessionTimeout( |
90 |
|
|
const v8::FunctionCallbackInfo<v8::Value>& args); |
91 |
|
|
static void SetMinProto(const v8::FunctionCallbackInfo<v8::Value>& args); |
92 |
|
|
static void SetMaxProto(const v8::FunctionCallbackInfo<v8::Value>& args); |
93 |
|
|
static void GetMinProto(const v8::FunctionCallbackInfo<v8::Value>& args); |
94 |
|
|
static void GetMaxProto(const v8::FunctionCallbackInfo<v8::Value>& args); |
95 |
|
|
static void Close(const v8::FunctionCallbackInfo<v8::Value>& args); |
96 |
|
|
static void LoadPKCS12(const v8::FunctionCallbackInfo<v8::Value>& args); |
97 |
|
|
#ifndef OPENSSL_NO_ENGINE |
98 |
|
|
static void SetClientCertEngine( |
99 |
|
|
const v8::FunctionCallbackInfo<v8::Value>& args); |
100 |
|
|
#endif // !OPENSSL_NO_ENGINE |
101 |
|
|
static void GetTicketKeys(const v8::FunctionCallbackInfo<v8::Value>& args); |
102 |
|
|
static void SetTicketKeys(const v8::FunctionCallbackInfo<v8::Value>& args); |
103 |
|
|
static void EnableTicketKeyCallback( |
104 |
|
|
const v8::FunctionCallbackInfo<v8::Value>& args); |
105 |
|
|
static void CtxGetter(const v8::FunctionCallbackInfo<v8::Value>& info); |
106 |
|
|
|
107 |
|
|
template <bool primary> |
108 |
|
|
static void GetCertificate(const v8::FunctionCallbackInfo<v8::Value>& args); |
109 |
|
|
|
110 |
|
|
static int TicketKeyCallback(SSL* ssl, |
111 |
|
|
unsigned char* name, |
112 |
|
|
unsigned char* iv, |
113 |
|
|
EVP_CIPHER_CTX* ectx, |
114 |
|
|
HMAC_CTX* hctx, |
115 |
|
|
int enc); |
116 |
|
|
|
117 |
|
|
static int TicketCompatibilityCallback(SSL* ssl, |
118 |
|
|
unsigned char* name, |
119 |
|
|
unsigned char* iv, |
120 |
|
|
EVP_CIPHER_CTX* ectx, |
121 |
|
|
HMAC_CTX* hctx, |
122 |
|
|
int enc); |
123 |
|
|
|
124 |
|
|
SecureContext(Environment* env, v8::Local<v8::Object> wrap); |
125 |
|
|
void Reset(); |
126 |
|
|
|
127 |
|
|
private: |
128 |
|
|
SSLCtxPointer ctx_; |
129 |
|
|
X509Pointer cert_; |
130 |
|
|
X509Pointer issuer_; |
131 |
|
|
#ifndef OPENSSL_NO_ENGINE |
132 |
|
|
bool client_cert_engine_provided_ = false; |
133 |
|
|
EnginePointer private_key_engine_; |
134 |
|
|
#endif // !OPENSSL_NO_ENGINE |
135 |
|
|
|
136 |
|
|
unsigned char ticket_key_name_[16]; |
137 |
|
|
unsigned char ticket_key_aes_[16]; |
138 |
|
|
unsigned char ticket_key_hmac_[16]; |
139 |
|
|
}; |
140 |
|
|
|
141 |
|
|
} // namespace crypto |
142 |
|
|
} // namespace node |
143 |
|
|
|
144 |
|
|
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS |
145 |
|
|
#endif // SRC_CRYPTO_CRYPTO_CONTEXT_H_ |