2017-09-05 01:49:28 +07:00
|
|
|
'use strict';
|
|
|
|
const common = require('../common');
|
|
|
|
|
|
|
|
// This test ensures that ecdhCurve option of TLS server supports colon
|
|
|
|
// separated ECDH curve names as value.
|
|
|
|
|
2025-01-24 16:58:32 -08:00
|
|
|
if (!common.hasCrypto) {
|
2017-09-05 01:49:28 +07:00
|
|
|
common.skip('missing crypto');
|
2025-01-24 16:58:32 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
const { opensslCli } = require('../common/crypto');
|
|
|
|
const crypto = require('crypto');
|
2017-09-05 01:49:28 +07:00
|
|
|
|
2025-01-24 16:58:32 -08:00
|
|
|
if (!opensslCli) {
|
2017-09-05 01:49:28 +07:00
|
|
|
common.skip('missing openssl-cli');
|
2025-01-24 16:58:32 -08:00
|
|
|
}
|
2017-09-05 01:49:28 +07:00
|
|
|
|
|
|
|
const assert = require('assert');
|
|
|
|
const tls = require('tls');
|
2023-03-05 18:36:55 +00:00
|
|
|
const { execFile } = require('child_process');
|
2017-09-05 01:49:28 +07:00
|
|
|
const fixtures = require('../common/fixtures');
|
|
|
|
|
|
|
|
function loadPEM(n) {
|
|
|
|
return fixtures.readKey(`${n}.pem`);
|
|
|
|
}
|
|
|
|
|
|
|
|
const options = {
|
|
|
|
key: loadPEM('agent2-key'),
|
|
|
|
cert: loadPEM('agent2-cert'),
|
|
|
|
ciphers: '-ALL:ECDHE-RSA-AES128-SHA256',
|
2022-06-27 10:47:13 +02:00
|
|
|
ecdhCurve: 'secp256k1:prime256v1:secp521r1',
|
|
|
|
maxVersion: 'TLSv1.2',
|
2017-09-05 01:49:28 +07:00
|
|
|
};
|
|
|
|
|
2019-03-22 03:44:26 +01:00
|
|
|
const reply = 'I AM THE WALRUS'; // Something recognizable
|
2017-09-05 01:49:28 +07:00
|
|
|
|
2023-03-05 18:36:55 +00:00
|
|
|
const server = tls.createServer(options, (conn) => {
|
2017-09-05 01:49:28 +07:00
|
|
|
conn.end(reply);
|
2023-03-05 18:36:55 +00:00
|
|
|
}).listen(0, common.mustCall(() => {
|
2017-09-05 01:49:28 +07:00
|
|
|
const args = ['s_client',
|
|
|
|
'-cipher', `${options.ciphers}`,
|
2023-03-05 18:36:55 +00:00
|
|
|
'-connect', `127.0.0.1:${server.address().port}`];
|
2017-09-05 01:49:28 +07:00
|
|
|
|
2025-01-24 16:58:32 -08:00
|
|
|
execFile(opensslCli, args, common.mustSucceed((stdout) => {
|
2023-03-05 18:36:55 +00:00
|
|
|
assert(stdout.includes(reply));
|
2017-09-05 01:49:28 +07:00
|
|
|
server.close();
|
2023-03-05 18:36:55 +00:00
|
|
|
}));
|
|
|
|
}));
|
2017-09-05 01:49:28 +07:00
|
|
|
|
2023-03-05 18:36:55 +00:00
|
|
|
{
|
|
|
|
// Some unsupported curves.
|
2017-09-05 01:49:28 +07:00
|
|
|
const unsupportedCurves = [
|
|
|
|
'wap-wsg-idm-ecid-wtls1',
|
|
|
|
'c2pnb163v1',
|
2021-03-26 08:51:08 -07:00
|
|
|
'prime192v3',
|
2017-09-05 01:49:28 +07:00
|
|
|
];
|
|
|
|
|
2023-03-05 18:36:55 +00:00
|
|
|
// Brainpool is not supported in FIPS mode.
|
2025-01-24 16:58:32 -08:00
|
|
|
if (crypto.getFips()) {
|
2017-09-05 01:49:28 +07:00
|
|
|
unsupportedCurves.push('brainpoolP256r1');
|
2025-01-24 16:58:32 -08:00
|
|
|
}
|
2017-09-05 01:49:28 +07:00
|
|
|
|
|
|
|
unsupportedCurves.forEach((ecdhCurve) => {
|
2018-01-11 19:03:58 +01:00
|
|
|
assert.throws(() => tls.createServer({ ecdhCurve }),
|
2017-09-05 01:49:28 +07:00
|
|
|
/Error: Failed to set ECDH curve/);
|
|
|
|
});
|
2023-03-05 18:36:55 +00:00
|
|
|
}
|