Files
node/test/parallel/test-dtls-srtp.mjs
Matteo Collina a46087d7e8 test: fix lint in dtls tests
a7d16a8cc6 introduced destructured uses of assert and fixtures, which
the test lint rules forbid, plus bare strictEqual/throws calls that
were never imported and threw ReferenceError at runtime. Use the
assert and fixtures namespaces directly.

Signed-off-by: Matteo Collina <hello@matteocollina.com>
PR-URL: https://github.com/nodejs/node/pull/64902
Reviewed-By: Mike McCready <66998419+MikeMcC399@users.noreply.github.com>
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2026-08-01 14:48:00 +02:00

76 lines
2.2 KiB
JavaScript

// Flags: --experimental-dtls --no-warnings
// Test: SRTP profile negotiation and keying-material export (DTLS-SRTP). Both
// peers must negotiate the same SRTP profile and derive identical keying
// material from exportKeyingMaterial.
import { hasCrypto, skip, mustCall } from '../common/index.mjs';
import assert from 'node:assert';
import * as fixtures from '../common/fixtures.mjs';
if (!hasCrypto) {
skip('missing crypto');
}
if (!process.features.dtls) {
skip('DTLS is not enabled');
}
const { listen, connect } = await import('node:dtls');
const cert = fixtures.readKey('agent1-cert.pem').toString();
const key = fixtures.readKey('agent1-key.pem').toString();
const ca = fixtures.readKey('ca1-cert.pem').toString();
const SRTP_PROFILE = 'SRTP_AEAD_AES_128_GCM';
const gotServerSession = Promise.withResolvers();
const server = listen(mustCall((session) => {
gotServerSession.resolve(session);
}), {
cert,
key,
port: 0,
host: '127.0.0.1',
srtp: SRTP_PROFILE,
});
const client = connect('127.0.0.1', server.address.port, {
ca: [ca],
rejectUnauthorized: false,
srtp: SRTP_PROFILE,
});
await client.opened;
const serverSession = await gotServerSession.promise;
await serverSession.opened;
// Both peers negotiate the same SRTP profile.
assert.strictEqual(client.srtpProfile, SRTP_PROFILE);
assert.strictEqual(serverSession.srtpProfile, SRTP_PROFILE);
// Both peers derive identical keying material for the same label and length.
const label = 'EXTRACTOR-dtls_srtp';
const clientKM = client.exportKeyingMaterial(60, label);
const serverKM = serverSession.exportKeyingMaterial(60, label);
assert.strictEqual(clientKM.length, 60);
assert.deepStrictEqual(clientKM, serverKM);
// The optional context is bound into the derivation: the same context yields
// the same material on both peers, and a different context yields different
// material.
const contextA = Buffer.from('context-a');
const contextB = Buffer.from('context-b');
assert.deepStrictEqual(
client.exportKeyingMaterial(32, label, contextA),
serverSession.exportKeyingMaterial(32, label, contextA),
);
assert.notDeepStrictEqual(
client.exportKeyingMaterial(32, label, contextA),
client.exportKeyingMaterial(32, label, contextB),
);
await client.close();
await server.close();