diff options
author | Mikhail Voytenko <mav@openoffice.org> | 2011-03-09 17:29:09 +0100 |
---|---|---|
committer | Mikhail Voytenko <mav@openoffice.org> | 2011-03-09 17:29:09 +0100 |
commit | 7422ecbc2a6057dfcd4d2237da3f581965d270f3 (patch) | |
tree | 3fd61f6f4aac635e0a82151c34f15d4510c73204 /package/inc | |
parent | c395e5608ce118f4296083632d6662f278f0b8fc (diff) |
mav60: #164341# support AES encryption
Diffstat (limited to 'package/inc')
-rw-r--r-- | package/inc/EncryptedDataHeader.hxx | 7 | ||||
-rw-r--r-- | package/inc/EncryptionData.hxx | 48 | ||||
-rw-r--r-- | package/inc/PackageConstants.hxx | 9 | ||||
-rw-r--r-- | package/inc/ZipFile.hxx | 41 | ||||
-rw-r--r-- | package/inc/ZipOutputStream.hxx | 6 | ||||
-rw-r--r-- | package/inc/ZipPackage.hxx | 45 | ||||
-rw-r--r-- | package/inc/ZipPackageEntry.hxx | 105 | ||||
-rw-r--r-- | package/inc/ZipPackageFolder.hxx | 2 | ||||
-rw-r--r-- | package/inc/ZipPackageStream.hxx | 210 |
9 files changed, 424 insertions, 49 deletions
diff --git a/package/inc/EncryptedDataHeader.hxx b/package/inc/EncryptedDataHeader.hxx index a166397cce34..70d83ea300d7 100644 --- a/package/inc/EncryptedDataHeader.hxx +++ b/package/inc/EncryptedDataHeader.hxx @@ -35,6 +35,9 @@ Version number 2 bytes Iteraction count 4 bytes Size 4 bytes + EncAlgorithm 4 bytes + DigestAlgorithm 4 bytes + DerivedKeySize 4 bytes Salt length 2 bytes IV length 2 bytes Digest length 2 bytes @@ -45,7 +48,7 @@ MediaType X bytes */ -const sal_uInt32 n_ConstHeader = 0x0502474dL; // "MG\002\005" -const sal_Int32 n_ConstHeaderSize = 22; // + salt length + iv length + digest length + mediatype length +const sal_uInt32 n_ConstHeader = 0x05024d4dL; // "MM\002\005" +const sal_Int32 n_ConstHeaderSize = 34; // + salt length + iv length + digest length + mediatype length const sal_Int16 n_ConstCurrentVersion = 1; #endif diff --git a/package/inc/EncryptionData.hxx b/package/inc/EncryptionData.hxx index 66d74f739b9c..1182ee66e14b 100644 --- a/package/inc/EncryptionData.hxx +++ b/package/inc/EncryptionData.hxx @@ -30,14 +30,48 @@ #include <com/sun/star/uno/Sequence.hxx> #include <cppuhelper/weak.hxx> -class EncryptionData : public cppu::OWeakObject +class BaseEncryptionData : public cppu::OWeakObject { public: - // On export aKey holds the derived key - // On import aKey holds the hash of the user enterred key - com::sun::star::uno::Sequence < sal_Int8 > aKey; - com::sun::star::uno::Sequence < sal_uInt8 > aSalt, aInitVector, aDigest; - sal_Int32 nIterationCount; - EncryptionData(): nIterationCount ( 0 ){} + ::com::sun::star::uno::Sequence< sal_uInt8 > m_aSalt; + ::com::sun::star::uno::Sequence< sal_uInt8 > m_aInitVector; + ::com::sun::star::uno::Sequence< sal_uInt8 > m_aDigest; + sal_Int32 m_nIterationCount; + + BaseEncryptionData() + : m_nIterationCount ( 0 ){} + + BaseEncryptionData( const BaseEncryptionData& aData ) + : m_aSalt( aData.m_aSalt ) + , m_aInitVector( aData.m_aInitVector ) + , m_aDigest( aData.m_aDigest ) + , m_nIterationCount( aData.m_nIterationCount ) + {} }; + +class EncryptionData : public BaseEncryptionData +{ +public: + ::com::sun::star::uno::Sequence < sal_Int8 > m_aKey; + sal_Int32 m_nEncAlg; + sal_Int32 m_nCheckAlg; + sal_Int32 m_nDerivedKeySize; + + EncryptionData( const BaseEncryptionData& aData, const ::com::sun::star::uno::Sequence< sal_Int8 >& aKey, sal_Int32 nEncAlg, sal_Int32 nCheckAlg, sal_Int32 nDerivedKeySize ) + : BaseEncryptionData( aData ) + , m_aKey( aKey ) + , m_nEncAlg( nEncAlg ) + , m_nCheckAlg( nCheckAlg ) + , m_nDerivedKeySize( nDerivedKeySize ) + {} + + EncryptionData( const EncryptionData& aData ) + : BaseEncryptionData( aData ) + , m_aKey( aData.m_aKey ) + , m_nEncAlg( aData.m_nEncAlg ) + , m_nCheckAlg( aData.m_nCheckAlg ) + , m_nDerivedKeySize( aData.m_nDerivedKeySize ) + {} +}; + #endif diff --git a/package/inc/PackageConstants.hxx b/package/inc/PackageConstants.hxx index a23a22fcb888..9314d0866cef 100644 --- a/package/inc/PackageConstants.hxx +++ b/package/inc/PackageConstants.hxx @@ -47,6 +47,15 @@ const sal_Int32 n_ConstDigestLength = 1024; #define PKG_SIZE_NOENCR_MNFST 3 #define PKG_SIZE_ENCR_MNFST 8 +// the properties related constants +#define ENCRYPTION_KEY_PROPERTY "EncryptionKey" +#define STORAGE_ENCRYPTION_KEYS_PROPERTY "StorageEncryptionKeys" +#define ENCRYPTION_ALGORITHMS_PROPERTY "EncryptionAlgorithms" +#define HAS_ENCRYPTED_ENTRIES_PROPERTY "HasEncryptedEntries" +#define HAS_NONENCRYPTED_ENTRIES_PROPERTY "HasNonEncryptedEntries" +#define IS_INCONSISTENT_PROPERTY "IsInconsistent" +#define MEDIATYPE_FALLBACK_USED_PROPERTY "MediaTypeFallbackUsed" + #endif diff --git a/package/inc/ZipFile.hxx b/package/inc/ZipFile.hxx index be8158c0ba4e..7ea53e78602b 100644 --- a/package/inc/ZipFile.hxx +++ b/package/inc/ZipFile.hxx @@ -31,11 +31,13 @@ #include <com/sun/star/packages/zip/ZipIOException.hpp> #include <com/sun/star/packages/NoEncryptionException.hpp> #include <com/sun/star/packages/WrongPasswordException.hpp> + +#include <rtl/ref.hxx> + #include <ByteGrabber.hxx> #include <HashMaps.hxx> -#ifndef _INFLATER_HXX #include <Inflater.hxx> -#endif +#include <EncryptionData.hxx> #include <mutexholder.hxx> @@ -43,10 +45,7 @@ namespace com { namespace sun { namespace star { namespace lang { class XMultiServiceFactory; } namespace ucb { class XProgressHandler; } } } } -namespace vos -{ - template < class T > class ORef; -} + /* * We impose arbitrary but reasonable limit on ZIP files. */ @@ -57,7 +56,6 @@ namespace vos typedef void* rtlCipher; class ZipEnumeration; -class EncryptionData; class ZipFile { @@ -77,13 +75,13 @@ protected: com::sun::star::uno::Reference < com::sun::star::io::XInputStream > createMemoryStream( ZipEntry & rEntry, - const vos::ORef < EncryptionData > &rData, + const ::rtl::Reference < EncryptionData > &rData, sal_Bool bRawStream, sal_Bool bDecrypt ); com::sun::star::uno::Reference < com::sun::star::io::XInputStream > createFileStream( ZipEntry & rEntry, - const vos::ORef < EncryptionData > &rData, + const ::rtl::Reference < EncryptionData > &rData, sal_Bool bRawStream, sal_Bool bDecrypt ); @@ -91,12 +89,12 @@ protected: com::sun::star::uno::Reference < com::sun::star::io::XInputStream > createUnbufferedStream( SotMutexHolderRef aMutexHolder, ZipEntry & rEntry, - const vos::ORef < EncryptionData > &rData, + const ::rtl::Reference < EncryptionData > &rData, sal_Int8 nStreamMode, sal_Bool bDecrypt, ::rtl::OUString aMediaType = ::rtl::OUString() ); - sal_Bool hasValidPassword ( ZipEntry & rEntry, const vos::ORef < EncryptionData > &rData ); + sal_Bool hasValidPassword ( ZipEntry & rEntry, const ::rtl::Reference < EncryptionData > &rData ); sal_Bool checkSizeAndCRC( const ZipEntry& aEntry ); @@ -127,44 +125,47 @@ public: void setInputStream ( com::sun::star::uno::Reference < com::sun::star::io::XInputStream > xNewStream ); ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getRawData( ZipEntry& rEntry, - const vos::ORef < EncryptionData > &rData, + const ::rtl::Reference < EncryptionData > &rData, sal_Bool bDecrypt, SotMutexHolderRef aMutexHolder ) throw(::com::sun::star::io::IOException, ::com::sun::star::packages::zip::ZipException, ::com::sun::star::uno::RuntimeException); - static sal_Bool StaticGetCipher ( const vos::ORef < EncryptionData > & xEncryptionData, rtlCipher &rCipher, sal_Bool bDecode ); + static sal_Bool StaticGetCipher ( const ::rtl::Reference < EncryptionData > & xEncryptionData, rtlCipher &rCipher, sal_Bool bDecode ); - static void StaticFillHeader ( const vos::ORef < EncryptionData > & rData, + static void StaticFillHeader ( const ::rtl::Reference < EncryptionData > & rData, sal_Int32 nSize, const ::rtl::OUString& aMediaType, sal_Int8 * & pHeader ); - static sal_Bool StaticFillData ( vos::ORef < EncryptionData > & rData, + static sal_Bool StaticFillData ( ::rtl::Reference < BaseEncryptionData > & rData, + sal_Int32 &rEncAlgorithm, + sal_Int32 &rChecksumAlgorithm, + sal_Int32 &rDerivedKeySize, sal_Int32 &rSize, ::rtl::OUString& aMediaType, ::com::sun::star::uno::Reference < com::sun::star::io::XInputStream > &rStream ); static ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > StaticGetDataFromRawStream( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& xStream, - const vos::ORef < EncryptionData > &rData ) + const ::rtl::Reference < EncryptionData > &rData ) throw ( ::com::sun::star::packages::WrongPasswordException, ::com::sun::star::packages::zip::ZipIOException, ::com::sun::star::uno::RuntimeException ); static sal_Bool StaticHasValidPassword ( const ::com::sun::star::uno::Sequence< sal_Int8 > &aReadBuffer, - const vos::ORef < EncryptionData > &rData ); + const ::rtl::Reference < EncryptionData > &rData ); ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getInputStream( ZipEntry& rEntry, - const vos::ORef < EncryptionData > &rData, + const ::rtl::Reference < EncryptionData > &rData, sal_Bool bDecrypt, SotMutexHolderRef aMutexHolder ) throw(::com::sun::star::io::IOException, ::com::sun::star::packages::zip::ZipException, ::com::sun::star::uno::RuntimeException); ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getDataStream( ZipEntry& rEntry, - const vos::ORef < EncryptionData > &rData, + const ::rtl::Reference < EncryptionData > &rData, sal_Bool bDecrypt, SotMutexHolderRef aMutexHolder ) throw ( ::com::sun::star::packages::WrongPasswordException, @@ -174,7 +175,7 @@ public: ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getWrappedRawStream( ZipEntry& rEntry, - const vos::ORef < EncryptionData > &rData, + const ::rtl::Reference < EncryptionData > &rData, const ::rtl::OUString& aMediaType, SotMutexHolderRef aMutexHolder ) throw ( ::com::sun::star::packages::NoEncryptionException, diff --git a/package/inc/ZipOutputStream.hxx b/package/inc/ZipOutputStream.hxx index 345fe332b8cc..ebfb6f52f944 100644 --- a/package/inc/ZipOutputStream.hxx +++ b/package/inc/ZipOutputStream.hxx @@ -40,7 +40,7 @@ #include <vector> struct ZipEntry; -class EncryptionData; +class ZipPackageStream; namespace vos { template < class T > class ORef; @@ -60,7 +60,7 @@ protected: ZipEntry *pCurrentEntry; sal_Int16 nMethod, nLevel, mnDigested; sal_Bool bFinished, bEncryptCurrentEntry; - EncryptionData *pCurrentEncryptData; + ZipPackageStream* m_pCurrentStream; public: ZipOutputStream( com::sun::star::uno::Reference < com::sun::star::io::XOutputStream > &xOStream ); @@ -78,7 +78,7 @@ public: void SAL_CALL setLevel( sal_Int32 nNewLevel ) throw(::com::sun::star::uno::RuntimeException); void SAL_CALL putNextEntry( ZipEntry& rEntry, - vos::ORef < EncryptionData > &rData, + ZipPackageStream* pStream, sal_Bool bEncrypt = sal_False ) throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); void SAL_CALL closeEntry( ) diff --git a/package/inc/ZipPackage.hxx b/package/inc/ZipPackage.hxx index e3b8d44be183..3d0ad38f6aac 100644 --- a/package/inc/ZipPackage.hxx +++ b/package/inc/ZipPackage.hxx @@ -35,11 +35,12 @@ #include <com/sun/star/lang/XUnoTunnel.hpp> #include <com/sun/star/beans/XPropertySet.hpp> #include <com/sun/star/beans/PropertyValue.hpp> -#ifndef _COM_SUN_STAR_LANG_XPSERVICEINFO_HPP_ +#include <com/sun/star/beans/NamedValue.hpp> #include <com/sun/star/lang/XServiceInfo.hpp> -#endif -#include <HashMaps.hxx> +#include <com/sun/star/xml/crypto/CipherID.hpp> #include <com/sun/star/lang/IllegalArgumentException.hpp> + +#include <HashMaps.hxx> #include <osl/file.h> #include <mutexholder.hxx> @@ -83,18 +84,25 @@ class ZipPackage : public cppu::WeakImplHelper7 protected: SotMutexHolderRef m_aMutexHolder; - ::com::sun::star::uno::Sequence < sal_Int8 > m_aEncryptionKey; - FolderHash m_aRecent; - ::rtl::OUString m_aURL; - sal_Bool m_bHasEncryptedEntries; - sal_Bool m_bHasNonEncryptedEntries; - sal_Bool m_bInconsistent; - sal_Bool m_bUseManifest; - sal_Bool m_bForceRecovery; + ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue > m_aStorageEncryptionKeys; + ::com::sun::star::uno::Sequence< sal_Int8 > m_aEncryptionKey; - sal_Bool m_bMediaTypeFallbackUsed; - sal_Int32 m_nFormat; - sal_Bool m_bAllowRemoveOnInsert; + FolderHash m_aRecent; + ::rtl::OUString m_aURL; + + bool m_bStartKeyGenerationImported; + sal_Int32 m_nStartKeyGenerationID; + sal_Int32 m_nChecksumDigestID; + sal_Int32 m_nCommonEncryptionID; + sal_Bool m_bHasEncryptedEntries; + sal_Bool m_bHasNonEncryptedEntries; + + sal_Bool m_bInconsistent; + sal_Bool m_bForceRecovery; + + sal_Bool m_bMediaTypeFallbackUsed; + sal_Int32 m_nFormat; + sal_Bool m_bAllowRemoveOnInsert; InitialisationMode m_eMode; @@ -121,15 +129,20 @@ protected: const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& xTempStream ); public: - ZipPackage (const ::com::sun::star::uno::Reference < com::sun::star::lang::XMultiServiceFactory > &xNewFactory); + ZipPackage( const ::com::sun::star::uno::Reference < com::sun::star::lang::XMultiServiceFactory > &xNewFactory ); virtual ~ZipPackage( void ); ZipFile& getZipFile() { return *m_pZipFile;} - const com::sun::star::uno::Sequence < sal_Int8 > & getEncryptionKey ( ) {return m_aEncryptionKey;} sal_Int32 getFormat() const { return m_nFormat; } + sal_Int32 GetKeyGenID() const { return m_nStartKeyGenerationID; } + sal_Int32 GetEncAlgID() const { return m_nCommonEncryptionID; } + sal_Int32 GetChecksumAlgID() const { return m_nChecksumDigestID; } + sal_Int32 GetDefaultDerivedKeySize() const { return m_nCommonEncryptionID == ::com::sun::star::xml::crypto::CipherID::AES_CBC ? 32 : 16; } + SotMutexHolderRef GetSharedMutexRef() { return m_aMutexHolder; } void ConnectTo( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& xInStream ); + const ::com::sun::star::uno::Sequence< sal_Int8 > GetEncryptionKey(); // XInitialization virtual void SAL_CALL initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments ) diff --git a/package/inc/ZipPackageEntry.hxx b/package/inc/ZipPackageEntry.hxx new file mode 100644 index 000000000000..767d84511a12 --- /dev/null +++ b/package/inc/ZipPackageEntry.hxx @@ -0,0 +1,105 @@ +/************************************************************************* + * + * 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/inc/ZipPackageFolder.hxx b/package/inc/ZipPackageFolder.hxx index 037c27f1fdd7..43774572dd8c 100644 --- a/package/inc/ZipPackageFolder.hxx +++ b/package/inc/ZipPackageFolder.hxx @@ -86,7 +86,7 @@ public: void setRemoveOnInsertMode_Impl( sal_Bool bRemove ) { this->mbAllowRemoveOnInsert = bRemove; } // Recursive functions - void saveContents(rtl::OUString &rPath, std::vector < com::sun::star::uno::Sequence < com::sun::star::beans::PropertyValue > > &rManList, ZipOutputStream & rZipOut, com::sun::star::uno::Sequence < sal_Int8 > &rEncryptionKey, rtlRandomPool & rRandomPool) + void saveContents(rtl::OUString &rPath, std::vector < com::sun::star::uno::Sequence < com::sun::star::beans::PropertyValue > > &rManList, ZipOutputStream & rZipOut, const com::sun::star::uno::Sequence< sal_Int8 > &rEncryptionKey, rtlRandomPool & rRandomPool) throw(::com::sun::star::uno::RuntimeException); void releaseUpwardRef(); diff --git a/package/inc/ZipPackageStream.hxx b/package/inc/ZipPackageStream.hxx new file mode 100644 index 000000000000..5ea0c82ce047 --- /dev/null +++ b/package/inc/ZipPackageStream.hxx @@ -0,0 +1,210 @@ +/************************************************************************* + * + * 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/beans/NamedValue.hpp> +#include <com/sun/star/packages/XDataSinkEncrSupport.hpp> + +#include <rtl/ref.hxx> +#include <cppuhelper/implbase2.hxx> + +#include <ZipPackageEntry.hxx> +#include <EncryptionData.hxx> +#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; + + ::rtl::Reference< BaseEncryptionData > m_xBaseEncryptionData; + ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue > m_aStorageEncryptionKeys; + ::com::sun::star::uno::Sequence< sal_Int8 > m_aEncryptionKey; + + sal_Int32 m_nImportedEncryptionAlgorithm; + sal_Int32 m_nImportedChecksumAlgorithm; + sal_Int32 m_nImportedDerivedKeySize; + + sal_uInt8 m_nStreamMode; + sal_uInt32 m_nMagicalHackPos; + sal_uInt32 m_nMagicalHackSize; + + sal_Bool m_bHasSeekable; + + sal_Bool m_bCompressedIsSetFromOutside; + + sal_Bool m_bFromManifest; + + bool m_bUseWinEncoding; + + ::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; } + + ::rtl::Reference< EncryptionData > GetEncryptionData( bool bWinEncoding = false ); + void SetBaseEncryptionData( const ::rtl::Reference< BaseEncryptionData >& xData ); + + ::com::sun::star::uno::Sequence< sal_Int8 > GetEncryptionKey( bool bWinEncoding = false ); + + const com::sun::star::uno::Sequence < sal_uInt8 >& getInitialisationVector () const + { return m_xBaseEncryptionData->m_aInitVector;} + const com::sun::star::uno::Sequence < sal_uInt8 >& getDigest () const + { return m_xBaseEncryptionData->m_aDigest;} + const com::sun::star::uno::Sequence < sal_uInt8 >& getSalt () const + { return m_xBaseEncryptionData->m_aSalt;} + sal_Int32 getIterationCount () const + { return m_xBaseEncryptionData->m_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 SetImportedEncryptionAlgorithm( sal_Int32 nAlgorithm ) { m_nImportedEncryptionAlgorithm = nAlgorithm; } + void SetImportedChecksumAlgorithm( sal_Int32 nAlgorithm ) { m_nImportedChecksumAlgorithm = nAlgorithm; } + void SetImportedDerivedKeySize( sal_Int32 nSize ) { m_nImportedDerivedKeySize = nSize; } + void SetToBeEncrypted (sal_Bool bNewValue) + { + bToBeEncrypted = bNewValue; + if ( bToBeEncrypted && !m_xBaseEncryptionData.is()) + m_xBaseEncryptionData = new BaseEncryptionData; + else if ( !bToBeEncrypted && m_xBaseEncryptionData.is() ) + m_xBaseEncryptionData.clear(); + } + void SetPackageMember (sal_Bool bNewValue); + + void setKey (const com::sun::star::uno::Sequence < sal_Int8 >& rNewKey ) + { m_aEncryptionKey = rNewKey; m_aStorageEncryptionKeys.realloc( 0 ); } + void setInitialisationVector (const com::sun::star::uno::Sequence < sal_uInt8 >& rNewVector ) + { m_xBaseEncryptionData->m_aInitVector = rNewVector;} + void setSalt (const com::sun::star::uno::Sequence < sal_uInt8 >& rNewSalt ) + { m_xBaseEncryptionData->m_aSalt = rNewSalt;} + void setDigest (const com::sun::star::uno::Sequence < sal_uInt8 >& rNewDigest ) + { m_xBaseEncryptionData->m_aDigest = rNewDigest;} + void setIterationCount (const sal_Int32 nNewCount) + { m_xBaseEncryptionData->m_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 |