vbuch / node-signpdf

Simple signing of PDFs in node.
MIT License
688 stars 175 forks source link

Signing with P12 bundle #137

Closed Gonzalosanto closed 2 years ago

Gonzalosanto commented 3 years ago

Describe the bug and the expected behaviour When I'm running this script:

const signing = (pdfBuffer, certificate) => {
    var signature = new signer.SignPdf;
    signature= signature.sign(pdfBuffer, certificate, {passphrase:"inge"});
    return signature;
}

Returns me an error saying:

SignPdfError: Failed to find a certificate that matches the private key.

My code is supposed to sign the pdf which has a placeholder with the bundle I generated from a chain of PEM certificates.

If I use a self signed certificate does not give any trouble. But with a certificate issued by a CA and signed with CA private key gets me this error.

Do you have any idea or workaround about this problem?

The documentation and tests are not so clear to understand why happens this.

Arisdolanan commented 3 years ago

Maybe someone can try this way if it's worth it. but the case here I make my own certificate.

const p12Buffer = fs.readFileSync( path.join(__dirname, "../utils/test.pfx") ); const pdfBuffer = fs.readFileSync(${url}/${file}); const obj = "[name: 'test1', createdAt: '27/05/2021']"; const dataReason = JSON.stringify(obj); const pdfWithPlaceholder = plainAddPlaceholder({ pdfBuffer, reason: dataReason, }); const signedPdf = signer.sign(pdfWithPlaceholder, p12Buffer, { passphrase: "test", }); fs.writeFileSync("test.pdf", signedPdf);

vbuch commented 3 years ago

This is where finding happens: https://github.com/vbuch/node-signpdf/blob/7ebdec0afa4b0fea0e287164d5cbe78335c890b5/src/signpdf.js#L113 You could try and debug in there to see why and where it messes up. I was doubtful when this was implemented, but it worked for our usecases so I had no reason to dig deeper. Would love to see your usecase but reality is that having the bundles that break it, you are the only one who can debug it @Gonzalosanto

inane commented 3 years ago

Latest version fix this @vbuch ?

vbuch commented 3 years ago

Doubt that @inane. There was no PR on the topic.

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had activity in the past 90 days. It will be closed if no further activity occurs. Thank you for your contributions.