Commit 1308c450903dcae15e37f06339a5c6bff73bab2c

Authored by Jay Berkenbilt
1 parent fe11f13d

Implement --remove-restrictions (fixes #833)

ChangeLog
  1 +2023-01-28 Jay Berkenbilt <ejb@ql.org>
  2 +
  3 + * New option --remove-restrictions removes security restrictions
  4 + from digitally signed files. Fixes #833.
  5 +
1 6 2023-01-09 Jay Berkenbilt <ejb@ql.org>
2 7  
3 8 * Bug fix: flatten annotations should handle a page with no
... ...
include/qpdf/QPDF.hh
... ... @@ -685,6 +685,10 @@ class QPDF
685 685 // this file
686 686 QPDF_DLL
687 687 std::string getEncryptionKey() const;
  688 + // Remove security restrictions associated with digitally signed
  689 + // files.
  690 + QPDF_DLL
  691 + void removeSecurityRestrictions();
688 692  
689 693 // Linearization support
690 694  
... ...
libqpdf/QPDF.cc
... ... @@ -2777,3 +2777,14 @@ QPDF::everPushedInheritedAttributesToPages() const
2777 2777 {
2778 2778 return this->m->ever_pushed_inherited_attributes_to_pages;
2779 2779 }
  2780 +
  2781 +void
  2782 +QPDF::removeSecurityRestrictions()
  2783 +{
  2784 + auto root = getRoot();
  2785 + root.removeKey("/Perms");
  2786 + auto acroform = root.getKey("/AcroForm");
  2787 + if (acroform.isDictionary() && acroform.hasKey("/SigFlags")) {
  2788 + acroform.replaceKey("/SigFlags", QPDFObjectHandle::newInteger(0));
  2789 + }
  2790 +}
... ...
libqpdf/QPDFJob.cc
... ... @@ -2333,6 +2333,9 @@ QPDFJob::handleTransformations(QPDF&amp; pdf)
2333 2333 afdh = std::make_shared<QPDFAcroFormDocumentHelper>(pdf);
2334 2334 }
2335 2335 };
  2336 + if (m->remove_restrictions) {
  2337 + pdf.removeSecurityRestrictions();
  2338 + }
2336 2339 if (m->externalize_inline_images ||
2337 2340 (m->optimize_images && (!m->keep_inline_images))) {
2338 2341 for (auto& ph: dh.getAllPages()) {
... ...
manual/release-notes.rst
... ... @@ -8,6 +8,17 @@ For a detailed list of changes, please see the file
8 8  
9 9 .. x.y.z: not yet released
10 10  
  11 +11.3.0: not yet released
  12 + - CLI Enhancements
  13 +
  14 + - New option :qpdf:ref:`--remove-restrictions` removes security
  15 + restrictions from digitally signed files.
  16 +
  17 + - Library enhancements
  18 +
  19 + - New method ``QPDF::removeSecurityRestrictions`` removes security
  20 + restrictions from digitally signed files.
  21 +
11 22 11.2.0: November 20, 2022
12 23 - Build changes
13 24  
... ...
qpdf/qtest/qpdf/minimal-signed-restricted.pdf 0 → 100644
No preview for this file type
qpdf/qtest/qpdf/minimal-signed-restrictions-removed.pdf 0 → 100644
No preview for this file type
qpdf/qtest/signature-dictionary.test
... ... @@ -128,5 +128,16 @@ foreach my $i (qw(40 128 256))
128 128 $td->EXIT_STATUS => 0});
129 129 }
130 130  
  131 +$n_tests += 2;
  132 +$td->runtest("remove security restrictions",
  133 + {$td->COMMAND =>
  134 + "qpdf --qdf --no-original-object-ids --static-id" .
  135 + " --remove-restrictions minimal-signed-restricted.pdf a.pdf"},
  136 + {$td->STRING => "", $td->EXIT_STATUS => 0},
  137 + $td->NORMALIZE_NEWLINES);
  138 +$td->runtest("checkout output (remove restrictions)",
  139 + {$td->FILE => "a.pdf"},
  140 + {$td->FILE => "minimal-signed-restrictions-removed.pdf"});
  141 +
131 142 cleanup();
132 143 $td->report($n_tests);
... ...