Skip to content

Commit 5879fc1

Browse files
committed
tls: tls-Server should generate lazily create sessionIdContext
1 parent 3cbeed8 commit 5879fc1

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

lib/_tls_wrap.js

+14-8
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,18 @@ const noop = () => {};
116116
let ipServernameWarned = false;
117117
let tlsTracingWarned = false;
118118

119+
let defaultSessionIdContext = null;
120+
121+
function lazyDefaultSessionIdContext() {
122+
if (defaultSessionIdContext === null) {
123+
defaultSessionIdContext = crypto.createHash('sha1')
124+
.update(process.argv.length === 1 ? process.argv[0] : process.argv.join(' '))
125+
.digest('hex')
126+
.slice(0, 32);
127+
}
128+
return defaultSessionIdContext;
129+
}
130+
119131
// Server side times how long a handshake is taking to protect against slow
120132
// handshakes being used for DoS.
121133
function onhandshakestart(now) {
@@ -1472,10 +1484,7 @@ Server.prototype.setSecureContext = function(options) {
14721484
if (options.sessionIdContext) {
14731485
this.sessionIdContext = options.sessionIdContext;
14741486
} else {
1475-
this.sessionIdContext = crypto.createHash('sha1')
1476-
.update(process.argv.join(' '))
1477-
.digest('hex')
1478-
.slice(0, 32);
1487+
this.sessionIdContext = lazyDefaultSessionIdContext();
14791488
}
14801489

14811490
if (options.sessionTimeout)
@@ -1570,10 +1579,7 @@ Server.prototype.setOptions = deprecate(function(options) {
15701579
if (options.sessionIdContext) {
15711580
this.sessionIdContext = options.sessionIdContext;
15721581
} else {
1573-
this.sessionIdContext = crypto.createHash('sha1')
1574-
.update(process.argv.join(' '))
1575-
.digest('hex')
1576-
.slice(0, 32);
1582+
this.sessionIdContext = lazyDefaultSessionIdContext();
15771583
}
15781584
if (options.pskCallback) this[kPskCallback] = options.pskCallback;
15791585
if (options.pskIdentityHint) this[kPskIdentityHint] = options.pskIdentityHint;

0 commit comments

Comments
 (0)