Return-Path: X-Original-To: apmail-pdfbox-commits-archive@www.apache.org Delivered-To: apmail-pdfbox-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id CEB5E17736 for ; Sat, 17 Jan 2015 14:43:05 +0000 (UTC) Received: (qmail 48977 invoked by uid 500); 17 Jan 2015 14:43:07 -0000 Delivered-To: apmail-pdfbox-commits-archive@pdfbox.apache.org Received: (qmail 48951 invoked by uid 500); 17 Jan 2015 14:43:07 -0000 Mailing-List: contact commits-help@pdfbox.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@pdfbox.apache.org Delivered-To: mailing list commits@pdfbox.apache.org Received: (qmail 48941 invoked by uid 99); 17 Jan 2015 14:43:07 -0000 Received: from eris.apache.org (HELO hades.apache.org) (140.211.11.105) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 17 Jan 2015 14:43:07 +0000 Received: from hades.apache.org (localhost [127.0.0.1]) by hades.apache.org (ASF Mail Server at hades.apache.org) with ESMTP id 9931AAC003E; Sat, 17 Jan 2015 14:43:07 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@pdfbox.apache.org From: lehmi@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20150117144307.9931AAC003E@hades.apache.org> 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 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 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 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);