@@ -1595,6 +1595,33 @@ void TLSWrap::SetALPNProtocols(const FunctionCallbackInfo<Value>& args) {
1595
1595
}
1596
1596
}
1597
1597
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
+
1598
1625
void TLSWrap::GetPeerCertificate (const FunctionCallbackInfo<Value>& args) {
1599
1626
TLSWrap* w;
1600
1627
ASSIGN_OR_RETURN_UNWRAP (&w, args.Holder ());
@@ -2130,6 +2157,7 @@ void TLSWrap::Initialize(
2130
2157
SetProtoMethod (isolate, t, " renegotiate" , Renegotiate);
2131
2158
SetProtoMethod (isolate, t, " requestOCSP" , RequestOCSP);
2132
2159
SetProtoMethod (isolate, t, " setALPNProtocols" , SetALPNProtocols);
2160
+ SetProtoMethod (isolate, t, " setKeyCert" , SetKeyCert);
2133
2161
SetProtoMethod (isolate, t, " setOCSPResponse" , SetOCSPResponse);
2134
2162
SetProtoMethod (isolate, t, " setServername" , SetServername);
2135
2163
SetProtoMethod (isolate, t, " setSession" , SetSession);
0 commit comments