summaryrefslogtreecommitdiff
path: root/package/source
diff options
context:
space:
mode:
authorMikhail Voytenko <mav@openoffice.org>2011-03-24 13:44:49 +0100
committerMikhail Voytenko <mav@openoffice.org>2011-03-24 13:44:49 +0100
commit481a55dc3bbf3c97c828fa727f4c30f0d8ab171e (patch)
treea29bf2cc93a7ed15d2903dae903703f4fee6beac /package/source
parent0cdc1272fdfbf181b6f297185e0a02dddb912a1a (diff)
mav60: #164341# fix problems with the new implementation
Diffstat (limited to 'package/source')
-rw-r--r--package/source/manifest/ManifestImport.cxx1
-rw-r--r--package/source/zipapi/ZipFile.cxx13
-rw-r--r--package/source/zippackage/ZipPackageFolder.cxx4
-rw-r--r--package/source/zippackage/ZipPackageStream.cxx18
4 files changed, 27 insertions, 9 deletions
diff --git a/package/source/manifest/ManifestImport.cxx b/package/source/manifest/ManifestImport.cxx
index ef17a188afc6..8272cedf6d15 100644
--- a/package/source/manifest/ManifestImport.cxx
+++ b/package/source/manifest/ManifestImport.cxx
@@ -167,6 +167,7 @@ void SAL_CALL ManifestImport::startElement( const OUString& aName, const uno::Re
{
// If this element exists, then this stream is encrypted and we need
// to import the initialisation vector, salt and iteration count used
+ nDerivedKeySize = 0;
OUString aString = aConvertedAttribs[sChecksumTypeAttribute];
if ( !bIgnoreEncryptData )
{
diff --git a/package/source/zipapi/ZipFile.cxx b/package/source/zipapi/ZipFile.cxx
index b359f5a4f99d..a870cb60e63f 100644
--- a/package/source/zipapi/ZipFile.cxx
+++ b/package/source/zipapi/ZipFile.cxx
@@ -257,6 +257,13 @@ void ZipFile::StaticFillHeader( const ::rtl::Reference< EncryptionData >& rData,
*(pHeader++) = static_cast< sal_Int8 >(( nDerivedKeySize >> 16 ) & 0xFF);
*(pHeader++) = static_cast< sal_Int8 >(( nDerivedKeySize >> 24 ) & 0xFF);
+ // Then the start key generation algorithm
+ sal_Int32 nKeyAlgID = rData->m_nStartKeyGenID;
+ *(pHeader++) = static_cast< sal_Int8 >(( nKeyAlgID >> 0 ) & 0xFF);
+ *(pHeader++) = static_cast< sal_Int8 >(( nKeyAlgID >> 8 ) & 0xFF);
+ *(pHeader++) = static_cast< sal_Int8 >(( nKeyAlgID >> 16 ) & 0xFF);
+ *(pHeader++) = static_cast< sal_Int8 >(( nKeyAlgID >> 24 ) & 0xFF);
+
// Then the salt length
*(pHeader++) = static_cast< sal_Int8 >(( nSaltLength >> 0 ) & 0xFF);
*(pHeader++) = static_cast< sal_Int8 >(( nSaltLength >> 8 ) & 0xFF);
@@ -294,6 +301,7 @@ sal_Bool ZipFile::StaticFillData ( ::rtl::Reference< BaseEncryptionData > & rDa
sal_Int32 &rEncAlg,
sal_Int32 &rChecksumAlg,
sal_Int32 &rDerivedKeySize,
+ sal_Int32 &rStartKeyGenID,
sal_Int32 &rSize,
::rtl::OUString& aMediaType,
uno::Reference < XInputStream > &rStream )
@@ -335,6 +343,11 @@ sal_Bool ZipFile::StaticFillData ( ::rtl::Reference< BaseEncryptionData > & rDa
rDerivedKeySize |= ( pBuffer[nPos++] & 0xFF ) << 16;
rDerivedKeySize |= ( pBuffer[nPos++] & 0xFF ) << 24;
+ rStartKeyGenID = pBuffer[nPos++] & 0xFF;
+ rStartKeyGenID |= ( pBuffer[nPos++] & 0xFF ) << 8;
+ rStartKeyGenID |= ( pBuffer[nPos++] & 0xFF ) << 16;
+ rStartKeyGenID |= ( pBuffer[nPos++] & 0xFF ) << 24;
+
sal_Int16 nSaltLength = pBuffer[nPos++] & 0xFF;
nSaltLength |= ( pBuffer[nPos++] & 0xFF ) << 8;
sal_Int16 nIVLength = ( pBuffer[nPos++] & 0xFF );
diff --git a/package/source/zippackage/ZipPackageFolder.cxx b/package/source/zippackage/ZipPackageFolder.cxx
index bc8fa227b8af..31ace7e34bf7 100644
--- a/package/source/zippackage/ZipPackageFolder.cxx
+++ b/package/source/zippackage/ZipPackageFolder.cxx
@@ -550,7 +550,7 @@ void ZipPackageFolder::saveContents( ::rtl::OUString &rPath, std::vector < uno::
aPropSet[PKG_MNFST_ENCALG].Name = sEncryptionAlgProperty;
aPropSet[PKG_MNFST_ENCALG].Value <<= xEncData->m_nEncAlg;
aPropSet[PKG_MNFST_STARTALG].Name = sStartKeyAlgProperty;
- aPropSet[PKG_MNFST_STARTALG].Value <<= pStream->GetKeyGenID();
+ aPropSet[PKG_MNFST_STARTALG].Value <<= xEncData->m_nStartKeyGenID;
aPropSet[PKG_MNFST_DIGESTALG].Name = sDigestAlgProperty;
aPropSet[PKG_MNFST_DIGESTALG].Value <<= xEncData->m_nCheckAlg;
aPropSet[PKG_MNFST_DERKEYSIZE].Name = sDerivedKeySizeProperty;
@@ -678,7 +678,7 @@ void ZipPackageFolder::saveContents( ::rtl::OUString &rPath, std::vector < uno::
aPropSet[PKG_MNFST_ENCALG].Name = sEncryptionAlgProperty;
aPropSet[PKG_MNFST_ENCALG].Value <<= xEncData->m_nEncAlg;
aPropSet[PKG_MNFST_STARTALG].Name = sStartKeyAlgProperty;
- aPropSet[PKG_MNFST_STARTALG].Value <<= pStream->GetKeyGenID();
+ aPropSet[PKG_MNFST_STARTALG].Value <<= xEncData->m_nStartKeyGenID;
aPropSet[PKG_MNFST_DIGESTALG].Name = sDigestAlgProperty;
aPropSet[PKG_MNFST_DIGESTALG].Value <<= xEncData->m_nCheckAlg;
aPropSet[PKG_MNFST_DERKEYSIZE].Name = sDerivedKeySizeProperty;
diff --git a/package/source/zippackage/ZipPackageStream.cxx b/package/source/zippackage/ZipPackageStream.cxx
index 5ae56872e252..79797b938f60 100644
--- a/package/source/zippackage/ZipPackageStream.cxx
+++ b/package/source/zippackage/ZipPackageStream.cxx
@@ -221,7 +221,8 @@ sal_Int32 ZipPackageStream::GetBlockSize() const
GetEncryptionKey( bUseWinEncoding ),
GetEncryptionAlgorithm(),
m_nImportedChecksumAlgorithm ? m_nImportedChecksumAlgorithm : rZipPackage.GetChecksumAlgID(),
- m_nImportedDerivedKeySize ? m_nImportedDerivedKeySize : rZipPackage.GetDefaultDerivedKeySize() );
+ m_nImportedDerivedKeySize ? m_nImportedDerivedKeySize : rZipPackage.GetDefaultDerivedKeySize(),
+ GetStartKeyGenID() );
return xResult;
}
@@ -236,7 +237,7 @@ void ZipPackageStream::SetBaseEncryptionData( const ::rtl::Reference< BaseEncryp
uno::Sequence< sal_Int8 > ZipPackageStream::GetEncryptionKey( bool bUseWinEncoding )
{
uno::Sequence< sal_Int8 > aResult;
- sal_Int32 nKeyGenID = m_nImportedStartKeyAlgorithm ? m_nImportedStartKeyAlgorithm : rZipPackage.GetKeyGenID();
+ sal_Int32 nKeyGenID = GetStartKeyGenID();
bUseWinEncoding = ( bUseWinEncoding || m_bUseWinEncoding );
if ( bHaveOwnKey && m_aStorageEncryptionKeys.getLength() )
@@ -270,10 +271,11 @@ uno::Sequence< sal_Int8 > ZipPackageStream::GetEncryptionKey( bool bUseWinEncodi
}
//--------------------------------------------------------------------------
-sal_Int32 ZipPackageStream::GetKeyGenID()
+sal_Int32 ZipPackageStream::GetStartKeyGenID()
{
- // all the streams must use the same Start Key
- return rZipPackage.GetKeyGenID();
+ // generally should all the streams use the same Start Key
+ // but if raw copy without password takes place, we should preserve the imported algorithm
+ return m_nImportedStartKeyAlgorithm ? m_nImportedStartKeyAlgorithm : rZipPackage.GetStartKeyGenID();
}
//--------------------------------------------------------------------------
@@ -420,7 +422,8 @@ sal_Bool ZipPackageStream::ParsePackageRawStream()
sal_Int32 nEncAlgorithm = 0;
sal_Int32 nChecksumAlgorithm = 0;
sal_Int32 nDerivedKeySize = 0;
- if ( ZipFile::StaticFillData( xTempEncrData, nEncAlgorithm, nChecksumAlgorithm, nDerivedKeySize, nMagHackSize, aMediaType, GetOwnSeekStream() ) )
+ sal_Int32 nStartKeyGenID = 0;
+ if ( ZipFile::StaticFillData( xTempEncrData, nEncAlgorithm, nChecksumAlgorithm, nDerivedKeySize, nStartKeyGenID, nMagHackSize, aMediaType, GetOwnSeekStream() ) )
{
// We'll want to skip the data we've just read, so calculate how much we just read
// and remember it
@@ -431,6 +434,7 @@ sal_Bool ZipPackageStream::ParsePackageRawStream()
m_nImportedEncryptionAlgorithm = nEncAlgorithm;
m_nImportedChecksumAlgorithm = nChecksumAlgorithm;
m_nImportedDerivedKeySize = nDerivedKeySize;
+ m_nImportedStartKeyAlgorithm = nStartKeyGenID;
m_nMagicalHackSize = nMagHackSize;
sMediaType = aMediaType;
@@ -566,7 +570,7 @@ uno::Reference< io::XInputStream > SAL_CALL ZipPackageStream::getDataStream()
catch( packages::WrongPasswordException& )
{
// workaround for the encrypted documents generated with the old OOo1.x bug.
- if ( rZipPackage.GetKeyGenID() == xml::crypto::DigestID::SHA1 && !m_bUseWinEncoding )
+ if ( rZipPackage.GetStartKeyGenID() == xml::crypto::DigestID::SHA1 && !m_bUseWinEncoding )
{
xResult = rZipPackage.getZipFile().getDataStream( aEntry, GetEncryptionData( true ), bIsEncrypted, rZipPackage.GetSharedMutexRef() );
m_bUseWinEncoding = true;