33 lines
1.2 KiB
JavaScript
33 lines
1.2 KiB
JavaScript
// check_cert_match.js
|
|
const fs = require('fs');
|
|
const crypto = require('crypto');
|
|
|
|
function pemToDer(pem) {
|
|
return Buffer.from(
|
|
pem.replace(/-----BEGIN CERTIFICATE-----/g, '')
|
|
.replace(/-----END CERTIFICATE-----/g, '')
|
|
.replace(/\s+/g, ''),
|
|
'base64'
|
|
);
|
|
}
|
|
|
|
function sha1Fingerprint(der) {
|
|
return crypto.createHash('sha1').update(der).digest('hex').toUpperCase().match(/.{2}/g).join(':');
|
|
}
|
|
|
|
// 1) Cert PEM que usa FourJs (el mismo con el que te funciona): p.ej. .\cert\marmotech\onlyCert.pem
|
|
const certPemFour = fs.readFileSync('.\\onlyCert.pem', 'utf8');
|
|
const fpFour = sha1Fingerprint(pemToDer(certPemFour));
|
|
console.log('Fingerprint PEM:', fpFour);
|
|
|
|
// 2) Extraer el cert del XML de FourJs (Signature.xml)
|
|
const xml = fs.readFileSync('.\\Signature.xml', 'utf8');
|
|
const m = xml.match(/<X509Certificate>([\s\S]*?)<\/X509Certificate>/i);
|
|
if (!m) throw new Error('No se encontró <X509Certificate> en Signature.xml');
|
|
const certFromXmlDer = Buffer.from(m[1].replace(/\s+/g, ''), 'base64');
|
|
const fpXml = sha1Fingerprint(certFromXmlDer);
|
|
console.log('Fingerprint en Signature.xml:', fpXml);
|
|
|
|
// Comparar
|
|
console.log('¿Coinciden? ', fpFour === fpXml ? 'SÍ ✅' : 'NO ❌');
|