summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2013-06-15 02:40:20 +0200
committerJay Berkenbilt <ejb@ql.org>2013-06-15 02:42:39 +0200
commiteae8370cd9c4e6ac748931a425721303561bd6ac (patch)
treeb6e83bb8bca29b286e9c50fb73f2cb96d7641499
parenta3576a73593987b26cd3eff346f8f7c11f713cbd (diff)
downloadqpdf-eae8370cd9c4e6ac748931a425721303561bd6ac.tar.zst
Add optional /Length key in crypt filter dictionary
-rw-r--r--ChangeLog4
-rw-r--r--libqpdf/QPDFWriter.cc6
-rw-r--r--qpdf/qtest/qpdf/V4-aes-clearmeta.pdf4
-rw-r--r--qpdf/qtest/qpdf/V4-aes.pdf4
-rw-r--r--qpdf/qtest/qpdf/V4-clearmeta.pdfbin15214 -> 15225 bytes
-rw-r--r--qpdf/qtest/qpdf/V4.pdfbin14770 -> 14781 bytes
-rw-r--r--qpdf/qtest/qpdf/c-r4.pdfbin10881 -> 10892 bytes
-rw-r--r--qpdf/qtest/qpdf/c-r5-in.pdfbin11195 -> 11206 bytes
-rw-r--r--qpdf/qtest/qpdf/c-r6-in.pdfbin11195 -> 11206 bytes
9 files changed, 13 insertions, 5 deletions
diff --git a/ChangeLog b/ChangeLog
index 5dafe0bc..13c964d2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
2013-06-14 Jay Berkenbilt <ejb@ql.org>
+ * Add /Length key to crypt filter dictionary for encrypted files.
+ This key is optional, but some version of MacOS reportedly fail to
+ open encrypted PDF files without this key.
+
* Bug fix: properly handle object stream generation when the
original file has some compressible objects with generation != 0.
diff --git a/libqpdf/QPDFWriter.cc b/libqpdf/QPDFWriter.cc
index dde6e559..8d169f3b 100644
--- a/libqpdf/QPDFWriter.cc
+++ b/libqpdf/QPDFWriter.cc
@@ -726,8 +726,12 @@ QPDFWriter::setEncryptionParametersInternal(
std::string method = (this->encrypt_use_aes
? ((V < 5) ? "/AESV2" : "/AESV3")
: "/V2");
+ // The PDF spec says the /Length key is optional, but the PDF
+ // previewer on some versions of MacOS won't open encrypted
+ // files without it.
encryption_dictionary["/CF"] =
- "<< /StdCF << /AuthEvent /DocOpen /CFM " + method + " >> >>";
+ "<< /StdCF << /AuthEvent /DocOpen /CFM " + method +
+ " /Length " + std::string((V < 5) ? "16" : "32") + " >> >>";
}
this->encrypted = true;
diff --git a/qpdf/qtest/qpdf/V4-aes-clearmeta.pdf b/qpdf/qtest/qpdf/V4-aes-clearmeta.pdf
index 61c57f5c..07edd079 100644
--- a/qpdf/qtest/qpdf/V4-aes-clearmeta.pdf
+++ b/qpdf/qtest/qpdf/V4-aes-clearmeta.pdf
@@ -327,7 +327,7 @@ endobj
<< /Dest [ 30 0 R /XYZ null null null ] /Parent 73 0 R /Title <0e1c2a38465462707e8c9aa8b6c4d2e04e0071f73ffb55e63fee8c296c57a5116ad91676f573b1c2fe59aca102ad3421cc50bd84f88f518cd8bbd9962c7a59d0> /Type /Outline >>
endobj
79 0 obj
-<< /CF << /StdCF << /AuthEvent /DocOpen /CFM /AESV2 >> >> /EncryptMetadata false /Filter /Standard /Length 128 /O <36451bd39d753b7c1d10922c28e6665aa4f3353fb0348b536893e3b1db5c579b> /P -4 /R 4 /StmF /StdCF /StrF /StdCF /U <e4d8eb0d7c43579866926fec0eab59020122456a91bae5134273a6db134c87c4> /V 4 >>
+<< /CF << /StdCF << /AuthEvent /DocOpen /CFM /AESV2 /Length 16 >> >> /EncryptMetadata false /Filter /Standard /Length 128 /O <36451bd39d753b7c1d10922c28e6665aa4f3353fb0348b536893e3b1db5c579b> /P -4 /R 4 /StmF /StdCF /StrF /StdCF /U <e4d8eb0d7c43579866926fec0eab59020122456a91bae5134273a6db134c87c4> /V 4 >>
endobj
xref
0 80
@@ -413,5 +413,5 @@ xref
0000014817 00000 n
trailer << /Info 2 0 R /Root 1 0 R /Size 80 /ID [<66d36a30a97e0f16f39955c6221e0c2a><31415926535897932384626433832795>] /Encrypt 79 0 R >>
startxref
-15129
+15140
%%EOF
diff --git a/qpdf/qtest/qpdf/V4-aes.pdf b/qpdf/qtest/qpdf/V4-aes.pdf
index a779a500..8bb68a1b 100644
--- a/qpdf/qtest/qpdf/V4-aes.pdf
+++ b/qpdf/qtest/qpdf/V4-aes.pdf
@@ -306,7 +306,7 @@ endobj
<< /Dest [ 30 0 R /XYZ null null null ] /Parent 73 0 R /Title <0e1c2a38465462707e8c9aa8b6c4d2e0a57e63f459f8a8428dfc859f799038f972379574e01ef823841a76dbefaa14665223960437217436968f6261cc32feb9> /Type /Outline >>
endobj
79 0 obj
-<< /CF << /StdCF << /AuthEvent /DocOpen /CFM /AESV2 >> >> /Filter /Standard /Length 128 /O <36451bd39d753b7c1d10922c28e6665aa4f3353fb0348b536893e3b1db5c579b> /P -4 /R 4 /StmF /StdCF /StrF /StdCF /U <32c27288b9ec6a4fab94e6188828595c0122456a91bae5134273a6db134c87c4> /V 4 >>
+<< /CF << /StdCF << /AuthEvent /DocOpen /CFM /AESV2 /Length 16 >> >> /Filter /Standard /Length 128 /O <36451bd39d753b7c1d10922c28e6665aa4f3353fb0348b536893e3b1db5c579b> /P -4 /R 4 /StmF /StdCF /StrF /StdCF /U <32c27288b9ec6a4fab94e6188828595c0122456a91bae5134273a6db134c87c4> /V 4 >>
endobj
xref
0 80
@@ -392,5 +392,5 @@ xref
0000014404 00000 n
trailer << /Info 2 0 R /Root 1 0 R /Size 80 /ID [<66d36a30a97e0f16f39955c6221e0c2a><31415926535897932384626433832795>] /Encrypt 79 0 R >>
startxref
-14693
+14704
%%EOF
diff --git a/qpdf/qtest/qpdf/V4-clearmeta.pdf b/qpdf/qtest/qpdf/V4-clearmeta.pdf
index 01325cc5..7d5786c0 100644
--- a/qpdf/qtest/qpdf/V4-clearmeta.pdf
+++ b/qpdf/qtest/qpdf/V4-clearmeta.pdf
Binary files differ
diff --git a/qpdf/qtest/qpdf/V4.pdf b/qpdf/qtest/qpdf/V4.pdf
index 2848782e..0827f6e1 100644
--- a/qpdf/qtest/qpdf/V4.pdf
+++ b/qpdf/qtest/qpdf/V4.pdf
Binary files differ
diff --git a/qpdf/qtest/qpdf/c-r4.pdf b/qpdf/qtest/qpdf/c-r4.pdf
index d985109f..89efb6a7 100644
--- a/qpdf/qtest/qpdf/c-r4.pdf
+++ b/qpdf/qtest/qpdf/c-r4.pdf
Binary files differ
diff --git a/qpdf/qtest/qpdf/c-r5-in.pdf b/qpdf/qtest/qpdf/c-r5-in.pdf
index 19c67a30..b2b249a5 100644
--- a/qpdf/qtest/qpdf/c-r5-in.pdf
+++ b/qpdf/qtest/qpdf/c-r5-in.pdf
Binary files differ
diff --git a/qpdf/qtest/qpdf/c-r6-in.pdf b/qpdf/qtest/qpdf/c-r6-in.pdf
index d8aa5d67..8ce12550 100644
--- a/qpdf/qtest/qpdf/c-r6-in.pdf
+++ b/qpdf/qtest/qpdf/c-r6-in.pdf
Binary files differ