summaryrefslogtreecommitdiff
path: root/package/source
diff options
context:
space:
mode:
authorMikhail Voytenko <mav@openoffice.org>2010-11-04 17:56:39 +0100
committerMikhail Voytenko <mav@openoffice.org>2010-11-04 17:56:39 +0100
commitfcd3252f26e20158ce96af5a7cc3a53e65616a4e (patch)
treea10ea55a2454e401e9cf17e31eefe524e10ce404 /package/source
parentb14b784844e479fafd2bc9388f87c21529c2b335 (diff)
pl08: #163778# use EncryptionData from MediaDescriptor
Diffstat (limited to 'package/source')
-rw-r--r--package/source/xstor/ohierarchyholder.cxx21
-rw-r--r--package/source/xstor/ohierarchyholder.hxx18
-rw-r--r--package/source/xstor/owriteablestream.cxx206
-rw-r--r--package/source/xstor/owriteablestream.hxx38
-rw-r--r--package/source/xstor/xstorage.cxx586
-rw-r--r--package/source/xstor/xstorage.hxx66
-rw-r--r--package/source/zippackage/ZipPackage.cxx2
7 files changed, 552 insertions, 385 deletions
diff --git a/package/source/xstor/ohierarchyholder.cxx b/package/source/xstor/ohierarchyholder.cxx
index 8e22b2b3a093..32ebc7068ec3 100644
--- a/package/source/xstor/ohierarchyholder.cxx
+++ b/package/source/xstor/ohierarchyholder.cxx
@@ -29,7 +29,7 @@
#include "precompiled_package.hxx"
#include <com/sun/star/uno/Reference.hxx>
#include <com/sun/star/embed/ElementModes.hpp>
-#include <com/sun/star/embed/XHierarchicalStorageAccess.hpp>
+#include <com/sun/star/embed/XHierarchicalStorageAccess2.hpp>
#include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
#include "ohierarchyholder.hxx"
@@ -41,7 +41,7 @@ using namespace ::com::sun::star;
//===============================================
//-----------------------------------------------
-uno::Reference< embed::XExtendedStorageStream > OHierarchyHolder_Impl::GetStreamHierarchically( sal_Int32 nStorageMode, OStringList_Impl& aListPath, sal_Int32 nStreamMode, const ::rtl::OUString& aPass )
+uno::Reference< embed::XExtendedStorageStream > OHierarchyHolder_Impl::GetStreamHierarchically( sal_Int32 nStorageMode, OStringList_Impl& aListPath, sal_Int32 nStreamMode, const ::comphelper::SequenceAsHashMap& aEncryptionData )
{
uno::Reference< embed::XStorage > xOwnStor( m_xWeakOwnStorage.get(), uno::UNO_QUERY_THROW );
@@ -49,7 +49,7 @@ uno::Reference< embed::XExtendedStorageStream > OHierarchyHolder_Impl::GetStream
throw io::IOException();
uno::Reference< embed::XExtendedStorageStream > xResult =
- m_xChild->GetStreamHierarchically( nStorageMode, aListPath, nStreamMode, aPass );
+ m_xChild->GetStreamHierarchically( nStorageMode, aListPath, nStreamMode, aEncryptionData );
if ( !xResult.is() )
throw uno::RuntimeException();
@@ -88,7 +88,7 @@ OStringList_Impl OHierarchyHolder_Impl::GetListPathFromString( const ::rtl::OUSt
//===============================================
//-----------------------------------------------
-uno::Reference< embed::XExtendedStorageStream > OHierarchyElement_Impl::GetStreamHierarchically( sal_Int32 nStorageMode, OStringList_Impl& aListPath, sal_Int32 nStreamMode, const ::rtl::OUString& aPass )
+uno::Reference< embed::XExtendedStorageStream > OHierarchyElement_Impl::GetStreamHierarchically( sal_Int32 nStorageMode, OStringList_Impl& aListPath, sal_Int32 nStreamMode, const ::comphelper::SequenceAsHashMap& aEncryptionData )
{
::osl::MutexGuard aGuard( m_aMutex );
@@ -110,11 +110,16 @@ uno::Reference< embed::XExtendedStorageStream > OHierarchyElement_Impl::GetStrea
if ( !aListPath.size() )
{
- uno::Reference< embed::XHierarchicalStorageAccess > xHStorage( xOwnStor, uno::UNO_QUERY_THROW );
- if ( !aPass.getLength() )
+ if ( !aEncryptionData.size() )
+ {
+ uno::Reference< embed::XHierarchicalStorageAccess > xHStorage( xOwnStor, uno::UNO_QUERY_THROW );
xResult = xHStorage->openStreamElementByHierarchicalName( aNextName, nStreamMode );
+ }
else
- xResult = xHStorage->openEncryptedStreamElementByHierarchicalName( aNextName, nStreamMode, aPass );
+ {
+ uno::Reference< embed::XHierarchicalStorageAccess2 > xHStorage( xOwnStor, uno::UNO_QUERY_THROW );
+ xResult = xHStorage->openEncryptedStreamByHierarchicalName( aNextName, nStreamMode, aEncryptionData.getAsConstNamedValueList() );
+ }
uno::Reference< embed::XTransactedObject > xTransact( xResult, uno::UNO_QUERY );
if ( xTransact.is() )
@@ -150,7 +155,7 @@ uno::Reference< embed::XExtendedStorageStream > OHierarchyElement_Impl::GetStrea
aElement = new OHierarchyElement_Impl( NULL, xChildStorage );
}
- xResult = aElement->GetStreamHierarchically( nStorageMode, aListPath, nStreamMode, aPass );
+ xResult = aElement->GetStreamHierarchically( nStorageMode, aListPath, nStreamMode, aEncryptionData );
if ( !xResult.is() )
throw uno::RuntimeException();
diff --git a/package/source/xstor/ohierarchyholder.hxx b/package/source/xstor/ohierarchyholder.hxx
index 17c14d3a6001..d36d784ac839 100644
--- a/package/source/xstor/ohierarchyholder.hxx
+++ b/package/source/xstor/ohierarchyholder.hxx
@@ -33,6 +33,8 @@
#include <com/sun/star/embed/XExtendedStorageStream.hpp>
#include <cppuhelper/implbase1.hxx>
+#include <comphelper/sequenceashashmap.hxx>
+
#include <rtl/ref.hxx>
#include <hash_map>
@@ -90,10 +92,10 @@ public:
void RemoveElement( const ::rtl::Reference< OHierarchyElement_Impl >& aRef );
::com::sun::star::uno::Reference< ::com::sun::star::embed::XExtendedStorageStream >
- GetStreamHierarchically( sal_Int32 nStorageMode,
- OStringList_Impl& aPath,
- sal_Int32 nStreamMode,
- const ::rtl::OUString& aPassword = ::rtl::OUString() );
+ GetStreamHierarchically( sal_Int32 nStorageMode,
+ OStringList_Impl& aPath,
+ sal_Int32 nStreamMode,
+ const ::comphelper::SequenceAsHashMap& aEncryptionData = ::comphelper::SequenceAsHashMap() );
void RemoveStreamHierarchically( OStringList_Impl& aListPath );
@@ -127,10 +129,10 @@ public:
static OStringList_Impl GetListPathFromString( const ::rtl::OUString& aPath );
::com::sun::star::uno::Reference< ::com::sun::star::embed::XExtendedStorageStream >
- GetStreamHierarchically( sal_Int32 nStorageMode,
- OStringList_Impl& aListPath,
- sal_Int32 nStreamMode,
- const ::rtl::OUString& aPassword = ::rtl::OUString() );
+ GetStreamHierarchically( sal_Int32 nStorageMode,
+ OStringList_Impl& aListPath,
+ sal_Int32 nStreamMode,
+ const ::comphelper::SequenceAsHashMap& aEncryptionData = ::comphelper::SequenceAsHashMap() );
void RemoveStreamHierarchically( OStringList_Impl& aListPath );
};
diff --git a/package/source/xstor/owriteablestream.cxx b/package/source/xstor/owriteablestream.cxx
index be11586bc4fb..9eefd8383cb3 100644
--- a/package/source/xstor/owriteablestream.cxx
+++ b/package/source/xstor/owriteablestream.cxx
@@ -64,29 +64,25 @@ using namespace ::com::sun::star;
namespace package
{
//-----------------------------------------------
-uno::Sequence< sal_Int8 > MakeKeyFromPass( const ::rtl::OUString& aPass, sal_Bool bUseUTF )
+bool PackageEncryptionDatasEqual( const ::comphelper::SequenceAsHashMap& aHash1, const ::comphelper::SequenceAsHashMap& aHash2 )
{
- // MS_1252 encoding was used for SO60 document format password encoding,
- // this encoding supports only a minor subset of nonascii characters,
- // but for compatibility reasons it has to be used for old document formats
-
- ::rtl::OString aByteStrPass;
- if ( bUseUTF )
- aByteStrPass = ::rtl::OUStringToOString( aPass, RTL_TEXTENCODING_UTF8 );
- else
- aByteStrPass = ::rtl::OUStringToOString( aPass, RTL_TEXTENCODING_MS_1252 );
-
- sal_uInt8 pBuffer[RTL_DIGEST_LENGTH_SHA1];
- rtlDigestError nError = rtl_digest_SHA1( aByteStrPass.getStr(),
- aByteStrPass.getLength(),
- pBuffer,
- RTL_DIGEST_LENGTH_SHA1 );
-
- if ( nError != rtl_Digest_E_None )
- throw uno::RuntimeException();
-
- return uno::Sequence< sal_Int8 >( (sal_Int8*)pBuffer, RTL_DIGEST_LENGTH_SHA1 );
+ bool bResult = ( aHash1.size() && aHash1.size() == aHash2.size() );
+ for ( ::comphelper::SequenceAsHashMap::const_iterator aIter = aHash1.begin();
+ bResult && aIter != aHash1.end();
+ aIter++ )
+ {
+ uno::Sequence< sal_Int8 > aKey1;
+ bResult = ( ( aIter->second >>= aKey1 ) && aKey1.getLength() );
+ if ( bResult )
+ {
+ uno::Sequence< sal_Int8 > aKey2 = aHash2.getUnpackedValueOrDefault( aIter->first, uno::Sequence< sal_Int8 >() );
+ bResult = ( aKey1.getLength() == aKey2.getLength() );
+ for ( sal_Int32 nInd = 0; bResult && nInd < aKey1.getLength(); nInd++ )
+ bResult = ( aKey1[nInd] == aKey2[nInd] );
+ }
+ }
+ return bResult;
}
//-----------------------------------------------
@@ -255,8 +251,8 @@ OWriteStream_Impl::OWriteStream_Impl( OStorage_Impl* pParent,
, m_xFactory( xFactory )
, m_pParent( pParent )
, m_bForceEncrypted( bForceEncrypted )
-, m_bUseCommonPass( !bForceEncrypted && nStorageType == embed::StorageFormats::PACKAGE )
-, m_bHasCachedPassword( sal_False )
+, m_bUseCommonEncryption( !bForceEncrypted && nStorageType == embed::StorageFormats::PACKAGE )
+, m_bHasCachedEncryptionData( sal_False )
, m_bCompressedSetExplicit( !bDefaultCompress )
, m_xPackage( xPackage )
, m_bHasInsertedStreamOptimization( sal_False )
@@ -363,7 +359,7 @@ sal_Bool OWriteStream_Impl::IsEncrypted()
if ( m_nStorageType != embed::StorageFormats::PACKAGE )
return sal_False;
- if ( m_bForceEncrypted || m_bHasCachedPassword )
+ if ( m_bForceEncrypted || m_bHasCachedEncryptionData )
return sal_True;
if ( m_aTempURL.getLength() || m_xCacheStream.is() )
@@ -410,7 +406,7 @@ sal_Bool OWriteStream_Impl::IsEncrypted()
if ( !bWasEncr && bToBeEncr && !aKey.getLength() )
{
// the stream is intended to use common storage password
- m_bUseCommonPass = sal_True;
+ m_bUseCommonEncryption = sal_True;
return sal_False;
}
else
@@ -432,8 +428,8 @@ void OWriteStream_Impl::SetDecrypted()
// remove encryption
m_bForceEncrypted = sal_False;
- m_bHasCachedPassword = sal_False;
- m_aPass = ::rtl::OUString();
+ m_bHasCachedEncryptionData = sal_False;
+ m_aEncryptionData.clear();
for ( sal_Int32 nInd = 0; nInd < m_aProps.getLength(); nInd++ )
{
@@ -443,12 +439,15 @@ void OWriteStream_Impl::SetDecrypted()
}
//-----------------------------------------------
-void OWriteStream_Impl::SetEncryptedWithPass( const ::rtl::OUString& aPass )
+void OWriteStream_Impl::SetEncrypted( const ::comphelper::SequenceAsHashMap& aEncryptionData )
{
OSL_ENSURE( m_nStorageType == embed::StorageFormats::PACKAGE, "The encryption is supported only for package storages!\n" );
if ( m_nStorageType != embed::StorageFormats::PACKAGE )
throw uno::RuntimeException();
+ if ( !aEncryptionData.size() )
+ throw uno::RuntimeException();
+
GetStreamProperties();
// let the stream be modified
@@ -462,10 +461,10 @@ void OWriteStream_Impl::SetEncryptedWithPass( const ::rtl::OUString& aPass )
m_aProps[nInd].Value <<= sal_True;
}
- m_bUseCommonPass = sal_False; // very important to set it to false
+ m_bUseCommonEncryption = sal_False; // very important to set it to false
- m_bHasCachedPassword = sal_True;
- m_aPass = aPass;
+ m_bHasCachedEncryptionData = sal_True;
+ m_aEncryptionData = aEncryptionData;
}
//-----------------------------------------------
@@ -796,7 +795,7 @@ void OWriteStream_Impl::InsertStreamDirectly( const uno::Reference< io::XInputSt
xPropertySet->setPropertyValue( aProps[nInd].Name, aProps[nInd].Value );
}
else if ( m_nStorageType == embed::StorageFormats::PACKAGE && aProps[nInd].Name.equalsAscii( "UseCommonStoragePasswordEncryption" ) )
- aProps[nInd].Value >>= m_bUseCommonPass;
+ aProps[nInd].Value >>= m_bUseCommonEncryption;
else
throw lang::IllegalArgumentException();
@@ -815,7 +814,7 @@ void OWriteStream_Impl::InsertStreamDirectly( const uno::Reference< io::XInputSt
m_bCompressedSetExplicit = sal_True;
}
- if ( m_bUseCommonPass )
+ if ( m_bUseCommonEncryption )
{
if ( m_nStorageType != embed::StorageFormats::PACKAGE )
throw uno::RuntimeException();
@@ -914,7 +913,7 @@ void OWriteStream_Impl::Commit()
xPropertySet->setPropertyValue( m_aProps[nInd].Name, m_aProps[nInd].Value );
}
- if ( m_bUseCommonPass )
+ if ( m_bUseCommonEncryption )
{
if ( m_nStorageType != embed::StorageFormats::PACKAGE )
throw uno::RuntimeException();
@@ -925,13 +924,13 @@ void OWriteStream_Impl::Commit()
xPropertySet->setPropertyValue( ::rtl::OUString::createFromAscii( "Encrypted" ),
uno::makeAny( sal_True ) );
}
- else if ( m_bHasCachedPassword )
+ else if ( m_bHasCachedEncryptionData )
{
if ( m_nStorageType != embed::StorageFormats::PACKAGE )
throw uno::RuntimeException();
xPropertySet->setPropertyValue( ::rtl::OUString::createFromAscii( "EncryptionKey" ),
- uno::makeAny( ::package::MakeKeyFromPass( m_aPass, sal_True ) ) );
+ uno::makeAny( m_aEncryptionData.getUnpackedValueOrDefault( PACKAGE_ENCRYPTIONDATA_SHA1UTF8, uno::Sequence< sal_Int8 >() ) ) );
}
// the stream should be free soon, after package is stored
@@ -969,9 +968,9 @@ void OWriteStream_Impl::Revert()
m_bHasDataToFlush = sal_False;
- m_bUseCommonPass = sal_True;
- m_bHasCachedPassword = sal_False;
- m_aPass = ::rtl::OUString();
+ m_bUseCommonEncryption = sal_True;
+ m_bHasCachedEncryptionData = sal_False;
+ m_aEncryptionData.clear();
if ( m_nStorageType == embed::StorageFormats::OFOPXML )
{
@@ -1007,7 +1006,7 @@ uno::Sequence< beans::PropertyValue > OWriteStream_Impl::GetStreamProperties()
//-----------------------------------------------
uno::Sequence< beans::PropertyValue > OWriteStream_Impl::InsertOwnProps(
const uno::Sequence< beans::PropertyValue >& aProps,
- sal_Bool bUseCommonPass )
+ sal_Bool bUseCommonEncryption )
{
uno::Sequence< beans::PropertyValue > aResult( aProps );
sal_Int32 nLen = aResult.getLength();
@@ -1017,13 +1016,13 @@ uno::Sequence< beans::PropertyValue > OWriteStream_Impl::InsertOwnProps(
for ( sal_Int32 nInd = 0; nInd < nLen; nInd++ )
if ( aResult[nInd].Name.equalsAscii( "UseCommonStoragePasswordEncryption" ) )
{
- aResult[nInd].Value <<= bUseCommonPass;
+ aResult[nInd].Value <<= bUseCommonEncryption;
return aResult;
}
aResult.realloc( ++nLen );
aResult[nLen - 1].Name = ::rtl::OUString::createFromAscii( "UseCommonStoragePasswordEncryption" );
- aResult[nLen - 1].Value <<= bUseCommonPass;
+ aResult[nLen - 1].Value <<= bUseCommonEncryption;
}
else if ( m_nStorageType == embed::StorageFormats::OFOPXML )
{
@@ -1172,11 +1171,11 @@ uno::Sequence< beans::PropertyValue > OWriteStream_Impl::ReadPackageStreamProper
//-----------------------------------------------
void OWriteStream_Impl::CopyInternallyTo_Impl( const uno::Reference< io::XStream >& xDestStream,
- const ::rtl::OUString& aPass )
+ const ::comphelper::SequenceAsHashMap& aEncryptionData )
{
::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ) ;
- OSL_ENSURE( !m_bUseCommonPass, "The stream can not be encrypted!" );
+ OSL_ENSURE( !m_bUseCommonEncryption, "The stream can not be encrypted!" );
if ( m_nStorageType != embed::StorageFormats::PACKAGE )
throw packages::NoEncryptionException();
@@ -1187,16 +1186,16 @@ void OWriteStream_Impl::CopyInternallyTo_Impl( const uno::Reference< io::XStream
}
else
{
- uno::Reference< io::XStream > xOwnStream = GetStream( embed::ElementModes::READ, aPass, sal_False );
+ uno::Reference< io::XStream > xOwnStream = GetStream( embed::ElementModes::READ, aEncryptionData, sal_False );
if ( !xOwnStream.is() )
throw io::IOException(); // TODO
OStorage_Impl::completeStorageStreamCopy_Impl( xOwnStream, xDestStream, m_nStorageType, GetAllRelationshipsIfAny() );
}
- uno::Reference< embed::XEncryptionProtectedSource > xEncr( xDestStream, uno::UNO_QUERY );
+ uno::Reference< embed::XEncryptionProtectedSource2 > xEncr( xDestStream, uno::UNO_QUERY );
if ( xEncr.is() )
- xEncr->setEncryptionPassword( aPass );
+ xEncr->setEncryptionData( aEncryptionData.getAsConstNamedValueList() );
}
//-----------------------------------------------
@@ -1236,7 +1235,7 @@ void OWriteStream_Impl::CopyInternallyTo_Impl( const uno::Reference< io::XStream
}
//-----------------------------------------------
-uno::Reference< io::XStream > OWriteStream_Impl::GetStream( sal_Int32 nStreamMode, const ::rtl::OUString& aPass, sal_Bool bHierarchyAccess )
+uno::Reference< io::XStream > OWriteStream_Impl::GetStream( sal_Int32 nStreamMode, const ::comphelper::SequenceAsHashMap& aEncryptionData, sal_Bool bHierarchyAccess )
{
::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ) ;
@@ -1254,9 +1253,9 @@ uno::Reference< io::XStream > OWriteStream_Impl::GetStream( sal_Int32 nStreamMod
if ( !xPropertySet.is() )
throw uno::RuntimeException();
- if ( m_bHasCachedPassword )
+ if ( m_bHasCachedEncryptionData )
{
- if ( !m_aPass.equals( aPass ) )
+ if ( !::package::PackageEncryptionDatasEqual( m_aEncryptionData, aEncryptionData ) )
throw packages::WrongPasswordException();
// the correct key must be set already
@@ -1264,26 +1263,26 @@ uno::Reference< io::XStream > OWriteStream_Impl::GetStream( sal_Int32 nStreamMod
}
else
{
- SetEncryptionKeyProperty_Impl( xPropertySet, ::package::MakeKeyFromPass( aPass, sal_True ) );
+ SetEncryptionKeyProperty_Impl( xPropertySet, aEncryptionData.getUnpackedValueOrDefault( PACKAGE_ENCRYPTIONDATA_SHA1UTF8, uno::Sequence< sal_Int8 >() ) );
try {
xResultStream = GetStream_Impl( nStreamMode, bHierarchyAccess );
- m_bUseCommonPass = sal_False; // very important to set it to false
- m_bHasCachedPassword = sal_True;
- m_aPass = aPass;
+ m_bUseCommonEncryption = sal_False; // very important to set it to false
+ m_bHasCachedEncryptionData = sal_True;
+ m_aEncryptionData = aEncryptionData;
}
catch( packages::WrongPasswordException& )
{
// retry with different encoding
- SetEncryptionKeyProperty_Impl( xPropertySet, ::package::MakeKeyFromPass( aPass, sal_False ) );
+ 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_bUseCommonPass = sal_False; // very important to set it to false
- m_bHasCachedPassword = sal_True;
- m_aPass = aPass;
+ 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 )
@@ -1343,10 +1342,10 @@ uno::Reference< io::XStream > OWriteStream_Impl::GetStream( sal_Int32 nStreamMod
if ( IsEncrypted() )
{
- ::rtl::OUString aGlobalPass;
+ ::comphelper::SequenceAsHashMap aGlobalEncryptionData;
try
{
- aGlobalPass = GetCommonRootPass();
+ aGlobalEncryptionData = GetCommonRootEncryptionData();
}
catch( packages::NoEncryptionException& aNoEncryptionException )
{
@@ -1356,7 +1355,7 @@ uno::Reference< io::XStream > OWriteStream_Impl::GetStream( sal_Int32 nStreamMod
throw packages::WrongPasswordException();
}
- xResultStream = GetStream( nStreamMode, aGlobalPass, bHierarchyAccess );
+ xResultStream = GetStream( nStreamMode, aGlobalEncryptionData, bHierarchyAccess );
}
else
xResultStream = GetStream_Impl( nStreamMode, bHierarchyAccess );
@@ -1385,7 +1384,7 @@ uno::Reference< io::XStream > OWriteStream_Impl::GetStream_Impl( sal_Int32 nStre
if ( !xInStream.is() )
throw io::IOException();
- OInputCompStream* pStream = new OInputCompStream( *this, xInStream, InsertOwnProps( m_aProps, m_bUseCommonPass ), m_nStorageType );
+ OInputCompStream* pStream = new OInputCompStream( *this, xInStream, InsertOwnProps( m_aProps, m_bUseCommonEncryption ), m_nStorageType );
uno::Reference< io::XStream > xCompStream(
static_cast< ::cppu::OWeakObject* >( pStream ),
uno::UNO_QUERY );
@@ -1410,7 +1409,7 @@ uno::Reference< io::XStream > OWriteStream_Impl::GetStream_Impl( sal_Int32 nStre
if ( !xInStream.is() )
throw io::IOException();
- OInputSeekStream* pStream = new OInputSeekStream( *this, xInStream, InsertOwnProps( m_aProps, m_bUseCommonPass ), m_nStorageType );
+ OInputSeekStream* pStream = new OInputSeekStream( *this, xInStream, InsertOwnProps( m_aProps, m_bUseCommonEncryption ), m_nStorageType );
uno::Reference< io::XStream > xSeekStream(
static_cast< ::cppu::OWeakObject* >( pStream ),
uno::UNO_QUERY );
@@ -1512,7 +1511,7 @@ uno::Reference< io::XInputStream > OWriteStream_Impl::GetRawInStream()
}
//-----------------------------------------------
-::rtl::OUString OWriteStream_Impl::GetCommonRootPass()
+::comphelper::SequenceAsHashMap OWriteStream_Impl::GetCommonRootEncryptionData()
throw ( packages::NoEncryptionException )
{
::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ) ;
@@ -1520,7 +1519,7 @@ uno::Reference< io::XInputStream > OWriteStream_Impl::GetRawInStream()
if ( m_nStorageType != embed::StorageFormats::PACKAGE || !m_pParent )
throw packages::NoEncryptionException();
- return m_pParent->GetCommonRootPass();
+ return m_pParent->GetCommonRootEncryptionData();
}
//-----------------------------------------------
@@ -1559,11 +1558,11 @@ void OWriteStream_Impl::CreateReadonlyCopyBasedOnData( const uno::Reference< io:
if ( !xInStream.is() )
throw io::IOException();
- // TODO: remember last state of m_bUseCommonPass
+ // TODO: remember last state of m_bUseCommonEncryption
if ( !xTargetStream.is() )
xTargetStream = uno::Reference< io::XStream > (
static_cast< ::cppu::OWeakObject* >(
- new OInputSeekStream( xInStream, InsertOwnProps( aProps, m_bUseCommonPass ), m_nStorageType ) ),
+ new OInputSeekStream( xInStream, InsertOwnProps( aProps, m_bUseCommonEncryption ), m_nStorageType ) ),
uno::UNO_QUERY_THROW );
}
@@ -1580,10 +1579,10 @@ void OWriteStream_Impl::GetCopyOfLastCommit( uno::Reference< io::XStream >& xTar
if ( IsEncrypted() )
{
// an encrypted stream must contain input stream
- ::rtl::OUString aGlobalPass;
+ ::comphelper::SequenceAsHashMap aGlobalEncryptionData;
try
{
- aGlobalPass = GetCommonRootPass();
+ aGlobalEncryptionData = GetCommonRootEncryptionData();
}
catch( packages::NoEncryptionException& aNoEncryptionException )
{
@@ -1593,7 +1592,7 @@ void OWriteStream_Impl::GetCopyOfLastCommit( uno::Reference< io::XStream >& xTar
throw packages::WrongPasswordException();
}
- GetCopyOfLastCommit( xTargetStream, aGlobalPass );
+ GetCopyOfLastCommit( xTargetStream, aGlobalEncryptionData );
}
else
{
@@ -1602,12 +1601,12 @@ void OWriteStream_Impl::GetCopyOfLastCommit( uno::Reference< io::XStream >& xTar
// in case of new inserted package stream it is possible that input stream still was not set
GetStreamProperties();
- CreateReadonlyCopyBasedOnData( xDataToCopy, m_aProps, m_bUseCommonPass, xTargetStream );
+ CreateReadonlyCopyBasedOnData( xDataToCopy, m_aProps, m_bUseCommonEncryption, xTargetStream );
}
}
//-----------------------------------------------
-void OWriteStream_Impl::GetCopyOfLastCommit( uno::Reference< io::XStream >& xTargetStream, const ::rtl::OUString& aPass )
+void OWriteStream_Impl::GetCopyOfLastCommit( uno::Reference< io::XStream >& xTargetStream, const ::comphelper::SequenceAsHashMap& aEncryptionData )
{
::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
@@ -1620,12 +1619,12 @@ void OWriteStream_Impl::GetCopyOfLastCommit( uno::Reference< io::XStream >& xTar
uno::Reference< io::XInputStream > xDataToCopy;
- if ( m_bHasCachedPassword )
+ if ( m_bHasCachedEncryptionData )
{
// 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 = ::package::MakeKeyFromPass( aPass, sal_True );
- uno::Sequence< sal_Int8 > aOldKey = ::package::MakeKeyFromPass( aPass, sal_False );
+ 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::Reference< beans::XPropertySet > xProps( m_xPackageStream, uno::UNO_QUERY );
if ( !xProps.is() )
@@ -1647,7 +1646,7 @@ void OWriteStream_Impl::GetCopyOfLastCommit( uno::Reference< io::XStream >& xTar
else
{
uno::Reference< beans::XPropertySet > xPropertySet( m_xPackageStream, uno::UNO_QUERY );
- SetEncryptionKeyProperty_Impl( xPropertySet, ::package::MakeKeyFromPass( aPass, sal_True ) );
+ SetEncryptionKeyProperty_Impl( xPropertySet, aEncryptionData.getUnpackedValueOrDefault( PACKAGE_ENCRYPTIONDATA_SHA1UTF8, uno::Sequence< sal_Int8 >() ) );
try {
xDataToCopy = m_xPackageStream->getDataStream();
@@ -1660,7 +1659,7 @@ void OWriteStream_Impl::GetCopyOfLastCommit( uno::Reference< io::XStream >& xTar
}
catch( packages::WrongPasswordException& aWrongPasswordException )
{
- SetEncryptionKeyProperty_Impl( xPropertySet, ::package::MakeKeyFromPass( aPass, sal_False ) );
+ SetEncryptionKeyProperty_Impl( xPropertySet, aEncryptionData.getUnpackedValueOrDefault( PACKAGE_ENCRYPTIONDATA_SHA1MS1252, uno::Sequence< sal_Int8 >() ) );
try {
xDataToCopy = m_xPackageStream->getDataStream();
@@ -1696,7 +1695,7 @@ void OWriteStream_Impl::GetCopyOfLastCommit( uno::Reference< io::XStream >& xTar
// in case of new inserted package stream it is possible that input stream still was not set
GetStreamProperties();
- CreateReadonlyCopyBasedOnData( xDataToCopy, m_aProps, m_bUseCommonPass, xTargetStream );
+ CreateReadonlyCopyBasedOnData( xDataToCopy, m_aProps, m_bUseCommonEncryption, xTargetStream );
}
//-----------------------------------------------
@@ -2028,6 +2027,7 @@ uno::Any SAL_CALL OWriteStream::queryInterface( const uno::Type& rType )
{
aReturn <<= ::cppu::queryInterface
( rType
+ , static_cast<embed::XEncryptionProtectedSource2*> ( this )
, static_cast<embed::XEncryptionProtectedSource*> ( this ) );
}
else if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML )
@@ -2080,7 +2080,7 @@ uno::Sequence< uno::Type > SAL_CALL OWriteStream::getTypes()
{
if ( m_pData->m_nStorageType == embed::StorageFormats::PACKAGE )
{
- m_pData->m_pTypeCollection = new ::cppu::OTypeCollection
+ ::cppu::OTypeCollection aTmpCollection
( ::getCppuType( ( const uno::Reference< lang::XTypeProvider >* )NULL )
, ::getCppuType( ( const uno::Reference< io::XInputStream >* )NULL )
, ::getCppuType( ( const uno::Reference< io::XOutputStream >* )NULL )
@@ -2088,11 +2088,15 @@ uno::Sequence< uno::Type > SAL_CALL OWriteStream::getTypes()
, ::getCppuType( ( const uno::Reference< io::XSeekable >* )NULL )
, ::getCppuType( ( const uno::Reference< io::XTruncate >* )NULL )
, ::getCppuType( ( const uno::Reference< lang::XComponent >* )NULL )
+ , ::getCppuType( ( const uno::Reference< embed::XEncryptionProtectedSource2 >* )NULL )
, ::getCppuType( ( const uno::Reference< embed::XEncryptionProtectedSource >* )NULL )
, ::getCppuType( ( const uno::Reference< embed::XExtendedStorageStream >* )NULL )
, ::getCppuType( ( const uno::Reference< embed::XTransactedObject >* )NULL )
- , ::getCppuType( ( const uno::Reference< embed::XTransactionBroadcaster >* )NULL )
- , ::getCppuType( ( const uno::Reference< beans::XPropertySet >* )NULL ) );
+ , ::getCppuType( ( const uno::Reference< embed::XTransactionBroadcaster >* )NULL ) );
+
+ m_pData->m_pTypeCollection = new ::cppu::OTypeCollection
+ ( ::getCppuType( ( const uno::Reference< beans::XPropertySet >* )NULL )
+ , aTmpCollection.getTypes() );
}
else if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML )
{
@@ -2138,6 +2142,7 @@ uno::Sequence< uno::Type > SAL_CALL OWriteStream::getTypes()
, ::getCppuType( ( const uno::Reference< io::XSeekable >* )NULL )
, ::getCppuType( ( const uno::Reference< io::XTruncate >* )NULL )
, ::getCppuType( ( const uno::Reference< lang::XComponent >* )NULL )
+ , ::getCppuType( ( const uno::Reference< embed::XEncryptionProtectedSource2 >* )NULL )
, ::getCppuType( ( const uno::Reference< embed::XEncryptionProtectedSource >* )NULL )
, ::getCppuType( ( const uno::Reference< beans::XPropertySet >* )NULL ) );
}
@@ -2713,7 +2718,7 @@ void SAL_CALL OWriteStream::setEncryptionPassword( const ::rtl::OUString& aPass
OSL_ENSURE( m_pImpl->m_xPackageStream.is(), "No package stream is set!\n" );
- m_pImpl->SetEncryptedWithPass( aPass );
+ m_pImpl->SetEncrypted( ::comphelper::OStorageHelper::CreatePackageEncryptionData( aPass ) );
ModifyParentUnlockMutex_Impl( aGuard );
}
@@ -2741,6 +2746,27 @@ void SAL_CALL OWriteStream::removeEncryption()
}
//-----------------------------------------------
+void SAL_CALL OWriteStream::setEncryptionData( const uno::Sequence< beans::NamedValue >& aEncryptionData )
+ throw (io::IOException, uno::RuntimeException)
+{
+ ::osl::ResettableMutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
+
+ CheckInitOnDemand();
+
+ if ( !m_pImpl )
+ {
+ ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
+ throw lang::DisposedException();
+ }
+
+ OSL_ENSURE( m_pImpl->m_xPackageStream.is(), "No package stream is set!\n" );
+
+ m_pImpl->SetEncrypted( aEncryptionData );
+
+ ModifyParentUnlockMutex_Impl( aGuard );
+}
+
+//-----------------------------------------------
sal_Bool SAL_CALL OWriteStream::hasByID( const ::rtl::OUString& sID )
throw ( io::IOException,
uno::RuntimeException )
@@ -3181,24 +3207,24 @@ void SAL_CALL OWriteStream::setPropertyValue( const ::rtl::OUString& aPropertyNa
else if ( m_pData->m_nStorageType == embed::StorageFormats::PACKAGE
&& aPropertyName.equalsAscii( "UseCommonStoragePasswordEncryption" ) )
{
- sal_Bool bUseCommonPass = sal_False;
- if ( aValue >>= bUseCommonPass )
+ sal_Bool bUseCommonEncryption = sal_False;
+ if ( aValue >>= bUseCommonEncryption )
{
if ( m_bInitOnDemand && m_pImpl->m_bHasInsertedStreamOptimization )
{
// the data stream is provided to the packagestream directly
- m_pImpl->m_bUseCommonPass = bUseCommonPass;
+ m_pImpl->m_bUseCommonEncryption = bUseCommonEncryption;
}
- else if ( bUseCommonPass )
+ else if ( bUseCommonEncryption )
{
- if ( !m_pImpl->m_bUseCommonPass )
+ if ( !m_pImpl->m_bUseCommonEncryption )
{
m_pImpl->SetDecrypted();
- m_pImpl->m_bUseCommonPass = sal_True;
+ m_pImpl->m_bUseCommonEncryption = sal_True;
}
}
else
- m_pImpl->m_bUseCommonPass = sal_False;
+ m_pImpl->m_bUseCommonEncryption = sal_False;
}
else
throw lang::IllegalArgumentException(); //TODO
@@ -3293,7 +3319,7 @@ uno::Any SAL_CALL OWriteStream::getPropertyValue( const ::rtl::OUString& aProp )
}
else if ( m_pData->m_nStorageType == embed::StorageFormats::PACKAGE
&& aPropertyName.equalsAscii( "UseCommonStoragePasswordEncryption" ) )
- return uno::makeAny( m_pImpl->m_bUseCommonPass );
+ return uno::makeAny( m_pImpl->m_bUseCommonEncryption );
else if ( aPropertyName.equalsAscii( "Size" ) )
{
CheckInitOnDemand();
diff --git a/package/source/xstor/owriteablestream.hxx b/package/source/xstor/owriteablestream.hxx
index 0d4a29893887..08f862b22f6c 100644
--- a/package/source/xstor/owriteablestream.hxx
+++ b/package/source/xstor/owriteablestream.hxx
@@ -38,7 +38,7 @@
#include <com/sun/star/lang/XEventListener.hpp>
#include <com/sun/star/lang/XSingleServiceFactory.hpp>
#include <com/sun/star/lang/XComponent.hpp>
-#include <com/sun/star/embed/XEncryptionProtectedSource.hpp>
+#include <com/sun/star/embed/XEncryptionProtectedSource2.hpp>
#include <com/sun/star/embed/XStorage.hpp>
#include <com/sun/star/embed/XRelationshipAccess.hpp>
#include <com/sun/star/embed/XExtendedStorageStream.hpp>
@@ -53,6 +53,8 @@
#include <cppuhelper/weak.hxx>
#include <cppuhelper/interfacecontainer.h>
+#include <comphelper/sequenceashashmap.hxx>
+
#include <list>
#include "ocompinstream.hxx"
@@ -75,7 +77,7 @@ namespace cppu {
namespace package {
void StaticAddLog( const ::rtl::OUString& aMessage );
- ::com::sun::star::uno::Sequence< sal_Int8 > MakeKeyFromPass( const ::rtl::OUString& aPass, sal_Bool bUseUTF );
+ bool PackageEncryptionDatasEqual( const ::comphelper::SequenceAsHashMap& aHash1, const ::comphelper::SequenceAsHashMap& aHash2 );
}
struct WSInternalData_Impl
@@ -127,9 +129,9 @@ struct OWriteStream_Impl : public PreCreationStruct
sal_Bool m_bForceEncrypted;
- sal_Bool m_bUseCommonPass;
- sal_Bool m_bHasCachedPassword;
- ::rtl::OUString m_aPass;
+ sal_Bool m_bUseCommonEncryption;
+ sal_Bool m_bHasCachedEncryptionData;
+ ::comphelper::SequenceAsHashMap m_aEncryptionData;
sal_Bool m_bCompressedSetExplicit;
@@ -161,12 +163,12 @@ private:
::com::sun::star::uno::Reference< ::com::sun::star::io::XStream > GetStream_Impl( sal_Int32 nStreamMode,
sal_Bool bHierarchyAccess );
- ::rtl::OUString GetCommonRootPass() throw ( ::com::sun::star::packages::NoEncryptionException );
+ ::comphelper::SequenceAsHashMap GetCommonRootEncryptionData() throw ( ::com::sun::star::packages::NoEncryptionException );
::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > ReadPackageStreamProperties();
::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > InsertOwnProps(
const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aProps,
- sal_Bool bUseCommonPass );
+ sal_Bool bUseCommonEncryption );
public:
OWriteStream_Impl(
@@ -186,7 +188,7 @@ public:
void AddLog( const ::rtl::OUString& aMessage );
- sal_Bool UsesCommonPass_Impl() { return m_bUseCommonPass; }
+ sal_Bool UsesCommonEncryption_Impl() { return m_bUseCommonEncryption; }
sal_Bool HasTempFile_Impl() { return ( m_aTempURL.getLength() != 0 ); }
sal_Bool IsTransacted();
@@ -198,13 +200,14 @@ public:
void SetToBeCommited() { m_bFlushed = sal_True; }
- sal_Bool HasCachedPassword() { return m_bHasCachedPassword; }
- ::rtl::OUString GetCachedPassword() { return m_aPass; }
+ sal_Bool HasCachedEncryptionData() { return m_bHasCachedEncryptionData; }
+ ::comphelper::SequenceAsHashMap& GetCachedEncryptionData() { return m_aEncryptionData; }
+
sal_Bool IsModified() { return m_bHasDataToFlush || m_bFlushed; }
sal_Bool IsEncrypted();
void SetDecrypted();
- void SetEncryptedWithPass( const ::rtl::OUString& aPass );
+ void SetEncrypted( const ::comphelper::SequenceAsHashMap& aEncryptionData );
void DisposeWrappers();
@@ -226,12 +229,12 @@ public:
::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair > > GetAllRelationshipsIfAny();
void CopyInternallyTo_Impl( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream >& xDestStream,
- const ::rtl::OUString& aPass );
+ const ::comphelper::SequenceAsHashMap& aEncryptionData );
void CopyInternallyTo_Impl( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream >& xDestStream );
::com::sun::star::uno::Reference< ::com::sun::star::io::XStream > GetStream(
sal_Int32 nStreamMode,
- const ::rtl::OUString& aPass,
+ const ::comphelper::SequenceAsHashMap& aEncryptionData,
sal_Bool bHierarchyAccess );
::com::sun::star::uno::Reference< ::com::sun::star::io::XStream > GetStream(
@@ -247,13 +250,13 @@ public:
void CreateReadonlyCopyBasedOnData(
const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& xDataToCopy,
const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aProps,
- sal_Bool bUseCommonPass,
+ sal_Bool bUseCommonEncryption,
::com::sun::star::uno::Reference< ::com::sun::star::io::XStream >& xTargetStream );
void GetCopyOfLastCommit( ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream >& xTargetStream );
void GetCopyOfLastCommit(
::com::sun::star::uno::Reference< ::com::sun::star::io::XStream >& xTargetStream,
- const ::rtl::OUString& aPass );
+ const ::comphelper::SequenceAsHashMap& aEncryptionData );
void CommitStreamRelInfo(
@@ -272,7 +275,7 @@ class OWriteStream : ::com::sun::star::lang::XTypeProvider
, public ::com::sun::star::embed::XExtendedStorageStream
, public ::com::sun::star::io::XSeekable
, public ::com::sun::star::io::XTruncate
- , public ::com::sun::star::embed::XEncryptionProtectedSource
+ , public ::com::sun::star::embed::XEncryptionProtectedSource2
, public ::com::sun::star::embed::XRelationshipAccess
, public ::com::sun::star::embed::XTransactedObject
, public ::com::sun::star::embed::XTransactionBroadcaster
@@ -366,6 +369,9 @@ public:
throw ( ::com::sun::star::uno::RuntimeException,
::com::sun::star::io::IOException );
+ //XEncryptionProtectedSource2
+ virtual void SAL_CALL setEncryptionData( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& aEncryptionData ) throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
+
//XRelationshipAccess
virtual ::sal_Bool SAL_CALL hasByID( const ::rtl::OUString& sID ) throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
virtual ::rtl::OUString SAL_CALL getTargetByID( const ::rtl::OUString& sID ) throw (::com::sun::star::container::NoSuchElementException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
diff --git a/package/source/xstor/xstorage.cxx b/package/source/xstor/xstorage.cxx
index 9c90c4ce35dd..db3ca63f649d 100644
--- a/package/source/xstor/xstorage.cxx
+++ b/package/source/xstor/xstorage.cxx
@@ -207,7 +207,7 @@ OStorage_Impl::OStorage_Impl( uno::Reference< io::XInputStream > xInputStream,
, m_bListCreated( sal_False )
, m_xFactory( xFactory )
, m_xProperties( xProperties )
-, m_bHasCommonPassword( sal_False )
+, m_bHasCommonEncryptionData( sal_False )
, m_pParent( NULL )
, m_bControlMediaType( sal_False )
, m_bMTFallbackUsed( sal_False )
@@ -247,7 +247,7 @@ OStorage_Impl::OStorage_Impl( uno::Reference< io::XStream > xStream,
, m_bListCreated( sal_False )
, m_xFactory( xFactory )
, m_xProperties( xProperties )
-, m_bHasCommonPassword( sal_False )
+, m_bHasCommonEncryptionData( sal_False )
, m_pParent( NULL )
, m_bControlMediaType( sal_False )
, m_bMTFallbackUsed( sal_False )
@@ -291,7 +291,7 @@ OStorage_Impl::OStorage_Impl( OStorage_Impl* pParent,
, m_xPackageFolder( xPackageFolder )
, m_xPackage( xPackage )
, m_xFactory( xFactory )
-, m_bHasCommonPassword( sal_False )
+, m_bHasCommonEncryptionData( sal_False )
, m_pParent( pParent ) // can be empty in case of temporary readonly substorages and relation storage
, m_bControlMediaType( sal_False )
, m_bMTFallbackUsed( sal_False )
@@ -748,10 +748,9 @@ void OStorage_Impl::CopyToStorage( const uno::Reference< embed::XStorage >& xDes
{
try
{
- ::rtl::OUString aCommonPass = GetCommonRootPass();
- uno::Reference< embed::XEncryptionProtectedSource > xEncr( xDest, uno::UNO_QUERY );
+ uno::Reference< embed::XEncryptionProtectedSource2 > xEncr( xDest, uno::UNO_QUERY );
if ( xEncr.is() )
- xEncr->setEncryptionPassword( aCommonPass );
+ xEncr->setEncryptionData( GetCommonRootEncryptionData().getAsConstNamedValueList() );
}
catch( packages::NoEncryptionException& aNoEncryptionException )
{
@@ -855,7 +854,7 @@ void OStorage_Impl::CopyStorageElement( SotElement_Impl* pElement,
{
aStrProps.realloc( ++nNum );
aStrProps[nNum-1].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "UseCommonStoragePasswordEncryption" ) );
- aStrProps[nNum-1].Value <<= (sal_Bool)( pElement->m_pStream->UsesCommonPass_Impl() );
+ aStrProps[nNum-1].Value <<= (sal_Bool)( pElement->m_pStream->UsesCommonEncryption_Impl() );
}
else if ( m_nStorageType == embed::StorageFormats::OFOPXML )
{
@@ -913,15 +912,15 @@ void OStorage_Impl::CopyStorageElement( SotElement_Impl* pElement,
OSL_ENSURE( sal_False, "Encryption is only supported in package storage!\n" );
throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
}
- else if ( pElement->m_pStream->HasCachedPassword()
+ else if ( pElement->m_pStream->HasCachedEncryptionData()
&& ( pElement->m_pStream->IsModified() || pElement->m_pStream->HasWriteOwner_Impl() ) )
{
- ::rtl::OUString aCommonPass;
- sal_Bool bHasCommonPass = sal_False;
+ ::comphelper::SequenceAsHashMap aCommonEncryptionData;
+ sal_Bool bHasCommonEncryptionData = sal_False;
try
{
- aCommonPass = GetCommonRootPass();
- bHasCommonPass = sal_True;
+ aCommonEncryptionData = GetCommonRootEncryptionData();
+ bHasCommonEncryptionData = sal_True;
}
catch( packages::NoEncryptionException& aNoEncryptionException )
{
@@ -929,7 +928,7 @@ void OStorage_Impl::CopyStorageElement( SotElement_Impl* pElement,
AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "No Encryption" ) ) );
}
- if ( bHasCommonPass && pElement->m_pStream->GetCachedPassword().equals( aCommonPass ) )
+ if ( bHasCommonEncryptionData && ::package::PackageEncryptionDatasEqual( pElement->m_pStream->GetCachedEncryptionData(), aCommonEncryptionData ) )
{
// If the stream can be opened with the common storage password
// it must be stored with the common storage password as well
@@ -947,13 +946,14 @@ void OStorage_Impl::CopyStorageElement( SotElement_Impl* pElement,
else
{
// the stream is already opened for writing or was changed
+ uno::Reference< embed::XStorage2 > xDest2( xDest, uno::UNO_QUERY_THROW );
uno::Reference< io::XStream > xSubStr =
- xDest->openEncryptedStreamElement( aName,
+ xDest2->openEncryptedStream( aName,
embed::ElementModes::READWRITE | embed::ElementModes::TRUNCATE,
- pElement->m_pStream->GetCachedPassword() );
+ pElement->m_pStream->GetCachedEncryptionData().getAsConstNamedValueList() );
OSL_ENSURE( xSubStr.is(), "No destination substream!\n" );
- pElement->m_pStream->CopyInternallyTo_Impl( xSubStr, pElement->m_pStream->GetCachedPassword() );
+ pElement->m_pStream->CopyInternallyTo_Impl( xSubStr, pElement->m_pStream->GetCachedEncryptionData() );
}
}
else
@@ -1360,7 +1360,7 @@ void OStorage_Impl::Revert()
}
//-----------------------------------------------
-::rtl::OUString OStorage_Impl::GetCommonRootPass()
+::comphelper::SequenceAsHashMap OStorage_Impl::GetCommonRootEncryptionData()
throw ( packages::NoEncryptionException )
{
::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ) ;
@@ -1370,17 +1370,17 @@ void OStorage_Impl::Revert()
if ( m_bIsRoot )
{
- if ( !m_bHasCommonPassword )
+ if ( !m_bHasCommonEncryptionData )
throw packages::NoEncryptionException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
- return m_aCommonPassword;
+ return m_aCommonEncryptionData;
}
else
{
if ( !m_pParent )
throw packages::NoEncryptionException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
- return m_pParent->GetCommonRootPass();
+ return m_pParent->GetCommonRootEncryptionData();
}
}
@@ -1679,8 +1679,8 @@ void OStorage_Impl::ClearElement( SotElement_Impl* pElement )
//-----------------------------------------------
void OStorage_Impl::CloneStreamElement( const ::rtl::OUString& aStreamName,
- sal_Bool bPassProvided,
- const ::rtl::OUString& aPass,
+ sal_Bool bEncryptionDataProvided,
+ const ::comphelper::SequenceAsHashMap& aEncryptionData,
uno::Reference< io::XStream >& xTargetStream )
throw ( embed::InvalidStorageException,
lang::IllegalArgumentException,
@@ -1712,8 +1712,8 @@ void OStorage_Impl::CloneStreamElement( const ::rtl::OUString& aStreamName,
// storage. The only problem is that some package streams can be accessed from outside
// at the same time ( now solwed by wrappers that remember own position ).
- if ( bPassProvided )
- pElement->m_pStream->GetCopyOfLastCommit( xTargetStream, aPass );
+ if ( bEncryptionDataProvided )
+ pElement->m_pStream->GetCopyOfLastCommit( xTargetStream, aEncryptionData );
else
pElement->m_pStream->GetCopyOfLastCommit( xTargetStream );
}
@@ -2247,6 +2247,7 @@ uno::Any SAL_CALL OStorage::queryInterface( const uno::Type& rType )
( rType
, static_cast<lang::XTypeProvider*> ( this )
, static_cast<embed::XStorage*> ( this )
+ , static_cast<embed::XStorage2*> ( this )
, static_cast<embed::XTransactedObject*> ( this )
, static_cast<embed::XTransactionBroadcaster*> ( this )
, static_cast<util::XModifiable*> ( this )
@@ -2254,8 +2255,15 @@ uno::Any SAL_CALL OStorage::queryInterface( const uno::Type& rType )
, static_cast<container::XElementAccess*> ( this )
, static_cast<lang::XComponent*> ( this )
, static_cast<beans::XPropertySet*> ( this )
- , static_cast<embed::XOptimizedStorage*> ( this )
- , static_cast<embed::XHierarchicalStorageAccess*> ( this ) );
+ , static_cast<embed::XOptimizedStorage*> ( this ) );
+
+ if ( aReturn.hasValue() == sal_True )
+ return aReturn ;
+
+ aReturn <<= ::cppu::queryInterface
+ ( rType
+ , static_cast<embed::XHierarchicalStorageAccess*> ( this )
+ , static_cast<embed::XHierarchicalStorageAccess2*> ( this ) );
if ( aReturn.hasValue() == sal_True )
return aReturn ;
@@ -2267,7 +2275,8 @@ uno::Any SAL_CALL OStorage::queryInterface( const uno::Type& rType )
aReturn <<= ::cppu::queryInterface
( rType
, static_cast<embed::XStorageRawAccess*> ( this )
- , static_cast<embed::XEncryptionProtectedSource*> ( this ) );
+ , static_cast<embed::XEncryptionProtectedSource*> ( this )
+ , static_cast<embed::XEncryptionProtectedSource2*> ( this ) );
}
else
{
@@ -2322,10 +2331,12 @@ uno::Sequence< uno::Type > SAL_CALL OStorage::getTypes()
m_pData->m_pTypeCollection = new ::cppu::OTypeCollection
( ::getCppuType( ( const uno::Reference< lang::XTypeProvider >* )NULL )
, ::getCppuType( ( const uno::Reference< embed::XStorage >* )NULL )
+ , ::getCppuType( ( const uno::Reference< embed::XStorage2 >* )NULL )
, ::getCppuType( ( const uno::Reference< embed::XStorageRawAccess >* )NULL )
, ::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::XEncryptionProtectedSource2 >* )NULL )
, ::getCppuType( ( const uno::Reference< embed::XEncryptionProtectedSource >* )NULL )
, ::getCppuType( ( const uno::Reference< beans::XPropertySet >* )NULL ) );
}
@@ -2334,6 +2345,7 @@ uno::Sequence< uno::Type > SAL_CALL OStorage::getTypes()
m_pData->m_pTypeCollection = new ::cppu::OTypeCollection
( ::getCppuType( ( const uno::Reference< lang::XTypeProvider >* )NULL )
, ::getCppuType( ( const uno::Reference< embed::XStorage >* )NULL )
+ , ::getCppuType( ( const uno::Reference< embed::XStorage2 >* )NULL )
, ::getCppuType( ( const uno::Reference< embed::XStorageRawAccess >* )NULL )
, ::getCppuType( ( const uno::Reference< embed::XTransactedObject >* )NULL )
, ::getCppuType( ( const uno::Reference< embed::XTransactionBroadcaster >* )NULL )
@@ -2576,100 +2588,7 @@ uno::Reference< io::XStream > SAL_CALL OStorage::openEncryptedStreamElement(
{
RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::openEncryptedStreamElement" );
- ::osl::ResettableMutexGuard 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 )
- packages::NoEncryptionException();
-
- if ( ( nOpenMode & embed::ElementModes::WRITE ) && m_pData->m_bReadOnlyWrap )
- throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: access denied
-
- if ( !aPass.getLength() )
- throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 3 );
-
- uno::Reference< io::XStream > xResult;
- try
- {
- SotElement_Impl *pElement = OpenStreamElement_Impl( aStreamName, nOpenMode, sal_True );
- OSL_ENSURE( pElement && pElement->m_pStream, "In case element can not be created an exception must be thrown!" );
-
- xResult = pElement->m_pStream->GetStream( nOpenMode, aPass, sal_False );
- OSL_ENSURE( xResult.is(), "The method must throw exception instead of removing empty result!\n" );
-
- if ( m_pData->m_bReadOnlyWrap )
- {
- // before the storage disposes the stream it must deregister itself as listener
- uno::Reference< lang::XComponent > xStreamComponent( xResult, uno::UNO_QUERY );
- if ( !xStreamComponent.is() )
- throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
-
- MakeLinkToSubComponent_Impl( xStreamComponent );
- }
- }
- catch( embed::InvalidStorageException& aInvalidStorageException )
- {
- m_pImpl->AddLog( aInvalidStorageException.Message );
- m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
- throw;
- }
- catch( lang::IllegalArgumentException& aIllegalArgumentException )
- {
- m_pImpl->AddLog( aIllegalArgumentException.Message );
- m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
- throw;
- }
- catch( packages::NoEncryptionException& aNoEncryptionException )
- {
- m_pImpl->AddLog( aNoEncryptionException.Message );
- m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
- throw;
- }
- catch( packages::WrongPasswordException& aWrongPasswordException )
- {
- m_pImpl->AddLog( aWrongPasswordException.Message );
- m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
- throw;
- }
- catch( embed::StorageWrappedTargetException& aStorageWrappedTargetException )
- {
- m_pImpl->AddLog( aStorageWrappedTargetException.Message );
- m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
- throw;
- }
- catch( io::IOException& aIOException )
- {
- m_pImpl->AddLog( aIOException.Message );
- m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
- throw;
- }
- 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 embed::StorageWrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't open encrypted stream stream!" ) ),
- uno::Reference< io::XInputStream >(),
- aCaught );
- }
-
- aGuard.clear();
-
- BroadcastModifiedIfNecessary();
-
- return xResult;
+ return openEncryptedStream( aStreamName, nOpenMode, ::comphelper::OStorageHelper::CreatePackageEncryptionData( aPass ) );
}
//-----------------------------------------------
@@ -2856,7 +2775,7 @@ uno::Reference< io::XStream > SAL_CALL OStorage::cloneStreamElement( const ::rtl
try
{
uno::Reference< io::XStream > xResult;
- m_pImpl->CloneStreamElement( aStreamName, sal_False, ::rtl::OUString(), xResult );
+ m_pImpl->CloneStreamElement( aStreamName, sal_False, ::comphelper::SequenceAsHashMap(), xResult );
if ( !xResult.is() )
throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
return xResult;
@@ -2923,80 +2842,7 @@ uno::Reference< io::XStream > SAL_CALL OStorage::cloneEncryptedStreamElement(
{
RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::cloneEncryptedStreamElement" );
- ::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 )
- packages::NoEncryptionException();
-
- if ( !aPass.getLength() )
- throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 2 );
-
- try
- {
- uno::Reference< io::XStream > xResult;
- m_pImpl->CloneStreamElement( aStreamName, sal_True, aPass, xResult );
- if ( !xResult.is() )
- throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
- return xResult;
- }
- catch( embed::InvalidStorageException& aInvalidStorageException )
- {
- m_pImpl->AddLog( aInvalidStorageException.Message );
- m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
- throw;
- }
- catch( lang::IllegalArgumentException& aIllegalArgumentException )
- {
- m_pImpl->AddLog( aIllegalArgumentException.Message );
- m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
- throw;
- }
- catch( packages::NoEncryptionException& aNoEncryptionException )
- {
- m_pImpl->AddLog( aNoEncryptionException.Message );
- m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
- throw;
- }
- catch( packages::WrongPasswordException& aWrongPasswordException )
- {
- m_pImpl->AddLog( aWrongPasswordException.Message );
- m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
- throw;
- }
- catch( io::IOException& aIOException )
- {
- m_pImpl->AddLog( aIOException.Message );
- m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
- throw;
- }
- catch( embed::StorageWrappedTargetException& aStorageWrappedTargetException )
- {
- m_pImpl->AddLog( aStorageWrappedTargetException.Message );
- m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
- throw;
- }
- 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 embed::StorageWrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't clone encrypted stream!" ) ),
- uno::Reference< io::XInputStream >(),
- aCaught );
- }
+ return cloneEncryptedStream( aStreamName, ::comphelper::OStorageHelper::CreatePackageEncryptionData( aPass ) );
}
//-----------------------------------------------
@@ -3721,6 +3567,210 @@ void SAL_CALL OStorage::moveElementTo( const ::rtl::OUString& aElementName,
}
//____________________________________________________________________________________________________
+// XStorage2
+//____________________________________________________________________________________________________
+
+//-----------------------------------------------
+uno::Reference< io::XStream > SAL_CALL OStorage::openEncryptedStream(
+ const ::rtl::OUString& aStreamName, sal_Int32 nOpenMode, const uno::Sequence< beans::NamedValue >& aEncryptionData )
+ throw ( embed::InvalidStorageException,
+ lang::IllegalArgumentException,
+ packages::NoEncryptionException,
+ packages::WrongPasswordException,
+ io::IOException,
+ embed::StorageWrappedTargetException,
+ uno::RuntimeException )
+{
+ RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::openEncryptedStream" );
+
+ ::osl::ResettableMutexGuard 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 )
+ packages::NoEncryptionException();
+
+ if ( ( nOpenMode & embed::ElementModes::WRITE ) && m_pData->m_bReadOnlyWrap )
+ throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: access denied
+
+ if ( !aEncryptionData.getLength() )
+ throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 3 );
+
+ uno::Reference< io::XStream > xResult;
+ try
+ {
+ SotElement_Impl *pElement = OpenStreamElement_Impl( aStreamName, nOpenMode, sal_True );
+ OSL_ENSURE( pElement && pElement->m_pStream, "In case element can not be created an exception must be thrown!" );
+
+ xResult = pElement->m_pStream->GetStream( nOpenMode, aEncryptionData, sal_False );
+ OSL_ENSURE( xResult.is(), "The method must throw exception instead of removing empty result!\n" );
+
+ if ( m_pData->m_bReadOnlyWrap )
+ {
+ // before the storage disposes the stream it must deregister itself as listener
+ uno::Reference< lang::XComponent > xStreamComponent( xResult, uno::UNO_QUERY );
+ if ( !xStreamComponent.is() )
+ throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
+
+ MakeLinkToSubComponent_Impl( xStreamComponent );
+ }
+ }
+ catch( embed::InvalidStorageException& aInvalidStorageException )
+ {
+ m_pImpl->AddLog( aInvalidStorageException.Message );
+ m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
+ throw;
+ }
+ catch( lang::IllegalArgumentException& aIllegalArgumentException )
+ {
+ m_pImpl->AddLog( aIllegalArgumentException.Message );
+ m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
+ throw;
+ }
+ catch( packages::NoEncryptionException& aNoEncryptionException )
+ {
+ m_pImpl->AddLog( aNoEncryptionException.Message );
+ m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
+ throw;
+ }
+ catch( packages::WrongPasswordException& aWrongPasswordException )
+ {
+ m_pImpl->AddLog( aWrongPasswordException.Message );
+ m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
+ throw;
+ }
+ catch( embed::StorageWrappedTargetException& aStorageWrappedTargetException )
+ {
+ m_pImpl->AddLog( aStorageWrappedTargetException.Message );
+ m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
+ throw;
+ }
+ catch( io::IOException& aIOException )
+ {
+ m_pImpl->AddLog( aIOException.Message );
+ m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
+ throw;
+ }
+ 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 embed::StorageWrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't open encrypted stream stream!" ) ),
+ uno::Reference< io::XInputStream >(),
+ aCaught );
+ }
+
+ aGuard.clear();
+
+ BroadcastModifiedIfNecessary();
+
+ return xResult;
+}
+
+//-----------------------------------------------
+uno::Reference< io::XStream > SAL_CALL OStorage::cloneEncryptedStream(
+ const ::rtl::OUString& aStreamName,
+ const uno::Sequence< beans::NamedValue >& aEncryptionData )
+ throw ( embed::InvalidStorageException,
+ lang::IllegalArgumentException,
+ packages::NoEncryptionException,
+ packages::WrongPasswordException,
+ io::IOException,
+ embed::StorageWrappedTargetException,
+ uno::RuntimeException )
+{
+ RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::cloneEncryptedStream" );
+
+ ::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 )
+ packages::NoEncryptionException();
+
+ if ( !aEncryptionData.getLength() )
+ throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 2 );
+
+ try
+ {
+ uno::Reference< io::XStream > xResult;
+ m_pImpl->CloneStreamElement( aStreamName, sal_True, aEncryptionData, xResult );
+ if ( !xResult.is() )
+ throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
+ return xResult;
+ }
+ catch( embed::InvalidStorageException& aInvalidStorageException )
+ {
+ m_pImpl->AddLog( aInvalidStorageException.Message );
+ m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
+ throw;
+ }
+ catch( lang::IllegalArgumentException& aIllegalArgumentException )
+ {
+ m_pImpl->AddLog( aIllegalArgumentException.Message );
+ m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
+ throw;
+ }
+ catch( packages::NoEncryptionException& aNoEncryptionException )
+ {
+ m_pImpl->AddLog( aNoEncryptionException.Message );
+ m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
+ throw;
+ }
+ catch( packages::WrongPasswordException& aWrongPasswordException )
+ {
+ m_pImpl->AddLog( aWrongPasswordException.Message );
+ m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
+ throw;
+ }
+ catch( io::IOException& aIOException )
+ {
+ m_pImpl->AddLog( aIOException.Message );
+ m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
+ throw;
+ }
+ catch( embed::StorageWrappedTargetException& aStorageWrappedTargetException )
+ {
+ m_pImpl->AddLog( aStorageWrappedTargetException.Message );
+ m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
+ throw;
+ }
+ 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 embed::StorageWrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't clone encrypted stream!" ) ),
+ uno::Reference< io::XInputStream >(),
+ aCaught );
+ }
+}
+
+
+//____________________________________________________________________________________________________
// XStorageRawAccess
//____________________________________________________________________________________________________
@@ -4608,6 +4658,15 @@ void SAL_CALL OStorage::setEncryptionPassword( const ::rtl::OUString& aPass )
io::IOException )
{
RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::setEncryptionPassword" );
+ setEncryptionData( ::comphelper::OStorageHelper::CreatePackageEncryptionData( aPass ) );
+}
+
+//-----------------------------------------------
+void SAL_CALL OStorage::removeEncryption()
+ throw ( uno::RuntimeException,
+ io::IOException )
+{
+ RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::removeEncryption" );
::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
@@ -4620,8 +4679,7 @@ void SAL_CALL OStorage::setEncryptionPassword( const ::rtl::OUString& aPass )
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
- OSL_ENSURE( m_pData->m_bIsRoot, "setEncryptionPassword() method is not available for nonroot storages!\n" );
-
+ OSL_ENSURE( m_pData->m_bIsRoot, "removeEncryption() method is not available for nonroot storages!\n" );
if ( m_pData->m_bIsRoot )
{
try {
@@ -4639,12 +4697,15 @@ void SAL_CALL OStorage::setEncryptionPassword( const ::rtl::OUString& aPass )
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" ) ),
+ throw lang::WrappedTargetRuntimeException( ::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 );
}
+ // 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 >() );
@@ -4652,10 +4713,10 @@ void SAL_CALL OStorage::setEncryptionPassword( const ::rtl::OUString& aPass )
try
{
xPackPropSet->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "EncryptionKey" ) ),
- uno::makeAny( ::package::MakeKeyFromPass( aPass, sal_True ) ) );
+ uno::makeAny( uno::Sequence< sal_Int8 >() ) );
- m_pImpl->m_bHasCommonPassword = sal_True;
- m_pImpl->m_aCommonPassword = aPass;
+ m_pImpl->m_bHasCommonEncryptionData = sal_False;
+ m_pImpl->m_aCommonEncryptionData.clear();
}
catch( uno::Exception& aException )
{
@@ -4668,12 +4729,15 @@ void SAL_CALL OStorage::setEncryptionPassword( const ::rtl::OUString& aPass )
}
}
-//-----------------------------------------------
-void SAL_CALL OStorage::removeEncryption()
- throw ( uno::RuntimeException,
- io::IOException )
+//____________________________________________________________________________________________________
+// XEncryptionProtectedSource2
+//____________________________________________________________________________________________________
+
+void SAL_CALL OStorage::setEncryptionData( const uno::Sequence< beans::NamedValue >& aEncryptionData )
+ throw ( io::IOException,
+ uno::RuntimeException )
{
- RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::removeEncryption" );
+ RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::setEncryptionData" );
::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
@@ -4686,8 +4750,10 @@ void SAL_CALL OStorage::removeEncryption()
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
- OSL_ENSURE( m_pData->m_bIsRoot, "removeEncryption() method is not available for nonroot storages!\n" );
+ if ( !aEncryptionData.getLength() )
+ throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected empty encryption data!") ), uno::Reference< uno::XInterface >() );
+ OSL_ENSURE( m_pData->m_bIsRoot, "setEncryptionData() method is not available for nonroot storages!\n" );
if ( m_pData->m_bIsRoot )
{
try {
@@ -4705,38 +4771,37 @@ void SAL_CALL OStorage::removeEncryption()
m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
uno::Any aCaught( ::cppu::getCaughtException() );
- throw lang::WrappedTargetRuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can not open package!\n" ) ),
+ 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 );
}
- // 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 >() );
try
{
+ ::comphelper::SequenceAsHashMap aEncryptionMap( aEncryptionData );
xPackPropSet->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "EncryptionKey" ) ),
- uno::makeAny( uno::Sequence< sal_Int8 >() ) );
+ uno::makeAny( aEncryptionMap.getUnpackedValueOrDefault( PACKAGE_ENCRYPTIONDATA_SHA1UTF8, uno::Sequence< sal_Int8 >() ) ) );
- m_pImpl->m_bHasCommonPassword = sal_False;
- m_pImpl->m_aCommonPassword = ::rtl::OUString();
+ m_pImpl->m_bHasCommonEncryptionData = sal_True;
+ m_pImpl->m_aCommonEncryptionData = aEncryptionMap;
}
catch( uno::Exception& aException )
{
m_pImpl->AddLog( aException.Message );
m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
- OSL_ENSURE( sal_False, "The call must not fail, it is pretty simple!" );
throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
}
}
+
}
+
//____________________________________________________________________________________________________
// XPropertySet
//____________________________________________________________________________________________________
@@ -5954,7 +6019,7 @@ void SAL_CALL OStorage::copyStreamElementData( const ::rtl::OUString& aStreamNam
try
{
uno::Reference< io::XStream > xNonconstRef = xTargetStream;
- m_pImpl->CloneStreamElement( aStreamName, sal_False, ::rtl::OUString(), xNonconstRef );
+ m_pImpl->CloneStreamElement( aStreamName, sal_False, ::comphelper::SequenceAsHashMap(), xNonconstRef );
OSL_ENSURE( xNonconstRef == xTargetStream, "The provided stream reference seems not be filled in correctly!\n" );
if ( xNonconstRef != xTargetStream )
@@ -6083,6 +6148,55 @@ uno::Reference< embed::XExtendedStorageStream > SAL_CALL OStorage::openEncrypted
embed::StorageWrappedTargetException,
uno::RuntimeException )
{
+ return openEncryptedStreamByHierarchicalName( aStreamPath, nOpenMode, ::comphelper::OStorageHelper::CreatePackageEncryptionData( sPassword ) );
+}
+
+//-----------------------------------------------
+void SAL_CALL OStorage::removeStreamElementByHierarchicalName( const ::rtl::OUString& aStreamPath )
+ throw ( embed::InvalidStorageException,
+ lang::IllegalArgumentException,
+ container::NoSuchElementException,
+ io::IOException,
+ embed::StorageWrappedTargetException,
+ uno::RuntimeException )
+{
+ ::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 ( !aStreamPath.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aStreamPath, sal_True ) )
+ throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 );
+
+ if ( !( m_pImpl->m_nStorageMode & embed::ElementModes::WRITE ) )
+ throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // Access denied
+
+ OStringList_Impl aListPath = OHierarchyHolder_Impl::GetListPathFromString( aStreamPath );
+ OSL_ENSURE( aListPath.size(), "The result list must not be empty!" );
+
+ if ( !m_pData->m_rHierarchyHolder.is() )
+ m_pData->m_rHierarchyHolder = new OHierarchyHolder_Impl(
+ uno::Reference< embed::XStorage >( static_cast< embed::XStorage* >( this ) ) );
+
+ m_pData->m_rHierarchyHolder->RemoveStreamHierarchically( aListPath );
+}
+
+//____________________________________________________________________________________________________
+// XHierarchicalStorageAccess2
+//____________________________________________________________________________________________________
+
+uno::Reference< embed::XExtendedStorageStream > SAL_CALL OStorage::openEncryptedStreamByHierarchicalName( const ::rtl::OUString& aStreamPath, ::sal_Int32 nOpenMode, const uno::Sequence< beans::NamedValue >& aEncryptionData )
+ throw ( embed::InvalidStorageException,
+ lang::IllegalArgumentException,
+ packages::NoEncryptionException,
+ packages::WrongPasswordException,
+ io::IOException,
+ embed::StorageWrappedTargetException,
+ uno::RuntimeException )
+{
::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
if ( !m_pImpl )
@@ -6097,7 +6211,7 @@ uno::Reference< embed::XExtendedStorageStream > SAL_CALL OStorage::openEncrypted
if ( !aStreamPath.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aStreamPath, sal_True ) )
throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 );
- if ( !sPassword.getLength() )
+ if ( !aEncryptionData.getLength() )
throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 3 );
if ( !( m_pImpl->m_nStorageMode & embed::ElementModes::WRITE )
@@ -6117,7 +6231,7 @@ uno::Reference< embed::XExtendedStorageStream > SAL_CALL OStorage::openEncrypted
OSL_ENSURE( pElement && pElement->m_pStream, "In case element can not be created an exception must be thrown!" );
xResult = uno::Reference< embed::XExtendedStorageStream >(
- pElement->m_pStream->GetStream( nOpenMode, sPassword, sal_True ),
+ pElement->m_pStream->GetStream( nOpenMode, aEncryptionData, sal_True ),
uno::UNO_QUERY_THROW );
}
else
@@ -6131,7 +6245,7 @@ uno::Reference< embed::XExtendedStorageStream > SAL_CALL OStorage::openEncrypted
( m_pImpl->m_nStorageMode & embed::ElementModes::READWRITE ),
aListPath,
nOpenMode,
- sPassword );
+ aEncryptionData );
}
if ( !xResult.is() )
@@ -6140,36 +6254,4 @@ uno::Reference< embed::XExtendedStorageStream > SAL_CALL OStorage::openEncrypted
return xResult;
}
-//-----------------------------------------------
-void SAL_CALL OStorage::removeStreamElementByHierarchicalName( const ::rtl::OUString& aStreamPath )
- throw ( embed::InvalidStorageException,
- lang::IllegalArgumentException,
- container::NoSuchElementException,
- io::IOException,
- embed::StorageWrappedTargetException,
- uno::RuntimeException )
-{
- ::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 ( !aStreamPath.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aStreamPath, sal_True ) )
- throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 );
-
- if ( !( m_pImpl->m_nStorageMode & embed::ElementModes::WRITE ) )
- throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // Access denied
-
- OStringList_Impl aListPath = OHierarchyHolder_Impl::GetListPathFromString( aStreamPath );
- OSL_ENSURE( aListPath.size(), "The result list must not be empty!" );
-
- if ( !m_pData->m_rHierarchyHolder.is() )
- m_pData->m_rHierarchyHolder = new OHierarchyHolder_Impl(
- uno::Reference< embed::XStorage >( static_cast< embed::XStorage* >( this ) ) );
-
- m_pData->m_rHierarchyHolder->RemoveStreamHierarchically( aListPath );
-}
diff --git a/package/source/xstor/xstorage.hxx b/package/source/xstor/xstorage.hxx
index f1c50e4d67bd..a49de3af6f3a 100644
--- a/package/source/xstor/xstorage.hxx
+++ b/package/source/xstor/xstorage.hxx
@@ -29,14 +29,14 @@
#define __XSTORAGE_HXX_
#include <com/sun/star/uno/Sequence.hxx>
-#include <com/sun/star/embed/XStorage.hpp>
+#include <com/sun/star/embed/XStorage2.hpp>
#include <com/sun/star/embed/XOptimizedStorage.hpp>
-#include <com/sun/star/embed/XHierarchicalStorageAccess.hpp>
+#include <com/sun/star/embed/XHierarchicalStorageAccess2.hpp>
#include <com/sun/star/embed/XStorageRawAccess.hpp>
#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/XEncryptionProtectedSource.hpp>
+#include <com/sun/star/embed/XEncryptionProtectedSource2.hpp>
#include <com/sun/star/embed/XRelationshipAccess.hpp>
#include <com/sun/star/util/XModifiable.hpp>
#include <com/sun/star/container/XNameAccess.hpp>
@@ -52,8 +52,10 @@
#include <com/sun/star/lang/XComponent.hpp>
#include <com/sun/star/packages/NoEncryptionException.hpp>
#include <com/sun/star/logging/XSimpleLogRing.hpp>
+
#include <cppuhelper/weak.hxx>
#include <cppuhelper/interfacecontainer.h>
+#include <comphelper/sequenceashashmap.hxx>
#include "mutexholder.hxx"
@@ -157,8 +159,8 @@ struct OStorage_Impl
::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > m_xInputStream; // ??? may be stored in properties
::com::sun::star::uno::Reference< ::com::sun::star::io::XStream > m_xStream; // ??? may be stored in properties
::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > m_xProperties;
- sal_Bool m_bHasCommonPassword;
- ::rtl::OUString m_aCommonPassword;
+ sal_Bool m_bHasCommonEncryptionData;
+ ::comphelper::SequenceAsHashMap m_aCommonEncryptionData;
// must be empty in case of root storage
OStorage_Impl* m_pParent;
@@ -231,7 +233,7 @@ struct OStorage_Impl
void Commit();
void Revert();
- ::rtl::OUString GetCommonRootPass() throw ( ::com::sun::star::packages::NoEncryptionException );
+ ::comphelper::SequenceAsHashMap GetCommonRootEncryptionData() throw ( ::com::sun::star::packages::NoEncryptionException );
void CopyToStorage( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xDest,
sal_Bool bDirect );
@@ -264,7 +266,7 @@ struct OStorage_Impl
void CloneStreamElement(
const ::rtl::OUString& aStreamName,
sal_Bool bPassProvided,
- const ::rtl::OUString& aPass,
+ const ::comphelper::SequenceAsHashMap& aEncryptionData,
::com::sun::star::uno::Reference< ::com::sun::star::io::XStream >& xTargetStream )
throw ( ::com::sun::star::embed::InvalidStorageException,
::com::sun::star::lang::IllegalArgumentException,
@@ -289,18 +291,18 @@ struct OStorage_Impl
class OStorage : public ::com::sun::star::lang::XTypeProvider
- , public ::com::sun::star::embed::XStorage
+ , public ::com::sun::star::embed::XStorage2
, public ::com::sun::star::embed::XStorageRawAccess
, public ::com::sun::star::embed::XTransactedObject
, public ::com::sun::star::embed::XTransactionBroadcaster
, public ::com::sun::star::util::XModifiable
// , public ::com::sun::star::container::XNameAccess
// , public ::com::sun::star::lang::XComponent
- , public ::com::sun::star::embed::XEncryptionProtectedSource
+ , public ::com::sun::star::embed::XEncryptionProtectedSource2
, public ::com::sun::star::beans::XPropertySet
, public ::com::sun::star::embed::XOptimizedStorage
, public ::com::sun::star::embed::XRelationshipAccess
- , public ::com::sun::star::embed::XHierarchicalStorageAccess
+ , public ::com::sun::star::embed::XHierarchicalStorageAccess2
, public ::cppu::OWeakObject
{
OStorage_Impl* m_pImpl;
@@ -490,6 +492,28 @@ public:
::com::sun::star::uno::RuntimeException );
//____________________________________________________________________________________________________
+ // XStorage2
+ //____________________________________________________________________________________________________
+
+ virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream > SAL_CALL openEncryptedStream( const ::rtl::OUString& sStreamName, ::sal_Int32 nOpenMode, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& aEncryptionData )
+ throw ( ::com::sun::star::embed::InvalidStorageException,
+ ::com::sun::star::lang::IllegalArgumentException,
+ ::com::sun::star::packages::NoEncryptionException,
+ ::com::sun::star::packages::WrongPasswordException,
+ ::com::sun::star::io::IOException,
+ ::com::sun::star::embed::StorageWrappedTargetException,
+ ::com::sun::star::uno::RuntimeException);
+
+ virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream > SAL_CALL cloneEncryptedStream( const ::rtl::OUString& sStreamName, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& aEncryptionData )
+ throw ( ::com::sun::star::embed::InvalidStorageException,
+ ::com::sun::star::lang::IllegalArgumentException,
+ ::com::sun::star::packages::NoEncryptionException,
+ ::com::sun::star::packages::WrongPasswordException,
+ ::com::sun::star::io::IOException,
+ ::com::sun::star::embed::StorageWrappedTargetException,
+ ::com::sun::star::uno::RuntimeException);
+
+ //____________________________________________________________________________________________________
// XStorageRawAccess
//____________________________________________________________________________________________________
@@ -616,6 +640,16 @@ public:
::com::sun::star::io::IOException );
//____________________________________________________________________________________________________
+ // XEncryptionProtectedSource2
+ //____________________________________________________________________________________________________
+
+ virtual void SAL_CALL setEncryptionData(
+ const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& aEncryptionData )
+ throw ( ::com::sun::star::io::IOException,
+ ::com::sun::star::uno::RuntimeException );
+
+
+ //____________________________________________________________________________________________________
// XPropertySet
//____________________________________________________________________________________________________
@@ -800,6 +834,18 @@ public:
::com::sun::star::embed::StorageWrappedTargetException,
::com::sun::star::uno::RuntimeException);
+ //____________________________________________________________________________________________________
+ // XHierarchicalStorageAccess2
+ //____________________________________________________________________________________________________
+
+ virtual ::com::sun::star::uno::Reference< ::com::sun::star::embed::XExtendedStorageStream > SAL_CALL openEncryptedStreamByHierarchicalName( const ::rtl::OUString& sStreamName, ::sal_Int32 nOpenMode, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& aEncryptionData )
+ throw ( ::com::sun::star::embed::InvalidStorageException,
+ ::com::sun::star::lang::IllegalArgumentException,
+ ::com::sun::star::packages::NoEncryptionException,
+ ::com::sun::star::packages::WrongPasswordException,
+ ::com::sun::star::io::IOException,
+ ::com::sun::star::embed::StorageWrappedTargetException,
+ ::com::sun::star::uno::RuntimeException );
};
diff --git a/package/source/zippackage/ZipPackage.cxx b/package/source/zippackage/ZipPackage.cxx
index 9ba26e0100c5..846ba7710298 100644
--- a/package/source/zippackage/ZipPackage.cxx
+++ b/package/source/zippackage/ZipPackage.cxx
@@ -1650,7 +1650,7 @@ void SAL_CALL ZipPackage::setPropertyValue( const OUString& aPropertyName, const
throw PropertyVetoException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
else if (aPropertyName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("EncryptionKey") ) )
{
- if (!( aValue >>= m_aEncryptionKey ) )
+ if (!( aValue >>= m_aEncryptionKey ) || m_aEncryptionKey.getLength() == 0 )
throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 2 );
}
else if (aPropertyName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("UseManifest") ) )