From 9188ea83c346fdc2f668178ae7538665a1b09c02 Mon Sep 17 00:00:00 2001 From: Michael Stahl Date: Fri, 12 Jan 2018 16:58:00 +0100 Subject: tdf#114939 package,comphelper: Try both real SHA1 and StarOffice SHA1 ... when importing ODF documents. In CreatePackageEncryptionData(), add a 3rd SHA1 password hash, PackageSHA1CorrectEncryptionKey, to EncryptionData. Use it in ZipPackageStream::getDataStream(), which has 3 fall-backs for SHA1 bugs now. Also add a CorrectSHA1DigestContext, to be used together with PackageSHA1CorrectEncryptionKey, and rename the existing one to StarOfficeSHA1DigestContext, to be used together with the existing 2 PackageSHA1{UTF8,MS1252}EncryptionKey. The fallback won't be used very often anyway: for the password SHA1 to be wrong, you need a password between 52 and 55 bytes long, and for the SHA1/1K checksum to be wrong, you need a file smaller than 1K with compressed size mod 64 between 52 and 55; all XML files have enough random "chaff" added to be too large. Test that we can read both correct SHA1 and StarOffice SHA1. Change-Id: I988fa489b5e40c7657f404f18538f637d54d28f1 --- package/inc/EncryptionData.hxx | 5 ++++- package/inc/ZipPackageStream.hxx | 5 +++-- 2 files changed, 7 insertions(+), 3 deletions(-) (limited to 'package/inc') diff --git a/package/inc/EncryptionData.hxx b/package/inc/EncryptionData.hxx index 0add43f143de..c7c6ffb3555e 100644 --- a/package/inc/EncryptionData.hxx +++ b/package/inc/EncryptionData.hxx @@ -50,14 +50,16 @@ public: sal_Int32 m_nCheckAlg; sal_Int32 m_nDerivedKeySize; sal_Int32 m_nStartKeyGenID; + bool m_bTryWrongSHA1; - EncryptionData( const BaseEncryptionData& aData, const css::uno::Sequence< sal_Int8 >& aKey, sal_Int32 nEncAlg, sal_Int32 nCheckAlg, sal_Int32 nDerivedKeySize, sal_Int32 nStartKeyGenID ) + EncryptionData(const BaseEncryptionData& aData, const css::uno::Sequence< sal_Int8 >& aKey, sal_Int32 nEncAlg, sal_Int32 nCheckAlg, sal_Int32 nDerivedKeySize, sal_Int32 nStartKeyGenID, bool const bTryWrongSHA1) : BaseEncryptionData( aData ) , m_aKey( aKey ) , m_nEncAlg( nEncAlg ) , m_nCheckAlg( nCheckAlg ) , m_nDerivedKeySize( nDerivedKeySize ) , m_nStartKeyGenID( nStartKeyGenID ) + , m_bTryWrongSHA1(bTryWrongSHA1) {} EncryptionData( const EncryptionData& aData ) @@ -67,6 +69,7 @@ public: , m_nCheckAlg( aData.m_nCheckAlg ) , m_nDerivedKeySize( aData.m_nDerivedKeySize ) , m_nStartKeyGenID( aData.m_nStartKeyGenID ) + , m_bTryWrongSHA1(aData.m_bTryWrongSHA1) {} }; diff --git a/package/inc/ZipPackageStream.hxx b/package/inc/ZipPackageStream.hxx index 4620b5da64f2..67428c086948 100644 --- a/package/inc/ZipPackageStream.hxx +++ b/package/inc/ZipPackageStream.hxx @@ -83,9 +83,10 @@ public: bool IsFromManifest() const { return m_bFromManifest; } void SetFromManifest( bool bValue ) { m_bFromManifest = bValue; } - ::rtl::Reference< EncryptionData > GetEncryptionData( bool bWinEncoding = false ); + enum class Bugs { None, WinEncodingWrongSHA1, WrongSHA1 }; + ::rtl::Reference GetEncryptionData(Bugs bugs = Bugs::WrongSHA1); - css::uno::Sequence< sal_Int8 > GetEncryptionKey( bool bWinEncoding = false ); + css::uno::Sequence GetEncryptionKey(Bugs bugs = Bugs::WrongSHA1); sal_Int32 GetStartKeyGenID(); -- cgit v1.2.3