summaryrefslogtreecommitdiff
path: root/filter
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2018-01-26 10:47:24 +0000
committerAron Budea <aron.budea@collabora.com>2018-02-20 17:29:03 +0100
commit9b8198dacc2208a29044ddc25784e328ac4af1cf (patch)
tree9f15ae3fe9bf51f2487952049302a52f804c72d8 /filter
parentf26899be899f1a39ea1e6b5ad8b46bad9cf1216f (diff)
Resolves: tdf#114221 generate both std97 and cryptoapi keys from password..
when we open a cryptoapi encrypted binary msoffice document. That way when we save as the same format, and try to reuse the generated keys for encryption, we have matching std97 encryption keys available because we always export using that scheme. Change-Id: I25f24a01d102242615768255ce888acb08ef6447 Reviewed-on: https://gerrit.libreoffice.org/48712 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Michael Stahl <mstahl@redhat.com> (cherry picked from commit b5914ba44f2fff9f282b6a5cbe21cbebf19e45b2) Reviewed-on: https://gerrit.libreoffice.org/48914 (cherry picked from commit 82e74f704ce4fe3ffe7ab74c14fe83d2d44dd088)
Diffstat (limited to 'filter')
-rw-r--r--filter/source/msfilter/mscodec.cxx25
1 files changed, 19 insertions, 6 deletions
diff --git a/filter/source/msfilter/mscodec.cxx b/filter/source/msfilter/mscodec.cxx
index c57559bfdd28..f5e400ffefae 100644
--- a/filter/source/msfilter/mscodec.cxx
+++ b/filter/source/msfilter/mscodec.cxx
@@ -245,8 +245,9 @@ void MSCodec_Xor95::Skip( std::size_t nBytes )
mnOffset = (mnOffset + nBytes) & 0x0F;
}
-MSCodec97::MSCodec97(size_t nHashLen)
- : m_nHashLen(nHashLen)
+MSCodec97::MSCodec97(size_t nHashLen, const OUString& rEncKeyName)
+ : m_sEncKeyName(rEncKeyName)
+ , m_nHashLen(nHashLen)
, m_hCipher(rtl_cipher_create(rtl_Cipher_AlgorithmARCFOUR, rtl_Cipher_ModeStream))
, m_aDocId(16, 0)
, m_aDigestValue(nHashLen, 0)
@@ -255,14 +256,14 @@ MSCodec97::MSCodec97(size_t nHashLen)
}
MSCodec_Std97::MSCodec_Std97()
- : MSCodec97(RTL_DIGEST_LENGTH_MD5)
+ : MSCodec97(RTL_DIGEST_LENGTH_MD5, "STD97EncryptionKey")
{
m_hDigest = rtl_digest_create(rtl_Digest_AlgorithmMD5);
assert(m_hDigest != nullptr);
}
MSCodec_CryptoAPI::MSCodec_CryptoAPI()
- : MSCodec97(RTL_DIGEST_LENGTH_SHA1)
+ : MSCodec97(RTL_DIGEST_LENGTH_SHA1, "CryptoAPIEncryptionKey")
{
}
@@ -300,7 +301,7 @@ bool MSCodec97::InitCodec( const uno::Sequence< beans::NamedValue >& aData )
bool bResult = false;
::comphelper::SequenceAsHashMap aHashData( aData );
- uno::Sequence< sal_Int8 > aKey = aHashData.getUnpackedValueOrDefault("STD97EncryptionKey", uno::Sequence< sal_Int8 >() );
+ uno::Sequence<sal_Int8> aKey = aHashData.getUnpackedValueOrDefault(m_sEncKeyName, uno::Sequence<sal_Int8>());
const size_t nKeyLen = aKey.getLength();
if (nKeyLen == m_nHashLen)
{
@@ -328,7 +329,7 @@ uno::Sequence< beans::NamedValue > MSCodec97::GetEncryptionData()
{
::comphelper::SequenceAsHashMap aHashData;
assert(m_aDigestValue.size() == m_nHashLen);
- aHashData[ OUString( "STD97EncryptionKey" ) ] <<= uno::Sequence< sal_Int8 >( reinterpret_cast<sal_Int8*>(m_aDigestValue.data()), m_nHashLen );
+ aHashData[m_sEncKeyName] <<= uno::Sequence<sal_Int8>(reinterpret_cast<sal_Int8*>(m_aDigestValue.data()), m_nHashLen);
aHashData[ OUString( "STD97UniqueID" ) ] <<= uno::Sequence< sal_Int8 >( reinterpret_cast<sal_Int8*>(m_aDocId.data()), m_aDocId.size() );
return aHashData.getAsConstNamedValueList();
@@ -381,6 +382,9 @@ void MSCodec_CryptoAPI::InitKey (
(void)memcpy(m_aDocId.data(), pDocId, 16);
lcl_PrintDigest(m_aDocId.data(), "DocId value");
+
+ //generate the old format key while we have the required data
+ m_aStd97Key = ::comphelper::DocPasswordHelper::GenerateStd97Key(pPassData, pDocId);
}
bool MSCodec97::VerifyKey(const sal_uInt8* pSaltData, const sal_uInt8* pSaltDigest)
@@ -478,6 +482,15 @@ bool MSCodec_CryptoAPI::InitCipher(sal_uInt32 nCounter)
return (result == rtl_Cipher_E_None);
}
+uno::Sequence<beans::NamedValue> MSCodec_CryptoAPI::GetEncryptionData()
+{
+ ::comphelper::SequenceAsHashMap aHashData(MSCodec97::GetEncryptionData());
+ //add in the old encryption key as well as our new key so saving using the
+ //old crypto scheme can be done without reprompt for the password
+ aHashData[OUString("STD97EncryptionKey")] <<= m_aStd97Key;
+ return aHashData.getAsConstNamedValueList();
+}
+
void MSCodec_Std97::CreateSaltDigest( const sal_uInt8 nSaltData[16], sal_uInt8 nSaltDigest[16] )
{
#if DEBUG_MSO_ENCRYPTION_STD97