summaryrefslogtreecommitdiff
path: root/package/inc
diff options
context:
space:
mode:
authorNorbert Thiebaud <nthiebaud@gmail.com>2011-08-21 18:12:16 -0500
committerNorbert Thiebaud <nthiebaud@gmail.com>2011-08-21 18:12:16 -0500
commit0d4720d1e1ffcefc43ae2af59c7487ab0bfab2ce (patch)
tree7cacea747b7ff3de52f69a8605ef486463201a9c /package/inc
parent57b992c0b57daba5f44b5c4cdb08e817f355ea01 (diff)
undo anything not wizard related in the previous merge-commit
Diffstat (limited to 'package/inc')
-rw-r--r--package/inc/EncryptedDataHeader.hxx32
-rw-r--r--package/inc/EncryptionData.hxx52
-rw-r--r--package/inc/PackageConstants.hxx36
-rw-r--r--package/inc/ZipFile.hxx52
-rw-r--r--package/inc/ZipOutputStream.hxx33
-rw-r--r--package/inc/ZipPackage.hxx42
-rw-r--r--package/inc/ZipPackageEntry.hxx106
-rw-r--r--package/inc/ZipPackageFolder.hxx4
-rw-r--r--package/inc/ZipPackageStream.hxx218
9 files changed, 502 insertions, 73 deletions
diff --git a/package/inc/EncryptedDataHeader.hxx b/package/inc/EncryptedDataHeader.hxx
index ed0ffe6628e3..43487ac88ea0 100644
--- a/package/inc/EncryptedDataHeader.hxx
+++ b/package/inc/EncryptedDataHeader.hxx
@@ -32,22 +32,26 @@
/* The structure of this header is as follows:
- Header signature 4 bytes
- Version number 2 bytes
- Iteraction count 4 bytes
- Size 4 bytes
- Salt length 2 bytes
- IV length 2 bytes
- Digest length 2 bytes
- MediaType length 2 bytes
- Salt content X bytes
- IV content X bytes
- digest content X bytes
- MediaType X bytes
+ Header signature 4 bytes
+ Version number 2 bytes
+ Iteraction count 4 bytes
+ Size 4 bytes
+ EncAlgorithm 4 bytes
+ DigestAlgorithm 4 bytes
+ DerivedKeySize 4 bytes
+ StartKeyAlgorithm 4 bytes
+ Salt length 2 bytes
+ IV length 2 bytes
+ Digest length 2 bytes
+ MediaType length 2 bytes
+ Salt content X bytes
+ IV content X bytes
+ digest content X bytes
+ 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 = 38; // + 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 ab2a658208c9..283b0b94caea 100644
--- a/package/inc/EncryptionData.hxx
+++ b/package/inc/EncryptionData.hxx
@@ -31,16 +31,54 @@
#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_Int8 > m_aSalt;
+ ::com::sun::star::uno::Sequence< sal_Int8 > m_aInitVector;
+ ::com::sun::star::uno::Sequence< sal_Int8 > m_aDigest;
+ sal_Int32 m_nIterationCount;
+
+ BaseEncryptionData()
+ : m_nIterationCount ( 0 ){}
+
+ BaseEncryptionData( const BaseEncryptionData& aData )
+ : cppu::OWeakObject()
+ , 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;
+ sal_Int32 m_nStartKeyGenID;
+
+ EncryptionData( const BaseEncryptionData& aData, const ::com::sun::star::uno::Sequence< sal_Int8 >& aKey, sal_Int32 nEncAlg, sal_Int32 nCheckAlg, sal_Int32 nDerivedKeySize, sal_Int32 nStartKeyGenID )
+ : BaseEncryptionData( aData )
+ , m_aKey( aKey )
+ , m_nEncAlg( nEncAlg )
+ , m_nCheckAlg( nCheckAlg )
+ , m_nDerivedKeySize( nDerivedKeySize )
+ , m_nStartKeyGenID( nStartKeyGenID )
+ {}
+
+ 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 )
+ , m_nStartKeyGenID( aData.m_nStartKeyGenID )
+ {}
+};
+
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/package/inc/PackageConstants.hxx b/package/inc/PackageConstants.hxx
index 7dd4d78a4e9b..be82010175fc 100644
--- a/package/inc/PackageConstants.hxx
+++ b/package/inc/PackageConstants.hxx
@@ -32,21 +32,39 @@
const sal_Int32 n_ConstBufferSize = 32768;
const sal_Int32 n_ConstMaxMemoryStreamSize = 20480;
+
+// by calculation of the digest we read 32 bytes more ( if available )
+// it allows to ignore the padding if the stream is longer than n_ConstDigestDecrypt since we read at least two blocks more;
+// if the stream is shorter or equal the padding will be done successfully
const sal_Int32 n_ConstDigestLength = 1024;
+const sal_Int32 n_ConstDigestDecrypt = 1056; // 1024 + 32
// the constants related to the manifest.xml entries
-#define PKG_MNFST_MEDIATYPE 0
-#define PKG_MNFST_VERSION 1
-#define PKG_MNFST_FULLPATH 2
+#define PKG_MNFST_MEDIATYPE 0
+#define PKG_MNFST_VERSION 1
+#define PKG_MNFST_FULLPATH 2
-#define PKG_MNFST_INIVECTOR 3
-#define PKG_MNFST_SALT 4
-#define PKG_MNFST_ITERATION 5
-#define PKG_MNFST_UCOMPSIZE 6
-#define PKG_MNFST_DIGEST 7
+#define PKG_MNFST_INIVECTOR 3
+#define PKG_MNFST_SALT 4
+#define PKG_MNFST_ITERATION 5
+#define PKG_MNFST_UCOMPSIZE 6
+#define PKG_MNFST_DIGEST 7
+#define PKG_MNFST_ENCALG 8
+#define PKG_MNFST_STARTALG 9
+#define PKG_MNFST_DIGESTALG 10
+#define PKG_MNFST_DERKEYSIZE 11
#define PKG_SIZE_NOENCR_MNFST 3
-#define PKG_SIZE_ENCR_MNFST 8
+#define PKG_SIZE_ENCR_MNFST 12
+
+// 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 8193eef68a5d..05186c0abccf 100644
--- a/package/inc/ZipFile.hxx
+++ b/package/inc/ZipFile.hxx
@@ -32,9 +32,13 @@
#include <com/sun/star/packages/zip/ZipIOException.hpp>
#include <com/sun/star/packages/NoEncryptionException.hpp>
#include <com/sun/star/packages/WrongPasswordException.hpp>
+#include <com/sun/star/xml/crypto/XCipherContext.hpp>
+#include <com/sun/star/xml/crypto/XDigestContext.hpp>
+
#include <ByteGrabber.hxx>
#include <HashMaps.hxx>
#include <Inflater.hxx>
+#include <EncryptionData.hxx>
#include <mutexholder.hxx>
@@ -46,6 +50,7 @@ namespace rtl
{
template < class T > class Reference;
}
+
/*
* We impose arbitrary but reasonable limit on ZIP files.
*/
@@ -54,9 +59,7 @@ namespace rtl
#define ZIP_MAXEXTRA 256
#define ZIP_MAXENTRIES (0x10000 - 2)
-typedef void* rtlCipher;
class ZipEnumeration;
-class EncryptionData;
class ZipFile
{
@@ -69,20 +72,20 @@ protected:
ZipUtils::Inflater aInflater;
com::sun::star::uno::Reference < com::sun::star::io::XInputStream > xStream;
com::sun::star::uno::Reference < com::sun::star::io::XSeekable > xSeek;
- const ::com::sun::star::uno::Reference < com::sun::star::lang::XMultiServiceFactory > xFactory;
+ const ::com::sun::star::uno::Reference < com::sun::star::lang::XMultiServiceFactory > m_xFactory;
::com::sun::star::uno::Reference < ::com::sun::star::ucb::XProgressHandler > xProgressHandler;
sal_Bool bRecoveryMode;
com::sun::star::uno::Reference < com::sun::star::io::XInputStream > createMemoryStream(
ZipEntry & rEntry,
- const rtl::Reference < 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 rtl::Reference < EncryptionData > &rData,
+ const ::rtl::Reference < EncryptionData > &rData,
sal_Bool bRawStream,
sal_Bool bDecrypt );
@@ -90,7 +93,7 @@ protected:
com::sun::star::uno::Reference < com::sun::star::io::XInputStream > createUnbufferedStream(
SotMutexHolderRef aMutexHolder,
ZipEntry & rEntry,
- const rtl::Reference < EncryptionData > &rData,
+ const ::rtl::Reference < EncryptionData > &rData,
sal_Int8 nStreamMode,
sal_Bool bDecrypt,
::rtl::OUString aMediaType = ::rtl::OUString() );
@@ -126,44 +129,59 @@ 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 rtl::Reference < 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 rtl::Reference < EncryptionData > & xEncryptionData, rtlCipher &rCipher, sal_Bool bDecode );
- static void StaticFillHeader ( const rtl::Reference < EncryptionData > & rData,
+ static ::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XDigestContext > StaticGetDigestContextForChecksum(
+ const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xArgFactory,
+ const ::rtl::Reference< EncryptionData >& xEncryptionData );
+
+ static ::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XCipherContext > StaticGetCipher(
+ const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xArgFactory,
+ const ::rtl::Reference< EncryptionData >& xEncryptionData,
+ bool bEncrypt );
+
+ static void StaticFillHeader ( const ::rtl::Reference < EncryptionData > & rData,
sal_Int32 nSize,
const ::rtl::OUString& aMediaType,
sal_Int8 * & pHeader );
- static sal_Bool StaticFillData ( rtl::Reference < EncryptionData > & rData,
+ static sal_Bool StaticFillData ( ::rtl::Reference < BaseEncryptionData > & rData,
+ sal_Int32 &rEncAlgorithm,
+ sal_Int32 &rChecksumAlgorithm,
+ sal_Int32 &rDerivedKeySize,
+ sal_Int32 &rStartKeyGenID,
sal_Int32 &rSize,
::rtl::OUString& aMediaType,
- ::com::sun::star::uno::Reference < com::sun::star::io::XInputStream > &rStream );
+ const ::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::lang::XMultiServiceFactory >& xFactory,
const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& xStream,
- const rtl::Reference < 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 rtl::Reference < EncryptionData > &rData );
+ static sal_Bool StaticHasValidPassword (
+ const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory,
+ const ::com::sun::star::uno::Sequence< sal_Int8 > &aReadBuffer,
+ const ::rtl::Reference < EncryptionData > &rData );
::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getInputStream(
ZipEntry& rEntry,
- const rtl::Reference < 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 rtl::Reference < EncryptionData > &rData,
+ const ::rtl::Reference < EncryptionData > &rData,
sal_Bool bDecrypt,
SotMutexHolderRef aMutexHolder )
throw ( ::com::sun::star::packages::WrongPasswordException,
@@ -173,7 +191,7 @@ public:
::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getWrappedRawStream(
ZipEntry& rEntry,
- const rtl::Reference < 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 9cd58d74e657..b5d6ee8b54f2 100644
--- a/package/inc/ZipOutputStream.hxx
+++ b/package/inc/ZipOutputStream.hxx
@@ -28,39 +28,52 @@
#ifndef _ZIP_OUTPUT_STREAM_HXX
#define _ZIP_OUTPUT_STREAM_HXX
+#include <com/sun/star/uno/Reference.hxx>
+#include <com/sun/star/lang/XMultiServiceFactory.hpp>
+#include <com/sun/star/io/XOutputStream.hpp>
+#include <com/sun/star/xml/crypto/XCipherContext.hpp>
+#include <com/sun/star/xml/crypto/XDigestContext.hpp>
+
#include <ByteChucker.hxx>
#include <Deflater.hxx>
#include <CRC32.hxx>
-#include <rtl/cipher.h>
-#include <rtl/digest.h>
#include <vector>
struct ZipEntry;
-class EncryptionData;
+class ZipPackageStream;
namespace rtl
{
template < class T > class Reference;
}
+
class ZipOutputStream
{
protected:
- com::sun::star::uno::Reference < com::sun::star::io::XOutputStream > xStream;
+ ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > m_xFactory;
+ ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream > xStream;
+
::std::vector < ZipEntry * > aZipList;
- com::sun::star::uno::Sequence < sal_Int8 > aBuffer, aEncryptionBuffer;
+
+ ::com::sun::star::uno::Sequence< sal_Int8 > m_aDeflateBuffer;
+
::rtl::OUString sComment;
ZipUtils::Deflater aDeflater;
- rtlCipher aCipher;
- rtlDigest aDigest;
+
+ ::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XCipherContext > m_xCipherContext;
+ ::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XDigestContext > m_xDigestContext;
+
CRC32 aCRC;
ByteChucker aChucker;
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 );
+ ZipOutputStream(
+ const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory,
+ const ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream > &xOStream );
~ZipOutputStream();
// rawWrite to support a direct write to the output stream
@@ -75,7 +88,7 @@ public:
void SAL_CALL setLevel( sal_Int32 nNewLevel )
throw(::com::sun::star::uno::RuntimeException);
void SAL_CALL putNextEntry( ZipEntry& rEntry,
- rtl::Reference < 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 226a19e529b5..ed7be23ea429 100644
--- a/package/inc/ZipPackage.hxx
+++ b/package/inc/ZipPackage.hxx
@@ -36,9 +36,12 @@
#include <com/sun/star/lang/XUnoTunnel.hpp>
#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/beans/PropertyValue.hpp>
+#include <com/sun/star/beans/NamedValue.hpp>
#include <com/sun/star/lang/XServiceInfo.hpp>
-#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>
#include <vector>
@@ -83,18 +86,24 @@ 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;
+
+ FolderHash m_aRecent;
+ ::rtl::OUString m_aURL;
- sal_Bool m_bMediaTypeFallbackUsed;
- sal_Int32 m_nFormat;
- sal_Bool m_bAllowRemoveOnInsert;
+ 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 +130,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 GetStartKeyGenID() 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_W3C_PADDING ? 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..6ae623a50664
--- /dev/null
+++ b/package/inc/ZipPackageEntry.hxx
@@ -0,0 +1,106 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * 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>
+#include <com/sun/star/lang/XServiceInfo.hpp>
+#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
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/package/inc/ZipPackageFolder.hxx b/package/inc/ZipPackageFolder.hxx
index c6ace8edf0c2..59be1b7b36ce 100644
--- a/package/inc/ZipPackageFolder.hxx
+++ b/package/inc/ZipPackageFolder.hxx
@@ -92,10 +92,10 @@ public:
void setPackageFormat_Impl( sal_Int32 nFormat ) { m_nFormat = nFormat; }
void setRemoveOnInsertMode_Impl( sal_Bool bRemove ) { this->mbAllowRemoveOnInsert = bRemove; }
- bool saveChild(const rtl::OUString &rShortName, const com::sun::star::packages::ContentInfo &rInfo, 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);
+ bool saveChild(const rtl::OUString &rShortName, const com::sun::star::packages::ContentInfo &rInfo, 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);
// 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..cb165af9ee97
--- /dev/null
+++ b/package/inc/ZipPackageStream.hxx
@@ -0,0 +1,218 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * 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 <ZipPackageEntry.hxx>
+#include <rtl/ref.hxx>
+#include <cppuhelper/implbase2.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_nImportedStartKeyAlgorithm;
+ 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 );
+
+ sal_Int32 GetStartKeyGenID();
+
+ const com::sun::star::uno::Sequence < sal_Int8 > getInitialisationVector () const
+ { return m_xBaseEncryptionData->m_aInitVector;}
+ const com::sun::star::uno::Sequence < sal_Int8 > getDigest () const
+ { return m_xBaseEncryptionData->m_aDigest;}
+ const com::sun::star::uno::Sequence < sal_Int8 > 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; }
+ sal_Int32 GetEncryptionAlgorithm() const;
+ sal_Int32 GetBlockSize() const;
+
+ void SetToBeCompressed (sal_Bool bNewValue) { bToBeCompressed = bNewValue;}
+ void SetIsEncrypted (sal_Bool bNewValue) { bIsEncrypted = bNewValue;}
+ void SetImportedStartKeyAlgorithm( sal_Int32 nAlgorithm ) { m_nImportedStartKeyAlgorithm = nAlgorithm; }
+ 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_Int8 >& rNewVector )
+ { m_xBaseEncryptionData->m_aInitVector = rNewVector;}
+ void setSalt (const com::sun::star::uno::Sequence < sal_Int8 >& rNewSalt )
+ { m_xBaseEncryptionData->m_aSalt = rNewSalt;}
+ void setDigest (const com::sun::star::uno::Sequence < sal_Int8 >& 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
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */