Commit 4ca185fd96dfd3c7a8d89d3afd8093a26acf178b

Authored by Jay Berkenbilt
1 parent 2f37633b

Remove --disable-signatures; incorporate into --remove-restrictions

Rather than adding yet another flag that is almost never useful on its
own, just have --remove-restrictions disable digital signatures. The
operations are still separate in the API.
ChangeLog
... ... @@ -4,10 +4,10 @@
4 4 official installers will offer to modify PATH when installing
5 5 qpdf. Fixes #1054.
6 6  
7   - * Add QPDFAcroFormDocumentHelper::disableDigitalSignatures and the
8   - --disable-signatures command-line argument. This disables any
9   - digital signature fields, leaving their visual representations
10   - intact.
  7 + * Add QPDFAcroFormDocumentHelper::disableDigitalSignatures, which
  8 + disables any digital signature fields, leaving their visual
  9 + representations intact. The --remove-restrictions command-line
  10 + argument now calls this. Fixes #1015.
11 11  
12 12 2023-12-22 Jay Berkenbilt <ejb@ql.org>
13 13  
... ...
include/qpdf/QPDF.hh
... ... @@ -600,7 +600,9 @@ class QPDF
600 600 // Return the previously computed or retrieved encryption key for this file
601 601 QPDF_DLL
602 602 std::string getEncryptionKey() const;
603   - // Remove security restrictions associated with digitally signed files.
  603 + // Remove security restrictions associated with digitally signed files. From qpdf 11.7.0, this
  604 + // is called by QPDFAcroFormDocumentHelper::disableDigitalSignatures and is more useful when
  605 + // called from there than when just called by itself.
604 606 QPDF_DLL
605 607 void removeSecurityRestrictions();
606 608  
... ...
include/qpdf/QPDFAcroFormDocumentHelper.hh
... ... @@ -164,7 +164,8 @@ class QPDFAcroFormDocumentHelper: public QPDFDocumentHelper
164 164 void generateAppearancesIfNeeded();
165 165  
166 166 // Disable Digital Signature Fields. Remove all digital signature fields from the document,
167   - // leaving any annotation showing the content of the field intact.
  167 + // leaving any annotation showing the content of the field intact. This also calls
  168 + // QPDF::removeSecurityRestrictions.
168 169 QPDF_DLL
169 170 void disableDigitalSignatures();
170 171  
... ...
include/qpdf/QPDFJob.hh
... ... @@ -557,7 +557,6 @@ class QPDFJob
557 557 bool linearize{false};
558 558 bool decrypt{false};
559 559 bool remove_restrictions{false};
560   - bool disable_signatures{false};
561 560 int split_pages{0};
562 561 bool progress{false};
563 562 std::function<void(int)> progress_handler{nullptr};
... ...
include/qpdf/auto_job_c_main.hh
... ... @@ -11,7 +11,6 @@ QPDF_DLL Config* checkLinearization();
11 11 QPDF_DLL Config* coalesceContents();
12 12 QPDF_DLL Config* decrypt();
13 13 QPDF_DLL Config* deterministicId();
14   -QPDF_DLL Config* disableSignatures();
15 14 QPDF_DLL Config* externalizeInlineImages();
16 15 QPDF_DLL Config* filteredStreamData();
17 16 QPDF_DLL Config* flattenRotation();
... ...
job.sums
... ... @@ -4,17 +4,17 @@ generate_auto_job f64733b79dcee5a0e3e8ccc6976448e8ddf0e8b6529987a66a7d3ab2ebc10a
4 4 include/qpdf/auto_job_c_att.hh 4c2b171ea00531db54720bf49a43f8b34481586ae7fb6cbf225099ee42bc5bb4
5 5 include/qpdf/auto_job_c_copy_att.hh 50609012bff14fd82f0649185940d617d05d530cdc522185c7f3920a561ccb42
6 6 include/qpdf/auto_job_c_enc.hh 28446f3c32153a52afa239ea40503e6cc8ac2c026813526a349e0cd4ae17ddd5
7   -include/qpdf/auto_job_c_main.hh 36b5ff48ae0dca67415efececa4470cda45364b10d0905e7de9971a2af1795ea
  7 +include/qpdf/auto_job_c_main.hh dbfc221d1533120d1aa9c361d8d2483dea5fcb1c0fd95144d98d305e64ed32a6
