Commit a42a4068b5ebdf557d2815ee1c72a27ebfefd3f5
1 parent
8b0fbfe8
preserve /EncryptMetadata when copying encryption parameters
Showing
4 changed files
with
25 additions
and
2 deletions
ChangeLog
| 1 | 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 | 8 | * include/qpdf/QPDFWriter.hh: add a new constructor that takes |
| 4 | 9 | only a QPDF reference and leaves specification of output for |
| 5 | 10 | later. Add methods setOutputFilename() to set the output to a | ... | ... |
libqpdf/QPDFWriter.cc
| ... | ... | @@ -383,6 +383,14 @@ QPDFWriter::copyEncryptionParameters() |
| 383 | 383 | { |
| 384 | 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 | 394 | setEncryptionParametersInternal( |
| 387 | 395 | V, |
| 388 | 396 | encrypt.getKey("/R").getIntValue(), | ... | ... |
qpdf/qpdf.testcov
qpdf/qtest/qpdf.test
| ... | ... | @@ -755,7 +755,7 @@ $td->runtest("show-xref-by-id-filtered", |
| 755 | 755 | show_ntests(); |
| 756 | 756 | # ---------- |
| 757 | 757 | $td->notify("--- Clear-text Metadata Tests ---"); |
| 758 | -$n_tests += 42; | |
| 758 | +$n_tests += 58; | |
| 759 | 759 | |
| 760 | 760 | # args: file, exp_encrypted, exp_cleartext |
| 761 | 761 | check_metadata("compressed-metadata.pdf", 0, 0); |
| ... | ... | @@ -787,13 +787,22 @@ foreach my $f (qw(compressed-metadata.pdf enc-base.pdf)) |
| 787 | 787 | " a.pdf b.pdf"}, |
| 788 | 788 | {$td->STRING => "", $td->EXIT_STATUS => 0}); |
| 789 | 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 | 795 | $td->runtest("encrypt with aes and cleartext metadata", |
| 792 | 796 | {$td->COMMAND => |
| 793 | 797 | "qpdf --encrypt '' '' 128" . |
| 794 | 798 | " --cleartext-metadata --use-aes=y -- a.pdf b.pdf"}, |
| 795 | 799 | {$td->STRING => "", $td->EXIT_STATUS => 0}); |
| 796 | 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 | ... | ... |