1 #ifndef SRC_NODE_CRYPTO_COMMON_H_ 2 #define SRC_NODE_CRYPTO_COMMON_H_ 3 4 #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS 5 6 #include "node_crypto.h" 7 #include "v8.h" 8 #include <openssl/ssl.h> 9 #include <openssl/x509v3.h> 10 11 #include <string> 12 13 namespace node { 14 namespace crypto { 15 16 // OPENSSL_free is a macro, so we need a wrapper function. 17 struct OpenSSLBufferDeleter { operatorOpenSSLBufferDeleter18 void operator()(char* pointer) const { OPENSSL_free(pointer); } 19 }; 20 using OpenSSLBuffer = std::unique_ptr<char[], OpenSSLBufferDeleter>; 21 22 struct StackOfX509Deleter { operatorStackOfX509Deleter23 void operator()(STACK_OF(X509)* p) const { sk_X509_pop_free(p, X509_free); } 24 }; 25 using StackOfX509 = std::unique_ptr<STACK_OF(X509), StackOfX509Deleter>; 26 27 struct StackOfXASN1Deleter { operatorStackOfXASN1Deleter28 void operator()(STACK_OF(ASN1_OBJECT)* p) const { 29 sk_ASN1_OBJECT_pop_free(p, ASN1_OBJECT_free); 30 } 31 }; 32 using StackOfASN1 = std::unique_ptr<STACK_OF(ASN1_OBJECT), StackOfXASN1Deleter>; 33 34 int SSL_CTX_get_issuer(SSL_CTX* ctx, X509* cert, X509** issuer); 35 36 void LogSecret( 37 const SSLPointer& ssl, 38 const char* name, 39 const unsigned char* secret, 40 size_t secretlen); 41 42 bool SetALPN(const SSLPointer& ssl, const std::string& alpn); 43 44 bool SetALPN(const SSLPointer& ssl, v8::Local<v8::Value> alpn); 45 46 v8::MaybeLocal<v8::Value> GetSSLOCSPResponse( 47 Environment* env, 48 SSL* ssl, 49 v8::Local<v8::Value> default_value); 50 51 bool SetTLSSession( 52 const SSLPointer& ssl, 53 const unsigned char* buf, 54 size_t length); 55 56 bool SetTLSSession( 57 const SSLPointer& ssl, 58 const SSLSessionPointer& session); 59 60 SSLSessionPointer GetTLSSession(v8::Local<v8::Value> val); 61 62 SSLSessionPointer GetTLSSession(const unsigned char* buf, size_t length); 63 64 long VerifyPeerCertificate( // NOLINT(runtime/int) 65 const SSLPointer& ssl, 66 long def = X509_V_ERR_UNSPECIFIED); // NOLINT(runtime/int) 67 68 int UseSNIContext(const SSLPointer& ssl, BaseObjectPtr<SecureContext> context); 69 70 const char* GetClientHelloALPN(const SSLPointer& ssl); 71 72 const char* GetClientHelloServerName(const SSLPointer& ssl); 73 74 const char* GetServerName(SSL* ssl); 75 76 v8::MaybeLocal<v8::Array> GetClientHelloCiphers( 77 Environment* env, 78 const SSLPointer& ssl); 79 80 bool SetGroups(SecureContext* sc, const char* groups); 81 82 const char* X509ErrorCode(long err); // NOLINT(runtime/int) 83 84 v8::MaybeLocal<v8::Value> GetValidationErrorReason(Environment* env, int err); 85 86 v8::MaybeLocal<v8::Value> GetValidationErrorCode(Environment* env, int err); 87 88 v8::MaybeLocal<v8::Value> GetCert(Environment* env, const SSLPointer& ssl); 89 90 v8::MaybeLocal<v8::Value> GetCipherName( 91 Environment* env, 92 const SSLPointer& ssl); 93 94 v8::MaybeLocal<v8::Value> GetCipherStandardName( 95 Environment* env, 96 const SSLPointer& ssl); 97 98 v8::MaybeLocal<v8::Value> GetCipherVersion( 99 Environment* env, 100 const SSLPointer& ssl); 101 102 v8::MaybeLocal<v8::Object> GetCipherInfo( 103 Environment* env, 104 const SSLPointer& ssl); 105 106 v8::MaybeLocal<v8::Object> GetEphemeralKey( 107 Environment* env, 108 const SSLPointer& ssl); 109 110 v8::MaybeLocal<v8::Value> GetPeerCert( 111 Environment* env, 112 const SSLPointer& ssl, 113 bool abbreviated = false, 114 bool is_server = false); 115 116 v8::MaybeLocal<v8::Object> ECPointToBuffer( 117 Environment* env, 118 const EC_GROUP* group, 119 const EC_POINT* point, 120 point_conversion_form_t form, 121 const char** error); 122 123 v8::MaybeLocal<v8::Object> X509ToObject( 124 Environment* env, 125 X509* cert, 126 bool names_as_string = false); 127 128 } // namespace crypto 129 } // namespace node 130 131 #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS 132 133 #endif // SRC_NODE_CRYPTO_COMMON_H_ 134