Skip to content

Commit a89bcf7

Browse files
mkrawczukMylesBorins
authored andcommitted
tls: make 'createSecureContext' honor more options
Added options: `ticketKeys` and `sessionTimeout`, that are honored by `createServer`, that calls `createSecureContext`. This also introduces a minor code simplification. PR-URL: #33974 Fixes: #20908 Reviewed-By: Alba Mendez <me@alba.sh> Reviewed-By: Ujjwal Sharma <ryzokuken@disroot.org>
1 parent 844bf77 commit a89bcf7

File tree

3 files changed

+22
-9
lines changed

3 files changed

+22
-9
lines changed

doc/api/tls.md

+5
Original file line numberDiff line numberDiff line change
@@ -1638,6 +1638,11 @@ changes:
16381638
**Default:** none, see `minVersion`.
16391639
* `sessionIdContext` {string} Opaque identifier used by servers to ensure
16401640
session state is not shared between applications. Unused by clients.
1641+
* `ticketKeys`: {Buffer} 48-bytes of cryptographically strong pseudo-random
1642+
data. See [Session Resumption][] for more information.
1643+
* `sessionTimeout` {number} The number of seconds after which a TLS session
1644+
created by the server will no longer be resumable. See
1645+
[Session Resumption][] for more information. **Default:** `300`.
16411646

16421647
[`tls.createServer()`][] sets the default value of the `honorCipherOrder` option
16431648
to `true`, other APIs that create secure contexts leave it unset.

lib/_tls_common.js

+8
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,14 @@ exports.createSecureContext = function createSecureContext(options) {
294294
options.clientCertEngine);
295295
}
296296

297+
if (options.ticketKeys) {
298+
c.context.setTicketKeys(options.ticketKeys);
299+
}
300+
301+
if (options.sessionTimeout) {
302+
c.context.setSessionTimeout(options.sessionTimeout);
303+
}
304+
297305
return c;
298306
};
299307

lib/_tls_wrap.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -1314,6 +1314,12 @@ Server.prototype.setSecureContext = function(options) {
13141314
.slice(0, 32);
13151315
}
13161316

1317+
if (options.sessionTimeout)
1318+
this.sessionTimeout = options.sessionTimeout;
1319+
1320+
if (options.ticketKeys)
1321+
this.ticketKeys = options.ticketKeys;
1322+
13171323
this._sharedCreds = tls.createSecureContext({
13181324
pfx: this.pfx,
13191325
key: this.key,
@@ -1331,16 +1337,10 @@ Server.prototype.setSecureContext = function(options) {
13311337
secureOptions: this.secureOptions,
13321338
honorCipherOrder: this.honorCipherOrder,
13331339
crl: this.crl,
1334-
sessionIdContext: this.sessionIdContext
1340+
sessionIdContext: this.sessionIdContext,
1341+
ticketKeys: this.ticketKeys,
1342+
sessionTimeout: this.sessionTimeout
13351343
});
1336-
1337-
if (this.sessionTimeout)
1338-
this._sharedCreds.context.setSessionTimeout(this.sessionTimeout);
1339-
1340-
if (options.ticketKeys) {
1341-
this.ticketKeys = options.ticketKeys;
1342-
this.setTicketKeys(this.ticketKeys);
1343-
}
13441344
};
13451345

13461346

0 commit comments

Comments
 (0)