pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1852786 - /pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/encryption/TestSymmetricKeyEncryption.java
Date Sat, 02 Feb 2019 11:05:53 GMT
Author: tilman
Date: Sat Feb  2 11:05:53 2019
New Revision: 1852786

URL: http://svn.apache.org/viewvc?rev=1852786&view=rev
Log:
PDFBOX-4453: create (inactive) test that fails as long as the bug isn't fixed

Modified:
    pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/encryption/TestSymmetricKeyEncryption.java

Modified: pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/encryption/TestSymmetricKeyEncryption.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/encryption/TestSymmetricKeyEncryption.java?rev=1852786&r1=1852785&r2=1852786&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/encryption/TestSymmetricKeyEncryption.java
(original)
+++ pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/encryption/TestSymmetricKeyEncryption.java
Sat Feb  2 11:05:53 2019
@@ -31,11 +31,15 @@ import javax.crypto.Cipher;
 import junit.framework.TestCase;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.pdfbox.cos.COSDictionary;
+import org.apache.pdfbox.cos.COSName;
+import org.apache.pdfbox.cos.COSString;
 import org.apache.pdfbox.io.IOUtils;
 import org.apache.pdfbox.pdmodel.PDDocument;
 import org.apache.pdfbox.pdmodel.PDDocumentCatalog;
 import org.apache.pdfbox.pdmodel.PDDocumentNameDictionary;
 import org.apache.pdfbox.pdmodel.PDEmbeddedFilesNameTreeNode;
+import org.apache.pdfbox.pdmodel.PDPage;
 import org.apache.pdfbox.pdmodel.common.filespecification.PDComplexFileSpecification;
 import org.apache.pdfbox.pdmodel.common.filespecification.PDEmbeddedFile;
 import org.apache.pdfbox.pdmodel.encryption.AccessPermission;
@@ -263,6 +267,48 @@ public class TestSymmetricKeyEncryption
                 inputFileWithEmbeddedFileAsByteArray, extractedEmbeddedFile, USERPASSWORD,
OWNERPASSWORD);
     }
 
+    /**
+     * PDFBOX-4453: verify that identical encrypted strings are really decrypted each.
+     * 
+     * @throws IOException 
+     */
+    public void t_estPDFBox4453() throws IOException
+    {
+        final int TESTCOUNT = 1000;
+        File file = new File(testResultsDir,"PDFBOX-4453.pdf");
+        PDDocument doc = new PDDocument();
+        doc.addPage(new PDPage());
+        for (int i = 0; i < TESTCOUNT; ++i)
+        {
+            // strings must be in different dictionaries so that the actual
+            // encryption key changes
+            COSDictionary dict = new COSDictionary();
+            doc.getPage(0).getCOSObject().setItem(COSName.getPDFName("_Test-" + i), dict);
+            // need two different keys so that there are both encrypted and decrypted COSStrings
+            // with value "0"
+            dict.setString("key1", "3");
+            dict.setString("key2", "0");
+        }
+
+        //RC4-40
+        StandardProtectionPolicy spp = new StandardProtectionPolicy("12345", "",new AccessPermission());
+        spp.setEncryptionKeyLength(40);
+        spp.setPreferAES(false);
+        doc.protect(spp);
+        doc.save(file);
+        doc.close();
+
+        doc = PDDocument.load(file);
+        Assert.assertTrue(doc.isEncrypted());
+        for (int i = 0; i < TESTCOUNT; ++i)
+        {
+            COSDictionary dict = doc.getPage(0).getCOSObject().getCOSDictionary(COSName.getPDFName("_Test-"
+ i));
+            Assert.assertEquals("3", dict.getString("key1"));
+            Assert.assertEquals("0", dict.getString("key2"));
+        }
+        doc.close();
+    }
+
     private void testSymmEncrForKeySize(int keyLength, boolean preferAES,
             int sizePriorToEncr, byte[] inputFileAsByteArray,
             String userpassword, String ownerpassword,



Mime
View raw message