2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-12-22 02:49:00 +00:00

Bug fix: preserve AES when copying encryption parameters

This commit is contained in:
Jay Berkenbilt 2012-07-15 19:07:59 -04:00
parent b501251291
commit db95960ac1
3 changed files with 33 additions and 2 deletions

View File

@ -1,3 +1,9 @@
2012-07-15 Jay Berkenbilt <ejb@ql.org>
* libqpdf/QPDFWriter.cc (copyEncryptionParameters): Bug fix: qpdf
was not preserving whether or not AES encryption was being used
when copying encryption parameters.
2012-07-14 Jay Berkenbilt <ejb@ql.org>
* QPDFWriter: add public copyEncryptionParameters to allow copying

View File

@ -409,10 +409,34 @@ QPDFWriter::copyEncryptionParameters(QPDF& qpdf)
this->encrypt_metadata =
encrypt.getKey("/EncryptMetadata").getBoolValue();
}
if (V >= 4)
{
if (encrypt.hasKey("/CF") &&
encrypt.getKey("/CF").isDictionary() &&
encrypt.hasKey("/StmF") &&
encrypt.getKey("/StmF").isName())
{
// Determine whether to use AES from StmF. QPDFWriter
// can't write files with different StrF and StmF.
QPDFObjectHandle CF = encrypt.getKey("/CF");
QPDFObjectHandle StmF = encrypt.getKey("/StmF");
if (CF.hasKey(StmF.getName()) &&
CF.getKey(StmF.getName()).isDictionary())
{
QPDFObjectHandle StmF_data = CF.getKey(StmF.getName());
if (StmF_data.hasKey("/CFM") &&
StmF_data.getKey("/CFM").isName() &&
StmF_data.getKey("/CFM").getName() == "/AESV2")
{
this->encrypt_use_aes = true;
}
}
}
}
QTC::TC("qpdf", "QPDFWriter copy encrypt metadata",
this->encrypt_metadata ? 0 : 1);
this->id1 =
trailer.getKey("/ID").getArrayItem(0).getStringValue();
QTC::TC("qpdf", "QPDFWriter copy use_aes",
this->encrypt_use_aes ? 0 : 1);
setEncryptionParametersInternal(
V,
encrypt.getKey("/R").getIntValue(),

View File

@ -234,3 +234,4 @@ QPDF replace foreign indirect with null 0
QPDF not copying pages object 0
QPDF insert foreign page 0
QPDFWriter foreign object 0
QPDFWriter copy use_aes 1