@@ -116,6 +116,18 @@ const noop = () => {};
116
116
let ipServernameWarned = false ;
117
117
let tlsTracingWarned = false ;
118
118
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
+
119
131
// Server side times how long a handshake is taking to protect against slow
120
132
// handshakes being used for DoS.
121
133
function onhandshakestart ( now ) {
@@ -1472,10 +1484,7 @@ Server.prototype.setSecureContext = function(options) {
1472
1484
if ( options . sessionIdContext ) {
1473
1485
this . sessionIdContext = options . sessionIdContext ;
1474
1486
} else {
1475
- this . sessionIdContext = crypto . createHash ( 'sha1' )
1476
- . update ( process . argv . join ( ' ' ) )
1477
- . digest ( 'hex' )
1478
- . slice ( 0 , 32 ) ;
1487
+ this . sessionIdContext = lazyDefaultSessionIdContext ( ) ;
1479
1488
}
1480
1489
1481
1490
if ( options . sessionTimeout )
@@ -1570,10 +1579,7 @@ Server.prototype.setOptions = deprecate(function(options) {
1570
1579
if ( options . sessionIdContext ) {
1571
1580
this . sessionIdContext = options . sessionIdContext ;
1572
1581
} else {
1573
- this . sessionIdContext = crypto . createHash ( 'sha1' )
1574
- . update ( process . argv . join ( ' ' ) )
1575
- . digest ( 'hex' )
1576
- . slice ( 0 , 32 ) ;
1582
+ this . sessionIdContext = lazyDefaultSessionIdContext ( ) ;
1577
1583
}
1578
1584
if ( options . pskCallback ) this [ kPskCallback ] = options . pskCallback ;
1579
1585
if ( options . pskIdentityHint ) this [ kPskIdentityHint ] = options . pskIdentityHint ;
0 commit comments