Commit 3d33a3a1e3eed4e09a625f81aaa8fcdc67d642e9

Authored by Jay Berkenbilt
1 parent 2c14be26

Add QPDFAcroFormDocumentHelper::disableDigitalSignatures

include/qpdf/QPDFAcroFormDocumentHelper.hh
@@ -163,6 +163,11 @@ class QPDFAcroFormDocumentHelper: public QPDFDocumentHelper @@ -163,6 +163,11 @@ class QPDFAcroFormDocumentHelper: public QPDFDocumentHelper
163 QPDF_DLL 163 QPDF_DLL
164 void generateAppearancesIfNeeded(); 164 void generateAppearancesIfNeeded();
165 165
  166 + // Disable Digital Signature Fields. Remove all digital signature fields from the document,
  167 + // leaving any annotation showing the content of the field intact.
  168 + QPDF_DLL
  169 + void disableDigitalSignatures();
  170 +
166 // Note: this method works on all annotations, not just ones with associated fields. For each 171 // Note: this method works on all annotations, not just ones with associated fields. For each
167 // annotation in old_annots, apply the given transformation matrix to create a new annotation. 172 // annotation in old_annots, apply the given transformation matrix to create a new annotation.
168 // New annotations are appended to new_annots. If the annotation is associated with a form 173 // New annotations are appended to new_annots. If the annotation is associated with a form
libqpdf/QPDFAcroFormDocumentHelper.cc
@@ -416,6 +416,28 @@ QPDFAcroFormDocumentHelper::generateAppearancesIfNeeded() @@ -416,6 +416,28 @@ QPDFAcroFormDocumentHelper::generateAppearancesIfNeeded()
416 } 416 }
417 417
418 void 418 void
  419 +QPDFAcroFormDocumentHelper::disableDigitalSignatures()
  420 +{
  421 + std::set<QPDFObjGen> to_remove;
  422 + auto fields = getFormFields();
  423 + for (auto& f: fields) {
  424 + auto ft = f.getFieldType();
  425 + if (ft == "/Sig") {
  426 + auto oh = f.getObjectHandle();
  427 + to_remove.insert(oh.getObjGen());
  428 + // Make this no longer a form field. If it's also an annotation, the annotation will
  429 + // survive. If it's only a field and is no longer referenced, it will disappear.
  430 + oh.removeKey("/FT");
  431 + // Remove fields that are specific to signature fields.
  432 + oh.removeKey("/V");
  433 + oh.removeKey("/SV");
  434 + oh.removeKey("/Lock");
  435 + }
  436 + }
  437 + removeFormFields(to_remove);
  438 +}
  439 +
  440 +void
419 QPDFAcroFormDocumentHelper::adjustInheritedFields( 441 QPDFAcroFormDocumentHelper::adjustInheritedFields(
420 QPDFObjectHandle obj, 442 QPDFObjectHandle obj,
421 bool override_da, 443 bool override_da,