@@ -1615,6 +1615,8 @@ void SSLWrap<Base>::AddMethods(Environment* env, Local<FunctionTemplate> t) {
1615
1615
HandleScope scope (env->isolate ());
1616
1616
1617
1617
env->SetProtoMethod (t, " getPeerCertificate" , GetPeerCertificate);
1618
+ env->SetProtoMethod (t, " getFinished" , GetFinished);
1619
+ env->SetProtoMethod (t, " getPeerFinished" , GetPeerFinished);
1618
1620
env->SetProtoMethod (t, " getSession" , GetSession);
1619
1621
env->SetProtoMethod (t, " setSession" , SetSession);
1620
1622
env->SetProtoMethod (t, " loadSession" , LoadSession);
@@ -2133,6 +2135,52 @@ void SSLWrap<Base>::GetPeerCertificate(
2133
2135
}
2134
2136
2135
2137
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
+
2136
2184
template <class Base >
2137
2185
void SSLWrap<Base>::GetSession (const FunctionCallbackInfo<Value>& args) {
2138
2186
Environment* env = Environment::GetCurrent (args);
0 commit comments