Skip to content

Commit 9b27933

Browse files
mkrawczukaddaleax
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 <[email protected]> Reviewed-By: Ujjwal Sharma <[email protected]>
1 parent 19b55be commit 9b27933

File tree

3 files changed

+22
-9
lines changed

3 files changed

+22
-9
lines changed

doc/api/tls.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1685,6 +1685,11 @@ changes:
16851685
**Default:** none, see `minVersion`.
16861686
* `sessionIdContext` {string} Opaque identifier used by servers to ensure
16871687
session state is not shared between applications. Unused by clients.
1688+
* `ticketKeys`: {Buffer} 48-bytes of cryptographically strong pseudo-random
1689+
data. See [Session Resumption][] for more information.
1690+
* `sessionTimeout` {number} The number of seconds after which a TLS session
1691+
created by the server will no longer be resumable. See
1692+
[Session Resumption][] for more information. **Default:** `300`.
16881693

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

lib/_tls_common.js

Lines changed: 8 additions & 0 deletions
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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1317,6 +1317,12 @@ Server.prototype.setSecureContext = function(options) {
13171317
.slice(0, 32);
13181318
}
13191319

1320+
if (options.sessionTimeout)
1321+
this.sessionTimeout = options.sessionTimeout;
1322+
1323+
if (options.ticketKeys)
1324+
this.ticketKeys = options.ticketKeys;
1325+
13201326
this._sharedCreds = tls.createSecureContext({
13211327
pfx: this.pfx,
13221328
key: this.key,
@@ -1334,16 +1340,10 @@ Server.prototype.setSecureContext = function(options) {
13341340
secureOptions: this.secureOptions,
13351341
honorCipherOrder: this.honorCipherOrder,
13361342
crl: this.crl,
1337-
sessionIdContext: this.sessionIdContext
1343+
sessionIdContext: this.sessionIdContext,
1344+
ticketKeys: this.ticketKeys,
1345+
sessionTimeout: this.sessionTimeout
13381346
});
1339-
1340-
if (this.sessionTimeout)
1341-
this._sharedCreds.context.setSessionTimeout(this.sessionTimeout);
1342-
1343-
if (options.ticketKeys) {
1344-
this.ticketKeys = options.ticketKeys;
1345-
this.setTicketKeys(this.ticketKeys);
1346-
}
13471347
};
13481348

13491349

0 commit comments

Comments
 (0)