pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From le...@apache.org
Subject svn commit: r1652614 - in /pdfbox/trunk: pdfbox/src/main/java/org/apache/pdfbox/pdfparser/ pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/ preflight/src/main/java/org/apache/pdfbox/preflight/parser/
Date Sat, 17 Jan 2015 14:43:07 GMT
Author: lehmi
Date: Sat Jan 17 14:43:07 2015
New Revision: 1652614

URL: http://svn.apache.org/r1652614
Log:
PDFBOX-2600: use the SecurityHandler to decrypt the content

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/NonSequentialPDFParser.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/SecurityHandler.java
    pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/parser/PreflightParser.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/NonSequentialPDFParser.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/NonSequentialPDFParser.java?rev=1652614&r1=1652613&r2=1652614&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/NonSequentialPDFParser.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/NonSequentialPDFParser.java
Sat Jan 17 14:43:07 2015
@@ -51,7 +51,6 @@ import org.apache.pdfbox.cos.COSNull;
 import org.apache.pdfbox.cos.COSNumber;
 import org.apache.pdfbox.cos.COSObject;
 import org.apache.pdfbox.cos.COSStream;
-import org.apache.pdfbox.cos.COSString;
 import org.apache.pdfbox.io.IOUtils;
 import org.apache.pdfbox.io.PushBackInputStream;
 import org.apache.pdfbox.io.RandomAccessBufferedFileInputStream;
@@ -901,7 +900,7 @@ public class NonSequentialPDFParser exte
      * @param pattern pattern to be skipped
      * @throws IOException if pattern could not be read
      */
