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:59:23 +0100
commit0065a315a8e7b06ce9f1c661638caf75536f50ca (patch)
treeaa709fde3dbcde08ca81a804da5db7cf4e604793 /filter
parented7fb360f9c1693355cd602de77ea680b286b55a (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) (cherry picked from commit 9b8198dacc2208a29044ddc25784e328ac4af1cf)
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