16 lines
1.5 KiB
JavaScript
16 lines
1.5 KiB
JavaScript
// tls-sonda.mjs <gazda> <port> <grupuri> [maxVersion]: o strangere de mana TLS reala cu grupurile de schimb de cheie date (de ex.
|
|
// X25519MLKEM768 singur, X25519 singur) si, optional, cu versiunea maxima (TLSv1.2 = un client care nu stie TLS 1.3). Fara verificarea
|
|
// certificatului (al probei e autosemnat). JSON pe stdout; iesire 0 = handshake reusit, 1 = refuzat.
|
|
import tls from 'node:tls';
|
|
const [gazda, port, grupuri, maxV] = process.argv.slice(2);
|
|
const t0 = Date.now();
|
|
const opt = { host: gazda, port: Number(port), servername: 'proba.local', rejectUnauthorized: false, ecdhCurve: grupuri, ALPNProtocols: ['http/1.1'] };
|
|
if (maxV) { opt.maxVersion = maxV; opt.minVersion = maxV; } else { opt.minVersion = 'TLSv1.3'; opt.maxVersion = 'TLSv1.3'; }
|
|
const s = tls.connect(opt, () => {
|
|
const ek = s.getEphemeralKeyInfo();
|
|
console.log(JSON.stringify({ ok: true, grupuriOferite: grupuri, versiuneCeruta: maxV || 'TLSv1.3', protocol: s.getProtocol(), cifru: s.getCipher().name, grupRaportat: ek && ek.name, ms: Date.now() - t0, openssl: process.versions.openssl }));
|
|
s.end(); process.exitCode = 0;
|
|
});
|
|
s.setTimeout(8000, () => { console.log(JSON.stringify({ ok: false, grupuriOferite: grupuri, versiuneCeruta: maxV || 'TLSv1.3', motiv: 'timeout' })); s.destroy(); process.exitCode = 1; });
|
|
s.on('error', (e) => { console.log(JSON.stringify({ ok: false, grupuriOferite: grupuri, versiuneCeruta: maxV || 'TLSv1.3', motiv: e.code || e.message, ms: Date.now() - t0, openssl: process.versions.openssl })); process.exitCode = 1; });
|