Skip to content

Commit df268f9

Browse files
stefanmbindutny
authored andcommitted
tls: use SHA1 for sessionIdContext
FIPS 140-2 disallows use of MD5, which is used to derive the default sessionIdContext for tls.createServer(). PR-URL: #3866 Reviewed-By: Fedor Indutny <fedor@indutny.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 424ae5d commit df268f9

File tree

2 files changed

+7
-19
lines changed

2 files changed

+7
-19
lines changed

doc/api/tls.markdown

+3-3
Original file line numberDiff line numberDiff line change
@@ -841,9 +841,9 @@ automatically set as a listener for the [secureConnection][] event. The
841841
NOTE: Automatically shared between `cluster` module workers.
842842

843843
- `sessionIdContext`: A string containing an opaque identifier for session
844-
resumption. If `requestCert` is `true`, the default is MD5 hash value
845-
generated from command-line. (In FIPS mode a truncated SHA1 hash is
846-
used instead.) Otherwise, the default is not provided.
844+
resumption. If `requestCert` is `true`, the default is a 128 bit
845+
truncated SHA1 hash value generated from command-line. Otherwise,
846+
the default is not provided.
847847

848848
- `secureProtocol`: The SSL method to use, e.g. `SSLv3_method` to force
849849
SSL version 3. The possible values depend on your installation of

lib/_tls_wrap.js

+4-16
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,6 @@ const Timer = process.binding('timer_wrap').Timer;
1414
const tls_wrap = process.binding('tls_wrap');
1515
const TCP = process.binding('tcp_wrap').TCP;
1616
const Pipe = process.binding('pipe_wrap').Pipe;
17-
const defaultSessionIdContext = getDefaultSessionIdContext();
18-
19-
function getDefaultSessionIdContext() {
20-
var defaultText = process.argv.join(' ');
21-
/* SSL_MAX_SID_CTX_LENGTH is 128 bits */
22-
if (process.config.variables.openssl_fips) {
23-
return crypto.createHash('sha1')
24-
.update(defaultText)
25-
.digest('hex').slice(0, 32);
26-
} else {
27-
return crypto.createHash('md5')
28-
.update(defaultText)
29-
.digest('hex');
30-
}
31-
}
3217

3318
function onhandshakestart() {
3419
debug('onhandshakestart');
@@ -908,7 +893,10 @@ Server.prototype.setOptions = function(options) {
908893
if (options.sessionIdContext) {
909894
this.sessionIdContext = options.sessionIdContext;
910895
} else {
911-
this.sessionIdContext = defaultSessionIdContext;
896+
this.sessionIdContext = crypto.createHash('sha1')
897+
.update(process.argv.join(' '))
898+
.digest('hex')
899+
.slice(0, 32);
912900
}
913901
};
914902

0 commit comments

Comments
 (0)