mirror of
https://github.com/qpdf/qpdf.git
synced 2024-06-04 03:10:52 +00:00
preserve /EncryptMetadata when copying encryption parameters
This commit is contained in:
parent
8b0fbfe806
commit
a42a4068b5
|
@ -1,5 +1,10 @@
|
||||||
2011-08-10 Jay Berkenbilt <ejb@ql.org>
|
2011-08-10 Jay Berkenbilt <ejb@ql.org>
|
||||||
|
|
||||||
|
* libqpdf/QPDFWriter.cc (copyEncryptionParameters): preserve
|
||||||
|
whether metadata is encryption. This fixes part of bug 3173659:
|
||||||
|
the password becomes invalid if qpdf copies an encrypted file with
|
||||||
|
cleartext-metadata.
|
||||||
|
|
||||||
* include/qpdf/QPDFWriter.hh: add a new constructor that takes
|
* include/qpdf/QPDFWriter.hh: add a new constructor that takes
|
||||||
only a QPDF reference and leaves specification of output for
|
only a QPDF reference and leaves specification of output for
|
||||||
later. Add methods setOutputFilename() to set the output to a
|
later. Add methods setOutputFilename() to set the output to a
|
||||||
|
|
|
@ -383,6 +383,14 @@ QPDFWriter::copyEncryptionParameters()
|
||||||
{
|
{
|
||||||
key_len = encrypt.getKey("/Length").getIntValue() / 8;
|
key_len = encrypt.getKey("/Length").getIntValue() / 8;
|
||||||
}
|
}
|
||||||
|
if (encrypt.hasKey("/EncryptMetadata") &&
|
||||||
|
encrypt.getKey("/EncryptMetadata").isBool())
|
||||||
|
{
|
||||||
|
this->encrypt_metadata =
|
||||||
|
encrypt.getKey("/EncryptMetadata").getBoolValue();
|
||||||
|
}
|
||||||
|
QTC::TC("qpdf", "QPDFWriter copy encrypt metadata",
|
||||||
|
this->encrypt_metadata ? 0 : 1);
|
||||||
setEncryptionParametersInternal(
|
setEncryptionParametersInternal(
|
||||||
V,
|
V,
|
||||||
encrypt.getKey("/R").getIntValue(),
|
encrypt.getKey("/R").getIntValue(),
|
||||||
|
|
|
@ -193,3 +193,4 @@ QPDF stream with CR only 0
|
||||||
QPDF stream with CRNL 0
|
QPDF stream with CRNL 0
|
||||||
QPDF stream with NL only 0
|
QPDF stream with NL only 0
|
||||||
QPDF replaceObject called with indirect object 0
|
QPDF replaceObject called with indirect object 0
|
||||||
|
QPDFWriter copy encrypt metadata 1
|
||||||
|
|
|
@ -755,7 +755,7 @@ $td->runtest("show-xref-by-id-filtered",
|
||||||
show_ntests();
|
show_ntests();
|
||||||
# ----------
|
# ----------
|
||||||
$td->notify("--- Clear-text Metadata Tests ---");
|
$td->notify("--- Clear-text Metadata Tests ---");
|
||||||
$n_tests += 42;
|
$n_tests += 58;
|
||||||
|
|
||||||
# args: file, exp_encrypted, exp_cleartext
|
# args: file, exp_encrypted, exp_cleartext
|
||||||
check_metadata("compressed-metadata.pdf", 0, 0);
|
check_metadata("compressed-metadata.pdf", 0, 0);
|
||||||
|
@ -787,13 +787,22 @@ foreach my $f (qw(compressed-metadata.pdf enc-base.pdf))
|
||||||
" a.pdf b.pdf"},
|
" a.pdf b.pdf"},
|
||||||
{$td->STRING => "", $td->EXIT_STATUS => 0});
|
{$td->STRING => "", $td->EXIT_STATUS => 0});
|
||||||
check_metadata("b.pdf", 1, 1);
|
check_metadata("b.pdf", 1, 1);
|
||||||
unlink "b.pdf";
|
$td->runtest("preserve encryption",
|
||||||
|
{$td->COMMAND => "qpdf b.pdf c.pdf"},
|
||||||
|
{$td->STRING => "", $td->EXIT_STATUS => 0});
|
||||||
|
check_metadata("c.pdf", 1, 1);
|
||||||
|
unlink "b.pdf", "c.pdf";
|
||||||
$td->runtest("encrypt with aes and cleartext metadata",
|
$td->runtest("encrypt with aes and cleartext metadata",
|
||||||
{$td->COMMAND =>
|
{$td->COMMAND =>
|
||||||
"qpdf --encrypt '' '' 128" .
|
"qpdf --encrypt '' '' 128" .
|
||||||
" --cleartext-metadata --use-aes=y -- a.pdf b.pdf"},
|
" --cleartext-metadata --use-aes=y -- a.pdf b.pdf"},
|
||||||
{$td->STRING => "", $td->EXIT_STATUS => 0});
|
{$td->STRING => "", $td->EXIT_STATUS => 0});
|
||||||
check_metadata("b.pdf", 1, 1);
|
check_metadata("b.pdf", 1, 1);
|
||||||
|
$td->runtest("preserve encryption",
|
||||||
|
{$td->COMMAND => "qpdf b.pdf c.pdf"},
|
||||||
|
{$td->STRING => "", $td->EXIT_STATUS => 0});
|
||||||
|
check_metadata("c.pdf", 1, 1);
|
||||||
|
unlink "b.pdf", "c.pdf";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user