8 8 include/qpdf/auto_job_c_pages.hh b3cc0f21029f6d89efa043dcdbfa183cb59325b6506001c18911614fe8e568ec
9 9 include/qpdf/auto_job_c_uo.hh ae21b69a1efa9333050f4833d465f6daff87e5b38e5106e49bbef5d4132e4ed1
10   -job.yml 3c030ce21138967b8a6768b386c0d3bfab9ef41cafbb6ec52f30a81194a7421d
  10 +job.yml 4f89fc7b622df897d30d403d8035aa36fc7de8d8c43042c736e0300d904cb05c
11 11 libqpdf/qpdf/auto_job_decl.hh 9c6f701c29f3f764d620186bed92685a2edf2e4d11e4f4532862c05470cfc4d2
12   -libqpdf/qpdf/auto_job_help.hh 72ae2354911aa353a0b11ca352e6ac6750c38e8c32d0d5ac6b3382ade1719c80
13   -libqpdf/qpdf/auto_job_init.hh 4413804cc784f288245039af053bfe74bc2755e994308220d1939e452011e5a5
  12 +libqpdf/qpdf/auto_job_help.hh 62c40dcd827fcea261a9f432f457aac1331731199ee3530e40de763811ba158e
  13 +libqpdf/qpdf/auto_job_init.hh b4c2b3724fba61f1206fd3bae81951636852592f67a63ef9539839c2c5995065
14 14 libqpdf/qpdf/auto_job_json_decl.hh 06caa46eaf71db8a50c046f91866baa8087745a9474319fb7c86d92634cc8297
15   -libqpdf/qpdf/auto_job_json_init.hh 7682e1e3bc465a3818036e1831aaf205478cc2e47ba5abe483d37c037b6bcf56
16   -libqpdf/qpdf/auto_job_schema.hh 039ee828cf91ece434f0c57706aecc40798e5537308737e01efc8f61eb20685f
  15 +libqpdf/qpdf/auto_job_json_init.hh f5acb9aa103131cb68dec0e12c4d237a6459bdb49b24773c24f0c2724a462b8f
  16 +libqpdf/qpdf/auto_job_schema.hh b53c006fec2e75b1b73588d242d49a32f7d3db820b1541de106c5d4c27fbb4d9
17 17 manual/_ext/qpdf.py 6add6321666031d55ed4aedf7c00e5662bba856dfcd66ccb526563bffefbb580
18   -manual/cli.rst e628a6e2853871679e156e63a53c493d18a38ef87cec8d44e3862401d3c8bde4
19   -manual/qpdf.1 d4a1b304e86c4e02fab5b22fe324235dffbfb50746cff4aec9b2787f12a4b2f6
  18 +manual/cli.rst f361df89dd212daf65e82df8b7b1f8a5e3554043c545f8e7cb14ba5ded21e04e
  19 +manual/qpdf.1 d44042b41642609628690560aad79845f0e9eb742624543c6fbb93f9ae065860
