Skip to content

Commit 8156e14

Browse files
stefanmbrvagg
authored andcommitted
tls: Use SHA1 for sessionIdContext in FIPS mode
FIPS 140-2 disallows use of MD5, which is used to derive the default sessionIdContext for tls.createServer(). PR-URL: #3755 Reviewed-By: Fedor Indutny <[email protected]>
1 parent 6c8dcc6 commit 8156e14

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

doc/api/tls.markdown

+2-1
Original file line numberDiff line numberDiff line change
@@ -804,7 +804,8 @@ automatically set as a listener for the [secureConnection][] event. The
804804

805805
- `sessionIdContext`: A string containing an opaque identifier for session
806806
resumption. If `requestCert` is `true`, the default is MD5 hash value
807-
generated from command-line. Otherwise, the default is not provided.
807+
generated from command-line. (In FIPS mode a truncated SHA1 hash is
808+
used instead.) Otherwise, the default is not provided.
808809

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

lib/_tls_wrap.js

+16-3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,21 @@ 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+
}
1732

1833
function onhandshakestart() {
1934
debug('onhandshakestart');
@@ -872,9 +887,7 @@ Server.prototype.setOptions = function(options) {
872887
if (options.sessionIdContext) {
873888
this.sessionIdContext = options.sessionIdContext;
874889
} else {
875-
this.sessionIdContext = crypto.createHash('md5')
876-
.update(process.argv.join(' '))
877-
.digest('hex');
890+
this.sessionIdContext = defaultSessionIdContext;
878891
}
879892
};
880893

0 commit comments

Comments
 (0)