-    protected final void readPattern(final char[] pattern) throws IOException
+    private final void readPattern(final char[] pattern) throws IOException
     {
         skipSpaces();
 
@@ -1051,7 +1050,7 @@ public class NonSequentialPDFParser exte
     /**
      * Remove the temporary file. A temporary file is created if this class is instantiated
with an InputStream
      */
-    protected void deleteTempFile()
+    private void deleteTempFile()
     {
         if (isTmpPDFFile)
         {
@@ -1381,8 +1380,8 @@ public class NonSequentialPDFParser exte
     }
 
     /**
-     * This will parse the next object from the stream and add it to the local state. This
is taken from
-     * {@link PDFParser} and reduced to parsing an indirect object.
+     * This will parse the next object from the stream and add it to the local state. 
+     * It's reduced to parsing an indirect object.
      * 
      * @param objNr object number of object to be parsed
      * @param objGenNr object generation number of object to be parsed
@@ -1481,7 +1480,7 @@ public class NonSequentialPDFParser exte
                 }
                 else if (securityHandler != null)
                 {
-                    decrypt(pb, objNr, objGenNr);
+                    securityHandler.decrypt(pb, objNr, objGenNr);
                 }
 
                 pdfObject.setObject(pb);
@@ -1539,78 +1538,6 @@ public class NonSequentialPDFParser exte
         return pdfObject.getObject();
     }
     
-    /**
-     * 
-     * @param dict the dictionary to be decrypted
-     * @param objNr the object number
-     * @param objGenNr the object generation number
-     * @throws IOException ff something went wrong
-     */
-    protected final void decryptDictionary(COSDictionary dict, long objNr, long objGenNr)
throws IOException
-    {
-        // skip dictionary containing the signature
-        if (!COSName.SIG.equals(dict.getItem(COSName.TYPE)))
-        {
-            for (Entry<COSName, COSBase> entry : dict.entrySet())
-            {
-                if (entry.getValue() instanceof COSString)
-                {
-                    decryptString((COSString) entry.getValue(), objNr, objGenNr);
-                }
-                else if (entry.getValue() instanceof COSArray)
-                {
-                    securityHandler.decryptArray((COSArray) entry.getValue(), objNr, objGenNr);
-                }
-                else if (entry.getValue() instanceof COSDictionary)
-                {
-                    decryptDictionary((COSDictionary) entry.getValue(), objNr, objGenNr);
-                }
-            }
-        }
-    }
-
-    /**
-     * Decrypts given COSString.
-     * 
-     * @param str the string to be decrypted
-     * @param objNr the object number
-     * @param objGenNr the object generation number
-     * @throws IOException ff something went wrong
-     */
-    protected final void decryptString(COSString str, long objNr, long objGenNr) throws IOException
-    {
-        securityHandler.decryptString(str, objNr, objGenNr);
-    }
-    
-    /**
-     * Decrypts given object.
-     * 
-     * @param pb the object to be decrypted
-     * @param objNr the object number
-     * @param objGenNr the object generation number
-     * @throws IOException ff something went wrong
-     */
-    protected final void decrypt(COSBase pb, int objNr, int objGenNr) throws IOException
-    {
-        if (pb instanceof COSString)
-        {
-            decryptString((COSString) pb, objNr, objGenNr);
-        }
-        else if (pb instanceof COSDictionary)
-        {
-            decryptDictionary((COSDictionary) pb, objNr, objGenNr);
-        }
-        else if (pb instanceof COSArray)
-        {
-            final COSArray array = (COSArray) pb;
-            for (int aIdx = 0, len = array.size(); aIdx < len; aIdx++)
-            {
-                decrypt(array.get(aIdx), objNr, objGenNr);
-            }
-        }
-    }
-    
-    
     private boolean inGetLength = false;
 
     /** Returns length value referred to or defined in given object. */

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/SecurityHandler.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/SecurityHandler.java?rev=1652614&r1=1652613&r2=1652614&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/SecurityHandler.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/SecurityHandler.java
Sat Jan 17 14:43:07 2015
@@ -200,26 +200,6 @@ public abstract class SecurityHandler
     }
 
     /**
-     * Encrypt a set of data.
-     *
-     * @param objectNumber The data object number.
-     * @param genNumber The data generation number.
-     * @param data The data to encrypt.
-     * @param output The output to write the encrypted data to.
-     * @throws IOException If there is an error reading the data.
-     * @deprecated While this works fine for RC4 encryption, it will never decrypt AES data
-     *             You should use encryptData(objectNumber, genNumber, data, output, decrypt)
-     *             which can do everything.  This function is just here for compatibility
-     *             reasons and will be removed in the future.
-     */
-    public void encryptData(long objectNumber, long genNumber, InputStream data,
-                            OutputStream output) throws IOException
-    {
-        // default to encrypting since the function is named "encryptData"
-        encryptData(objectNumber, genNumber, data, output, false);
-    }
-
-    /**
      * Encrypt or decrypt a set of data.
      *
      * @param objectNumber The data object number.
@@ -437,7 +417,7 @@ public abstract class SecurityHandler
      *
      * @throws IOException If there is an error getting the stream data.
      */
-    private void decrypt(COSBase obj, long objNum, long genNum) throws IOException
+    public void decrypt(COSBase obj, long objNum, long genNum) throws IOException
     {
         if (!objects.contains(obj))
         {
@@ -515,18 +495,22 @@ public abstract class SecurityHandler
      */
     private void decryptDictionary(COSDictionary dictionary, long objNum, long genNum) throws
IOException
     {
-        for (Map.Entry<COSName, COSBase> entry : dictionary.entrySet())
+        // skip dictionary containing the signature
+        if (!COSName.SIG.equals(dictionary.getItem(COSName.TYPE)))
         {
-            COSBase value = entry.getValue();
-            // within a dictionary only the following kind of COS objects have to be decrypted
-            if (value instanceof COSString || value instanceof COSStream || value instanceof
COSArray || value instanceof COSDictionary)
-            {
-                // if we are a signature dictionary and contain a Contents entry then
-                // we don't decrypt it.
-                if (!(entry.getKey().equals(COSName.CONTENTS) && value instanceof
COSString && potentialSignatures
-                        .contains(dictionary)))
+            for (Map.Entry<COSName, COSBase> entry : dictionary.entrySet())
+            {
+                COSBase value = entry.getValue();
+                // within a dictionary only the following kind of COS objects have to be
decrypted
+                if (value instanceof COSString || value instanceof COSStream || value instanceof
COSArray || value instanceof COSDictionary)
                 {
-                    decrypt(value, objNum, genNum);
+                    // if we are a signature dictionary and contain a Contents entry then
+                    // we don't decrypt it.
+                    if (!(entry.getKey().equals(COSName.CONTENTS) && value instanceof
COSString && potentialSignatures
+                            .contains(dictionary)))
+                    {
+                        decrypt(value, objNum, genNum);
+                    }
                 }
             }
         }
@@ -541,7 +525,7 @@ public abstract class SecurityHandler
      *
      * @throws IOException If an error occurs writing the new string.
      */
-    public void decryptString(COSString string, long objNum, long genNum) throws IOException
+    private void decryptString(COSString string, long objNum, long genNum) throws IOException
     {
         ByteArrayInputStream data = new ByteArrayInputStream(string.getBytes());
         ByteArrayOutputStream buffer = new ByteArrayOutputStream();
@@ -575,7 +559,7 @@ public abstract class SecurityHandler
      *
      * @throws IOException If there is an error accessing the data.
      */
-    public void decryptArray(COSArray array, long objNum, long genNum) throws IOException
+    private void decryptArray(COSArray array, long objNum, long genNum) throws IOException
     {
         for (int i = 0; i < array.size(); i++)
         {

Modified: pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/parser/PreflightParser.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/parser/PreflightParser.java?rev=1652614&r1=1652613&r2=1652614&view=diff
==============================================================================
--- pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/parser/PreflightParser.java
(original)
+++ pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/parser/PreflightParser.java
Sat Jan 17 14:43:07 2015
@@ -757,7 +757,7 @@ public class PreflightParser extends Non
                 }
                 else if (securityHandler != null)
                 {
-                    decrypt(pb, objNr, objGenNr);
+                    securityHandler.decrypt(pb, objNr, objGenNr);
                 }
 
                 pdfObject.setObject(pb);



Mime
View raw message