summaryrefslogtreecommitdiff
path: root/oox/source/crypto
diff options
context:
space:
mode:
authorBalazs Varga <balazs.varga.extern@allotropia.de>2023-08-22 22:10:20 +0200
committerSamuel Mehrbrodt <samuel.mehrbrodt@allotropia.de>2023-08-30 14:34:39 +0200
commit9254fbce6b9e20a75aa2a379bcf2fc9dc41a5b44 (patch)
tree9d4e6904934321ce76d1d4b6c6a85d8a396887c9 /oox/source/crypto
parent53fed6a869d0fa983dd28a2f4c62b46d1e67a9f5 (diff)
tdf#156835 - FILEOPEN XLSX: add SHA-384 encryption support for ooxml import
Password protected file with SHA-384 encryption does not open before this patch. Change-Id: I482233f788b8e9da210ad6d2a6c4ece18d05d248 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/156282 Tested-by: Jenkins Reviewed-by: Samuel Mehrbrodt <samuel.mehrbrodt@allotropia.de>
Diffstat (limited to 'oox/source/crypto')
-rw-r--r--oox/source/crypto/AgileEngine.cxx31
-rw-r--r--oox/source/crypto/CryptTools.cxx6
2 files changed, 36 insertions, 1 deletions
diff --git a/oox/source/crypto/AgileEngine.cxx b/oox/source/crypto/AgileEngine.cxx
index f7518498171d..ae2568d0f3f6 100644
--- a/oox/source/crypto/AgileEngine.cxx
+++ b/oox/source/crypto/AgileEngine.cxx
@@ -206,6 +206,12 @@ bool hashCalc(std::vector<sal_uInt8>& output,
output = out;
return true;
}
+ else if (sAlgorithm == u"SHA384")
+ {
+ std::vector<unsigned char> out = comphelper::Hash::calculateHash(input.data(), input.size(), comphelper::HashType::SHA384);
+ output = out;
+ return true;
+ }
else if (sAlgorithm == u"SHA512")
{
std::vector<unsigned char> out = comphelper::Hash::calculateHash(input.data(), input.size(), comphelper::HashType::SHA512);
@@ -219,7 +225,10 @@ CryptoHashType cryptoHashTypeFromString(std::u16string_view sAlgorithm)
{
if (sAlgorithm == u"SHA512")
return CryptoHashType::SHA512;
- return CryptoHashType::SHA1;
+ else if (sAlgorithm == u"SHA384")
+ return CryptoHashType::SHA384;
+ else
+ return CryptoHashType::SHA1;
}
} // namespace
@@ -384,6 +393,8 @@ bool AgileEngine::decryptHmacKey()
comphelper::HashType eType;
if (mInfo.hashAlgorithm == "SHA1")
eType = comphelper::HashType::SHA1;
+ else if (mInfo.hashAlgorithm == "SHA384")
+ eType = comphelper::HashType::SHA384;
else if (mInfo.hashAlgorithm == "SHA512")
eType = comphelper::HashType::SHA512;
else
@@ -410,6 +421,8 @@ bool AgileEngine::decryptHmacValue()
comphelper::HashType eType;
if (mInfo.hashAlgorithm == "SHA1")
eType = comphelper::HashType::SHA1;
+ else if (mInfo.hashAlgorithm == "SHA384")
+ eType = comphelper::HashType::SHA384;
else if (mInfo.hashAlgorithm == "SHA512")
eType = comphelper::HashType::SHA512;
else
@@ -550,6 +563,16 @@ bool AgileEngine::readEncryptionInfo(uno::Reference<io::XInputStream> & rxInputS
return true;
}
+ // AES 128 CBC with SHA384
+ if (mInfo.keyBits == 128 &&
+ mInfo.cipherAlgorithm == "AES" &&
+ mInfo.cipherChaining == "ChainingModeCBC" &&
+ mInfo.hashAlgorithm == "SHA384" &&
+ mInfo.hashSize == comphelper::SHA384_HASH_LENGTH)
+ {
+ return true;
+ }
+
// AES 256 CBC with SHA512
if (mInfo.keyBits == 256 &&
mInfo.cipherAlgorithm == "AES" &&
@@ -613,6 +636,8 @@ bool AgileEngine::encryptHmacKey()
comphelper::HashType eType;
if (mInfo.hashAlgorithm == "SHA1")
eType = comphelper::HashType::SHA1;
+ else if (mInfo.hashAlgorithm == "SHA384")
+ eType = comphelper::HashType::SHA384;
else if (mInfo.hashAlgorithm == "SHA512")
eType = comphelper::HashType::SHA512;
else
@@ -640,6 +665,8 @@ bool AgileEngine::encryptHmacValue()
comphelper::HashType eType;
if (mInfo.hashAlgorithm == "SHA1")
eType = comphelper::HashType::SHA1;
+ else if (mInfo.hashAlgorithm == "SHA384")
+ eType = comphelper::HashType::SHA384;
else if (mInfo.hashAlgorithm == "SHA512")
eType = comphelper::HashType::SHA512;
else
@@ -679,6 +706,8 @@ bool AgileEngine::setupEncryption(OUString const & rPassword)
{
if (meEncryptionPreset == AgileEncryptionPreset::AES_128_SHA1)
setupEncryptionParameters({ 100000, 16, 128, 20, 16, OUString("AES"), OUString("ChainingModeCBC"), OUString("SHA1") });
+ else if (meEncryptionPreset == AgileEncryptionPreset::AES_128_SHA384)
+ setupEncryptionParameters({ 100000, 16, 128, 48, 16, OUString("AES"), OUString("ChainingModeCBC"), OUString("SHA384") });
else
setupEncryptionParameters({ 100000, 16, 256, 64, 16, OUString("AES"), OUString("ChainingModeCBC"), OUString("SHA512") });
diff --git a/oox/source/crypto/CryptTools.cxx b/oox/source/crypto/CryptTools.cxx
index e0a4b9d686cc..86d8ab270d19 100644
--- a/oox/source/crypto/CryptTools.cxx
+++ b/oox/source/crypto/CryptTools.cxx
@@ -117,6 +117,8 @@ struct CryptoImpl
aEvpMd = EVP_sha1(); break;
case CryptoHashType::SHA256:
aEvpMd = EVP_sha256(); break;
+ case CryptoHashType::SHA384:
+ aEvpMd = EVP_sha384(); break;
case CryptoHashType::SHA512:
aEvpMd = EVP_sha512(); break;
}
@@ -318,6 +320,9 @@ struct CryptoImpl
case CryptoHashType::SHA256:
aMechanism = CKM_SHA256_HMAC;
break;
+ case CryptoHashType::SHA384:
+ aMechanism = CKM_SHA384_HMAC;
+ break;
case CryptoHashType::SHA512:
aMechanism = CKM_SHA512_HMAC;
break;
@@ -460,6 +465,7 @@ sal_Int32 getSizeForHashType(CryptoHashType eType)
{
case CryptoHashType::SHA1: return 20;
case CryptoHashType::SHA256: return 32;
+ case CryptoHashType::SHA384: return 48;
case CryptoHashType::SHA512: return 64;
}
return 0;