diff options
author | Anton Salikhmetov <anton.salikhmetov@gmail.com> | 2018-03-02 21:46:34 +0200 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2018-03-11 18:29:18 +0100 |
commit | 98a14e026bab0bda4013f75d1d0968a12fe5117f (patch) | |
tree | 2c8b58aba092f3a6609dc352642bf219ac9ae138 /src | |
parent | d3f174faab55662226ced53bef6bb2040352a825 (diff) | |
download | android-node-v8-98a14e026bab0bda4013f75d1d0968a12fe5117f.tar.gz android-node-v8-98a14e026bab0bda4013f75d1d0968a12fe5117f.tar.bz2 android-node-v8-98a14e026bab0bda4013f75d1d0968a12fe5117f.zip |
tls: expose Finished messages in TLSSocket
Exposes SSL_get_finished and SSL_get_peer_finished routines in OpenSSL
as tlsSocket.getFinished and tlsSocket.getPeerFinished, respectively.
PR-URL: https://github.com/nodejs/node/pull/19102
Fixes: https://github.com/nodejs/node/issues/19055
Refs: https://github.com/ripple/rippled/issues/2413
Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/node_crypto.cc | 48 | ||||
-rw-r--r-- | src/node_crypto.h | 2 |
2 files changed, 50 insertions, 0 deletions
diff --git a/src/node_crypto.cc b/src/node_crypto.cc index 5c5981b76b..92e98e2eb2 100644 --- a/src/node_crypto.cc +++ b/src/node_crypto.cc @@ -1606,6 +1606,8 @@ void SSLWrap<Base>::AddMethods(Environment* env, Local<FunctionTemplate> t) { HandleScope scope(env->isolate()); env->SetProtoMethod(t, "getPeerCertificate", GetPeerCertificate); + env->SetProtoMethod(t, "getFinished", GetFinished); + env->SetProtoMethod(t, "getPeerFinished", GetPeerFinished); env->SetProtoMethod(t, "getSession", GetSession); env->SetProtoMethod(t, "setSession", SetSession); env->SetProtoMethod(t, "loadSession", LoadSession); @@ -2121,6 +2123,52 @@ void SSLWrap<Base>::GetPeerCertificate( template <class Base> +void SSLWrap<Base>::GetFinished(const FunctionCallbackInfo<Value>& args) { + Environment* env = Environment::GetCurrent(args); + + Base* w; + ASSIGN_OR_RETURN_UNWRAP(&w, args.Holder()); + + // We cannot just pass nullptr to SSL_get_finished() + // because it would further be propagated to memcpy(), + // where the standard requirements as described in ISO/IEC 9899:2011 + // sections 7.21.2.1, 7.21.1.2, and 7.1.4, would be violated. + // Thus, we use a dummy byte. + char dummy[1]; + size_t len = SSL_get_finished(w->ssl_, dummy, sizeof dummy); + if (len == 0) + return; + + char* buf = Malloc(len); + CHECK_EQ(len, SSL_get_finished(w->ssl_, buf, len)); + args.GetReturnValue().Set(Buffer::New(env, buf, len).ToLocalChecked()); +} + + +template <class Base> +void SSLWrap<Base>::GetPeerFinished(const FunctionCallbackInfo<Value>& args) { + Environment* env = Environment::GetCurrent(args); + + Base* w; + ASSIGN_OR_RETURN_UNWRAP(&w, args.Holder()); + + // We cannot just pass nullptr to SSL_get_peer_finished() + // because it would further be propagated to memcpy(), + // where the standard requirements as described in ISO/IEC 9899:2011 + // sections 7.21.2.1, 7.21.1.2, and 7.1.4, would be violated. + // Thus, we use a dummy byte. + char dummy[1]; + size_t len = SSL_get_peer_finished(w->ssl_, dummy, sizeof dummy); + if (len == 0) + return; + + char* buf = Malloc(len); + CHECK_EQ(len, SSL_get_peer_finished(w->ssl_, buf, len)); + args.GetReturnValue().Set(Buffer::New(env, buf, len).ToLocalChecked()); +} + + +template <class Base> void SSLWrap<Base>::GetSession(const FunctionCallbackInfo<Value>& args) { Environment* env = Environment::GetCurrent(args); diff --git a/src/node_crypto.h b/src/node_crypto.h index 05ea79f71f..668781aca9 100644 --- a/src/node_crypto.h +++ b/src/node_crypto.h @@ -269,6 +269,8 @@ class SSLWrap { static void GetPeerCertificate( const v8::FunctionCallbackInfo<v8::Value>& args); + static void GetFinished(const v8::FunctionCallbackInfo<v8::Value>& args); + static void GetPeerFinished(const v8::FunctionCallbackInfo<v8::Value>& args); static void GetSession(const v8::FunctionCallbackInfo<v8::Value>& args); static void SetSession(const v8::FunctionCallbackInfo<v8::Value>& args); static void LoadSession(const v8::FunctionCallbackInfo<v8::Value>& args); |