@@ -1615,6 +1615,8 @@ void SSLWrap<Base>::AddMethods(Environment* env, Local<FunctionTemplate> t) {
16151615  HandleScope scope (env->isolate ());
16161616
16171617  env->SetProtoMethod (t, " getPeerCertificate"  , GetPeerCertificate);
1618+   env->SetProtoMethod (t, " getFinished"  , GetFinished);
1619+   env->SetProtoMethod (t, " getPeerFinished"  , GetPeerFinished);
16181620  env->SetProtoMethod (t, " getSession"  , GetSession);
16191621  env->SetProtoMethod (t, " setSession"  , SetSession);
16201622  env->SetProtoMethod (t, " loadSession"  , LoadSession);
@@ -2133,6 +2135,52 @@ void SSLWrap<Base>::GetPeerCertificate(
21332135}
21342136
21352137
2138+ template  <class  Base >
2139+ void  SSLWrap<Base>::GetFinished (const  FunctionCallbackInfo<Value>& args) {
2140+   Environment* env = Environment::GetCurrent (args);
2141+ 
2142+   Base* w;
2143+   ASSIGN_OR_RETURN_UNWRAP (&w, args.Holder ());
2144+ 
2145+   //  We cannot just pass nullptr to SSL_get_finished()
2146+   //  because it would further be propagated to memcpy(),
2147+   //  where the standard requirements as described in ISO/IEC 9899:2011
2148+   //  sections 7.21.2.1, 7.21.1.2, and 7.1.4, would be violated.
2149+   //  Thus, we use a dummy byte.
2150+   char  dummy[1 ];
2151+   size_t  len = SSL_get_finished (w->ssl_ , dummy, sizeof  dummy);
2152+   if  (len == 0 )
2153+     return ;
2154+ 
2155+   char * buf = Malloc (len);
2156+   CHECK_EQ (len, SSL_get_finished (w->ssl_ , buf, len));
2157+   args.GetReturnValue ().Set (Buffer::New (env, buf, len).ToLocalChecked ());
2158+ }
2159+ 
2160+ 
2161+ template  <class  Base >
2162+ void  SSLWrap<Base>::GetPeerFinished (const  FunctionCallbackInfo<Value>& args) {
2163+   Environment* env = Environment::GetCurrent (args);
2164+ 
2165+   Base* w;
2166+   ASSIGN_OR_RETURN_UNWRAP (&w, args.Holder ());
2167+ 
2168+   //  We cannot just pass nullptr to SSL_get_peer_finished()
2169+   //  because it would further be propagated to memcpy(),
2170+   //  where the standard requirements as described in ISO/IEC 9899:2011
2171+   //  sections 7.21.2.1, 7.21.1.2, and 7.1.4, would be violated.
2172+   //  Thus, we use a dummy byte.
2173+   char  dummy[1 ];
2174+   size_t  len = SSL_get_peer_finished (w->ssl_ , dummy, sizeof  dummy);
2175+   if  (len == 0 )
2176+     return ;
2177+ 
2178+   char * buf = Malloc (len);
2179+   CHECK_EQ (len, SSL_get_peer_finished (w->ssl_ , buf, len));
2180+   args.GetReturnValue ().Set (Buffer::New (env, buf, len).ToLocalChecked ());
2181+ }
2182+ 
2183+ 
21362184template  <class  Base >
21372185void  SSLWrap<Base>::GetSession (const  FunctionCallbackInfo<Value>& args) {
21382186  Environment* env = Environment::GetCurrent (args);
0 commit comments