Skip to content

Commit 03fefb2

Browse files
AdamMajertargos
authored andcommitted
crypto: don't disable TLS 1.3 without suites
In the manual page, there is a statement that ciphersuites contain explicit default settings - all TLS 1.3 ciphersuites enabled. In node, we assume that an empty setting mean no ciphersuites and we disable TLS 1.3. A correct approach to disabling TLS 1.3 is to disable TLS 1.3 and by not override the default ciphersuits with an empty string. So, only override OpenSSL's TLS 1.3 ciphersuites with an explicit list of ciphers. If none are acceptable, the correct approach is to disable TLS 1.3 instead elsewhere. Fixes: #43419 PR-URL: #43427 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Paolo Insogna <paolo@cowtech.it> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 8d2389a commit 03fefb2

15 files changed

+54
-23
lines changed

benchmark/tls/secure-pair.js

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ function main({ dur, size, securing }) {
2525
isServer: true,
2626
requestCert: true,
2727
rejectUnauthorized: true,
28+
maxVersion: 'TLSv1.2',
2829
};
2930

3031
const server = net.createServer(onRedirectConnection);
@@ -38,6 +39,7 @@ function main({ dur, size, securing }) {
3839
cert: options.cert,
3940
isServer: false,
4041
rejectUnauthorized: false,
42+
maxVersion: options.maxVersion,
4143
};
4244
const network = securing === 'clear' ? net : tls;
4345
const conn = network.connect(clientOptions, () => {

benchmark/tls/throughput-c2s.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ function main({ dur, type, size }) {
3333
key: fixtures.readKey('rsa_private.pem'),
3434
cert: fixtures.readKey('rsa_cert.crt'),
3535
ca: fixtures.readKey('rsa_ca.crt'),
36-
ciphers: 'AES256-GCM-SHA384'
36+
ciphers: 'AES256-GCM-SHA384',
37+
maxVersion: 'TLSv1.2',
3738
};
3839

3940
const server = tls.createServer(options, onConnection);

benchmark/tls/throughput-s2c.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ function main({ dur, type, sendchunklen, recvbuflen, recvbufgenfn }) {
4040
key: fixtures.readKey('rsa_private.pem'),
4141
cert: fixtures.readKey('rsa_cert.crt'),
4242
ca: fixtures.readKey('rsa_ca.crt'),
43-
ciphers: 'AES256-GCM-SHA384'
43+
ciphers: 'AES256-GCM-SHA384',
44+
maxVersion: 'TLSv1.2',
4445
};
4546

4647
let socketOpts;

benchmark/tls/tls-connect.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ function main(conf) {
2121
key: fixtures.readKey('rsa_private.pem'),
2222
cert: fixtures.readKey('rsa_cert.crt'),
2323
ca: fixtures.readKey('rsa_ca.crt'),
24-
ciphers: 'AES256-GCM-SHA384'
24+
ciphers: 'AES256-GCM-SHA384',
25+
maxVersion: 'TLSv1.2',
2526
};
2627

2728
const server = tls.createServer(options, onConnection);

lib/internal/tls/secure-context.js

+2-7
Original file line numberDiff line numberDiff line change
@@ -225,15 +225,10 @@ function configSecureContext(context, options = kEmptyObject, name = 'options')
225225
cipherSuites,
226226
} = processCiphers(ciphers, `${name}.ciphers`);
227227

228-
context.setCipherSuites(cipherSuites);
228+
if (cipherSuites !== '')
229+
context.setCipherSuites(cipherSuites);
229230
context.setCiphers(cipherList);
230231

231-
if (cipherSuites === '' &&
232-
context.getMaxProto() > TLS1_2_VERSION &&
233-
context.getMinProto() < TLS1_3_VERSION) {
234-
context.setMaxProto(TLS1_2_VERSION);
235-
}
236-
237232
if (cipherList === '' &&
238233
context.getMinProto() < TLS1_3_VERSION &&
239234
context.getMaxProto() > TLS1_2_VERSION) {

test/parallel/test-tls-client-getephemeralkeyinfo.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ function test(size, type, name, cipher) {
2323
const options = {
2424
key: key,
2525
cert: cert,
26-
ciphers: cipher
26+
ciphers: cipher,
27+
maxVersion: 'TLSv1.2',
2728
};
2829

2930
if (name) options.ecdhCurve = name;

test/parallel/test-tls-client-mindhsize.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ function test(size, err, next) {
4141
const client = tls.connect({
4242
minDHSize: 2048,
4343
port: this.address().port,
44-
rejectUnauthorized: false
44+
rejectUnauthorized: false,
45+
maxVersion: 'TLSv1.2',
4546
}, function() {
4647
nsuccess++;
4748
server.close();

test/parallel/test-tls-dhe.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ function test(keylen, expectedCipher, cb) {
5353
key: key,
5454
cert: cert,
5555
ciphers: ciphers,
56-
dhparam: loadDHParam(keylen)
56+
dhparam: loadDHParam(keylen),
57+
maxVersion: 'TLSv1.2',
5758
};
5859

5960
const server = tls.createServer(options, function(conn) {

test/parallel/test-tls-ecdh-auto.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ const options = {
2323
key: loadPEM('agent2-key'),
2424
cert: loadPEM('agent2-cert'),
2525
ciphers: '-ALL:ECDHE-RSA-AES128-SHA256',
26-
ecdhCurve: 'auto'
26+
ecdhCurve: 'auto',
27+
maxVersion: 'TLSv1.2',
2728
};
2829

2930
const reply = 'I AM THE WALRUS'; // Something recognizable

test/parallel/test-tls-ecdh-multiple.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ const options = {
2323
key: loadPEM('agent2-key'),
2424
cert: loadPEM('agent2-cert'),
2525
ciphers: '-ALL:ECDHE-RSA-AES128-SHA256',
26-
ecdhCurve: 'secp256k1:prime256v1:secp521r1'
26+
ecdhCurve: 'secp256k1:prime256v1:secp521r1',
27+
maxVersion: 'TLSv1.2',
2728
};
2829

2930
const reply = 'I AM THE WALRUS'; // Something recognizable

test/parallel/test-tls-ecdh.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ const options = {
3838
key: fixtures.readKey('agent2-key.pem'),
3939
cert: fixtures.readKey('agent2-cert.pem'),
4040
ciphers: '-ALL:ECDHE-RSA-AES128-SHA256',
41-
ecdhCurve: 'prime256v1'
41+
ecdhCurve: 'prime256v1',
42+
maxVersion: 'TLSv1.2'
4243
};
4344

4445
const reply = 'I AM THE WALRUS'; // Something recognizable

test/parallel/test-tls-getcipher.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ server.listen(0, '127.0.0.1', common.mustCall(function() {
4848
host: '127.0.0.1',
4949
port: this.address().port,
5050
ciphers: 'AES128-SHA256',
51-
rejectUnauthorized: false
51+
rejectUnauthorized: false,
52+
maxVersion: 'TLSv1.2',
5253
}, common.mustCall(function() {
5354
const cipher = this.getCipher();
5455
assert.strictEqual(cipher.name, 'AES128-SHA256');
@@ -62,7 +63,8 @@ server.listen(0, '127.0.0.1', common.mustCall(function() {
6263
host: '127.0.0.1',
6364
port: this.address().port,
6465
ciphers: 'ECDHE-RSA-AES128-GCM-SHA256',
65-
rejectUnauthorized: false
66+
rejectUnauthorized: false,
67+
maxVersion: 'TLSv1.2',
6668
}, common.mustCall(function() {
6769
const cipher = this.getCipher();
6870
assert.strictEqual(cipher.name, 'ECDHE-RSA-AES128-GCM-SHA256');

test/parallel/test-tls-multi-key.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,12 @@ function test(options) {
154154
rejectUnauthorized: true,
155155
ca: clientTrustRoots,
156156
checkServerIdentity: (_, c) => assert.strictEqual(c.subject.CN, eccCN),
157+
maxVersion: 'TLSv1.2'
157158
}, common.mustCall(function() {
158159
assert.deepStrictEqual(ecdsa.getCipher(), {
159160
name: 'ECDHE-ECDSA-AES256-GCM-SHA384',
160161
standardName: 'TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384',
161-
version: 'TLSv1.2'
162+
version: 'TLSv1.2',
162163
});
163164
assert.strictEqual(ecdsa.getPeerCertificate().subject.CN, eccCN);
164165
assert.strictEqual(ecdsa.getPeerCertificate().asn1Curve, 'prime256v1');
@@ -173,11 +174,12 @@ function test(options) {
173174
rejectUnauthorized: true,
174175
ca: clientTrustRoots,
175176
checkServerIdentity: (_, c) => assert.strictEqual(c.subject.CN, rsaCN),
177+
maxVersion: 'TLSv1.2',
176178
}, common.mustCall(function() {
177179
assert.deepStrictEqual(rsa.getCipher(), {
178180
name: 'ECDHE-RSA-AES256-GCM-SHA384',
179181
standardName: 'TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384',
180-
version: 'TLSv1.2'
182+
version: 'TLSv1.2',
181183
});
182184
assert.strictEqual(rsa.getPeerCertificate().subject.CN, rsaCN);
183185
assert(rsa.getPeerCertificate().exponent, 'cert for an RSA key');

test/parallel/test-tls-multi-pfx.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,14 @@ const server = tls.createServer(options, function(conn) {
2424
}).listen(0, function() {
2525
const ecdsa = tls.connect(this.address().port, {
2626
ciphers: 'ECDHE-ECDSA-AES256-GCM-SHA384',
27-
rejectUnauthorized: false
27+
maxVersion: 'TLSv1.2',
28+
rejectUnauthorized: false,
2829
}, common.mustCall(function() {
2930
ciphers.push(ecdsa.getCipher());
3031
const rsa = tls.connect(server.address().port, {
3132
ciphers: 'ECDHE-RSA-AES256-GCM-SHA384',
32-
rejectUnauthorized: false
33+
maxVersion: 'TLSv1.2',
34+
rejectUnauthorized: false,
3335
}, common.mustCall(function() {
3436
ciphers.push(rsa.getCipher());
3537
ecdsa.end();

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

+20-1
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,31 @@ const {
1313
} = require(fixtures.path('tls-connect'));
1414

1515

16-
function test(cciphers, sciphers, cipher, cerr, serr) {
16+
function test(cciphers, sciphers, cipher, cerr, serr, options) {
1717
assert(cipher || cerr || serr, 'test missing any expectations');
1818
const where = inspect(new Error()).split('\n')[2].replace(/[^(]*/, '');
19+
20+
const max_tls_ver = (ciphers, options) => {
21+
if (options instanceof Object && Object.hasOwn(options, 'maxVersion'))
22+
return options.maxVersion;
23+
if ((typeof ciphers === 'string' || ciphers instanceof String) && ciphers.length > 0 && !ciphers.includes('TLS_'))
24+
return 'TLSv1.2';
25+
26+
return 'TLSv1.3';
27+
};
28+
1929
connect({
2030
client: {
2131
checkServerIdentity: (servername, cert) => { },
2232
ca: `${keys.agent1.cert}\n${keys.agent6.ca}`,
2333
ciphers: cciphers,
34+
maxVersion: max_tls_ver(cciphers, options),
2435
},
2536
server: {
2637
cert: keys.agent6.cert,
2738
key: keys.agent6.key,
2839
ciphers: sciphers,
40+
maxVersion: max_tls_ver(sciphers, options),
2941
},
3042
}, common.mustCall((err, pair, cleanup) => {
3143
function u(_) { return _ === undefined ? 'U' : _; }
@@ -87,6 +99,13 @@ test('AES128-SHA:TLS_AES_256_GCM_SHA384',
8799
test('AES256-SHA:TLS_AES_256_GCM_SHA384', U, 'TLS_AES_256_GCM_SHA384');
88100
test(U, 'AES256-SHA:TLS_AES_256_GCM_SHA384', 'TLS_AES_256_GCM_SHA384');
89101

102+
// Cipher order ignored, TLS1.3 before TLS1.2 and
103+
// cipher suites are not disabled if TLS ciphers are set only
104+
// TODO: maybe these tests should be reworked so maxVersion clamping
105+
// is done explicitly and not implicitly in the test() function
106+
test('AES256-SHA', U, 'TLS_AES_256_GCM_SHA384', U, U, { maxVersion: 'TLSv1.3' });
107+
test(U, 'AES256-SHA', 'TLS_AES_256_GCM_SHA384', U, U, { maxVersion: 'TLSv1.3' });
108+
90109
// TLS_AES_128_CCM_8_SHA256 & TLS_AES_128_CCM_SHA256 are not enabled by
91110
// default, but work.
92111
test('TLS_AES_128_CCM_8_SHA256', U,

0 commit comments

Comments
 (0)