diff options
Diffstat (limited to 'package/source/zippackage')
-rw-r--r-- | package/source/zippackage/ZipPackage.cxx | 575 | ||||
-rw-r--r-- | package/source/zippackage/ZipPackageEntry.cxx | 24 | ||||
-rw-r--r-- | package/source/zippackage/ZipPackageEntry.hxx | 105 | ||||
-rw-r--r-- | package/source/zippackage/ZipPackageFolder.cxx | 197 | ||||
-rw-r--r-- | package/source/zippackage/ZipPackageStream.cxx | 406 | ||||
-rw-r--r-- | package/source/zippackage/ZipPackageStream.hxx | 197 | ||||
-rw-r--r-- | package/source/zippackage/zipfileaccess.cxx | 5 |
7 files changed, 770 insertions, 739 deletions
diff --git a/package/source/zippackage/ZipPackage.cxx b/package/source/zippackage/ZipPackage.cxx index fca0e09f63bd..41d944288d53 100644 --- a/package/source/zippackage/ZipPackage.cxx +++ b/package/source/zippackage/ZipPackage.cxx @@ -16,7 +16,7 @@ * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). + * ( a copy is included in the LICENSE file that accompanied this code ). * * You should have received a copy of the GNU Lesser General Public License * version 3 along with OpenOffice.org. If not, see @@ -25,7 +25,7 @@ * ************************************************************************/ -// MARKER(update_precomp.py): autogen include statement, do not remove +// MARKER( update_precomp.py ): autogen include statement, do not remove #include "precompiled_package.hxx" #include <ZipPackage.hxx> #include <ZipPackageSink.hxx> @@ -63,6 +63,8 @@ #include <com/sun/star/embed/UseBackupException.hpp> #include <com/sun/star/embed/StorageFormats.hpp> #include <com/sun/star/beans/NamedValue.hpp> +#include <com/sun/star/xml/crypto/DigestID.hpp> +#include <com/sun/star/xml/crypto/CipherID.hpp> #include <cppuhelper/implbase1.hxx> #include <ContentInfo.hxx> #include <cppuhelper/typeprovider.hxx> @@ -83,6 +85,7 @@ #include <comphelper/storagehelper.hxx> #include <comphelper/ofopxmlhelper.hxx> #include <comphelper/documentconstants.hxx> +#include <comphelper/sequenceashashmap.hxx> using namespace rtl; using namespace std; @@ -154,35 +157,37 @@ public: class DummyInputStream : public ::cppu::WeakImplHelper1< XInputStream > { - virtual sal_Int32 SAL_CALL readBytes( Sequence< sal_Int8 >&, sal_Int32 ) - throw ( NotConnectedException, BufferSizeExceededException, IOException, RuntimeException) + virtual sal_Int32 SAL_CALL readBytes( uno::Sequence< sal_Int8 >&, sal_Int32 ) + throw ( NotConnectedException, BufferSizeExceededException, IOException, RuntimeException ) { return 0; } - virtual sal_Int32 SAL_CALL readSomeBytes( Sequence< sal_Int8 >&, sal_Int32 ) - throw ( NotConnectedException, BufferSizeExceededException, IOException, RuntimeException) + virtual sal_Int32 SAL_CALL readSomeBytes( uno::Sequence< sal_Int8 >&, sal_Int32 ) + throw ( NotConnectedException, BufferSizeExceededException, IOException, RuntimeException ) { return 0; } virtual void SAL_CALL skipBytes( sal_Int32 ) - throw ( NotConnectedException, BufferSizeExceededException, IOException, RuntimeException) + throw ( NotConnectedException, BufferSizeExceededException, IOException, RuntimeException ) {} virtual sal_Int32 SAL_CALL available() - throw ( NotConnectedException, BufferSizeExceededException, IOException, RuntimeException) + throw ( NotConnectedException, BufferSizeExceededException, IOException, RuntimeException ) { return 0; } virtual void SAL_CALL closeInput() - throw ( NotConnectedException, BufferSizeExceededException, IOException, RuntimeException) + throw ( NotConnectedException, BufferSizeExceededException, IOException, RuntimeException ) {} }; //=========================================================================== -ZipPackage::ZipPackage (const uno::Reference < XMultiServiceFactory > &xNewFactory) +ZipPackage::ZipPackage ( const uno::Reference < XMultiServiceFactory > &xNewFactory ) : m_aMutexHolder( new SotMutexHolder ) +, m_nStartKeyGenerationID( xml::crypto::DigestID::SHA1 ) +, m_nChecksumDigestID( xml::crypto::DigestID::SHA1_1K ) +, m_nCommonEncryptionID( xml::crypto::CipherID::BLOWFISH_CFB_8 ) , m_bHasEncryptedEntries ( sal_False ) , m_bHasNonEncryptedEntries ( sal_False ) , m_bInconsistent ( sal_False ) -, m_bUseManifest ( sal_True ) , m_bForceRecovery ( sal_False ) , m_bMediaTypeFallbackUsed ( sal_False ) , m_nFormat( embed::StorageFormats::PACKAGE ) // package is the default format @@ -204,28 +209,19 @@ ZipPackage::~ZipPackage( void ) // So there is no need in explicit m_pRootFolder->releaseUpwardRef() call here any more // since m_pRootFolder has no parent and cleaning of it's children will be done automatically // during m_pRootFolder dieing by refcount. - -#if 0 - // As all folders and streams contain references to their parents, - // we must remove these references so that they will be deleted when - // the hash_map of the root folder is cleared, releasing all subfolders - // and substreams which in turn release theirs, etc. When m_xRootFolder is - // released when this destructor completes, the folder tree should be - // deleted fully (and automagically). - - m_pRootFolder->releaseUpwardRef(); -#endif } +//-------------------------------------------------------- void ZipPackage::parseManifest() { if ( m_nFormat == embed::StorageFormats::PACKAGE ) { sal_Bool bManifestParsed = sal_False; + bool bDifferentStartKeyAlgorithm = false; const OUString sMeta ( RTL_CONSTASCII_USTRINGPARAM ( "META-INF" ) ); if ( m_xRootFolder->hasByName( sMeta ) ) { - const OUString sManifest (RTL_CONSTASCII_USTRINGPARAM( "manifest.xml") ); + const OUString sManifest ( RTL_CONSTASCII_USTRINGPARAM( "manifest.xml" ) ); try { uno::Reference< XUnoTunnel > xTunnel; @@ -236,11 +232,11 @@ void ZipPackage::parseManifest() { aAny = xMetaInfFolder->getByName( sManifest ); aAny >>= xTunnel; - uno::Reference < XActiveDataSink > xSink (xTunnel, UNO_QUERY); - if (xSink.is()) + uno::Reference < XActiveDataSink > xSink ( xTunnel, UNO_QUERY ); + if ( xSink.is() ) { OUString sManifestReader ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.packages.manifest.ManifestReader" ) ); - uno::Reference < XManifestReader > xReader (m_xFactory->createInstance( sManifestReader ), UNO_QUERY ); + uno::Reference < XManifestReader > xReader ( m_xFactory->createInstance( sManifestReader ), UNO_QUERY ); if ( xReader.is() ) { const OUString sPropFullPath ( RTL_CONSTASCII_USTRINGPARAM ( "FullPath" ) ); @@ -251,45 +247,57 @@ void ZipPackage::parseManifest() const OUString sPropIterationCount ( RTL_CONSTASCII_USTRINGPARAM ( "IterationCount" ) ); const OUString sPropSize ( RTL_CONSTASCII_USTRINGPARAM ( "Size" ) ); const OUString sPropDigest ( RTL_CONSTASCII_USTRINGPARAM ( "Digest" ) ); + const OUString sPropDerivedKeySize ( RTL_CONSTASCII_USTRINGPARAM ( "DerivedKeySize" ) ); + const OUString sPropDigestAlgorithm ( RTL_CONSTASCII_USTRINGPARAM ( "DigestAlgorithm" ) ); + const OUString sPropEncryptionAlgorithm ( RTL_CONSTASCII_USTRINGPARAM ( "EncryptionAlgorithm" ) ); + const OUString sPropStartKeyAlgorithm ( RTL_CONSTASCII_USTRINGPARAM ( "StartKeyAlgorithm" ) ); - Sequence < Sequence < PropertyValue > > aManifestSequence = xReader->readManifestSequence ( xSink->getInputStream() ); + uno::Sequence < uno::Sequence < PropertyValue > > aManifestSequence = xReader->readManifestSequence ( xSink->getInputStream() ); sal_Int32 nLength = aManifestSequence.getLength(); - const Sequence < PropertyValue > *pSequence = aManifestSequence.getConstArray(); + const uno::Sequence < PropertyValue > *pSequence = aManifestSequence.getConstArray(); ZipPackageStream *pStream = NULL; ZipPackageFolder *pFolder = NULL; - for (sal_Int32 i = 0; i < nLength ; i++, pSequence++) + for ( sal_Int32 i = 0; i < nLength ; i++, pSequence++ ) { OUString sPath, sMediaType, sVersion; const PropertyValue *pValue = pSequence->getConstArray(); - const Any *pSalt = NULL, *pVector = NULL, *pCount = NULL, *pSize = NULL, *pDigest = NULL; - for (sal_Int32 j = 0, nNum = pSequence->getLength(); j < nNum; j++ ) + const Any *pSalt = NULL, *pVector = NULL, *pCount = NULL, *pSize = NULL, *pDigest = NULL, *pDigestAlg = NULL, *pEncryptionAlg = NULL, *pStartKeyAlg = NULL, *pDerivedKeySize = NULL; + for ( sal_Int32 j = 0, nNum = pSequence->getLength(); j < nNum; j++ ) { - if (pValue[j].Name.equals( sPropFullPath ) ) + if ( pValue[j].Name.equals( sPropFullPath ) ) pValue[j].Value >>= sPath; - else if (pValue[j].Name.equals( sPropVersion ) ) + else if ( pValue[j].Name.equals( sPropVersion ) ) pValue[j].Value >>= sVersion; - else if (pValue[j].Name.equals( sPropMediaType ) ) + else if ( pValue[j].Name.equals( sPropMediaType ) ) pValue[j].Value >>= sMediaType; - else if (pValue[j].Name.equals( sPropSalt ) ) - pSalt = &(pValue[j].Value); - else if (pValue[j].Name.equals( sPropInitialisationVector ) ) - pVector = &(pValue[j].Value); - else if (pValue[j].Name.equals( sPropIterationCount ) ) - pCount = &(pValue[j].Value); - else if (pValue[j].Name.equals( sPropSize ) ) - pSize = &(pValue[j].Value); - else if (pValue[j].Name.equals( sPropDigest ) ) - pDigest = &(pValue[j].Value); + else if ( pValue[j].Name.equals( sPropSalt ) ) + pSalt = &( pValue[j].Value ); + else if ( pValue[j].Name.equals( sPropInitialisationVector ) ) + pVector = &( pValue[j].Value ); + else if ( pValue[j].Name.equals( sPropIterationCount ) ) + pCount = &( pValue[j].Value ); + else if ( pValue[j].Name.equals( sPropSize ) ) + pSize = &( pValue[j].Value ); + else if ( pValue[j].Name.equals( sPropDigest ) ) + pDigest = &( pValue[j].Value ); + else if ( pValue[j].Name.equals( sPropDigestAlgorithm ) ) + pDigestAlg = &( pValue[j].Value ); + else if ( pValue[j].Name.equals( sPropEncryptionAlgorithm ) ) + pEncryptionAlg = &( pValue[j].Value ); + else if ( pValue[j].Name.equals( sPropStartKeyAlgorithm ) ) + pStartKeyAlg = &( pValue[j].Value ); + else if ( pValue[j].Name.equals( sPropDerivedKeySize ) ) + pDerivedKeySize = &( pValue[j].Value ); } - if (sPath.getLength() && hasByHierarchicalName ( sPath ) ) + if ( sPath.getLength() && hasByHierarchicalName ( sPath ) ) { aAny = getByHierarchicalName( sPath ); uno::Reference < XUnoTunnel > xUnoTunnel; aAny >>= xUnoTunnel; sal_Int64 nTest=0; - if ((nTest = xUnoTunnel->getSomething(ZipPackageFolder::static_getImplementationId())) != 0) + if ( (nTest = xUnoTunnel->getSomething( ZipPackageFolder::static_getImplementationId() )) != 0 ) { pFolder = reinterpret_cast < ZipPackageFolder* > ( nTest ); pFolder->SetMediaType ( sMediaType ); @@ -297,15 +305,16 @@ void ZipPackage::parseManifest() } else { - pStream = reinterpret_cast < ZipPackageStream* > ( xUnoTunnel->getSomething(ZipPackageStream::static_getImplementationId())); + pStream = reinterpret_cast < ZipPackageStream* > ( xUnoTunnel->getSomething( ZipPackageStream::static_getImplementationId() )); pStream->SetMediaType ( sMediaType ); pStream->SetFromManifest( sal_True ); - if (pSalt && pVector && pCount && pSize) + if ( pSalt && pVector && pCount && pSize && pDigest && pDigestAlg && pEncryptionAlg ) { - Sequence < sal_uInt8 > aSequence; - sal_Int32 nCount = 0, nSize = 0; - pStream->SetToBeEncrypted ( sal_True ); + uno::Sequence < sal_Int8 > aSequence; + sal_Int32 nCount = 0, nSize = 0, nDigestAlg = 0, nEncryptionAlg = 0, nDerivedKeySize = 16, nStartKeyAlg = xml::crypto::DigestID::SHA1; + + pStream->SetToBeEncrypted ( sal_True ); *pSalt >>= aSequence; pStream->setSalt ( aSequence ); @@ -319,18 +328,34 @@ void ZipPackage::parseManifest() *pSize >>= nSize; pStream->setSize ( nSize ); - if ( pDigest ) - { - *pDigest >>= aSequence; - pStream->setDigest ( aSequence ); - } + *pDigest >>= aSequence; + pStream->setDigest ( aSequence ); + + *pDigestAlg >>= nDigestAlg; + pStream->SetImportedChecksumAlgorithm( nDigestAlg ); + + *pEncryptionAlg >>= nEncryptionAlg; + pStream->SetImportedEncryptionAlgorithm( nEncryptionAlg ); + + if ( pDerivedKeySize ) + *pDerivedKeySize >>= nDerivedKeySize; + pStream->SetImportedDerivedKeySize( nDerivedKeySize ); + + if ( pStartKeyAlg ) + *pStartKeyAlg >>= nStartKeyAlg; + pStream->SetImportedStartKeyAlgorithm( nStartKeyAlg ); pStream->SetToBeCompressed ( sal_True ); pStream->SetToBeEncrypted ( sal_True ); pStream->SetIsEncrypted ( sal_True ); if ( !m_bHasEncryptedEntries && pStream->getName().equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "content.xml" ) ) ) ) + { m_bHasEncryptedEntries = sal_True; + m_nStartKeyGenerationID = nStartKeyAlg; + m_nChecksumDigestID = nDigestAlg; + m_nCommonEncryptionID = nEncryptionAlg; + } } else m_bHasNonEncryptedEntries = sal_True; @@ -380,7 +405,7 @@ void ZipPackage::parseManifest() nRead = aData.getLength(); if ( nRead ) - aPackageMediatype = ::rtl::OUString( (sal_Char*)aData.getConstArray(), nRead, RTL_TEXTENCODING_ASCII_US ); + aPackageMediatype = ::rtl::OUString( ( sal_Char* )aData.getConstArray(), nRead, RTL_TEXTENCODING_ASCII_US ); } } @@ -409,24 +434,35 @@ void ZipPackage::parseManifest() m_bInconsistent = m_pRootFolder->LookForUnexpectedODF12Streams( ::rtl::OUString() ); - sal_Bool bODF12AndOlder = ( m_pRootFolder->GetVersion().compareTo( ODFVER_012_TEXT ) >= 0 ); - if ( !m_bForceRecovery && bODF12AndOlder && m_bInconsistent ) + sal_Bool bODF12AndNewer = ( m_pRootFolder->GetVersion().compareTo( ODFVER_012_TEXT ) >= 0 ); + if ( !m_bForceRecovery && bODF12AndNewer ) { - // this is an ODF1.2 document that contains streams not referred in the manifest.xml; - // in case of ODF1.2 documents without version in manifest.xml the property IsInconsistent - // should be checked later - throw ZipIOException( - ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "there are streams not referred in manifest.xml\n" ) ), - uno::Reference< uno::XInterface >() ); + if ( m_bInconsistent ) + { + // this is an ODF1.2 document that contains streams not referred in the manifest.xml; + // in case of ODF1.2 documents without version in manifest.xml the property IsInconsistent + // should be checked later + throw ZipIOException( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "there are streams not referred in manifest.xml\n" ) ), + uno::Reference< uno::XInterface >() ); + } + else if ( bDifferentStartKeyAlgorithm ) + { + // all the streams should be encrypted with the same StartKey in ODF1.2 + // TODO/LATER: in future the exception should be thrown + OSL_ENSURE( false, "ODF1.2 contains different StartKey Algorithms" ); + // throw ZipIOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "More than one Start Key Generation algorithm is specified!" ) ), uno::Reference< uno::XInterface >() ); + } } // in case it is a correct ODF1.2 document, the version must be set // and the META-INF folder is reserved for package format - if ( bODF12AndOlder ) + if ( bODF12AndNewer ) m_xRootFolder->removeByName( sMeta ); } } +//-------------------------------------------------------- void ZipPackage::parseContentType() { if ( m_nFormat == embed::StorageFormats::OFOPXML ) @@ -463,7 +499,7 @@ void ZipPackage::parseContentType() for ( nInd = 0; nInd < aContentTypeInfo[1].getLength(); nInd++ ) { ::rtl::OUString aPath; - if ( aContentTypeInfo[1][nInd].First.toChar() == (sal_Unicode)'/' ) + if ( aContentTypeInfo[1][nInd].First.toChar() == ( sal_Unicode )'/' ) aPath = aContentTypeInfo[1][nInd].First.copy( 1 ); else aPath = aContentTypeInfo[1][nInd].First; @@ -495,6 +531,7 @@ void ZipPackage::parseContentType() } } +//-------------------------------------------------------- void ZipPackage::getZipFileContents() { auto_ptr < ZipEnumeration > pEnum ( m_pZipFile->entries() ); @@ -504,7 +541,7 @@ void ZipPackage::getZipFileContents() sal_Int32 nOldIndex, nIndex, nStreamIndex; FolderHash::iterator aIter; - while (pEnum->hasMoreElements()) + while ( pEnum->hasMoreElements() ) { nIndex = nOldIndex = 0; pCurrent = m_pRootFolder; @@ -521,18 +558,18 @@ void ZipPackage::getZipFileContents() nStreamIndex = rName.lastIndexOf ( '/' ); if ( nStreamIndex != -1 ) { - sDirName = rName.copy ( 0, nStreamIndex); + sDirName = rName.copy ( 0, nStreamIndex ); aIter = m_aRecent.find ( sDirName ); if ( aIter != m_aRecent.end() ) - pCurrent = (*aIter).second; + pCurrent = ( *aIter ).second; } if ( pCurrent == m_pRootFolder ) { - while ( (nIndex = rName.indexOf('/', nOldIndex) ) != -1 ) + while ( ( nIndex = rName.indexOf( '/', nOldIndex ) ) != -1 ) { sTemp = rName.copy ( nOldIndex, nIndex - nOldIndex ); - if (nIndex == nOldIndex) + if ( nIndex == nOldIndex ) break; if ( !pCurrent->hasByName( sTemp ) ) { @@ -542,7 +579,7 @@ void ZipPackage::getZipFileContents() pCurrent = pPkgFolder; } else - pCurrent = pCurrent->doGetByName(sTemp).pFolder; + pCurrent = pCurrent->doGetByName( sTemp ).pFolder; nOldIndex = nIndex+1; } if ( nStreamIndex != -1 && sDirName.getLength() ) @@ -551,7 +588,7 @@ void ZipPackage::getZipFileContents() if ( rName.getLength() -1 != nStreamIndex ) { nStreamIndex++; - sTemp = rName.copy( nStreamIndex, rName.getLength() - nStreamIndex); + sTemp = rName.copy( nStreamIndex, rName.getLength() - nStreamIndex ); pPkgStream = new ZipPackageStream( *this, m_xFactory, m_bAllowRemoveOnInsert ); pPkgStream->SetPackageMember( sal_True ); pPkgStream->setZipEntryOnLoading( rEntry ); @@ -566,9 +603,9 @@ void ZipPackage::getZipFileContents() parseContentType(); } -// XInitialization -void SAL_CALL ZipPackage::initialize( const Sequence< Any >& aArguments ) - throw(Exception, RuntimeException) +//-------------------------------------------------------- +void SAL_CALL ZipPackage::initialize( const uno::Sequence< Any >& aArguments ) + throw( Exception, RuntimeException ) { RTL_LOGFILE_TRACE_AUTHOR ( "package", LOGFILE_AUTHOR, "{ ZipPackage::initialize" ); sal_Bool bBadZipFile = sal_False, bHaveZipFile = sal_True; @@ -580,7 +617,7 @@ void SAL_CALL ZipPackage::initialize( const Sequence< Any >& aArguments ) for( int ind = 0; ind < aArguments.getLength(); ind++ ) { OUString aParamUrl; - if ( (aArguments[ind] >>= aParamUrl)) + if ( ( aArguments[ind] >>= aParamUrl )) { m_eMode = e_IMode_URL; try @@ -627,13 +664,13 @@ void SAL_CALL ZipPackage::initialize( const Sequence< Any >& aArguments ) if( !bHasSizeProperty || ( bHasSizeProperty && aSize ) ) { uno::Reference < XActiveDataSink > xSink = new ZipPackageSink; - if (aContent.openStream ( xSink ) ) + if ( aContent.openStream ( xSink ) ) m_xContentStream = xSink->getInputStream(); } else bHaveZipFile = sal_False; } - catch (com::sun::star::uno::Exception&) + catch ( com::sun::star::uno::Exception& ) { // Exception derived from uno::Exception thrown. This probably // means the file doesn't exist...we'll create it at @@ -641,13 +678,13 @@ void SAL_CALL ZipPackage::initialize( const Sequence< Any >& aArguments ) bHaveZipFile = sal_False; } } - else if ( (aArguments[ind] >>= m_xStream ) ) + else if ( ( aArguments[ind] >>= m_xStream ) ) { // a writable stream can implement both XStream & XInputStream m_eMode = e_IMode_XStream; m_xContentStream = m_xStream->getInputStream(); } - else if ( (aArguments[ind] >>= m_xContentStream) ) + else if ( ( aArguments[ind] >>= m_xContentStream ) ) { m_eMode = e_IMode_XInputStream; } @@ -715,7 +752,7 @@ void SAL_CALL ZipPackage::initialize( const Sequence< Any >& aArguments ) try { - if (m_xContentStream.is()) + if ( m_xContentStream.is() ) { // the stream must be seekable, if it is not it will be wrapped m_xContentStream = ::comphelper::OSeekableInputWrapper::CheckSeekableCanWrap( m_xContentStream, m_xFactory ); @@ -730,7 +767,7 @@ void SAL_CALL ZipPackage::initialize( const Sequence< Any >& aArguments ) else bHaveZipFile = sal_False; } - catch (com::sun::star::uno::Exception&) + catch ( com::sun::star::uno::Exception& ) { // Exception derived from uno::Exception thrown. This probably // means the file doesn't exist...we'll create it at @@ -773,22 +810,23 @@ void SAL_CALL ZipPackage::initialize( const Sequence< Any >& aArguments ) RTL_LOGFILE_TRACE_AUTHOR ( "package", LOGFILE_AUTHOR, "} ZipPackage::initialize" ); } +//-------------------------------------------------------- Any SAL_CALL ZipPackage::getByHierarchicalName( const OUString& aName ) - throw(NoSuchElementException, RuntimeException) + throw( NoSuchElementException, RuntimeException ) { OUString sTemp, sDirName; sal_Int32 nOldIndex, nIndex, nStreamIndex; FolderHash::iterator aIter; - if ( (nIndex = aName.getLength() ) == 1 && *aName.getStr() == '/' ) - return makeAny ( uno::Reference < XUnoTunnel > (m_pRootFolder) ); + if ( ( nIndex = aName.getLength() ) == 1 && *aName.getStr() == '/' ) + return makeAny ( uno::Reference < XUnoTunnel > ( m_pRootFolder ) ); else { nStreamIndex = aName.lastIndexOf ( '/' ); bool bFolder = nStreamIndex == nIndex-1; if ( nStreamIndex != -1 ) { - sDirName = aName.copy ( 0, nStreamIndex); + sDirName = aName.copy ( 0, nStreamIndex ); aIter = m_aRecent.find ( sDirName ); if ( aIter != m_aRecent.end() ) { @@ -796,16 +834,16 @@ Any SAL_CALL ZipPackage::getByHierarchicalName( const OUString& aName ) { sal_Int32 nDirIndex = aName.lastIndexOf ( '/', nStreamIndex ); sTemp = aName.copy ( nDirIndex == -1 ? 0 : nDirIndex+1, nStreamIndex-nDirIndex-1 ); - if ( sTemp == (*aIter).second->getName() ) - return makeAny ( uno::Reference < XUnoTunnel > ( (*aIter).second ) ); + if ( sTemp == ( *aIter ).second->getName() ) + return makeAny ( uno::Reference < XUnoTunnel > ( ( *aIter ).second ) ); else m_aRecent.erase ( aIter ); } else { sTemp = aName.copy ( nStreamIndex + 1 ); - if ( (*aIter).second->hasByName( sTemp ) ) - return (*aIter).second->getByName( sTemp ); + if ( ( *aIter ).second->hasByName( sTemp ) ) + return ( *aIter ).second->getByName( sTemp ); else m_aRecent.erase( aIter ); } @@ -819,15 +857,15 @@ Any SAL_CALL ZipPackage::getByHierarchicalName( const OUString& aName ) nOldIndex = 0; ZipPackageFolder * pCurrent = m_pRootFolder; ZipPackageFolder * pPrevious = NULL; - while ( ( nIndex = aName.indexOf('/', nOldIndex)) != -1) + while ( ( nIndex = aName.indexOf( '/', nOldIndex )) != -1 ) { - sTemp = aName.copy (nOldIndex, nIndex - nOldIndex); + sTemp = aName.copy ( nOldIndex, nIndex - nOldIndex ); if ( nIndex == nOldIndex ) break; if ( pCurrent->hasByName( sTemp ) ) { pPrevious = pCurrent; - pCurrent = pCurrent->doGetByName(sTemp).pFolder; + pCurrent = pCurrent->doGetByName( sTemp ).pFolder; } else throw NoSuchElementException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); @@ -835,16 +873,16 @@ Any SAL_CALL ZipPackage::getByHierarchicalName( const OUString& aName ) } if ( bFolder ) { - if (nStreamIndex != -1 ) + if ( nStreamIndex != -1 ) m_aRecent[sDirName] = pPrevious; return makeAny ( uno::Reference < XUnoTunnel > ( pCurrent ) ); } else { - sTemp = aName.copy( nOldIndex, aName.getLength() - nOldIndex); + sTemp = aName.copy( nOldIndex, aName.getLength() - nOldIndex ); if ( pCurrent->hasByName ( sTemp ) ) { - if (nStreamIndex != -1 ) + if ( nStreamIndex != -1 ) m_aRecent[sDirName] = pCurrent; return pCurrent->getByName( sTemp ); } @@ -854,14 +892,15 @@ Any SAL_CALL ZipPackage::getByHierarchicalName( const OUString& aName ) } } +//-------------------------------------------------------- sal_Bool SAL_CALL ZipPackage::hasByHierarchicalName( const OUString& aName ) - throw(RuntimeException) + throw( RuntimeException ) { OUString sTemp, sDirName; sal_Int32 nOldIndex, nIndex, nStreamIndex; FolderHash::iterator aIter; - if ( (nIndex = aName.getLength() ) == 1 && *aName.getStr() == '/' ) + if ( ( nIndex = aName.getLength() ) == 1 && *aName.getStr() == '/' ) return sal_True; else { @@ -869,7 +908,7 @@ sal_Bool SAL_CALL ZipPackage::hasByHierarchicalName( const OUString& aName ) bool bFolder = nStreamIndex == nIndex-1; if ( nStreamIndex != -1 ) { - sDirName = aName.copy ( 0, nStreamIndex); + sDirName = aName.copy ( 0, nStreamIndex ); aIter = m_aRecent.find ( sDirName ); if ( aIter != m_aRecent.end() ) { @@ -877,7 +916,7 @@ sal_Bool SAL_CALL ZipPackage::hasByHierarchicalName( const OUString& aName ) { sal_Int32 nDirIndex = aName.lastIndexOf ( '/', nStreamIndex ); sTemp = aName.copy ( nDirIndex == -1 ? 0 : nDirIndex+1, nStreamIndex-nDirIndex-1 ); - if ( sTemp == (*aIter).second->getName() ) + if ( sTemp == ( *aIter ).second->getName() ) return sal_True; else m_aRecent.erase ( aIter ); @@ -885,7 +924,7 @@ sal_Bool SAL_CALL ZipPackage::hasByHierarchicalName( const OUString& aName ) else { sTemp = aName.copy ( nStreamIndex + 1 ); - if ( (*aIter).second->hasByName( sTemp ) ) + if ( ( *aIter ).second->hasByName( sTemp ) ) return sal_True; else m_aRecent.erase( aIter ); @@ -900,9 +939,9 @@ sal_Bool SAL_CALL ZipPackage::hasByHierarchicalName( const OUString& aName ) ZipPackageFolder * pCurrent = m_pRootFolder; ZipPackageFolder * pPrevious = NULL; nOldIndex = 0; - while ( ( nIndex = aName.indexOf('/', nOldIndex)) != -1) + while ( ( nIndex = aName.indexOf( '/', nOldIndex )) != -1 ) { - sTemp = aName.copy (nOldIndex, nIndex - nOldIndex); + sTemp = aName.copy ( nOldIndex, nIndex - nOldIndex ); if ( nIndex == nOldIndex ) break; if ( pCurrent->hasByName( sTemp ) ) @@ -921,7 +960,7 @@ sal_Bool SAL_CALL ZipPackage::hasByHierarchicalName( const OUString& aName ) } else { - sTemp = aName.copy( nOldIndex, aName.getLength() - nOldIndex); + sTemp = aName.copy( nOldIndex, aName.getLength() - nOldIndex ); if ( pCurrent->hasByName( sTemp ) ) { @@ -933,21 +972,22 @@ sal_Bool SAL_CALL ZipPackage::hasByHierarchicalName( const OUString& aName ) } } -// XSingleServiceFactory -uno::Reference< XInterface > SAL_CALL ZipPackage::createInstance( ) - throw(Exception, RuntimeException) +//-------------------------------------------------------- +uno::Reference< XInterface > SAL_CALL ZipPackage::createInstance() + throw( Exception, RuntimeException ) { - uno::Reference < XInterface > xRef = *(new ZipPackageStream ( *this, m_xFactory, m_bAllowRemoveOnInsert )); + uno::Reference < XInterface > xRef = *( new ZipPackageStream ( *this, m_xFactory, m_bAllowRemoveOnInsert ) ); return xRef; } -uno::Reference< XInterface > SAL_CALL ZipPackage::createInstanceWithArguments( const Sequence< Any >& aArguments ) - throw(Exception, RuntimeException) +//-------------------------------------------------------- +uno::Reference< XInterface > SAL_CALL ZipPackage::createInstanceWithArguments( const uno::Sequence< Any >& aArguments ) + throw( Exception, RuntimeException ) { sal_Bool bArg = sal_False; uno::Reference < XInterface > xRef; if ( aArguments.getLength() ) aArguments[0] >>= bArg; - if (bArg) + if ( bArg ) xRef = *new ZipPackageFolder ( m_xFactory, m_nFormat, m_bAllowRemoveOnInsert ); else xRef = *new ZipPackageStream ( *this, m_xFactory, m_bAllowRemoveOnInsert ); @@ -955,16 +995,17 @@ uno::Reference< XInterface > SAL_CALL ZipPackage::createInstanceWithArguments( c return xRef; } +//-------------------------------------------------------- void ZipPackage::WriteMimetypeMagicFile( ZipOutputStream& aZipOut ) { const OUString sMime ( RTL_CONSTASCII_USTRINGPARAM ( "mimetype" ) ); - if (m_xRootFolder->hasByName( sMime ) ) + if ( m_xRootFolder->hasByName( sMime ) ) m_xRootFolder->removeByName( sMime ); ZipEntry * pEntry = new ZipEntry; - sal_Int32 nBufferLength = m_pRootFolder->GetMediaType( ).getLength(); + sal_Int32 nBufferLength = m_pRootFolder->GetMediaType().getLength(); OString sMediaType = OUStringToOString( m_pRootFolder->GetMediaType(), RTL_TEXTENCODING_ASCII_US ); - Sequence< sal_Int8 > aType( (sal_Int8*)sMediaType.getStr(), + uno::Sequence< sal_Int8 > aType( ( sal_Int8* )sMediaType.getStr(), nBufferLength ); @@ -979,14 +1020,12 @@ void ZipPackage::WriteMimetypeMagicFile( ZipOutputStream& aZipOut ) try { - vos::ORef < EncryptionData > xEmpty; - aZipOut.putNextEntry( *pEntry, xEmpty ); + aZipOut.putNextEntry( *pEntry, NULL ); aZipOut.write( aType, 0, nBufferLength ); aZipOut.closeEntry(); } catch ( ::com::sun::star::io::IOException & r ) { - VOS_ENSURE( 0, "Error adding mimetype to the ZipOutputStream" ); throw WrappedTargetException( OUString( RTL_CONSTASCII_USTRINGPARAM ( OSL_LOG_PREFIX "Error adding mimetype to the ZipOutputStream!" ) ), static_cast < OWeakObject * > ( this ), @@ -994,7 +1033,8 @@ void ZipPackage::WriteMimetypeMagicFile( ZipOutputStream& aZipOut ) } } -void ZipPackage::WriteManifest( ZipOutputStream& aZipOut, const vector< Sequence < PropertyValue > >& aManList ) +//-------------------------------------------------------- +void ZipPackage::WriteManifest( ZipOutputStream& aZipOut, const vector< uno::Sequence < PropertyValue > >& aManList ) { // Write the manifest uno::Reference < XOutputStream > xManOutStream; @@ -1004,28 +1044,29 @@ void ZipPackage::WriteManifest( ZipOutputStream& aZipOut, const vector< Sequence { ZipEntry * pEntry = new ZipEntry; ZipPackageBuffer *pBuffer = new ZipPackageBuffer( n_ConstBufferSize ); - xManOutStream = uno::Reference < XOutputStream > (*pBuffer, UNO_QUERY); + xManOutStream = uno::Reference < XOutputStream > ( *pBuffer, UNO_QUERY ); - pEntry->sPath = OUString( RTL_CONSTASCII_USTRINGPARAM ( "META-INF/manifest.xml") ); + pEntry->sPath = OUString( RTL_CONSTASCII_USTRINGPARAM ( "META-INF/manifest.xml" ) ); pEntry->nMethod = DEFLATED; pEntry->nCrc = pEntry->nSize = pEntry->nCompressedSize = -1; pEntry->nTime = ZipOutputStream::getCurrentDosTime(); - // Convert vector into a Sequence - Sequence < Sequence < PropertyValue > > aManifestSequence ( aManList.size() ); - Sequence < PropertyValue > * pSequence = aManifestSequence.getArray(); - for (vector < Sequence < PropertyValue > >::const_iterator aIter = aManList.begin(), aEnd = aManList.end(); + // Convert vector into a uno::Sequence + uno::Sequence < uno::Sequence < PropertyValue > > aManifestSequence ( aManList.size() ); + sal_Int32 nInd = 0; + for ( vector < uno::Sequence < PropertyValue > >::const_iterator aIter = aManList.begin(), aEnd = aManList.end(); aIter != aEnd; - aIter++, pSequence++) - *pSequence= (*aIter); + aIter++, nInd++ ) + { + aManifestSequence[nInd] = ( *aIter ); + } xWriter->writeManifestSequence ( xManOutStream, aManifestSequence ); sal_Int32 nBufferLength = static_cast < sal_Int32 > ( pBuffer->getPosition() ); pBuffer->realloc( nBufferLength ); // the manifest.xml is never encrypted - so pass an empty reference - vos::ORef < EncryptionData > xEmpty; - aZipOut.putNextEntry( *pEntry, xEmpty ); + aZipOut.putNextEntry( *pEntry, NULL ); aZipOut.write( pBuffer->getSequence(), 0, nBufferLength ); aZipOut.closeEntry(); } @@ -1040,7 +1081,8 @@ void ZipPackage::WriteManifest( ZipOutputStream& aZipOut, const vector< Sequence } } -void ZipPackage::WriteContentTypes( ZipOutputStream& aZipOut, const vector< Sequence < PropertyValue > >& aManList ) +//-------------------------------------------------------- +void ZipPackage::WriteContentTypes( ZipOutputStream& aZipOut, const vector< uno::Sequence < PropertyValue > >& aManList ) { const OUString sFullPath ( RTL_CONSTASCII_USTRINGPARAM ( "FullPath" ) ); const OUString sMediaType ( RTL_CONSTASCII_USTRINGPARAM ( "MediaType" ) ); @@ -1049,12 +1091,12 @@ void ZipPackage::WriteContentTypes( ZipOutputStream& aZipOut, const vector< Sequ ZipPackageBuffer *pBuffer = new ZipPackageBuffer( n_ConstBufferSize ); uno::Reference< io::XOutputStream > xConTypeOutStream( *pBuffer, UNO_QUERY ); - pEntry->sPath = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "[Content_Types].xml") ); + pEntry->sPath = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "[Content_Types].xml" ) ); pEntry->nMethod = DEFLATED; pEntry->nCrc = pEntry->nSize = pEntry->nCompressedSize = -1; pEntry->nTime = ZipOutputStream::getCurrentDosTime(); - // Convert vector into a Sequence + // Convert vector into a uno::Sequence // TODO/LATER: use Defaulst entries in future uno::Sequence< beans::StringPair > aDefaultsSequence; uno::Sequence< beans::StringPair > aOverridesSequence( aManList.size() ); @@ -1062,18 +1104,18 @@ void ZipPackage::WriteContentTypes( ZipOutputStream& aZipOut, const vector< Sequ for ( vector< uno::Sequence< beans::PropertyValue > >::const_iterator aIter = aManList.begin(), aEnd = aManList.end(); aIter != aEnd; - aIter++) + aIter++ ) { ::rtl::OUString aPath; ::rtl::OUString aType; - OSL_ENSURE( (*aIter)[PKG_MNFST_MEDIATYPE].Name.equals( sMediaType ) && (*aIter)[PKG_MNFST_FULLPATH].Name.equals( sFullPath ), + OSL_ENSURE( ( *aIter )[PKG_MNFST_MEDIATYPE].Name.equals( sMediaType ) && ( *aIter )[PKG_MNFST_FULLPATH].Name.equals( sFullPath ), "The mediatype sequence format is wrong!\n" ); - (*aIter)[PKG_MNFST_MEDIATYPE].Value >>= aType; + ( *aIter )[PKG_MNFST_MEDIATYPE].Value >>= aType; if ( aType.getLength() ) { // only nonempty type makes sence here nSeqLength++; - (*aIter)[PKG_MNFST_FULLPATH].Value >>= aPath; + ( *aIter )[PKG_MNFST_FULLPATH].Value >>= aPath; aOverridesSequence[nSeqLength-1].First = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/" ) ) + aPath; aOverridesSequence[nSeqLength-1].Second = aType; } @@ -1087,12 +1129,12 @@ void ZipPackage::WriteContentTypes( ZipOutputStream& aZipOut, const vector< Sequ pBuffer->realloc( nBufferLength ); // there is no encryption in this format currently - vos::ORef < EncryptionData > xEmpty; - aZipOut.putNextEntry( *pEntry, xEmpty ); + aZipOut.putNextEntry( *pEntry, NULL ); aZipOut.write( pBuffer->getSequence(), 0, nBufferLength ); aZipOut.closeEntry(); } +//-------------------------------------------------------- void ZipPackage::ConnectTo( const uno::Reference< io::XInputStream >& xInStream ) { m_xContentSeek.set( xInStream, uno::UNO_QUERY_THROW ); @@ -1106,6 +1148,7 @@ void ZipPackage::ConnectTo( const uno::Reference< io::XInputStream >& xInStream m_pZipFile = new ZipFile ( m_xContentStream, m_xFactory, sal_False ); } +//-------------------------------------------------------- uno::Reference< io::XInputStream > ZipPackage::writeTempFile() { // In case the target local file does not exist or empty @@ -1152,9 +1195,9 @@ uno::Reference< io::XInputStream > ZipPackage::writeTempFile() } // Hand it to the ZipOutputStream: - ZipOutputStream aZipOut ( xTempOut ); - aZipOut.setMethod(DEFLATED); - aZipOut.setLevel(DEFAULT_COMPRESSION); + ZipOutputStream aZipOut( m_xFactory, xTempOut ); + aZipOut.setMethod( DEFLATED ); + aZipOut.setLevel( DEFAULT_COMPRESSION ); try { @@ -1167,7 +1210,7 @@ uno::Reference< io::XInputStream > ZipPackage::writeTempFile() if ( m_xRootFolder->hasByName( sMeta ) ) { - const OUString sManifest (RTL_CONSTASCII_USTRINGPARAM( "manifest.xml") ); + const OUString sManifest ( RTL_CONSTASCII_USTRINGPARAM( "manifest.xml" ) ); uno::Reference< XUnoTunnel > xTunnel; Any aAny = m_xRootFolder->getByName( sMeta ); @@ -1192,7 +1235,7 @@ uno::Reference< io::XInputStream > ZipPackage::writeTempFile() } // Create a vector to store data for the manifest.xml file - vector < Sequence < PropertyValue > > aManList; + vector < uno::Sequence < PropertyValue > > aManList; const OUString sMediaType ( RTL_CONSTASCII_USTRINGPARAM ( "MediaType" ) ); const OUString sVersion ( RTL_CONSTASCII_USTRINGPARAM ( "Version" ) ); @@ -1200,11 +1243,11 @@ uno::Reference< io::XInputStream > ZipPackage::writeTempFile() if ( m_nFormat == embed::StorageFormats::PACKAGE ) { - Sequence < PropertyValue > aPropSeq ( PKG_SIZE_NOENCR_MNFST ); + uno::Sequence < PropertyValue > aPropSeq( PKG_SIZE_NOENCR_MNFST ); aPropSeq [PKG_MNFST_MEDIATYPE].Name = sMediaType; - aPropSeq [PKG_MNFST_MEDIATYPE].Value <<= m_pRootFolder->GetMediaType( ); + aPropSeq [PKG_MNFST_MEDIATYPE].Value <<= m_pRootFolder->GetMediaType(); aPropSeq [PKG_MNFST_VERSION].Name = sVersion; - aPropSeq [PKG_MNFST_VERSION].Value <<= m_pRootFolder->GetVersion( ); + aPropSeq [PKG_MNFST_VERSION].Value <<= m_pRootFolder->GetVersion(); aPropSeq [PKG_MNFST_FULLPATH].Name = sFullPath; aPropSeq [PKG_MNFST_FULLPATH].Value <<= OUString ( RTL_CONSTASCII_USTRINGPARAM ( "/" ) ); @@ -1219,15 +1262,14 @@ uno::Reference< io::XInputStream > ZipPackage::writeTempFile() rtlRandomPool aRandomPool = rtl_random_createPool (); rtl_random_addBytes ( aRandomPool, &aTime, 8 ); - - // call saveContents (it will recursively save sub-directories + // call saveContents ( it will recursively save sub-directories OUString aEmptyString; - m_pRootFolder->saveContents( aEmptyString, aManList, aZipOut, m_aEncryptionKey, aRandomPool ); + m_pRootFolder->saveContents( aEmptyString, aManList, aZipOut, GetEncryptionKey(), aRandomPool ); // Clean up random pool memory rtl_random_destroyPool ( aRandomPool ); - if( m_bUseManifest && m_nFormat == embed::StorageFormats::PACKAGE ) + if( m_nFormat == embed::StorageFormats::PACKAGE ) { WriteManifest( aZipOut, aManList ); } @@ -1296,10 +1338,11 @@ uno::Reference< io::XInputStream > ZipPackage::writeTempFile() return xResult; } +//-------------------------------------------------------- uno::Reference< XActiveDataStreamer > ZipPackage::openOriginalForOutput() { // open and truncate the original file - Content aOriginalContent (m_aURL, uno::Reference < XCommandEnvironment >() ); + Content aOriginalContent ( m_aURL, uno::Reference < XCommandEnvironment >() ); uno::Reference< XActiveDataStreamer > xSink = new ActiveDataStreamer; if ( m_eMode == e_IMode_URL ) @@ -1333,7 +1376,7 @@ uno::Reference< XActiveDataStreamer > ZipPackage::openOriginalForOutput() aArg.Mode = OpenMode::DOCUMENT; aArg.Priority = 0; // unused aArg.Sink = xSink; - aArg.Properties = Sequence< Property >( 0 ); // unused + aArg.Properties = uno::Sequence< Property >( 0 ); // unused aOriginalContent.executeCommand( OUString::createFromAscii( "open" ), makeAny( aArg ) ); } @@ -1347,9 +1390,9 @@ uno::Reference< XActiveDataStreamer > ZipPackage::openOriginalForOutput() return xSink; } -// XChangesBatch +//-------------------------------------------------------- void SAL_CALL ZipPackage::commitChanges() - throw(WrappedTargetException, RuntimeException) + throw( WrappedTargetException, RuntimeException ) { // lock the component for the time of commiting ::osl::MutexGuard aGuard( m_aMutexHolder->GetMutex() ); @@ -1412,8 +1455,8 @@ void SAL_CALL ZipPackage::commitChanges() ::comphelper::OStorageHelper::CopyInputToOutput( xTempInStream, xOutputStream ); xOutputStream->flush(); uno::Reference< io::XAsyncOutputMonitor > asyncOutputMonitor( - xOutputStream, uno::UNO_QUERY); - if (asyncOutputMonitor.is()) { + xOutputStream, uno::UNO_QUERY ); + if ( asyncOutputMonitor.is() ) { asyncOutputMonitor->waitForCompletion(); } } @@ -1499,7 +1542,7 @@ void SAL_CALL ZipPackage::commitChanges() // if the file is still not corrupted, it can become after the next step aContent.executeCommand ( OUString ( RTL_CONSTASCII_USTRINGPARAM ( "transfer" ) ), aAny ); } - catch (::com::sun::star::uno::Exception& r) + catch ( ::com::sun::star::uno::Exception& r ) { if ( bCanBeCorrupted ) DisconnectFromTargetAndThrowException_Impl( xTempInStream ); @@ -1519,6 +1562,7 @@ void SAL_CALL ZipPackage::commitChanges() RTL_LOGFILE_TRACE_AUTHOR ( "package", LOGFILE_AUTHOR, "} ZipPackage::commitChanges" ); } +//-------------------------------------------------------- void ZipPackage::DisconnectFromTargetAndThrowException_Impl( const uno::Reference< io::XInputStream >& xTempStream ) { m_xStream = uno::Reference< io::XStream >( xTempStream, uno::UNO_QUERY ); @@ -1547,15 +1591,47 @@ void ZipPackage::DisconnectFromTargetAndThrowException_Impl( const uno::Referenc makeAny ( aException ) ); } -sal_Bool SAL_CALL ZipPackage::hasPendingChanges( ) - throw(RuntimeException) +//-------------------------------------------------------- +const uno::Sequence< sal_Int8 > ZipPackage::GetEncryptionKey() +{ + uno::Sequence< sal_Int8 > aResult; + + if ( m_aStorageEncryptionKeys.getLength() ) + { + ::rtl::OUString aNameToFind; + if ( m_nStartKeyGenerationID == xml::crypto::DigestID::SHA256 ) + aNameToFind = PACKAGE_ENCRYPTIONDATA_SHA256UTF8; + else if ( m_nStartKeyGenerationID == xml::crypto::DigestID::SHA1 ) + aNameToFind = PACKAGE_ENCRYPTIONDATA_SHA1UTF8; + else + throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "No expected key is provided!" ) ), uno::Reference< uno::XInterface >() ); + + for ( sal_Int32 nInd = 0; nInd < m_aStorageEncryptionKeys.getLength(); nInd++ ) + if ( m_aStorageEncryptionKeys[nInd].Name.equals( aNameToFind ) ) + m_aStorageEncryptionKeys[nInd].Value >>= aResult; + + // empty keys are not allowed here + // so it is not important whether there is no key, or the key is empty, it is an error + if ( !aResult.getLength() ) + throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "No expected key is provided!" ) ), uno::Reference< uno::XInterface >() ); + } + else + aResult = m_aEncryptionKey; + + return aResult; +} + +//-------------------------------------------------------- +sal_Bool SAL_CALL ZipPackage::hasPendingChanges() + throw( RuntimeException ) { return sal_False; } -Sequence< ElementChange > SAL_CALL ZipPackage::getPendingChanges( ) - throw(RuntimeException) +//-------------------------------------------------------- +Sequence< ElementChange > SAL_CALL ZipPackage::getPendingChanges() + throw( RuntimeException ) { - return Sequence < ElementChange > (); + return uno::Sequence < ElementChange > (); } /** @@ -1565,149 +1641,246 @@ Sequence< ElementChange > SAL_CALL ZipPackage::getPendingChanges( ) uno::Reference < XInterface >SAL_CALL ZipPackage_createInstance( const uno::Reference< XMultiServiceFactory > & xMgr ) { - return uno::Reference< XInterface >( *new ZipPackage(xMgr) ); + return uno::Reference< XInterface >( *new ZipPackage( xMgr ) ); } +//-------------------------------------------------------- OUString ZipPackage::static_getImplementationName() { return OUString( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.packages.comp.ZipPackage" ) ); } +//-------------------------------------------------------- Sequence< OUString > ZipPackage::static_getSupportedServiceNames() { - Sequence< OUString > aNames(1); + uno::Sequence< OUString > aNames( 1 ); aNames[0] = OUString( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.packages.Package" ) ); return aNames; } +//-------------------------------------------------------- sal_Bool SAL_CALL ZipPackage::static_supportsService( OUString const & rServiceName ) { return rServiceName == getSupportedServiceNames()[0]; } +//-------------------------------------------------------- OUString ZipPackage::getImplementationName() - throw (RuntimeException) + throw ( RuntimeException ) { return static_getImplementationName(); } +//-------------------------------------------------------- Sequence< OUString > ZipPackage::getSupportedServiceNames() - throw (RuntimeException) + throw ( RuntimeException ) { return static_getSupportedServiceNames(); } +//-------------------------------------------------------- sal_Bool SAL_CALL ZipPackage::supportsService( OUString const & rServiceName ) - throw (RuntimeException) + throw ( RuntimeException ) { return static_supportsService ( rServiceName ); } +//-------------------------------------------------------- uno::Reference < XSingleServiceFactory > ZipPackage::createServiceFactory( uno::Reference < XMultiServiceFactory > const & rServiceFactory ) { - return cppu::createSingleFactory (rServiceFactory, + return cppu::createSingleFactory ( rServiceFactory, static_getImplementationName(), ZipPackage_createInstance, - static_getSupportedServiceNames()); + static_getSupportedServiceNames() ); } namespace { struct lcl_ImplId : public rtl::Static< ::cppu::OImplementationId, lcl_ImplId > {}; } -// XUnoTunnel +//-------------------------------------------------------- Sequence< sal_Int8 > ZipPackage::getUnoTunnelImplementationId( void ) - throw (RuntimeException) + throw ( RuntimeException ) { ::cppu::OImplementationId &rId = lcl_ImplId::get(); return rId.getImplementationId(); } -sal_Int64 SAL_CALL ZipPackage::getSomething( const Sequence< sal_Int8 >& aIdentifier ) - throw(RuntimeException) +//-------------------------------------------------------- +sal_Int64 SAL_CALL ZipPackage::getSomething( const uno::Sequence< sal_Int8 >& aIdentifier ) + throw( RuntimeException ) { - if (aIdentifier.getLength() == 16 && 0 == rtl_compareMemory(getUnoTunnelImplementationId().getConstArray(), aIdentifier.getConstArray(), 16 ) ) + if ( aIdentifier.getLength() == 16 && 0 == rtl_compareMemory( getUnoTunnelImplementationId().getConstArray(), aIdentifier.getConstArray(), 16 ) ) return reinterpret_cast < sal_Int64 > ( this ); return 0; } -uno::Reference< XPropertySetInfo > SAL_CALL ZipPackage::getPropertySetInfo( ) - throw(RuntimeException) +//-------------------------------------------------------- +uno::Reference< XPropertySetInfo > SAL_CALL ZipPackage::getPropertySetInfo() + throw( RuntimeException ) { return uno::Reference < XPropertySetInfo > (); } + +//-------------------------------------------------------- void SAL_CALL ZipPackage::setPropertyValue( const OUString& aPropertyName, const Any& aValue ) - throw(UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException) + throw( UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException ) { if ( m_nFormat != embed::StorageFormats::PACKAGE ) throw UnknownPropertyException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - if (aPropertyName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("HasEncryptedEntries") ) - ||aPropertyName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("HasNonEncryptedEntries") ) - ||aPropertyName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("IsInconsistent") ) - ||aPropertyName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("MediaTypeFallbackUsed") ) ) + if ( aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( HAS_ENCRYPTED_ENTRIES_PROPERTY ) ) + ||aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( HAS_NONENCRYPTED_ENTRIES_PROPERTY ) ) + ||aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( IS_INCONSISTENT_PROPERTY ) ) + ||aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( MEDIATYPE_FALLBACK_USED_PROPERTY ) ) ) throw PropertyVetoException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - else if (aPropertyName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("EncryptionKey") ) ) + else if ( aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ENCRYPTION_KEY_PROPERTY ) ) ) { - if (!( aValue >>= m_aEncryptionKey ) || m_aEncryptionKey.getLength() == 0 ) + if ( !( aValue >>= m_aEncryptionKey ) ) throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 2 ); + + m_aStorageEncryptionKeys.realloc( 0 ); } - else if (aPropertyName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("UseManifest") ) ) + else if ( aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( STORAGE_ENCRYPTION_KEYS_PROPERTY ) ) ) { - if (!( aValue >>= m_bUseManifest ) ) + // this property is only necessary to support raw passwords in storage API; + // because of this support the storage has to operate with more than one key dependent on storage generation algorithm; + // when this support is removed, the storage will get only one key from outside + // TODO/LATER: Get rid of this property as well as of support of raw passwords in storages + uno::Sequence< beans::NamedValue > aKeys; + if ( !( aValue >>= aKeys ) || ( aKeys.getLength() && aKeys.getLength() < 2 ) ) throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 2 ); + + if ( aKeys.getLength() ) + { + bool bHasSHA256 = false; + bool bHasSHA1 = false; + for ( sal_Int32 nInd = 0; nInd < aKeys.getLength(); nInd++ ) + { + if ( aKeys[nInd].Name.equals( PACKAGE_ENCRYPTIONDATA_SHA256UTF8 ) ) + bHasSHA256 = true; + if ( aKeys[nInd].Name.equals( PACKAGE_ENCRYPTIONDATA_SHA1UTF8 ) ) + bHasSHA1 = true; + } + + if ( !bHasSHA256 || !bHasSHA1 ) + throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Expected keys are not provided!" ) ), uno::Reference< uno::XInterface >(), 2 ); + } + + m_aStorageEncryptionKeys = aKeys; + m_aEncryptionKey.realloc( 0 ); + } + else if ( aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ENCRYPTION_ALGORITHMS_PROPERTY ) ) ) + { + uno::Sequence< beans::NamedValue > aAlgorithms; + if ( m_pZipFile || !( aValue >>= aAlgorithms ) || aAlgorithms.getLength() == 0 ) + { + // the algorithms can not be changed if the file has a persistence based on the algorithms ( m_pZipFile ) + throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "unexpected algorithms list is provided." ) ), uno::Reference< uno::XInterface >(), 2 ); + } + + for ( sal_Int32 nInd = 0; nInd < aAlgorithms.getLength(); nInd++ ) + { + if ( aAlgorithms[nInd].Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "StartKeyGenerationAlgorithm" ) ) ) + { + sal_Int32 nID = 0; + if ( !( aAlgorithms[nInd].Value >>= nID ) + || ( nID != xml::crypto::DigestID::SHA256 && nID != xml::crypto::DigestID::SHA1 ) ) + throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected start key generation algorithm is provided!" ) ), uno::Reference< uno::XInterface >(), 2 ); + + m_nStartKeyGenerationID = nID; + } + else if ( aAlgorithms[nInd].Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "EncryptionAlgorithm" ) ) ) + { + sal_Int32 nID = 0; + if ( !( aAlgorithms[nInd].Value >>= nID ) + || ( nID != xml::crypto::CipherID::AES_CBC_W3C_PADDING && nID != xml::crypto::CipherID::BLOWFISH_CFB_8 ) ) + throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected start key generation algorithm is provided!" ) ), uno::Reference< uno::XInterface >(), 2 ); + + m_nCommonEncryptionID = nID; + } + else if ( aAlgorithms[nInd].Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "ChecksumAlgorithm" ) ) ) + { + sal_Int32 nID = 0; + if ( !( aAlgorithms[nInd].Value >>= nID ) + || ( nID != xml::crypto::DigestID::SHA1_1K && nID != xml::crypto::DigestID::SHA256_1K ) ) + throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected start key generation algorithm is provided!" ) ), uno::Reference< uno::XInterface >(), 2 ); + + m_nChecksumDigestID = nID; + } + else + { + OSL_ENSURE( sal_False, "Unexpected encryption algorithm is provided!" ); + throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "unexpected algorithms list is provided." ) ), uno::Reference< uno::XInterface >(), 2 ); + } + } } else throw UnknownPropertyException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); } + +//-------------------------------------------------------- Any SAL_CALL ZipPackage::getPropertyValue( const OUString& PropertyName ) - throw(UnknownPropertyException, WrappedTargetException, RuntimeException) + throw( UnknownPropertyException, WrappedTargetException, RuntimeException ) { // TODO/LATER: Activate the check when zip-ucp is ready // if ( m_nFormat != embed::StorageFormats::PACKAGE ) // throw UnknownPropertyException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); Any aAny; - if (PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "EncryptionKey" ) ) ) + if ( PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( ENCRYPTION_KEY_PROPERTY ) ) ) { aAny <<= m_aEncryptionKey; return aAny; } - else if (PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "HasEncryptedEntries" ) ) ) + else if ( PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ENCRYPTION_ALGORITHMS_PROPERTY ) ) ) { - aAny <<= m_bHasEncryptedEntries; + ::comphelper::SequenceAsHashMap aAlgorithms; + aAlgorithms[ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "StartKeyGenerationAlgorithm" ) ) ] <<= m_nStartKeyGenerationID; + aAlgorithms[ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "EncryptionAlgorithm" ) ) ] <<= m_nCommonEncryptionID; + aAlgorithms[ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ChecksumAlgorithm" ) ) ] <<= m_nChecksumDigestID; + aAny <<= aAlgorithms.getAsConstNamedValueList(); return aAny; } - else if (PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "HasNonEncryptedEntries" ) ) ) + if ( PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( STORAGE_ENCRYPTION_KEYS_PROPERTY ) ) ) { - aAny <<= m_bHasNonEncryptedEntries; + aAny <<= m_aStorageEncryptionKeys; return aAny; } - else if (PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "IsInconsistent" ) ) ) + else if ( PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( HAS_ENCRYPTED_ENTRIES_PROPERTY ) ) ) { - aAny <<= m_bInconsistent; + aAny <<= m_bHasEncryptedEntries; + return aAny; + } + else if ( PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( HAS_NONENCRYPTED_ENTRIES_PROPERTY ) ) ) + { + aAny <<= m_bHasNonEncryptedEntries; return aAny; } - else if (PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "UseManifest" ) ) ) + else if ( PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( IS_INCONSISTENT_PROPERTY ) ) ) { - aAny <<= m_bUseManifest; + aAny <<= m_bInconsistent; return aAny; } - else if (PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "MediaTypeFallbackUsed" ) ) ) + else if ( PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( MEDIATYPE_FALLBACK_USED_PROPERTY ) ) ) { aAny <<= m_bMediaTypeFallbackUsed; return aAny; } throw UnknownPropertyException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); } +//-------------------------------------------------------- void SAL_CALL ZipPackage::addPropertyChangeListener( const OUString& /*aPropertyName*/, const uno::Reference< XPropertyChangeListener >& /*xListener*/ ) - throw(UnknownPropertyException, WrappedTargetException, RuntimeException) + throw( UnknownPropertyException, WrappedTargetException, RuntimeException ) { } +//-------------------------------------------------------- void SAL_CALL ZipPackage::removePropertyChangeListener( const OUString& /*aPropertyName*/, const uno::Reference< XPropertyChangeListener >& /*aListener*/ ) - throw(UnknownPropertyException, WrappedTargetException, RuntimeException) + throw( UnknownPropertyException, WrappedTargetException, RuntimeException ) { } +//-------------------------------------------------------- void SAL_CALL ZipPackage::addVetoableChangeListener( const OUString& /*PropertyName*/, const uno::Reference< XVetoableChangeListener >& /*aListener*/ ) - throw(UnknownPropertyException, WrappedTargetException, RuntimeException) + throw( UnknownPropertyException, WrappedTargetException, RuntimeException ) { } +//-------------------------------------------------------- void SAL_CALL ZipPackage::removeVetoableChangeListener( const OUString& /*PropertyName*/, const uno::Reference< XVetoableChangeListener >& /*aListener*/ ) - throw(UnknownPropertyException, WrappedTargetException, RuntimeException) + throw( UnknownPropertyException, WrappedTargetException, RuntimeException ) { } diff --git a/package/source/zippackage/ZipPackageEntry.cxx b/package/source/zippackage/ZipPackageEntry.cxx index 7514e7b6f55a..a1f752174dc6 100644 --- a/package/source/zippackage/ZipPackageEntry.cxx +++ b/package/source/zippackage/ZipPackageEntry.cxx @@ -73,18 +73,18 @@ void SAL_CALL ZipPackageEntry::setName( const OUString& aName ) // unfortunately no other exception than RuntimeException can be thrown here // usually the package is used through storage implementation, the problem should be detected there if ( !::comphelper::OStorageHelper::IsValidZipEntryFileName( aName, sal_True ) ) - throw RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected character is used in file name." ) ), Reference< XInterface >() ); + throw RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected character is used in file name." ) ), uno::Reference< XInterface >() ); msName = aName; if ( pParent ) pParent->doInsertByName ( this, sal_False ); } -Reference< XInterface > SAL_CALL ZipPackageEntry::getParent( ) +uno::Reference< XInterface > SAL_CALL ZipPackageEntry::getParent( ) throw(RuntimeException) { - // return Reference< XInterface >( xParent, UNO_QUERY ); - return Reference< XInterface >( static_cast< ::cppu::OWeakObject* >( pParent ), UNO_QUERY ); + // return uno::Reference< XInterface >( xParent, UNO_QUERY ); + return uno::Reference< XInterface >( static_cast< ::cppu::OWeakObject* >( pParent ), UNO_QUERY ); } void ZipPackageEntry::doSetParent ( ZipPackageFolder * pNewParent, sal_Bool bInsert ) @@ -95,11 +95,11 @@ void ZipPackageEntry::doSetParent ( ZipPackageFolder * pNewParent, sal_Bool bIns pNewParent->doInsertByName ( this, sal_False ); } -void SAL_CALL ZipPackageEntry::setParent( const Reference< XInterface >& xNewParent ) +void SAL_CALL ZipPackageEntry::setParent( const uno::Reference< XInterface >& xNewParent ) throw(NoSupportException, RuntimeException) { sal_Int64 nTest(0); - Reference < XUnoTunnel > xTunnel ( xNewParent, UNO_QUERY ); + uno::Reference < XUnoTunnel > xTunnel ( xNewParent, UNO_QUERY ); if ( !xNewParent.is() || ( nTest = xTunnel->getSomething ( ZipPackageFolder::static_getImplementationId () ) ) == 0 ) throw NoSupportException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); @@ -113,24 +113,24 @@ void SAL_CALL ZipPackageEntry::setParent( const Reference< XInterface >& xNewPar } } //XPropertySet -Reference< beans::XPropertySetInfo > SAL_CALL ZipPackageEntry::getPropertySetInfo( ) +uno::Reference< beans::XPropertySetInfo > SAL_CALL ZipPackageEntry::getPropertySetInfo( ) throw(RuntimeException) { - return Reference < beans::XPropertySetInfo > (); + return uno::Reference < beans::XPropertySetInfo > (); } -void SAL_CALL ZipPackageEntry::addPropertyChangeListener( const OUString& /*aPropertyName*/, const Reference< beans::XPropertyChangeListener >& /*xListener*/ ) +void SAL_CALL ZipPackageEntry::addPropertyChangeListener( const OUString& /*aPropertyName*/, const uno::Reference< beans::XPropertyChangeListener >& /*xListener*/ ) throw(beans::UnknownPropertyException, WrappedTargetException, RuntimeException) { } -void SAL_CALL ZipPackageEntry::removePropertyChangeListener( const OUString& /*aPropertyName*/, const Reference< beans::XPropertyChangeListener >& /*aListener*/ ) +void SAL_CALL ZipPackageEntry::removePropertyChangeListener( const OUString& /*aPropertyName*/, const uno::Reference< beans::XPropertyChangeListener >& /*aListener*/ ) throw(beans::UnknownPropertyException, WrappedTargetException, RuntimeException) { } -void SAL_CALL ZipPackageEntry::addVetoableChangeListener( const OUString& /*PropertyName*/, const Reference< beans::XVetoableChangeListener >& /*aListener*/ ) +void SAL_CALL ZipPackageEntry::addVetoableChangeListener( const OUString& /*PropertyName*/, const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ ) throw(beans::UnknownPropertyException, WrappedTargetException, RuntimeException) { } -void SAL_CALL ZipPackageEntry::removeVetoableChangeListener( const OUString& /*PropertyName*/, const Reference< beans::XVetoableChangeListener >& /*aListener*/ ) +void SAL_CALL ZipPackageEntry::removeVetoableChangeListener( const OUString& /*PropertyName*/, const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ ) throw(beans::UnknownPropertyException, WrappedTargetException, RuntimeException) { } diff --git a/package/source/zippackage/ZipPackageEntry.hxx b/package/source/zippackage/ZipPackageEntry.hxx deleted file mode 100644 index 767d84511a12..000000000000 --- a/package/source/zippackage/ZipPackageEntry.hxx +++ /dev/null @@ -1,105 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ -#ifndef _ZIP_PACKAGE_ENTRY_HXX -#define _ZIP_PACKAGE_ENTRY_HXX - -#include <com/sun/star/container/XChild.hpp> -#include <com/sun/star/container/XNamed.hpp> -#include <com/sun/star/beans/XPropertySet.hpp> -#include <com/sun/star/lang/XUnoTunnel.hpp> -#include <com/sun/star/container/XNameContainer.hpp> -#ifndef _COM_SUN_STAR_LANG_XPSERVICEINFO_HPP_ -#include <com/sun/star/lang/XServiceInfo.hpp> -#endif -#include <ZipEntry.hxx> -#include <cppuhelper/implbase5.hxx> - -class ZipPackageFolder; - -class ZipPackageEntry : public cppu::WeakImplHelper5 -< - com::sun::star::container::XNamed, - com::sun::star::container::XChild, - com::sun::star::lang::XUnoTunnel, - com::sun::star::beans::XPropertySet, - com::sun::star::lang::XServiceInfo -> -{ -protected: - ::rtl::OUString msName; - bool mbIsFolder:1; - bool mbAllowRemoveOnInsert:1; - // com::sun::star::uno::Reference < com::sun::star::container::XNameContainer > xParent; - ::rtl::OUString sMediaType; - ZipPackageFolder * pParent; -public: - ZipEntry aEntry; - ZipPackageEntry ( bool bNewFolder = sal_False ); - virtual ~ZipPackageEntry( void ); - - ::rtl::OUString & GetMediaType () { return sMediaType; } - void SetMediaType ( const ::rtl::OUString & sNewType) { sMediaType = sNewType; } - void doSetParent ( ZipPackageFolder * pNewParent, sal_Bool bInsert ); - bool IsFolder ( ) { return mbIsFolder; } - ZipPackageFolder* GetParent ( ) { return pParent; } - void SetFolder ( bool bSetFolder ) { mbIsFolder = bSetFolder; } - - void clearParent ( void ) - { - // xParent.clear(); - pParent = NULL; - } - // XNamed - virtual ::rtl::OUString SAL_CALL getName( ) - throw(::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL setName( const ::rtl::OUString& aName ) - throw(::com::sun::star::uno::RuntimeException); - // XChild - virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL getParent( ) - throw(::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL setParent( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& Parent ) - throw(::com::sun::star::lang::NoSupportException, ::com::sun::star::uno::RuntimeException); - // XUnoTunnel - virtual sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& aIdentifier ) - throw(::com::sun::star::uno::RuntimeException) = 0; - // XPropertySet - virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) - throw(::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL setPropertyValue( const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Any& aValue ) - throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException) = 0; - virtual ::com::sun::star::uno::Any SAL_CALL getPropertyValue( const ::rtl::OUString& PropertyName ) - throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException) = 0; - virtual void SAL_CALL addPropertyChangeListener( const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& xListener ) - throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL removePropertyChangeListener( const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& aListener ) - throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL addVetoableChangeListener( const ::rtl::OUString& PropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener >& aListener ) - throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL removeVetoableChangeListener( const ::rtl::OUString& PropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener >& aListener ) - throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); -}; -#endif diff --git a/package/source/zippackage/ZipPackageFolder.cxx b/package/source/zippackage/ZipPackageFolder.cxx index 5bb5b4db89b6..0d78fe42cd34 100644 --- a/package/source/zippackage/ZipPackageFolder.cxx +++ b/package/source/zippackage/ZipPackageFolder.cxx @@ -46,23 +46,22 @@ #include <rtl/instance.hxx> #include <memory> +using namespace com::sun::star; using namespace com::sun::star::packages::zip::ZipConstants; using namespace com::sun::star::packages::zip; using namespace com::sun::star::packages; using namespace com::sun::star::container; using namespace com::sun::star::beans; using namespace com::sun::star::lang; -using namespace com::sun::star::uno; using namespace com::sun::star::io; using namespace cppu; -using namespace rtl; using namespace std; using namespace ::com::sun::star; using vos::ORef; -namespace { struct lcl_CachedImplId : public rtl::Static< Sequence < sal_Int8 >, lcl_CachedImplId > {}; } +namespace { struct lcl_CachedImplId : public rtl::Static< uno::Sequence < sal_Int8 >, lcl_CachedImplId > {}; } -ZipPackageFolder::ZipPackageFolder ( const Reference< XMultiServiceFactory >& xFactory, +ZipPackageFolder::ZipPackageFolder ( const uno::Reference< XMultiServiceFactory >& xFactory, sal_Int32 nFormat, sal_Bool bAllowRemoveOnInsert ) : m_xFactory( xFactory ) @@ -81,7 +80,7 @@ ZipPackageFolder::ZipPackageFolder ( const Reference< XMultiServiceFactory >& xF aEntry.nCompressedSize = 0; aEntry.nSize = 0; aEntry.nOffset = -1; - Sequence < sal_Int8 > &rCachedImplId = lcl_CachedImplId::get(); + uno::Sequence < sal_Int8 > &rCachedImplId = lcl_CachedImplId::get(); if ( !rCachedImplId.getLength() ) rCachedImplId = getImplementationId(); } @@ -99,7 +98,7 @@ sal_Bool ZipPackageFolder::LookForUnexpectedODF12Streams( const ::rtl::OUString& !bHasUnexpected && aCI != aEnd; aCI++) { - const OUString &rShortName = (*aCI).first; + const ::rtl::OUString &rShortName = (*aCI).first; const ContentInfo &rInfo = *(*aCI).second; if ( rInfo.bFolder ) @@ -111,7 +110,7 @@ sal_Bool ZipPackageFolder::LookForUnexpectedODF12Streams( const ::rtl::OUString& } else { - OUString sOwnPath = aPath + rShortName + OUString( RTL_CONSTASCII_USTRINGPARAM ( "/" ) ); + ::rtl::OUString sOwnPath = aPath + rShortName + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "/" ) ); bHasUnexpected = rInfo.pFolder->LookForUnexpectedODF12Streams( sOwnPath ); } } @@ -157,7 +156,7 @@ void ZipPackageFolder::setChildStreamsTypeByExtension( const beans::StringPair& aCI != aEnd; aCI++) { - const OUString &rShortName = (*aCI).first; + const ::rtl::OUString &rShortName = (*aCI).first; const ContentInfo &rInfo = *(*aCI).second; if ( rInfo.bFolder ) @@ -193,14 +192,14 @@ const ::com::sun::star::uno::Sequence < sal_Int8 >& ZipPackageFolder::static_get } // XNameContainer -void SAL_CALL ZipPackageFolder::insertByName( const OUString& aName, const Any& aElement ) - throw(IllegalArgumentException, ElementExistException, WrappedTargetException, RuntimeException) +void SAL_CALL ZipPackageFolder::insertByName( const ::rtl::OUString& aName, const uno::Any& aElement ) + throw(IllegalArgumentException, ElementExistException, WrappedTargetException, uno::RuntimeException) { if (hasByName(aName)) throw ElementExistException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); else { - Reference < XUnoTunnel > xRef; + uno::Reference < XUnoTunnel > xRef; aElement >>= xRef; if ( ( aElement >>= xRef ) ) { @@ -227,8 +226,8 @@ void SAL_CALL ZipPackageFolder::insertByName( const OUString& aName, const Any& throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 0 ); } } -void SAL_CALL ZipPackageFolder::removeByName( const OUString& Name ) - throw(NoSuchElementException, WrappedTargetException, RuntimeException) +void SAL_CALL ZipPackageFolder::removeByName( const ::rtl::OUString& Name ) + throw(NoSuchElementException, WrappedTargetException, uno::RuntimeException) { ContentHash::iterator aIter = maContents.find ( Name ); if ( aIter == maContents.end() ) @@ -236,55 +235,55 @@ void SAL_CALL ZipPackageFolder::removeByName( const OUString& Name ) maContents.erase( aIter ); } // XEnumerationAccess -Reference< XEnumeration > SAL_CALL ZipPackageFolder::createEnumeration( ) - throw(RuntimeException) +uno::Reference< XEnumeration > SAL_CALL ZipPackageFolder::createEnumeration( ) + throw(uno::RuntimeException) { - return Reference < XEnumeration> (new ZipPackageFolderEnumeration(maContents)); + return uno::Reference < XEnumeration> (new ZipPackageFolderEnumeration(maContents)); } // XElementAccess -Type SAL_CALL ZipPackageFolder::getElementType( ) - throw(RuntimeException) +uno::Type SAL_CALL ZipPackageFolder::getElementType( ) + throw(uno::RuntimeException) { - return ::getCppuType ((const Reference< XUnoTunnel > *) 0); + return ::getCppuType ((const uno::Reference< XUnoTunnel > *) 0); } sal_Bool SAL_CALL ZipPackageFolder::hasElements( ) - throw(RuntimeException) + throw(uno::RuntimeException) { return maContents.size() > 0; } // XNameAccess -ContentInfo& ZipPackageFolder::doGetByName( const OUString& aName ) - throw(NoSuchElementException, WrappedTargetException, RuntimeException) +ContentInfo& ZipPackageFolder::doGetByName( const ::rtl::OUString& aName ) + throw(NoSuchElementException, WrappedTargetException, uno::RuntimeException) { ContentHash::iterator aIter = maContents.find ( aName ); if ( aIter == maContents.end()) throw NoSuchElementException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); return *(*aIter).second; } -Any SAL_CALL ZipPackageFolder::getByName( const OUString& aName ) - throw(NoSuchElementException, WrappedTargetException, RuntimeException) +uno::Any SAL_CALL ZipPackageFolder::getByName( const ::rtl::OUString& aName ) + throw(NoSuchElementException, WrappedTargetException, uno::RuntimeException) { - return makeAny ( doGetByName ( aName ).xTunnel ); + return uno::makeAny ( doGetByName ( aName ).xTunnel ); } -Sequence< OUString > SAL_CALL ZipPackageFolder::getElementNames( ) - throw(RuntimeException) +uno::Sequence< ::rtl::OUString > SAL_CALL ZipPackageFolder::getElementNames( ) + throw(uno::RuntimeException) { sal_uInt32 i=0, nSize = maContents.size(); - Sequence < OUString > aSequence ( nSize ); + uno::Sequence < ::rtl::OUString > aSequence ( nSize ); for ( ContentHash::const_iterator aIterator = maContents.begin(), aEnd = maContents.end(); aIterator != aEnd; ++i, ++aIterator) aSequence[i] = (*aIterator).first; return aSequence; } -sal_Bool SAL_CALL ZipPackageFolder::hasByName( const OUString& aName ) - throw(RuntimeException) +sal_Bool SAL_CALL ZipPackageFolder::hasByName( const ::rtl::OUString& aName ) + throw(uno::RuntimeException) { return maContents.find ( aName ) != maContents.end (); } // XNameReplace -void SAL_CALL ZipPackageFolder::replaceByName( const OUString& aName, const Any& aElement ) - throw(IllegalArgumentException, NoSuchElementException, WrappedTargetException, RuntimeException) +void SAL_CALL ZipPackageFolder::replaceByName( const ::rtl::OUString& aName, const uno::Any& aElement ) + throw(IllegalArgumentException, NoSuchElementException, WrappedTargetException, uno::RuntimeException) { if ( hasByName( aName ) ) removeByName( aName ); @@ -293,7 +292,7 @@ void SAL_CALL ZipPackageFolder::replaceByName( const OUString& aName, const Any& insertByName(aName, aElement); } -static void ImplSetStoredData( ZipEntry & rEntry, Reference < XInputStream> & rStream ) +static void ImplSetStoredData( ZipEntry & rEntry, uno::Reference< XInputStream> & rStream ) { // It's very annoying that we have to do this, but lots of zip packages // don't allow data descriptors for STORED streams, meaning we have to @@ -305,25 +304,29 @@ static void ImplSetStoredData( ZipEntry & rEntry, Reference < XInputStream> & rS rEntry.nCrc = aCRC32.getValue(); } -bool ZipPackageFolder::saveChild( const OUString &rShortName, const ContentInfo &rInfo, OUString &rPath, std::vector < Sequence < PropertyValue > > &rManList, ZipOutputStream & rZipOut, Sequence < sal_Int8 > &rEncryptionKey, rtlRandomPool &rRandomPool) +bool ZipPackageFolder::saveChild( const ::rtl::OUString &rShortName, const ContentInfo &rInfo, ::rtl::OUString &rPath, std::vector < uno::Sequence < PropertyValue > > &rManList, ZipOutputStream & rZipOut, const uno::Sequence < sal_Int8 >& rEncryptionKey, rtlRandomPool &rRandomPool) { bool bSuccess = true; - const OUString sMediaTypeProperty ( RTL_CONSTASCII_USTRINGPARAM ( "MediaType" ) ); - const OUString sVersionProperty ( RTL_CONSTASCII_USTRINGPARAM ( "Version" ) ); - const OUString sFullPathProperty ( RTL_CONSTASCII_USTRINGPARAM ( "FullPath" ) ); - const OUString sInitialisationVectorProperty ( RTL_CONSTASCII_USTRINGPARAM ( "InitialisationVector" ) ); - const OUString sSaltProperty ( RTL_CONSTASCII_USTRINGPARAM ( "Salt" ) ); - const OUString sIterationCountProperty ( RTL_CONSTASCII_USTRINGPARAM ( "IterationCount" ) ); - const OUString sSizeProperty ( RTL_CONSTASCII_USTRINGPARAM ( "Size" ) ); - const OUString sDigestProperty ( RTL_CONSTASCII_USTRINGPARAM ( "Digest" ) ); - - Sequence < PropertyValue > aPropSet (PKG_SIZE_NOENCR_MNFST); + const ::rtl::OUString sMediaTypeProperty ( RTL_CONSTASCII_USTRINGPARAM ( "MediaType" ) ); + const ::rtl::OUString sVersionProperty ( RTL_CONSTASCII_USTRINGPARAM ( "Version" ) ); + const ::rtl::OUString sFullPathProperty ( RTL_CONSTASCII_USTRINGPARAM ( "FullPath" ) ); + const ::rtl::OUString sInitialisationVectorProperty ( RTL_CONSTASCII_USTRINGPARAM ( "InitialisationVector" ) ); + const ::rtl::OUString sSaltProperty ( RTL_CONSTASCII_USTRINGPARAM ( "Salt" ) ); + const ::rtl::OUString sIterationCountProperty ( RTL_CONSTASCII_USTRINGPARAM ( "IterationCount" ) ); + const ::rtl::OUString sSizeProperty ( RTL_CONSTASCII_USTRINGPARAM ( "Size" ) ); + const ::rtl::OUString sDigestProperty ( RTL_CONSTASCII_USTRINGPARAM ( "Digest" ) ); + const ::rtl::OUString sEncryptionAlgProperty ( RTL_CONSTASCII_USTRINGPARAM ( "EncryptionAlgorithm" ) ); + const ::rtl::OUString sStartKeyAlgProperty ( RTL_CONSTASCII_USTRINGPARAM ( "StartKeyAlgorithm" ) ); + const ::rtl::OUString sDigestAlgProperty ( RTL_CONSTASCII_USTRINGPARAM ( "DigestAlgorithm" ) ); + const ::rtl::OUString sDerivedKeySizeProperty ( RTL_CONSTASCII_USTRINGPARAM ( "DerivedKeySize" ) ); + + uno::Sequence < PropertyValue > aPropSet (PKG_SIZE_NOENCR_MNFST); OSL_ENSURE( ( rInfo.bFolder && rInfo.pFolder ) || ( !rInfo.bFolder && rInfo.pStream ), "A valid child object is expected!" ); if ( rInfo.bFolder ) { - OUString sTempName = rPath + rShortName + OUString( RTL_CONSTASCII_USTRINGPARAM ( "/" ) ); + ::rtl::OUString sTempName = rPath + rShortName + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "/" ) ); if ( rInfo.pFolder->GetMediaType().getLength() ) { @@ -378,7 +381,7 @@ bool ZipPackageFolder::saveChild( const OUString &rShortName, const ContentInfo sal_Int32 nOwnStreamOrigSize = bRawStream ? rInfo.pStream->GetMagicalHackSize() : rInfo.pStream->getSize(); sal_Bool bUseNonSeekableAccess = sal_False; - Reference < XInputStream > xStream; + uno::Reference < XInputStream > xStream; if ( !rInfo.pStream->IsPackageMember() && !bRawStream && !bToBeEncrypted && bToBeCompressed ) { // the stream is not a package member, not a raw stream, @@ -386,7 +389,7 @@ bool ZipPackageFolder::saveChild( const OUString &rShortName, const ContentInfo // in this case nonseekable access can be used xStream = rInfo.pStream->GetOwnStreamNoWrap(); - Reference < XSeekable > xSeek ( xStream, UNO_QUERY ); + uno::Reference < XSeekable > xSeek ( xStream, uno::UNO_QUERY ); bUseNonSeekableAccess = ( xStream.is() && !xSeek.is() ); } @@ -402,7 +405,7 @@ bool ZipPackageFolder::saveChild( const OUString &rShortName, const ContentInfo return bSuccess; } - Reference < XSeekable > xSeek ( xStream, UNO_QUERY ); + uno::Reference < XSeekable > xSeek ( xStream, uno::UNO_QUERY ); try { if ( xSeek.is() ) @@ -450,15 +453,13 @@ bool ZipPackageFolder::saveChild( const OUString &rShortName, const ContentInfo } else { - VOS_ENSURE( 0, "The package component requires that every stream either be FROM a package or it must support XSeekable!" ); bSuccess = false; return bSuccess; } } } - catch ( Exception& ) + catch ( uno::Exception& ) { - VOS_ENSURE( 0, "The stream provided to the package component has problems!" ); bSuccess = false; return bSuccess; } @@ -467,9 +468,9 @@ bool ZipPackageFolder::saveChild( const OUString &rShortName, const ContentInfo { if ( bToBeEncrypted && !bTransportOwnEncrStreamAsRaw ) { - Sequence < sal_uInt8 > aSalt ( 16 ), aVector ( 8 ); + uno::Sequence < sal_Int8 > aSalt( 16 ), aVector( rInfo.pStream->GetBlockSize() ); rtl_random_getBytes ( rRandomPool, aSalt.getArray(), 16 ); - rtl_random_getBytes ( rRandomPool, aVector.getArray(), 8 ); + rtl_random_getBytes ( rRandomPool, aVector.getArray(), aVector.getLength() ); sal_Int32 nIterationCount = 1024; if ( !rInfo.pStream->HasOwnKey() ) @@ -498,8 +499,20 @@ bool ZipPackageFolder::saveChild( const OUString &rShortName, const ContentInfo if ( bRawStream || bTransportOwnEncrStreamAsRaw ) { + ::rtl::Reference< EncryptionData > xEncData = rInfo.pStream->GetEncryptionData(); + if ( !xEncData.is() ) + throw uno::RuntimeException(); + aPropSet[PKG_MNFST_DIGEST].Name = sDigestProperty; aPropSet[PKG_MNFST_DIGEST].Value <<= rInfo.pStream->getDigest(); + 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 <<= xEncData->m_nStartKeyGenID; + aPropSet[PKG_MNFST_DIGESTALG].Name = sDigestAlgProperty; + aPropSet[PKG_MNFST_DIGESTALG].Value <<= xEncData->m_nCheckAlg; + aPropSet[PKG_MNFST_DERKEYSIZE].Name = sDerivedKeySizeProperty; + aPropSet[PKG_MNFST_DERKEYSIZE].Value <<= xEncData->m_nDerivedKeySize; } } } @@ -520,7 +533,6 @@ bool ZipPackageFolder::saveChild( const OUString &rShortName, const ContentInfo if ( !xStream.is() ) { // Make sure that we actually _got_ a new one ! - VOS_ENSURE( 0, "ZipPackageStream didn't have a stream associated with it, skipping!" ); bSuccess = false; return bSuccess; } @@ -531,11 +543,11 @@ bool ZipPackageFolder::saveChild( const OUString &rShortName, const ContentInfo if ( bRawStream ) xStream->skipBytes( rInfo.pStream->GetMagicalHackPos() ); - rZipOut.putNextEntry ( *pTempEntry, rInfo.pStream->getEncryptionData(), sal_False ); + rZipOut.putNextEntry ( *pTempEntry, rInfo.pStream, sal_False ); // the entry is provided to the ZipOutputStream that will delete it pAutoTempEntry.release(); - Sequence < sal_Int8 > aSeq ( n_ConstBufferSize ); + uno::Sequence < sal_Int8 > aSeq ( n_ConstBufferSize ); sal_Int32 nLength; do @@ -549,12 +561,10 @@ bool ZipPackageFolder::saveChild( const OUString &rShortName, const ContentInfo } catch ( ZipException& ) { - VOS_ENSURE( 0, "Error writing ZipOutputStream" ); bSuccess = false; } catch ( IOException& ) { - VOS_ENSURE( 0, "Error writing ZipOutputStream" ); bSuccess = false; } } @@ -576,7 +586,6 @@ bool ZipPackageFolder::saveChild( const OUString &rShortName, const ContentInfo if ( !xStream.is() ) { // Make sure that we actually _got_ a new one ! - VOS_ENSURE( 0, "ZipPackageStream didn't have a stream associated with it, skipping!" ); bSuccess = false; return bSuccess; } @@ -590,12 +599,12 @@ bool ZipPackageFolder::saveChild( const OUString &rShortName, const ContentInfo try { - rZipOut.putNextEntry ( *pTempEntry, rInfo.pStream->getEncryptionData(), bToBeEncrypted); + rZipOut.putNextEntry ( *pTempEntry, rInfo.pStream, bToBeEncrypted); // the entry is provided to the ZipOutputStream that will delete it pAutoTempEntry.release(); sal_Int32 nLength; - Sequence < sal_Int8 > aSeq (n_ConstBufferSize); + uno::Sequence < sal_Int8 > aSeq (n_ConstBufferSize); do { nLength = xStream->readBytes(aSeq, n_ConstBufferSize); @@ -607,19 +616,30 @@ bool ZipPackageFolder::saveChild( const OUString &rShortName, const ContentInfo } catch ( ZipException& ) { - VOS_ENSURE( 0, "Error writing ZipOutputStream" ); bSuccess = false; } catch ( IOException& ) { - VOS_ENSURE( 0, "Error writing ZipOutputStream" ); bSuccess = false; } if ( bToBeEncrypted ) { + ::rtl::Reference< EncryptionData > xEncData = rInfo.pStream->GetEncryptionData(); + if ( !xEncData.is() ) + throw uno::RuntimeException(); + aPropSet[PKG_MNFST_DIGEST].Name = sDigestProperty; aPropSet[PKG_MNFST_DIGEST].Value <<= rInfo.pStream->getDigest(); + 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 <<= xEncData->m_nStartKeyGenID; + aPropSet[PKG_MNFST_DIGESTALG].Name = sDigestAlgProperty; + aPropSet[PKG_MNFST_DIGESTALG].Value <<= xEncData->m_nCheckAlg; + aPropSet[PKG_MNFST_DERKEYSIZE].Name = sDerivedKeySizeProperty; + aPropSet[PKG_MNFST_DERKEYSIZE].Value <<= xEncData->m_nDerivedKeySize; + rInfo.pStream->SetIsEncrypted ( sal_True ); } } @@ -665,8 +685,8 @@ bool ZipPackageFolder::saveChild( const OUString &rShortName, const ContentInfo return bSuccess; } -void ZipPackageFolder::saveContents(OUString &rPath, std::vector < Sequence < PropertyValue > > &rManList, ZipOutputStream & rZipOut, Sequence < sal_Int8 > &rEncryptionKey, rtlRandomPool &rRandomPool) - throw(RuntimeException) +void ZipPackageFolder::saveContents( ::rtl::OUString &rPath, std::vector < uno::Sequence < PropertyValue > > &rManList, ZipOutputStream & rZipOut, const uno::Sequence < sal_Int8 >& rEncryptionKey, rtlRandomPool &rRandomPool ) + throw( uno::RuntimeException ) { bool bWritingFailed = false; @@ -681,18 +701,15 @@ void ZipPackageFolder::saveContents(OUString &rPath, std::vector < Sequence < Pr try { - vos::ORef < EncryptionData > aEmptyEncr; - rZipOut.putNextEntry ( *pTempEntry, aEmptyEncr, sal_False ); + rZipOut.putNextEntry( *pTempEntry, NULL, sal_False ); rZipOut.rawCloseEntry(); } catch ( ZipException& ) { - VOS_ENSURE( 0, "Error writing ZipOutputStream" ); bWritingFailed = true; } catch ( IOException& ) { - VOS_ENSURE( 0, "Error writing ZipOutputStream" ); bWritingFailed = true; } } @@ -714,7 +731,7 @@ void ZipPackageFolder::saveContents(OUString &rPath, std::vector < Sequence < Pr aCI != aEnd; aCI++) { - const OUString &rShortName = (*aCI).first; + const ::rtl::OUString &rShortName = (*aCI).first; const ContentInfo &rInfo = *(*aCI).second; if ( !bMimeTypeStreamStored || !rShortName.equals( aMimeTypeStreamName ) ) @@ -722,7 +739,7 @@ void ZipPackageFolder::saveContents(OUString &rPath, std::vector < Sequence < Pr } if( bWritingFailed ) - throw RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); + throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); } void ZipPackageFolder::releaseUpwardRef( void ) @@ -754,8 +771,8 @@ void ZipPackageFolder::releaseUpwardRef( void ) #endif } -sal_Int64 SAL_CALL ZipPackageFolder::getSomething( const Sequence< sal_Int8 >& aIdentifier ) - throw(RuntimeException) +sal_Int64 SAL_CALL ZipPackageFolder::getSomething( const uno::Sequence< sal_Int8 >& aIdentifier ) + throw(uno::RuntimeException) { sal_Int64 nMe = 0; if ( aIdentifier.getLength() == 16 && @@ -763,8 +780,8 @@ sal_Int64 SAL_CALL ZipPackageFolder::getSomething( const Sequence< sal_Int8 >& a nMe = reinterpret_cast < sal_Int64 > ( this ); return nMe; } -void SAL_CALL ZipPackageFolder::setPropertyValue( const OUString& aPropertyName, const Any& aValue ) - throw(UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException) +void SAL_CALL ZipPackageFolder::setPropertyValue( const ::rtl::OUString& aPropertyName, const uno::Any& aValue ) + throw(UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException, uno::RuntimeException) { if (aPropertyName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("MediaType"))) { @@ -781,8 +798,8 @@ void SAL_CALL ZipPackageFolder::setPropertyValue( const OUString& aPropertyName, else throw UnknownPropertyException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); } -Any SAL_CALL ZipPackageFolder::getPropertyValue( const OUString& PropertyName ) - throw(UnknownPropertyException, WrappedTargetException, RuntimeException) +uno::Any SAL_CALL ZipPackageFolder::getPropertyValue( const ::rtl::OUString& PropertyName ) + throw(UnknownPropertyException, WrappedTargetException, uno::RuntimeException) { if (PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "MediaType" ) ) ) { @@ -790,18 +807,18 @@ Any SAL_CALL ZipPackageFolder::getPropertyValue( const OUString& PropertyName ) // if ( m_nFormat != embed::StorageFormats::PACKAGE ) // throw UnknownPropertyException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - return makeAny ( sMediaType ); + return uno::makeAny ( sMediaType ); } else if (PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "Version" ) ) ) - return makeAny( m_sVersion ); + return uno::makeAny( m_sVersion ); else if (PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "Size" ) ) ) - return makeAny ( aEntry.nSize ); + return uno::makeAny ( aEntry.nSize ); else throw UnknownPropertyException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); } void ZipPackageFolder::doInsertByName ( ZipPackageEntry *pEntry, sal_Bool bSetParent ) - throw(IllegalArgumentException, ElementExistException, WrappedTargetException, RuntimeException) + throw(IllegalArgumentException, ElementExistException, WrappedTargetException, uno::RuntimeException) { try { @@ -818,21 +835,21 @@ void ZipPackageFolder::doInsertByName ( ZipPackageEntry *pEntry, sal_Bool bSetPa if ( bSetParent ) pEntry->setParent ( *this ); } -OUString ZipPackageFolder::getImplementationName() - throw (RuntimeException) +::rtl::OUString ZipPackageFolder::getImplementationName() + throw (uno::RuntimeException) { - return OUString ( RTL_CONSTASCII_USTRINGPARAM ( "ZipPackageFolder" ) ); + return ::rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM ( "ZipPackageFolder" ) ); } -Sequence< OUString > ZipPackageFolder::getSupportedServiceNames() - throw (RuntimeException) +uno::Sequence< ::rtl::OUString > ZipPackageFolder::getSupportedServiceNames() + throw (uno::RuntimeException) { - Sequence< OUString > aNames(1); - aNames[0] = OUString( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.packages.PackageFolder" ) ); + uno::Sequence< ::rtl::OUString > aNames(1); + aNames[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.packages.PackageFolder" ) ); return aNames; } -sal_Bool SAL_CALL ZipPackageFolder::supportsService( OUString const & rServiceName ) - throw (RuntimeException) +sal_Bool SAL_CALL ZipPackageFolder::supportsService( ::rtl::OUString const & rServiceName ) + throw (uno::RuntimeException) { return rServiceName == getSupportedServiceNames()[0]; } diff --git a/package/source/zippackage/ZipPackageStream.cxx b/package/source/zippackage/ZipPackageStream.cxx index da44dafa000b..79797b938f60 100644 --- a/package/source/zippackage/ZipPackageStream.cxx +++ b/package/source/zippackage/ZipPackageStream.cxx @@ -16,7 +16,7 @@ * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). + * ( a copy is included in the LICENSE file that accompanied this code ). * * You should have received a copy of the GNU Lesser General Public License * version 3 along with OpenOffice.org. If not, see @@ -25,7 +25,7 @@ * ************************************************************************/ -// MARKER(update_precomp.py): autogen include statement, do not remove +// MARKER( update_precomp.py ): autogen include statement, do not remove #include "precompiled_package.hxx" #include <com/sun/star/packages/zip/ZipConstants.hpp> #include <com/sun/star/embed/StorageFormats.hpp> @@ -34,6 +34,8 @@ #include <com/sun/star/io/XOutputStream.hpp> #include <com/sun/star/io/XStream.hpp> #include <com/sun/star/io/XSeekable.hpp> +#include <com/sun/star/xml/crypto/DigestID.hpp> +#include <com/sun/star/xml/crypto/CipherID.hpp> #include <ZipPackageStream.hxx> @@ -66,21 +68,25 @@ const ::com::sun::star::uno::Sequence < sal_Int8 >& ZipPackageStream::static_get } ZipPackageStream::ZipPackageStream ( ZipPackage & rNewPackage, - const Reference< XMultiServiceFactory >& xFactory, + const uno::Reference< XMultiServiceFactory >& xFactory, sal_Bool bAllowRemoveOnInsert ) : m_xFactory( xFactory ) -, rZipPackage(rNewPackage) +, rZipPackage( rNewPackage ) , bToBeCompressed ( sal_True ) , bToBeEncrypted ( sal_False ) , bHaveOwnKey ( sal_False ) , bIsEncrypted ( sal_False ) -, xEncryptionData ( ) +, m_nImportedStartKeyAlgorithm( 0 ) +, m_nImportedEncryptionAlgorithm( 0 ) +, m_nImportedChecksumAlgorithm( 0 ) +, m_nImportedDerivedKeySize( 0 ) , m_nStreamMode( PACKAGE_STREAM_NOTSET ) , m_nMagicalHackPos( 0 ) , m_nMagicalHackSize( 0 ) , m_bHasSeekable( sal_False ) , m_bCompressedIsSetFromOutside( sal_False ) , m_bFromManifest( sal_False ) +, m_bUseWinEncoding( false ) { OSL_ENSURE( m_xFactory.is(), "No factory is provided to ZipPackageStream!\n" ); @@ -107,7 +113,7 @@ ZipPackageStream::~ZipPackageStream( void ) { } -void ZipPackageStream::setZipEntryOnLoading( const ZipEntry &rInEntry) +void ZipPackageStream::setZipEntryOnLoading( const ZipEntry &rInEntry ) { aEntry.nVersion = rInEntry.nVersion; aEntry.nFlag = rInEntry.nFlag; @@ -137,7 +143,7 @@ void ZipPackageStream::CloseOwnStreamIfAny() } //-------------------------------------------------------------------------- -uno::Reference< io::XInputStream >& ZipPackageStream::GetOwnSeekStream() +uno::Reference< io::XInputStream > ZipPackageStream::GetOwnSeekStream() { if ( !m_bHasSeekable && xStream.is() ) { @@ -146,10 +152,10 @@ uno::Reference< io::XInputStream >& ZipPackageStream::GetOwnSeekStream() // is accessed before commit it MUST be wrapped. // Wrap the stream in case it is not seekable xStream = ::comphelper::OSeekableInputWrapper::CheckSeekableCanWrap( xStream, m_xFactory ); - Reference< io::XSeekable > xSeek( xStream, UNO_QUERY ); + uno::Reference< io::XSeekable > xSeek( xStream, UNO_QUERY ); if ( !xSeek.is() ) throw RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "The stream must support XSeekable!" ) ), - Reference< XInterface >() ); + uno::Reference< XInterface >() ); m_bHasSeekable = sal_True; } @@ -163,18 +169,18 @@ uno::Reference< io::XInputStream > ZipPackageStream::GetRawEncrStreamNoHeaderCop if ( m_nStreamMode != PACKAGE_STREAM_RAW || !GetOwnSeekStream().is() ) throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - if ( xEncryptionData.isEmpty() ) + if ( m_xBaseEncryptionData.is() ) throw ZipIOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Encrypted stream without encryption data!\n" ) ), - Reference< XInterface >() ); + uno::Reference< XInterface >() ); uno::Reference< io::XSeekable > xSeek( GetOwnSeekStream(), UNO_QUERY ); if ( !xSeek.is() ) throw ZipIOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "The stream must be seekable!\n" ) ), - Reference< XInterface >() ); + uno::Reference< XInterface >() ); // skip header - xSeek->seek( n_ConstHeaderSize + xEncryptionData->aInitVector.getLength() + - xEncryptionData->aSalt.getLength() + xEncryptionData->aDigest.getLength() ); + xSeek->seek( n_ConstHeaderSize + getInitialisationVector().getLength() + + getSalt().getLength() + getDigest().getLength() ); // create temporary stream uno::Reference < io::XOutputStream > xTempOut( @@ -194,17 +200,95 @@ uno::Reference< io::XInputStream > ZipPackageStream::GetRawEncrStreamNoHeaderCop } //-------------------------------------------------------------------------- -Reference< io::XInputStream > ZipPackageStream::TryToGetRawFromDataStream( sal_Bool bAddHeaderForEncr ) +sal_Int32 ZipPackageStream::GetEncryptionAlgorithm() const { - if ( m_nStreamMode != PACKAGE_STREAM_DATA || !GetOwnSeekStream().is() || (bAddHeaderForEncr && !bToBeEncrypted) ) + return m_nImportedEncryptionAlgorithm ? m_nImportedEncryptionAlgorithm : rZipPackage.GetEncAlgID(); +} + +//-------------------------------------------------------------------------- +sal_Int32 ZipPackageStream::GetBlockSize() const +{ + return GetEncryptionAlgorithm() == ::com::sun::star::xml::crypto::CipherID::AES_CBC_W3C_PADDING ? 16 : 8; +} + +//-------------------------------------------------------------------------- +::rtl::Reference< EncryptionData > ZipPackageStream::GetEncryptionData( bool bUseWinEncoding ) +{ + ::rtl::Reference< EncryptionData > xResult; + if ( m_xBaseEncryptionData.is() ) + xResult = new EncryptionData( + *m_xBaseEncryptionData, + GetEncryptionKey( bUseWinEncoding ), + GetEncryptionAlgorithm(), + m_nImportedChecksumAlgorithm ? m_nImportedChecksumAlgorithm : rZipPackage.GetChecksumAlgID(), + m_nImportedDerivedKeySize ? m_nImportedDerivedKeySize : rZipPackage.GetDefaultDerivedKeySize(), + GetStartKeyGenID() ); + + return xResult; +} + +//-------------------------------------------------------------------------- +void ZipPackageStream::SetBaseEncryptionData( const ::rtl::Reference< BaseEncryptionData >& xData ) +{ + m_xBaseEncryptionData = xData; +} + +//-------------------------------------------------------------------------- +uno::Sequence< sal_Int8 > ZipPackageStream::GetEncryptionKey( bool bUseWinEncoding ) +{ + uno::Sequence< sal_Int8 > aResult; + sal_Int32 nKeyGenID = GetStartKeyGenID(); + bUseWinEncoding = ( bUseWinEncoding || m_bUseWinEncoding ); + + if ( bHaveOwnKey && m_aStorageEncryptionKeys.getLength() ) + { + ::rtl::OUString aNameToFind; + if ( nKeyGenID == xml::crypto::DigestID::SHA256 ) + aNameToFind = PACKAGE_ENCRYPTIONDATA_SHA256UTF8; + else if ( nKeyGenID == xml::crypto::DigestID::SHA1 ) + { + aNameToFind = bUseWinEncoding ? PACKAGE_ENCRYPTIONDATA_SHA1MS1252 : PACKAGE_ENCRYPTIONDATA_SHA1UTF8; + } + else + throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "No expected key is provided!" ) ), uno::Reference< uno::XInterface >() ); + + for ( sal_Int32 nInd = 0; nInd < m_aStorageEncryptionKeys.getLength(); nInd++ ) + if ( m_aStorageEncryptionKeys[nInd].Name.equals( aNameToFind ) ) + m_aStorageEncryptionKeys[nInd].Value >>= aResult; + + // empty keys are not allowed here + // so it is not important whether there is no key, or the key is empty, it is an error + if ( !aResult.getLength() ) + throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "No expected key is provided!" ) ), uno::Reference< uno::XInterface >() ); + } + else + aResult = m_aEncryptionKey; + + if ( !aResult.getLength() || !bHaveOwnKey ) + aResult = rZipPackage.GetEncryptionKey(); + + return aResult; +} + +//-------------------------------------------------------------------------- +sal_Int32 ZipPackageStream::GetStartKeyGenID() +{ + // 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(); +} + +//-------------------------------------------------------------------------- +uno::Reference< io::XInputStream > ZipPackageStream::TryToGetRawFromDataStream( sal_Bool bAddHeaderForEncr ) +{ + if ( m_nStreamMode != PACKAGE_STREAM_DATA || !GetOwnSeekStream().is() || ( bAddHeaderForEncr && !bToBeEncrypted ) ) throw packages::NoEncryptionException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); Sequence< sal_Int8 > aKey; if ( bToBeEncrypted ) { - aKey = ( xEncryptionData.isEmpty() || !bHaveOwnKey ) ? rZipPackage.getEncryptionKey() : - xEncryptionData->aKey; + aKey = GetEncryptionKey(); if ( !aKey.getLength() ) throw packages::NoEncryptionException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); } @@ -220,7 +304,7 @@ Reference< io::XInputStream > ZipPackageStream::TryToGetRawFromDataStream( sal_B // create a package based on it ZipPackage* pPackage = new ZipPackage( m_xFactory ); - Reference< XSingleServiceFactory > xPackageAsFactory( static_cast< XSingleServiceFactory* >( pPackage ) ); + uno::Reference< XSingleServiceFactory > xPackageAsFactory( static_cast< XSingleServiceFactory* >( pPackage ) ); if ( !xPackageAsFactory.is() ) throw RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); @@ -229,14 +313,14 @@ Reference< io::XInputStream > ZipPackageStream::TryToGetRawFromDataStream( sal_B pPackage->initialize( aArgs ); // create a new package stream - Reference< XDataSinkEncrSupport > xNewPackStream( xPackageAsFactory->createInstance(), UNO_QUERY ); + uno::Reference< XDataSinkEncrSupport > xNewPackStream( xPackageAsFactory->createInstance(), UNO_QUERY ); if ( !xNewPackStream.is() ) throw RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); xNewPackStream->setDataStream( static_cast< io::XInputStream* >( new WrapStreamForShare( GetOwnSeekStream(), rZipPackage.GetSharedMutexRef() ) ) ); - Reference< XPropertySet > xNewPSProps( xNewPackStream, UNO_QUERY ); + uno::Reference< XPropertySet > xNewPSProps( xNewPackStream, UNO_QUERY ); if ( !xNewPSProps.is() ) throw RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); @@ -245,26 +329,26 @@ Reference< io::XInputStream > ZipPackageStream::TryToGetRawFromDataStream( sal_B xNewPSProps->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Compressed" ) ), makeAny( bToBeCompressed ) ); if ( bToBeEncrypted ) { - xNewPSProps->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "EncryptionKey" ) ), makeAny( aKey ) ); + xNewPSProps->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ENCRYPTION_KEY_PROPERTY ) ), makeAny( aKey ) ); xNewPSProps->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Encrypted" ) ), makeAny( sal_True ) ); } // insert a new stream in the package - Reference< XUnoTunnel > xTunnel; + uno::Reference< XUnoTunnel > xTunnel; Any aRoot = pPackage->getByHierarchicalName( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/" ) ) ); aRoot >>= xTunnel; - Reference< container::XNameContainer > xRootNameContainer( xTunnel, UNO_QUERY ); + uno::Reference< container::XNameContainer > xRootNameContainer( xTunnel, UNO_QUERY ); if ( !xRootNameContainer.is() ) throw RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - Reference< XUnoTunnel > xNPSTunnel( xNewPackStream, UNO_QUERY ); + uno::Reference< XUnoTunnel > xNPSTunnel( xNewPackStream, UNO_QUERY ); xRootNameContainer->insertByName( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "dummy" ) ), makeAny( xNPSTunnel ) ); // commit the temporary package pPackage->commitChanges(); // get raw stream from the temporary package - Reference< io::XInputStream > xInRaw; + uno::Reference< io::XInputStream > xInRaw; if ( bAddHeaderForEncr ) xInRaw = xNewPackStream->getRawStream(); else @@ -285,12 +369,12 @@ Reference< io::XInputStream > ZipPackageStream::TryToGetRawFromDataStream( sal_B xTempSeek->seek( 0 ); // close raw stream, package stream and folder - xInRaw = Reference< io::XInputStream >(); - xNewPSProps = Reference< XPropertySet >(); - xNPSTunnel = Reference< XUnoTunnel >(); - xNewPackStream = Reference< XDataSinkEncrSupport >(); - xTunnel = Reference< XUnoTunnel >(); - xRootNameContainer = Reference< container::XNameContainer >(); + xInRaw = uno::Reference< io::XInputStream >(); + xNewPSProps = uno::Reference< XPropertySet >(); + xNPSTunnel = uno::Reference< XUnoTunnel >(); + xNewPackStream = uno::Reference< XDataSinkEncrSupport >(); + xTunnel = uno::Reference< XUnoTunnel >(); + xRootNameContainer = uno::Reference< container::XNameContainer >(); // return the stream representing the first temporary file return xTempIn; @@ -316,7 +400,7 @@ sal_Bool ZipPackageStream::ParsePackageRawStream() sal_Bool bOk = sal_False; - vos::ORef < EncryptionData > xTempEncrData; + ::rtl::Reference< BaseEncryptionData > xTempEncrData; sal_Int32 nMagHackSize = 0; Sequence < sal_Int8 > aHeader ( 4 ); @@ -332,17 +416,25 @@ sal_Bool ZipPackageStream::ParsePackageRawStream() if ( nHeader == n_ConstHeader ) { // this is one of our god-awful, but extremely devious hacks, everyone cheer - xTempEncrData = new EncryptionData; + xTempEncrData = new BaseEncryptionData; ::rtl::OUString aMediaType; - if ( ZipFile::StaticFillData ( xTempEncrData, nMagHackSize, aMediaType, GetOwnSeekStream() ) ) + sal_Int32 nEncAlgorithm = 0; + sal_Int32 nChecksumAlgorithm = 0; + sal_Int32 nDerivedKeySize = 0; + 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 - m_nMagicalHackPos = n_ConstHeaderSize + xTempEncrData->aSalt.getLength() - + xTempEncrData->aInitVector.getLength() - + xTempEncrData->aDigest.getLength() + m_nMagicalHackPos = n_ConstHeaderSize + xTempEncrData->m_aSalt.getLength() + + xTempEncrData->m_aInitVector.getLength() + + xTempEncrData->m_aDigest.getLength() + aMediaType.getLength() * sizeof( sal_Unicode ); + m_nImportedEncryptionAlgorithm = nEncAlgorithm; + m_nImportedChecksumAlgorithm = nChecksumAlgorithm; + m_nImportedDerivedKeySize = nDerivedKeySize; + m_nImportedStartKeyAlgorithm = nStartKeyGenID; m_nMagicalHackSize = nMagHackSize; sMediaType = aMediaType; @@ -361,7 +453,7 @@ sal_Bool ZipPackageStream::ParsePackageRawStream() return sal_False; } - xEncryptionData = xTempEncrData; + m_xBaseEncryptionData = xTempEncrData; SetIsEncrypted ( sal_True ); // it's already compressed and encrypted bToBeEncrypted = bToBeCompressed = sal_False; @@ -383,11 +475,12 @@ void ZipPackageStream::SetPackageMember( sal_Bool bNewValue ) // XActiveDataSink //-------------------------------------------------------------------------- -void SAL_CALL ZipPackageStream::setInputStream( const Reference< io::XInputStream >& aStream ) - throw(RuntimeException) +void SAL_CALL ZipPackageStream::setInputStream( const uno::Reference< io::XInputStream >& aStream ) + throw( RuntimeException ) { // if seekable access is required the wrapping will be done on demand xStream = aStream; + m_nImportedEncryptionAlgorithm = 0; m_bHasSeekable = sal_False; SetPackageMember ( sal_False ); aEntry.nTime = -1; @@ -395,94 +488,100 @@ void SAL_CALL ZipPackageStream::setInputStream( const Reference< io::XInputStrea } //-------------------------------------------------------------------------- -Reference< io::XInputStream > SAL_CALL ZipPackageStream::getRawData() - throw(RuntimeException) +uno::Reference< io::XInputStream > SAL_CALL ZipPackageStream::getRawData() + throw( RuntimeException ) { try { - if (IsPackageMember()) + if ( IsPackageMember() ) { - if ( !xEncryptionData.isEmpty() && !bHaveOwnKey ) - xEncryptionData->aKey = rZipPackage.getEncryptionKey(); - return rZipPackage.getZipFile().getRawData( aEntry, xEncryptionData, bIsEncrypted, rZipPackage.GetSharedMutexRef() ); + return rZipPackage.getZipFile().getRawData( aEntry, GetEncryptionData(), bIsEncrypted, rZipPackage.GetSharedMutexRef() ); } else if ( GetOwnSeekStream().is() ) { return new WrapStreamForShare( GetOwnSeekStream(), rZipPackage.GetSharedMutexRef() ); } else - return Reference < io::XInputStream > (); + return uno::Reference < io::XInputStream > (); } - catch (ZipException &)//rException) + catch ( ZipException & )//rException ) { - VOS_ENSURE( 0, "ZipException thrown");//rException.Message); - return Reference < io::XInputStream > (); + VOS_ENSURE( 0, "ZipException thrown" );//rException.Message ); + return uno::Reference < io::XInputStream > (); } - catch (Exception &) + catch ( Exception & ) { - VOS_ENSURE( 0, "Exception is thrown during stream wrapping!\n"); - return Reference < io::XInputStream > (); + VOS_ENSURE( 0, "Exception is thrown during stream wrapping!\n" ); + return uno::Reference < io::XInputStream > (); } } //-------------------------------------------------------------------------- -Reference< io::XInputStream > SAL_CALL ZipPackageStream::getInputStream( ) - throw(RuntimeException) +uno::Reference< io::XInputStream > SAL_CALL ZipPackageStream::getInputStream() + throw( RuntimeException ) { try { - if (IsPackageMember()) + if ( IsPackageMember() ) { - if ( !xEncryptionData.isEmpty() && !bHaveOwnKey ) - xEncryptionData->aKey = rZipPackage.getEncryptionKey(); - return rZipPackage.getZipFile().getInputStream( aEntry, xEncryptionData, bIsEncrypted, rZipPackage.GetSharedMutexRef() ); + return rZipPackage.getZipFile().getInputStream( aEntry, GetEncryptionData(), bIsEncrypted, rZipPackage.GetSharedMutexRef() ); } else if ( GetOwnSeekStream().is() ) { return new WrapStreamForShare( GetOwnSeekStream(), rZipPackage.GetSharedMutexRef() ); } else - return Reference < io::XInputStream > (); + return uno::Reference < io::XInputStream > (); } - catch (ZipException &)//rException) + catch ( ZipException & )//rException ) { - VOS_ENSURE( 0,"ZipException thrown");//rException.Message); - return Reference < io::XInputStream > (); + VOS_ENSURE( 0,"ZipException thrown" );//rException.Message ); + return uno::Reference < io::XInputStream > (); } - catch (Exception &) + catch ( Exception & ) { - VOS_ENSURE( 0, "Exception is thrown during stream wrapping!\n"); - return Reference < io::XInputStream > (); + VOS_ENSURE( 0, "Exception is thrown during stream wrapping!\n" ); + return uno::Reference < io::XInputStream > (); } } // XDataSinkEncrSupport //-------------------------------------------------------------------------- -Reference< io::XInputStream > SAL_CALL ZipPackageStream::getDataStream() +uno::Reference< io::XInputStream > SAL_CALL ZipPackageStream::getDataStream() throw ( packages::WrongPasswordException, io::IOException, RuntimeException ) { // There is no stream attached to this object if ( m_nStreamMode == PACKAGE_STREAM_NOTSET ) - return Reference< io::XInputStream >(); + return uno::Reference< io::XInputStream >(); // this method can not be used together with old approach if ( m_nStreamMode == PACKAGE_STREAM_DETECT ) throw packages::zip::ZipIOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - if ( !xEncryptionData.isEmpty() && !bHaveOwnKey ) - xEncryptionData->aKey = rZipPackage.getEncryptionKey(); - - if (IsPackageMember()) + if ( IsPackageMember() ) { - if ( !xEncryptionData.isEmpty() && !bHaveOwnKey ) - xEncryptionData->aKey = rZipPackage.getEncryptionKey(); - - return rZipPackage.getZipFile().getDataStream( aEntry, xEncryptionData, bIsEncrypted, rZipPackage.GetSharedMutexRef() ); + uno::Reference< io::XInputStream > xResult; + try + { + xResult = rZipPackage.getZipFile().getDataStream( aEntry, GetEncryptionData(), bIsEncrypted, rZipPackage.GetSharedMutexRef() ); + } + catch( packages::WrongPasswordException& ) + { + // workaround for the encrypted documents generated with the old OOo1.x bug. + if ( rZipPackage.GetStartKeyGenID() == xml::crypto::DigestID::SHA1 && !m_bUseWinEncoding ) + { + xResult = rZipPackage.getZipFile().getDataStream( aEntry, GetEncryptionData( true ), bIsEncrypted, rZipPackage.GetSharedMutexRef() ); + m_bUseWinEncoding = true; + } + else + throw; + } + return xResult; } else if ( m_nStreamMode == PACKAGE_STREAM_RAW ) - return ZipFile::StaticGetDataFromRawStream( GetOwnSeekStream(), xEncryptionData ); + return ZipFile::StaticGetDataFromRawStream( m_xFactory, GetOwnSeekStream(), GetEncryptionData() ); else if ( GetOwnSeekStream().is() ) { return new WrapStreamForShare( GetOwnSeekStream(), rZipPackage.GetSharedMutexRef() ); @@ -492,25 +591,25 @@ Reference< io::XInputStream > SAL_CALL ZipPackageStream::getDataStream() } //-------------------------------------------------------------------------- -Reference< io::XInputStream > SAL_CALL ZipPackageStream::getRawStream() +uno::Reference< io::XInputStream > SAL_CALL ZipPackageStream::getRawStream() throw ( packages::NoEncryptionException, io::IOException, uno::RuntimeException ) { // There is no stream attached to this object if ( m_nStreamMode == PACKAGE_STREAM_NOTSET ) - return Reference< io::XInputStream >(); + return uno::Reference< io::XInputStream >(); // this method can not be used together with old approach if ( m_nStreamMode == PACKAGE_STREAM_DETECT ) throw packages::zip::ZipIOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - if (IsPackageMember()) + if ( IsPackageMember() ) { - if ( !bIsEncrypted || xEncryptionData.isEmpty() ) + if ( !bIsEncrypted || !GetEncryptionData().is() ) throw packages::NoEncryptionException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - return rZipPackage.getZipFile().getWrappedRawStream( aEntry, xEncryptionData, sMediaType, rZipPackage.GetSharedMutexRef() ); + return rZipPackage.getZipFile().getWrappedRawStream( aEntry, GetEncryptionData(), sMediaType, rZipPackage.GetSharedMutexRef() ); } else if ( GetOwnSeekStream().is() ) { @@ -527,7 +626,7 @@ Reference< io::XInputStream > SAL_CALL ZipPackageStream::getRawStream() //-------------------------------------------------------------------------- -void SAL_CALL ZipPackageStream::setDataStream( const Reference< io::XInputStream >& aStream ) +void SAL_CALL ZipPackageStream::setDataStream( const uno::Reference< io::XInputStream >& aStream ) throw ( io::IOException, RuntimeException ) { @@ -536,21 +635,21 @@ void SAL_CALL ZipPackageStream::setDataStream( const Reference< io::XInputStream } //-------------------------------------------------------------------------- -void SAL_CALL ZipPackageStream::setRawStream( const Reference< io::XInputStream >& aStream ) +void SAL_CALL ZipPackageStream::setRawStream( const uno::Reference< io::XInputStream >& aStream ) throw ( packages::EncryptionNotAllowedException, packages::NoRawFormatException, io::IOException, - RuntimeException) + RuntimeException ) { // wrap the stream in case it is not seekable - Reference< io::XInputStream > xNewStream = ::comphelper::OSeekableInputWrapper::CheckSeekableCanWrap( aStream, m_xFactory ); - Reference< io::XSeekable > xSeek( xNewStream, UNO_QUERY ); + uno::Reference< io::XInputStream > xNewStream = ::comphelper::OSeekableInputWrapper::CheckSeekableCanWrap( aStream, m_xFactory ); + uno::Reference< io::XSeekable > xSeek( xNewStream, UNO_QUERY ); if ( !xSeek.is() ) throw RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "The stream must support XSeekable!" ) ), - Reference< XInterface >() ); + uno::Reference< XInterface >() ); xSeek->seek( 0 ); - Reference< io::XInputStream > xOldStream = xStream; + uno::Reference< io::XInputStream > xOldStream = xStream; xStream = xNewStream; if ( !ParsePackageRawStream() ) { @@ -573,15 +672,15 @@ uno::Reference< io::XInputStream > SAL_CALL ZipPackageStream::getPlainRawStream( { // There is no stream attached to this object if ( m_nStreamMode == PACKAGE_STREAM_NOTSET ) - return Reference< io::XInputStream >(); + return uno::Reference< io::XInputStream >(); // this method can not be used together with old approach if ( m_nStreamMode == PACKAGE_STREAM_DETECT ) throw packages::zip::ZipIOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - if (IsPackageMember()) + if ( IsPackageMember() ) { - return rZipPackage.getZipFile().getRawData( aEntry, xEncryptionData, bIsEncrypted, rZipPackage.GetSharedMutexRef() ); + return rZipPackage.getZipFile().getRawData( aEntry, GetEncryptionData(), bIsEncrypted, rZipPackage.GetSharedMutexRef() ); } else if ( GetOwnSeekStream().is() ) { @@ -594,14 +693,14 @@ uno::Reference< io::XInputStream > SAL_CALL ZipPackageStream::getPlainRawStream( return TryToGetRawFromDataStream( sal_False ); } - return Reference< io::XInputStream >(); + return uno::Reference< io::XInputStream >(); } // XUnoTunnel //-------------------------------------------------------------------------- sal_Int64 SAL_CALL ZipPackageStream::getSomething( const Sequence< sal_Int8 >& aIdentifier ) - throw(RuntimeException) + throw( RuntimeException ) { sal_Int64 nMe = 0; if ( aIdentifier.getLength() == 16 && @@ -613,18 +712,18 @@ sal_Int64 SAL_CALL ZipPackageStream::getSomething( const Sequence< sal_Int8 >& a // XPropertySet //-------------------------------------------------------------------------- void SAL_CALL ZipPackageStream::setPropertyValue( const OUString& aPropertyName, const Any& aValue ) - throw(beans::UnknownPropertyException, beans::PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException) + throw( beans::UnknownPropertyException, beans::PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException ) { - if (aPropertyName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("MediaType"))) + if ( aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "MediaType" )) ) { if ( rZipPackage.getFormat() != embed::StorageFormats::PACKAGE && rZipPackage.getFormat() != embed::StorageFormats::OFOPXML ) throw beans::PropertyVetoException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); if ( aValue >>= sMediaType ) { - if (sMediaType.getLength() > 0) + if ( sMediaType.getLength() > 0 ) { - if ( sMediaType.indexOf (OUString( RTL_CONSTASCII_USTRINGPARAM ( "text" ) ) ) != -1 + if ( sMediaType.indexOf ( OUString( RTL_CONSTASCII_USTRINGPARAM ( "text" ) ) ) != -1 || sMediaType.equals( OUString( RTL_CONSTASCII_USTRINGPARAM ( "application/vnd.sun.star.oleobject" ) ) ) ) bToBeCompressed = sal_True; else if ( !m_bCompressedIsSetFromOutside ) @@ -633,18 +732,18 @@ void SAL_CALL ZipPackageStream::setPropertyValue( const OUString& aPropertyName, } else throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "MediaType must be a string!\n" ) ), - Reference< XInterface >(), + uno::Reference< XInterface >(), 2 ); } - else if (aPropertyName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("Size") ) ) + else if ( aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Size" ) ) ) { if ( !( aValue >>= aEntry.nSize ) ) throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Wrong type for Size property!\n" ) ), - Reference< XInterface >(), + uno::Reference< XInterface >(), 2 ); } - else if (aPropertyName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("Encrypted") ) ) + else if ( aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Encrypted" ) ) ) { if ( rZipPackage.getFormat() != embed::StorageFormats::PACKAGE ) throw beans::PropertyVetoException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); @@ -655,25 +754,25 @@ void SAL_CALL ZipPackageStream::setPropertyValue( const OUString& aPropertyName, // In case of new raw stream, the stream must not be encrypted on storing if ( bEnc && m_nStreamMode == PACKAGE_STREAM_RAW ) throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Raw stream can not be encrypted on storing" ) ), - Reference< XInterface >(), + uno::Reference< XInterface >(), 2 ); bToBeEncrypted = bEnc; - if ( bToBeEncrypted && xEncryptionData.isEmpty()) - xEncryptionData = new EncryptionData; + if ( bToBeEncrypted && !m_xBaseEncryptionData.is() ) + m_xBaseEncryptionData = new BaseEncryptionData; } else throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Wrong type for Encrypted property!\n" ) ), - Reference< XInterface >(), + uno::Reference< XInterface >(), 2 ); } - else if (aPropertyName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("EncryptionKey") ) ) + else if ( aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ENCRYPTION_KEY_PROPERTY ) ) ) { if ( rZipPackage.getFormat() != embed::StorageFormats::PACKAGE ) throw beans::PropertyVetoException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - Sequence < sal_Int8 > aNewKey; + uno::Sequence< sal_Int8 > aNewKey; if ( !( aValue >>= aNewKey ) ) { @@ -684,31 +783,69 @@ void SAL_CALL ZipPackageStream::setPropertyValue( const OUString& aPropertyName, Sequence < sal_Int8 > aSequence ( nPathLength ); sal_Int8 *pArray = aSequence.getArray(); const sal_Unicode *pChar = sTempString.getStr(); - for ( sal_Int16 i = 0; i < nPathLength; i++) - pArray[i] = static_cast < const sal_Int8 > (pChar[i]); + for ( sal_Int16 i = 0; i < nPathLength; i++ ) + pArray[i] = static_cast < const sal_Int8 > ( pChar[i] ); aNewKey = aSequence; } else throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Wrong type for EncryptionKey property!\n" ) ), - Reference< XInterface >(), + uno::Reference< XInterface >(), 2 ); } if ( aNewKey.getLength() ) { - if ( xEncryptionData.isEmpty()) - xEncryptionData = new EncryptionData; + if ( !m_xBaseEncryptionData.is() ) + m_xBaseEncryptionData = new BaseEncryptionData; + + m_aEncryptionKey = aNewKey; + // In case of new raw stream, the stream must not be encrypted on storing + bHaveOwnKey = sal_True; + if ( m_nStreamMode != PACKAGE_STREAM_RAW ) + bToBeEncrypted = sal_True; + } + else + { + bHaveOwnKey = sal_False; + m_aEncryptionKey.realloc( 0 ); + } + + m_aStorageEncryptionKeys.realloc( 0 ); + } + else if ( aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( STORAGE_ENCRYPTION_KEYS_PROPERTY ) ) ) + { + if ( rZipPackage.getFormat() != embed::StorageFormats::PACKAGE ) + throw beans::PropertyVetoException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); + + uno::Sequence< beans::NamedValue > aKeys; + if ( !( aValue >>= aKeys ) ) + { + throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Wrong type for StorageEncryptionKeys property!\n" ) ), + uno::Reference< XInterface >(), + 2 ); + } + + if ( aKeys.getLength() ) + { + if ( !m_xBaseEncryptionData.is() ) + m_xBaseEncryptionData = new BaseEncryptionData; + + m_aStorageEncryptionKeys = aKeys; - xEncryptionData->aKey = aNewKey; // In case of new raw stream, the stream must not be encrypted on storing bHaveOwnKey = sal_True; if ( m_nStreamMode != PACKAGE_STREAM_RAW ) bToBeEncrypted = sal_True; } else + { bHaveOwnKey = sal_False; + m_aStorageEncryptionKeys.realloc( 0 ); + } + + m_aEncryptionKey.realloc( 0 ); } - else if (aPropertyName.equalsAsciiL ( RTL_CONSTASCII_STRINGPARAM ( "Compressed" ) ) ) + else if ( aPropertyName.equalsAsciiL ( RTL_CONSTASCII_STRINGPARAM ( "Compressed" ) ) ) { sal_Bool bCompr = sal_False; @@ -717,7 +854,7 @@ void SAL_CALL ZipPackageStream::setPropertyValue( const OUString& aPropertyName, // In case of new raw stream, the stream must not be encrypted on storing if ( bCompr && m_nStreamMode == PACKAGE_STREAM_RAW ) throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Raw stream can not be encrypted on storing" ) ), - Reference< XInterface >(), + uno::Reference< XInterface >(), 2 ); bToBeCompressed = bCompr; @@ -725,7 +862,7 @@ void SAL_CALL ZipPackageStream::setPropertyValue( const OUString& aPropertyName, } else throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Wrong type for Compressed property!\n" ) ), - Reference< XInterface >(), + uno::Reference< XInterface >(), 2 ); } else @@ -734,37 +871,42 @@ void SAL_CALL ZipPackageStream::setPropertyValue( const OUString& aPropertyName, //-------------------------------------------------------------------------- Any SAL_CALL ZipPackageStream::getPropertyValue( const OUString& PropertyName ) - throw(beans::UnknownPropertyException, WrappedTargetException, RuntimeException) + throw( beans::UnknownPropertyException, WrappedTargetException, RuntimeException ) { Any aAny; - if (PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "MediaType" ) ) ) + if ( PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "MediaType" ) ) ) { aAny <<= sMediaType; return aAny; } - else if (PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "Size" ) ) ) + else if ( PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "Size" ) ) ) { aAny <<= aEntry.nSize; return aAny; } - else if (PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "Encrypted" ) ) ) + else if ( PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "Encrypted" ) ) ) { aAny <<= ( m_nStreamMode == PACKAGE_STREAM_RAW ) ? sal_True : bToBeEncrypted; return aAny; } - else if (PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "WasEncrypted" ) ) ) + else if ( PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "WasEncrypted" ) ) ) { aAny <<= bIsEncrypted; return aAny; } - else if (PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "Compressed" ) ) ) + else if ( PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "Compressed" ) ) ) { aAny <<= bToBeCompressed; return aAny; } - else if (PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "EncryptionKey" ) ) ) + else if ( PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ENCRYPTION_KEY_PROPERTY ) ) ) + { + aAny <<= m_aEncryptionKey; + return aAny; + } + else if ( PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( STORAGE_ENCRYPTION_KEYS_PROPERTY ) ) ) { - aAny <<= xEncryptionData.isEmpty () ? Sequence < sal_Int8 > () : xEncryptionData->aKey; + aAny <<= m_aStorageEncryptionKeys; return aAny; } else @@ -772,30 +914,30 @@ Any SAL_CALL ZipPackageStream::getPropertyValue( const OUString& PropertyName ) } //-------------------------------------------------------------------------- -void ZipPackageStream::setSize (const sal_Int32 nNewSize) +void ZipPackageStream::setSize ( const sal_Int32 nNewSize ) { - if (aEntry.nCompressedSize != nNewSize ) + if ( aEntry.nCompressedSize != nNewSize ) aEntry.nMethod = DEFLATED; aEntry.nSize = nNewSize; } //-------------------------------------------------------------------------- OUString ZipPackageStream::getImplementationName() - throw (RuntimeException) + throw ( RuntimeException ) { return OUString ( RTL_CONSTASCII_USTRINGPARAM ( "ZipPackageStream" ) ); } //-------------------------------------------------------------------------- Sequence< OUString > ZipPackageStream::getSupportedServiceNames() - throw (RuntimeException) + throw ( RuntimeException ) { - Sequence< OUString > aNames(1); + Sequence< OUString > aNames( 1 ); aNames[0] = OUString( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.packages.PackageStream" ) ); return aNames; } //-------------------------------------------------------------------------- sal_Bool SAL_CALL ZipPackageStream::supportsService( OUString const & rServiceName ) - throw (RuntimeException) + throw ( RuntimeException ) { return rServiceName == getSupportedServiceNames()[0]; } diff --git a/package/source/zippackage/ZipPackageStream.hxx b/package/source/zippackage/ZipPackageStream.hxx deleted file mode 100644 index 38301d5e7d12..000000000000 --- a/package/source/zippackage/ZipPackageStream.hxx +++ /dev/null @@ -1,197 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ -#ifndef _ZIP_PACKAGE_STREAM_HXX -#define _ZIP_PACKAGE_STREAM_HXX - -#include <com/sun/star/io/XActiveDataSink.hpp> -#include <com/sun/star/io/XSeekable.hpp> -#include <com/sun/star/packages/XDataSinkEncrSupport.hpp> -#include <ZipPackageEntry.hxx> -#ifndef _VOS_REF_H_ -#include <vos/ref.hxx> -#endif -#include <EncryptionData.hxx> -#ifndef _CPPUHELPER_IMPLBASE2_HXX -#include <cppuhelper/implbase2.hxx> -#endif -#include <mutexholder.hxx> - -#define PACKAGE_STREAM_NOTSET 0 -#define PACKAGE_STREAM_PACKAGEMEMBER 1 -#define PACKAGE_STREAM_DETECT 2 -#define PACKAGE_STREAM_DATA 3 -#define PACKAGE_STREAM_RAW 4 - -class ZipPackage; -struct ZipEntry; -class ZipPackageStream : public cppu::ImplInheritanceHelper2 -< - ZipPackageEntry, - ::com::sun::star::io::XActiveDataSink, - ::com::sun::star::packages::XDataSinkEncrSupport -> -{ -protected: - com::sun::star::uno::Reference < com::sun::star::io::XInputStream > xStream; - const ::com::sun::star::uno::Reference < com::sun::star::lang::XMultiServiceFactory > m_xFactory; - ZipPackage &rZipPackage; - sal_Bool bToBeCompressed, bToBeEncrypted, bHaveOwnKey, bIsEncrypted; - vos::ORef < EncryptionData > xEncryptionData; - - sal_uInt8 m_nStreamMode; - sal_uInt32 m_nMagicalHackPos; - sal_uInt32 m_nMagicalHackSize; - - sal_Bool m_bHasSeekable; - - sal_Bool m_bCompressedIsSetFromOutside; - - sal_Bool m_bFromManifest; - - ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& GetOwnSeekStream(); - -public: - sal_Bool HasOwnKey () const { return bHaveOwnKey;} - sal_Bool IsToBeCompressed () const { return bToBeCompressed;} - sal_Bool IsToBeEncrypted () const { return bToBeEncrypted;} - sal_Bool IsEncrypted () const { return bIsEncrypted;} - sal_Bool IsPackageMember () const { return m_nStreamMode == PACKAGE_STREAM_PACKAGEMEMBER;} - - sal_Bool IsFromManifest() const { return m_bFromManifest; } - void SetFromManifest( sal_Bool bValue ) { m_bFromManifest = bValue; } - - vos::ORef < EncryptionData > & getEncryptionData () - { return xEncryptionData;} - const com::sun::star::uno::Sequence < sal_Int8 >& getKey () const - { return xEncryptionData->aKey;} - const com::sun::star::uno::Sequence < sal_uInt8 >& getInitialisationVector () const - { return xEncryptionData->aInitVector;} - const com::sun::star::uno::Sequence < sal_uInt8 >& getDigest () const - { return xEncryptionData->aDigest;} - const com::sun::star::uno::Sequence < sal_uInt8 >& getSalt () const - { return xEncryptionData->aSalt;} - sal_Int32 getIterationCount () const - { return xEncryptionData->nIterationCount;} - sal_Int32 getSize () const - { return aEntry.nSize;} - - sal_uInt8 GetStreamMode() const { return m_nStreamMode; } - sal_uInt32 GetMagicalHackPos() const { return m_nMagicalHackPos; } - sal_uInt32 GetMagicalHackSize() const { return m_nMagicalHackSize; } - - void SetToBeCompressed (sal_Bool bNewValue) { bToBeCompressed = bNewValue;} - void SetIsEncrypted (sal_Bool bNewValue) { bIsEncrypted = bNewValue;} - void SetToBeEncrypted (sal_Bool bNewValue) - { - bToBeEncrypted = bNewValue; - if ( bToBeEncrypted && xEncryptionData.isEmpty()) - xEncryptionData = new EncryptionData; - else if ( !bToBeEncrypted && !xEncryptionData.isEmpty() ) - xEncryptionData.unbind(); - } - void SetPackageMember (sal_Bool bNewValue); - void setKey (const com::sun::star::uno::Sequence < sal_Int8 >& rNewKey ) - { xEncryptionData->aKey = rNewKey;} - void setInitialisationVector (const com::sun::star::uno::Sequence < sal_uInt8 >& rNewVector ) - { xEncryptionData->aInitVector = rNewVector;} - void setSalt (const com::sun::star::uno::Sequence < sal_uInt8 >& rNewSalt ) - { xEncryptionData->aSalt = rNewSalt;} - void setDigest (const com::sun::star::uno::Sequence < sal_uInt8 >& rNewDigest ) - { xEncryptionData->aDigest = rNewDigest;} - void setIterationCount (const sal_Int32 nNewCount) - { xEncryptionData->nIterationCount = nNewCount;} - void setSize (const sal_Int32 nNewSize); - - ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > GetOwnStreamNoWrap() { return xStream; } - - void CloseOwnStreamIfAny(); - - ZipPackageStream ( ZipPackage & rNewPackage, - const ::com::sun::star::uno::Reference < com::sun::star::lang::XMultiServiceFactory >& xFactory, - sal_Bool bAllowRemoveOnInsert ); - virtual ~ZipPackageStream( void ); - - ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > GetRawEncrStreamNoHeaderCopy(); - ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > TryToGetRawFromDataStream( - sal_Bool bAddHeaderForEncr ); - - sal_Bool ParsePackageRawStream(); - - void setZipEntryOnLoading( const ZipEntry &rInEntry); - ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getRawData() - throw(::com::sun::star::uno::RuntimeException); - - static const ::com::sun::star::uno::Sequence < sal_Int8 >& static_getImplementationId(); - - // XActiveDataSink - virtual void SAL_CALL setInputStream( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& aStream ) - throw(::com::sun::star::uno::RuntimeException); - virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getInputStream( ) - throw(::com::sun::star::uno::RuntimeException); - - // XDataSinkEncrSupport - virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getDataStream() - throw ( ::com::sun::star::packages::WrongPasswordException, - ::com::sun::star::io::IOException, - ::com::sun::star::uno::RuntimeException ); - virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getRawStream() - throw ( ::com::sun::star::packages::NoEncryptionException, - ::com::sun::star::io::IOException, - ::com::sun::star::uno::RuntimeException ); - virtual void SAL_CALL setDataStream( - const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& aStream ) - throw ( ::com::sun::star::io::IOException, - ::com::sun::star::uno::RuntimeException ); - virtual void SAL_CALL setRawStream( - const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& aStream ) - throw ( ::com::sun::star::packages::EncryptionNotAllowedException, - ::com::sun::star::packages::NoRawFormatException, - ::com::sun::star::io::IOException, - ::com::sun::star::uno::RuntimeException ); - virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getPlainRawStream() - throw ( ::com::sun::star::io::IOException, - ::com::sun::star::uno::RuntimeException ); - - // XUnoTunnel - virtual sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& aIdentifier ) - throw(::com::sun::star::uno::RuntimeException); - - // XPropertySet - virtual void SAL_CALL setPropertyValue( const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Any& aValue ) - throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); - virtual ::com::sun::star::uno::Any SAL_CALL getPropertyValue( const ::rtl::OUString& PropertyName ) - throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); - - // XServiceInfo - virtual ::rtl::OUString SAL_CALL getImplementationName( ) - throw (::com::sun::star::uno::RuntimeException); - virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) - throw (::com::sun::star::uno::RuntimeException); - virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) - throw (::com::sun::star::uno::RuntimeException); -}; -#endif diff --git a/package/source/zippackage/zipfileaccess.cxx b/package/source/zippackage/zipfileaccess.cxx index 9acae56ad68a..d93e03803204 100644 --- a/package/source/zippackage/zipfileaccess.cxx +++ b/package/source/zippackage/zipfileaccess.cxx @@ -42,6 +42,7 @@ #include <EncryptionData.hxx> #include <ucbhelper/content.hxx> +#include <rtl/ref.hxx> #include <memory> @@ -253,7 +254,7 @@ uno::Any SAL_CALL OZipFileAccess::getByName( const ::rtl::OUString& aName ) throw container::NoSuchElementException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); uno::Reference< io::XInputStream > xEntryStream( m_pZipFile->getDataStream( (*aIter).second, - new EncryptionData(), + ::rtl::Reference< EncryptionData >(), sal_False, m_aMutexHolder ) ); @@ -368,7 +369,7 @@ uno::Reference< io::XInputStream > SAL_CALL OZipFileAccess::getStreamByPattern( if ( StringGoodForPattern_Impl( (*aIter).second.sPath, aPattern ) ) { uno::Reference< io::XInputStream > xEntryStream( m_pZipFile->getDataStream( (*aIter).second, - new EncryptionData(), + ::rtl::Reference< EncryptionData >(), sal_False, m_aMutexHolder ) ); |