From 820dfda63da8e8280523fe273dee69e80dd11548 Mon Sep 17 00:00:00 2001 From: Sam Alloing Date: Fri, 5 Jun 2020 16:47:56 +0200 Subject: [PATCH 1/7] added extra encryption algorithm In the extensionlevel 3 a new encryption algorithm is allowed 256-bit AES. This commit adds that option --- .../java/edu/harvard/hul/ois/jhove/module/pdf/PdfStrings.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/jhove-modules/pdf-hul/src/main/java/edu/harvard/hul/ois/jhove/module/pdf/PdfStrings.java b/jhove-modules/pdf-hul/src/main/java/edu/harvard/hul/ois/jhove/module/pdf/PdfStrings.java index 10b573bc9..cabd5ed1c 100644 --- a/jhove-modules/pdf-hul/src/main/java/edu/harvard/hul/ois/jhove/module/pdf/PdfStrings.java +++ b/jhove-modules/pdf-hul/src/main/java/edu/harvard/hul/ois/jhove/module/pdf/PdfStrings.java @@ -18,7 +18,8 @@ public class PdfStrings "40-bit RC4 or AES", "40-bit or greater RC4 or AES", "Unpublished", - "Document-defined" + "Document-defined", + "256-bit AES" }; /** Flags for FontDescriptor. In PDF notation, bit 1 From 7b184c368658299772a093f363a72913e07fff4b Mon Sep 17 00:00:00 2001 From: Sam Alloing Date: Fri, 5 Jun 2020 17:01:26 +0200 Subject: [PATCH 2/7] extra code added for the encryption algorithm 5 Extra code when the encryption algorithm is 5, because there are additional properties --- .../hul/ois/jhove/module/PdfModule.java | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/jhove-modules/pdf-hul/src/main/java/edu/harvard/hul/ois/jhove/module/PdfModule.java b/jhove-modules/pdf-hul/src/main/java/edu/harvard/hul/ois/jhove/module/PdfModule.java index 1cae0a569..f6021837c 100644 --- a/jhove-modules/pdf-hul/src/main/java/edu/harvard/hul/ois/jhove/module/PdfModule.java +++ b/jhove-modules/pdf-hul/src/main/java/edu/harvard/hul/ois/jhove/module/PdfModule.java @@ -303,6 +303,8 @@ public class PdfModule extends ModuleBase { private static final String PROP_NAME_REVISION = "Revision"; private static final String PROP_NAME_OWNER_STRING = "OwnerString"; private static final String PROP_NAME_USER_STRING = "UserString"; + private static final String PROP_NAME_OWNERKEY_STRING = "OwnerEncryptionKey"; + private static final String PROP_NAME_USERKEY_STRING = "UserEncryptionKey"; private static final String PROP_NAME_USER_UNIT = DICT_KEY_USER_UNIT; private static final String PROP_NAME_STANDARD_SECURITY_HANDLER = "StandardSecurityHandler"; private static final String PROP_NAME_TITLE = DICT_KEY_TITLE; @@ -1863,6 +1865,37 @@ protected boolean readEncryptDict(RepInfo info) throws IOException { toHex(((PdfSimpleObject) uObj).getRawBytes()))); } } + // Required if ExtensionLevel 3 and Encryption Algorithm (V) is 5 + // Defined in AdobeĀ® Supplement to the ISO 32000 + if (algValue == 5) { + PdfObject oeObj = dict.get("OE"); + if (oeObj != null) { + if (oeObj instanceof PdfSimpleObject) { + stdList.add(new Property(PROP_NAME_OWNERKEY_STRING, + PropertyType.STRING, + toHex(((PdfSimpleObject) oeObj).getRawBytes()))); + } + } else { + // if algValue is 5; OE is mandatory + throw new PdfInvalidException // PDF-HUL-15X + (MessageConstants.PDF_HUL_152, _parser.getOffset()); + } + } + // Required if ExtensionLevel 3 and Encryption Algorithm (V) is 5 + if (algValue == 5) { + PdfObject ueObj = dict.get("UE"); + if (ueObj != null) { + if (ueObj instanceof PdfSimpleObject) { + stdList.add(new Property(PROP_NAME_USERKEY_STRING, + PropertyType.STRING, + toHex(((PdfSimpleObject) ueObj).getRawBytes()))); + } + } else { + // if algValue is 5; UE is mandatory + throw new PdfInvalidException // PDF-HUL-15X + (MessageConstants.PDF_HUL_153, _parser.getOffset()); + } + } _encryptList.add(new Property( PROP_NAME_STANDARD_SECURITY_HANDLER, PropertyType.PROPERTY, PropertyArity.LIST, stdList)); From 9393ff23cad9a89462652f2933338a357b8168ea Mon Sep 17 00:00:00 2001 From: Sam Alloing Date: Fri, 5 Jun 2020 17:20:47 +0200 Subject: [PATCH 3/7] Error messages updated for missing mandatory fields When the Encryption Algorithm is 5, the fields OwnerEncryptionKey and UserEncryptionKey are mandatory --- .../edu/harvard/hul/ois/jhove/module/pdf/MessageConstants.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/jhove-modules/pdf-hul/src/main/java/edu/harvard/hul/ois/jhove/module/pdf/MessageConstants.java b/jhove-modules/pdf-hul/src/main/java/edu/harvard/hul/ois/jhove/module/pdf/MessageConstants.java index be175df32..2d7071a21 100644 --- a/jhove-modules/pdf-hul/src/main/java/edu/harvard/hul/ois/jhove/module/pdf/MessageConstants.java +++ b/jhove-modules/pdf-hul/src/main/java/edu/harvard/hul/ois/jhove/module/pdf/MessageConstants.java @@ -188,6 +188,9 @@ public enum MessageConstants { public static final JhoveMessage PDF_HUL_148 = messageFactory.getMessage("PDF-HUL-148"); public static final JhoveMessage PDF_HUL_149 = messageFactory.getMessage("PDF-HUL-149"); public static final JhoveMessage PDF_HUL_150 = messageFactory.getMessage("PDF-HUL-150"); + public static final JhoveMessage PDF_HUL_151 = messageFactory.getMessage("PDF-HUL-151"); + public static final JhoveMessage PDF_HUL_152 = messageFactory.getMessage("PDF-HUL-152"); + public static final JhoveMessage PDF_HUL_153 = messageFactory.getMessage("PDF-HUL-153"); /** * Logger Messages From 14122f660dcededd303d185149db6eeab05820df Mon Sep 17 00:00:00 2001 From: Sam Alloing Date: Fri, 5 Jun 2020 17:23:36 +0200 Subject: [PATCH 4/7] error messages updated for PDF_HUL_152 and PDF_HUL_153 Error messages updated --- .../harvard/hul/ois/jhove/module/pdf/ErrorMessages.properties | 3 +++ 1 file changed, 3 insertions(+) diff --git a/jhove-modules/pdf-hul/src/main/resources/edu/harvard/hul/ois/jhove/module/pdf/ErrorMessages.properties b/jhove-modules/pdf-hul/src/main/resources/edu/harvard/hul/ois/jhove/module/pdf/ErrorMessages.properties index da142460d..195b8edce 100644 --- a/jhove-modules/pdf-hul/src/main/resources/edu/harvard/hul/ois/jhove/module/pdf/ErrorMessages.properties +++ b/jhove-modules/pdf-hul/src/main/resources/edu/harvard/hul/ois/jhove/module/pdf/ErrorMessages.properties @@ -153,3 +153,6 @@ PDF-HUL-147 = Page tree node not found. PDF-HUL-148 = PDF minor version number is greater than 7. PDF-HUL-149 = Invalid indirect destination - referenced object ''{0}'' cannot be found PDF-HUL-150 = Cross-reference stream must be a stream +PDF_HUL_151 = Unexpected error occurred while attempting to read the cross-reference table +PDF_HUL_152 = The mandatory OE is missing +PDF_HUL_153 = The mandatory UE is missing From b84750a210fcd6ca1e2eb27cf1208f6170738641 Mon Sep 17 00:00:00 2001 From: Sam Alloing Date: Fri, 5 Jun 2020 18:49:59 +0200 Subject: [PATCH 5/7] updated error messages David Russo's suggestions --- .../harvard/hul/ois/jhove/module/pdf/ErrorMessages.properties | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jhove-modules/pdf-hul/src/main/resources/edu/harvard/hul/ois/jhove/module/pdf/ErrorMessages.properties b/jhove-modules/pdf-hul/src/main/resources/edu/harvard/hul/ois/jhove/module/pdf/ErrorMessages.properties index 195b8edce..b9793d457 100644 --- a/jhove-modules/pdf-hul/src/main/resources/edu/harvard/hul/ois/jhove/module/pdf/ErrorMessages.properties +++ b/jhove-modules/pdf-hul/src/main/resources/edu/harvard/hul/ois/jhove/module/pdf/ErrorMessages.properties @@ -154,5 +154,5 @@ PDF-HUL-148 = PDF minor version number is greater than 7. PDF-HUL-149 = Invalid indirect destination - referenced object ''{0}'' cannot be found PDF-HUL-150 = Cross-reference stream must be a stream PDF_HUL_151 = Unexpected error occurred while attempting to read the cross-reference table -PDF_HUL_152 = The mandatory OE is missing -PDF_HUL_153 = The mandatory UE is missing +PDF_HUL_152 = Encrypt dictionary has no OE key or it has a null value +PDF_HUL_153 = Encrypt dictionary has no UE key or it has a null value From 6ed15424a8e67198c74f2127c368e870892646aa Mon Sep 17 00:00:00 2001 From: Sam Alloing Date: Fri, 5 Jun 2020 18:52:15 +0200 Subject: [PATCH 6/7] code changed after review david russo --- .../java/edu/harvard/hul/ois/jhove/module/PdfModule.java | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/jhove-modules/pdf-hul/src/main/java/edu/harvard/hul/ois/jhove/module/PdfModule.java b/jhove-modules/pdf-hul/src/main/java/edu/harvard/hul/ois/jhove/module/PdfModule.java index f6021837c..231757869 100644 --- a/jhove-modules/pdf-hul/src/main/java/edu/harvard/hul/ois/jhove/module/PdfModule.java +++ b/jhove-modules/pdf-hul/src/main/java/edu/harvard/hul/ois/jhove/module/PdfModule.java @@ -1877,12 +1877,9 @@ protected boolean readEncryptDict(RepInfo info) throws IOException { } } else { // if algValue is 5; OE is mandatory - throw new PdfInvalidException // PDF-HUL-15X + throw new PdfInvalidException (MessageConstants.PDF_HUL_152, _parser.getOffset()); } - } - // Required if ExtensionLevel 3 and Encryption Algorithm (V) is 5 - if (algValue == 5) { PdfObject ueObj = dict.get("UE"); if (ueObj != null) { if (ueObj instanceof PdfSimpleObject) { @@ -1892,7 +1889,7 @@ protected boolean readEncryptDict(RepInfo info) throws IOException { } } else { // if algValue is 5; UE is mandatory - throw new PdfInvalidException // PDF-HUL-15X + throw new PdfInvalidException (MessageConstants.PDF_HUL_153, _parser.getOffset()); } } From 526160573aa2af4def69dfb40c52d295891225b2 Mon Sep 17 00:00:00 2001 From: Sam Alloing Date: Thu, 11 Jun 2020 08:07:10 +0200 Subject: [PATCH 7/7] underscores replaced with hyphens in the errormessages --- .../hul/ois/jhove/module/pdf/ErrorMessages.properties | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/jhove-modules/pdf-hul/src/main/resources/edu/harvard/hul/ois/jhove/module/pdf/ErrorMessages.properties b/jhove-modules/pdf-hul/src/main/resources/edu/harvard/hul/ois/jhove/module/pdf/ErrorMessages.properties index b9793d457..00c55a528 100644 --- a/jhove-modules/pdf-hul/src/main/resources/edu/harvard/hul/ois/jhove/module/pdf/ErrorMessages.properties +++ b/jhove-modules/pdf-hul/src/main/resources/edu/harvard/hul/ois/jhove/module/pdf/ErrorMessages.properties @@ -153,6 +153,6 @@ PDF-HUL-147 = Page tree node not found. PDF-HUL-148 = PDF minor version number is greater than 7. PDF-HUL-149 = Invalid indirect destination - referenced object ''{0}'' cannot be found PDF-HUL-150 = Cross-reference stream must be a stream -PDF_HUL_151 = Unexpected error occurred while attempting to read the cross-reference table -PDF_HUL_152 = Encrypt dictionary has no OE key or it has a null value -PDF_HUL_153 = Encrypt dictionary has no UE key or it has a null value +PDF-HUL-151 = Unexpected error occurred while attempting to read the cross-reference table +PDF-HUL-152 = Encrypt dictionary has no OE key or it has a null value +PDF-HUL-153 = Encrypt dictionary has no UE key or it has a null value