@@ -1595,6 +1595,33 @@ void TLSWrap::SetALPNProtocols(const FunctionCallbackInfo<Value>& args) {
15951595 }
15961596}
15971597
1598+ void TLSWrap::SetKeyCert (const FunctionCallbackInfo<Value>& args) {
1599+ TLSWrap* w;
1600+ ASSIGN_OR_RETURN_UNWRAP (&w, args.This ());
1601+ Environment* env = w->env ();
1602+
1603+ if (w->is_client ()) return ;
1604+
1605+ if (args.Length () < 1 || !args[0 ]->IsObject ())
1606+ return env->ThrowTypeError (" Must give a SecureContext as first argument" );
1607+
1608+ Local<Value> ctx = args[0 ];
1609+ if (UNLIKELY (ctx.IsEmpty ())) return ;
1610+
1611+ Local<FunctionTemplate> cons = env->secure_context_constructor_template ();
1612+ if (cons->HasInstance (ctx)) {
1613+ SecureContext* sc = Unwrap<SecureContext>(ctx.As <Object>());
1614+ CHECK_NOT_NULL (sc);
1615+ if (!UseSNIContext (w->ssl_ , BaseObjectPtr<SecureContext>(sc)) ||
1616+ !w->SetCACerts (sc)) {
1617+ unsigned long err = ERR_get_error (); // NOLINT(runtime/int)
1618+ return ThrowCryptoError (env, err, " SetKeyCert" );
1619+ }
1620+ } else {
1621+ return env->ThrowTypeError (" Must give a SecureContext as first argument" );
1622+ }
1623+ }
1624+
15981625void TLSWrap::GetPeerCertificate (const FunctionCallbackInfo<Value>& args) {
15991626 TLSWrap* w;
16001627 ASSIGN_OR_RETURN_UNWRAP (&w, args.This ());
@@ -2130,6 +2157,7 @@ void TLSWrap::Initialize(
21302157 SetProtoMethod (isolate, t, " renegotiate" , Renegotiate);
21312158 SetProtoMethod (isolate, t, " requestOCSP" , RequestOCSP);
21322159 SetProtoMethod (isolate, t, " setALPNProtocols" , SetALPNProtocols);
2160+ SetProtoMethod (isolate, t, " setKeyCert" , SetKeyCert);
21332161 SetProtoMethod (isolate, t, " setOCSPResponse" , SetOCSPResponse);
21342162 SetProtoMethod (isolate, t, " setServername" , SetServername);
21352163 SetProtoMethod (isolate, t, " setSession" , SetSession);
0 commit comments