@@ -1497,6 +1497,8 @@ void SSLWrap<Base>::AddMethods(Environment* env, Local<FunctionTemplate> t) {
1497
1497
HandleScope scope (env->isolate ());
1498
1498
1499
1499
env->SetProtoMethod (t, " getPeerCertificate" , GetPeerCertificate);
1500
+ env->SetProtoMethod (t, " getFinished" , GetFinished);
1501
+ env->SetProtoMethod (t, " getPeerFinished" , GetPeerFinished);
1500
1502
env->SetProtoMethod (t, " getSession" , GetSession);
1501
1503
env->SetProtoMethod (t, " setSession" , SetSession);
1502
1504
env->SetProtoMethod (t, " loadSession" , LoadSession);
@@ -1985,6 +1987,52 @@ void SSLWrap<Base>::GetPeerCertificate(
1985
1987
}
1986
1988
1987
1989
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
+
1988
2036
template <class Base >
1989
2037
void SSLWrap<Base>::GetSession (const FunctionCallbackInfo<Value>& args) {
1990
2038
Environment* env = Environment::GetCurrent (args);
0 commit comments