@@ -1606,6 +1606,8 @@ void SSLWrap<Base>::AddMethods(Environment* env, Local<FunctionTemplate> t) {
1606
1606
HandleScope scope (env->isolate ());
1607
1607
1608
1608
env->SetProtoMethod (t, " getPeerCertificate" , GetPeerCertificate);
1609
+ env->SetProtoMethod (t, " getFinished" , GetFinished);
1610
+ env->SetProtoMethod (t, " getPeerFinished" , GetPeerFinished);
1609
1611
env->SetProtoMethod (t, " getSession" , GetSession);
1610
1612
env->SetProtoMethod (t, " setSession" , SetSession);
1611
1613
env->SetProtoMethod (t, " loadSession" , LoadSession);
@@ -2120,6 +2122,52 @@ void SSLWrap<Base>::GetPeerCertificate(
2120
2122
}
2121
2123
2122
2124
2125
+ template <class Base >
2126
+ void SSLWrap<Base>::GetFinished (const FunctionCallbackInfo<Value>& args) {
2127
+ Environment* env = Environment::GetCurrent (args);
2128
+
2129
+ Base* w;
2130
+ ASSIGN_OR_RETURN_UNWRAP (&w, args.Holder ());
2131
+
2132
+ // We cannot just pass nullptr to SSL_get_finished()
2133
+ // because it would further be propagated to memcpy(),
2134
+ // where the standard requirements as described in ISO/IEC 9899:2011
2135
+ // sections 7.21.2.1, 7.21.1.2, and 7.1.4, would be violated.
2136
+ // Thus, we use a dummy byte.
2137
+ char dummy[1 ];
2138
+ size_t len = SSL_get_finished (w->ssl_ , dummy, sizeof dummy);
2139
+ if (len == 0 )
2140
+ return ;
2141
+
2142
+ char * buf = Malloc (len);
2143
+ CHECK_EQ (len, SSL_get_finished (w->ssl_ , buf, len));
2144
+ args.GetReturnValue ().Set (Buffer::New (env, buf, len).ToLocalChecked ());
2145
+ }
2146
+
2147
+
2148
+ template <class Base >
2149
+ void SSLWrap<Base>::GetPeerFinished (const FunctionCallbackInfo<Value>& args) {
2150
+ Environment* env = Environment::GetCurrent (args);
2151
+
2152
+ Base* w;
2153
+ ASSIGN_OR_RETURN_UNWRAP (&w, args.Holder ());
2154
+
2155
+ // We cannot just pass nullptr to SSL_get_peer_finished()
2156
+ // because it would further be propagated to memcpy(),
2157
+ // where the standard requirements as described in ISO/IEC 9899:2011
2158
+ // sections 7.21.2.1, 7.21.1.2, and 7.1.4, would be violated.
2159
+ // Thus, we use a dummy byte.
2160
+ char dummy[1 ];
2161
+ size_t len = SSL_get_peer_finished (w->ssl_ , dummy, sizeof dummy);
2162
+ if (len == 0 )
2163
+ return ;
2164
+
2165
+ char * buf = Malloc (len);
2166
+ CHECK_EQ (len, SSL_get_peer_finished (w->ssl_ , buf, len));
2167
+ args.GetReturnValue ().Set (Buffer::New (env, buf, len).ToLocalChecked ());
2168
+ }
2169
+
2170
+
2123
2171
template <class Base >
2124
2172
void SSLWrap<Base>::GetSession (const FunctionCallbackInfo<Value>& args) {
2125
2173
Environment* env = Environment::GetCurrent (args);
0 commit comments