summaryrefslogtreecommitdiff
path: root/oox
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2016-10-20 14:25:13 +0100
committerCaolán McNamara <caolanm@redhat.com>2016-10-21 11:16:11 +0100
commitfc514cbf30be1613fdf4d4b7c12cbd55ca08b9b0 (patch)
tree927407e2073694207561dfb3a1761c5da24b7d88 /oox
parentfcc846e8f29839eaace7e1d28746abea8f4b598a (diff)
move some useful header information to mscodec for reuse
Change-Id: Ic7adf3ed3c8279cc93a06975d6fb337210d1af87
Diffstat (limited to 'oox')
-rw-r--r--oox/source/crypto/CryptTools.cxx6
-rw-r--r--oox/source/crypto/DocumentDecryption.cxx22
-rw-r--r--oox/source/crypto/Standard2007Engine.cxx67
3 files changed, 37 insertions, 58 deletions
diff --git a/oox/source/crypto/CryptTools.cxx b/oox/source/crypto/CryptTools.cxx
index d6dbc96dc989..4bb3ec2f2d28 100644
--- a/oox/source/crypto/CryptTools.cxx
+++ b/oox/source/crypto/CryptTools.cxx
@@ -9,8 +9,8 @@
*/
#include "oox/crypto/CryptTools.hxx"
+#include <filter/msfilter/mscodec.hxx>
#include <com/sun/star/uno/RuntimeException.hpp>
-#include "oox/crypto/Standard2007Engine.hxx"
namespace oox {
namespace core {
@@ -267,9 +267,9 @@ sal_uInt32 Digest::getLength()
switch(meType)
{
case SHA1:
- return oox::core::SHA1_HASH_LENGTH;
+ return msfilter::SHA1_HASH_LENGTH;
case SHA512:
- return oox::core::SHA512_HASH_LENGTH;
+ return msfilter::SHA512_HASH_LENGTH;
default:
break;
}
diff --git a/oox/source/crypto/DocumentDecryption.cxx b/oox/source/crypto/DocumentDecryption.cxx
index c843ad116d13..3fcbc571d3f1 100644
--- a/oox/source/crypto/DocumentDecryption.cxx
+++ b/oox/source/crypto/DocumentDecryption.cxx
@@ -241,7 +241,7 @@ bool DocumentDecryption::readAgileEncryptionInfo(Reference< XInputStream >& xInp
info.cipherAlgorithm == "AES" &&
info.cipherChaining == "ChainingModeCBC" &&
info.hashAlgorithm == "SHA1" &&
- info.hashSize == SHA1_HASH_LENGTH)
+ info.hashSize == msfilter::SHA1_HASH_LENGTH)
{
return true;
}
@@ -251,7 +251,7 @@ bool DocumentDecryption::readAgileEncryptionInfo(Reference< XInputStream >& xInp
info.cipherAlgorithm == "AES" &&
info.cipherChaining == "ChainingModeCBC" &&
info.hashAlgorithm == "SHA512" &&
- info.hashSize == SHA512_HASH_LENGTH)
+ info.hashSize == msfilter::SHA512_HASH_LENGTH)
{
return true;
}
@@ -263,10 +263,10 @@ bool DocumentDecryption::readStandard2007EncryptionInfo(BinaryInputStream& rStre
{
Standard2007Engine* engine = new Standard2007Engine();
mEngine.reset(engine);
- StandardEncryptionInfo& info = engine->getInfo();
+ msfilter::StandardEncryptionInfo& info = engine->getInfo();
info.header.flags = rStream.readuInt32();
- if( getFlag( info.header.flags, ENCRYPTINFO_EXTERNAL ) )
+ if( getFlag( info.header.flags, msfilter::ENCRYPTINFO_EXTERNAL ) )
return false;
sal_uInt32 nHeaderSize = rStream.readuInt32();
@@ -297,18 +297,18 @@ bool DocumentDecryption::readStandard2007EncryptionInfo(BinaryInputStream& rStre
return false;
// check flags and algorithm IDs, required are AES128 and SHA-1
- if( !getFlag( info.header.flags , ENCRYPTINFO_CRYPTOAPI ) )
+ if( !getFlag( info.header.flags, msfilter::ENCRYPTINFO_CRYPTOAPI ) )
return false;
- if( !getFlag( info.header.flags, ENCRYPTINFO_AES ) )
+ if( !getFlag( info.header.flags, msfilter::ENCRYPTINFO_AES ) )
return false;
// algorithm ID 0 defaults to AES128 too, if ENCRYPTINFO_AES flag is set
- if( info.header.algId != 0 && info.header.algId != ENCRYPT_ALGO_AES128 )
+ if( info.header.algId != 0 && info.header.algId != msfilter::ENCRYPT_ALGO_AES128 )
return false;
// hash algorithm ID 0 defaults to SHA-1 too
- if( info.header.algIdHash != 0 && info.header.algIdHash != ENCRYPT_HASH_SHA1 )
+ if( info.header.algIdHash != 0 && info.header.algIdHash != msfilter::ENCRYPT_HASH_SHA1 )
return false;
if( info.verifier.encryptedVerifierHashSize != 20 )
@@ -332,12 +332,12 @@ bool DocumentDecryption::readEncryptionInfo()
switch (aVersion)
{
- case VERSION_INFO_2007_FORMAT:
- case VERSION_INFO_2007_FORMAT_SP2:
+ case msfilter::VERSION_INFO_2007_FORMAT:
+ case msfilter::VERSION_INFO_2007_FORMAT_SP2:
mCryptoType = STANDARD_2007; // Set encryption info format
bResult = readStandard2007EncryptionInfo( aBinaryInputStream );
break;
- case VERSION_INFO_AGILE:
+ case msfilter::VERSION_INFO_AGILE:
mCryptoType = AGILE; // Set encryption info format
aBinaryInputStream.skip(4);
bResult = readAgileEncryptionInfo( xEncryptionInfo );
diff --git a/oox/source/crypto/Standard2007Engine.cxx b/oox/source/crypto/Standard2007Engine.cxx
index 87ef81b56e9b..ecf9d8c5dfe8 100644
--- a/oox/source/crypto/Standard2007Engine.cxx
+++ b/oox/source/crypto/Standard2007Engine.cxx
@@ -42,27 +42,6 @@ static const OUString lclCspName = "Microsoft Enhanced RSA and AES Cryptographic
} // namespace
-EncryptionStandardHeader::EncryptionStandardHeader()
-{
- flags = 0;
- sizeExtra = 0;
- algId = 0;
- algIdHash = 0;
- keyBits = 0;
- providedType = 0;
- reserved1 = 0;
- reserved2 = 0;
-}
-
-EncryptionVerifierAES::EncryptionVerifierAES()
- : saltSize(SALT_LENGTH)
- , encryptedVerifierHashSize(SHA1_HASH_LENGTH)
-{
- memset(salt, 0, sizeof(salt));
- memset(encryptedVerifier, 0, sizeof(encryptedVerifier));
- memset(encryptedVerifierHash, 0, sizeof(encryptedVerifierHash));
-}
-
Standard2007Engine::Standard2007Engine() :
CryptoEngine()
{}
@@ -76,23 +55,23 @@ bool Standard2007Engine::generateVerifier()
if (mKey.size() != 16)
return false;
- vector<sal_uInt8> verifier(ENCRYPTED_VERIFIER_LENGTH);
- vector<sal_uInt8> encryptedVerifier(ENCRYPTED_VERIFIER_LENGTH);
+ vector<sal_uInt8> verifier(msfilter::ENCRYPTED_VERIFIER_LENGTH);
+ vector<sal_uInt8> encryptedVerifier(msfilter::ENCRYPTED_VERIFIER_LENGTH);
lclRandomGenerateValues(&verifier[0], verifier.size());
vector<sal_uInt8> iv;
Encrypt aEncryptorVerifier(mKey, iv, Crypto::AES_128_ECB);
- if (aEncryptorVerifier.update(encryptedVerifier, verifier) != ENCRYPTED_VERIFIER_LENGTH)
+ if (aEncryptorVerifier.update(encryptedVerifier, verifier) != msfilter::ENCRYPTED_VERIFIER_LENGTH)
return false;
std::copy(encryptedVerifier.begin(), encryptedVerifier.end(), mInfo.verifier.encryptedVerifier);
- vector<sal_uInt8> hash(SHA1_HASH_LENGTH, 0);
- mInfo.verifier.encryptedVerifierHashSize = SHA1_HASH_LENGTH;
+ vector<sal_uInt8> hash(msfilter::SHA1_HASH_LENGTH, 0);
+ mInfo.verifier.encryptedVerifierHashSize = msfilter::SHA1_HASH_LENGTH;
Digest::sha1(hash, verifier);
- hash.resize(SHA256_HASH_LENGTH, 0);
+ hash.resize(msfilter::SHA256_HASH_LENGTH, 0);
- vector<sal_uInt8> encryptedHash(SHA256_HASH_LENGTH, 0);
+ vector<sal_uInt8> encryptedHash(msfilter::SHA256_HASH_LENGTH, 0);
Encrypt aEncryptorHash(mKey, iv, Crypto::AES_128_ECB);
aEncryptorHash.update(encryptedHash, hash, hash.size());
@@ -119,13 +98,13 @@ bool Standard2007Engine::calculateEncryptionKey(const OUString& rPassword)
initialData.begin() + saltSize);
// use "hash" vector for result of sha1 hashing
- vector<sal_uInt8> hash(SHA1_HASH_LENGTH, 0);
+ vector<sal_uInt8> hash(msfilter::SHA1_HASH_LENGTH, 0);
// calculate SHA1 hash of initialData
Digest::sha1(hash, initialData);
// data = iterator (4bytes) + hash
- vector<sal_uInt8> data(SHA1_HASH_LENGTH + 4, 0);
+ vector<sal_uInt8> data(msfilter::SHA1_HASH_LENGTH + 4, 0);
for (sal_Int32 i = 0; i < 50000; ++i)
{
@@ -134,7 +113,7 @@ bool Standard2007Engine::calculateEncryptionKey(const OUString& rPassword)
Digest::sha1(hash, data);
}
std::copy(hash.begin(), hash.end(), data.begin() );
- std::fill(data.begin() + SHA1_HASH_LENGTH, data.end(), 0 );
+ std::fill(data.begin() + msfilter::SHA1_HASH_LENGTH, data.end(), 0 );
Digest::sha1(hash, data);
@@ -156,16 +135,16 @@ bool Standard2007Engine::generateEncryptionKey(const OUString& password)
calculateEncryptionKey(password);
- vector<sal_uInt8> encryptedVerifier(ENCRYPTED_VERIFIER_LENGTH);
+ vector<sal_uInt8> encryptedVerifier(msfilter::ENCRYPTED_VERIFIER_LENGTH);
std::copy(
mInfo.verifier.encryptedVerifier,
- mInfo.verifier.encryptedVerifier + ENCRYPTED_VERIFIER_LENGTH,
+ mInfo.verifier.encryptedVerifier + msfilter::ENCRYPTED_VERIFIER_LENGTH,
encryptedVerifier.begin());
- vector<sal_uInt8> encryptedHash(SHA256_HASH_LENGTH);
+ vector<sal_uInt8> encryptedHash(msfilter::SHA256_HASH_LENGTH);
std::copy(
mInfo.verifier.encryptedVerifierHash,
- mInfo.verifier.encryptedVerifierHash + SHA256_HASH_LENGTH,
+ mInfo.verifier.encryptedVerifierHash + msfilter::SHA256_HASH_LENGTH,
encryptedHash.begin());
vector<sal_uInt8> verifier(encryptedVerifier.size(), 0);
@@ -174,7 +153,7 @@ bool Standard2007Engine::generateEncryptionKey(const OUString& password)
vector<sal_uInt8> verifierHash(encryptedHash.size(), 0);
Decrypt::aes128ecb(verifierHash, encryptedHash, mKey);
- vector<sal_uInt8> hash(SHA1_HASH_LENGTH, 0);
+ vector<sal_uInt8> hash(msfilter::SHA1_HASH_LENGTH, 0);
Digest::sha1(hash, verifier);
return std::equal( hash.begin(), hash.end(), verifierHash.begin() );
@@ -204,11 +183,11 @@ bool Standard2007Engine::decrypt(
void Standard2007Engine::writeEncryptionInfo(const OUString& password, BinaryXOutputStream& rStream)
{
- mInfo.header.flags = ENCRYPTINFO_AES | ENCRYPTINFO_CRYPTOAPI;
- mInfo.header.algId = ENCRYPT_ALGO_AES128;
- mInfo.header.algIdHash = ENCRYPT_HASH_SHA1;
- mInfo.header.keyBits = ENCRYPT_KEY_SIZE_AES_128;
- mInfo.header.providedType = ENCRYPT_PROVIDER_TYPE_AES;
+ mInfo.header.flags = msfilter::ENCRYPTINFO_AES | msfilter::ENCRYPTINFO_CRYPTOAPI;
+ mInfo.header.algId = msfilter::ENCRYPT_ALGO_AES128;
+ mInfo.header.algIdHash = msfilter::ENCRYPT_HASH_SHA1;
+ mInfo.header.keyBits = msfilter::ENCRYPT_KEY_SIZE_AES_128;
+ mInfo.header.providedType = msfilter::ENCRYPT_PROVIDER_TYPE_AES;
lclRandomGenerateValues(mInfo.verifier.salt, mInfo.verifier.saltSize);
const sal_Int32 keyLength = mInfo.header.keyBits / 8;
@@ -222,11 +201,11 @@ void Standard2007Engine::writeEncryptionInfo(const OUString& password, BinaryXOu
if (!generateVerifier())
return;
- rStream.WriteUInt32(VERSION_INFO_2007_FORMAT);
+ rStream.WriteUInt32(msfilter::VERSION_INFO_2007_FORMAT);
sal_uInt32 cspNameSize = (lclCspName.getLength() * 2) + 2;
- sal_uInt32 encryptionHeaderSize = static_cast<sal_uInt32>(sizeof(EncryptionStandardHeader));
+ sal_uInt32 encryptionHeaderSize = static_cast<sal_uInt32>(sizeof(msfilter::EncryptionStandardHeader));
rStream.WriteUInt32( mInfo.header.flags );
sal_uInt32 headerSize = encryptionHeaderSize + cspNameSize;
@@ -236,7 +215,7 @@ void Standard2007Engine::writeEncryptionInfo(const OUString& password, BinaryXOu
rStream.writeUnicodeArray(lclCspName);
rStream.WriteUInt16(0);
- sal_uInt32 encryptionVerifierSize = static_cast<sal_uInt32>(sizeof(EncryptionVerifierAES));
+ sal_uInt32 encryptionVerifierSize = static_cast<sal_uInt32>(sizeof(msfilter::EncryptionVerifierAES));
rStream.writeMemory(&mInfo.verifier, encryptionVerifierSize);
}