Skip to content

Commit 462e2fb

Browse files
committed
Read and rewrite PDF documents with MAC token
DEVSIX-8572
1 parent 83d02fe commit 462e2fb

File tree

72 files changed

+808
-273
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+808
-273
lines changed

bouncy-castle-adapter/src/main/java/com/itextpdf/bouncycastle/BouncyCastleFactory.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1898,6 +1898,16 @@ public byte[] generateEncryptedKeyWithAES256NoPad(byte[] key, byte[] kek) throws
18981898
return cipher.wrap(new SecretKeySpec(key, "AESWrap"));
18991899
}
19001900

1901+
/**
1902+
* {@inheritDoc}
1903+
*/
1904+
@Override
1905+
public byte[] generateDecryptedKeyWithAES256NoPad(byte[] key, byte[] kek) throws GeneralSecurityException {
1906+
Cipher cipher = Cipher.getInstance("AESWrap", this.getProvider());
1907+
cipher.init(Cipher.UNWRAP_MODE, new SecretKeySpec(kek, "AESWrap"));
1908+
return cipher.unwrap(key, "AESWrap", Cipher.SECRET_KEY).getEncoded();
1909+
}
1910+
19011911
/**
19021912
* {@inheritDoc}
19031913
*/

bouncy-castle-connector/src/main/java/com/itextpdf/bouncycastleconnector/BouncyCastleDefaultFactory.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,6 +1009,11 @@ public byte[] generateEncryptedKeyWithAES256NoPad(byte[] key, byte[] kek) {
10091009
throw new UnsupportedOperationException(BouncyCastleLogMessageConstant.BOUNCY_CASTLE_DEPENDENCY_MUST_PRESENT);
10101010
}
10111011

1012+
@Override
1013+
public byte[] generateDecryptedKeyWithAES256NoPad(byte[] key, byte[] kek) {
1014+
throw new UnsupportedOperationException(BouncyCastleLogMessageConstant.BOUNCY_CASTLE_DEPENDENCY_MUST_PRESENT);
1015+
}
1016+
10121017
@Override
10131018
public IGCMBlockCipher createGCMBlockCipher() {
10141019
throw new UnsupportedOperationException(BouncyCastleLogMessageConstant.BOUNCY_CASTLE_DEPENDENCY_MUST_PRESENT);

bouncy-castle-fips-adapter/src/main/java/com/itextpdf/bouncycastlefips/BouncyCastleFipsFactory.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1903,6 +1903,16 @@ public byte[] generateEncryptedKeyWithAES256NoPad(byte[] key, byte[] kek) throws
19031903
return cipher.wrap(new SecretKeySpec(key, "AESWrap"));
19041904
}
19051905

1906+
/**
1907+
* {@inheritDoc}
1908+
*/
1909+
@Override
1910+
public byte[] generateDecryptedKeyWithAES256NoPad(byte[] key, byte[] kek) throws GeneralSecurityException {
1911+
Cipher cipher = Cipher.getInstance("AESWrap", this.getProvider());
1912+
cipher.init(Cipher.UNWRAP_MODE, new SecretKeySpec(kek, "AESWrap"));
1913+
return cipher.unwrap(key, "AESWrap", Cipher.SECRET_KEY).getEncoded();
1914+
}
1915+
19061916
/**
19071917
* {@inheritDoc}
19081918
*/

commons/src/main/java/com/itextpdf/commons/bouncycastle/IBouncyCastleFactory.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1717,10 +1717,22 @@ byte[] createCipherBytes(X509Certificate x509certificate, byte[] abyte0, IAlgori
17171717
*/
17181718
byte[] generateEncryptedKeyWithAES256NoPad(byte[] key, byte[] kek) throws GeneralSecurityException;
17191719

1720+
/**
1721+
* Generates decrypted key based on AES256 without padding unwrapping algorithm.
1722+
*
1723+
* @param key key to be decrypted
1724+
* @param kek key encryption key to be used
1725+
*
1726+
* @return decrypted key.
1727+
*
1728+
* @throws GeneralSecurityException in case of encryption related exceptions.
1729+
*/
1730+
byte[] generateDecryptedKeyWithAES256NoPad(byte[] key, byte[] kek) throws GeneralSecurityException;
1731+
17201732
/**
17211733
* Returns a Block Cipher object that implements the aes-gcm transformation.
17221734
*
1723-
* @return {@code IGCMBlockCipher} instance with provider specific implementation
1735+
* @return {@link IGCMBlockCipher} instance with provider specific implementation
17241736
*/
17251737
IGCMBlockCipher createGCMBlockCipher();
17261738
}

kernel/src/main/java/com/itextpdf/kernel/crypto/securityhandler/PubSecHandlerUsingAes128.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ protected void setPubSecSpecificHandlerDicEntries(PdfDictionary encryptionDictio
9191
encryptionDictionary.put(PdfName.Filter, PdfName.Adobe_PubSec);
9292
encryptionDictionary.put(PdfName.SubFilter, PdfName.Adbe_pkcs7_s5);
9393

94-
encryptionDictionary.put(PdfName.R, new PdfNumber(4));
9594
encryptionDictionary.put(PdfName.V, new PdfNumber(4));
9695

9796
PdfArray recipients = createRecipientsArray();

kernel/src/main/java/com/itextpdf/kernel/crypto/securityhandler/PubSecHandlerUsingAes256.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ protected void setPubSecSpecificHandlerDicEntries(PdfDictionary encryptionDictio
6161
encryptionDictionary.put(PdfName.Filter, PdfName.Adobe_PubSec);
6262
encryptionDictionary.put(PdfName.SubFilter, PdfName.Adbe_pkcs7_s5);
6363

64-
encryptionDictionary.put(PdfName.R, new PdfNumber(5));
6564
encryptionDictionary.put(PdfName.V, new PdfNumber(5));
6665

6766
PdfArray recipients = createRecipientsArray();

kernel/src/main/java/com/itextpdf/kernel/crypto/securityhandler/PubSecHandlerUsingAesGcm.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ public IDecryptor getDecryptor() {
104104
@Override
105105
protected void setPubSecSpecificHandlerDicEntries(PdfDictionary encryptionDictionary, boolean encryptMetadata, boolean embeddedFilesOnly) {
106106
super.setPubSecSpecificHandlerDicEntries(encryptionDictionary, encryptMetadata, embeddedFilesOnly);
107-
encryptionDictionary.put(PdfName.R, new PdfNumber(6));
108107
encryptionDictionary.put(PdfName.V, new PdfNumber(7));
109108
}
110109
}

kernel/src/main/java/com/itextpdf/kernel/crypto/securityhandler/PubSecHandlerUsingStandard128.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,10 @@ protected void setPubSecSpecificHandlerDicEntries(PdfDictionary encryptionDictio
4949
encryptionDictionary.put(PdfName.Filter, PdfName.Adobe_PubSec);
5050
PdfArray recipients = createRecipientsArray();
5151
if (encryptMetadata) {
52-
encryptionDictionary.put(PdfName.R, new PdfNumber(3));
5352
encryptionDictionary.put(PdfName.V, new PdfNumber(2));
5453
encryptionDictionary.put(PdfName.SubFilter, PdfName.Adbe_pkcs7_s4);
5554
encryptionDictionary.put(PdfName.Recipients, recipients);
5655
} else {
57-
encryptionDictionary.put(PdfName.R, new PdfNumber(4));
5856
encryptionDictionary.put(PdfName.V, new PdfNumber(4));
5957
encryptionDictionary.put(PdfName.SubFilter, PdfName.Adbe_pkcs7_s5);
6058

0 commit comments

Comments
 (0)