vbuch / node-signpdf

Simple signing of PDFs in node.
MIT License
719 stars 178 forks source link

Signature details null #43

Closed ghost closed 3 years ago

ghost commented 4 years ago

Hello, i adapt your code signpdf.test.js to make it simpler, but when i use pdfsig to check the signature, the fields return null:

pdfsig bla.pdf 
Digital Signature Info of: bla.pdf
Internal Error (0): Input couldn't be parsed as a CMS signature
Syntax Error (0): Illegal values in ByteRange array
Signature #1:
  - Signer Certificate Common Name: (null)
  - Signer full Distinguished Name: (null)
  - Signing Time: Nov 18 2019 14:18:39
  - Signing Hash Algorithm: unknown
  - Signature Type: adbe.pkcs7.detached
  - Signature Validation: Signature has not yet been verified.

This is my code:

global.signpdf = require('node-signpdf'); 
global.PDF = require('pdfkit'); 
...
                doc = new PDF(.....);
                ....
                if (toSign) {

                    let fieldIds = [], form;
                    const signatureLength = 8192,
                            byteRangePlaceholder = '**********',
                            signature = doc.ref({
                                Type: 'Sig',
                                Filter: 'Adobe.PPKLite',
                                SubFilter: 'adbe.pkcs7.detached',
                                ByteRange: [
                                    0,
                                    byteRangePlaceholder,
                                    byteRangePlaceholder,
                                    byteRangePlaceholder
                                ],
                                Contents: Buffer.from(String.fromCharCode(0).repeat(signatureLength)),
                                Reason: new String("Blabla"),
                                M: new Date(),
                                ContactInfo: new String("bla@bla.pt"),
                                Name: new String('Bla'),
                                Location: new String('Bla')
                            }),
                            signatureName = 'Signature',
                            widget = doc.ref({
                                Type: 'Annot',
                                Subtype: 'Widget',
                                FT: 'Sig',
                                Rect: [0, 0, 0, 0],
                                V: signature,
                                T: new String(signatureName + (fieldIds.length + 1)),
                                F: 4,
                                P: doc.page.dictionary
                            });
                    doc.page.dictionary.data.Annots = [widget];

                    form = doc.ref({
                        Type: 'AcroForm',
                        SigFlags: 3,
                        Fields: [...fieldIds, widget]
                    });
                    doc._root.data.AcroForm = form;
                    signature.end();
                    widget.end();
                    form.end();
                }
                doc.end();
                const assinarPDF = new signpdf.SignPdf(
                        FS.readFileSync("./bla.pdf"),
                        FS.readFileSync(".bla.p12")
                        );

Can you help identifiyng what am i missing? Thank you.

erickximenes commented 4 years ago

Hi, was I able to find a solution to the problem?

HanderUp commented 4 years ago

@vbuch First of all thank you for your library, I have the same problem, and I need to show Chinese. please help me, thanks

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.