diff options
author | Andreas Beeker <kiwiwings@apache.org> | 2017-06-06 22:21:11 +0000 |
---|---|---|
committer | Andreas Beeker <kiwiwings@apache.org> | 2017-06-06 22:21:11 +0000 |
commit | 1bcde5f6d490a6782a8d12ae571fc32ace45056d (patch) | |
tree | 8d05c52441ab318868733fced6ae0bc7ffbed38e /src/java | |
parent | 8909c066be7b3e341f0ef3d8302833d1e68bb5e9 (diff) | |
download | poi-1bcde5f6d490a6782a8d12ae571fc32ace45056d.tar.gz poi-1bcde5f6d490a6782a8d12ae571fc32ace45056d.zip |
#61162 - En-/decryption support for HWPF
Decryption for Binary RC4 and CryptoAPI (... XOR is missing)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1797837 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java')
4 files changed, 21 insertions, 6 deletions
diff --git a/src/java/org/apache/poi/POIDocument.java b/src/java/org/apache/poi/POIDocument.java index dc626da49b..774507722a 100644 --- a/src/java/org/apache/poi/POIDocument.java +++ b/src/java/org/apache/poi/POIDocument.java @@ -195,7 +195,7 @@ public abstract class POIDocument implements Closeable { NPOIFSFileSystem encPoifs = null; String step = "getting"; try { - if (encryptionInfo != null) { + if (encryptionInfo != null && encryptionInfo.isDocPropsEncrypted()) { step = "getting encrypted"; String encryptedStream = null; for (String s : encryptedStreamNames) { diff --git a/src/java/org/apache/poi/hssf/record/crypto/Biff8EncryptionKey.java b/src/java/org/apache/poi/hssf/record/crypto/Biff8EncryptionKey.java index 382ae2f130..f589f02cb9 100644 --- a/src/java/org/apache/poi/hssf/record/crypto/Biff8EncryptionKey.java +++ b/src/java/org/apache/poi/hssf/record/crypto/Biff8EncryptionKey.java @@ -32,7 +32,11 @@ public final class Biff8EncryptionKey { * @param password pass <code>null</code> to clear user password (and use default) */ public static void setCurrentUserPassword(String password) { - _userPasswordTLS.set(password); + if (password == null) { + _userPasswordTLS.remove(); + } else { + _userPasswordTLS.set(password); + } } /** diff --git a/src/java/org/apache/poi/poifs/crypt/EncryptionInfo.java b/src/java/org/apache/poi/poifs/crypt/EncryptionInfo.java index e8895c1abf..c70105fb93 100644 --- a/src/java/org/apache/poi/poifs/crypt/EncryptionInfo.java +++ b/src/java/org/apache/poi/poifs/crypt/EncryptionInfo.java @@ -122,8 +122,11 @@ public class EncryptionInfo implements Cloneable { } else if ( 2 <= versionMajor && versionMajor <= 4 && versionMinor == 2) { - encryptionMode = (preferredEncryptionMode == cryptoAPI) ? cryptoAPI : standard; encryptionFlags = dis.readInt(); + encryptionMode = ( + preferredEncryptionMode == cryptoAPI + || !flagAES.isSet(encryptionFlags)) + ? cryptoAPI : standard; } else if ( versionMajor == agile.versionMajor && versionMinor == agile.versionMinor){ @@ -268,6 +271,14 @@ public class EncryptionInfo implements Cloneable { return encryptionMode; } + /** + * @return true, if Document Summary / Summary are encrypted and stored in the {@code EncryptedStream} stream, + * otherwise the Summaries aren't encrypted and located in their usual streams + */ + public boolean isDocPropsEncrypted() { + return !flagDocProps.isSet(getEncryptionFlags()); + } + @Override public EncryptionInfo clone() throws CloneNotSupportedException { EncryptionInfo other = (EncryptionInfo)super.clone(); diff --git a/src/java/org/apache/poi/poifs/crypt/binaryrc4/BinaryRC4Decryptor.java b/src/java/org/apache/poi/poifs/crypt/binaryrc4/BinaryRC4Decryptor.java index 1cc6b1b2f4..8be9ab3faa 100644 --- a/src/java/org/apache/poi/poifs/crypt/binaryrc4/BinaryRC4Decryptor.java +++ b/src/java/org/apache/poi/poifs/crypt/binaryrc4/BinaryRC4Decryptor.java @@ -51,9 +51,9 @@ public class BinaryRC4Decryptor extends Decryptor implements Cloneable { super(stream, size, chunkSize); } - public BinaryRC4CipherInputStream(InputStream stream) + public BinaryRC4CipherInputStream(InputStream stream, int size, int initialPos) throws GeneralSecurityException { - super(stream, Integer.MAX_VALUE, chunkSize); + super(stream, size, chunkSize, initialPos); } } @@ -141,7 +141,7 @@ public class BinaryRC4Decryptor extends Decryptor implements Cloneable { @Override public InputStream getDataStream(InputStream stream, int size, int initialPos) throws IOException, GeneralSecurityException { - return new BinaryRC4CipherInputStream(stream); + return new BinaryRC4CipherInputStream(stream, size, initialPos); } |