|
| 1 | +'use strict'; |
| 2 | +const common = require('../common'); |
| 3 | +if (!common.hasCrypto) |
| 4 | + common.skip('missing crypto'); |
| 5 | + |
| 6 | +// Test that --tls-groups sets tls.DEFAULT_ECDH_CURVE. |
| 7 | + |
| 8 | +const { spawnSyncAndAssert } = require('../common/child_process'); |
| 9 | +const fixtures = require('../common/fixtures'); |
| 10 | + |
| 11 | +spawnSyncAndAssert(process.execPath, ['-p', 'tls.DEFAULT_ECDH_CURVE'], { |
| 12 | + stdout: 'auto', |
| 13 | + trim: true, |
| 14 | +}); |
| 15 | + |
| 16 | +spawnSyncAndAssert(process.execPath, |
| 17 | + ['--tls-groups=P-384:P-256', '-p', 'tls.DEFAULT_ECDH_CURVE'], |
| 18 | + { stdout: 'P-384:P-256', trim: true }); |
| 19 | + |
| 20 | +spawnSyncAndAssert(process.execPath, ['-p', 'tls.DEFAULT_ECDH_CURVE'], { |
| 21 | + env: { ...process.env, NODE_OPTIONS: '--tls-groups=P-384' }, |
| 22 | +}, { stdout: 'P-384', trim: true }); |
| 23 | + |
| 24 | +// The option applies to servers and clients that do not set ecdhCurve. |
| 25 | +const script = ` |
| 26 | + const tls = require('tls'); |
| 27 | + const server = tls.createServer({ |
| 28 | + key: ${JSON.stringify(fixtures.readKey('agent2-key.pem', 'utf8'))}, |
| 29 | + cert: ${JSON.stringify(fixtures.readKey('agent2-cert.pem', 'utf8'))}, |
| 30 | + }, (conn) => conn.end()); |
| 31 | + server.listen(0, () => { |
| 32 | + const client = tls.connect({ |
| 33 | + port: server.address().port, |
| 34 | + rejectUnauthorized: false, |
| 35 | + }, () => { |
| 36 | + console.log(client.getEphemeralKeyInfo().name); |
| 37 | + client.end(); |
| 38 | + server.close(); |
| 39 | + }); |
| 40 | + }); |
| 41 | +`; |
| 42 | +spawnSyncAndAssert(process.execPath, ['--tls-groups=P-384', '-e', script], { |
| 43 | + stdout: 'secp384r1', |
| 44 | + trim: true, |
| 45 | +}); |
0 commit comments