@@ -1595,6 +1595,35 @@ 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 ())
1604+ return ;
1605+
1606+ if (args.Length () < 1 || !args[0 ]->IsObject ())
1607+ return env->ThrowTypeError (" Must give a SecureContext as first argument" );
1608+
1609+ Local<Value> ctx = args[0 ];
1610+ if (UNLIKELY (ctx.IsEmpty ()))
1611+ return ;
1612+
1613+ Local<FunctionTemplate> cons = env->secure_context_constructor_template ();
1614+ if (cons->HasInstance (ctx)) {
1615+ SecureContext* sc = Unwrap<SecureContext>(ctx.As <Object>());
1616+ CHECK_NOT_NULL (sc);
1617+ if (!UseSNIContext (w->ssl_ , BaseObjectPtr<SecureContext>(sc)) ||
1618+ !w->SetCACerts (sc)) {
1619+ unsigned long err = ERR_get_error (); // NOLINT(runtime/int)
1620+ return ThrowCryptoError (env, err, " SetKeyCert" );
1621+ }
1622+ } else {
1623+ return env->ThrowTypeError (" Must give a SecureContext as first argument" );
1624+ }
1625+ }
1626+
15981627void TLSWrap::GetPeerCertificate (const FunctionCallbackInfo<Value>& args) {
15991628 TLSWrap* w;
16001629 ASSIGN_OR_RETURN_UNWRAP (&w, args.This ());
@@ -2130,6 +2159,7 @@ void TLSWrap::Initialize(
21302159 SetProtoMethod (isolate, t, " renegotiate" , Renegotiate);
21312160 SetProtoMethod (isolate, t, " requestOCSP" , RequestOCSP);
21322161 SetProtoMethod (isolate, t, " setALPNProtocols" , SetALPNProtocols);
2162+ SetProtoMethod (isolate, t, " setKeyCert" , SetKeyCert);
21332163 SetProtoMethod (isolate, t, " setOCSPResponse" , SetOCSPResponse);
21342164 SetProtoMethod (isolate, t, " setServername" , SetServername);
21352165 SetProtoMethod (isolate, t, " setSession" , SetSession);
0 commit comments