mirror of
https://github.com/nodejs/node.git
synced 2026-10-28 10:15:07 +08:00
Signed-off-by: Antoine du Hamel <duhamelantoine1995@gmail.com> PR-URL: https://github.com/nodejs/node/pull/64716 Reviewed-By: Ethan Arrowood <ethan@arrowood.dev> Reviewed-By: Aviv Keller <me@aviv.sh>
83 lines
2.4 KiB
JavaScript
83 lines
2.4 KiB
JavaScript
// Flags: --experimental-quic --no-warnings
|
|
|
|
// Test: custom TLS ciphers and groups.
|
|
// Custom ciphers option on the server/client.
|
|
// Custom groups option on the server/client.
|
|
// Default ciphers/groups used when not specified.
|
|
|
|
import { hasQuic, skip, mustCall } from '../common/index.mjs';
|
|
import assert from 'node:assert';
|
|
import * as fixtures from '../common/fixtures.mjs';
|
|
|
|
if (!hasQuic) {
|
|
skip('QUIC is not enabled');
|
|
}
|
|
|
|
const { listen, connect, constants } = await import('node:quic');
|
|
const { createPrivateKey } = await import('node:crypto');
|
|
|
|
const key = createPrivateKey(fixtures.readKey('agent1-key.pem'));
|
|
const cert = fixtures.readKey('agent1-cert.pem');
|
|
|
|
// Custom ciphers. Use a specific TLS 1.3 cipher suite.
|
|
{
|
|
const serverEndpoint = await listen(mustCall(async (serverSession) => {
|
|
const info = await serverSession.opened;
|
|
assert.strictEqual(typeof info.cipher, 'string');
|
|
assert.ok(info.cipher.includes('AES_256_GCM'));
|
|
serverSession.close();
|
|
}), {
|
|
sni: { '*': { keys: [key], certs: [cert] } },
|
|
alpn: ['quic-test'],
|
|
ciphers: 'TLS_AES_256_GCM_SHA384',
|
|
});
|
|
|
|
const clientSession = await connect(serverEndpoint.address, {
|
|
alpn: 'quic-test',
|
|
verifyPeer: 'manual',
|
|
servername: 'localhost',
|
|
ciphers: 'TLS_AES_256_GCM_SHA384',
|
|
});
|
|
|
|
const info = await clientSession.opened;
|
|
assert.ok(info.cipher.includes('AES_256_GCM'));
|
|
assert.strictEqual(info.cipherVersion, 'TLSv1.3');
|
|
|
|
await clientSession.closed;
|
|
await serverEndpoint.close();
|
|
}
|
|
|
|
// Custom groups. Use a specific key exchange group.
|
|
{
|
|
const serverEndpoint = await listen(mustCall(async (serverSession) => {
|
|
await serverSession.opened;
|
|
serverSession.close();
|
|
}), {
|
|
sni: { '*': { keys: [key], certs: [cert] } },
|
|
alpn: ['quic-test'],
|
|
groups: 'P-256',
|
|
});
|
|
|
|
const clientSession = await connect(serverEndpoint.address, {
|
|
alpn: 'quic-test',
|
|
verifyPeer: 'manual',
|
|
servername: 'localhost',
|
|
groups: 'P-256',
|
|
});
|
|
|
|
const info = await clientSession.opened;
|
|
// The handshake should succeed with the specified group.
|
|
assert.strictEqual(info.cipherVersion, 'TLSv1.3');
|
|
|
|
await clientSession.closed;
|
|
await serverEndpoint.close();
|
|
}
|
|
|
|
// Default ciphers/groups are non-empty strings from constants.
|
|
{
|
|
assert.strictEqual(typeof constants.DEFAULT_CIPHERS, 'string');
|
|
assert.ok(constants.DEFAULT_CIPHERS.length > 0);
|
|
assert.strictEqual(typeof constants.DEFAULT_GROUPS, 'string');
|
|
assert.ok(constants.DEFAULT_GROUPS.length > 0);
|
|
}
|