[Libreoffice-commits] .: Branch 'libreoffice-3-4' - package/inc package/qa package/source xmlsecurity/inc xmlsecurity/source xmlsecurity/util
Stephan Bergmann
sbergmann at kemper.freedesktop.org
Fri Nov 18 06:41:06 PST 2011
package/inc/EncryptedDataHeader.hxx | 8
package/inc/EncryptionData.hxx | 52
package/inc/PackageConstants.hxx | 20
package/inc/ZipFile.hxx | 35
package/inc/ZipOutputStream.hxx | 37
package/inc/ZipPackage.hxx | 15
package/inc/ZipPackageEntry.hxx | 106 ++
package/inc/ZipPackageFolder.hxx | 4
package/inc/ZipPackageStream.hxx | 216 ++++
package/qa/storages/TestHelper.java | 16
package/source/manifest/Base64Codec.cxx | 8
package/source/manifest/Base64Codec.hxx | 4
package/source/manifest/ManifestDefines.hxx | 20
package/source/manifest/ManifestExport.cxx | 2
package/source/manifest/ManifestImport.cxx | 134 ++
package/source/manifest/ManifestImport.hxx | 29
package/source/xstor/owriteablestream.cxx | 162 +--
package/source/xstor/xstorage.cxx | 139 ++
package/source/xstor/xstorage.hxx | 9
package/source/zipapi/EntryInputStream.cxx | 205 ---
package/source/zipapi/EntryInputStream.hxx | 85 -
package/source/zipapi/XFileStream.cxx | 230 ----
package/source/zipapi/XFileStream.hxx | 95 -
package/source/zipapi/XMemoryStream.cxx | 55 -
package/source/zipapi/XMemoryStream.hxx | 45
package/source/zipapi/XUnbufferedStream.cxx | 75 -
package/source/zipapi/XUnbufferedStream.hxx | 13
package/source/zipapi/ZipFile.cxx | 288 ++++-
package/source/zipapi/ZipOutputStream.cxx | 102 +
package/source/zipapi/blowfishcontext.cxx | 122 ++
package/source/zipapi/blowfishcontext.hxx | 58 +
package/source/zipapi/makefile.mk | 2
package/source/zipapi/sha1context.cxx | 97 +
package/source/zipapi/sha1context.hxx | 57 +
package/source/zippackage/ZipPackage.cxx | 252 +++-
package/source/zippackage/ZipPackageEntry.hxx | 106 --
package/source/zippackage/ZipPackageFolder.cxx | 54 -
package/source/zippackage/ZipPackageStream.cxx | 238 +++-
package/source/zippackage/ZipPackageStream.hxx | 196 ---
package/source/zippackage/zipfileaccess.cxx | 5
xmlsecurity/inc/xmlsecurity/digitalsignaturesdialog.hxx | 2
xmlsecurity/inc/xmlsecurity/xmlsignaturehelper.hxx | 5
xmlsecurity/source/component/documentdigitalsignatures.cxx | 8
xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx | 4
xmlsecurity/source/helper/xmlsignaturehelper.cxx | 6
xmlsecurity/source/xmlsec/makefile.mk | 6
xmlsecurity/source/xmlsec/nss/ciphercontext.cxx | 276 +++++
xmlsecurity/source/xmlsec/nss/ciphercontext.hxx | 89 +
xmlsecurity/source/xmlsec/nss/digestcontext.cxx | 101 +
xmlsecurity/source/xmlsec/nss/digestcontext.hxx | 68 +
xmlsecurity/source/xmlsec/nss/makefile.mk | 20
xmlsecurity/source/xmlsec/nss/nssinitializer.cxx | 521 ++++++++++
xmlsecurity/source/xmlsec/nss/nssinitializer.hxx | 90 +
xmlsecurity/source/xmlsec/nss/securityenvironment_nssimpl.cxx | 38
xmlsecurity/source/xmlsec/nss/seinitializer_nssimpl.cxx | 355 ------
xmlsecurity/source/xmlsec/nss/seinitializer_nssimpl.hxx | 34
xmlsecurity/source/xmlsec/nss/x509certificate_nssimpl.cxx | 28
xmlsecurity/source/xmlsec/nss/xsec_nss.cxx | 34
xmlsecurity/source/xmlsec/xsec_xmlsec.cxx | 4
xmlsecurity/util/makefile.mk | 10
xmlsecurity/util/xsec_xmlsec.component | 1
xmlsecurity/util/xsec_xmlsec.windows.component | 3
62 files changed, 3208 insertions(+), 1891 deletions(-)
New commits:
commit c726de0c282cab62b9f1a3b51249e37224325fe9
Author: Stephan Bergmann <sbergman at redhat.com>
Date: Wed Nov 9 08:54:35 2011 +0100
Backport reading AES-encrypted ODF 1.2 documents (as genereated by LibO 3.5).
This backports the reading half of CWS mav60 plus <http://cgit.freedesktop.org/
libreoffice/core/commit/?id=2d775f593abd9bc487ccc60f06aa5a3ca9632056> "Produce
correct sha256 uri, consume correct uri and original spec typo." It spans the
repos components, libs-core, libs-gui, and ure.
diff --git a/package/inc/EncryptedDataHeader.hxx b/package/inc/EncryptedDataHeader.hxx
index 88cdaa5..4e35664 100644
--- a/package/inc/EncryptedDataHeader.hxx
+++ b/package/inc/EncryptedDataHeader.hxx
@@ -36,6 +36,10 @@
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
@@ -46,8 +50,8 @@
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 4dba2e3..1662510 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 229f739..7507ada 100644
--- a/package/inc/PackageConstants.hxx
+++ b/package/inc/PackageConstants.hxx
@@ -32,7 +32,12 @@
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
@@ -44,9 +49,22 @@ const sal_Int32 n_ConstDigestLength = 1024;
#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 c64500c..bd108b3 100644
--- a/package/inc/ZipFile.hxx
+++ b/package/inc/ZipFile.hxx
@@ -32,9 +32,15 @@
#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 <rtl/ref.hxx>
+
#include <ByteGrabber.hxx>
#include <HashMaps.hxx>
#include <Inflater.hxx>
+#include <EncryptionData.hxx>
#include <mutexholder.hxx>
@@ -56,7 +62,6 @@ namespace rtl
typedef void* rtlCipher;
class ZipEnumeration;
-class EncryptionData;
class ZipFile
{
@@ -69,7 +74,7 @@ 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;
@@ -133,25 +138,41 @@ public:
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 )
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(
diff --git a/package/inc/ZipOutputStream.hxx b/package/inc/ZipOutputStream.hxx
index b36f4d2..506e913 100644
--- a/package/inc/ZipOutputStream.hxx
+++ b/package/inc/ZipOutputStream.hxx
@@ -28,39 +28,48 @@
#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;
-namespace rtl
-{
- template < class T > class Reference;
-}
+class ZipPackageStream;
+
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 +84,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 8ea3f60..a4aed11 100644
--- a/package/inc/ZipPackage.hxx
+++ b/package/inc/ZipPackage.hxx
@@ -36,7 +36,9 @@
#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 <com/sun/star/xml/crypto/CipherID.hpp>
#include <HashMaps.hxx>
#include <com/sun/star/lang/IllegalArgumentException.hpp>
#include <osl/file.h>
@@ -83,13 +85,17 @@ class ZipPackage : public cppu::WeakImplHelper7
protected:
SotMutexHolderRef m_aMutexHolder;
+ ::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_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_bUseManifest;
sal_Bool m_bForceRecovery;
sal_Bool m_bMediaTypeFallbackUsed;
@@ -124,12 +130,17 @@ public:
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 0000000..18adfdc
--- /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 c6ace8e..59be1b7 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 0000000..a3bbf73
--- /dev/null
+++ b/package/inc/ZipPackageStream.hxx
@@ -0,0 +1,216 @@
+/*************************************************************************
+ *
+ * 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_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
diff --git a/package/qa/storages/TestHelper.java b/package/qa/storages/TestHelper.java
index 0c1580f..b0b3434 100644
--- a/package/qa/storages/TestHelper.java
+++ b/package/qa/storages/TestHelper.java
@@ -1434,24 +1434,24 @@ public class TestHelper {
try
{
- byte pData[][] = new byte[1][22];
- if ( xHeadRawStream.readBytes( pData, 22 ) != 22 )
+ byte pData[][] = new byte[1][38];
+ if ( xHeadRawStream.readBytes( pData, 38 ) != 38 )
{
Error( "Can't read header of encrypted stream '" + sStreamName + "' raw representations!" );
return false;
}
- if ( pData[0][0] != 0x4d || pData[0][1] != 0x47 || pData[0][2] != 0x02 || pData[0][3] != 0x05 )
+ if ( pData[0][0] != 0x4d || pData[0][1] != 0x4d || pData[0][2] != 0x02 || pData[0][3] != 0x05 )
{
Error( "No signature in the header of encrypted stream '" + sStreamName + "' raw representations!" );
return false;
}
int nVariableHeaderLength =
- ( pData[0][14] + pData[0][15] * 0x100 ) // salt length
- + ( pData[0][16] + pData[0][17] * 0x100 ) // iv length
- + ( pData[0][18] + pData[0][19] * 0x100 ) // digest length
- + ( pData[0][20] + pData[0][21] * 0x100 ); // mediatype length
+ ( pData[0][30] + pData[0][31] * 0x100 ) // salt length
+ + ( pData[0][32] + pData[0][33] * 0x100 ) // iv length
+ + ( pData[0][34] + pData[0][35] * 0x100 ) // digest length
+ + ( pData[0][36] + pData[0][37] * 0x100 ); // mediatype length
xHeadRawStream.skipBytes( nVariableHeaderLength );
@@ -1467,7 +1467,7 @@ public class TestHelper {
if ( nRead1 != nRead2 )
{
- Error( "The encrypted stream '" + sStreamName + "' raw representations have different size!" );
+ Error( "The encrypted stream '" + sStreamName + "' raw representations have different size! nRead1 - nRead2 = " + ( new Integer( nRead1 - nRead2 ) ).toString() );
return false;
}
diff --git a/package/source/manifest/Base64Codec.cxx b/package/source/manifest/Base64Codec.cxx
index 1438d86..5dc4ebf 100644
--- a/package/source/manifest/Base64Codec.cxx
+++ b/package/source/manifest/Base64Codec.cxx
@@ -131,11 +131,11 @@ void ThreeByteToFourByte (const sal_uInt8* pBuffer, const sal_Int32 nStart, cons
sBuffer.setCharAt(3, aBase64EncodeTable [nIndex]);
}
-void Base64Codec::encodeBase64(rtl::OUStringBuffer& aStrBuffer, const uno::Sequence < sal_uInt8 >& aPass)
+void Base64Codec::encodeBase64(rtl::OUStringBuffer& aStrBuffer, const uno::Sequence < sal_Int8 >& aPass)
{
sal_Int32 i(0);
sal_Int32 nBufferLength(aPass.getLength());
- const sal_uInt8* pBuffer = aPass.getConstArray();
+ const sal_uInt8* pBuffer = reinterpret_cast< const sal_uInt8* >( aPass.getConstArray() );
while (i < nBufferLength)
{
rtl::OUStringBuffer sBuffer;
@@ -185,7 +185,7 @@ void FourByteToThreeByte (sal_uInt8* pBuffer, sal_Int32& nLength, const sal_Int3
pBuffer[nStart + 2] = OneByte;
}
-void Base64Codec::decodeBase64(uno::Sequence< sal_uInt8 >& aBuffer, const rtl::OUString& sBuffer)
+void Base64Codec::decodeBase64(uno::Sequence< sal_Int8 >& aBuffer, const rtl::OUString& sBuffer)
{
sal_Int32 nFirstLength((sBuffer.getLength() / 4) * 3);
sal_uInt8* pBuffer = new sal_uInt8[nFirstLength];
@@ -201,7 +201,7 @@ void Base64Codec::decodeBase64(uno::Sequence< sal_uInt8 >& aBuffer, const rtl::O
i += 4;
k += 3;
}
- aBuffer = uno::Sequence<sal_uInt8>(pBuffer, nSecondLength);
+ aBuffer = uno::Sequence<sal_Int8>( reinterpret_cast< sal_Int8* >( pBuffer ), nSecondLength );
delete[] pBuffer;
}
diff --git a/package/source/manifest/Base64Codec.hxx b/package/source/manifest/Base64Codec.hxx
index 941c115..60456ad 100644
--- a/package/source/manifest/Base64Codec.hxx
+++ b/package/source/manifest/Base64Codec.hxx
@@ -40,8 +40,8 @@ class OUStringBuffer;
class Base64Codec
{
public:
- static void encodeBase64(rtl::OUStringBuffer& aStrBuffer, const com::sun::star::uno::Sequence<sal_uInt8>& aPass);
- static void decodeBase64(com::sun::star::uno::Sequence<sal_uInt8>& aPass, const rtl::OUString& sBuffer);
+ static void encodeBase64(rtl::OUStringBuffer& aStrBuffer, const com::sun::star::uno::Sequence<sal_Int8>& aPass);
+ static void decodeBase64(com::sun::star::uno::Sequence<sal_Int8>& aPass, const rtl::OUString& sBuffer);
};
#endif
diff --git a/package/source/manifest/ManifestDefines.hxx b/package/source/manifest/ManifestDefines.hxx
index 67159ee..dc9c47e 100644
--- a/package/source/manifest/ManifestDefines.hxx
+++ b/package/source/manifest/ManifestDefines.hxx
@@ -65,6 +65,26 @@
#define CHECKSUM_TYPE "SHA1/1K"
#define DERIVED_KEY_SIZE "16"
+#define SHA256_URL "http://www.w3.org/2001/04/xmlenc#sha256"
+//http://tools.oasis-open.org/issues/browse/OFFICE-3702
+//http://tools.oasis-open.org/issues/browse/OFFICE-3708
+#define SHA256_URL_TYPO "http://www.w3.org/2000/09/xmldsig#sha256"
+#define SHA1_NAME "SHA1"
+#define SHA1_URL "http://www.w3.org/2000/09/xmldsig#sha1"
+
+#define SHA1_1K_NAME "SHA1/1K"
+#define SHA1_1K_URL "urn:oasis:names:tc:opendocument:xmlns:manifest:1.0#sha1-1k"
+#define SHA256_1K_URL "urn:oasis:names:tc:opendocument:xmlns:manifest:1.0#sha256-1k"
+
+#define BLOWFISH_NAME "Blowfish CFB"
+#define BLOWFISH_URL "urn:oasis:names:tc:opendocument:xmlns:manifest:1.0#blowfish"
+#define AES128_URL "http://www.w3.org/2001/04/xmlenc#aes128-cbc"
+#define AES192_URL "http://www.w3.org/2001/04/xmlenc#aes192-cbc"
+#define AES256_URL "http://www.w3.org/2001/04/xmlenc#aes256-cbc"
+
+#define PBKDF2_NAME "PBKDF2"
+#define PBKDF2_URL "urn:oasis:names:tc:opendocument:xmlns:manifest:1.0#pbkdf2"
+
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/package/source/manifest/ManifestExport.cxx b/package/source/manifest/ManifestExport.cxx
index dfdcf2f..bb53541 100644
--- a/package/source/manifest/ManifestExport.cxx
+++ b/package/source/manifest/ManifestExport.cxx
@@ -239,7 +239,7 @@ ManifestExport::ManifestExport(Reference < XDocumentHandler > xHandler, const S
::comphelper::AttributeList * pNewAttrList = new ::comphelper::AttributeList;
Reference < XAttributeList > xNewAttrList (pNewAttrList);
OUStringBuffer aBuffer;
- Sequence < sal_uInt8 > aSequence;
+ Sequence < sal_Int8 > aSequence;
xHandler->ignorableWhitespace ( sWhiteSpace );
if ( pDigest )
diff --git a/package/source/manifest/ManifestImport.cxx b/package/source/manifest/ManifestImport.cxx
index 2f99d66..abd67d5 100644
--- a/package/source/manifest/ManifestImport.cxx
+++ b/package/source/manifest/ManifestImport.cxx
@@ -32,6 +32,8 @@
#include <ManifestDefines.hxx>
#include <Base64Codec.hxx>
#include <com/sun/star/xml/sax/XAttributeList.hpp>
+#include <com/sun/star/xml/crypto/DigestID.hpp>
+#include <com/sun/star/xml/crypto/CipherID.hpp>
#include <com/sun/star/beans/PropertyValue.hpp>
using namespace com::sun::star::uno;
@@ -45,12 +47,14 @@ using ::rtl::OUString;
ManifestImport::ManifestImport( vector < Sequence < PropertyValue > > & rNewManVector )
: nNumProperty ( 0 )
, bIgnoreEncryptData ( sal_False )
+, nDerivedKeySize( 0 )
, rManVector ( rNewManVector )
, sFileEntryElement ( RTL_CONSTASCII_USTRINGPARAM ( ELEMENT_FILE_ENTRY ) )
, sManifestElement ( RTL_CONSTASCII_USTRINGPARAM ( ELEMENT_MANIFEST ) )
, sEncryptionDataElement( RTL_CONSTASCII_USTRINGPARAM ( ELEMENT_ENCRYPTION_DATA ) )
, sAlgorithmElement ( RTL_CONSTASCII_USTRINGPARAM ( ELEMENT_ALGORITHM ) )
+, sStartKeyAlgElement ( RTL_CONSTASCII_USTRINGPARAM ( ELEMENT_START_KEY_GENERATION ) )
, sKeyDerivationElement( RTL_CONSTASCII_USTRINGPARAM ( ELEMENT_KEY_DERIVATION ) )
, sCdataAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_CDATA ) )
@@ -61,7 +65,9 @@ ManifestImport::ManifestImport( vector < Sequence < PropertyValue > > & rNewManV
, sSaltAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_SALT ) )
, sInitialisationVectorAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_INITIALISATION_VECTOR ) )
, sIterationCountAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_ITERATION_COUNT ) )
+, sKeySizeAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_KEY_SIZE ) )
, sAlgorithmNameAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_ALGORITHM_NAME ) )
+, sStartKeyAlgNameAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_START_KEY_GENERATION_NAME ) )
, sKeyDerivationNameAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_KEY_DERIVATION_NAME ) )
, sChecksumAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_CHECKSUM ) )
, sChecksumTypeAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_CHECKSUM_TYPE ) )
@@ -70,15 +76,34 @@ ManifestImport::ManifestImport( vector < Sequence < PropertyValue > > & rNewManV
, sMediaTypeProperty ( RTL_CONSTASCII_USTRINGPARAM ( "MediaType" ) )
, sVersionProperty ( RTL_CONSTASCII_USTRINGPARAM ( "Version" ) )
, sIterationCountProperty ( RTL_CONSTASCII_USTRINGPARAM ( "IterationCount" ) )
+, sDerivedKeySizeProperty ( RTL_CONSTASCII_USTRINGPARAM ( "DerivedKeySize" ) )
, sSaltProperty ( RTL_CONSTASCII_USTRINGPARAM ( "Salt" ) )
, sInitialisationVectorProperty ( RTL_CONSTASCII_USTRINGPARAM ( "InitialisationVector" ) )
, sSizeProperty ( RTL_CONSTASCII_USTRINGPARAM ( "Size" ) )
, sDigestProperty ( RTL_CONSTASCII_USTRINGPARAM ( "Digest" ) )
+, sEncryptionAlgProperty ( RTL_CONSTASCII_USTRINGPARAM ( "EncryptionAlgorithm" ) )
+, sStartKeyAlgProperty ( RTL_CONSTASCII_USTRINGPARAM ( "StartKeyAlgorithm" ) )
+, sDigestAlgProperty ( RTL_CONSTASCII_USTRINGPARAM ( "DigestAlgorithm" ) )
, sWhiteSpace ( RTL_CONSTASCII_USTRINGPARAM ( " " ) )
-, sBlowfish ( RTL_CONSTASCII_USTRINGPARAM ( "Blowfish CFB" ) )
-, sPBKDF2 ( RTL_CONSTASCII_USTRINGPARAM ( "PBKDF2" ) )
-, sChecksumType ( RTL_CONSTASCII_USTRINGPARAM ( CHECKSUM_TYPE ) )
+
+, sSHA256_URL ( RTL_CONSTASCII_USTRINGPARAM ( SHA256_URL ) )
+, sSHA256_URL_TYPO ( RTL_CONSTASCII_USTRINGPARAM ( SHA256_URL_TYPO ) )
+, sSHA1_Name ( RTL_CONSTASCII_USTRINGPARAM ( SHA1_NAME ) )
+, sSHA1_URL ( RTL_CONSTASCII_USTRINGPARAM ( SHA1_URL ) )
+
+, sSHA256_1k_URL ( RTL_CONSTASCII_USTRINGPARAM ( SHA256_1K_URL ) )
+, sSHA1_1k_Name ( RTL_CONSTASCII_USTRINGPARAM ( SHA1_1K_NAME ) )
+, sSHA1_1k_URL ( RTL_CONSTASCII_USTRINGPARAM ( SHA1_1K_URL ) )
+
+, sBlowfish_Name ( RTL_CONSTASCII_USTRINGPARAM ( BLOWFISH_NAME ) )
+, sBlowfish_URL ( RTL_CONSTASCII_USTRINGPARAM ( BLOWFISH_URL ) )
+, sAES128_URL ( RTL_CONSTASCII_USTRINGPARAM ( AES128_URL ) )
+, sAES192_URL ( RTL_CONSTASCII_USTRINGPARAM ( AES192_URL ) )
+, sAES256_URL ( RTL_CONSTASCII_USTRINGPARAM ( AES256_URL ) )
+
+, sPBKDF2_Name ( RTL_CONSTASCII_USTRINGPARAM ( PBKDF2_NAME ) )
+, sPBKDF2_URL ( RTL_CONSTASCII_USTRINGPARAM ( PBKDF2_URL ) )
{
aStack.reserve( 10 );
}
@@ -143,43 +168,90 @@ void SAL_CALL ManifestImport::startElement( const OUString& aName, const uno::Re
if ( aConvertedName.equals( sEncryptionDataElement ) )
{
// If this element exists, then this stream is encrypted and we need
- // to store the initialisation vector, salt and iteration count used
+ // to import the initialisation vector, salt and iteration count used
+ nDerivedKeySize = 0;
OUString aString = aConvertedAttribs[sChecksumTypeAttribute];
- if ( aString == sChecksumType && !bIgnoreEncryptData )
+ if ( !bIgnoreEncryptData )
+ {
+ if ( aString.equals( sSHA1_1k_Name ) || aString.equals( sSHA1_1k_URL ) )
+ {
+ aSequence[nNumProperty].Name = sDigestAlgProperty;
+ aSequence[nNumProperty++].Value <<= xml::crypto::DigestID::SHA1_1K;
+ }
+ else if ( aString.equals( sSHA256_1k_URL ) )
+ {
+ aSequence[nNumProperty].Name = sDigestAlgProperty;
+ aSequence[nNumProperty++].Value <<= xml::crypto::DigestID::SHA256_1K;
+ }
+ else
+ bIgnoreEncryptData = sal_True;
+
+ if ( !bIgnoreEncryptData )
{
aString = aConvertedAttribs[sChecksumAttribute];
- Sequence < sal_uInt8 > aDecodeBuffer;
+ Sequence < sal_Int8 > aDecodeBuffer;
Base64Codec::decodeBase64 ( aDecodeBuffer, aString );
aSequence[nNumProperty].Name = sDigestProperty;
aSequence[nNumProperty++].Value <<= aDecodeBuffer;
}
}
}
+ }
else if ( aIter->m_aConvertedName.equals( sEncryptionDataElement ) )
{
if ( aConvertedName == sAlgorithmElement )
{
+ if ( !bIgnoreEncryptData )
+ {
OUString aString = aConvertedAttribs[sAlgorithmNameAttribute];
- if ( aString == sBlowfish && !bIgnoreEncryptData )
+ if ( aString.equals( sBlowfish_Name ) || aString.equals( sBlowfish_URL ) )
+ {
+ aSequence[nNumProperty].Name = sEncryptionAlgProperty;
+ aSequence[nNumProperty++].Value <<= xml::crypto::CipherID::BLOWFISH_CFB_8;
+ }
+ else if ( aString.equals( sAES256_URL ) )
+ {
+ aSequence[nNumProperty].Name = sEncryptionAlgProperty;
+ aSequence[nNumProperty++].Value <<= xml::crypto::CipherID::AES_CBC_W3C_PADDING;
+ OSL_ENSURE( !nDerivedKeySize || nDerivedKeySize == 32, "Unexpected derived key length!" );
+ nDerivedKeySize = 32;
+ }
+ else if ( aString.equals( sAES192_URL ) )
+ {
+ aSequence[nNumProperty].Name = sEncryptionAlgProperty;
+ aSequence[nNumProperty++].Value <<= xml::crypto::CipherID::AES_CBC_W3C_PADDING;
+ OSL_ENSURE( !nDerivedKeySize || nDerivedKeySize == 24, "Unexpected derived key length!" );
+ nDerivedKeySize = 24;
+ }
+ else if ( aString.equals( sAES128_URL ) )
+ {
+ aSequence[nNumProperty].Name = sEncryptionAlgProperty;
+ aSequence[nNumProperty++].Value <<= xml::crypto::CipherID::AES_CBC_W3C_PADDING;
+ OSL_ENSURE( !nDerivedKeySize || nDerivedKeySize == 16, "Unexpected derived key length!" );
+ nDerivedKeySize = 16;
+ }
+ else
+ bIgnoreEncryptData = sal_True;
+
+ if ( !bIgnoreEncryptData )
{
aString = aConvertedAttribs[sInitialisationVectorAttribute];
- Sequence < sal_uInt8 > aDecodeBuffer;
+ Sequence < sal_Int8 > aDecodeBuffer;
Base64Codec::decodeBase64 ( aDecodeBuffer, aString );
aSequence[nNumProperty].Name = sInitialisationVectorProperty;
aSequence[nNumProperty++].Value <<= aDecodeBuffer;
}
- else
- // If we don't recognise the algorithm, then the key derivation info
- // is useless to us
- bIgnoreEncryptData = sal_True;
+ }
}
else if ( aConvertedName == sKeyDerivationElement )
{
+ if ( !bIgnoreEncryptData )
+ {
OUString aString = aConvertedAttribs[sKeyDerivationNameAttribute];
- if ( aString == sPBKDF2 && !bIgnoreEncryptData )
+ if ( aString.equals( sPBKDF2_Name ) || aString.equals( sPBKDF2_URL ) )
{
aString = aConvertedAttribs[sSaltAttribute];
- Sequence < sal_uInt8 > aDecodeBuffer;
+ Sequence < sal_Int8 > aDecodeBuffer;
Base64Codec::decodeBase64 ( aDecodeBuffer, aString );
aSequence[nNumProperty].Name = sSaltProperty;
aSequence[nNumProperty++].Value <<= aDecodeBuffer;
@@ -187,10 +259,40 @@ void SAL_CALL ManifestImport::startElement( const OUString& aName, const uno::Re
aString = aConvertedAttribs[sIterationCountAttribute];
aSequence[nNumProperty].Name = sIterationCountProperty;
aSequence[nNumProperty++].Value <<= aString.toInt32();
+
+ aString = aConvertedAttribs[sKeySizeAttribute];
+ if ( aString.getLength() )
+ {
+ sal_Int32 nKey = aString.toInt32();
+ OSL_ENSURE( !nDerivedKeySize || nKey == nDerivedKeySize , "Provided derived key length differs from the expected one!" );
+ nDerivedKeySize = nKey;
+ }
+ else if ( !nDerivedKeySize )
+ nDerivedKeySize = 16;
+ else if ( nDerivedKeySize != 16 )
+ OSL_ENSURE( sal_False, "Default derived key length differs from the expected one!" );
+
+ aSequence[nNumProperty].Name = sDerivedKeySizeProperty;
+ aSequence[nNumProperty++].Value <<= nDerivedKeySize;
+ }
+ else
+ bIgnoreEncryptData = sal_True;
+ }
+ }
+ else if ( aConvertedName == sStartKeyAlgElement )
+ {
+ OUString aString = aConvertedAttribs[sStartKeyAlgNameAttribute];
+ if (aString.equals(sSHA256_URL) || aString.equals(sSHA256_URL_TYPO))
+ {
+ aSequence[nNumProperty].Name = sStartKeyAlgProperty;
+ aSequence[nNumProperty++].Value <<= xml::crypto::DigestID::SHA256;
+ }
+ else if ( aString.equals( sSHA1_Name ) || aString.equals( sSHA1_URL ) )
+ {
+ aSequence[nNumProperty].Name = sStartKeyAlgProperty;
+ aSequence[nNumProperty++].Value <<= xml::crypto::DigestID::SHA1;
}
else
- // If we don't recognise the key derivation technique, then the
- // algorithm info is useless to us
bIgnoreEncryptData = sal_True;
}
}
diff --git a/package/source/manifest/ManifestImport.hxx b/package/source/manifest/ManifestImport.hxx
index 9655e71..4b92797 100644
--- a/package/source/manifest/ManifestImport.hxx
+++ b/package/source/manifest/ManifestImport.hxx
@@ -65,12 +65,14 @@ protected:
sal_Int16 nNumProperty;
ManifestStack aStack;
sal_Bool bIgnoreEncryptData;
+ sal_Int32 nDerivedKeySize;
::std::vector < ::com::sun::star::uno::Sequence < ::com::sun::star::beans::PropertyValue > > & rManVector;
const ::rtl::OUString sFileEntryElement;
const ::rtl::OUString sManifestElement;
const ::rtl::OUString sEncryptionDataElement;
const ::rtl::OUString sAlgorithmElement;
+ const ::rtl::OUString sStartKeyAlgElement;
const ::rtl::OUString sKeyDerivationElement;
const ::rtl::OUString sCdataAttribute;
@@ -81,7 +83,9 @@ protected:
const ::rtl::OUString sSaltAttribute;
const ::rtl::OUString sInitialisationVectorAttribute;
const ::rtl::OUString sIterationCountAttribute;
+ const ::rtl::OUString sKeySizeAttribute;
const ::rtl::OUString sAlgorithmNameAttribute;
+ const ::rtl::OUString sStartKeyAlgNameAttribute;
const ::rtl::OUString sKeyDerivationNameAttribute;
const ::rtl::OUString sChecksumAttribute;
const ::rtl::OUString sChecksumTypeAttribute;
@@ -90,15 +94,34 @@ protected:
const ::rtl::OUString sMediaTypeProperty;
const ::rtl::OUString sVersionProperty;
const ::rtl::OUString sIterationCountProperty;
+ const ::rtl::OUString sDerivedKeySizeProperty;
const ::rtl::OUString sSaltProperty;
const ::rtl::OUString sInitialisationVectorProperty;
const ::rtl::OUString sSizeProperty;
const ::rtl::OUString sDigestProperty;
+ const ::rtl::OUString sEncryptionAlgProperty;
+ const ::rtl::OUString sStartKeyAlgProperty;
+ const ::rtl::OUString sDigestAlgProperty;
const ::rtl::OUString sWhiteSpace;
- const ::rtl::OUString sBlowfish;
- const ::rtl::OUString sPBKDF2;
- const ::rtl::OUString sChecksumType;
+
+ const ::rtl::OUString sSHA256_URL;
+ const ::rtl::OUString sSHA256_URL_TYPO;
+ const ::rtl::OUString sSHA1_Name;
+ const ::rtl::OUString sSHA1_URL;
+
+ const ::rtl::OUString sSHA256_1k_URL;
+ const ::rtl::OUString sSHA1_1k_Name;
+ const ::rtl::OUString sSHA1_1k_URL;
+
+ const ::rtl::OUString sBlowfish_Name;
+ const ::rtl::OUString sBlowfish_URL;
+ const ::rtl::OUString sAES128_URL;
+ const ::rtl::OUString sAES192_URL;
+ const ::rtl::OUString sAES256_URL;
+
+ const ::rtl::OUString sPBKDF2_Name;
+ const ::rtl::OUString sPBKDF2_URL;
::rtl::OUString PushNameAndNamespaces( const ::rtl::OUString& aName,
diff --git a/package/source/xstor/owriteablestream.cxx b/package/source/xstor/owriteablestream.cxx
index c1c5e8f..03e1776 100644
--- a/package/source/xstor/owriteablestream.cxx
+++ b/package/source/xstor/owriteablestream.cxx
@@ -47,6 +47,8 @@
#include <comphelper/storagehelper.hxx>
#include <comphelper/ofopxmlhelper.hxx>
+#include <PackageConstants.hxx>
+
#include "selfterminatefilestream.hxx"
#include "owriteablestream.hxx"
#include "oseekinstream.hxx"
@@ -111,15 +113,14 @@ namespace
{
//-----------------------------------------------
void SetEncryptionKeyProperty_Impl( const uno::Reference< beans::XPropertySet >& xPropertySet,
- const uno::Sequence< sal_Int8 >& aKey )
+ const uno::Sequence< beans::NamedValue >& aKey )
{
OSL_ENSURE( xPropertySet.is(), "No property set is provided!\n" );
if ( !xPropertySet.is() )
throw uno::RuntimeException();
- ::rtl::OUString aString_EncryptionKey (RTL_CONSTASCII_USTRINGPARAM("EncryptionKey") );
try {
- xPropertySet->setPropertyValue( aString_EncryptionKey, uno::makeAny( aKey ) );
+ xPropertySet->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( STORAGE_ENCRYPTION_KEYS_PROPERTY ) ), uno::makeAny( aKey ) );
}
catch ( uno::Exception& aException )
{
@@ -137,9 +138,8 @@ uno::Any GetEncryptionKeyProperty_Impl( const uno::Reference< beans::XPropertySe
if ( !xPropertySet.is() )
throw uno::RuntimeException();
- ::rtl::OUString aString_EncryptionKey (RTL_CONSTASCII_USTRINGPARAM("EncryptionKey") );
try {
- return xPropertySet->getPropertyValue( aString_EncryptionKey );
+ return xPropertySet->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( STORAGE_ENCRYPTION_KEYS_PROPERTY ) ) );
}
catch ( uno::Exception& aException )
{
@@ -152,16 +152,65 @@ uno::Any GetEncryptionKeyProperty_Impl( const uno::Reference< beans::XPropertySe
}
//-----------------------------------------------
-sal_Bool SequencesEqual( uno::Sequence< sal_Int8 > aSequence1, uno::Sequence< sal_Int8 > aSequence2 )
+bool SequencesEqual( const uno::Sequence< sal_Int8 >& aSequence1, const uno::Sequence< sal_Int8 >& aSequence2 )
{
if ( aSequence1.getLength() != aSequence2.getLength() )
- return sal_False;
+ return false;
for ( sal_Int32 nInd = 0; nInd < aSequence1.getLength(); nInd++ )
if ( aSequence1[nInd] != aSequence2[nInd] )
- return sal_False;
+ return false;
+
+ return true;
+}
+
+//-----------------------------------------------
+bool SequencesEqual( const uno::Sequence< beans::NamedValue >& aSequence1, const uno::Sequence< beans::NamedValue >& aSequence2 )
+{
+ if ( aSequence1.getLength() != aSequence2.getLength() )
+ return false;
+
+ for ( sal_Int32 nInd = 0; nInd < aSequence1.getLength(); nInd++ )
+ {
+ bool bHasMember = false;
+ uno::Sequence< sal_Int8 > aMember1;
+ sal_Int32 nMember1 = 0;
+ if ( ( aSequence1[nInd].Value >>= aMember1 ) )
+ {
+ for ( sal_Int32 nInd2 = 0; nInd2 < aSequence2.getLength(); nInd2++ )
+ {
+ if ( aSequence1[nInd].Name.equals( aSequence2[nInd2].Name ) )
+ {
+ bHasMember = true;
+
+ uno::Sequence< sal_Int8 > aMember2;
+ if ( !( aSequence2[nInd2].Value >>= aMember2 ) || !SequencesEqual( aMember1, aMember2 ) )
+ return false;
+ }
+ }
+ }
+ else if ( ( aSequence1[nInd].Value >>= nMember1 ) )
+ {
+ for ( sal_Int32 nInd2 = 0; nInd2 < aSequence2.getLength(); nInd2++ )
+ {
+ if ( aSequence1[nInd].Name.equals( aSequence2[nInd2].Name ) )
+ {
+ bHasMember = true;
- return sal_True;
+ sal_Int32 nMember2 = 0;
+ if ( !( aSequence2[nInd2].Value >>= nMember2 ) || nMember1 != nMember2 )
+ return false;
+ }
+ }
+ }
+ else
+ return false;
+
+ if ( !bHasMember )
+ return false;
+ }
+
+ return true;
}
//-----------------------------------------------
@@ -395,7 +444,7 @@ sal_Bool OWriteStream_Impl::IsEncrypted()
// since a new key set to the package stream it should not be removed except the case when
// the stream becomes nonencrypted
- uno::Sequence< sal_Int8 > aKey;
+ uno::Sequence< beans::NamedValue > aKey;
if ( bToBeEncr )
GetEncryptionKeyProperty_Impl( xPropSet ) >>= aKey;
@@ -822,8 +871,8 @@ void OWriteStream_Impl::InsertStreamDirectly( const uno::Reference< io::XInputSt
throw uno::RuntimeException();
// set to be encrypted but do not use encryption key
- xPropertySet->setPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("EncryptionKey") ),
- uno::makeAny( uno::Sequence< sal_Int8 >() ) );
+ xPropertySet->setPropertyValue( ::rtl::OUString::createFromAscii( STORAGE_ENCRYPTION_KEYS_PROPERTY ),
+ uno::makeAny( uno::Sequence< beans::NamedValue >() ) );
xPropertySet->setPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Encrypted") ),
uno::makeAny( sal_True ) );
}
@@ -921,8 +970,8 @@ void OWriteStream_Impl::Commit()
throw uno::RuntimeException();
// set to be encrypted but do not use encryption key
- xPropertySet->setPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("EncryptionKey") ),
- uno::makeAny( uno::Sequence< sal_Int8 >() ) );
+ xPropertySet->setPropertyValue( ::rtl::OUString::createFromAscii( STORAGE_ENCRYPTION_KEYS_PROPERTY ),
+ uno::makeAny( uno::Sequence< beans::NamedValue >() ) );
xPropertySet->setPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Encrypted") ),
uno::makeAny( sal_True ) );
}
@@ -931,8 +980,8 @@ void OWriteStream_Impl::Commit()
if ( m_nStorageType != embed::StorageFormats::PACKAGE )
throw uno::RuntimeException();
- xPropertySet->setPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("EncryptionKey") ),
- uno::makeAny( m_aEncryptionData.getUnpackedValueOrDefault( PACKAGE_ENCRYPTIONDATA_SHA1UTF8, uno::Sequence< sal_Int8 >() ) ) );
+ xPropertySet->setPropertyValue( ::rtl::OUString::createFromAscii( STORAGE_ENCRYPTION_KEYS_PROPERTY ),
+ uno::makeAny( m_aEncryptionData.getAsConstNamedValueList() ) );
}
// the stream should be free soon, after package is stored
@@ -1265,7 +1314,7 @@ uno::Reference< io::XStream > OWriteStream_Impl::GetStream( sal_Int32 nStreamMod
}
else
{
- SetEncryptionKeyProperty_Impl( xPropertySet, aEncryptionData.getUnpackedValueOrDefault( PACKAGE_ENCRYPTIONDATA_SHA1UTF8, uno::Sequence< sal_Int8 >() ) );
+ SetEncryptionKeyProperty_Impl( xPropertySet, aEncryptionData.getAsConstNamedValueList() );
try {
xResultStream = GetStream_Impl( nStreamMode, bHierarchyAccess );
@@ -1274,32 +1323,9 @@ uno::Reference< io::XStream > OWriteStream_Impl::GetStream( sal_Int32 nStreamMod
m_bHasCachedEncryptionData = sal_True;
m_aEncryptionData = aEncryptionData;
}
- catch( packages::WrongPasswordException& )
- {
- // retry with different encoding
- SetEncryptionKeyProperty_Impl( xPropertySet, aEncryptionData.getUnpackedValueOrDefault( PACKAGE_ENCRYPTIONDATA_SHA1MS1252, uno::Sequence< sal_Int8 >() ) );
- try {
- // the stream must be cashed to be resaved
- xResultStream = GetStream_Impl( nStreamMode | embed::ElementModes::SEEKABLE, bHierarchyAccess );
-
- m_bUseCommonEncryption = sal_False; // very important to set it to false
- m_bHasCachedEncryptionData = sal_True;
- m_aEncryptionData = aEncryptionData;
-
- // the stream must be resaved with new password encryption
- if ( nStreamMode & embed::ElementModes::WRITE )
- {
- FillTempGetFileName();
- m_bHasDataToFlush = sal_True;
-
- // TODO/LATER: should the notification be done?
- if ( m_pParent )
- m_pParent->m_bIsModified = sal_True;
- }
- }
catch( packages::WrongPasswordException& aWrongPasswordException )
{
- SetEncryptionKeyProperty_Impl( xPropertySet, uno::Sequence< sal_Int8 >() );
+ SetEncryptionKeyProperty_Impl( xPropertySet, uno::Sequence< beans::NamedValue >() );
AddLog( aWrongPasswordException.Message );
AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
throw;
@@ -1310,20 +1336,10 @@ uno::Reference< io::XStream > OWriteStream_Impl::GetStream( sal_Int32 nStreamMod
AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Quiet exception" ) ) );
OSL_FAIL( "Can't write encryption related properties!\n" );
- SetEncryptionKeyProperty_Impl( xPropertySet, uno::Sequence< sal_Int8 >() );
+ SetEncryptionKeyProperty_Impl( xPropertySet, uno::Sequence< beans::NamedValue >() );
throw io::IOException(); // TODO:
}
}
- catch( uno::Exception& aException )
- {
- SetEncryptionKeyProperty_Impl( xPropertySet, uno::Sequence< sal_Int8 >() );
-
- AddLog( aException.Message );
- AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
- throw;
- }
-
- }
OSL_ENSURE( xResultStream.is(), "In case stream can not be retrieved an exception must be thrown!\n" );
@@ -1625,8 +1641,7 @@ void OWriteStream_Impl::GetCopyOfLastCommit( uno::Reference< io::XStream >& xTar
{
// TODO: introduce last commited cashed password information and use it here
// that means "use common pass" also should be remembered on flash
- uno::Sequence< sal_Int8 > aNewKey = aEncryptionData.getUnpackedValueOrDefault( PACKAGE_ENCRYPTIONDATA_SHA1UTF8, uno::Sequence< sal_Int8 >() );
- uno::Sequence< sal_Int8 > aOldKey = aEncryptionData.getUnpackedValueOrDefault( PACKAGE_ENCRYPTIONDATA_SHA1MS1252, uno::Sequence< sal_Int8 >() );
+ uno::Sequence< beans::NamedValue > aKey = aEncryptionData.getAsConstNamedValueList();
uno::Reference< beans::XPropertySet > xProps( m_xPackageStream, uno::UNO_QUERY );
if ( !xProps.is() )
@@ -1637,9 +1652,9 @@ void OWriteStream_Impl::GetCopyOfLastCommit( uno::Reference< io::XStream >& xTar
if ( !bEncr )
throw packages::NoEncryptionException();
- uno::Sequence< sal_Int8 > aEncrKey;
- xProps->getPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("EncryptionKey") ) ) >>= aEncrKey;
- if ( !SequencesEqual( aNewKey, aEncrKey ) && !SequencesEqual( aOldKey, aEncrKey ) )
+ uno::Sequence< beans::NamedValue > aPackKey;
+ xProps->getPropertyValue( ::rtl::OUString::createFromAscii( STORAGE_ENCRYPTION_KEYS_PROPERTY ) ) >>= aPackKey;
+ if ( !SequencesEqual( aKey, aPackKey ) )
throw packages::WrongPasswordException();
// the correct key must be set already
@@ -1648,7 +1663,7 @@ void OWriteStream_Impl::GetCopyOfLastCommit( uno::Reference< io::XStream >& xTar
else
{
uno::Reference< beans::XPropertySet > xPropertySet( m_xPackageStream, uno::UNO_QUERY );
- SetEncryptionKeyProperty_Impl( xPropertySet, aEncryptionData.getUnpackedValueOrDefault( PACKAGE_ENCRYPTIONDATA_SHA1UTF8, uno::Sequence< sal_Int8 >() ) );
+ SetEncryptionKeyProperty_Impl( xPropertySet, aEncryptionData.getAsConstNamedValueList() );
try {
xDataToCopy = m_xPackageStream->getDataStream();
@@ -1656,42 +1671,19 @@ void OWriteStream_Impl::GetCopyOfLastCommit( uno::Reference< io::XStream >& xTar
if ( !xDataToCopy.is() )
{
OSL_FAIL( "Encrypted ZipStream must already have input stream inside!\n" );
- SetEncryptionKeyProperty_Impl( xPropertySet, uno::Sequence< sal_Int8 >() );
- }
- }
- catch( packages::WrongPasswordException& aWrongPasswordException )
- {
- SetEncryptionKeyProperty_Impl( xPropertySet, aEncryptionData.getUnpackedValueOrDefault( PACKAGE_ENCRYPTIONDATA_SHA1MS1252, uno::Sequence< sal_Int8 >() ) );
- try {
- xDataToCopy = m_xPackageStream->getDataStream();
-
- if ( !xDataToCopy.is() )
- {
- OSL_FAIL( "Encrypted ZipStream must already have input stream inside!\n" );
- SetEncryptionKeyProperty_Impl( xPropertySet, uno::Sequence< sal_Int8 >() );
- AddLog( aWrongPasswordException.Message );
- AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
- throw;
+ SetEncryptionKeyProperty_Impl( xPropertySet, uno::Sequence< beans::NamedValue >() );
}
}
catch( uno::Exception& aException )
{
- SetEncryptionKeyProperty_Impl( xPropertySet, uno::Sequence< sal_Int8 >() );
+ OSL_FAIL( "Can't open encrypted stream!" );
+ SetEncryptionKeyProperty_Impl( xPropertySet, uno::Sequence< beans::NamedValue >() );
AddLog( aException.Message );
AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
throw;
}
- }
- catch( uno::Exception& aException )
- {
- OSL_FAIL( "Can't open encrypted stream!\n" );
- SetEncryptionKeyProperty_Impl( xPropertySet, uno::Sequence< sal_Int8 >() );
- AddLog( aException.Message );
- AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
- throw;
- }
- SetEncryptionKeyProperty_Impl( xPropertySet, uno::Sequence< sal_Int8 >() );
+ SetEncryptionKeyProperty_Impl( xPropertySet, uno::Sequence< beans::NamedValue >() );
}
// in case of new inserted package stream it is possible that input stream still was not set
diff --git a/package/source/xstor/xstorage.cxx b/package/source/xstor/xstorage.cxx
index ab3c5f3..1eca31c 100644
--- a/package/source/xstor/xstorage.cxx
+++ b/package/source/xstor/xstorage.cxx
@@ -46,6 +46,7 @@
#include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
#include <com/sun/star/beans/NamedValue.hpp>
+#include <PackageConstants.hxx>
#include <cppuhelper/typeprovider.hxx>
#include <cppuhelper/exc_hlp.hxx>
@@ -572,7 +573,7 @@ void OStorage_Impl::GetStorageProperties()
if ( !m_bControlMediaType )
{
uno::Reference< beans::XPropertySet > xPackageProps( m_xPackage, uno::UNO_QUERY_THROW );
- xPackageProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MediaTypeFallbackUsed" ) ) ) >>= m_bMTFallbackUsed;
+ xPackageProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MEDIATYPE_FALLBACK_USED_PROPERTY ) ) ) >>= m_bMTFallbackUsed;
xProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MediaType" ) ) ) >>= m_aMediaType;
m_bControlMediaType = sal_True;
@@ -750,9 +751,17 @@ void OStorage_Impl::CopyToStorage( const uno::Reference< embed::XStorage >& xDes
{
try
{
- uno::Reference< embed::XEncryptionProtectedSource2 > xEncr( xDest, uno::UNO_QUERY );
+ uno::Reference< embed::XEncryptionProtectedStorage > xEncr( xDest, uno::UNO_QUERY );
if ( xEncr.is() )
+ {
xEncr->setEncryptionData( GetCommonRootEncryptionData().getAsConstNamedValueList() );
+
+ uno::Sequence< beans::NamedValue > aAlgorithms;
+ uno::Reference< beans::XPropertySet > xPackPropSet( m_xPackage, uno::UNO_QUERY_THROW );
+ xPackPropSet->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ENCRYPTION_ALGORITHMS_PROPERTY ) ) )
+ >>= aAlgorithms;
+ xEncr->setEncryptionAlgorithms( aAlgorithms );
+ }
}
catch( packages::NoEncryptionException& aNoEncryptionException )
{
@@ -985,7 +994,9 @@ void OStorage_Impl::CopyStorageElement( SotElement_Impl* pElement,
AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Handled exception" ) ) );
// If the common storage password does not allow to open the stream
- // it must be copyed in raw way
+ // it could be copyed in raw way, the problem is that the StartKey should be the same
+ // in the ODF1.2 package, so an invalid package could be produced if the stream
+ // is copied from ODF1.1 package, where it is allowed to have different StartKeys
uno::Reference< embed::XStorageRawAccess > xRawDest( xDest, uno::UNO_QUERY_THROW );
uno::Reference< io::XInputStream > xRawInStream = pElement->m_pStream->GetRawInStream();
xRawDest->insertRawEncrStreamElement( aName, xRawInStream );
@@ -2278,7 +2289,8 @@ uno::Any SAL_CALL OStorage::queryInterface( const uno::Type& rType )
( rType
, static_cast<embed::XStorageRawAccess*> ( this )
, static_cast<embed::XEncryptionProtectedSource*> ( this )
- , static_cast<embed::XEncryptionProtectedSource2*> ( this ) );
+ , static_cast<embed::XEncryptionProtectedSource2*> ( this )
+ , static_cast<embed::XEncryptionProtectedStorage*> ( this ) );
}
else
{
@@ -2338,6 +2350,7 @@ uno::Sequence< uno::Type > SAL_CALL OStorage::getTypes()
, ::getCppuType( ( const uno::Reference< embed::XTransactedObject >* )NULL )
, ::getCppuType( ( const uno::Reference< embed::XTransactionBroadcaster >* )NULL )
, ::getCppuType( ( const uno::Reference< util::XModifiable >* )NULL )
+ , ::getCppuType( ( const uno::Reference< embed::XEncryptionProtectedStorage >* )NULL )
, ::getCppuType( ( const uno::Reference< embed::XEncryptionProtectedSource2 >* )NULL )
, ::getCppuType( ( const uno::Reference< embed::XEncryptionProtectedSource >* )NULL )
, ::getCppuType( ( const uno::Reference< beans::XPropertySet >* )NULL ) );
@@ -4697,18 +4710,23 @@ void SAL_CALL OStorage::removeEncryption()
// TODO: check if the password is valid
// update all streams that was encrypted with old password
- uno::Reference< beans::XPropertySet > xPackPropSet( m_pImpl->m_xPackage, uno::UNO_QUERY );
- if ( !xPackPropSet.is() )
- throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
-
+ uno::Reference< beans::XPropertySet > xPackPropSet( m_pImpl->m_xPackage, uno::UNO_QUERY_THROW );
try
{
- xPackPropSet->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "EncryptionKey" ) ),
- uno::makeAny( uno::Sequence< sal_Int8 >() ) );
+ xPackPropSet->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( STORAGE_ENCRYPTION_KEYS_PROPERTY ) ),
+ uno::makeAny( uno::Sequence< beans::NamedValue >() ) );
m_pImpl->m_bHasCommonEncryptionData = sal_False;
m_pImpl->m_aCommonEncryptionData.clear();
}
+ catch( uno::RuntimeException& aRException )
+ {
+ m_pImpl->AddLog( aRException.Message );
+ m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
+
+ OSL_FAIL( "The call must not fail, it is pretty simple!" );
+ throw;
+ }
catch( uno::Exception& aException )
{
m_pImpl->AddLog( aException.Message );
@@ -4767,16 +4785,13 @@ void SAL_CALL OStorage::setEncryptionData( const uno::Sequence< beans::NamedValu
uno::UNO_QUERY ),
aCaught );
}
-
- uno::Reference< beans::XPropertySet > xPackPropSet( m_pImpl->m_xPackage, uno::UNO_QUERY );
- if ( !xPackPropSet.is() )
- throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
+ uno::Reference< beans::XPropertySet > xPackPropSet( m_pImpl->m_xPackage, uno::UNO_QUERY_THROW );
try
{
::comphelper::SequenceAsHashMap aEncryptionMap( aEncryptionData );
- xPackPropSet->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "EncryptionKey" ) ),
- uno::makeAny( aEncryptionMap.getUnpackedValueOrDefault( PACKAGE_ENCRYPTIONDATA_SHA1UTF8, uno::Sequence< sal_Int8 >() ) ) );
+ xPackPropSet->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( STORAGE_ENCRYPTION_KEYS_PROPERTY ) ),
+ uno::makeAny( aEncryptionMap.getAsConstNamedValueList() ) );
m_pImpl->m_bHasCommonEncryptionData = sal_True;
m_pImpl->m_aCommonEncryptionData = aEncryptionMap;
@@ -4792,6 +4807,82 @@ void SAL_CALL OStorage::setEncryptionData( const uno::Sequence< beans::NamedValu
}
+//____________________________________________________________________________________________________
+// XEncryptionProtectedStorage
+//____________________________________________________________________________________________________
+
+//-----------------------------------------------
+void SAL_CALL OStorage::setEncryptionAlgorithms( const uno::Sequence< beans::NamedValue >& aAlgorithms )
+ throw (lang::IllegalArgumentException, uno::RuntimeException)
+{
+ RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::setEncryptionAlgorithms" );
+
+ ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
+
+ if ( !m_pImpl )
+ {
+ ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
+ throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
+ }
+
+ if ( m_pData->m_nStorageType != embed::StorageFormats::PACKAGE )
+ throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // the interface must be visible only for package storage
+
+ if ( !aAlgorithms.getLength() )
+ throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected empty encryption algorithms list!") ), uno::Reference< uno::XInterface >() );
+
+ OSL_ENSURE( m_pData->m_bIsRoot, "setEncryptionAlgorithms() method is not available for nonroot storages!\n" );
+ if ( m_pData->m_bIsRoot )
+ {
+ try {
+ m_pImpl->ReadContents();
+ }
+ catch ( uno::RuntimeException& aRuntimeException )
+ {
+ m_pImpl->AddLog( aRuntimeException.Message );
+ m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
+ throw;
+ }
+ catch ( uno::Exception& aException )
+ {
+ m_pImpl->AddLog( aException.Message );
+ m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
+
+ uno::Any aCaught( ::cppu::getCaughtException() );
+ throw lang::WrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can not open package!\n" ) ),
+ uno::Reference< uno::XInterface >( static_cast< OWeakObject* >( this ),
+ uno::UNO_QUERY ),
+ aCaught );
+ }
+
+ uno::Reference< beans::XPropertySet > xPackPropSet( m_pImpl->m_xPackage, uno::UNO_QUERY_THROW );
+ try
+ {
+ xPackPropSet->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ENCRYPTION_ALGORITHMS_PROPERTY ) ),
+ uno::makeAny( aAlgorithms ) );
+ }
+ catch ( uno::RuntimeException& aRuntimeException )
+ {
+ m_pImpl->AddLog( aRuntimeException.Message );
+ m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
+ throw;
+ }
+ catch( lang::IllegalArgumentException& aIAException )
+ {
+ m_pImpl->AddLog( aIAException.Message );
+ m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
+
+ throw;
+ }
+ catch( uno::Exception& aException )
+ {
+ m_pImpl->AddLog( aException.Message );
+ m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
+
+ throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
+ }
+ }
+}
//____________________________________________________________________________________________________
// XPropertySet
@@ -4864,13 +4955,13 @@ void SAL_CALL OStorage::setPropertyValue( const ::rtl::OUString& aPropertyName,
m_pImpl->m_bIsModified = sal_True;
}
}
- else if ( ( m_pData->m_bIsRoot && ( aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "HasEncryptedEntries" ) )
- || aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "HasNonEncryptedEntries" ) )
- || aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "IsInconsistent" ) )
+ else if ( ( m_pData->m_bIsRoot && ( aPropertyName.equalsAscii( HAS_ENCRYPTED_ENTRIES_PROPERTY )
+ || aPropertyName.equalsAscii( HAS_NONENCRYPTED_ENTRIES_PROPERTY )
+ || aPropertyName.equalsAscii( IS_INCONSISTENT_PROPERTY )
|| aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "URL" ) )
|| aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "RepairPackage" ) ) ) )
|| aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "IsRoot" ) )
- || aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "MediaTypeFallbackUsed" ) ) )
+ || aPropertyName.equalsAscii( MEDIATYPE_FALLBACK_USED_PROPERTY ) )
throw beans::PropertyVetoException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
else
throw beans::UnknownPropertyException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
@@ -4944,7 +5035,7 @@ uno::Any SAL_CALL OStorage::getPropertyValue( const ::rtl::OUString& aPropertyNa
if ( m_pData->m_nStorageType == embed::StorageFormats::PACKAGE
&& ( aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "MediaType" ) )
- || aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "MediaTypeFallbackUsed" ) )
+ || aPropertyName.equalsAscii( MEDIATYPE_FALLBACK_USED_PROPERTY )
|| aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Version" ) ) ) )
{
try
@@ -5001,9 +5092,9 @@ uno::Any SAL_CALL OStorage::getPropertyValue( const ::rtl::OUString& aPropertyNa
return uno::makeAny( sal_False ); // RepairPackage
}
else if ( m_pData->m_nStorageType == embed::StorageFormats::PACKAGE
- && ( aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "HasEncryptedEntries" ) )
- || aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "HasNonEncryptedEntries" ) )
- || aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "IsInconsistent" ) ) ) )
+ && ( aPropertyName.equalsAscii( HAS_ENCRYPTED_ENTRIES_PROPERTY )
+ || aPropertyName.equalsAscii( HAS_NONENCRYPTED_ENTRIES_PROPERTY )
+ || aPropertyName.equalsAscii( IS_INCONSISTENT_PROPERTY ) ) )
{
try {
m_pImpl->ReadContents();
diff --git a/package/source/xstor/xstorage.hxx b/package/source/xstor/xstorage.hxx
index 66a626e..46764df 100644
--- a/package/source/xstor/xstorage.hxx
+++ b/package/source/xstor/xstorage.hxx
@@ -37,7 +37,7 @@
#include <com/sun/star/embed/XTransactedObject.hpp>
#include <com/sun/star/embed/XTransactionBroadcaster.hpp>
#include <com/sun/star/embed/XClassifiedObject.hpp>
-#include <com/sun/star/embed/XEncryptionProtectedSource2.hpp>
+#include <com/sun/star/embed/XEncryptionProtectedStorage.hpp>
#include <com/sun/star/embed/XRelationshipAccess.hpp>
#include <com/sun/star/util/XModifiable.hpp>
#include <com/sun/star/container/XNameAccess.hpp>
@@ -297,7 +297,7 @@ class OStorage : public ::com::sun::star::lang::XTypeProvider
, public ::com::sun::star::embed::XTransactedObject
, public ::com::sun::star::embed::XTransactionBroadcaster
, public ::com::sun::star::util::XModifiable
- , public ::com::sun::star::embed::XEncryptionProtectedSource2
+ , public ::com::sun::star::embed::XEncryptionProtectedStorage
, public ::com::sun::star::beans::XPropertySet
, public ::com::sun::star::embed::XOptimizedStorage
, public ::com::sun::star::embed::XRelationshipAccess
@@ -647,6 +647,11 @@ public:
throw ( ::com::sun::star::io::IOException,
::com::sun::star::uno::RuntimeException );
+ //____________________________________________________________________________________________________
+ // XEncryptionProtectedStorage
+ //____________________________________________________________________________________________________
+
+ virtual void SAL_CALL setEncryptionAlgorithms( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& aAlgorithms ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
//____________________________________________________________________________________________________
// XPropertySet
diff --git a/package/source/zipapi/EntryInputStream.cxx b/package/source/zipapi/EntryInputStream.cxx
deleted file mode 100644
index 00ae61f..0000000
--- a/package/source/zipapi/EntryInputStream.cxx
+++ /dev/null
@@ -1,205 +0,0 @@
-/* -*- 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.
- *
- ************************************************************************/
-
-// MARKER(update_precomp.py): autogen include statement, do not remove
-#include "precompiled_package.hxx"
-#include <EntryInputStream.hxx>
-#include <com/sun/star/packages/zip/ZipConstants.hpp>
-#include <rtl/cipher.h>
-#include <rtl/digest.h>
-#include <memory.h> // for memcpy
-
-using namespace com::sun::star;
-using namespace com::sun::star::uno;
-using namespace com::sun::star::packages::zip;
-using namespace com::sun::star::packages::zip::ZipConstants;
-
-using ::rtl::OUString;
-
-/** Provides access to the compressed data in a zipfile.
- *
- * uncompresses the stream into memory and seeks on it 'in memory'
- * This and the ZipPackageBuffer used in the ZipOutputStream are memory hogs
- * and will hopefully be replaced eventually
- *
- * Acts on the same underlying XInputStream as both the full Zip File and other
- * EntryInputStreams, and thus must maintain its current position in the stream and
- * seek to it before performing any reads.
- */
-
-EntryInputStream::EntryInputStream( Reference < io::XInputStream > xNewInput,
- const ZipEntry & rNewEntry,
- const rtl::Reference < EncryptionData > &xEncryptData,
- sal_Bool bGetRawStream)
-: xStream( xNewInput )
-, xSeek( xNewInput, UNO_QUERY )
-, aEntry (rNewEntry )
-, nCurrent( 0 )
-, bHaveInMemory ( sal_False )
-, aInflater( sal_True )
-, aBuffer( 0 )
-, xEncryptionData (xEncryptData)
-, bRawStream (bGetRawStream)
-{
- if (bGetRawStream)
- {
- nUncompressedSize = aEntry.nMethod == DEFLATED ? aEntry.nCompressedSize : aEntry.nSize;
- nEnd = aEntry.nOffset + nUncompressedSize;
- }
- else
- {
- nEnd = aEntry.nMethod == DEFLATED ? aEntry.nOffset + aEntry.nCompressedSize : aEntry.nOffset + aEntry.nSize;
- nUncompressedSize = aEntry.nSize;
- }
-}
-void EntryInputStream::readIntoMemory()
- throw(io::NotConnectedException, io::BufferSizeExceededException, io::IOException, RuntimeException)
-{
- if (!bHaveInMemory)
- {
- Sequence < sal_Int8 > aReadBuffer;
- xSeek->seek(aEntry.nOffset);
- sal_Int32 nSize = aEntry.nMethod == DEFLATED ? aEntry.nCompressedSize : aEntry.nSize;
-
- if (nSize <0)
- throw io::BufferSizeExceededException(::rtl::OUString(), *this);
-
- xStream->readBytes( aReadBuffer, nSize ); // Now it holds the raw stuff from disk
-
- if (xEncryptionData->aSalt.getLength())
- {
- // Have salt, will travel
- Sequence < sal_uInt8 > aDerivedKey (16);
- rtlCipherError aResult;
- Sequence < sal_Int8 > aDecryptBuffer;
-
- // Get the key
- rtl_digest_PBKDF2 ( aDerivedKey.getArray(), 16,
- reinterpret_cast < const sal_uInt8 * > (xEncryptionData->aKey.getConstArray()),
- xEncryptionData->aKey.getLength(),
- xEncryptionData->aSalt.getConstArray(),
- xEncryptionData->aSalt.getLength(),
- xEncryptionData->nIterationCount );
-
- rtlCipher aCipher = rtl_cipher_create (rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeStream);
- aResult = rtl_cipher_init( aCipher, rtl_Cipher_DirectionDecode,
- aDerivedKey.getConstArray(),
- aDerivedKey.getLength(),
- xEncryptionData->aInitVector.getConstArray(),
- xEncryptionData->aInitVector.getLength());
- OSL_ASSERT (aResult == rtl_Cipher_E_None);
- aDecryptBuffer.realloc ( nSize );
- aResult = rtl_cipher_decode ( aCipher,
- aReadBuffer.getConstArray(),
- nSize,
- reinterpret_cast < sal_uInt8 * > (aDecryptBuffer.getArray()),
- nSize);
- OSL_ASSERT (aResult == rtl_Cipher_E_None);
- aReadBuffer = aDecryptBuffer; // Now it holds the decrypted data
- }
- if (bRawStream || aEntry.nMethod == STORED)
- aBuffer = aReadBuffer; // bRawStream means the caller doesn't want it decompressed
- else
- {
- aInflater.setInputSegment(aReadBuffer, 0, nSize );
- aBuffer.realloc( aEntry.nSize );
- aInflater.doInflate(aBuffer);
- aInflater.end();
- }
- bHaveInMemory = sal_True;
- }
-}
-EntryInputStream::~EntryInputStream( void )
-{
-}
-
-sal_Int32 SAL_CALL EntryInputStream::readBytes( Sequence< sal_Int8 >& aData,
- sal_Int32 nBytesToRead )
- throw(io::NotConnectedException, io::BufferSizeExceededException, io::IOException, RuntimeException)
-{
- if (nBytesToRead <0)
- throw io::BufferSizeExceededException(::rtl::OUString(), *this);
- if (!bHaveInMemory)
- readIntoMemory();
- if (nBytesToRead + nCurrent > nUncompressedSize)
- nBytesToRead = static_cast < sal_Int32> ( nUncompressedSize - nCurrent );
-
- aData.realloc( nBytesToRead );
- memcpy(aData.getArray(), aBuffer.getConstArray() + nCurrent, nBytesToRead);
- nCurrent+=nBytesToRead;
-
- return nBytesToRead;
-}
-sal_Int32 SAL_CALL EntryInputStream::readSomeBytes( Sequence< sal_Int8 >& aData,
- sal_Int32 nMaxBytesToRead )
- throw(io::NotConnectedException, io::BufferSizeExceededException, io::IOException, RuntimeException)
-{
- return readBytes( aData, nMaxBytesToRead );
-}
-void SAL_CALL EntryInputStream::skipBytes( sal_Int32 nBytesToSkip )
- throw(io::NotConnectedException, io::BufferSizeExceededException, io::IOException, RuntimeException)
-{
- if (nBytesToSkip < 0)
- throw io::BufferSizeExceededException(::rtl::OUString(), *this);
-
- if (nBytesToSkip + nCurrent > nUncompressedSize)
- nBytesToSkip = static_cast < sal_Int32 > (nUncompressedSize- nCurrent);
-
- nCurrent+=nBytesToSkip;
-}
-sal_Int32 SAL_CALL EntryInputStream::available( )
- throw(io::NotConnectedException, io::IOException, RuntimeException)
-{
- return static_cast < sal_Int32 > (nUncompressedSize - nCurrent);
-}
-void SAL_CALL EntryInputStream::closeInput( )
- throw(io::NotConnectedException, io::IOException, RuntimeException)
-{
-}
-
-void SAL_CALL EntryInputStream::seek( sal_Int64 location )
- throw(lang::IllegalArgumentException, io::IOException, RuntimeException)
-{
- if (location > nUncompressedSize)
- location = nUncompressedSize;
- if (location <0)
- location = 0;
- nCurrent = location;
-}
-sal_Int64 SAL_CALL EntryInputStream::getPosition( )
- throw(io::IOException, RuntimeException)
-{
- return nCurrent;
-}
-sal_Int64 SAL_CALL EntryInputStream::getLength( )
- throw(io::IOException, RuntimeException)
-{
- return nUncompressedSize;
-}
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/package/source/zipapi/EntryInputStream.hxx b/package/source/zipapi/EntryInputStream.hxx
deleted file mode 100644
index cf1bf5a..0000000
--- a/package/source/zipapi/EntryInputStream.hxx
+++ /dev/null
@@ -1,85 +0,0 @@
-/* -*- 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 _ENTRY_INPUT_STREAM_HXX
-#define _ENTRY_INPUT_STREAM_HXX
-
-#include <cppuhelper/implbase2.hxx> // helper for implementations
-#include <com/sun/star/io/XInputStream.hpp>
-#include <com/sun/star/io/XSeekable.hpp>
-#include <Inflater.hxx>
-#include <com/sun/star/packages/zip/ZipEntry.hpp>
-#include <rtl/ref.hxx>
-#include <EncryptionData.hxx>
-class EntryInputStream : public cppu::WeakImplHelper2< com::sun::star::io::XInputStream,
- com::sun::star::io::XSeekable >
-{
-protected:
- com::sun::star::uno::Reference< com::sun::star::io::XInputStream > xStream;
- com::sun::star::uno::Reference< com::sun::star::io::XSeekable > xSeek;
- sal_Int64 nEnd, nCurrent, nUncompressedSize;
- sal_Bool bRawStream, bHaveInMemory, bEncrypted;
- com::sun::star::uno::Sequence < sal_Int8 > aBuffer;
- const rtl::Reference < EncryptionData > xEncryptionData;
- const com::sun::star::packages::zip::ZipEntry aEntry;
- Inflater aInflater;
- void readIntoMemory()
- throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
-public:
- EntryInputStream( com::sun::star::uno::Reference < com::sun::star::io::XInputStream > xInput,
- const com::sun::star::packages::zip::ZipEntry &rNewEntry,
- const rtl::Reference < EncryptionData > &xEncryptData,
- sal_Bool bGetRawStream = sal_False);
- virtual ~EntryInputStream();
-
- // XInputStream
- virtual sal_Int32 SAL_CALL readBytes( ::com::sun::star::uno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead )
- throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
- virtual sal_Int32 SAL_CALL readSomeBytes( ::com::sun::star::uno::Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead )
... etc. - the rest is truncated
More information about the Libreoffice-commits
mailing list