Commit a42a4068b5ebdf557d2815ee1c72a27ebfefd3f5
1 parent
8b0fbfe8
preserve /EncryptMetadata when copying encryption parameters
Showing
4 changed files
with
25 additions
and
2 deletions
ChangeLog
| 1 | 2011-08-10 Jay Berkenbilt <ejb@ql.org> | 1 | 2011-08-10 Jay Berkenbilt <ejb@ql.org> |
| 2 | 2 | ||
| 3 | + * libqpdf/QPDFWriter.cc (copyEncryptionParameters): preserve | ||
| 4 | + whether metadata is encryption. This fixes part of bug 3173659: | ||
| 5 | + the password becomes invalid if qpdf copies an encrypted file with | ||
| 6 | + cleartext-metadata. | ||
| 7 | + | ||
| 3 | * include/qpdf/QPDFWriter.hh: add a new constructor that takes | 8 | * include/qpdf/QPDFWriter.hh: add a new constructor that takes |
| 4 | only a QPDF reference and leaves specification of output for | 9 | only a QPDF reference and leaves specification of output for |
| 5 | later. Add methods setOutputFilename() to set the output to a | 10 | later. Add methods setOutputFilename() to set the output to a |
libqpdf/QPDFWriter.cc
| @@ -383,6 +383,14 @@ QPDFWriter::copyEncryptionParameters() | @@ -383,6 +383,14 @@ QPDFWriter::copyEncryptionParameters() | ||
| 383 | { | 383 | { |
| 384 | key_len = encrypt.getKey("/Length").getIntValue() / 8; | 384 | key_len = encrypt.getKey("/Length").getIntValue() / 8; |
| 385 | } | 385 | } |
| 386 | + if (encrypt.hasKey("/EncryptMetadata") && | ||
| 387 | + encrypt.getKey("/EncryptMetadata").isBool()) | ||
| 388 | + { | ||
| 389 | + this->encrypt_metadata = | ||
| 390 | + encrypt.getKey("/EncryptMetadata").getBoolValue(); | ||
| 391 | + } | ||
| 392 | + QTC::TC("qpdf", "QPDFWriter copy encrypt metadata", | ||
| 393 | + this->encrypt_metadata ? 0 : 1); | ||
| 386 | setEncryptionParametersInternal( | 394 | setEncryptionParametersInternal( |
| 387 | V, | 395 | V, |
| 388 | encrypt.getKey("/R").getIntValue(), | 396 | encrypt.getKey("/R").getIntValue(), |
qpdf/qpdf.testcov
| @@ -193,3 +193,4 @@ QPDF stream with CR only 0 | @@ -193,3 +193,4 @@ QPDF stream with CR only 0 | ||
| 193 | QPDF stream with CRNL 0 | 193 | QPDF stream with CRNL 0 |
| 194 | QPDF stream with NL only 0 | 194 | QPDF stream with NL only 0 |
| 195 | QPDF replaceObject called with indirect object 0 | 195 | QPDF replaceObject called with indirect object 0 |
| 196 | +QPDFWriter copy encrypt metadata 1 |
qpdf/qtest/qpdf.test
| @@ -755,7 +755,7 @@ $td->runtest("show-xref-by-id-filtered", | @@ -755,7 +755,7 @@ $td->runtest("show-xref-by-id-filtered", | ||
| 755 | show_ntests(); | 755 | show_ntests(); |
| 756 | # ---------- | 756 | # ---------- |
| 757 | $td->notify("--- Clear-text Metadata Tests ---"); | 757 | $td->notify("--- Clear-text Metadata Tests ---"); |
| 758 | -$n_tests += 42; | 758 | +$n_tests += 58; |
| 759 | 759 | ||
| 760 | # args: file, exp_encrypted, exp_cleartext | 760 | # args: file, exp_encrypted, exp_cleartext |
| 761 | check_metadata("compressed-metadata.pdf", 0, 0); | 761 | check_metadata("compressed-metadata.pdf", 0, 0); |
| @@ -787,13 +787,22 @@ foreach my $f (qw(compressed-metadata.pdf enc-base.pdf)) | @@ -787,13 +787,22 @@ foreach my $f (qw(compressed-metadata.pdf enc-base.pdf)) | ||
| 787 | " a.pdf b.pdf"}, | 787 | " a.pdf b.pdf"}, |
| 788 | {$td->STRING => "", $td->EXIT_STATUS => 0}); | 788 | {$td->STRING => "", $td->EXIT_STATUS => 0}); |
| 789 | check_metadata("b.pdf", 1, 1); | 789 | check_metadata("b.pdf", 1, 1); |
| 790 | - unlink "b.pdf"; | 790 | + $td->runtest("preserve encryption", |
| 791 | + {$td->COMMAND => "qpdf b.pdf c.pdf"}, | ||
| 792 | + {$td->STRING => "", $td->EXIT_STATUS => 0}); | ||
| 793 | + check_metadata("c.pdf", 1, 1); | ||
| 794 | + unlink "b.pdf", "c.pdf"; | ||
| 791 | $td->runtest("encrypt with aes and cleartext metadata", | 795 | $td->runtest("encrypt with aes and cleartext metadata", |
| 792 | {$td->COMMAND => | 796 | {$td->COMMAND => |
| 793 | "qpdf --encrypt '' '' 128" . | 797 | "qpdf --encrypt '' '' 128" . |
| 794 | " --cleartext-metadata --use-aes=y -- a.pdf b.pdf"}, | 798 | " --cleartext-metadata --use-aes=y -- a.pdf b.pdf"}, |
| 795 | {$td->STRING => "", $td->EXIT_STATUS => 0}); | 799 | {$td->STRING => "", $td->EXIT_STATUS => 0}); |
| 796 | check_metadata("b.pdf", 1, 1); | 800 | check_metadata("b.pdf", 1, 1); |
| 801 | + $td->runtest("preserve encryption", | ||
| 802 | + {$td->COMMAND => "qpdf b.pdf c.pdf"}, | ||
| 803 | + {$td->STRING => "", $td->EXIT_STATUS => 0}); | ||
| 804 | + check_metadata("c.pdf", 1, 1); | ||
| 805 | + unlink "b.pdf", "c.pdf"; | ||
| 797 | } | 806 | } |
| 798 | } | 807 | } |
| 799 | 808 |