diff options
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); |