pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From le...@apache.org
Subject svn commit: r1858696 - in /pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption: SecurityHandler.java StandardSecurityHandler.java
Date Sun, 05 May 2019 17:10:49 GMT
Author: lehmi
Date: Sun May  5 17:10:49 2019
New Revision: 1858696

URL: http://svn.apache.org/viewvc?rev=1858696&view=rev
Log:
PDFBOX-4517: add the missing pieces to support identity filter as proposed by Jerome Joslet

Modified:
    pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/SecurityHandler.java
    pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/StandardSecurityHandler.java

Modified: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/SecurityHandler.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/SecurityHandler.java?rev=1858696&r1=1858695&r2=1858696&view=diff
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/SecurityHandler.java
(original)
+++ pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/SecurityHandler.java
Sun May  5 17:10:49 2019
@@ -101,6 +101,16 @@ public abstract class SecurityHandler
     private AccessPermission currentAccessPermission = null;
 
     /**
+     * The stream filter name.
+     */
+	private COSName streamFilterName;
+
+	/**
+	 * The string filter name.
+	 */
+	private COSName stringFilterName;
+
+    /**
      * Set wether to decrypt meta data.
      *
      * @param decryptMetadata true if meta data has to be decrypted.
@@ -109,6 +119,26 @@ public abstract class SecurityHandler
     {
         this.decryptMetadata = decryptMetadata;
     }
+    
+    /**
+     * Set the string filter name.
+     * 
+     * @param stringFilterName the string filter name.
+     */
+    protected void setStringFilterName(COSName stringFilterName)
+    {
+		this.stringFilterName = stringFilterName;
+	}
+
+    /**
+     * Set the stream filter name.
+     * 
+     * @param streamFilterName the stream filter name.
+     */
+    protected void setStreamFilterName(COSName streamFilterName)
+	{
+    	this.streamFilterName = streamFilterName;
+	}
 
     /**
      * Prepare the document for encryption.
@@ -438,6 +468,12 @@ public abstract class SecurityHandler
      */
     public void decryptStream(COSStream stream, long objNum, long genNum) throws IOException
     {
+    	// Stream encrypted with identity filter
+    	if (COSName.IDENTITY.equals(streamFilterName))
+    	{
+            return;
+    	}
+    	
         COSBase type = stream.getCOSName(COSName.TYPE);
         if (!decryptMetadata && COSName.METADATA.equals(type))
         {
@@ -551,6 +587,12 @@ public abstract class SecurityHandler
      */
     private void decryptString(COSString string, long objNum, long genNum) throws IOException
     {
+    	// String encrypted with identity filter
+    	if (COSName.IDENTITY.equals(stringFilterName))
+    	{
+            return;
+    	}
+    	
         ByteArrayInputStream data = new ByteArrayInputStream(string.getBytes());
         ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
         try

Modified: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/StandardSecurityHandler.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/StandardSecurityHandler.java?rev=1858696&r1=1858695&r2=1858696&view=diff
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/StandardSecurityHandler.java
(original)
+++ pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/StandardSecurityHandler.java
Sun May  5 17:10:49 2019
@@ -173,6 +173,12 @@ public final class StandardSecurityHandl
         {
             throw new IOException("Decryption material is not compatible with the document");
         }
+        
+        // This is only used with security version 4 and 5.
+        if (encryption.getVersion() >= 4) {
+	        setStreamFilterName(encryption.getStreamFilterName());
+	        setStringFilterName(encryption.getStreamFilterName());
+        }
         setDecryptMetadata(encryption.isEncryptMetaData());
         StandardDecryptionMaterial material = (StandardDecryptionMaterial)decryptionMaterial;
 



Mime
View raw message