vbuch / node-signpdf

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

The signed.pdf will not open in Acrobat reader #109

Closed jbeuckm closed 3 years ago

jbeuckm commented 3 years ago

Error message: "An error exists on this page. Acrobat may not display the page correctly. Please contact the person who created the PDF document to correct the problem." and "At least one signature has problems."

To Reproduce

  1. Generate self-signed p12 file (no password):

    openssl req -new -key myKey.pem -out cert.csr
    openssl x509 -req -in cert.csr -signkey myKey.pem -out cert.crt
    openssl pkcs12 -export -in cert.crt -inkey myKey.pem -out cert.p12
  2. Add placeholder and sign PDF

    
    const pdfBuffer = fs.readFileSync('./test.pdf')

const pdfBufferWithPlaceholder = plainAddPlaceholder({ pdfBuffer, reason: 'Signing the pdf.', signatureLength: 3300, })

const signedPdf = signer.sign(pdfBufferWithPlaceholder, fs.readFileSync('./keyStore.p12')) fs.writeFileSync('signed.pdf', signedPdf)


3. Check signature with `pdfsig`

➜ $ pdfsig ./signed.pdf Internal Error (0): couldn't find default Firefox Folder Digital Signature Info of: ./signed.pdf Signature #1:

vbuch commented 3 years ago

Can't remember on top of my head if the trailer must always contain the full reftable. The initial version has a huge trailer, the signed one has a small one with lots of skipped numbers. But... I seem to have some memory that only overridden entries are mandatory in the updated version. I need to check if that's correct. Chrome's PDF reader seems to do alright with the file but it doesn't care of signatures. LiberOffice Draw shows some malformed version of the doc and shows there is a signature but can't show signature's details. So... yes, there is an issue with the file. If I happen to have some time, I'll check deeper.

stale[bot] commented 3 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.

MallRoy commented 2 years ago

I am also facing the same issue. do we have any workaround for this?