|
|
|
@ -49,8 +49,8 @@
|
|
|
|
|
using namespace com::sun::star;
|
|
|
|
|
using namespace com::sun::star::packages::zip::ZipConstants;
|
|
|
|
|
using namespace com::sun::star::packages::zip;
|
|
|
|
|
using namespace com::sun::star::container;
|
|
|
|
|
using namespace com::sun::star::packages;
|
|
|
|
|
using namespace com::sun::star::container;
|
|
|
|
|
using namespace com::sun::star::beans;
|
|
|
|
|
using namespace com::sun::star::lang;
|
|
|
|
|
using namespace com::sun::star::io;
|
|
|
|
@ -304,84 +304,43 @@ static void ImplSetStoredData( ZipEntry & rEntry, uno::Reference< XInputStream>
|
|
|
|
|
rEntry.nCrc = aCRC32.getValue();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ZipPackageFolder::saveContents( ::rtl::OUString &rPath, std::vector < uno::Sequence < PropertyValue > > &rManList, ZipOutputStream & rZipOut, const uno::Sequence < sal_Int8 >&rEncryptionKey, rtlRandomPool &rRandomPool)
|
|
|
|
|
throw(uno::RuntimeException)
|
|
|
|
|
bool ZipPackageFolder::saveChild( const OUString &rShortName, const ContentInfo &rInfo, OUString &rPath, std::vector < Sequence < PropertyValue > > &rManList, ZipOutputStream & rZipOut, Sequence < sal_Int8 > &rEncryptionKey, rtlRandomPool &rRandomPool)
|
|
|
|
|
{
|
|
|
|
|
sal_Bool bWritingFailed = sal_False;
|
|
|
|
|
ZipPackageFolder *pFolder = NULL;
|
|
|
|
|
ZipPackageStream *pStream = NULL;
|
|
|
|
|
const ::rtl::OUString sMediaTypeProperty ( RTL_CONSTASCII_USTRINGPARAM ( "MediaType" ) );
|
|
|
|
|
const ::rtl::OUString sVersionProperty ( RTL_CONSTASCII_USTRINGPARAM ( "Version" ) );
|
|
|
|
|
const ::rtl::OUString sFullPathProperty ( RTL_CONSTASCII_USTRINGPARAM ( "FullPath" ) );
|
|
|
|
|
const ::rtl::OUString sInitialisationVectorProperty ( RTL_CONSTASCII_USTRINGPARAM ( "InitialisationVector" ) );
|
|
|
|
|
const ::rtl::OUString sSaltProperty ( RTL_CONSTASCII_USTRINGPARAM ( "Salt" ) );
|
|
|
|
|
const ::rtl::OUString sIterationCountProperty ( RTL_CONSTASCII_USTRINGPARAM ( "IterationCount" ) );
|
|
|
|
|
const ::rtl::OUString sSizeProperty ( RTL_CONSTASCII_USTRINGPARAM ( "Size" ) );
|
|
|
|
|
const ::rtl::OUString sDigestProperty ( RTL_CONSTASCII_USTRINGPARAM ( "Digest" ) );
|
|
|
|
|
bool bSuccess = true;
|
|
|
|
|
|
|
|
|
|
const OUString sMediaTypeProperty ( RTL_CONSTASCII_USTRINGPARAM ( "MediaType" ) );
|
|
|
|
|
const OUString sVersionProperty ( RTL_CONSTASCII_USTRINGPARAM ( "Version" ) );
|
|
|
|
|
const OUString sFullPathProperty ( RTL_CONSTASCII_USTRINGPARAM ( "FullPath" ) );
|
|
|
|
|
const OUString sInitialisationVectorProperty ( RTL_CONSTASCII_USTRINGPARAM ( "InitialisationVector" ) );
|
|
|
|
|
const OUString sSaltProperty ( RTL_CONSTASCII_USTRINGPARAM ( "Salt" ) );
|
|
|
|
|
const OUString sIterationCountProperty ( RTL_CONSTASCII_USTRINGPARAM ( "IterationCount" ) );
|
|
|
|
|
const OUString sSizeProperty ( RTL_CONSTASCII_USTRINGPARAM ( "Size" ) );
|
|
|
|
|
const OUString sDigestProperty ( RTL_CONSTASCII_USTRINGPARAM ( "Digest" ) );
|
|
|
|
|
const ::rtl::OUString sEncryptionAlgProperty ( RTL_CONSTASCII_USTRINGPARAM ( "EncryptionAlgorithm" ) );
|
|
|
|
|
const ::rtl::OUString sStartKeyAlgProperty ( RTL_CONSTASCII_USTRINGPARAM ( "StartKeyAlgorithm" ) );
|
|
|
|
|
const ::rtl::OUString sDigestAlgProperty ( RTL_CONSTASCII_USTRINGPARAM ( "DigestAlgorithm" ) );
|
|
|
|
|
const ::rtl::OUString sDerivedKeySizeProperty ( RTL_CONSTASCII_USTRINGPARAM ( "DerivedKeySize" ) );
|
|
|
|
|
|
|
|
|
|
sal_Bool bHaveEncryptionKey = rEncryptionKey.getLength() ? sal_True : sal_False;
|
|
|
|
|
|
|
|
|
|
if ( maContents.begin() == maContents.end() && rPath.getLength() && m_nFormat != embed::StorageFormats::OFOPXML )
|
|
|
|
|
{
|
|
|
|
|
// it is an empty subfolder, use workaround to store it
|
|
|
|
|
ZipEntry* pTempEntry = new ZipEntry();
|
|
|
|
|
ZipPackageFolder::copyZipEntry ( *pTempEntry, aEntry );
|
|
|
|
|
pTempEntry->nPathLen = (sal_Int16)( ::rtl::OUStringToOString( rPath, RTL_TEXTENCODING_UTF8 ).getLength() );
|
|
|
|
|
pTempEntry->nExtraLen = -1;
|
|
|
|
|
pTempEntry->sPath = rPath;
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
rZipOut.putNextEntry( *pTempEntry, NULL, sal_False );
|
|
|
|
|
rZipOut.rawCloseEntry();
|
|
|
|
|
}
|
|
|
|
|
catch ( ZipException& )
|
|
|
|
|
{
|
|
|
|
|
VOS_ENSURE( 0, "Error writing ZipOutputStream" );
|
|
|
|
|
bWritingFailed = sal_True;
|
|
|
|
|
}
|
|
|
|
|
catch ( IOException& )
|
|
|
|
|
{
|
|
|
|
|
VOS_ENSURE( 0, "Error writing ZipOutputStream" );
|
|
|
|
|
bWritingFailed = sal_True;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for ( ContentHash::const_iterator aCI = maContents.begin(), aEnd = maContents.end();
|
|
|
|
|
aCI != aEnd;
|
|
|
|
|
aCI++)
|
|
|
|
|
{
|
|
|
|
|
const ::rtl::OUString &rShortName = (*aCI).first;
|
|
|
|
|
const ContentInfo &rInfo = *(*aCI).second;
|
|
|
|
|
|
|
|
|
|
uno::Sequence < PropertyValue > aPropSet( PKG_SIZE_NOENCR_MNFST );
|
|
|
|
|
|
|
|
|
|
if ( rInfo.bFolder )
|
|
|
|
|
pFolder = rInfo.pFolder;
|
|
|
|
|
else
|
|
|
|
|
pStream = rInfo.pStream;
|
|
|
|
|
Sequence < PropertyValue > aPropSet (PKG_SIZE_NOENCR_MNFST);
|
|
|
|
|
|
|
|
|
|
OSL_ENSURE( ( rInfo.bFolder && rInfo.pFolder ) || ( !rInfo.bFolder && rInfo.pStream ), "A valid child object is expected!" );
|
|
|
|
|
if ( rInfo.bFolder )
|
|
|
|
|
{
|
|
|
|
|
::rtl::OUString sTempName = rPath + rShortName + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "/" ) );
|
|
|
|
|
OUString sTempName = rPath + rShortName + OUString( RTL_CONSTASCII_USTRINGPARAM ( "/" ) );
|
|
|
|
|
|
|
|
|
|
if ( pFolder->GetMediaType().getLength() )
|
|
|
|
|
if ( rInfo.pFolder->GetMediaType().getLength() )
|
|
|
|
|
{
|
|
|
|
|
aPropSet[PKG_MNFST_MEDIATYPE].Name = sMediaTypeProperty;
|
|
|
|
|
aPropSet[PKG_MNFST_MEDIATYPE].Value <<= pFolder->GetMediaType();
|
|
|
|
|
aPropSet[PKG_MNFST_MEDIATYPE].Value <<= rInfo.pFolder->GetMediaType();
|
|
|
|
|
aPropSet[PKG_MNFST_VERSION].Name = sVersionProperty;
|
|
|
|
|
aPropSet[PKG_MNFST_VERSION].Value <<= pFolder->GetVersion();
|
|
|
|
|
aPropSet[PKG_MNFST_VERSION].Value <<= rInfo.pFolder->GetVersion();
|
|
|
|
|
aPropSet[PKG_MNFST_FULLPATH].Name = sFullPathProperty;
|
|
|
|
|
aPropSet[PKG_MNFST_FULLPATH].Value <<= sTempName;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
aPropSet.realloc( 0 );
|
|
|
|
|
|
|
|
|
|
pFolder->saveContents( sTempName, rManList, rZipOut, rEncryptionKey, rRandomPool);
|
|
|
|
|
rInfo.pFolder->saveContents( sTempName, rManList, rZipOut, rEncryptionKey, rRandomPool);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
@ -393,60 +352,60 @@ void ZipPackageFolder::saveContents( ::rtl::OUString &rPath, std::vector < uno::
|
|
|
|
|
// In case the entry we are reading is also the entry we are writing, we will
|
|
|
|
|
// store the ZipEntry data in pTempEntry
|
|
|
|
|
|
|
|
|
|
ZipPackageFolder::copyZipEntry ( *pTempEntry, pStream->aEntry );
|
|
|
|
|
ZipPackageFolder::copyZipEntry ( *pTempEntry, rInfo.pStream->aEntry );
|
|
|
|
|
pTempEntry->sPath = rPath + rShortName;
|
|
|
|
|
pTempEntry->nPathLen = (sal_Int16)( ::rtl::OUStringToOString( pTempEntry->sPath, RTL_TEXTENCODING_UTF8 ).getLength() );
|
|
|
|
|
|
|
|
|
|
sal_Bool bToBeEncrypted = pStream->IsToBeEncrypted() && (bHaveEncryptionKey || pStream->HasOwnKey());
|
|
|
|
|
sal_Bool bToBeCompressed = bToBeEncrypted ? sal_True : pStream->IsToBeCompressed();
|
|
|
|
|
sal_Bool bToBeEncrypted = rInfo.pStream->IsToBeEncrypted() && (rEncryptionKey.getLength() || rInfo.pStream->HasOwnKey());
|
|
|
|
|
sal_Bool bToBeCompressed = bToBeEncrypted ? sal_True : rInfo.pStream->IsToBeCompressed();
|
|
|
|
|
|
|
|
|
|
aPropSet[PKG_MNFST_MEDIATYPE].Name = sMediaTypeProperty;
|
|
|
|
|
aPropSet[PKG_MNFST_MEDIATYPE].Value <<= pStream->GetMediaType( );
|
|
|
|
|
aPropSet[PKG_MNFST_MEDIATYPE].Value <<= rInfo.pStream->GetMediaType( );
|
|
|
|
|
aPropSet[PKG_MNFST_VERSION].Name = sVersionProperty;
|
|
|
|
|
aPropSet[PKG_MNFST_VERSION].Value <<= ::rtl::OUString(); // no version is stored for streams currently
|
|
|
|
|
aPropSet[PKG_MNFST_FULLPATH].Name = sFullPathProperty;
|
|
|
|
|
aPropSet[PKG_MNFST_FULLPATH].Value <<= pTempEntry->sPath;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
OSL_ENSURE( pStream->GetStreamMode() != PACKAGE_STREAM_NOTSET, "Unacceptable ZipPackageStream mode!" );
|
|
|
|
|
OSL_ENSURE( rInfo.pStream->GetStreamMode() != PACKAGE_STREAM_NOTSET, "Unacceptable ZipPackageStream mode!" );
|
|
|
|
|
|
|
|
|
|
sal_Bool bRawStream = sal_False;
|
|
|
|
|
if ( pStream->GetStreamMode() == PACKAGE_STREAM_DETECT )
|
|
|
|
|
bRawStream = pStream->ParsePackageRawStream();
|
|
|
|
|
else if ( pStream->GetStreamMode() == PACKAGE_STREAM_RAW )
|
|
|
|
|
if ( rInfo.pStream->GetStreamMode() == PACKAGE_STREAM_DETECT )
|
|
|
|
|
bRawStream = rInfo.pStream->ParsePackageRawStream();
|
|
|
|
|
else if ( rInfo.pStream->GetStreamMode() == PACKAGE_STREAM_RAW )
|
|
|
|
|
bRawStream = sal_True;
|
|
|
|
|
|
|
|
|
|
sal_Bool bTransportOwnEncrStreamAsRaw = sal_False;
|
|
|
|
|
// During the storing the original size of the stream can be changed
|
|
|
|
|
// TODO/LATER: get rid of this hack
|
|
|
|
|
sal_Int32 nOwnStreamOrigSize = bRawStream ? pStream->GetMagicalHackSize() : pStream->getSize();
|
|
|
|
|
sal_Int32 nOwnStreamOrigSize = bRawStream ? rInfo.pStream->GetMagicalHackSize() : rInfo.pStream->getSize();
|
|
|
|
|
|
|
|
|
|
sal_Bool bUseNonSeekableAccess = sal_False;
|
|
|
|
|
uno::Reference < XInputStream > xStream;
|
|
|
|
|
if ( !pStream->IsPackageMember() && !bRawStream && !bToBeEncrypted && bToBeCompressed )
|
|
|
|
|
Reference < XInputStream > xStream;
|
|
|
|
|
if ( !rInfo.pStream->IsPackageMember() && !bRawStream && !bToBeEncrypted && bToBeCompressed )
|
|
|
|
|
{
|
|
|
|
|
// the stream is not a package member, not a raw stream,
|
|
|
|
|
// it should not be encrypted and it should be compressed,
|
|
|
|
|
// in this case nonseekable access can be used
|
|
|
|
|
|
|
|
|
|
xStream = pStream->GetOwnStreamNoWrap();
|
|
|
|
|
uno::Reference < XSeekable > xSeek ( xStream, uno::UNO_QUERY );
|
|
|
|
|
xStream = rInfo.pStream->GetOwnStreamNoWrap();
|
|
|
|
|
Reference < XSeekable > xSeek ( xStream, UNO_QUERY );
|
|
|
|
|
|
|
|
|
|
bUseNonSeekableAccess = ( xStream.is() && !xSeek.is() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( !bUseNonSeekableAccess )
|
|
|
|
|
{
|
|
|
|
|
xStream = pStream->getRawData();
|
|
|
|
|
xStream = rInfo.pStream->getRawData();
|
|
|
|
|
|
|
|
|
|
if ( !xStream.is() )
|
|
|
|
|
{
|
|
|
|
|
VOS_ENSURE( 0, "ZipPackageStream didn't have a stream associated with it, skipping!" );
|
|
|
|
|
bWritingFailed = sal_True;
|
|
|
|
|
continue;
|
|
|
|
|
bSuccess = false;
|
|
|
|
|
return bSuccess;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uno::Reference < XSeekable > xSeek ( xStream, uno::UNO_QUERY );
|
|
|
|
|
Reference < XSeekable > xSeek ( xStream, UNO_QUERY );
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if ( xSeek.is() )
|
|
|
|
@ -457,7 +416,7 @@ void ZipPackageFolder::saveContents( ::rtl::OUString &rPath, std::vector < uno::
|
|
|
|
|
{
|
|
|
|
|
// The raw stream can neither be encrypted nor connected
|
|
|
|
|
OSL_ENSURE( !bRawStream || !bToBeCompressed && !bToBeEncrypted, "The stream is already encrypted!\n" );
|
|
|
|
|
xSeek->seek ( bRawStream ? pStream->GetMagicalHackPos() : 0 );
|
|
|
|
|
xSeek->seek ( bRawStream ? rInfo.pStream->GetMagicalHackPos() : 0 );
|
|
|
|
|
ImplSetStoredData ( *pTempEntry, xStream );
|
|
|
|
|
|
|
|
|
|
// TODO/LATER: Get rid of hacks related to switching of Flag Method and Size properties!
|
|
|
|
@ -477,10 +436,10 @@ void ZipPackageFolder::saveContents( ::rtl::OUString &rPath, std::vector < uno::
|
|
|
|
|
// check if it's one of our own streams, if it is then we know that
|
|
|
|
|
// each time we ask for it we'll get a new stream that will be
|
|
|
|
|
// at position zero...otherwise, assert and skip this stream...
|
|
|
|
|
if ( pStream->IsPackageMember() )
|
|
|
|
|
if ( rInfo.pStream->IsPackageMember() )
|
|
|
|
|
{
|
|
|
|
|
// if the password has been changed than the stream should not be package member any more
|
|
|
|
|
if ( pStream->IsEncrypted() && pStream->IsToBeEncrypted() )
|
|
|
|
|
if ( rInfo.pStream->IsEncrypted() && rInfo.pStream->IsToBeEncrypted() )
|
|
|
|
|
{
|
|
|
|
|
// Should be handled close to the raw stream handling
|
|
|
|
|
bTransportOwnEncrStreamAsRaw = sal_True;
|
|
|
|
@ -495,45 +454,45 @@ void ZipPackageFolder::saveContents( ::rtl::OUString &rPath, std::vector < uno::
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
VOS_ENSURE( 0, "The package component requires that every stream either be FROM a package or it must support XSeekable!" );
|
|
|
|
|
continue;
|
|
|
|
|
bSuccess = false;
|
|
|
|
|
return bSuccess;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch ( uno::Exception& )
|
|
|
|
|
catch ( Exception& )
|
|
|
|
|
{
|
|
|
|
|
VOS_ENSURE( 0, "The stream provided to the package component has problems!" );
|
|
|
|
|
bWritingFailed = sal_True;
|
|
|
|
|
continue;
|
|
|
|
|
bSuccess = false;
|
|
|
|
|
return bSuccess;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( bToBeEncrypted || bRawStream || bTransportOwnEncrStreamAsRaw )
|
|
|
|
|
{
|
|
|
|
|
if ( bToBeEncrypted && !bTransportOwnEncrStreamAsRaw )
|
|
|
|
|
{
|
|
|
|
|
sal_Int32 nVectorLen = pStream->GetBlockSize();
|
|
|
|
|
uno::Sequence < sal_Int8 > aSalt ( 16 ), aVector ( nVectorLen );
|
|
|
|
|
Sequence < sal_uInt8 > aSalt ( 16 ), aVector ( 8 );
|
|
|
|
|
rtl_random_getBytes ( rRandomPool, aSalt.getArray(), 16 );
|
|
|
|
|
rtl_random_getBytes ( rRandomPool, aVector.getArray(), nVectorLen );
|
|
|
|
|
rtl_random_getBytes ( rRandomPool, aVector.getArray(), 8 );
|
|
|
|
|
sal_Int32 nIterationCount = 1024;
|
|
|
|
|
|
|
|
|
|
if ( !pStream->HasOwnKey() )
|
|
|
|
|
pStream->setKey ( rEncryptionKey );
|
|
|
|
|
if ( !rInfo.pStream->HasOwnKey() )
|
|
|
|
|
rInfo.pStream->setKey ( rEncryptionKey );
|
|
|
|
|
|
|
|
|
|
pStream->setInitialisationVector ( aVector );
|
|
|
|
|
pStream->setSalt ( aSalt );
|
|
|
|
|
pStream->setIterationCount ( nIterationCount );
|
|
|
|
|
rInfo.pStream->setInitialisationVector ( aVector );
|
|
|
|
|
rInfo.pStream->setSalt ( aSalt );
|
|
|
|
|
rInfo.pStream->setIterationCount ( nIterationCount );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// last property is digest, which is inserted later if we didn't have
|
|
|
|
|
// a magic header
|
|
|
|
|
aPropSet.realloc( PKG_SIZE_ENCR_MNFST );
|
|
|
|
|
aPropSet.realloc(PKG_SIZE_ENCR_MNFST);
|
|
|
|
|
|
|
|
|
|
aPropSet[PKG_MNFST_INIVECTOR].Name = sInitialisationVectorProperty;
|
|
|
|
|
aPropSet[PKG_MNFST_INIVECTOR].Value <<= pStream->getInitialisationVector();
|
|
|
|
|
aPropSet[PKG_MNFST_INIVECTOR].Value <<= rInfo.pStream->getInitialisationVector();
|
|
|
|
|
aPropSet[PKG_MNFST_SALT].Name = sSaltProperty;
|
|
|
|
|
aPropSet[PKG_MNFST_SALT].Value <<= pStream->getSalt();
|
|
|
|
|
aPropSet[PKG_MNFST_SALT].Value <<= rInfo.pStream->getSalt();
|
|
|
|
|
aPropSet[PKG_MNFST_ITERATION].Name = sIterationCountProperty;
|
|
|
|
|
aPropSet[PKG_MNFST_ITERATION].Value <<= pStream->getIterationCount ();
|
|
|
|
|
aPropSet[PKG_MNFST_ITERATION].Value <<= rInfo.pStream->getIterationCount ();
|
|
|
|
|
|
|
|
|
|
// Need to store the uncompressed size in the manifest
|
|
|
|
|
OSL_ENSURE( nOwnStreamOrigSize >= 0, "The stream size was not correctly initialized!\n" );
|
|
|
|
@ -541,12 +500,9 @@ void ZipPackageFolder::saveContents( ::rtl::OUString &rPath, std::vector < uno::
|
|
|
|
|
aPropSet[PKG_MNFST_UCOMPSIZE].Value <<= nOwnStreamOrigSize;
|
|
|
|
|
|
|
|
|
|
if ( bRawStream || bTransportOwnEncrStreamAsRaw )
|
|
|
|
|
{
|
|
|
|
|
::rtl::Reference< EncryptionData > xEncData = pStream->GetEncryptionData();
|
|
|
|
|
if ( xEncData.is() )
|
|
|
|
|
{
|
|
|
|
|
aPropSet[PKG_MNFST_DIGEST].Name = sDigestProperty;
|
|
|
|
|
aPropSet[PKG_MNFST_DIGEST].Value <<= xEncData->m_aDigest;
|
|
|
|
|
aPropSet[PKG_MNFST_DIGEST].Value <<= rInfo.pStream->getDigest();
|
|
|
|
|
aPropSet[PKG_MNFST_ENCALG].Name = sEncryptionAlgProperty;
|
|
|
|
|
aPropSet[PKG_MNFST_ENCALG].Value <<= xEncData->m_nEncAlg;
|
|
|
|
|
aPropSet[PKG_MNFST_STARTALG].Name = sStartKeyAlgProperty;
|
|
|
|
@ -558,39 +514,39 @@ void ZipPackageFolder::saveContents( ::rtl::OUString &rPath, std::vector < uno::
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If the entry is already stored in the zip file in the format we
|
|
|
|
|
// want for this write...copy it raw
|
|
|
|
|
if ( !bUseNonSeekableAccess
|
|
|
|
|
&& ( bRawStream || bTransportOwnEncrStreamAsRaw
|
|
|
|
|
|| ( pStream->IsPackageMember() && !bToBeEncrypted
|
|
|
|
|
&& ( ( pStream->aEntry.nMethod == DEFLATED && bToBeCompressed )
|
|
|
|
|
|| ( pStream->aEntry.nMethod == STORED && !bToBeCompressed ) ) ) ) )
|
|
|
|
|
|| ( rInfo.pStream->IsPackageMember() && !bToBeEncrypted
|
|
|
|
|
&& ( ( rInfo.pStream->aEntry.nMethod == DEFLATED && bToBeCompressed )
|
|
|
|
|
|| ( rInfo.pStream->aEntry.nMethod == STORED && !bToBeCompressed ) ) ) ) )
|
|
|
|
|
{
|
|
|
|
|
// If it's a PackageMember, then it's an unbuffered stream and we need
|
|
|
|
|
// to get a new version of it as we can't seek backwards.
|
|
|
|
|
if ( pStream->IsPackageMember() )
|
|
|
|
|
if ( rInfo.pStream->IsPackageMember() )
|
|
|
|
|
{
|
|
|
|
|
xStream = pStream->getRawData();
|
|
|
|
|
xStream = rInfo.pStream->getRawData();
|
|
|
|
|
if ( !xStream.is() )
|
|
|
|
|
{
|
|
|
|
|
// Make sure that we actually _got_ a new one !
|
|
|
|
|
VOS_ENSURE( 0, "ZipPackageStream didn't have a stream associated with it, skipping!" );
|
|
|
|
|
continue;
|
|
|
|
|
bSuccess = false;
|
|
|
|
|
return bSuccess;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if ( bRawStream )
|
|
|
|
|
xStream->skipBytes( pStream->GetMagicalHackPos() );
|
|
|
|
|
xStream->skipBytes( rInfo.pStream->GetMagicalHackPos() );
|
|
|
|
|
|
|
|
|
|
rZipOut.putNextEntry( *pTempEntry, pStream, sal_False );
|
|
|
|
|
rZipOut.putNextEntry ( *pTempEntry, rInfo.pStream, sal_False );
|
|
|
|
|
// the entry is provided to the ZipOutputStream that will delete it
|
|
|
|
|
pAutoTempEntry.release();
|
|
|
|
|
|
|
|
|
|
uno::Sequence < sal_Int8 > aSeq ( n_ConstBufferSize );
|
|
|
|
|
Sequence < sal_Int8 > aSeq ( n_ConstBufferSize );
|
|
|
|
|
sal_Int32 nLength;
|
|
|
|
|
|
|
|
|
|
do
|
|
|
|
@ -605,12 +561,12 @@ void ZipPackageFolder::saveContents( ::rtl::OUString &rPath, std::vector < uno::
|
|
|
|
|
catch ( ZipException& )
|
|
|
|
|
{
|
|
|
|
|
VOS_ENSURE( 0, "Error writing ZipOutputStream" );
|
|
|
|
|
bWritingFailed = sal_True;
|
|
|
|
|
bSuccess = false;
|
|
|
|
|
}
|
|
|
|
|
catch ( IOException& )
|
|
|
|
|
{
|
|
|
|
|
VOS_ENSURE( 0, "Error writing ZipOutputStream" );
|
|
|
|
|
bWritingFailed = sal_True;
|
|
|
|
|
bSuccess = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
@ -625,14 +581,15 @@ void ZipPackageFolder::saveContents( ::rtl::OUString &rPath, std::vector < uno::
|
|
|
|
|
// If it's a PackageMember, then our previous reference held a 'raw' stream
|
|
|
|
|
// so we need to re-get it, unencrypted, uncompressed and positioned at the
|
|
|
|
|
// beginning of the stream
|
|
|
|
|
if ( pStream->IsPackageMember() )
|
|
|
|
|
if ( rInfo.pStream->IsPackageMember() )
|
|
|
|
|
{
|
|
|
|
|
xStream = pStream->getInputStream();
|
|
|
|
|
xStream = rInfo.pStream->getInputStream();
|
|
|
|
|
if ( !xStream.is() )
|
|
|
|
|
{
|
|
|
|
|
// Make sure that we actually _got_ a new one !
|
|
|
|
|
VOS_ENSURE( 0, "ZipPackageStream didn't have a stream associated with it, skipping!" );
|
|
|
|
|
continue;
|
|
|
|
|
bSuccess = false;
|
|
|
|
|
return bSuccess;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -644,12 +601,12 @@ void ZipPackageFolder::saveContents( ::rtl::OUString &rPath, std::vector < uno::
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
rZipOut.putNextEntry ( *pTempEntry, pStream, bToBeEncrypted);
|
|
|
|
|
rZipOut.putNextEntry ( *pTempEntry, rInfo.pStream, bToBeEncrypted);
|
|
|
|
|
// the entry is provided to the ZipOutputStream that will delete it
|
|
|
|
|
pAutoTempEntry.release();
|
|
|
|
|
|
|
|
|
|
sal_Int32 nLength;
|
|
|
|
|
uno::Sequence < sal_Int8 > aSeq (n_ConstBufferSize);
|
|
|
|
|
Sequence < sal_Int8 > aSeq (n_ConstBufferSize);
|
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
nLength = xStream->readBytes(aSeq, n_ConstBufferSize);
|
|
|
|
@ -661,20 +618,19 @@ void ZipPackageFolder::saveContents( ::rtl::OUString &rPath, std::vector < uno::
|
|
|
|
|
}
|
|
|
|
|
catch ( ZipException& )
|
|
|
|
|
{
|
|
|
|
|
bWritingFailed = sal_True;
|
|
|
|
|
VOS_ENSURE( 0, "Error writing ZipOutputStream" );
|
|
|
|
|
bSuccess = false;
|
|
|
|
|
}
|
|
|
|
|
catch ( IOException& )
|
|
|
|
|
{
|
|
|
|
|
bWritingFailed = sal_True;
|
|
|
|
|
VOS_ENSURE( 0, "Error writing ZipOutputStream" );
|
|
|
|
|
bSuccess = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( bToBeEncrypted )
|
|
|
|
|
{
|
|
|
|
|
::rtl::Reference< EncryptionData > xEncData = pStream->GetEncryptionData();
|
|
|
|
|
if ( xEncData.is() )
|
|
|
|
|
{
|
|
|
|
|
aPropSet[PKG_MNFST_DIGEST].Name = sDigestProperty;
|
|
|
|
|
aPropSet[PKG_MNFST_DIGEST].Value <<= xEncData->m_aDigest;
|
|
|
|
|
aPropSet[PKG_MNFST_DIGEST].Value <<= rInfo.pStream->getDigest();
|
|
|
|
|
aPropSet[PKG_MNFST_ENCALG].Name = sEncryptionAlgProperty;
|
|
|
|
|
aPropSet[PKG_MNFST_ENCALG].Value <<= xEncData->m_nEncAlg;
|
|
|
|
|
aPropSet[PKG_MNFST_STARTALG].Name = sStartKeyAlgProperty;
|
|
|
|
@ -684,24 +640,23 @@ void ZipPackageFolder::saveContents( ::rtl::OUString &rPath, std::vector < uno::
|
|
|
|
|
aPropSet[PKG_MNFST_DERKEYSIZE].Name = sDerivedKeySizeProperty;
|
|
|
|
|
aPropSet[PKG_MNFST_DERKEYSIZE].Value <<= xEncData->m_nDerivedKeySize;
|
|
|
|
|
|
|
|
|
|
pStream->SetIsEncrypted ( sal_True );
|
|
|
|
|
}
|
|
|
|
|
rInfo.pStream->SetIsEncrypted ( sal_True );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if( !bWritingFailed )
|
|
|
|
|
if( bSuccess )
|
|
|
|
|
{
|
|
|
|
|
if ( !pStream->IsPackageMember() )
|
|
|
|
|
if ( !rInfo.pStream->IsPackageMember() )
|
|
|
|
|
{
|
|
|
|
|
pStream->CloseOwnStreamIfAny();
|
|
|
|
|
pStream->SetPackageMember ( sal_True );
|
|
|
|
|
rInfo.pStream->CloseOwnStreamIfAny();
|
|
|
|
|
rInfo.pStream->SetPackageMember ( sal_True );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( bRawStream )
|
|
|
|
|
{
|
|
|
|
|
// the raw stream was integrated and now behaves
|
|
|
|
|
// as usual encrypted stream
|
|
|
|
|
pStream->SetToBeEncrypted( sal_True );
|
|
|
|
|
rInfo.pStream->SetToBeEncrypted( sal_True );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Remove hacky bit from entry flags
|
|
|
|
@ -712,13 +667,13 @@ void ZipPackageFolder::saveContents( ::rtl::OUString &rPath, std::vector < uno::
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Then copy it back afterwards...
|
|
|
|
|
ZipPackageFolder::copyZipEntry ( pStream->aEntry, *pTempEntry );
|
|
|
|
|
ZipPackageFolder::copyZipEntry ( rInfo.pStream->aEntry, *pTempEntry );
|
|
|
|
|
|
|
|
|
|
// TODO/LATER: get rid of this hack ( the encrypted stream size property is changed during saving )
|
|
|
|
|
if ( pStream->IsEncrypted() )
|
|
|
|
|
pStream->setSize( nOwnStreamOrigSize );
|
|
|
|
|
if ( rInfo.pStream->IsEncrypted() )
|
|
|
|
|
rInfo.pStream->setSize( nOwnStreamOrigSize );
|
|
|
|
|
|
|
|
|
|
pStream->aEntry.nOffset *= -1;
|
|
|
|
|
rInfo.pStream->aEntry.nOffset *= -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -726,6 +681,63 @@ void ZipPackageFolder::saveContents( ::rtl::OUString &rPath, std::vector < uno::
|
|
|
|
|
if ( aPropSet.getLength()
|
|
|
|
|
&& ( m_nFormat == embed::StorageFormats::PACKAGE || ( m_nFormat == embed::StorageFormats::OFOPXML && !rInfo.bFolder ) ) )
|
|
|
|
|
rManList.push_back( aPropSet );
|
|
|
|
|
|
|
|
|
|
return bSuccess;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ZipPackageFolder::saveContents(OUString &rPath, std::vector < Sequence < PropertyValue > > &rManList, ZipOutputStream & rZipOut, Sequence < sal_Int8 > &rEncryptionKey, rtlRandomPool &rRandomPool)
|
|
|
|
|
throw(RuntimeException)
|
|
|
|
|
{
|
|
|
|
|
bool bWritingFailed = false;
|
|
|
|
|
|
|
|
|
|
if ( maContents.begin() == maContents.end() && rPath.getLength() && m_nFormat != embed::StorageFormats::OFOPXML )
|
|
|
|
|
{
|
|
|
|
|
// it is an empty subfolder, use workaround to store it
|
|
|
|
|
ZipEntry* pTempEntry = new ZipEntry();
|
|
|
|
|
ZipPackageFolder::copyZipEntry ( *pTempEntry, aEntry );
|
|
|
|
|
pTempEntry->nPathLen = (sal_Int16)( ::rtl::OUStringToOString( rPath, RTL_TEXTENCODING_UTF8 ).getLength() );
|
|
|
|
|
pTempEntry->nExtraLen = -1;
|
|
|
|
|
pTempEntry->sPath = rPath;
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
rZipOut.putNextEntry( *pTempEntry, NULL, sal_False );
|
|
|
|
|
rZipOut.rawCloseEntry();
|
|
|
|
|
}
|
|
|
|
|
catch ( ZipException& )
|
|
|
|
|
{
|
|
|
|
|
VOS_ENSURE( 0, "Error writing ZipOutputStream" );
|
|
|
|
|
bWritingFailed = true;
|
|
|
|
|
}
|
|
|
|
|
catch ( IOException& )
|
|
|
|
|
{
|
|
|
|
|
VOS_ENSURE( 0, "Error writing ZipOutputStream" );
|
|
|
|
|
bWritingFailed = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool bMimeTypeStreamStored = false;
|
|
|
|
|
::rtl::OUString aMimeTypeStreamName( RTL_CONSTASCII_USTRINGPARAM( "mimetype" ) );
|
|
|
|
|
if ( m_nFormat == embed::StorageFormats::ZIP && !rPath.getLength() )
|
|
|
|
|
{
|
|
|
|
|
// let the "mimtype" stream in root folder be stored as the first stream if it is zip format
|
|
|
|
|
ContentHash::iterator aIter = maContents.find ( aMimeTypeStreamName );
|
|
|
|
|
if ( aIter != maContents.end() && !(*aIter).second->bFolder )
|
|
|
|
|
{
|
|
|
|
|
bMimeTypeStreamStored = true;
|
|
|
|
|
bWritingFailed = !saveChild( (*aIter).first, *(*aIter).second, rPath, rManList, rZipOut, rEncryptionKey, rRandomPool );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for ( ContentHash::const_iterator aCI = maContents.begin(), aEnd = maContents.end();
|
|
|
|
|
aCI != aEnd;
|
|
|
|
|
aCI++)
|
|
|
|
|
{
|
|
|
|
|
const ::rtl::OUString &rShortName = (*aCI).first;
|
|
|
|
|
const ContentInfo &rInfo = *(*aCI).second;
|
|
|
|
|
|
|
|
|
|
if ( !bMimeTypeStreamStored || !rShortName.equals( aMimeTypeStreamName ) )
|
|
|
|
|
bWritingFailed = !saveChild( rShortName, rInfo, rPath, rManList, rZipOut, rEncryptionKey, rRandomPool );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if( bWritingFailed )
|
|
|
|
|