node-signpdf icon indicating copy to clipboard operation
node-signpdf copied to clipboard

Document partially signed

Open bernardodesousa opened this issue 2 years ago • 4 comments

Hi! I signed an existing pdf with the following code:

import fs from 'fs';
import { SignPdf, plainAddPlaceholder } from 'node-signpdf';

const signer = new SignPdf()

const p12Buffer = fs.readFileSync("./cert.p12");
let pdfBuffer = fs.readFileSync("./original.pdf");
let pdfWithPlaceHolderBuffer = plainAddPlaceholder({
    pdfBuffer,
    reason: 'Some reason',
    location: 'Some City',
    signatureLength: 15708,
});

let signedPdfBuffer = signer.sign(pdfWithPlaceHolderBuffer, p12Buffer, {
    passphrase: process.env.CERTIFICATE_PASSPHRASE,
});

fs.createWriteStream("./signed.pdf").write(signedPdfBuffer);

Adobe Acrobat says the signature is not valid and that the certificate has "invalid policy constraint":

invalid_policy_constraint

LibreOffice Draw, however, says the document is only partially signed and that the certificate is good:

partially_signed partially_signed_2 valid_cert

When I use Acrobat to sign the same document with the same certificate (although from the Windows Certificate Store, not from a p12 file), the signature is considered valid by LibreOffice:

signed_by_Acrobat

I don't have a lot of experience signing pdf files with x.509 certificates, so this is all very confusing to me. I don't know how to interpret these errors. Any help is appreciated!

bernardodesousa avatar May 21 '22 18:05 bernardodesousa

I tried your code, but show me this error:

SignPdfError: Expected xref at NaN but found other content.
    at getXref (/home/hermes/Projetos/pdf/pdf_sign/node_modules/node-signpdf/dist/helpers/plainAddPlaceholder/readRefTable.js:36:13)
    at getFullXrefTable (/home/hermes/Projetos/pdf/pdf_sign/node_modules/node-signpdf/dist/helpers/plainAddPlaceholder/readRefTable.js:88:25)
    at readRefTable (/home/hermes/Projetos/pdf/pdf_sign/node_modules/node-signpdf/dist/helpers/plainAddPlaceholder/readRefTable.js:108:25)
    at readPdf (/home/hermes/Projetos/pdf/pdf_sign/node_modules/node-signpdf/dist/helpers/plainAddPlaceholder/readPdf.js:47:46)
    at plainAddPlaceholder (/home/hermes/Projetos/pdf/pdf_sign/node_modules/node-signpdf/dist/helpers/plainAddPlaceholder/index.js:58:37)
    at Object.<anonymous> (/home/hermes/Projetos/pdf/pdf_sign/dist/pfx.js:15:69)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12) {
  type: 3
}
error Command failed with exit code 1.

Você é Brasileiro?

hermesalvesbr avatar Aug 28 '22 01:08 hermesalvesbr

Sim, eu sou brasileiro. Você tá com o certificado e o pdf original no mesmo diretório do script? Os nomes são cert.p12 e original.pdf?

bernardodesousa avatar Aug 29 '22 14:08 bernardodesousa

Sim, eu sou brasileiro. Você tá com o certificado e o pdf original no mesmo diretório do script? Os nomes são cert.p12 e original.pdf?

Sim, os arquivos são encontrados.

Topa um freela? https://www.99freelas.com.br/project/assinar-pdf-com-node-signpdf-em-vue3-compostion-api-365076

hermesalvesbr avatar Aug 29 '22 14:08 hermesalvesbr

Sim, eu sou brasileiro. Você tá com o certificado e o pdf original no mesmo diretório do script? Os nomes são cert.p12 e original.pdf?

Sim, os arquivos são encontrados.

Topa um freela? https://www.99freelas.com.br/project/assinar-pdf-com-node-signpdf-em-vue3-compostion-api-365076

Não, obrigado. Brother, não vou poder te ajudar. Boa sorte!

bernardodesousa avatar Aug 29 '22 20:08 bernardodesousa

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.

stale[bot] avatar Dec 31 '22 23:12 stale[bot]