Skip to content

Commit

Permalink
tls: use SHA1 for sessionIdContext
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
stefanmb authored and indutny committed Nov 16, 2015
1 parent 424ae5d commit df268f9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 19 deletions.
6 changes: 3 additions & 3 deletions doc/api/tls.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -841,9 +841,9 @@ automatically set as a listener for the [secureConnection][] event. The
NOTE: Automatically shared between `cluster` module workers.

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

- `secureProtocol`: The SSL method to use, e.g. `SSLv3_method` to force
SSL version 3. The possible values depend on your installation of
Expand Down
20 changes: 4 additions & 16 deletions lib/_tls_wrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,6 @@ const Timer = process.binding('timer_wrap').Timer;
const tls_wrap = process.binding('tls_wrap');
const TCP = process.binding('tcp_wrap').TCP;
const Pipe = process.binding('pipe_wrap').Pipe;
const defaultSessionIdContext = getDefaultSessionIdContext();

function getDefaultSessionIdContext() {
var defaultText = process.argv.join(' ');
/* SSL_MAX_SID_CTX_LENGTH is 128 bits */
if (process.config.variables.openssl_fips) {
return crypto.createHash('sha1')
.update(defaultText)
.digest('hex').slice(0, 32);
} else {
return crypto.createHash('md5')
.update(defaultText)
.digest('hex');
}
}

function onhandshakestart() {
debug('onhandshakestart');
Expand Down Expand Up @@ -908,7 +893,10 @@ Server.prototype.setOptions = function(options) {
if (options.sessionIdContext) {
this.sessionIdContext = options.sessionIdContext;
} else {
this.sessionIdContext = defaultSessionIdContext;
this.sessionIdContext = crypto.createHash('sha1')
.update(process.argv.join(' '))
.digest('hex')
.slice(0, 32);
}
};

Expand Down

0 comments on commit df268f9

Please sign in to comment.