1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir #ifndef _ZIP_PACKAGE_STREAM_HXX 28*cdf0e10cSrcweir #define _ZIP_PACKAGE_STREAM_HXX 29*cdf0e10cSrcweir 30*cdf0e10cSrcweir #include <com/sun/star/io/XActiveDataSink.hpp> 31*cdf0e10cSrcweir #include <com/sun/star/io/XSeekable.hpp> 32*cdf0e10cSrcweir #include <com/sun/star/beans/NamedValue.hpp> 33*cdf0e10cSrcweir #include <com/sun/star/packages/XDataSinkEncrSupport.hpp> 34*cdf0e10cSrcweir 35*cdf0e10cSrcweir #include <rtl/ref.hxx> 36*cdf0e10cSrcweir #include <cppuhelper/implbase2.hxx> 37*cdf0e10cSrcweir 38*cdf0e10cSrcweir #include <ZipPackageEntry.hxx> 39*cdf0e10cSrcweir #include <EncryptionData.hxx> 40*cdf0e10cSrcweir #include <mutexholder.hxx> 41*cdf0e10cSrcweir 42*cdf0e10cSrcweir #define PACKAGE_STREAM_NOTSET 0 43*cdf0e10cSrcweir #define PACKAGE_STREAM_PACKAGEMEMBER 1 44*cdf0e10cSrcweir #define PACKAGE_STREAM_DETECT 2 45*cdf0e10cSrcweir #define PACKAGE_STREAM_DATA 3 46*cdf0e10cSrcweir #define PACKAGE_STREAM_RAW 4 47*cdf0e10cSrcweir 48*cdf0e10cSrcweir class ZipPackage; 49*cdf0e10cSrcweir struct ZipEntry; 50*cdf0e10cSrcweir class ZipPackageStream : public cppu::ImplInheritanceHelper2 51*cdf0e10cSrcweir < 52*cdf0e10cSrcweir ZipPackageEntry, 53*cdf0e10cSrcweir ::com::sun::star::io::XActiveDataSink, 54*cdf0e10cSrcweir ::com::sun::star::packages::XDataSinkEncrSupport 55*cdf0e10cSrcweir > 56*cdf0e10cSrcweir { 57*cdf0e10cSrcweir protected: 58*cdf0e10cSrcweir com::sun::star::uno::Reference < com::sun::star::io::XInputStream > xStream; 59*cdf0e10cSrcweir const ::com::sun::star::uno::Reference < com::sun::star::lang::XMultiServiceFactory > m_xFactory; 60*cdf0e10cSrcweir ZipPackage &rZipPackage; 61*cdf0e10cSrcweir sal_Bool bToBeCompressed, bToBeEncrypted, bHaveOwnKey, bIsEncrypted; 62*cdf0e10cSrcweir 63*cdf0e10cSrcweir ::rtl::Reference< BaseEncryptionData > m_xBaseEncryptionData; 64*cdf0e10cSrcweir ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue > m_aStorageEncryptionKeys; 65*cdf0e10cSrcweir ::com::sun::star::uno::Sequence< sal_Int8 > m_aEncryptionKey; 66*cdf0e10cSrcweir 67*cdf0e10cSrcweir sal_Int32 m_nImportedStartKeyAlgorithm; 68*cdf0e10cSrcweir sal_Int32 m_nImportedEncryptionAlgorithm; 69*cdf0e10cSrcweir sal_Int32 m_nImportedChecksumAlgorithm; 70*cdf0e10cSrcweir sal_Int32 m_nImportedDerivedKeySize; 71*cdf0e10cSrcweir 72*cdf0e10cSrcweir sal_uInt8 m_nStreamMode; 73*cdf0e10cSrcweir sal_uInt32 m_nMagicalHackPos; 74*cdf0e10cSrcweir sal_uInt32 m_nMagicalHackSize; 75*cdf0e10cSrcweir 76*cdf0e10cSrcweir sal_Bool m_bHasSeekable; 77*cdf0e10cSrcweir 78*cdf0e10cSrcweir sal_Bool m_bCompressedIsSetFromOutside; 79*cdf0e10cSrcweir 80*cdf0e10cSrcweir sal_Bool m_bFromManifest; 81*cdf0e10cSrcweir 82*cdf0e10cSrcweir bool m_bUseWinEncoding; 83*cdf0e10cSrcweir 84*cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > GetOwnSeekStream(); 85*cdf0e10cSrcweir 86*cdf0e10cSrcweir public: 87*cdf0e10cSrcweir sal_Bool HasOwnKey () const { return bHaveOwnKey;} 88*cdf0e10cSrcweir sal_Bool IsToBeCompressed () const { return bToBeCompressed;} 89*cdf0e10cSrcweir sal_Bool IsToBeEncrypted () const { return bToBeEncrypted;} 90*cdf0e10cSrcweir sal_Bool IsEncrypted () const { return bIsEncrypted;} 91*cdf0e10cSrcweir sal_Bool IsPackageMember () const { return m_nStreamMode == PACKAGE_STREAM_PACKAGEMEMBER;} 92*cdf0e10cSrcweir 93*cdf0e10cSrcweir sal_Bool IsFromManifest() const { return m_bFromManifest; } 94*cdf0e10cSrcweir void SetFromManifest( sal_Bool bValue ) { m_bFromManifest = bValue; } 95*cdf0e10cSrcweir 96*cdf0e10cSrcweir ::rtl::Reference< EncryptionData > GetEncryptionData( bool bWinEncoding = false ); 97*cdf0e10cSrcweir void SetBaseEncryptionData( const ::rtl::Reference< BaseEncryptionData >& xData ); 98*cdf0e10cSrcweir 99*cdf0e10cSrcweir ::com::sun::star::uno::Sequence< sal_Int8 > GetEncryptionKey( bool bWinEncoding = false ); 100*cdf0e10cSrcweir 101*cdf0e10cSrcweir sal_Int32 GetStartKeyGenID(); 102*cdf0e10cSrcweir 103*cdf0e10cSrcweir const com::sun::star::uno::Sequence < sal_Int8 > getInitialisationVector () const 104*cdf0e10cSrcweir { return m_xBaseEncryptionData->m_aInitVector;} 105*cdf0e10cSrcweir const com::sun::star::uno::Sequence < sal_Int8 > getDigest () const 106*cdf0e10cSrcweir { return m_xBaseEncryptionData->m_aDigest;} 107*cdf0e10cSrcweir const com::sun::star::uno::Sequence < sal_Int8 > getSalt () const 108*cdf0e10cSrcweir { return m_xBaseEncryptionData->m_aSalt;} 109*cdf0e10cSrcweir sal_Int32 getIterationCount () const 110*cdf0e10cSrcweir { return m_xBaseEncryptionData->m_nIterationCount;} 111*cdf0e10cSrcweir sal_Int32 getSize () const 112*cdf0e10cSrcweir { return aEntry.nSize;} 113*cdf0e10cSrcweir 114*cdf0e10cSrcweir sal_uInt8 GetStreamMode() const { return m_nStreamMode; } 115*cdf0e10cSrcweir sal_uInt32 GetMagicalHackPos() const { return m_nMagicalHackPos; } 116*cdf0e10cSrcweir sal_uInt32 GetMagicalHackSize() const { return m_nMagicalHackSize; } 117*cdf0e10cSrcweir sal_Int32 GetEncryptionAlgorithm() const; 118*cdf0e10cSrcweir sal_Int32 GetBlockSize() const; 119*cdf0e10cSrcweir 120*cdf0e10cSrcweir void SetToBeCompressed (sal_Bool bNewValue) { bToBeCompressed = bNewValue;} 121*cdf0e10cSrcweir void SetIsEncrypted (sal_Bool bNewValue) { bIsEncrypted = bNewValue;} 122*cdf0e10cSrcweir void SetImportedStartKeyAlgorithm( sal_Int32 nAlgorithm ) { m_nImportedStartKeyAlgorithm = nAlgorithm; } 123*cdf0e10cSrcweir void SetImportedEncryptionAlgorithm( sal_Int32 nAlgorithm ) { m_nImportedEncryptionAlgorithm = nAlgorithm; } 124*cdf0e10cSrcweir void SetImportedChecksumAlgorithm( sal_Int32 nAlgorithm ) { m_nImportedChecksumAlgorithm = nAlgorithm; } 125*cdf0e10cSrcweir void SetImportedDerivedKeySize( sal_Int32 nSize ) { m_nImportedDerivedKeySize = nSize; } 126*cdf0e10cSrcweir void SetToBeEncrypted (sal_Bool bNewValue) 127*cdf0e10cSrcweir { 128*cdf0e10cSrcweir bToBeEncrypted = bNewValue; 129*cdf0e10cSrcweir if ( bToBeEncrypted && !m_xBaseEncryptionData.is()) 130*cdf0e10cSrcweir m_xBaseEncryptionData = new BaseEncryptionData; 131*cdf0e10cSrcweir else if ( !bToBeEncrypted && m_xBaseEncryptionData.is() ) 132*cdf0e10cSrcweir m_xBaseEncryptionData.clear(); 133*cdf0e10cSrcweir } 134*cdf0e10cSrcweir void SetPackageMember (sal_Bool bNewValue); 135*cdf0e10cSrcweir 136*cdf0e10cSrcweir void setKey (const com::sun::star::uno::Sequence < sal_Int8 >& rNewKey ) 137*cdf0e10cSrcweir { m_aEncryptionKey = rNewKey; m_aStorageEncryptionKeys.realloc( 0 ); } 138*cdf0e10cSrcweir void setInitialisationVector (const com::sun::star::uno::Sequence < sal_Int8 >& rNewVector ) 139*cdf0e10cSrcweir { m_xBaseEncryptionData->m_aInitVector = rNewVector;} 140*cdf0e10cSrcweir void setSalt (const com::sun::star::uno::Sequence < sal_Int8 >& rNewSalt ) 141*cdf0e10cSrcweir { m_xBaseEncryptionData->m_aSalt = rNewSalt;} 142*cdf0e10cSrcweir void setDigest (const com::sun::star::uno::Sequence < sal_Int8 >& rNewDigest ) 143*cdf0e10cSrcweir { m_xBaseEncryptionData->m_aDigest = rNewDigest;} 144*cdf0e10cSrcweir void setIterationCount (const sal_Int32 nNewCount) 145*cdf0e10cSrcweir { m_xBaseEncryptionData->m_nIterationCount = nNewCount;} 146*cdf0e10cSrcweir void setSize (const sal_Int32 nNewSize); 147*cdf0e10cSrcweir 148*cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > GetOwnStreamNoWrap() { return xStream; } 149*cdf0e10cSrcweir 150*cdf0e10cSrcweir void CloseOwnStreamIfAny(); 151*cdf0e10cSrcweir 152*cdf0e10cSrcweir ZipPackageStream ( ZipPackage & rNewPackage, 153*cdf0e10cSrcweir const ::com::sun::star::uno::Reference < com::sun::star::lang::XMultiServiceFactory >& xFactory, 154*cdf0e10cSrcweir sal_Bool bAllowRemoveOnInsert ); 155*cdf0e10cSrcweir virtual ~ZipPackageStream( void ); 156*cdf0e10cSrcweir 157*cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > GetRawEncrStreamNoHeaderCopy(); 158*cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > TryToGetRawFromDataStream( 159*cdf0e10cSrcweir sal_Bool bAddHeaderForEncr ); 160*cdf0e10cSrcweir 161*cdf0e10cSrcweir sal_Bool ParsePackageRawStream(); 162*cdf0e10cSrcweir 163*cdf0e10cSrcweir void setZipEntryOnLoading( const ZipEntry &rInEntry); 164*cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getRawData() 165*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException); 166*cdf0e10cSrcweir 167*cdf0e10cSrcweir static const ::com::sun::star::uno::Sequence < sal_Int8 >& static_getImplementationId(); 168*cdf0e10cSrcweir 169*cdf0e10cSrcweir // XActiveDataSink 170*cdf0e10cSrcweir virtual void SAL_CALL setInputStream( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& aStream ) 171*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException); 172*cdf0e10cSrcweir virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getInputStream( ) 173*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException); 174*cdf0e10cSrcweir 175*cdf0e10cSrcweir // XDataSinkEncrSupport 176*cdf0e10cSrcweir virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getDataStream() 177*cdf0e10cSrcweir throw ( ::com::sun::star::packages::WrongPasswordException, 178*cdf0e10cSrcweir ::com::sun::star::io::IOException, 179*cdf0e10cSrcweir ::com::sun::star::uno::RuntimeException ); 180*cdf0e10cSrcweir virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getRawStream() 181*cdf0e10cSrcweir throw ( ::com::sun::star::packages::NoEncryptionException, 182*cdf0e10cSrcweir ::com::sun::star::io::IOException, 183*cdf0e10cSrcweir ::com::sun::star::uno::RuntimeException ); 184*cdf0e10cSrcweir virtual void SAL_CALL setDataStream( 185*cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& aStream ) 186*cdf0e10cSrcweir throw ( ::com::sun::star::io::IOException, 187*cdf0e10cSrcweir ::com::sun::star::uno::RuntimeException ); 188*cdf0e10cSrcweir virtual void SAL_CALL setRawStream( 189*cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& aStream ) 190*cdf0e10cSrcweir throw ( ::com::sun::star::packages::EncryptionNotAllowedException, 191*cdf0e10cSrcweir ::com::sun::star::packages::NoRawFormatException, 192*cdf0e10cSrcweir ::com::sun::star::io::IOException, 193*cdf0e10cSrcweir ::com::sun::star::uno::RuntimeException ); 194*cdf0e10cSrcweir virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getPlainRawStream() 195*cdf0e10cSrcweir throw ( ::com::sun::star::io::IOException, 196*cdf0e10cSrcweir ::com::sun::star::uno::RuntimeException ); 197*cdf0e10cSrcweir 198*cdf0e10cSrcweir // XUnoTunnel 199*cdf0e10cSrcweir virtual sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& aIdentifier ) 200*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException); 201*cdf0e10cSrcweir 202*cdf0e10cSrcweir // XPropertySet 203*cdf0e10cSrcweir virtual void SAL_CALL setPropertyValue( const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Any& aValue ) 204*cdf0e10cSrcweir 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); 205*cdf0e10cSrcweir virtual ::com::sun::star::uno::Any SAL_CALL getPropertyValue( const ::rtl::OUString& PropertyName ) 206*cdf0e10cSrcweir throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); 207*cdf0e10cSrcweir 208*cdf0e10cSrcweir // XServiceInfo 209*cdf0e10cSrcweir virtual ::rtl::OUString SAL_CALL getImplementationName( ) 210*cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException); 211*cdf0e10cSrcweir virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) 212*cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException); 213*cdf0e10cSrcweir virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) 214*cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException); 215*cdf0e10cSrcweir }; 216*cdf0e10cSrcweir #endif 217