Skip to content

Commit e04ef62

Browse files
committed
test: skip weak crypto tests in FIPS mode
FIPS 140-2 does not permit the use of MD5 and RC4, skip tests that use them, or substitute with stronger crypto where applicable.
1 parent df9c4a6 commit e04ef62

8 files changed

+64
-46
lines changed

test/parallel/test-crypto-binary-default.js

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -324,11 +324,13 @@ var rfc2202_sha1 = [
324324
];
325325

326326
for (var i = 0, l = rfc2202_md5.length; i < l; i++) {
327-
assert.equal(rfc2202_md5[i]['hmac'],
328-
crypto.createHmac('md5', rfc2202_md5[i]['key'])
329-
.update(rfc2202_md5[i]['data'])
330-
.digest('hex'),
331-
'Test HMAC-MD5 : Test case ' + (i + 1) + ' rfc 2202');
327+
if (!common.hasFipsCrypto) {
328+
assert.equal(rfc2202_md5[i]['hmac'],
329+
crypto.createHmac('md5', rfc2202_md5[i]['key'])
330+
.update(rfc2202_md5[i]['data'])
331+
.digest('hex'),
332+
'Test HMAC-MD5 : Test case ' + (i + 1) + ' rfc 2202');
333+
}
332334
}
333335
for (var i = 0, l = rfc2202_sha1.length; i < l; i++) {
334336
assert.equal(rfc2202_sha1[i]['hmac'],
@@ -339,15 +341,19 @@ for (var i = 0, l = rfc2202_sha1.length; i < l; i++) {
339341
}
340342

341343
// Test hashing
342-
var a0 = crypto.createHash('sha1').update('Test123').digest('hex');
343-
var a1 = crypto.createHash('md5').update('Test123').digest('binary');
344+
var a1 = crypto.createHash('sha1').update('Test123').digest('hex');
344345
var a2 = crypto.createHash('sha256').update('Test123').digest('base64');
345346
var a3 = crypto.createHash('sha512').update('Test123').digest(); // binary
346347
var a4 = crypto.createHash('sha1').update('Test123').digest('buffer');
347348

348-
assert.equal(a0, '8308651804facb7b9af8ffc53a33a22d6a1c8ac2', 'Test SHA1');
349-
assert.equal(a1, 'h\u00ea\u00cb\u0097\u00d8o\fF!\u00fa+\u000e\u0017\u00ca' +
350-
'\u00bd\u008c', 'Test MD5 as binary');
349+
if (!common.hasFipsCrypto) {
350+
var a0 = crypto.createHash('md5').update('Test123').digest('binary');
351+
assert.equal(a1, 'h\u00ea\u00cb\u0097\u00d8o\fF!\u00fa+\u000e\u0017\u00ca' +
352+
'\u00bd\u008c', 'Test MD5 as binary');
353+
}
354+
355+
assert.equal(a1, '8308651804facb7b9af8ffc53a33a22d6a1c8ac2', 'Test SHA1');
356+
351357
assert.equal(a2, '2bX1jws4GYKTlxhloUB09Z66PoJZW+y+hq5R8dnx9l4=',
352358
'Test SHA256 as base64');
353359

test/parallel/test-crypto-hash.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ if (!common.hasCrypto) {
1111
var crypto = require('crypto');
1212

1313
// Test hashing
14-
var a0 = crypto.createHash('sha1').update('Test123').digest('hex');
15-
var a1 = crypto.createHash('md5').update('Test123').digest('binary');
14+
var a1 = crypto.createHash('sha1').update('Test123').digest('hex');
1615
var a2 = crypto.createHash('sha256').update('Test123').digest('base64');
1716
var a3 = crypto.createHash('sha512').update('Test123').digest(); // binary
1817
var a4 = crypto.createHash('sha1').update('Test123').digest('buffer');
@@ -38,9 +37,12 @@ a8.write('');
3837
a8.end();
3938
a8 = a8.read();
4039

41-
assert.equal(a0, '8308651804facb7b9af8ffc53a33a22d6a1c8ac2', 'Test SHA1');
42-
assert.equal(a1, 'h\u00ea\u00cb\u0097\u00d8o\fF!\u00fa+\u000e\u0017\u00ca' +
43-
'\u00bd\u008c', 'Test MD5 as binary');
40+
if (!common.hasFipsCrypto) {
41+
var a0 = crypto.createHash('md5').update('Test123').digest('binary');
42+
assert.equal(a0, 'h\u00ea\u00cb\u0097\u00d8o\fF!\u00fa+\u000e\u0017\u00ca' +
43+
'\u00bd\u008c', 'Test MD5 as binary');
44+
}
45+
assert.equal(a1, '8308651804facb7b9af8ffc53a33a22d6a1c8ac2', 'Test SHA1');
4446
assert.equal(a2, '2bX1jws4GYKTlxhloUB09Z66PoJZW+y+hq5R8dnx9l4=',
4547
'Test SHA256 as base64');
4648
assert.deepEqual(

test/parallel/test-crypto-hmac.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ var wikipedia = [
6161

6262
for (var i = 0, l = wikipedia.length; i < l; i++) {
6363
for (var hash in wikipedia[i]['hmac']) {
64+
// FIPS does not support MD5.
65+
if (common.hasFipsCrypto && hash == 'md5' )
66+
continue;
6467
var result = crypto.createHmac(hash, wikipedia[i]['key'])
6568
.update(wikipedia[i]['data'])
6669
.digest('hex');
@@ -346,12 +349,14 @@ var rfc2202_sha1 = [
346349
}
347350
];
348351

349-
for (var i = 0, l = rfc2202_md5.length; i < l; i++) {
350-
assert.equal(rfc2202_md5[i]['hmac'],
351-
crypto.createHmac('md5', rfc2202_md5[i]['key'])
352-
.update(rfc2202_md5[i]['data'])
353-
.digest('hex'),
354-
'Test HMAC-MD5 : Test case ' + (i + 1) + ' rfc 2202');
352+
if (!common.hasFipsCrypto) {
353+
for (var i = 0, l = rfc2202_md5.length; i < l; i++) {
354+
assert.equal(rfc2202_md5[i]['hmac'],
355+
crypto.createHmac('md5', rfc2202_md5[i]['key'])
356+
.update(rfc2202_md5[i]['data'])
357+
.digest('hex'),
358+
'Test HMAC-MD5 : Test case ' + (i + 1) + ' rfc 2202');
359+
}
355360
}
356361
for (var i = 0, l = rfc2202_sha1.length; i < l; i++) {
357362
assert.equal(rfc2202_sha1[i]['hmac'],

test/parallel/test-crypto-stream.js

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,21 @@ Stream2buffer.prototype._write = function(data, encodeing, done) {
2626
return done(null);
2727
};
2828

29-
// Create an md5 hash of "Hallo world"
30-
var hasher1 = crypto.createHash('md5');
31-
hasher1.pipe(new Stream2buffer(common.mustCall(function end(err, hash) {
32-
assert.equal(err, null);
33-
assert.equal(hash.toString('hex'), '06460dadb35d3d503047ce750ceb2d07');
34-
})));
35-
hasher1.end('Hallo world');
36-
37-
// Simpler check for unpipe, setEncoding, pause and resume
38-
crypto.createHash('md5').unpipe({});
39-
crypto.createHash('md5').setEncoding('utf8');
40-
crypto.createHash('md5').pause();
41-
crypto.createHash('md5').resume();
29+
if (!common.hasFipsCrypto) {
30+
// Create an md5 hash of "Hallo world"
31+
var hasher1 = crypto.createHash('md5');
32+
hasher1.pipe(new Stream2buffer(common.mustCall(function end(err, hash) {
33+
assert.equal(err, null);
34+
assert.equal(hash.toString('hex'), '06460dadb35d3d503047ce750ceb2d07');
35+
})));
36+
hasher1.end('Hallo world');
37+
38+
// Simpler check for unpipe, setEncoding, pause and resume
39+
crypto.createHash('md5').unpipe({});
40+
crypto.createHash('md5').setEncoding('utf8');
41+
crypto.createHash('md5').pause();
42+
crypto.createHash('md5').resume();
43+
}
4244

4345
// Decipher._flush() should emit an error event, not an exception.
4446
var key = new Buffer('48fb56eb10ffeb13fc0ef551bbca3b1b', 'hex'),

test/parallel/test-tls-ecdh.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ var fs = require('fs');
1414
var options = {
1515
key: fs.readFileSync(common.fixturesDir + '/keys/agent2-key.pem'),
1616
cert: fs.readFileSync(common.fixturesDir + '/keys/agent2-cert.pem'),
17-
ciphers: '-ALL:ECDHE-RSA-RC4-SHA',
17+
ciphers: '-ALL:ECDHE-RSA-AES128-SHA256',
1818
ecdhCurve: 'prime256v1'
1919
};
2020

test/parallel/test-tls-getcipher.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ if (!common.hasCrypto) {
99
var tls = require('tls');
1010

1111
var fs = require('fs');
12-
var cipher_list = ['RC4-SHA', 'AES256-SHA'];
12+
var cipher_list = ['AES128-SHA256', 'AES256-SHA256'];
1313
var cipher_version_pattern = /TLS|SSL/;
1414
var options = {
1515
key: fs.readFileSync(common.fixturesDir + '/keys/agent2-key.pem'),

test/parallel/test-tls-set-ciphers.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ var fs = require('fs');
1919
var options = {
2020
key: fs.readFileSync(common.fixturesDir + '/keys/agent2-key.pem'),
2121
cert: fs.readFileSync(common.fixturesDir + '/keys/agent2-cert.pem'),
22-
ciphers: 'RC4-MD5'
22+
ciphers: 'DES-CBC3-SHA'
2323
};
2424

2525
var reply = 'I AM THE WALRUS'; // something recognizable

test/pummel/test-crypto-dh.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,27 +20,30 @@ assert.throws(function() {
2020
});
2121

2222
var hashes = {
23-
modp1 : 'b4b330a6ffeacfbd861e7fe2135b4431',
24-
modp2 : '7c3c5cad8b9f378d88f1dd64a4b6413a',
25-
modp5 : 'b1d2acc22c542e08669a5c5ae812694d',
26-
modp14 : '8d041538cecc1a7d915ba4b718f8ad20',
27-
modp15 : 'dc3b93def24e078c4fbf92d5e14ba69b',
28-
modp16 : 'a273487f46f699461f613b3878d9dfd9',
29-
modp17 : 'dc76e09935310348c492de9bd82014d0',
30-
modp18 : 'db08973bfd2371758a69db180871c993'
23+
modp1 : '630e9acd2cc63f7e80d8507624ba60ac0757201a',
24+
modp2 : '18f7aa964484137f57bca64b21917a385b6a0b60',
25+
modp5 : 'c0a8eec0c2c8a5ec2f9c26f9661eb339a010ec61',
26+
modp14 : 'af5455606fe74cec49782bb374e4c63c9b1d132c',
27+
modp15 : '7bdd39e5cdbb9748113933e5c2623b559c534e74',
28+
modp16 : 'daea5277a7ad0116e734a8e0d2f297ef759d1161',
29+
modp17 : '3b62aaf0142c2720f0bf26a9589b0432c00eadc1',
30+
modp18 : 'a870b491bbbec9b131ae9878d07449d32e54f160'
3131
};
3232

3333
for (var name in hashes) {
3434
var group = crypto.getDiffieHellman(name);
3535
var private_key = group.getPrime('hex');
3636
var hash1 = hashes[name];
37-
var hash2 = crypto.createHash('md5')
37+
var hash2 = crypto.createHash('sha1')
3838
.update(private_key.toUpperCase()).digest('hex');
3939
assert.equal(hash1, hash2);
4040
assert.equal(group.getGenerator('hex'), '02');
4141
}
4242

4343
for (var name in hashes) {
44+
// modp1 is 768 bits, FIPS requires >= 1024
45+
if (name == 'modp1' && common.hasFipsCrypto)
46+
continue;
4447
var group1 = crypto.getDiffieHellman(name);
4548
var group2 = crypto.getDiffieHellman(name);
4649
group1.generateKeys();

0 commit comments

Comments
 (0)