Adding OCSPs and Certs to DSS dictionary of signed PDF in node.js to make it LTV enabled

61 Views Asked by At

I want to create DSS dictionary for my signed PDF to add OCSPs and Certs into it make the PDF ltv enabled. Which open source node module is better to achieve this? Any reference code would be helpful.

I see pdf-lib library as one of the suggestion using which we can achieve above.

Is below correct way of doing it?

const { PDFDocument, PDFName } = require('pdf-lib');
const addOcspResponsesToDss = async () => {
  const pdfDoc = await PDFDocument.load(existingPdfBytes);
  let dssDict = pdfDoc.catalog.lookup(PDFName.of('DSS'));
  if (!dssDict) {
    dssDict = pdfDoc.context.obj({
      Type: 'DSS',
      V: 1,
      OCSPs: pdfDoc.context.obj([]),
    });
    pdfDoc.catalog.set(PDFName.of('DSS'), dssDict);
  }

  for (const ocspResponse of ocps) {
    dssDict.OCSps.push(pdfDoc.context.obj(new Uint8Array(ocspResponse)));
  }

  const modifiedPdfBytes = await pdfDoc.save();

  fs.writeFileSync('path/to/output.pdf', modifiedPdfBytes);
};

I had achieved LTV enabled signature in JAVA using pdfbox. I am not aware of node modules. Any help would be appreciated, thanks.

0

There are 0 best solutions below