1 #ifndef SRC_CRYPTO_CRYPTO_COMMON_H_ 2 #define SRC_CRYPTO_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 struct StackOfX509Deleter { operatorStackOfX509Deleter17 void operator()(STACK_OF(X509)* p) const { sk_X509_pop_free(p, X509_free); } 18 }; 19 using StackOfX509 = std::unique_ptr<STACK_OF(X509), StackOfX509Deleter>; 20 21 struct StackOfXASN1Deleter { operatorStackOfXASN1Deleter22 void operator()(STACK_OF(ASN1_OBJECT)* p) const { 23 sk_ASN1_OBJECT_pop_free(p, ASN1_OBJECT_free); 24 } 25 }; 26 using StackOfASN1 = std::unique_ptr<STACK_OF(ASN1_OBJECT), StackOfXASN1Deleter>; 27 28 X509Pointer SSL_CTX_get_issuer(SSL_CTX* ctx, X509* cert); 29 30 void LogSecret( 31 const SSLPointer& ssl, 32 const char* name, 33 const unsigned char* secret, 34 size_t secretlen); 35 36 v8::MaybeLocal<v8::Value> GetSSLOCSPResponse( 37 Environment* env, 38 SSL* ssl, 39 v8::Local<v8::Value> default_value); 40 41 bool SetTLSSession( 42 const SSLPointer& ssl, 43 const SSLSessionPointer& session); 44 45 SSLSessionPointer GetTLSSession(const unsigned char* buf, size_t length); 46 47 long VerifyPeerCertificate( // NOLINT(runtime/int) 48 const SSLPointer& ssl, 49 long def = X509_V_ERR_UNSPECIFIED); // NOLINT(runtime/int) 50 51 bool UseSNIContext(const SSLPointer& ssl, BaseObjectPtr<SecureContext> context); 52 53 const char* GetClientHelloALPN(const SSLPointer& ssl); 54 55 const char* GetClientHelloServerName(const SSLPointer& ssl); 56 57 const char* GetServerName(SSL* ssl); 58 59 v8::MaybeLocal<v8::Array> GetClientHelloCiphers( 60 Environment* env, 61 const SSLPointer& ssl); 62 63 bool SetGroups(SecureContext* sc, const char* groups); 64 65 const char* X509ErrorCode(long err); // NOLINT(runtime/int) 66 67 v8::MaybeLocal<v8::Value> GetValidationErrorReason(Environment* env, int err); 68 69 v8::MaybeLocal<v8::Value> GetValidationErrorCode(Environment* env, int err); 70 71 v8::MaybeLocal<v8::Value> GetCert(Environment* env, const SSLPointer& ssl); 72 73 v8::MaybeLocal<v8::Object> GetCipherInfo( 74 Environment* env, 75 const SSLPointer& ssl); 76 77 v8::MaybeLocal<v8::Object> GetEphemeralKey( 78 Environment* env, 79 const SSLPointer& ssl); 80 81 v8::MaybeLocal<v8::Value> GetPeerCert( 82 Environment* env, 83 const SSLPointer& ssl, 84 bool abbreviated = false, 85 bool is_server = false); 86 87 v8::MaybeLocal<v8::Object> ECPointToBuffer( 88 Environment* env, 89 const EC_GROUP* group, 90 const EC_POINT* point, 91 point_conversion_form_t form, 92 const char** error); 93 94 v8::MaybeLocal<v8::Object> X509ToObject( 95 Environment* env, 96 X509* cert); 97 98 v8::MaybeLocal<v8::Value> GetValidTo( 99 Environment* env, 100 X509* cert, 101 const BIOPointer& bio); 102 103 v8::MaybeLocal<v8::Value> GetValidFrom( 104 Environment* env, 105 X509* cert, 106 const BIOPointer& bio); 107 108 v8::MaybeLocal<v8::Value> GetFingerprintDigest( 109 Environment* env, 110 const EVP_MD* method, 111 X509* cert); 112 113 v8::MaybeLocal<v8::Value> GetKeyUsage(Environment* env, X509* cert); 114 v8::MaybeLocal<v8::Value> GetCurrentCipherName(Environment* env, 115 const SSLPointer& ssl); 116 v8::MaybeLocal<v8::Value> GetCurrentCipherVersion(Environment* env, 117 const SSLPointer& ssl); 118 119 v8::MaybeLocal<v8::Value> GetSerialNumber(Environment* env, X509* cert); 120 121 v8::MaybeLocal<v8::Value> GetRawDERCertificate(Environment* env, X509* cert); 122 123 v8::Local<v8::Value> ToV8Value(Environment* env, const BIOPointer& bio); 124 bool SafeX509SubjectAltNamePrint(const BIOPointer& out, X509_EXTENSION* ext); 125 126 v8::MaybeLocal<v8::Value> GetSubject(Environment* env, 127 X509* cert, 128 const BIOPointer& bio); 129 130 v8::MaybeLocal<v8::Value> GetIssuerString(Environment* env, 131 X509* cert, 132 const BIOPointer& bio); 133 134 v8::MaybeLocal<v8::Value> GetSubjectAltNameString(Environment* env, 135 X509* cert, 136 const BIOPointer& bio); 137 138 v8::MaybeLocal<v8::Value> GetInfoAccessString(Environment* env, 139 X509* cert, 140 const BIOPointer& bio); 141 142 } // namespace crypto 143 } // namespace node 144 145 #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS 146 147 #endif // SRC_CRYPTO_CRYPTO_COMMON_H_ 148