Kaydet (Commit) 11ad93f4 authored tarafından Caolán McNamara's avatar Caolán McNamara

Resolves: rhbz#1013844 fdo#47482 encrypted OOo 1.0 docs cannot be reopened

Workaround for the encrypted OpenOffice.org 1.0 documents generated by
Libreoffice <= 3.6 with the new encryption format and using SHA256, but missing
a specified startkey of SHA256

Change-Id: Ib1acc4441b5adc6721cb3cde7a1191aa978e9a1b
üst f7f42167
...@@ -535,13 +535,37 @@ uno::Reference< io::XInputStream > SAL_CALL ZipPackageStream::getDataStream() ...@@ -535,13 +535,37 @@ uno::Reference< io::XInputStream > SAL_CALL ZipPackageStream::getDataStream()
{ {
xResult = rZipPackage.getZipFile().getDataStream( aEntry, GetEncryptionData(), bIsEncrypted, rZipPackage.GetSharedMutexRef() ); xResult = rZipPackage.getZipFile().getDataStream( aEntry, GetEncryptionData(), bIsEncrypted, rZipPackage.GetSharedMutexRef() );
} }
catch( packages::WrongPasswordException& ) catch( const packages::WrongPasswordException& )
{ {
// workaround for the encrypted documents generated with the old OOo1.x bug. if ( rZipPackage.GetStartKeyGenID() == xml::crypto::DigestID::SHA1 )
if ( rZipPackage.GetStartKeyGenID() == xml::crypto::DigestID::SHA1 && !m_bUseWinEncoding )
{ {
xResult = rZipPackage.getZipFile().getDataStream( aEntry, GetEncryptionData( true ), bIsEncrypted, rZipPackage.GetSharedMutexRef() ); try
m_bUseWinEncoding = true; {
// rhbz#1013844 / fdo#47482 workaround for the encrypted
// OpenOffice.org 1.0 documents generated by Libreoffice <=
// 3.6 with the new encryption format and using SHA256, but
// missing a specified startkey of SHA256
// force SHA256 and see if that works
m_nImportedStartKeyAlgorithm = xml::crypto::DigestID::SHA256;
xResult = rZipPackage.getZipFile().getDataStream( aEntry, GetEncryptionData(), bIsEncrypted, rZipPackage.GetSharedMutexRef() );
return xResult;
}
catch (const packages::WrongPasswordException&)
{
// if that didn't work, restore to SHA1 and trundle through the *other* earlier
// bug fix
m_nImportedStartKeyAlgorithm = xml::crypto::DigestID::SHA1;
}
// workaround for the encrypted documents generated with the old OOo1.x bug.
if ( !m_bUseWinEncoding )
{
xResult = rZipPackage.getZipFile().getDataStream( aEntry, GetEncryptionData( true ), bIsEncrypted, rZipPackage.GetSharedMutexRef() );
m_bUseWinEncoding = true;
}
else
throw;
} }
else else
throw; throw;
......
...@@ -125,6 +125,7 @@ public: ...@@ -125,6 +125,7 @@ public:
//misc tests unrelated to the import filters //misc tests unrelated to the import filters
void testPasswordNew(); void testPasswordNew();
void testPasswordOld(); void testPasswordOld();
void testPasswordWrongSHA();
//test shape import //test shape import
void testControlImport(); void testControlImport();
...@@ -198,6 +199,7 @@ public: ...@@ -198,6 +199,7 @@ public:
//disable testPassword on MacOSX due to problems with libsqlite3 //disable testPassword on MacOSX due to problems with libsqlite3
//also crashes on DragonFly due to problems with nss/nspr headers //also crashes on DragonFly due to problems with nss/nspr headers
#if !defined(MACOSX) && !defined(DRAGONFLY) && !defined(WNT) #if !defined(MACOSX) && !defined(DRAGONFLY) && !defined(WNT)
CPPUNIT_TEST(testPasswordWrongSHA);
CPPUNIT_TEST(testPasswordOld); CPPUNIT_TEST(testPasswordOld);
CPPUNIT_TEST(testPasswordNew); CPPUNIT_TEST(testPasswordNew);
#endif #endif
...@@ -1326,6 +1328,14 @@ void ScFiltersTest::testPasswordOld() ...@@ -1326,6 +1328,14 @@ void ScFiltersTest::testPasswordOld()
testPassword_Impl(aFileNameBase); testPassword_Impl(aFileNameBase);
} }
void ScFiltersTest::testPasswordWrongSHA()
{
//tests opening a file wrongly using the new password algorithm
//in a sxc with the key algorithm missing
const OUString aFileNameBase("passwordWrongSHA.");
testPassword_Impl(aFileNameBase);
}
void ScFiltersTest::testControlImport() void ScFiltersTest::testControlImport()
{ {
ScDocShellRef xDocSh = loadDoc("singlecontrol.", XLSX); ScDocShellRef xDocSh = loadDoc("singlecontrol.", XLSX);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment