@@ -1497,6 +1497,8 @@ void SSLWrap<Base>::AddMethods(Environment* env, Local<FunctionTemplate> t) {
14971497  HandleScope scope (env->isolate ());
14981498
14991499  env->SetProtoMethod (t, " getPeerCertificate" 
1500+   env->SetProtoMethod (t, " getFinished" 
1501+   env->SetProtoMethod (t, " getPeerFinished" 
15001502  env->SetProtoMethod (t, " getSession" 
15011503  env->SetProtoMethod (t, " setSession" 
15021504  env->SetProtoMethod (t, " loadSession" 
@@ -1985,6 +1987,52 @@ void SSLWrap<Base>::GetPeerCertificate(
19851987}
19861988
19871989
1990+ template  <class  Base >
1991+ void  SSLWrap<Base>::GetFinished (const  FunctionCallbackInfo<Value>& args) {
1992+   Environment* env = Environment::GetCurrent (args);
1993+ 
1994+   Base* w;
1995+   ASSIGN_OR_RETURN_UNWRAP (&w, args.Holder ());
1996+ 
1997+   //  We cannot just pass nullptr to SSL_get_finished()
1998+   //  because it would further be propagated to memcpy(),
1999+   //  where the standard requirements as described in ISO/IEC 9899:2011
2000+   //  sections 7.21.2.1, 7.21.1.2, and 7.1.4, would be violated.
2001+   //  Thus, we use a dummy byte.
2002+   char  dummy[1 ];
2003+   size_t  len = SSL_get_finished (w->ssl_ , dummy, sizeof  dummy);
2004+   if  (len == 0 )
2005+     return ;
2006+ 
2007+   char * buf = Malloc (len);
2008+   CHECK_EQ (len, SSL_get_finished (w->ssl_ , buf, len));
2009+   args.GetReturnValue ().Set (Buffer::New (env, buf, len).ToLocalChecked ());
2010+ }
2011+ 
2012+ 
2013+ template  <class  Base >
2014+ void  SSLWrap<Base>::GetPeerFinished (const  FunctionCallbackInfo<Value>& args) {
2015+   Environment* env = Environment::GetCurrent (args);
2016+ 
2017+   Base* w;
2018+   ASSIGN_OR_RETURN_UNWRAP (&w, args.Holder ());
2019+ 
2020+   //  We cannot just pass nullptr to SSL_get_peer_finished()
2021+   //  because it would further be propagated to memcpy(),
2022+   //  where the standard requirements as described in ISO/IEC 9899:2011
2023+   //  sections 7.21.2.1, 7.21.1.2, and 7.1.4, would be violated.
2024+   //  Thus, we use a dummy byte.
2025+   char  dummy[1 ];
2026+   size_t  len = SSL_get_peer_finished (w->ssl_ , dummy, sizeof  dummy);
2027+   if  (len == 0 )
2028+     return ;
2029+ 
2030+   char * buf = Malloc (len);
2031+   CHECK_EQ (len, SSL_get_peer_finished (w->ssl_ , buf, len));
2032+   args.GetReturnValue ().Set (Buffer::New (env, buf, len).ToLocalChecked ());
2033+ }
2034+ 
2035+ 
19882036template  <class  Base >
19892037void  SSLWrap<Base>::GetSession (const  FunctionCallbackInfo<Value>& args) {
19902038  Environment* env = Environment::GetCurrent (args);
0 commit comments