quic: apply multiple TLS context improvements and SNI support · nodejs/node@476926c
@@ -204,6 +204,34 @@ added: v23.8.0
204204205205True if `endpoint.destroy()` has been called. Read only.
206206207+### `endpoint.setSNIContexts(entries[, options])`
208+209+<!-- YAML
210+added: REPLACEME
211+-->
212+213+* `entries` {object} An object mapping host names to TLS identity options.
214+ Each entry must include `keys` and `certs`.
215+* `options` {object}
216+* `replace` {boolean} If `true`, replaces the entire SNI map. If `false`
217+ (the default), merges the entries into the existing map.
218+219+Replaces or updates the SNI TLS contexts for this endpoint. This allows
220+changing the TLS identity (key/certificate) used for specific host names
221+without restarting the endpoint. Existing sessions are unaffected — only
222+new sessions will use the updated contexts.
223+224+```mjs
225+endpoint.setSNIContexts({
226+'api.example.com': { keys: [newApiKey], certs: [newApiCert] },
227+});
228+229+// Replace the entire SNI map
230+endpoint.setSNIContexts({
231+'api.example.com': { keys: [newApiKey], certs: [newApiCert] },
232+}, { replace: true });
233+```
234+207235### `endpoint.stats`
208236209237<!-- YAML
@@ -1120,15 +1148,16 @@ added: v23.8.0
1120114811211149The ALPN protocol identifier.
112211501123-#### `sessionOptions.ca`
1151+#### `sessionOptions.ca` (client only)
1124115211251153<!-- YAML
11261154added: v23.8.0
11271155-->
1128115611291157* Type: {ArrayBuffer|ArrayBufferView|ArrayBuffer\[]|ArrayBufferView\[]}
113011581131-The CA certificates to use for sessions.
1159+The CA certificates to use for client sessions. For server sessions, CA
1160+certificates are specified per-identity in the [`sessionOptions.sni`][] map.
1132116111331162#### `sessionOptions.cc`
11341163@@ -1143,15 +1172,16 @@ Specifies the congestion control algorithm that will be used
1143117211441173This is an advanced option that users typically won't have need to specify.
114511741146-#### `sessionOptions.certs`
1175+#### `sessionOptions.certs` (client only)
1147117611481177<!-- YAML
11491178added: v23.8.0
11501179-->
1151118011521181* Type: {ArrayBuffer|ArrayBufferView|ArrayBuffer\[]|ArrayBufferView\[]}
115311821154-The TLS certificates to use for sessions.
1183+The TLS certificates to use for client sessions. For server sessions,
1184+certificates are specified per-identity in the [`sessionOptions.sni`][] map.
1155118511561186#### `sessionOptions.ciphers`
11571187@@ -1163,15 +1193,16 @@ added: v23.8.0
1163119311641194The list of supported TLS 1.3 cipher algorithms.
116511951166-#### `sessionOptions.crl`
1196+#### `sessionOptions.crl` (client only)
1167119711681198<!-- YAML
11691199added: v23.8.0
11701200-->
1171120111721202* Type: {ArrayBuffer|ArrayBufferView|ArrayBuffer\[]|ArrayBufferView\[]}
117312031174-The CRL to use for sessions.
1204+The CRL to use for client sessions. For server sessions, CRLs are specified
1205+per-identity in the [`sessionOptions.sni`][] map.
1175120611761207#### `sessionOptions.groups`
11771208@@ -1193,7 +1224,7 @@ added: v23.8.0
1193122411941225True to enable TLS keylogging output.
119512261196-#### `sessionOptions.keys`
1227+#### `sessionOptions.keys` (client only)
1197122811981229<!-- YAML
11991230added: v23.8.0
@@ -1205,7 +1236,8 @@ changes:
1205123612061237* Type: {KeyObject|KeyObject\[]}
120712381208-The TLS crypto keys to use for sessions.
1239+The TLS crypto keys to use for client sessions. For server sessions,
1240+keys are specified per-identity in the [`sessionOptions.sni`][] map.
1209124112101242#### `sessionOptions.maxPayloadSize`
12111243@@ -1288,15 +1320,56 @@ added: v23.8.0
12881320Specifies the maximum number of milliseconds a TLS handshake is permitted to take
12891321to complete before timing out.
129013221291-#### `sessionOptions.sni`
1323+#### `sessionOptions.servername` (client only)
1292132412931325<!-- YAML
12941326added: v23.8.0
12951327-->
1296132812971329* Type: {string}
129813301299-The peer server name to target.
1331+The peer server name to target (SNI). Defaults to `'localhost'`.
1332+1333+#### `sessionOptions.sni` (server only)
1334+1335+<!-- YAML
1336+added: REPLACEME
1337+-->
1338+1339+* Type: {Object}
1340+1341+An object mapping host names to TLS identity options for Server Name
1342+Indication (SNI) support. This is required for server sessions. The
1343+special key `'*'` specifies the default/fallback identity used when
1344+no other host name matches. Each entry may contain:
1345+1346+* `keys` {KeyObject|KeyObject\[]} The TLS private keys. **Required.**
1347+* `certs` {ArrayBuffer|ArrayBufferView|ArrayBuffer\[]|ArrayBufferView\[]}
1348+ The TLS certificates. **Required.**
1349+* `ca` {ArrayBuffer|ArrayBufferView|ArrayBuffer\[]|ArrayBufferView\[]}
1350+ Optional CA certificate overrides.
1351+* `crl` {ArrayBuffer|ArrayBufferView|ArrayBuffer\[]|ArrayBufferView\[]}
1352+ Optional certificate revocation lists.
1353+* `verifyPrivateKey` {boolean} Verify the private key. Default: `false`.
1354+1355+```mjs
1356+const endpoint = await listen(callback, {
1357+ sni: {
1358+'*': { keys: [defaultKey], certs: [defaultCert] },
1359+'api.example.com': { keys: [apiKey], certs: [apiCert] },
1360+'www.example.com': { keys: [wwwKey], certs: [wwwCert], ca: [customCA] },
1361+ },
1362+});
1363+```
1364+1365+Shared TLS options (such as `ciphers`, `groups`, `keylog`, and `verifyClient`)
1366+are specified at the top level of the session options and apply to all
1367+identities. Each SNI entry overrides only the per-identity certificate
1368+fields.
1369+1370+The SNI map can be replaced at runtime using `endpoint.setSNIContexts()`,
1371+which atomically swaps the map for new sessions while existing sessions
1372+continue to use their original identity.
1300137313011374#### `sessionOptions.tlsTrace`
13021375@@ -1338,15 +1411,17 @@ added: v23.8.0
1338141113391412True to require verification of TLS client certificate.
134014131341-#### `sessionOptions.verifyPrivateKey`
1414+#### `sessionOptions.verifyPrivateKey` (client only)
1342141513431416<!-- YAML
13441417added: v23.8.0
13451418-->
1346141913471420* Type: {boolean}
134814211349-True to require private key verification.
1422+True to require private key verification for client sessions. For server
1423+sessions, this option is specified per-identity in the
1424+[`sessionOptions.sni`][] map.
1350142513511426#### `sessionOptions.version`
13521427@@ -1715,3 +1790,5 @@ added: v23.8.0
17151790<!-- YAML
17161791added: v23.8.0
17171792-->
1793+1794+[`sessionOptions.sni`]: #sessionoptionssni-server-only