diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/env.h | 1 | ||||
-rw-r--r-- | src/node_crypto.cc | 17 | ||||
-rw-r--r-- | src/node_crypto.h | 1 | ||||
-rw-r--r-- | src/tls_wrap.cc | 10 | ||||
-rw-r--r-- | src/tls_wrap.h | 2 |
5 files changed, 31 insertions, 0 deletions
@@ -252,6 +252,7 @@ constexpr size_t kFsStatsBufferLength = kFsStatsFieldsNumber * 2; V(onexit_string, "onexit") \ V(onhandshakedone_string, "onhandshakedone") \ V(onhandshakestart_string, "onhandshakestart") \ + V(onkeylog_string, "onkeylog") \ V(onmessage_string, "onmessage") \ V(onnewsession_string, "onnewsession") \ V(onocspresponse_string, "onocspresponse") \ diff --git a/src/node_crypto.cc b/src/node_crypto.cc index 4529a5d22d..d4399231b9 100644 --- a/src/node_crypto.cc +++ b/src/node_crypto.cc @@ -149,6 +149,8 @@ template SSL_SESSION* SSLWrap<TLSWrap>::GetSessionCallback( int* copy); template int SSLWrap<TLSWrap>::NewSessionCallback(SSL* s, SSL_SESSION* sess); +template void SSLWrap<TLSWrap>::KeylogCallback(const SSL* s, + const char* line); template void SSLWrap<TLSWrap>::OnClientHello( void* arg, const ClientHelloParser::ClientHello& hello); @@ -1750,6 +1752,21 @@ int SSLWrap<Base>::NewSessionCallback(SSL* s, SSL_SESSION* sess) { template <class Base> +void SSLWrap<Base>::KeylogCallback(const SSL* s, const char* line) { + Base* w = static_cast<Base*>(SSL_get_app_data(s)); + Environment* env = w->ssl_env(); + HandleScope handle_scope(env->isolate()); + Context::Scope context_scope(env->context()); + + const size_t size = strlen(line); + Local<Value> line_bf = Buffer::Copy(env, line, 1 + size).ToLocalChecked(); + char* data = Buffer::Data(line_bf); + data[size] = '\n'; + w->MakeCallback(env->onkeylog_string(), 1, &line_bf); +} + + +template <class Base> void SSLWrap<Base>::OnClientHello(void* arg, const ClientHelloParser::ClientHello& hello) { Base* w = static_cast<Base*>(arg); diff --git a/src/node_crypto.h b/src/node_crypto.h index 44206b58dd..849b80f4e0 100644 --- a/src/node_crypto.h +++ b/src/node_crypto.h @@ -256,6 +256,7 @@ class SSLWrap { int* copy); #endif static int NewSessionCallback(SSL* s, SSL_SESSION* sess); + static void KeylogCallback(const SSL* s, const char* line); static void OnClientHello(void* arg, const ClientHelloParser::ClientHello& hello); diff --git a/src/tls_wrap.cc b/src/tls_wrap.cc index 4c5d002295..cd6321b969 100644 --- a/src/tls_wrap.cc +++ b/src/tls_wrap.cc @@ -912,6 +912,15 @@ void TLSWrap::EnableSessionCallbacks( wrap); } +void TLSWrap::EnableKeylogCallback( + const FunctionCallbackInfo<Value>& args) { + TLSWrap* wrap; + ASSIGN_OR_RETURN_UNWRAP(&wrap, args.Holder()); + CHECK_NOT_NULL(wrap->sc_); + SSL_CTX_set_keylog_callback(wrap->sc_->ctx_.get(), + SSLWrap<TLSWrap>::KeylogCallback); +} + // Check required capabilities were not excluded from the OpenSSL build: // - OPENSSL_NO_SSL_TRACE excludes SSL_trace() // - OPENSSL_NO_STDIO excludes BIO_new_fp() @@ -1105,6 +1114,7 @@ void TLSWrap::Initialize(Local<Object> target, env->SetProtoMethod(t, "start", Start); env->SetProtoMethod(t, "setVerifyMode", SetVerifyMode); env->SetProtoMethod(t, "enableSessionCallbacks", EnableSessionCallbacks); + env->SetProtoMethod(t, "enableKeylogCallback", EnableKeylogCallback); env->SetProtoMethod(t, "enableTrace", EnableTrace); env->SetProtoMethod(t, "destroySSL", DestroySSL); env->SetProtoMethod(t, "enableCertCb", EnableCertCb); diff --git a/src/tls_wrap.h b/src/tls_wrap.h index 41e16ea9ac..b866bbb7af 100644 --- a/src/tls_wrap.h +++ b/src/tls_wrap.h @@ -160,6 +160,8 @@ class TLSWrap : public AsyncWrap, static void SetVerifyMode(const v8::FunctionCallbackInfo<v8::Value>& args); static void EnableSessionCallbacks( const v8::FunctionCallbackInfo<v8::Value>& args); + static void EnableKeylogCallback( + const v8::FunctionCallbackInfo<v8::Value>& args); static void EnableTrace(const v8::FunctionCallbackInfo<v8::Value>& args); static void EnableCertCb(const v8::FunctionCallbackInfo<v8::Value>& args); static void DestroySSL(const v8::FunctionCallbackInfo<v8::Value>& args); |