From f862f66eeeb114cdac89992b1365907f82f39a56 Mon Sep 17 00:00:00 2001 From: mscdex Date: Mon, 15 Jul 2024 11:17:59 -0400 Subject: [PATCH] tls: add setKeyCert() to tls.Socket PR-URL: https://github.com/nodejs/node/pull/53636 Reviewed-By: Yagiz Nizipli Reviewed-By: James M Snell Reviewed-By: Tim Perry --- doc/api/tls.md | 14 ++++++ lib/_tls_wrap.js | 11 ++++ src/crypto/crypto_tls.cc | 28 +++++++++++ src/crypto/crypto_tls.h | 1 + test/parallel/test-tls-server-setkeycert.js | 56 +++++++++++++++++++++ 5 files changed, 110 insertions(+) create mode 100644 test/parallel/test-tls-server-setkeycert.js diff --git a/doc/api/tls.md b/doc/api/tls.md index 544472ead16abb..c3712a2b8eb4d3 100644 --- a/doc/api/tls.md +++ b/doc/api/tls.md @@ -1533,6 +1533,20 @@ When running as the server, the socket will be destroyed with an error after For TLSv1.3, renegotiation cannot be initiated, it is not supported by the protocol. +### `tlsSocket.setKeyCert(context)` + + + +* `context` {Object|tls.SecureContext} An object containing at least `key` and + `cert` properties from the [`tls.createSecureContext()`][] `options`, or a + TLS context object created with [`tls.createSecureContext()`][] itself. + +The `tlsSocket.setKeyCert()` method sets the private key and certificate to use +for the socket. This is mainly useful if you wish to select a server certificate +from a TLS server's `ALPNCallback`. + ### `tlsSocket.setMaxSendFragment(size)`