Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b2e2e64

Browse filesBrowse files
jasnelladuh95
authored andcommitted
quic: apply multiple TLS context improvements and SNI support
Signed-off-by: James M Snell <jasnell@gmail.com> Assisted-by: Opencode:Opus 4.6 PR-URL: #62620 Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: Tim Perry <pimterry@gmail.com>
1 parent 56b941a commit b2e2e64
Copy full SHA for b2e2e64

15 files changed

+573-112Lines changed: 573 additions & 112 deletions
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎doc/api/quic.md‎

Copy file name to clipboardExpand all lines: doc/api/quic.md
+89-12Lines changed: 89 additions & 12 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,34 @@ added: v23.8.0
204204

205205
True if `endpoint.destroy()` has been called. Read only.
206206

207+
### `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`
208236

209237
<!-- YAML
@@ -1120,15 +1148,16 @@ added: v23.8.0
11201148

11211149
The ALPN protocol identifier.
11221150

1123-
#### `sessionOptions.ca`
1151+
#### `sessionOptions.ca` (client only)
11241152

11251153
<!-- YAML
11261154
added: v23.8.0
11271155
-->
11281156

11291157
* Type: {ArrayBuffer|ArrayBufferView|ArrayBuffer\[]|ArrayBufferView\[]}
11301158

1131-
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.
11321161

11331162
#### `sessionOptions.cc`
11341163

@@ -1143,15 +1172,16 @@ Specifies the congestion control algorithm that will be used
11431172

11441173
This is an advanced option that users typically won't have need to specify.
11451174

1146-
#### `sessionOptions.certs`
1175+
#### `sessionOptions.certs` (client only)
11471176

11481177
<!-- YAML
11491178
added: v23.8.0
11501179
-->
11511180

11521181
* Type: {ArrayBuffer|ArrayBufferView|ArrayBuffer\[]|ArrayBufferView\[]}
11531182

1154-
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.
11551185

11561186
#### `sessionOptions.ciphers`
11571187

@@ -1163,15 +1193,16 @@ added: v23.8.0
11631193

11641194
The list of supported TLS 1.3 cipher algorithms.
11651195

1166-
#### `sessionOptions.crl`
1196+
#### `sessionOptions.crl` (client only)
11671197

11681198
<!-- YAML
11691199
added: v23.8.0
11701200
-->
11711201

11721202
* Type: {ArrayBuffer|ArrayBufferView|ArrayBuffer\[]|ArrayBufferView\[]}
11731203

1174-
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.
11751206

11761207
#### `sessionOptions.groups`
11771208

@@ -1193,7 +1224,7 @@ added: v23.8.0
11931224

11941225
True to enable TLS keylogging output.
11951226

1196-
#### `sessionOptions.keys`
1227+
#### `sessionOptions.keys` (client only)
11971228

11981229
<!-- YAML
11991230
added: v23.8.0
@@ -1205,7 +1236,8 @@ changes:
12051236

12061237
* Type: {KeyObject|KeyObject\[]}
12071238

1208-
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.
12091241

12101242
#### `sessionOptions.maxPayloadSize`
12111243

@@ -1288,15 +1320,56 @@ added: v23.8.0
12881320
Specifies the maximum number of milliseconds a TLS handshake is permitted to take
12891321
to complete before timing out.
12901322

1291-
#### `sessionOptions.sni`
1323+
#### `sessionOptions.servername` (client only)
12921324

12931325
<!-- YAML
12941326
added: v23.8.0
12951327
-->
12961328

12971329
* Type: {string}
12981330

1299-
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.
13001373

13011374
#### `sessionOptions.tlsTrace`
13021375

@@ -1338,15 +1411,17 @@ added: v23.8.0
13381411

13391412
True to require verification of TLS client certificate.
13401413

1341-
#### `sessionOptions.verifyPrivateKey`
1414+
#### `sessionOptions.verifyPrivateKey` (client only)
13421415

13431416
<!-- YAML
13441417
added: v23.8.0
13451418
-->
13461419

13471420
* Type: {boolean}
13481421

1349-
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.
13501425

13511426
#### `sessionOptions.version`
13521427

@@ -1715,3 +1790,5 @@ added: v23.8.0
17151790
<!-- YAML
17161791
added: v23.8.0
17171792
-->
1793+
1794+
[`sessionOptions.sni`]: #sessionoptionssni-server-only

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.