diff options
author | Alba Mendez <me@alba.sh> | 2019-05-11 23:07:06 +0200 |
---|---|---|
committer | Daniel Bevenius <daniel.bevenius@gmail.com> | 2019-05-15 05:32:33 +0200 |
commit | 53bef423f31bb383212a6754228c21ca3d3231b6 (patch) | |
tree | 489bb9e43883e4bdf3dac4bdbb3f2a82e86b2db0 /src/node_crypto.cc | |
parent | 10d7e01ee9618a42cb658a07d692557a03456fe5 (diff) | |
download | android-node-v8-53bef423f31bb383212a6754228c21ca3d3231b6.tar.gz android-node-v8-53bef423f31bb383212a6754228c21ca3d3231b6.tar.bz2 android-node-v8-53bef423f31bb383212a6754228c21ca3d3231b6.zip |
tls: expose keylog event on TLSSocket
Exposes SSL_CTX_set_keylog_callback in the form of a `keylog` event
that is emitted on clients and servers. This enables easy debugging
of TLS connections with i.e. Wireshark, which is a long-requested
feature.
PR-URL: https://github.com/nodejs/node/pull/27654
Refs: https://github.com/nodejs/node/issues/2363
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Diffstat (limited to 'src/node_crypto.cc')
-rw-r--r-- | src/node_crypto.cc | 17 |
1 files changed, 17 insertions, 0 deletions
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); |