Where Online Learning is simpler!
The C and C++ Include Header Files
cat -n /usr/include/nodejs/src/crypto/crypto_context.h
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 X509_STORE* NewRootCertStore(); 23 24 X509_STORE* GetOrCreateRootCertStore(); 25 26 ncrypto::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 const ncrypto::SSLCtxPointer& ctx() const { return ctx_; } 45 46 // Non-const ctx() that allows for non-default initialization of 47 // the SecureContext. 48 ncrypto::SSLCtxPointer& ctx() { return ctx_; } 49 50 ncrypto::SSLPointer CreateSSL(); 51 52 void SetGetSessionCallback(GetSessionCb cb); 53 void SetKeylogCallback(KeylogCb cb); 54 void SetNewSessionCallback(NewSessionCb cb); 55 void SetSelectSNIContextCallback(SelectSNIContextCb cb); 56 57 inline const ncrypto::X509Pointer& issuer() const { return issuer_; } 58 inline const ncrypto::X509Pointer& cert() const { return cert_; } 59 60 v8::Maybe<void> AddCert(Environment* env, ncrypto::BIOPointer&& bio); 61 v8::Maybe<void> SetCRL(Environment* env, const ncrypto::BIOPointer& bio); 62 v8::Maybe<void> UseKey(Environment* env, const KeyObjectData& key); 63 64 void SetCACert(const ncrypto::BIOPointer& bio); 65 void SetRootCerts(); 66 67 void SetX509StoreFlag(unsigned long flags); // NOLINT(runtime/int) 68 X509_STORE* GetCertStoreOwnedByThisSecureContext(); 69 70 // TODO(joyeecheung): track the memory used by OpenSSL types 71 SET_NO_MEMORY_INFO() 72 SET_MEMORY_INFO_NAME(SecureContext) 73 SET_SELF_SIZE(SecureContext) 74 75 static const int kMaxSessionSize = 10 * 1024; 76 77 // See TicketKeyCallback 78 static const int kTicketKeyReturnIndex = 0; 79 static const int kTicketKeyHMACIndex = 1; 80 static const int kTicketKeyAESIndex = 2; 81 static const int kTicketKeyNameIndex = 3; 82 static const int kTicketKeyIVIndex = 4; 83 84 protected: 85 // OpenSSL structures are opaque. This is sizeof(SSL_CTX) for OpenSSL 1.1.1b: 86 static const int64_t kExternalSize = 1024; 87 88 static void New(const v8::FunctionCallbackInfo<v8::Value>& args); 89 static void Init(const v8::FunctionCallbackInfo<v8::Value>& args); 90 static void SetKey(const v8::FunctionCallbackInfo<v8::Value>& args); 91 #ifndef OPENSSL_NO_ENGINE 92 static void SetEngineKey(const v8::FunctionCallbackInfo<v8::Value>& args); 93 #endif // !OPENSSL_NO_ENGINE 94 static void SetCert(const v8::FunctionCallbackInfo<v8::Value>& args); 95 static void AddCACert(const v8::FunctionCallbackInfo<v8::Value>& args); 96 static void SetAllowPartialTrustChain( 97 const v8::FunctionCallbackInfo<v8::Value>& args); 98 static void AddCRL(const v8::FunctionCallbackInfo<v8::Value>& args); 99 static void AddRootCerts(const v8::FunctionCallbackInfo<v8::Value>& args); 100 static void SetCipherSuites(const v8::FunctionCallbackInfo<v8::Value>& args); 101 static void SetCiphers(const v8::FunctionCallbackInfo<v8::Value>& args); 102 static void SetSigalgs(const v8::FunctionCallbackInfo<v8::Value>& args); 103 static void SetECDHCurve(const v8::FunctionCallbackInfo<v8::Value>& args); 104 static void SetDHParam(const v8::FunctionCallbackInfo<v8::Value>& args); 105 static void SetOptions(const v8::FunctionCallbackInfo<v8::Value>& args); 106 static void SetSessionIdContext( 107 const v8::FunctionCallbackInfo<v8::Value>& args); 108 static void SetSessionTimeout( 109 const v8::FunctionCallbackInfo<v8::Value>& args); 110 static void SetMinProto(const v8::FunctionCallbackInfo<v8::Value>& args); 111 static void SetMaxProto(const v8::FunctionCallbackInfo<v8::Value>& args); 112 static void GetMinProto(const v8::FunctionCallbackInfo<v8::Value>& args); 113 static void GetMaxProto(const v8::FunctionCallbackInfo<v8::Value>& args); 114 static void Close(const v8::FunctionCallbackInfo<v8::Value>& args); 115 static void LoadPKCS12(const v8::FunctionCallbackInfo<v8::Value>& args); 116 #ifndef OPENSSL_NO_ENGINE 117 static void SetClientCertEngine( 118 const v8::FunctionCallbackInfo<v8::Value>& args); 119 #endif // !OPENSSL_NO_ENGINE 120 static void GetTicketKeys(const v8::FunctionCallbackInfo<v8::Value>& args); 121 static void SetTicketKeys(const v8::FunctionCallbackInfo<v8::Value>& args); 122 static void EnableTicketKeyCallback( 123 const v8::FunctionCallbackInfo<v8::Value>& args); 124 static void CtxGetter(const v8::FunctionCallbackInfo<v8::Value>& info); 125 126 template <bool primary> 127 static void GetCertificate(const v8::FunctionCallbackInfo<v8::Value>& args); 128 129 static int TicketKeyCallback(SSL* ssl, 130 unsigned char* name, 131 unsigned char* iv, 132 EVP_CIPHER_CTX* ectx, 133 HMAC_CTX* hctx, 134 int enc); 135 136 static int TicketCompatibilityCallback(SSL* ssl, 137 unsigned char* name, 138 unsigned char* iv, 139 EVP_CIPHER_CTX* ectx, 140 HMAC_CTX* hctx, 141 int enc); 142 143 SecureContext(Environment* env, v8::Local<v8::Object> wrap); 144 void Reset(); 145 146 private: 147 ncrypto::SSLCtxPointer ctx_; 148 ncrypto::X509Pointer cert_; 149 ncrypto::X509Pointer issuer_; 150 // Non-owning cache for SSL_CTX_get_cert_store(ctx_.get()) 151 X509_STORE* own_cert_store_cache_ = nullptr; 152 #ifndef OPENSSL_NO_ENGINE 153 bool client_cert_engine_provided_ = false; 154 ncrypto::EnginePointer private_key_engine_; 155 #endif // !OPENSSL_NO_ENGINE 156 157 unsigned char ticket_key_name_[16]; 158 unsigned char ticket_key_aes_[16]; 159 unsigned char ticket_key_hmac_[16]; 160 }; 161 162 int SSL_CTX_use_certificate_chain(SSL_CTX* ctx, 163 ncrypto::BIOPointer&& in, 164 ncrypto::X509Pointer* cert, 165 ncrypto::X509Pointer* issuer); 166 167 } // namespace crypto 168 } // namespace node 169 170 #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS 171 #endif // SRC_CRYPTO_CRYPTO_CONTEXT_H_