Skip to content

Commit cc835ad

Browse files
committed
tls: test honor cipher order with TLS1.2
Modified tests to work in FIPS and non-FIPS mode using TLS1.2 crypto.
1 parent e04ef62 commit cc835ad

File tree

2 files changed

+26
-21
lines changed

2 files changed

+26
-21
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ var a4 = crypto.createHash('sha1').update('Test123').digest('buffer');
348348

349349
if (!common.hasFipsCrypto) {
350350
var a0 = crypto.createHash('md5').update('Test123').digest('binary');
351-
assert.equal(a1, 'h\u00ea\u00cb\u0097\u00d8o\fF!\u00fa+\u000e\u0017\u00ca' +
351+
assert.equal(a0, 'h\u00ea\u00cb\u0097\u00d8o\fF!\u00fa+\u000e\u0017\u00ca' +
352352
'\u00bd\u008c', 'Test MD5 as binary');
353353
}
354354

test/sequential/test-tls-honorcipherorder.js

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ var tls = require('tls');
1010

1111
var fs = require('fs');
1212
var nconns = 0;
13-
// test only in TLSv1 to use DES which is no longer supported TLSv1.2
14-
// to be safe when the default method is updated in the future
15-
var SSL_Method = 'TLSv1_method';
13+
14+
// We explicitly set TLS version to 1.2 so as to be safe when the
15+
// default method is updated in the future
16+
var SSL_Method = 'TLSv1_2_method';
1617
var localhost = '127.0.0.1';
1718

1819
process.on('exit', function() {
@@ -24,7 +25,8 @@ function test(honorCipherOrder, clientCipher, expectedCipher, cb) {
2425
secureProtocol: SSL_Method,
2526
key: fs.readFileSync(common.fixturesDir + '/keys/agent2-key.pem'),
2627
cert: fs.readFileSync(common.fixturesDir + '/keys/agent2-cert.pem'),
27-
ciphers: 'DES-CBC-SHA:AES256-SHA:RC4-SHA:ECDHE-RSA-AES256-SHA',
28+
ciphers: 'AES256-SHA256:AES128-GCM-SHA256:AES128-SHA256:' +
29+
'ECDHE-RSA-AES128-GCM-SHA256',
2830
honorCipherOrder: !!honorCipherOrder
2931
};
3032

@@ -57,37 +59,40 @@ test1();
5759

5860
function test1() {
5961
// Client has the preference of cipher suites by default
60-
test(false, 'AES256-SHA:DES-CBC-SHA:RC4-SHA', 'AES256-SHA', test2);
62+
test(false, 'AES128-GCM-SHA256:AES256-SHA256:AES128-SHA256',
63+
'AES128-GCM-SHA256', test2);
6164
}
6265

6366
function test2() {
64-
// Server has the preference of cipher suites where DES-CBC-SHA is in
65-
// the first.
66-
test(true, 'AES256-SHA:DES-CBC-SHA:RC4-SHA', 'DES-CBC-SHA', test3);
67+
// Server has the preference of cipher suites, and AES256-SHA256 is
68+
// the server's top choice.
69+
test(true, 'AES128-GCM-SHA256:AES256-SHA256:AES128-SHA256',
70+
'AES256-SHA256', test3);
6771
}
6872

6973
function test3() {
70-
// Server has the preference of cipher suites. RC4-SHA is given
71-
// higher priority over DES-CBC-SHA among client cipher suites.
72-
test(true, 'RC4-SHA:AES256-SHA', 'AES256-SHA', test4);
74+
// Server has the preference of cipher suites. AES128-GCM-SHA256 is given
75+
// higher priority over AES128-SHA256 among client cipher suites.
76+
test(true, 'AES128-SHA256:AES128-GCM-SHA256', 'AES128-GCM-SHA256', test4);
77+
7378
}
7479

7580
function test4() {
76-
// As client has only one cipher, server has no choice in regardless
81+
// As client has only one cipher, server has no choice, irrespective
7782
// of honorCipherOrder.
78-
test(true, 'RC4-SHA', 'RC4-SHA', test5);
83+
test(true, 'AES128-SHA256', 'AES128-SHA256', test5);
7984
}
8085

8186
function test5() {
82-
// Client did not explicitly set ciphers. Ensure that client defaults to
83-
// sane ciphers. Even though server gives top priority to DES-CBC-SHA
84-
// it should not be negotiated because it's not in default client ciphers.
85-
test(true, null, 'AES256-SHA', test6);
87+
// Client did not explicitly set ciphers and client offers
88+
// tls.DEFAULT_CIPHERS. All ciphers of the server are included in the
89+
// default list so the negotiated cipher is selected according to the
90+
// server's top preference of AES256-SHA256.
91+
test(true, null, 'AES256-SHA256', test6);
8692
}
8793

8894
function test6() {
8995
// Ensure that `tls.DEFAULT_CIPHERS` is used
90-
SSL_Method = 'TLSv1_2_method';
91-
tls.DEFAULT_CIPHERS = 'ECDHE-RSA-AES256-SHA';
92-
test(true, null, 'ECDHE-RSA-AES256-SHA');
96+
tls.DEFAULT_CIPHERS = 'ECDHE-RSA-AES128-GCM-SHA256';
97+
test(true, null, 'ECDHE-RSA-AES128-GCM-SHA256');
9398
}

0 commit comments

Comments
 (0)