20 20 manual/qpdf.1.in 436ecc85d45c4c9e2dbd1725fb7f0177fb627179469f114561adf3cb6cbb677b
... ...
... ... @@ -104,7 +104,6 @@ options:
104 104 - copy-attachments-from
105 105 - decrypt
106 106 - deterministic-id
107   - - disable-signatures
108 107 - empty
109 108 - encrypt
110 109 - externalize-inline-images
... ... @@ -320,7 +319,6 @@ json:
320 319 decode-level:
321 320 decrypt:
322 321 deterministic-id:
323   - disable-signatures:
324 322 static-aes-iv:
325 323 static-id:
326 324 no-original-object-ids:
... ...
libqpdf/QPDFAcroFormDocumentHelper.cc
... ... @@ -418,6 +418,7 @@ QPDFAcroFormDocumentHelper::generateAppearancesIfNeeded()
418 418 void
419 419 QPDFAcroFormDocumentHelper::disableDigitalSignatures()
420 420 {
  421 + qpdf.removeSecurityRestrictions();
421 422 std::set<QPDFObjGen> to_remove;
422 423 auto fields = getFormFields();
423 424 for (auto& f: fields) {
... ...
libqpdf/QPDFJob.cc
... ... @@ -2127,9 +2127,6 @@ QPDFJob::handleTransformations(QPDF&amp; pdf)
2127 2127 }
2128 2128 };
2129 2129 if (m->remove_restrictions) {
2130   - pdf.removeSecurityRestrictions();
2131   - }
2132   - if (m->disable_signatures) {
2133 2130 make_afdh();
2134 2131 afdh->disableDigitalSignatures();
2135 2132 }
... ...
libqpdf/QPDFJob_config.cc
... ... @@ -145,13 +145,6 @@ QPDFJob::Config::deterministicId()
145 145 }
146 146  
147 147 QPDFJob::Config*
148   -QPDFJob::Config::disableSignatures()
149   -{
150   - o.m->disable_signatures = true;
151   - return this;
152   -}
153   -
154   -QPDFJob::Config*
155 148 QPDFJob::Config::encryptionFilePassword(std::string const& parameter)
156 149 {
157 150 o.m->encryption_file_password = QUtil::make_shared_cstr(parameter);
... ...
libqpdf/qpdf/auto_job_help.hh
... ... @@ -157,15 +157,10 @@ encrypted. Normally qpdf preserves whatever encryption was
157 157 present on the input file. This option overrides that behavior.
158 158 )");
159 159 ap.addOptionHelp("--remove-restrictions", "transformation", "remove security restrictions from input file", R"(Remove restrictions associated with digitally signed PDF files.
160   -This may be combined with --decrypt and --disable-signatures to
161   -allow free editing of previously signed/encrypted files. This
162   -option invalidates the signature but leaves its visual
163   -appearance intact. See also --disable-signatures.
164   -)");
165   -ap.addOptionHelp("--disable-signatures", "transformation", "disable digital signature fields", R"(Remove all digital signature fields from a file. The appearance
166   -of the digital signature, if any, will remain on the page, but
167   -it will no longer be a signature field. See also
168   ---remove-restrictions.
  160 +This may be combined with --decrypt to allow free editing of
  161 +previously signed/encrypted files. This option invalidates and
  162 +disables any digital signatures but leaves their visual
  163 +appearances intact.
169 164 )");
170 165 ap.addOptionHelp("--copy-encryption", "transformation", "copy another file's encryption details", R"(--copy-encryption=file
171 166  
... ... @@ -173,14 +168,14 @@ Copy encryption details from the specified file instead of
173 168 preserving the input file's encryption. Use --encryption-file-password
174 169 to specify the encryption file's password.
175 170 )");
176   -}
177   -static void add_help_3(QPDFArgParser& ap)
178   -{
179 171 ap.addOptionHelp("--encryption-file-password", "transformation", "supply password for --copy-encryption", R"(--encryption-file-password=password
180 172  
181 173 If the file named in --copy-encryption requires a password, use
182 174 this option to supply the password.
183 175 )");
  176 +}
  177 +static void add_help_3(QPDFArgParser& ap)
  178 +{
184 179 ap.addOptionHelp("--qdf", "transformation", "enable viewing PDF code in a text editor", R"(Create a PDF file suitable for viewing in a text editor and even
185 180 editing. This is for editing the PDF code, not the page contents.
186 181 All streams that can be uncompressed are uncompressed, and
... ... @@ -290,9 +285,6 @@ Force the output PDF file&#39;s PDF version header to be the specified
290 285 value, even if the file uses features that may not be available
291 286 in that version.
292 287 )");
293   -}
294   -static void add_help_4(QPDFArgParser& ap)
295   -{
296 288 ap.addHelpTopic("page-ranges", "page range syntax", R"(A full description of the page range syntax, with examples, can be
297 289 found in the manual. Summary:
298 290  
... ... @@ -306,6 +298,9 @@ resulting set of pages, where :odd starts with the first page and
306 298 :even starts with the second page. These are odd and even pages
307 299 from the resulting set, not based on the original page numbers.
308 300 )");
  301 +}
  302 +static void add_help_4(QPDFArgParser& ap)
  303 +{
309 304 ap.addHelpTopic("modification", "change parts of the PDF", R"(Modification options make systematic changes to certain parts of
310 305 the PDF, causing the PDF to render differently from the original.
311 306 )");
... ... @@ -481,13 +476,13 @@ ap.addOptionHelp(&quot;--user-password&quot;, &quot;encryption&quot;, &quot;specify user password&quot;, R&quot;(--
481 476  
482 477 Set the user password of the encrypted file.
483 478 )");
484   -}
485   -static void add_help_5(QPDFArgParser& ap)
486   -{
487 479 ap.addOptionHelp("--owner-password", "encryption", "specify owner password", R"(--owner-password=owner-password
488 480  
489 481 Set the owner password of the encrypted file.
490 482 )");
  483 +}
  484 +static void add_help_5(QPDFArgParser& ap)
  485 +{
491 486 ap.addOptionHelp("--bits", "encryption", "specify encryption key length", R"(--bits={48|128|256}
492 487  
493 488 Specify the encryption key length. For best security, always use
... ... @@ -659,15 +654,15 @@ the destination pages. See qpdf --help=page-ranges for help
659 654 with the page range syntax. The page range may be omitted
660 655 if --repeat is used.
661 656 )");
662   -}
663   -static void add_help_6(QPDFArgParser& ap)
664   -{
665 657 ap.addOptionHelp("--repeat", "overlay-underlay", "overlay/underlay pages to repeat", R"(--repeat=page-range
666 658  
667 659 Specify pages from the overlay/underlay that are repeated after
668 660 "from" pages have been exhausted. See qpdf --help=page-ranges
669 661 for help with the page range syntax.
670 662 )");
  663 +}
  664 +static void add_help_6(QPDFArgParser& ap)
  665 +{
671 666 ap.addHelpTopic("attachments", "work with embedded files", R"(It is possible to list, add, or delete embedded files (also known
672 667 as attachments) and to copy attachments from other files. See help
673 668 on individual options for details. Run qpdf --help=add-attachment
... ... @@ -776,9 +771,6 @@ ap.addOptionHelp(&quot;--requires-password&quot;, &quot;inspection&quot;, &quot;silently test a file&#39;s pa
776 771 2: the file is not encrypted
777 772 3: the file is encrypted, and correct password (if any) has been supplied
778 773 )");
779   -}
780   -static void add_help_7(QPDFArgParser& ap)
781   -{
782 774 ap.addOptionHelp("--check", "inspection", "partially check whether PDF is valid", R"(Check the structure of the PDF file as well as a number of other
783 775 aspects of the file, and write information about the file to
784 776 standard output. Note that qpdf does not perform any validation
... ... @@ -786,6 +778,9 @@ of the actual PDF page content or semantic correctness of the
786 778 PDF file. It merely checks that the PDF file is syntactically
787 779 valid. See also qpdf --help=exit-status.
788 780 )");
  781 +}
  782 +static void add_help_7(QPDFArgParser& ap)
  783 +{
789 784 ap.addOptionHelp("--show-encryption", "inspection", "information about encrypted files", R"(Show document encryption parameters. Also show the document's
790 785 user password if the owner password is given and the file was
791 786 encrypted using older encryption formats that allow user
... ... @@ -866,9 +861,6 @@ This option is repeatable. If given, only specified objects will
866 861 be shown in the "objects" key of the JSON output. Otherwise, all
867 862 objects will be shown.
868 863 )");
869   -}
870   -static void add_help_8(QPDFArgParser& ap)
871   -{
872 864 ap.addOptionHelp("--json-stream-data", "json", "how to handle streams in json output", R"(--json-stream-data={none|inline|file}
873 865  
874 866 When used with --json, this option controls whether streams in
... ... @@ -880,6 +872,9 @@ object number. The prefix can be overridden with
880 872 when --json-output is specified, in which case the default is
881 873 "inline".
882 874 )");
  875 +}
  876 +static void add_help_8(QPDFArgParser& ap)
  877 +{
883 878 ap.addOptionHelp("--json-stream-prefix", "json", "prefix for json stream data files", R"(--json-stream-prefix=file-prefix
884 879  
885 880 When used with --json-stream-data=file, --json-stream-data=file-prefix
... ...
libqpdf/qpdf/auto_job_init.hh
... ... @@ -43,7 +43,6 @@ this-&gt;ap.addBare(&quot;coalesce-contents&quot;, [this](){c_main-&gt;coalesceContents();});
43 43 this->ap.addBare("copy-attachments-from", b(&ArgParser::argCopyAttachmentsFrom));
44 44 this->ap.addBare("decrypt", [this](){c_main->decrypt();});
45 45 this->ap.addBare("deterministic-id", [this](){c_main->deterministicId();});
46   -this->ap.addBare("disable-signatures", [this](){c_main->disableSignatures();});
47 46 this->ap.addBare("empty", b(&ArgParser::argEmpty));
48 47 this->ap.addBare("encrypt", b(&ArgParser::argEncrypt));
49 48 this->ap.addBare("externalize-inline-images", [this](){c_main->externalizeInlineImages();});
... ...
libqpdf/qpdf/auto_job_json_init.hh
... ... @@ -71,9 +71,6 @@ popHandler(); // key: decrypt
71 71 pushKey("deterministicId");
72 72 addBare([this]() { c_main->deterministicId(); });
73 73 popHandler(); // key: deterministicId
74   -pushKey("disableSignatures");
75   -addBare([this]() { c_main->disableSignatures(); });
76   -popHandler(); // key: disableSignatures
77 74 pushKey("staticAesIv");
78 75 addBare([this]() { c_main->staticAesIv(); });
79 76 popHandler(); // key: staticAesIv
... ...
libqpdf/qpdf/auto_job_schema.hh
... ... @@ -16,7 +16,6 @@ static constexpr char const* JOB_SCHEMA_DATA = R&quot;({
16 16 "decodeLevel": "control which streams to uncompress",
17 17 "decrypt": "remove encryption from input file",
18 18 "deterministicId": "generate ID deterministically",
19   - "disableSignatures": "disable digital signature fields",
20 19 "staticAesIv": "use a fixed AES vector",
21 20 "staticId": "use a fixed document ID",
22 21 "noOriginalObjectIds": "omit original object IDs in qdf",
... ...
manual/cli.rst
... ... @@ -736,40 +736,24 @@ Related Options
736 736 whatever encryption was present on the input file. This
737 737 functionality is not intended to be used for bypassing copyright
738 738 restrictions or other restrictions placed on files by their
739   - producers. See also :qpdf:ref:`--copy-encryption`,
740   - :qpdf:ref:`--remove-restrictions`, and
741   - :qpdf:ref:`--disable-signatures`.
  739 + producers. See also :qpdf:ref:`--copy-encryption` and
  740 + :qpdf:ref:`--remove-restrictions`.
742 741  
743 742 .. qpdf:option:: --remove-restrictions
744 743  
745 744 .. help: remove security restrictions from input file
746 745  
747 746 Remove restrictions associated with digitally signed PDF files.
748   - This may be combined with --decrypt and --disable-signatures to
749   - allow free editing of previously signed/encrypted files. This
750   - option invalidates the signature but leaves its visual
751   - appearance intact. See also --disable-signatures.
  747 + This may be combined with --decrypt to allow free editing of
  748 + previously signed/encrypted files. This option invalidates and
  749 + disables any digital signatures but leaves their visual
  750 + appearances intact.
752 751  
753 752 Remove security restrictions associated with digitally signed PDF
754   - files. This may be combined with :qpdf:ref:`--decrypt` and
755   - :qpdf:ref:`--disable-signatures` to allow free editing of
756   - previously signed/encrypted files. This option invalidates the
757   - signature but leaves its visual appearance intact. See also
758   - :qpdf:ref:`--disable-signatures`.
759   -
760   -.. qpdf:option:: --disable-signatures
761   -
762   - .. help: disable digital signature fields
763   -
764   - Remove all digital signature fields from a file. The appearance
765   - of the digital signature, if any, will remain on the page, but
766   - it will no longer be a signature field. See also
767   - --remove-restrictions.
768   -
769   - Remove all digital signature fields from a file. The appearance
770   - of the digital signature, if any, will remain on the page, but
771   - it will no longer be a signature field. See also
772   - :qpdf:ref:`--remove-restrictions`.
  753 + files. This may be combined with :qpdf:ref:`--decrypt` to allow
  754 + free editing of previously signed/encrypted files. This option
  755 + invalidates and disables any digital signatures but leaves their
  756 + visual appearances intact.
773 757  
774 758 .. qpdf:option:: --copy-encryption=file
775 759  
... ...
manual/qpdf.1
... ... @@ -221,16 +221,10 @@ present on the input file. This option overrides that behavior.
221 221 .TP
222 222 .B --remove-restrictions \-\- remove security restrictions from input file
223 223 Remove restrictions associated with digitally signed PDF files.
224   -This may be combined with --decrypt and --disable-signatures to
225   -allow free editing of previously signed/encrypted files. This
226   -option invalidates the signature but leaves its visual
227   -appearance intact. See also --disable-signatures.
228   -.TP
229   -.B --disable-signatures \-\- disable digital signature fields
230   -Remove all digital signature fields from a file. The appearance
231   -of the digital signature, if any, will remain on the page, but
232   -it will no longer be a signature field. See also
233   ---remove-restrictions.
  224 +This may be combined with --decrypt to allow free editing of
  225 +previously signed/encrypted files. This option invalidates and
  226 +disables any digital signatures but leaves their visual
  227 +appearances intact.
234 228 .TP
235 229 .B --copy-encryption \-\- copy another file's encryption details
236 230 --copy-encryption=file
... ...
manual/release-notes.rst
... ... @@ -71,10 +71,8 @@ Planned changes for future 12.x (subject to change):
71 71 shell completion and allows creation of passwords that start
72 72 with ``-``.
73 73  
74   - - Add ``QPDFAcroFormDocumentHelper::disableDigitalSignatures`` and
75   - the :qpdf:ref:`--disable-signatures` command-line argument. This
76   - disables any digital signature fields, leaving their visual
77   - representations intact.
  74 + - :qpdf:ref:`--remove-restrictions` flag now also disables
  75 + digital signatures in the file.
78 76  
79 77 - Build Enhancements:
80 78  
... ... @@ -102,6 +100,10 @@ Planned changes for future 12.x (subject to change):
102 100 - Add methods to ``Buffer`` to work more easily and efficiently
103 101 with ``std::string``.
104 102  
  103 + - Add ``QPDFAcroFormDocumentHelper::disableDigitalSignatures``,
  104 + which disables any digital signature fields, leaving their
  105 + visual representations intact.
  106 +
105 107 11.6.4: December 10, 2023
106 108 - Bug fixes:
107 109  
... ...
qpdf/qtest/qpdf/minimal-signed-restricted.pdf
No preview for this file type
qpdf/qtest/qpdf/minimal-signed-restrictions-removed.pdf
No preview for this file type