ninja-labs-tech / verify-pdf

Verify pdf signatures in JS
49 stars 39 forks source link

my authenticity property of verifyPdf is getting false every time. please onyone let me know what the issue #118

Open raheelLT opened 2 years ago

MathExpertBulgaria commented 1 year ago

Probably because you have to manually add some root CA's certificates in @ninja-labs\verify-pdf\lib\helpers\rootCAs.json.

Also, verifyRootCert in verify.js might throw an error and the verification is set to false. Try splitting the logic there in two separate try catch blocks like this: const verifyRootCert = (chainRootInForgeFormat) => {

var r1 = undefined;
r1 = rootCAs.find((x) => {
    try {
       // replace newline
        return forge.pki.certificateToPem(chainRootInForgeFormat).replace(/[\r\n]*/g, "").replace(/(?:\\[rn])+/g, "") == x.replace(/[\r\n]*/g, "").replace(/(?:\\[rn])+/g, "");
    } catch (e) {
        // fs.appendFileSync(normalPath, '\r\n --- r1 err: ' + e + ' ---- ' + e.stack);
    }
});

// fs.appendFileSync(normalPath, '\r\n --- r1: ' + r1);

var r2 = undefined;
r2 = rootCAs.find((x) => {
    try {
        return forge.pki.certificateFromPem(x).issued(chainRootInForgeFormat);
    } catch (e) {
        // fs.appendFileSync(normalPath, ' --- r2 err: ' + e + ' ---- ' + e.stack);
    }
});

// fs.appendFileSync(normalPath, ' --- r2: ' + r2);

return r1 != undefined || r2 != undefined;

}