summaryrefslogtreecommitdiff
path: root/package/source/zipapi
diff options
context:
space:
mode:
Diffstat (limited to 'package/source/zipapi')
-rw-r--r--package/source/zipapi/EntryInputStream.cxx201
-rw-r--r--package/source/zipapi/EntryInputStream.hxx86
-rw-r--r--package/source/zipapi/MemoryByteGrabber.hxx2
-rw-r--r--package/source/zipapi/XFileStream.cxx227
-rw-r--r--package/source/zipapi/XFileStream.hxx96
-rw-r--r--package/source/zipapi/XMemoryStream.cxx52
-rw-r--r--package/source/zipapi/XUnbufferedStream.cxx100
-rw-r--r--package/source/zipapi/XUnbufferedStream.hxx19
-rw-r--r--package/source/zipapi/ZipFile.cxx519
-rw-r--r--package/source/zipapi/ZipOutputStream.cxx121
-rw-r--r--package/source/zipapi/blowfishcontext.cxx122
-rw-r--r--package/source/zipapi/blowfishcontext.hxx58
-rw-r--r--package/source/zipapi/makefile.mk2
-rw-r--r--package/source/zipapi/sha1context.cxx97
-rw-r--r--package/source/zipapi/sha1context.hxx (renamed from package/source/zipapi/XMemoryStream.hxx)35
15 files changed, 719 insertions, 1018 deletions
diff --git a/package/source/zipapi/EntryInputStream.cxx b/package/source/zipapi/EntryInputStream.cxx
deleted file mode 100644
index 671ef7381f9d..000000000000
--- a/package/source/zipapi/EntryInputStream.cxx
+++ /dev/null
@@ -1,201 +0,0 @@
-/*************************************************************************
- *
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * Copyright 2000, 2010 Oracle and/or its affiliates.
- *
- * OpenOffice.org - a multi-platform office productivity suite
- *
- * This file is part of OpenOffice.org.
- *
- * OpenOffice.org is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License version 3
- * only, as published by the Free Software Foundation.
- *
- * OpenOffice.org is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License version 3 for more details
- * (a copy is included in the LICENSE file that accompanied this code).
- *
- * You should have received a copy of the GNU Lesser General Public License
- * version 3 along with OpenOffice.org. If not, see
- * <http://www.openoffice.org/license.html>
- * for a copy of the LGPLv3 License.
- *
- ************************************************************************/
-
-// MARKER(update_precomp.py): autogen include statement, do not remove
-#include "precompiled_package.hxx"
-#include <EntryInputStream.hxx>
-#include <com/sun/star/packages/zip/ZipConstants.hpp>
-#include <rtl/cipher.h>
-#include <rtl/digest.h>
-#include <memory.h> // for memcpy
-
-using namespace rtl;
-using namespace com::sun::star;
-using namespace com::sun::star::uno;
-using namespace com::sun::star::packages::zip;
-using namespace com::sun::star::packages::zip::ZipConstants;
-
-/** Provides access to the compressed data in a zipfile.
- *
- * 04/12/00 - uncompresses the stream into memory and seeks on it 'in memory'
- * This and the ZipPackageBuffer used in the ZipOutputStream are memory hogs
- * and will hopefully be replaced eventually
- *
- * Acts on the same underlying XInputStream as both the full Zip File and other
- * EntryInputStreams, and thus must maintain its current position in the stream and
- * seek to it before performing any reads.
- */
-
-EntryInputStream::EntryInputStream( Reference < io::XInputStream > xNewInput,
- const ZipEntry & rNewEntry,
- const vos::ORef < EncryptionData > &xEncryptData,
- sal_Bool bGetRawStream)
-: xStream( xNewInput )
-, xSeek( xNewInput, UNO_QUERY )
-, aEntry (rNewEntry )
-, nCurrent( 0 )
-, bHaveInMemory ( sal_False )
-, aInflater( sal_True )
-, aBuffer( 0 )
-, xEncryptionData (xEncryptData)
-, bRawStream (bGetRawStream)
-{
- if (bGetRawStream)
- {
- nUncompressedSize = aEntry.nMethod == DEFLATED ? aEntry.nCompressedSize : aEntry.nSize;
- nEnd = aEntry.nOffset + nUncompressedSize;
- }
- else
- {
- nEnd = aEntry.nMethod == DEFLATED ? aEntry.nOffset + aEntry.nCompressedSize : aEntry.nOffset + aEntry.nSize;
- nUncompressedSize = aEntry.nSize;
- }
-}
-void EntryInputStream::readIntoMemory()
- throw(io::NotConnectedException, io::BufferSizeExceededException, io::IOException, RuntimeException)
-{
- if (!bHaveInMemory)
- {
- Sequence < sal_Int8 > aReadBuffer;
- xSeek->seek(aEntry.nOffset);
- sal_Int32 nSize = aEntry.nMethod == DEFLATED ? aEntry.nCompressedSize : aEntry.nSize;
-
- if (nSize <0)
- throw io::BufferSizeExceededException(::rtl::OUString(), *this);
-
- xStream->readBytes( aReadBuffer, nSize ); // Now it holds the raw stuff from disk
-
- if (xEncryptionData->aSalt.getLength())
- {
- // Have salt, will travel
- Sequence < sal_uInt8 > aDerivedKey (16);
- rtlCipherError aResult;
- Sequence < sal_Int8 > aDecryptBuffer;
-
- // Get the key
- rtl_digest_PBKDF2 ( aDerivedKey.getArray(), 16,
- reinterpret_cast < const sal_uInt8 * > (xEncryptionData->aKey.getConstArray()),
- xEncryptionData->aKey.getLength(),
- xEncryptionData->aSalt.getConstArray(),
- xEncryptionData->aSalt.getLength(),
- xEncryptionData->nIterationCount );
-
- rtlCipher aCipher = rtl_cipher_create (rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeStream);
- aResult = rtl_cipher_init( aCipher, rtl_Cipher_DirectionDecode,
- aDerivedKey.getConstArray(),
- aDerivedKey.getLength(),
- xEncryptionData->aInitVector.getConstArray(),
- xEncryptionData->aInitVector.getLength());
- OSL_ASSERT (aResult == rtl_Cipher_E_None);
- aDecryptBuffer.realloc ( nSize );
- aResult = rtl_cipher_decode ( aCipher,
- aReadBuffer.getConstArray(),
- nSize,
- reinterpret_cast < sal_uInt8 * > (aDecryptBuffer.getArray()),
- nSize);
- OSL_ASSERT (aResult == rtl_Cipher_E_None);
- aReadBuffer = aDecryptBuffer; // Now it holds the decrypted data
- }
- if (bRawStream || aEntry.nMethod == STORED)
- aBuffer = aReadBuffer; // bRawStream means the caller doesn't want it decompressed
- else
- {
- aInflater.setInputSegment(aReadBuffer, 0, nSize );
- aBuffer.realloc( aEntry.nSize );
- aInflater.doInflate(aBuffer);
- aInflater.end();
- }
- bHaveInMemory = sal_True;
- }
-}
-EntryInputStream::~EntryInputStream( void )
-{
-}
-
-sal_Int32 SAL_CALL EntryInputStream::readBytes( Sequence< sal_Int8 >& aData,
- sal_Int32 nBytesToRead )
- throw(io::NotConnectedException, io::BufferSizeExceededException, io::IOException, RuntimeException)
-{
- if (nBytesToRead <0)
- throw io::BufferSizeExceededException(::rtl::OUString(), *this);
- if (!bHaveInMemory)
- readIntoMemory();
- if (nBytesToRead + nCurrent > nUncompressedSize)
- nBytesToRead = static_cast < sal_Int32> ( nUncompressedSize - nCurrent );
-
- aData.realloc( nBytesToRead );
- memcpy(aData.getArray(), aBuffer.getConstArray() + nCurrent, nBytesToRead);
- nCurrent+=nBytesToRead;
-
- return nBytesToRead;
-}
-sal_Int32 SAL_CALL EntryInputStream::readSomeBytes( Sequence< sal_Int8 >& aData,
- sal_Int32 nMaxBytesToRead )
- throw(io::NotConnectedException, io::BufferSizeExceededException, io::IOException, RuntimeException)
-{
- return readBytes( aData, nMaxBytesToRead );
-}
-void SAL_CALL EntryInputStream::skipBytes( sal_Int32 nBytesToSkip )
- throw(io::NotConnectedException, io::BufferSizeExceededException, io::IOException, RuntimeException)
-{
- if (nBytesToSkip < 0)
- throw io::BufferSizeExceededException(::rtl::OUString(), *this);
-
- if (nBytesToSkip + nCurrent > nUncompressedSize)
- nBytesToSkip = static_cast < sal_Int32 > (nUncompressedSize- nCurrent);
-
- nCurrent+=nBytesToSkip;
-}
-sal_Int32 SAL_CALL EntryInputStream::available( )
- throw(io::NotConnectedException, io::IOException, RuntimeException)
-{
- return static_cast < sal_Int32 > (nUncompressedSize - nCurrent);
-}
-void SAL_CALL EntryInputStream::closeInput( )
- throw(io::NotConnectedException, io::IOException, RuntimeException)
-{
-}
-
-void SAL_CALL EntryInputStream::seek( sal_Int64 location )
- throw(lang::IllegalArgumentException, io::IOException, RuntimeException)
-{
- if (location > nUncompressedSize)
- location = nUncompressedSize;
- if (location <0)
- location = 0;
- nCurrent = location;
-}
-sal_Int64 SAL_CALL EntryInputStream::getPosition( )
- throw(io::IOException, RuntimeException)
-{
- return nCurrent;
-}
-sal_Int64 SAL_CALL EntryInputStream::getLength( )
- throw(io::IOException, RuntimeException)
-{
- return nUncompressedSize;
-}
diff --git a/package/source/zipapi/EntryInputStream.hxx b/package/source/zipapi/EntryInputStream.hxx
deleted file mode 100644
index c04a5dc2d33b..000000000000
--- a/package/source/zipapi/EntryInputStream.hxx
+++ /dev/null
@@ -1,86 +0,0 @@
-/*************************************************************************
- *
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * Copyright 2000, 2010 Oracle and/or its affiliates.
- *
- * OpenOffice.org - a multi-platform office productivity suite
- *
- * This file is part of OpenOffice.org.
- *
- * OpenOffice.org is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License version 3
- * only, as published by the Free Software Foundation.
- *
- * OpenOffice.org is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License version 3 for more details
- * (a copy is included in the LICENSE file that accompanied this code).
- *
- * You should have received a copy of the GNU Lesser General Public License
- * version 3 along with OpenOffice.org. If not, see
- * <http://www.openoffice.org/license.html>
- * for a copy of the LGPLv3 License.
- *
- ************************************************************************/
-#ifndef _ENTRY_INPUT_STREAM_HXX
-#define _ENTRY_INPUT_STREAM_HXX
-
-#include <cppuhelper/implbase2.hxx> // helper for implementations
-#include <com/sun/star/io/XInputStream.hpp>
-#include <com/sun/star/io/XSeekable.hpp>
-#include <Inflater.hxx>
-#include <com/sun/star/packages/zip/ZipEntry.hpp>
-#ifndef _VOS_REF_H_
-#include <vos/ref.hxx>
-#endif
-#ifndef _ENCRYPTION_DATA_HXX
-#include <EncryptionData.hxx>
-#endif
-class EntryInputStream : public cppu::WeakImplHelper2< com::sun::star::io::XInputStream,
- com::sun::star::io::XSeekable >
-{
-protected:
- com::sun::star::uno::Reference< com::sun::star::io::XInputStream > xStream;
- com::sun::star::uno::Reference< com::sun::star::io::XSeekable > xSeek;
- sal_Int64 nEnd, nCurrent, nUncompressedSize;
- sal_Bool bRawStream, bHaveInMemory, bEncrypted;
- com::sun::star::uno::Sequence < sal_Int8 > aBuffer;
- const vos::ORef < EncryptionData > xEncryptionData;
- const com::sun::star::packages::zip::ZipEntry aEntry;
- Inflater aInflater;
- void readIntoMemory()
- throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
-public:
- EntryInputStream( com::sun::star::uno::Reference < com::sun::star::io::XInputStream > xInput,
- const com::sun::star::packages::zip::ZipEntry &rNewEntry,
- const vos::ORef < EncryptionData > &xEncryptData,
- sal_Bool bGetRawStream = sal_False);
- virtual ~EntryInputStream();
-
- // XInputStream
- virtual sal_Int32 SAL_CALL readBytes( ::com::sun::star::uno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead )
- throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
- virtual sal_Int32 SAL_CALL readSomeBytes( ::com::sun::star::uno::Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead )
- throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
- virtual void SAL_CALL skipBytes( sal_Int32 nBytesToSkip )
- throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
- virtual sal_Int32 SAL_CALL available( )
- throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
- virtual void SAL_CALL closeInput( )
- throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
- // XSeekable
- virtual void SAL_CALL seek( sal_Int64 location )
- throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
- virtual sal_Int64 SAL_CALL getPosition( )
- throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
- virtual sal_Int64 SAL_CALL getLength( )
- throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
- /*
-private:
- void fill( void );
- */
-};
-
-#endif
diff --git a/package/source/zipapi/MemoryByteGrabber.hxx b/package/source/zipapi/MemoryByteGrabber.hxx
index 8a8d96556bae..f27eaf4826ad 100644
--- a/package/source/zipapi/MemoryByteGrabber.hxx
+++ b/package/source/zipapi/MemoryByteGrabber.hxx
@@ -62,7 +62,7 @@ public:
nBytesToRead = mnEnd - mnCurrent;
aData.realloc ( nBytesToRead );
- memcpy ( aData.getArray(), mpBuffer + mnCurrent, nBytesToRead );
+ rtl_copyMemory( aData.getArray(), mpBuffer + mnCurrent, nBytesToRead );
mnCurrent += nBytesToRead;
return nBytesToRead;
}
diff --git a/package/source/zipapi/XFileStream.cxx b/package/source/zipapi/XFileStream.cxx
deleted file mode 100644
index 9e7156ee82b3..000000000000
--- a/package/source/zipapi/XFileStream.cxx
+++ /dev/null
@@ -1,227 +0,0 @@
-/*************************************************************************
- *
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * Copyright 2000, 2010 Oracle and/or its affiliates.
- *
- * OpenOffice.org - a multi-platform office productivity suite
- *
- * This file is part of OpenOffice.org.
- *
- * OpenOffice.org is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License version 3
- * only, as published by the Free Software Foundation.
- *
- * OpenOffice.org is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License version 3 for more details
- * (a copy is included in the LICENSE file that accompanied this code).
- *
- * You should have received a copy of the GNU Lesser General Public License
- * version 3 along with OpenOffice.org. If not, see
- * <http://www.openoffice.org/license.html>
- * for a copy of the LGPLv3 License.
- *
- ************************************************************************/
-
-// MARKER(update_precomp.py): autogen include statement, do not remove
-#include "precompiled_package.hxx"
-#include <XFileStream.hxx>
-#include <EncryptionData.hxx>
-#include <com/sun/star/packages/zip/ZipConstants.hpp>
-#include <PackageConstants.hxx>
-#include <rtl/cipher.h>
-#include <ZipFile.hxx>
-#include <EncryptedDataHeader.hxx>
-#include <com/sun/star/io/XOutputStream.hpp>
-
-using namespace com::sun::star::packages::zip::ZipConstants;
-using namespace com::sun::star::io;
-using namespace com::sun::star::uno;
-using com::sun::star::lang::IllegalArgumentException;
-using ::rtl::OUString;
-
-XFileStream::XFileStream( ZipEntry & rEntry,
- com::sun::star::uno::Reference < com::sun::star::io::XInputStream > xNewZipStream,
- com::sun::star::uno::Reference < com::sun::star::io::XInputStream > xNewTempStream,
- const vos::ORef < EncryptionData > &rData,
- sal_Bool bNewRawStream,
- sal_Bool bIsEncrypted )
-: maEntry ( rEntry )
-, mxData ( rData )
-, mbRawStream ( bNewRawStream )
-, mbFinished ( sal_False )
-, mxTempIn ( xNewTempStream )
-, mxTempSeek ( xNewTempStream, UNO_QUERY )
-, mxTempOut ( xNewTempStream, UNO_QUERY )
-, mxZipStream ( xNewZipStream )
-, mxZipSeek ( xNewZipStream, UNO_QUERY )
-, maInflater ( sal_True )
-, maCipher ( NULL )
-{
- mnZipCurrent = maEntry.nOffset;
- if (mbRawStream)
- {
- mnZipSize = maEntry.nMethod == DEFLATED ? maEntry.nCompressedSize : maEntry.nSize;
- mnZipEnd = maEntry.nOffset + mnZipSize;
- }
- else
- {
- mnZipSize = maEntry.nSize;
- mnZipEnd = maEntry.nMethod == DEFLATED ? maEntry.nOffset + maEntry.nCompressedSize : maEntry.nOffset + maEntry.nSize;
- }
-
- if ( bIsEncrypted )
- {
- sal_Bool bHaveEncryptData = ( !rData.isEmpty() && rData->aSalt.getLength() && rData->aInitVector.getLength() && rData->nIterationCount != 0 ) ? sal_True : sal_False;
-
- // if we have all the encrypted data, and want a raw stream, then prepend it to the stream, otherwise
- // make a cipher so we can decrypt it
- if ( bHaveEncryptData )
- {
- if ( !bNewRawStream )
- ZipFile::StaticGetCipher ( rData, maCipher, sal_True );
- else
- {
- // Put in the EncryptedDataHeader
- Sequence < sal_Int8 > aEncryptedDataHeader ( n_ConstHeaderSize +
- rData->aInitVector.getLength() +
- rData->aSalt.getLength() +
- rData->aDigest.getLength() );
- sal_Int8 * pHeader = aEncryptedDataHeader.getArray();
- ZipFile::StaticFillHeader ( rData, rEntry.nSize, pHeader );
- mxTempOut->writeBytes ( aEncryptedDataHeader );
- mnZipSize += mxTempSeek->getPosition();
- mxTempSeek->seek ( 0 );
- }
- }
- }
-}
-
-XFileStream::~XFileStream()
-{
- if ( maCipher )
- rtl_cipher_destroy ( maCipher );
-}
-
-void XFileStream::fill( sal_Int64 nUntil)
-{
- sal_Int32 nRead;
- sal_Int64 nPosition = mxTempSeek->getPosition();
- mxTempSeek->seek ( mxTempSeek->getLength() );
- maBuffer.realloc ( n_ConstBufferSize );
-
- while ( mxTempSeek->getLength() < nUntil )
- {
- if ( !mbRawStream )
- {
- while ( 0 == ( nRead = maInflater.doInflate( maBuffer ) ) )
- {
- if ( maInflater.finished() || maInflater.needsDictionary() )
- {
- // some error handling ?
- return;
- }
-
- sal_Int64 nDiff = mnZipEnd - mnZipCurrent;
- if ( nDiff > 0 )
- {
- mxZipSeek->seek ( mnZipCurrent );
- nRead = mxZipStream->readBytes ( maCompBuffer, static_cast < sal_Int32 > ( nDiff < n_ConstBufferSize ? nDiff : n_ConstBufferSize ) );
- mnZipCurrent += nRead;
- // maCompBuffer now has the uncompressed data, check if we need to decrypt
- // before passing to the Inflater
- if ( maCipher )
- {
- Sequence < sal_Int8 > aCryptBuffer ( nRead );
- rtlCipherError aResult = rtl_cipher_decode ( maCipher,
- maCompBuffer.getConstArray(),
- nRead,
- reinterpret_cast < sal_uInt8 * > (aCryptBuffer.getArray()),
- nRead);
- OSL_ASSERT (aResult == rtl_Cipher_E_None);
- maCompBuffer = aCryptBuffer; // Now it holds the decrypted data
-
- }
- maInflater.setInput ( maCompBuffer );
- }
- else
- {
- // some error handling ?
- return;
- }
- }
- }
- else
- {
- sal_Int64 nDiff = mnZipEnd - mnZipCurrent;
- mxZipSeek->seek ( mnZipCurrent );
- nRead = mxZipStream->readBytes ( maBuffer, static_cast < sal_Int32 > ( nDiff < n_ConstBufferSize ? nDiff : n_ConstBufferSize ) );
- mnZipCurrent += nRead;
- }
- Sequence < sal_Int8 > aTmpBuffer ( maBuffer.getConstArray(), nRead );
- mxTempOut->writeBytes ( aTmpBuffer );
- }
- mxTempSeek->seek ( nPosition );
-}
-
-sal_Int32 SAL_CALL XFileStream::readBytes( Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead )
- throw( NotConnectedException, BufferSizeExceededException, IOException, RuntimeException)
-{
- sal_Int64 nPosition = mxTempSeek->getPosition();
- if ( nPosition + nBytesToRead > mnZipSize )
- nBytesToRead = static_cast < sal_Int32 > ( mnZipSize - nPosition );
-
- sal_Int64 nUntil = nBytesToRead + nPosition + n_ConstBufferSize;
- if (nUntil > mnZipSize )
- nUntil = mnZipSize;
- if ( nUntil > mxTempSeek->getLength() )
- fill ( nUntil );
- sal_Int32 nRead = mxTempIn->readBytes ( aData, nBytesToRead );
- return nRead;
-}
-
-sal_Int32 SAL_CALL XFileStream::readSomeBytes( Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead )
- throw( NotConnectedException, BufferSizeExceededException, IOException, RuntimeException)
-{
- return readBytes ( aData, nMaxBytesToRead );
-}
-void SAL_CALL XFileStream::skipBytes( sal_Int32 nBytesToSkip )
- throw( NotConnectedException, BufferSizeExceededException, IOException, RuntimeException)
-{
- seek ( mxTempSeek->getPosition() + nBytesToSkip );
-}
-
-sal_Int32 SAL_CALL XFileStream::available( )
- throw( NotConnectedException, IOException, RuntimeException)
-{
- return static_cast < sal_Int32 > ( mnZipSize - mxTempSeek->getPosition() );
-}
-
-void SAL_CALL XFileStream::closeInput( )
- throw( NotConnectedException, IOException, RuntimeException)
-{
-}
-void SAL_CALL XFileStream::seek( sal_Int64 location )
- throw( IllegalArgumentException, IOException, RuntimeException)
-{
- if ( location > mnZipSize || location < 0 )
- throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 1 );
- if ( location > mxTempSeek->getLength() )
- {
- sal_Int64 nUntil = location + n_ConstBufferSize > mnZipSize ? mnZipSize : location + n_ConstBufferSize;
- fill ( nUntil );
- }
- mxTempSeek->seek ( location );
-}
-sal_Int64 SAL_CALL XFileStream::getPosition( )
- throw(IOException, RuntimeException)
-{
- return mxTempSeek->getPosition();
-}
-sal_Int64 SAL_CALL XFileStream::getLength( )
- throw(IOException, RuntimeException)
-{
- return mnZipSize;
-}
diff --git a/package/source/zipapi/XFileStream.hxx b/package/source/zipapi/XFileStream.hxx
deleted file mode 100644
index 0cf82c5f35cd..000000000000
--- a/package/source/zipapi/XFileStream.hxx
+++ /dev/null
@@ -1,96 +0,0 @@
-/*************************************************************************
- *
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * Copyright 2000, 2010 Oracle and/or its affiliates.
- *
- * OpenOffice.org - a multi-platform office productivity suite
- *
- * This file is part of OpenOffice.org.
- *
- * OpenOffice.org is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License version 3
- * only, as published by the Free Software Foundation.
- *
- * OpenOffice.org is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License version 3 for more details
- * (a copy is included in the LICENSE file that accompanied this code).
- *
- * You should have received a copy of the GNU Lesser General Public License
- * version 3 along with OpenOffice.org. If not, see
- * <http://www.openoffice.org/license.html>
- * for a copy of the LGPLv3 License.
- *
- ************************************************************************/
-#ifndef _XFILE_STREAM_HXX
-#define _XFILE_STREAM_HXX
-
-#include <com/sun/star/lang/IllegalArgumentException.hpp>
-#include <com/sun/star/io/XSeekable.hpp>
-#include <com/sun/star/io/XInputStream.hpp>
-#include <cppuhelper/implbase2.hxx>
-#ifndef _VOS_REF_H_
-#include <vos/ref.hxx>
-#endif
-#ifndef _INFLATER_HXX
-#include <Inflater.hxx>
-#endif
-#include <ZipEntry.hxx>
-
-namespace com { namespace sun { namespace star {
- namespace io { class XOutputStream; }
-} } }
-class EncryptionData;
-typedef void* rtlCipher;
-class XFileStream : public cppu::WeakImplHelper2
-<
- com::sun::star::io::XInputStream,
- com::sun::star::io::XSeekable
->
-{
-protected:
- com::sun::star::uno::Reference < com::sun::star::io::XInputStream > mxZipStream;
- com::sun::star::uno::Reference < com::sun::star::io::XSeekable > mxZipSeek;
- com::sun::star::uno::Reference < com::sun::star::io::XInputStream > mxTempIn;
- com::sun::star::uno::Reference < com::sun::star::io::XSeekable > mxTempSeek;
- com::sun::star::uno::Reference < com::sun::star::io::XOutputStream > mxTempOut;
- com::sun::star::uno::Sequence < sal_Int8 > maBuffer, maCompBuffer;
- ZipEntry maEntry;
- vos::ORef < EncryptionData > mxData;
- rtlCipher maCipher;
- Inflater maInflater;
- sal_Bool mbRawStream, mbFinished;
- sal_Int64 mnZipCurrent, mnZipEnd, mnZipSize;
- void fill( sal_Int64 nUntil );
-
-public:
- XFileStream( ZipEntry & rEntry,
- com::sun::star::uno::Reference < com::sun::star::io::XInputStream > xNewZipStream,
- com::sun::star::uno::Reference < com::sun::star::io::XInputStream > xNewTempStream,
- const vos::ORef < EncryptionData > &rData,
- sal_Bool bRawStream,
- sal_Bool bIsEncrypted );
- virtual ~XFileStream();
-
- // XInputStream
- virtual sal_Int32 SAL_CALL readBytes( ::com::sun::star::uno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead )
- throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
- virtual sal_Int32 SAL_CALL readSomeBytes( ::com::sun::star::uno::Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead )
- throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
- virtual void SAL_CALL skipBytes( sal_Int32 nBytesToSkip )
- throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
- virtual sal_Int32 SAL_CALL available( )
- throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
- virtual void SAL_CALL closeInput( )
- throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
- // XSeekable
- virtual void SAL_CALL seek( sal_Int64 location )
- throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
- virtual sal_Int64 SAL_CALL getPosition( )
- throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
- virtual sal_Int64 SAL_CALL getLength( )
- throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
-};
-#endif
diff --git a/package/source/zipapi/XMemoryStream.cxx b/package/source/zipapi/XMemoryStream.cxx
deleted file mode 100644
index c5ffe9ac874c..000000000000
--- a/package/source/zipapi/XMemoryStream.cxx
+++ /dev/null
@@ -1,52 +0,0 @@
-/*************************************************************************
- *
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * Copyright 2000, 2010 Oracle and/or its affiliates.
- *
- * OpenOffice.org - a multi-platform office productivity suite
- *
- * This file is part of OpenOffice.org.
- *
- * OpenOffice.org is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License version 3
- * only, as published by the Free Software Foundation.
- *
- * OpenOffice.org is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License version 3 for more details
- * (a copy is included in the LICENSE file that accompanied this code).
- *
- * You should have received a copy of the GNU Lesser General Public License
- * version 3 along with OpenOffice.org. If not, see
- * <http://www.openoffice.org/license.html>
- * for a copy of the LGPLv3 License.
- *
- ************************************************************************/
-
-// MARKER(update_precomp.py): autogen include statement, do not remove
-#include "precompiled_package.hxx"
-#include <XMemoryStream.hxx>
-
-using namespace com::sun::star::io;
-using namespace com::sun::star::uno;
-
-XMemoryStream::XMemoryStream ( com::sun::star::uno::Sequence < sal_Int8 > & rNewBuffer )
-: ZipPackageBuffer ( rNewBuffer )
-{
-}
-XMemoryStream::~XMemoryStream(void)
-{
-}
-::com::sun::star::uno::Any SAL_CALL XMemoryStream::queryInterface( const com::sun::star::uno::Type& rType )
- throw(com::sun::star::uno::RuntimeException)
-{
- return ::cppu::queryInterface ( rType ,
- // OWeakObject interfaces
- reinterpret_cast< XInterface* > ( this ) ,
- static_cast< XWeak* > ( this ) ,
- // my interfaces
- static_cast< XInputStream* > ( this ) ,
- static_cast< XSeekable* > ( this ) );
-}
diff --git a/package/source/zipapi/XUnbufferedStream.cxx b/package/source/zipapi/XUnbufferedStream.cxx
index a75af35914a1..e8e16329eccc 100644
--- a/package/source/zipapi/XUnbufferedStream.cxx
+++ b/package/source/zipapi/XUnbufferedStream.cxx
@@ -27,12 +27,14 @@
// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_package.hxx"
-#include <XUnbufferedStream.hxx>
-#include <EncryptionData.hxx>
+
#include <com/sun/star/packages/zip/ZipConstants.hpp>
#include <com/sun/star/packages/zip/ZipIOException.hpp>
+#include <com/sun/star/xml/crypto/CipherID.hpp>
+
+#include <XUnbufferedStream.hxx>
+#include <EncryptionData.hxx>
#include <PackageConstants.hxx>
-#include <rtl/cipher.h>
#include <ZipFile.hxx>
#include <EncryptedDataHeader.hxx>
#include <algorithm>
@@ -47,6 +49,7 @@
using namespace ::com::sun::star;
#endif
+using namespace ::com::sun::star;
using namespace com::sun::star::packages::zip::ZipConstants;
using namespace com::sun::star::io;
using namespace com::sun::star::uno;
@@ -54,20 +57,22 @@ using com::sun::star::lang::IllegalArgumentException;
using com::sun::star::packages::zip::ZipIOException;
using ::rtl::OUString;
-XUnbufferedStream::XUnbufferedStream( SotMutexHolderRef aMutexHolder,
- ZipEntry & rEntry,
- Reference < XInputStream > xNewZipStream,
- const vos::ORef < EncryptionData > &rData,
- sal_Int8 nStreamMode,
- sal_Bool bIsEncrypted,
- const ::rtl::OUString& aMediaType,
- sal_Bool bRecoveryMode )
+XUnbufferedStream::XUnbufferedStream(
+ const uno::Reference< lang::XMultiServiceFactory >& xFactory,
+ SotMutexHolderRef aMutexHolder,
+ ZipEntry & rEntry,
+ Reference < XInputStream > xNewZipStream,
+ const ::rtl::Reference< EncryptionData >& rData,
+ sal_Int8 nStreamMode,
+ sal_Bool bIsEncrypted,
+ const ::rtl::OUString& aMediaType,
+ sal_Bool bRecoveryMode )
: maMutexHolder( aMutexHolder.Is() ? aMutexHolder : SotMutexHolderRef( new SotMutexHolder ) )
, mxZipStream ( xNewZipStream )
, mxZipSeek ( xNewZipStream, UNO_QUERY )
, maEntry ( rEntry )
, mxData ( rData )
-, maCipher ( NULL )
+, mnBlockSize( 1 )
, maInflater ( sal_True )
, mbRawStream ( nStreamMode == UNBUFF_STREAM_RAW || nStreamMode == UNBUFF_STREAM_WRAPPEDRAW )
, mbWrappedRaw ( nStreamMode == UNBUFF_STREAM_WRAPPEDRAW )
@@ -90,11 +95,15 @@ XUnbufferedStream::XUnbufferedStream( SotMutexHolderRef aMutexHolder,
mnZipSize = maEntry.nSize;
mnZipEnd = maEntry.nMethod == DEFLATED ? maEntry.nOffset + maEntry.nCompressedSize : maEntry.nOffset + maEntry.nSize;
}
- sal_Bool bHaveEncryptData = ( !rData.isEmpty() && rData->aSalt.getLength() && rData->aInitVector.getLength() && rData->nIterationCount != 0 ) ? sal_True : sal_False;
+ sal_Bool bHaveEncryptData = ( rData.is() && rData->m_aSalt.getLength() && rData->m_aInitVector.getLength() && rData->m_nIterationCount != 0 ) ? sal_True : sal_False;
sal_Bool bMustDecrypt = ( nStreamMode == UNBUFF_STREAM_DATA && bHaveEncryptData && bIsEncrypted ) ? sal_True : sal_False;
if ( bMustDecrypt )
- ZipFile::StaticGetCipher ( rData, maCipher, sal_True );
+ {
+ m_xCipherContext = ZipFile::StaticGetCipher( xFactory, rData, false );
+ mnBlockSize = ( rData->m_nEncAlg == xml::crypto::CipherID::AES_CBC_W3C_PADDING ? 16 : 1 );
+ }
+
if ( bHaveEncryptData && mbWrappedRaw && bIsEncrypted )
{
// if we have the data needed to decrypt it, but didn't want it decrypted (or
@@ -103,24 +112,26 @@ XUnbufferedStream::XUnbufferedStream( SotMutexHolderRef aMutexHolder,
// Make a buffer big enough to hold both the header and the data itself
maHeader.realloc ( n_ConstHeaderSize +
- rData->aInitVector.getLength() +
- rData->aSalt.getLength() +
- rData->aDigest.getLength() +
+ rData->m_aInitVector.getLength() +
+ rData->m_aSalt.getLength() +
+ rData->m_aDigest.getLength() +
aMediaType.getLength() * sizeof( sal_Unicode ) );
sal_Int8 * pHeader = maHeader.getArray();
- ZipFile::StaticFillHeader ( rData, rEntry.nSize, aMediaType, pHeader );
+ ZipFile::StaticFillHeader( rData, rEntry.nSize, aMediaType, pHeader );
mnHeaderToRead = static_cast < sal_Int16 > ( maHeader.getLength() );
}
}
// allows to read package raw stream
-XUnbufferedStream::XUnbufferedStream( const Reference < XInputStream >& xRawStream,
- const vos::ORef < EncryptionData > &rData )
+XUnbufferedStream::XUnbufferedStream(
+ const uno::Reference< lang::XMultiServiceFactory >& /*xFactory*/,
+ const Reference < XInputStream >& xRawStream,
+ const ::rtl::Reference< EncryptionData >& rData )
: maMutexHolder( new SotMutexHolder )
, mxZipStream ( xRawStream )
, mxZipSeek ( xRawStream, UNO_QUERY )
, mxData ( rData )
-, maCipher ( NULL )
+, mnBlockSize( 1 )
, maInflater ( sal_True )
, mbRawStream ( sal_False )
, mbWrappedRaw ( sal_False )
@@ -136,8 +147,8 @@ XUnbufferedStream::XUnbufferedStream( const Reference < XInputStream >& xRawStre
OSL_ENSURE( mxZipSeek.is(), "The stream must be seekable!\n" );
// skip raw header, it must be already parsed to rData
- mnZipCurrent = n_ConstHeaderSize + rData->aInitVector.getLength() +
- rData->aSalt.getLength() + rData->aDigest.getLength();
+ mnZipCurrent = n_ConstHeaderSize + rData->m_aInitVector.getLength() +
+ rData->m_aSalt.getLength() + rData->m_aDigest.getLength();
try {
if ( mxZipSeek.is() )
@@ -149,13 +160,12 @@ XUnbufferedStream::XUnbufferedStream( const Reference < XInputStream >& xRawStre
mnZipEnd = mnZipCurrent + mnZipSize;
- ZipFile::StaticGetCipher ( rData, maCipher, sal_True );
+ // the raw data will not be decrypted, no need for the cipher
+ // m_xCipherContext = ZipFile::StaticGetCipher( xFactory, rData, false );
}
XUnbufferedStream::~XUnbufferedStream()
{
- if ( maCipher )
- rtl_cipher_destroy ( maCipher );
}
sal_Int32 SAL_CALL XUnbufferedStream::readBytes( Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead )
@@ -180,7 +190,7 @@ sal_Int32 SAL_CALL XUnbufferedStream::readBytes( Sequence< sal_Int8 >& aData, sa
{
sal_Int16 nHeadRead = static_cast< sal_Int16 >(( nRequestedBytes > mnHeaderToRead ?
mnHeaderToRead : nRequestedBytes ));
- memcpy ( aData.getArray(), maHeader.getConstArray() + maHeader.getLength() - mnHeaderToRead, nHeadRead );
+ rtl_copyMemory ( aData.getArray(), maHeader.getConstArray() + maHeader.getLength() - mnHeaderToRead, nHeadRead );
mnHeaderToRead = mnHeaderToRead - nHeadRead;
if ( nHeadRead < nRequestedBytes )
@@ -242,12 +252,17 @@ sal_Int32 SAL_CALL XUnbufferedStream::readBytes( Sequence< sal_Int8 >& aData, sa
throw ZipIOException( OUString( RTL_CONSTASCII_USTRINGPARAM( "Dictionaries are not supported!" ) ),
Reference< XInterface >() );
- sal_Int32 nDiff = static_cast < sal_Int32 > ( mnZipEnd - mnZipCurrent );
+ sal_Int32 nDiff = static_cast< sal_Int32 >( mnZipEnd - mnZipCurrent );
if ( nDiff > 0 )
{
mxZipSeek->seek ( mnZipCurrent );
- sal_Int32 nToRead = std::min ( nDiff, std::max ( nRequestedBytes, static_cast< sal_Int32 >( 8192 ) ) );
- sal_Int32 nZipRead = mxZipStream->readBytes ( maCompBuffer, nToRead );
+
+ sal_Int32 nToRead = std::max( nRequestedBytes, static_cast< sal_Int32 >( 8192 ) );
+ if ( mnBlockSize > 1 )
+ nToRead = nToRead + mnBlockSize - nToRead % mnBlockSize;
+ nToRead = std::min( nDiff, nToRead );
+
+ sal_Int32 nZipRead = mxZipStream->readBytes( maCompBuffer, nToRead );
if ( nZipRead < nToRead )
throw ZipIOException( OUString( RTL_CONSTASCII_USTRINGPARAM( "No expected data!" ) ),
Reference< XInterface >() );
@@ -255,23 +270,22 @@ sal_Int32 SAL_CALL XUnbufferedStream::readBytes( Sequence< sal_Int8 >& aData, sa
mnZipCurrent += nZipRead;
// maCompBuffer now has the data, check if we need to decrypt
// before passing to the Inflater
- if ( maCipher )
+ if ( m_xCipherContext.is() )
{
if ( mbCheckCRC )
maCRC.update( maCompBuffer );
- Sequence < sal_Int8 > aCryptBuffer ( nZipRead );
- rtlCipherError aResult =
- rtl_cipher_decode ( maCipher,
- maCompBuffer.getConstArray(),
- nZipRead,
- reinterpret_cast < sal_uInt8 * > (aCryptBuffer.getArray()),
- nZipRead);
- if( aResult != rtl_Cipher_E_None ) {
- OSL_ASSERT (aResult == rtl_Cipher_E_None);
+ maCompBuffer = m_xCipherContext->convertWithCipherContext( maCompBuffer );
+ if ( mnZipCurrent == mnZipEnd )
+ {
+ uno::Sequence< sal_Int8 > aSuffix = m_xCipherContext->finalizeCipherContextAndDispose();
+ if ( aSuffix.getLength() )
+ {
+ sal_Int32 nOldLen = maCompBuffer.getLength();
+ maCompBuffer.realloc( nOldLen + aSuffix.getLength() );
+ rtl_copyMemory( maCompBuffer.getArray() + nOldLen, aSuffix.getConstArray(), aSuffix.getLength() );
+ }
}
- maCompBuffer = aCryptBuffer; // Now it holds the decrypted data
-
}
maInflater.setInput ( maCompBuffer );
}
@@ -290,7 +304,7 @@ sal_Int32 SAL_CALL XUnbufferedStream::readBytes( Sequence< sal_Int8 >& aData, sa
if ( mbCheckCRC && ( !mbRawStream || mbWrappedRaw ) )
{
- if ( !maCipher && !mbWrappedRaw )
+ if ( !m_xCipherContext.is() && !mbWrappedRaw )
maCRC.update( aData );
#if 0
diff --git a/package/source/zipapi/XUnbufferedStream.hxx b/package/source/zipapi/XUnbufferedStream.hxx
index 321ec10b8032..f8878c25979a 100644
--- a/package/source/zipapi/XUnbufferedStream.hxx
+++ b/package/source/zipapi/XUnbufferedStream.hxx
@@ -32,8 +32,10 @@
#include <com/sun/star/io/XSeekable.hpp>
#include <com/sun/star/io/XInputStream.hpp>
#include <com/sun/star/io/XOutputStream.hpp>
+#include <com/sun/star/xml/crypto/XCipherContext.hpp>
+
#include <cppuhelper/implbase1.hxx>
-#include <vos/ref.hxx>
+#include <rtl/ref.hxx>
#include <Inflater.hxx>
#include <ZipEntry.hxx>
#include <CRC32.hxx>
@@ -44,7 +46,6 @@
#define UNBUFF_STREAM_WRAPPEDRAW 2
class EncryptionData;
-typedef void* rtlCipher;
class XUnbufferedStream : public cppu::WeakImplHelper1
<
com::sun::star::io::XInputStream
@@ -57,8 +58,9 @@ protected:
com::sun::star::uno::Reference < com::sun::star::io::XSeekable > mxZipSeek;
com::sun::star::uno::Sequence < sal_Int8 > maCompBuffer, maHeader;
ZipEntry maEntry;
- vos::ORef < EncryptionData > mxData;
- rtlCipher maCipher;
+ ::rtl::Reference< EncryptionData > mxData;
+ sal_Int32 mnBlockSize;
+ ::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XCipherContext > m_xCipherContext;
Inflater maInflater;
sal_Bool mbRawStream, mbWrappedRaw, mbFinished;
sal_Int16 mnHeaderToRead;
@@ -68,18 +70,21 @@ protected:
public:
XUnbufferedStream(
+ const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory,
SotMutexHolderRef aMutexHolder,
ZipEntry & rEntry,
com::sun::star::uno::Reference < com::sun::star::io::XInputStream > xNewZipStream,
- const vos::ORef < EncryptionData > &rData,
+ const ::rtl::Reference< EncryptionData >& rData,
sal_Int8 nStreamMode,
sal_Bool bIsEncrypted,
const ::rtl::OUString& aMediaType,
sal_Bool bRecoveryMode );
// allows to read package raw stream
- XUnbufferedStream( const com::sun::star::uno::Reference < com::sun::star::io::XInputStream >& xRawStream,
- const vos::ORef < EncryptionData > &rData );
+ XUnbufferedStream(
+ const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory,
+ const com::sun::star::uno::Reference < com::sun::star::io::XInputStream >& xRawStream,
+ const ::rtl::Reference< EncryptionData >& rData );
virtual ~XUnbufferedStream();
diff --git a/package/source/zipapi/ZipFile.cxx b/package/source/zipapi/ZipFile.cxx
index dcd5669897e3..4827f6879853 100644
--- a/package/source/zipapi/ZipFile.cxx
+++ b/package/source/zipapi/ZipFile.cxx
@@ -27,31 +27,36 @@
// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_package.hxx"
-#include <ZipFile.hxx>
-#include <ZipEnumeration.hxx>
+
+#include <com/sun/star/lang/XMultiServiceFactory.hpp>
+#include <com/sun/star/ucb/XProgressHandler.hpp>
#include <com/sun/star/packages/zip/ZipConstants.hpp>
-#include <rtl/cipher.h>
+#include <com/sun/star/xml/crypto/XCipherContext.hpp>
+#include <com/sun/star/xml/crypto/XDigestContext.hpp>
+#include <com/sun/star/xml/crypto/XCipherContextSupplier.hpp>
+#include <com/sun/star/xml/crypto/XDigestContextSupplier.hpp>
+#include <com/sun/star/xml/crypto/CipherID.hpp>
+#include <com/sun/star/xml/crypto/DigestID.hpp>
+
+#include <comphelper/storagehelper.hxx>
+#include <comphelper/processfactory.hxx>
#include <rtl/digest.h>
-/*
-#include <XMemoryStream.hxx>
-#include <XFileStream.hxx>
-*/
+
+#include <vector>
+
+#include "blowfishcontext.hxx"
+#include "sha1context.hxx"
+#include <ZipFile.hxx>
+#include <ZipEnumeration.hxx>
#include <XUnbufferedStream.hxx>
#include <PackageConstants.hxx>
#include <EncryptedDataHeader.hxx>
#include <EncryptionData.hxx>
#include <MemoryByteGrabber.hxx>
-#include <com/sun/star/lang/XMultiServiceFactory.hpp>
-#include <com/sun/star/ucb/XProgressHandler.hpp>
-#ifndef _CRC32_HXX_
#include <CRC32.hxx>
-#endif
-#include <string.h> // for memcpy
-#include <vector>
-
-#include <comphelper/storagehelper.hxx>
+#define AES_CBC_BLOCK_SIZE 16
using namespace vos;
using namespace rtl;
@@ -67,13 +72,13 @@ using namespace com::sun::star::packages::zip::ZipConstants;
/** This class is used to read entries from a zip file
*/
-ZipFile::ZipFile( Reference < XInputStream > &xInput, const Reference < XMultiServiceFactory > &xNewFactory, sal_Bool bInitialise )
+ZipFile::ZipFile( uno::Reference < XInputStream > &xInput, const uno::Reference < XMultiServiceFactory > &xNewFactory, sal_Bool bInitialise )
throw(IOException, ZipException, RuntimeException)
: aGrabber(xInput)
, aInflater (sal_True)
, xStream(xInput)
, xSeek(xInput, UNO_QUERY)
-, xFactory ( xNewFactory )
+, m_xFactory ( xNewFactory )
, bRecoveryMode( sal_False )
{
if (bInitialise)
@@ -81,20 +86,20 @@ ZipFile::ZipFile( Reference < XInputStream > &xInput, const Reference < XMultiSe
if ( readCEN() == -1 )
{
aEntries.clear();
- throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "stream data looks to be broken" ) ), Reference < XInterface > () );
+ throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "stream data looks to be broken" ) ), uno::Reference < XInterface > () );
}
}
}
-ZipFile::ZipFile( Reference < XInputStream > &xInput, const Reference < XMultiServiceFactory > &xNewFactory, sal_Bool bInitialise, sal_Bool bForceRecovery, Reference < XProgressHandler > xProgress )
+ZipFile::ZipFile( uno::Reference < XInputStream > &xInput, const uno::Reference < XMultiServiceFactory > &xNewFactory, sal_Bool bInitialise, sal_Bool bForceRecovery, uno::Reference < XProgressHandler > xProgress )
throw(IOException, ZipException, RuntimeException)
: aGrabber(xInput)
, aInflater (sal_True)
, xStream(xInput)
, xSeek(xInput, UNO_QUERY)
-, xFactory ( xNewFactory )
+, m_xFactory ( xNewFactory )
, xProgressHandler( xProgress )
, bRecoveryMode( bForceRecovery )
{
@@ -107,7 +112,7 @@ ZipFile::ZipFile( Reference < XInputStream > &xInput, const Reference < XMultiSe
else if ( readCEN() == -1 )
{
aEntries.clear();
- throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "stream data looks to be broken" ) ), Reference < XInterface > () );
+ throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "stream data looks to be broken" ) ), uno::Reference < XInterface > () );
}
}
}
@@ -117,55 +122,94 @@ ZipFile::~ZipFile()
aEntries.clear();
}
-void ZipFile::setInputStream ( Reference < XInputStream > xNewStream )
+void ZipFile::setInputStream ( uno::Reference < XInputStream > xNewStream )
{
::osl::MutexGuard aGuard( m_aMutex );
xStream = xNewStream;
- xSeek = Reference < XSeekable > ( xStream, UNO_QUERY );
+ xSeek = uno::Reference < XSeekable > ( xStream, UNO_QUERY );
aGrabber.setInputStream ( xStream );
}
-sal_Bool ZipFile::StaticGetCipher ( const ORef < EncryptionData > & xEncryptionData, rtlCipher &rCipher, sal_Bool bDecode )
+uno::Reference< xml::crypto::XDigestContext > ZipFile::StaticGetDigestContextForChecksum( const uno::Reference< lang::XMultiServiceFactory >& xArgFactory, const ::rtl::Reference< EncryptionData >& xEncryptionData )
+{
+ uno::Reference< xml::crypto::XDigestContext > xDigestContext;
+ if ( xEncryptionData->m_nCheckAlg == xml::crypto::DigestID::SHA256_1K )
+ {
+ uno::Reference< lang::XMultiServiceFactory > xFactory = xArgFactory;
+ if ( !xFactory.is() )
+ xFactory.set( comphelper::getProcessServiceFactory(), uno::UNO_SET_THROW );
+
+ uno::Reference< xml::crypto::XDigestContextSupplier > xDigestContextSupplier(
+ xFactory->createInstance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.xml.crypto.NSSInitializer" ) ) ),
+ uno::UNO_QUERY_THROW );
+
+ xDigestContext.set( xDigestContextSupplier->getDigestContext( xEncryptionData->m_nCheckAlg, uno::Sequence< beans::NamedValue >() ), uno::UNO_SET_THROW );
+ }
+ else if ( xEncryptionData->m_nCheckAlg == xml::crypto::DigestID::SHA1_1K )
+ xDigestContext.set( SHA1DigestContext::Create(), uno::UNO_SET_THROW );
+
+ return xDigestContext;
+}
+
+uno::Reference< xml::crypto::XCipherContext > ZipFile::StaticGetCipher( const uno::Reference< lang::XMultiServiceFactory >& xArgFactory, const ::rtl::Reference< EncryptionData >& xEncryptionData, bool bEncrypt )
{
- sal_Bool bResult = sal_False;
- if ( ! xEncryptionData.isEmpty() )
+ uno::Reference< xml::crypto::XCipherContext > xResult;
+
+ try
+ {
+ uno::Sequence< sal_Int8 > aDerivedKey( xEncryptionData->m_nDerivedKeySize );
+ if ( rtl_Digest_E_None != rtl_digest_PBKDF2( reinterpret_cast< sal_uInt8* >( aDerivedKey.getArray() ),
+ aDerivedKey.getLength(),
+ reinterpret_cast< const sal_uInt8 * > (xEncryptionData->m_aKey.getConstArray() ),
+ xEncryptionData->m_aKey.getLength(),
+ reinterpret_cast< const sal_uInt8 * > ( xEncryptionData->m_aSalt.getConstArray() ),
+ xEncryptionData->m_aSalt.getLength(),
+ xEncryptionData->m_nIterationCount ) )
+ {
+ throw ZipIOException( ::rtl::OUString::createFromAscii( "Can not create derived key!\n" ),
+ uno::Reference< XInterface >() );
+ }
+
+ if ( xEncryptionData->m_nEncAlg == xml::crypto::CipherID::AES_CBC_W3C_PADDING )
+ {
+ uno::Reference< lang::XMultiServiceFactory > xFactory = xArgFactory;
+ if ( !xFactory.is() )
+ xFactory.set( comphelper::getProcessServiceFactory(), uno::UNO_SET_THROW );
+
+ uno::Reference< xml::crypto::XCipherContextSupplier > xCipherContextSupplier(
+ xFactory->createInstance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.xml.crypto.NSSInitializer" ) ) ),
+ uno::UNO_QUERY_THROW );
+
+ xResult = xCipherContextSupplier->getCipherContext( xEncryptionData->m_nEncAlg, aDerivedKey, xEncryptionData->m_aInitVector, bEncrypt, uno::Sequence< beans::NamedValue >() );
+ }
+ else if ( xEncryptionData->m_nEncAlg == xml::crypto::CipherID::BLOWFISH_CFB_8 )
+ {
+ xResult = BlowfishCFB8CipherContext::Create( aDerivedKey, xEncryptionData->m_aInitVector, bEncrypt );
+ }
+ else
+ {
+ throw ZipIOException( ::rtl::OUString::createFromAscii( "Unknown cipher algorithm is requested!\n" ),
+ uno::Reference< XInterface >() );
+ }
+ }
+ catch( uno::Exception& )
{
- Sequence < sal_uInt8 > aDerivedKey (16);
- rtlCipherError aResult;
- Sequence < sal_Int8 > aDecryptBuffer;
-
- // Get the key
- rtl_digest_PBKDF2 ( aDerivedKey.getArray(), 16,
- reinterpret_cast < const sal_uInt8 * > (xEncryptionData->aKey.getConstArray() ),
- xEncryptionData->aKey.getLength(),
- reinterpret_cast < const sal_uInt8 * > ( xEncryptionData->aSalt.getConstArray() ),
- xEncryptionData->aSalt.getLength(),
- xEncryptionData->nIterationCount );
-
- rCipher = rtl_cipher_create (rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeStream);
- aResult = rtl_cipher_init( rCipher, bDecode ? rtl_Cipher_DirectionDecode : rtl_Cipher_DirectionEncode,
- aDerivedKey.getConstArray(),
- aDerivedKey.getLength(),
- reinterpret_cast < const sal_uInt8 * > ( xEncryptionData->aInitVector.getConstArray() ),
- xEncryptionData->aInitVector.getLength());
- OSL_ASSERT (aResult == rtl_Cipher_E_None);
-
- bResult = ( aResult == rtl_Cipher_E_None );
+ OSL_ENSURE( sal_False, "Can not create cipher context!" );
}
- return bResult;
+ return xResult;
}
-void ZipFile::StaticFillHeader ( const ORef < EncryptionData > & rData,
+void ZipFile::StaticFillHeader( const ::rtl::Reference< EncryptionData >& rData,
sal_Int32 nSize,
const ::rtl::OUString& aMediaType,
sal_Int8 * & pHeader )
{
// I think it's safe to restrict vector and salt length to 2 bytes !
- sal_Int16 nIVLength = static_cast < sal_Int16 > ( rData->aInitVector.getLength() );
- sal_Int16 nSaltLength = static_cast < sal_Int16 > ( rData->aSalt.getLength() );
- sal_Int16 nDigestLength = static_cast < sal_Int16 > ( rData->aDigest.getLength() );
+ sal_Int16 nIVLength = static_cast < sal_Int16 > ( rData->m_aInitVector.getLength() );
+ sal_Int16 nSaltLength = static_cast < sal_Int16 > ( rData->m_aSalt.getLength() );
+ sal_Int16 nDigestLength = static_cast < sal_Int16 > ( rData->m_aDigest.getLength() );
sal_Int16 nMediaTypeLength = static_cast < sal_Int16 > ( aMediaType.getLength() * sizeof( sal_Unicode ) );
// First the header
@@ -179,7 +223,7 @@ void ZipFile::StaticFillHeader ( const ORef < EncryptionData > & rData,
*(pHeader++) = ( n_ConstCurrentVersion >> 8 ) & 0xFF;
// Then the iteration Count
- sal_Int32 nIterationCount = rData->nIterationCount;
+ sal_Int32 nIterationCount = rData->m_nIterationCount;
*(pHeader++) = static_cast< sal_Int8 >(( nIterationCount >> 0 ) & 0xFF);
*(pHeader++) = static_cast< sal_Int8 >(( nIterationCount >> 8 ) & 0xFF);
*(pHeader++) = static_cast< sal_Int8 >(( nIterationCount >> 16 ) & 0xFF);
@@ -191,6 +235,34 @@ void ZipFile::StaticFillHeader ( const ORef < EncryptionData > & rData,
*(pHeader++) = static_cast< sal_Int8 >(( nSize >> 16 ) & 0xFF);
*(pHeader++) = static_cast< sal_Int8 >(( nSize >> 24 ) & 0xFF);
+ // Then the encryption algorithm
+ sal_Int32 nEncAlgID = rData->m_nEncAlg;
+ *(pHeader++) = static_cast< sal_Int8 >(( nEncAlgID >> 0 ) & 0xFF);
+ *(pHeader++) = static_cast< sal_Int8 >(( nEncAlgID >> 8 ) & 0xFF);
+ *(pHeader++) = static_cast< sal_Int8 >(( nEncAlgID >> 16 ) & 0xFF);
+ *(pHeader++) = static_cast< sal_Int8 >(( nEncAlgID >> 24 ) & 0xFF);
+
+ // Then the checksum algorithm
+ sal_Int32 nChecksumAlgID = rData->m_nCheckAlg;
+ *(pHeader++) = static_cast< sal_Int8 >(( nChecksumAlgID >> 0 ) & 0xFF);
+ *(pHeader++) = static_cast< sal_Int8 >(( nChecksumAlgID >> 8 ) & 0xFF);
+ *(pHeader++) = static_cast< sal_Int8 >(( nChecksumAlgID >> 16 ) & 0xFF);
+ *(pHeader++) = static_cast< sal_Int8 >(( nChecksumAlgID >> 24 ) & 0xFF);
+
+ // Then the derived key size
+ sal_Int32 nDerivedKeySize = rData->m_nDerivedKeySize;
+ *(pHeader++) = static_cast< sal_Int8 >(( nDerivedKeySize >> 0 ) & 0xFF);
+ *(pHeader++) = static_cast< sal_Int8 >(( nDerivedKeySize >> 8 ) & 0xFF);
+ *(pHeader++) = static_cast< sal_Int8 >(( nDerivedKeySize >> 16 ) & 0xFF);
+ *(pHeader++) = static_cast< sal_Int8 >(( nDerivedKeySize >> 24 ) & 0xFF);
+
+ // Then the start key generation algorithm
+ sal_Int32 nKeyAlgID = rData->m_nStartKeyGenID;
+ *(pHeader++) = static_cast< sal_Int8 >(( nKeyAlgID >> 0 ) & 0xFF);
+ *(pHeader++) = static_cast< sal_Int8 >(( nKeyAlgID >> 8 ) & 0xFF);
+ *(pHeader++) = static_cast< sal_Int8 >(( nKeyAlgID >> 16 ) & 0xFF);
+ *(pHeader++) = static_cast< sal_Int8 >(( nKeyAlgID >> 24 ) & 0xFF);
+
// Then the salt length
*(pHeader++) = static_cast< sal_Int8 >(( nSaltLength >> 0 ) & 0xFF);
*(pHeader++) = static_cast< sal_Int8 >(( nSaltLength >> 8 ) & 0xFF);
@@ -208,26 +280,30 @@ void ZipFile::StaticFillHeader ( const ORef < EncryptionData > & rData,
*(pHeader++) = static_cast< sal_Int8 >(( nMediaTypeLength >> 8 ) & 0xFF);
// Then the salt content
- memcpy ( pHeader, rData->aSalt.getConstArray(), nSaltLength );
+ rtl_copyMemory ( pHeader, rData->m_aSalt.getConstArray(), nSaltLength );
pHeader += nSaltLength;
// Then the IV content
- memcpy ( pHeader, rData->aInitVector.getConstArray(), nIVLength );
+ rtl_copyMemory ( pHeader, rData->m_aInitVector.getConstArray(), nIVLength );
pHeader += nIVLength;
// Then the digest content
- memcpy ( pHeader, rData->aDigest.getConstArray(), nDigestLength );
+ rtl_copyMemory ( pHeader, rData->m_aDigest.getConstArray(), nDigestLength );
pHeader += nDigestLength;
// Then the mediatype itself
- memcpy ( pHeader, aMediaType.getStr(), nMediaTypeLength );
+ rtl_copyMemory ( pHeader, aMediaType.getStr(), nMediaTypeLength );
pHeader += nMediaTypeLength;
}
-sal_Bool ZipFile::StaticFillData ( ORef < EncryptionData > & rData,
+sal_Bool ZipFile::StaticFillData ( ::rtl::Reference< BaseEncryptionData > & rData,
+ sal_Int32 &rEncAlg,
+ sal_Int32 &rChecksumAlg,
+ sal_Int32 &rDerivedKeySize,
+ sal_Int32 &rStartKeyGenID,
sal_Int32 &rSize,
::rtl::OUString& aMediaType,
- Reference < XInputStream > &rStream )
+ const uno::Reference< XInputStream >& rStream )
{
sal_Bool bOk = sal_False;
const sal_Int32 nHeaderSize = n_ConstHeaderSize - 4;
@@ -244,13 +320,33 @@ sal_Bool ZipFile::StaticFillData ( ORef < EncryptionData > & rData,
nCount |= ( pBuffer[nPos++] & 0xFF ) << 8;
nCount |= ( pBuffer[nPos++] & 0xFF ) << 16;
nCount |= ( pBuffer[nPos++] & 0xFF ) << 24;
- rData->nIterationCount = nCount;
+ rData->m_nIterationCount = nCount;
rSize = pBuffer[nPos++] & 0xFF;
rSize |= ( pBuffer[nPos++] & 0xFF ) << 8;
rSize |= ( pBuffer[nPos++] & 0xFF ) << 16;
rSize |= ( pBuffer[nPos++] & 0xFF ) << 24;
+ rEncAlg = pBuffer[nPos++] & 0xFF;
+ rEncAlg |= ( pBuffer[nPos++] & 0xFF ) << 8;
+ rEncAlg |= ( pBuffer[nPos++] & 0xFF ) << 16;
+ rEncAlg |= ( pBuffer[nPos++] & 0xFF ) << 24;
+
+ rChecksumAlg = pBuffer[nPos++] & 0xFF;
+ rChecksumAlg |= ( pBuffer[nPos++] & 0xFF ) << 8;
+ rChecksumAlg |= ( pBuffer[nPos++] & 0xFF ) << 16;
+ rChecksumAlg |= ( pBuffer[nPos++] & 0xFF ) << 24;
+
+ rDerivedKeySize = pBuffer[nPos++] & 0xFF;
+ rDerivedKeySize |= ( pBuffer[nPos++] & 0xFF ) << 8;
+ rDerivedKeySize |= ( pBuffer[nPos++] & 0xFF ) << 16;
+ rDerivedKeySize |= ( pBuffer[nPos++] & 0xFF ) << 24;
+
+ rStartKeyGenID = pBuffer[nPos++] & 0xFF;
+ rStartKeyGenID |= ( pBuffer[nPos++] & 0xFF ) << 8;
+ rStartKeyGenID |= ( pBuffer[nPos++] & 0xFF ) << 16;
+ rStartKeyGenID |= ( pBuffer[nPos++] & 0xFF ) << 24;
+
sal_Int16 nSaltLength = pBuffer[nPos++] & 0xFF;
nSaltLength |= ( pBuffer[nPos++] & 0xFF ) << 8;
sal_Int16 nIVLength = ( pBuffer[nPos++] & 0xFF );
@@ -263,16 +359,16 @@ sal_Bool ZipFile::StaticFillData ( ORef < EncryptionData > & rData,
if ( nSaltLength == rStream->readBytes ( aBuffer, nSaltLength ) )
{
- rData->aSalt.realloc ( nSaltLength );
- memcpy ( rData->aSalt.getArray(), aBuffer.getConstArray(), nSaltLength );
+ rData->m_aSalt.realloc ( nSaltLength );
+ rtl_copyMemory ( rData->m_aSalt.getArray(), aBuffer.getConstArray(), nSaltLength );
if ( nIVLength == rStream->readBytes ( aBuffer, nIVLength ) )
{
- rData->aInitVector.realloc ( nIVLength );
- memcpy ( rData->aInitVector.getArray(), aBuffer.getConstArray(), nIVLength );
+ rData->m_aInitVector.realloc ( nIVLength );
+ rtl_copyMemory ( rData->m_aInitVector.getArray(), aBuffer.getConstArray(), nIVLength );
if ( nDigestLength == rStream->readBytes ( aBuffer, nDigestLength ) )
{
- rData->aDigest.realloc ( nDigestLength );
- memcpy ( rData->aDigest.getArray(), aBuffer.getConstArray(), nDigestLength );
+ rData->m_aDigest.realloc ( nDigestLength );
+ rtl_copyMemory ( rData->m_aDigest.getArray(), aBuffer.getConstArray(), nDigestLength );
if ( nMediaTypeLength == rStream->readBytes ( aBuffer, nMediaTypeLength ) )
{
@@ -288,84 +384,107 @@ sal_Bool ZipFile::StaticFillData ( ORef < EncryptionData > & rData,
return bOk;
}
-Reference< XInputStream > ZipFile::StaticGetDataFromRawStream( const Reference< XInputStream >& xStream,
- const ORef < EncryptionData > &rData )
+uno::Reference< XInputStream > ZipFile::StaticGetDataFromRawStream( const uno::Reference< lang::XMultiServiceFactory >& xFactory,
+ const uno::Reference< XInputStream >& xStream,
+ const ::rtl::Reference< EncryptionData > &rData )
throw ( packages::WrongPasswordException, ZipIOException, RuntimeException )
{
- if ( rData.isEmpty() )
+ if ( !rData.is() )
throw ZipIOException( OUString::createFromAscii( "Encrypted stream without encryption data!\n" ),
- Reference< XInterface >() );
+ uno::Reference< XInterface >() );
- if ( !rData->aKey.getLength() )
+ if ( !rData->m_aKey.getLength() )
throw packages::WrongPasswordException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
- Reference< XSeekable > xSeek( xStream, UNO_QUERY );
+ uno::Reference< XSeekable > xSeek( xStream, UNO_QUERY );
if ( !xSeek.is() )
throw ZipIOException( OUString::createFromAscii( "The stream must be seekable!\n" ),
- Reference< XInterface >() );
+ uno::Reference< XInterface >() );
// if we have a digest, then this file is an encrypted one and we should
// check if we can decrypt it or not
- OSL_ENSURE( rData->aDigest.getLength(), "Can't detect password correctness without digest!\n" );
- if ( rData->aDigest.getLength() )
+ OSL_ENSURE( rData->m_aDigest.getLength(), "Can't detect password correctness without digest!\n" );
+ if ( rData->m_aDigest.getLength() )
{
- sal_Int32 nSize = sal::static_int_cast< sal_Int32 >( xSeek->getLength() );
- nSize = nSize > n_ConstDigestLength ? n_ConstDigestLength : nSize;
+ sal_Int32 nSize = sal::static_int_cast< sal_Int32 >( xSeek->getLength() );
+ if ( nSize > n_ConstDigestLength + 32 )
+ nSize = n_ConstDigestLength + 32;
// skip header
- xSeek->seek( n_ConstHeaderSize + rData->aInitVector.getLength() +
- rData->aSalt.getLength() + rData->aDigest.getLength() );
+ xSeek->seek( n_ConstHeaderSize + rData->m_aInitVector.getLength() +
+ rData->m_aSalt.getLength() + rData->m_aDigest.getLength() );
// Only want to read enough to verify the digest
Sequence < sal_Int8 > aReadBuffer ( nSize );
xStream->readBytes( aReadBuffer, nSize );
- if ( !StaticHasValidPassword( aReadBuffer, rData ) )
+ if ( !StaticHasValidPassword( xFactory, aReadBuffer, rData ) )
throw packages::WrongPasswordException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
}
- return new XUnbufferedStream ( xStream, rData );
+ return new XUnbufferedStream( xFactory, xStream, rData );
}
-sal_Bool ZipFile::StaticHasValidPassword( const Sequence< sal_Int8 > &aReadBuffer, const ORef < EncryptionData > &rData )
+#if 0
+// for debugging purposes
+void CheckSequence( const uno::Sequence< sal_Int8 >& aSequence )
{
- if ( !rData.isValid() || !rData->aKey.getLength() )
+ if ( aSequence.getLength() )
+ {
+ sal_Int32* pPointer = *( (sal_Int32**)&aSequence );
+ sal_Int32 nSize = *( pPointer + 1 );
+ sal_Int32 nMemSize = *( pPointer - 2 );
+ sal_Int32 nUsedMemSize = ( nSize + 4 * sizeof( sal_Int32 ) );
+ OSL_ENSURE( nSize == aSequence.getLength() && nUsedMemSize + 7 - ( nUsedMemSize - 1 ) % 8 == nMemSize, "Broken Sequence!" );
+ }
+}
+#endif
+
+sal_Bool ZipFile::StaticHasValidPassword( const uno::Reference< lang::XMultiServiceFactory >& xFactory, const Sequence< sal_Int8 > &aReadBuffer, const ::rtl::Reference< EncryptionData > &rData )
+{
+ if ( !rData.is() || !rData->m_aKey.getLength() )
return sal_False;
sal_Bool bRet = sal_False;
- sal_Int32 nSize = aReadBuffer.getLength();
-
- // make a temporary cipher
- rtlCipher aCipher;
- StaticGetCipher ( rData, aCipher, sal_True );
-
- Sequence < sal_Int8 > aDecryptBuffer ( nSize );
- rtlDigest aDigest = rtl_digest_createSHA1();
- rtlDigestError aDigestResult;
- Sequence < sal_uInt8 > aDigestSeq ( RTL_DIGEST_LENGTH_SHA1 );
- rtlCipherError aResult = rtl_cipher_decode ( aCipher,
- aReadBuffer.getConstArray(),
- nSize,
- reinterpret_cast < sal_uInt8 * > (aDecryptBuffer.getArray()),
- nSize);
- if(aResult != rtl_Cipher_E_None ) {
- OSL_ASSERT ( aResult == rtl_Cipher_E_None);
+
+ uno::Reference< xml::crypto::XCipherContext > xCipher( StaticGetCipher( xFactory, rData, false ), uno::UNO_SET_THROW );
+
+ uno::Sequence< sal_Int8 > aDecryptBuffer;
+ uno::Sequence< sal_Int8 > aDecryptBuffer2;
+ try
+ {
+ aDecryptBuffer = xCipher->convertWithCipherContext( aReadBuffer );
+ aDecryptBuffer2 = xCipher->finalizeCipherContextAndDispose();
+ }
+ catch( uno::Exception& )
+ {
+ // decryption with padding will throw the exception in finalizing if the buffer represent only part of the stream
+ // it is no problem, actually this is why we read 32 additional bytes ( two of maximal possible encryption blocks )
+ }
+
+ if ( aDecryptBuffer2.getLength() )
+ {
+ sal_Int32 nOldLen = aDecryptBuffer.getLength();
+ aDecryptBuffer.realloc( nOldLen + aDecryptBuffer2.getLength() );
+ rtl_copyMemory( aDecryptBuffer.getArray() + nOldLen, aDecryptBuffer2.getArray(), aDecryptBuffer2.getLength() );
}
- aDigestResult = rtl_digest_updateSHA1 ( aDigest,
- static_cast < const void * > ( aDecryptBuffer.getConstArray() ), nSize );
- OSL_ASSERT ( aDigestResult == rtl_Digest_E_None );
+ if ( aDecryptBuffer.getLength() > n_ConstDigestLength )
+ aDecryptBuffer.realloc( n_ConstDigestLength );
+
+ uno::Sequence< sal_Int8 > aDigestSeq;
+ uno::Reference< xml::crypto::XDigestContext > xDigestContext( StaticGetDigestContextForChecksum( xFactory, rData ), uno::UNO_SET_THROW );
- aDigestResult = rtl_digest_getSHA1 ( aDigest, aDigestSeq.getArray(), RTL_DIGEST_LENGTH_SHA1 );
- OSL_ASSERT ( aDigestResult == rtl_Digest_E_None );
+ xDigestContext->updateDigest( aDecryptBuffer );
+ aDigestSeq = xDigestContext->finalizeDigestAndDispose();
// If we don't have a digest, then we have to assume that the password is correct
- if ( rData->aDigest.getLength() != 0 &&
- ( aDigestSeq.getLength() != rData->aDigest.getLength() ||
+ if ( rData->m_aDigest.getLength() != 0 &&
+ ( aDigestSeq.getLength() != rData->m_aDigest.getLength() ||
0 != rtl_compareMemory ( aDigestSeq.getConstArray(),
- rData->aDigest.getConstArray(),
+ rData->m_aDigest.getConstArray(),
aDigestSeq.getLength() ) ) )
{
// We should probably tell the user that the password they entered was wrong
@@ -373,136 +492,44 @@ sal_Bool ZipFile::StaticHasValidPassword( const Sequence< sal_Int8 > &aReadBuffe
else
bRet = sal_True;
- rtl_digest_destroySHA1 ( aDigest );
-
return bRet;
}
-sal_Bool ZipFile::hasValidPassword ( ZipEntry & rEntry, const ORef < EncryptionData > &rData )
+sal_Bool ZipFile::hasValidPassword ( ZipEntry & rEntry, const ::rtl::Reference< EncryptionData >& rData )
{
::osl::MutexGuard aGuard( m_aMutex );
sal_Bool bRet = sal_False;
- if ( rData->aKey.getLength() )
+ if ( rData.is() && rData->m_aKey.getLength() )
{
xSeek->seek( rEntry.nOffset );
sal_Int32 nSize = rEntry.nMethod == DEFLATED ? rEntry.nCompressedSize : rEntry.nSize;
// Only want to read enough to verify the digest
- nSize = nSize > n_ConstDigestLength ? n_ConstDigestLength : nSize;
+ if ( nSize > n_ConstDigestDecrypt )
+ nSize = n_ConstDigestDecrypt;
+
Sequence < sal_Int8 > aReadBuffer ( nSize );
xStream->readBytes( aReadBuffer, nSize );
- bRet = StaticHasValidPassword( aReadBuffer, rData );
+ bRet = StaticHasValidPassword( m_xFactory, aReadBuffer, rData );
}
+
return bRet;
}
-#if 0
-Reference < XInputStream > ZipFile::createFileStream(
- ZipEntry & rEntry,
- const ORef < EncryptionData > &rData,
- sal_Bool bRawStream,
- sal_Bool bIsEncrypted )
-{
- static OUString sServiceName ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.io.TempFile" ) );
- Reference < XInputStream > xTempStream = Reference < XInputStream > ( xFactory->createInstance ( sServiceName ), UNO_QUERY );
- return new XFileStream ( rEntry, xStream, xTempStream, rData, bRawStream, bIsEncrypted );
-}
-Reference < XInputStream > ZipFile::createMemoryStream(
- ZipEntry & rEntry,
- const ORef < EncryptionData > &rData,
- sal_Bool bRawStream,
- sal_Bool bIsEncrypted )
-{
- sal_Int32 nUncompressedSize, nEnd;
- if (bRawStream)
- {
- nUncompressedSize = rEntry.nMethod == DEFLATED ? rEntry.nCompressedSize : rEntry.nSize;
- nEnd = rEntry.nOffset + nUncompressedSize;
- }
- else
- {
- nUncompressedSize = rEntry.nSize;
- nEnd = rEntry.nMethod == DEFLATED ? rEntry.nOffset + rEntry.nCompressedSize : rEntry.nOffset + rEntry.nSize;
- }
- sal_Int32 nSize = rEntry.nMethod == DEFLATED ? rEntry.nCompressedSize : rEntry.nSize;
- Sequence < sal_Int8 > aReadBuffer ( nSize ), aDecryptBuffer, aWriteBuffer;
- rtlCipher aCipher;
-
- // If the encryption key is zero, we need to return the raw stream. First check if
- // we have the salt. If we have the salt, then check if we have the encryption key
- // if not, return rawStream instead.
-
- sal_Bool bHaveEncryptData = ( !rData.isEmpty() && rData->aSalt.getLength() && rData->aInitVector.getLength() && rData->nIterationCount != 0 ) ? sal_True : sal_False;
- sal_Bool bMustDecrypt = ( !bRawStream && bHaveEncryptData && bIsEncrypted ) ? sal_True : sal_False;
-
- if ( bMustDecrypt )
- {
- StaticGetCipher ( rData, aCipher, sal_True );
- aDecryptBuffer.realloc ( nSize );
- }
-
- if ( nSize <0 )
- throw IOException ( );
-
- xSeek->seek( rEntry.nOffset );
- xStream->readBytes( aReadBuffer, nSize ); // Now it holds the raw stuff from disk
-
- if ( bMustDecrypt )
- {
- rtlCipherError aResult = rtl_cipher_decode ( aCipher,
- aReadBuffer.getConstArray(),
- nSize,
- reinterpret_cast < sal_uInt8 * > (aDecryptBuffer.getArray()),
- nSize);
- OSL_ASSERT (aResult == rtl_Cipher_E_None);
- aReadBuffer = aDecryptBuffer; // Now it holds the decrypted data
- }
- if (bRawStream || rEntry.nMethod == STORED)
- aWriteBuffer = aReadBuffer; // bRawStream means the caller doesn't want it decompressed
- else
- {
- aInflater.setInputSegment( aReadBuffer, 0, nSize );
- aWriteBuffer.realloc( nUncompressedSize );
- aInflater.doInflate( aWriteBuffer );
- aInflater.reset();
- }
-
- if ( bHaveEncryptData && !bMustDecrypt && bIsEncrypted )
- {
- // if we have the data needed to decrypt it, but didn't want it decrypted (or
- // we couldn't decrypt it due to wrong password), then we prepend this
- // data to the stream
-
- // Make a buffer big enough to hold both the header and the data itself
- Sequence < sal_Int8 > aEncryptedDataHeader ( n_ConstHeaderSize +
- rData->aInitVector.getLength() +
- rData->aSalt.getLength() +
- rData->aDigest.getLength() +
- aWriteBuffer.getLength() );
- sal_Int8 * pHeader = aEncryptedDataHeader.getArray();
- StaticFillHeader ( rData, rEntry.nSize, pHeader );
- memcpy ( pHeader, aWriteBuffer.getConstArray(), aWriteBuffer.getLength() );
-
- // dump old buffer and point aWriteBuffer to the new one with the header
- aWriteBuffer = aEncryptedDataHeader;
- }
- return Reference < XInputStream > ( new XMemoryStream ( aWriteBuffer ) );
-}
-#endif
-Reference < XInputStream > ZipFile::createUnbufferedStream(
+uno::Reference< XInputStream > ZipFile::createUnbufferedStream(
SotMutexHolderRef aMutexHolder,
ZipEntry & rEntry,
- const ORef < EncryptionData > &rData,
+ const ::rtl::Reference< EncryptionData > &rData,
sal_Int8 nStreamMode,
sal_Bool bIsEncrypted,
::rtl::OUString aMediaType )
{
::osl::MutexGuard aGuard( m_aMutex );
- return new XUnbufferedStream ( aMutexHolder, rEntry, xStream, rData, nStreamMode, bIsEncrypted, aMediaType, bRecoveryMode );
+ return new XUnbufferedStream ( m_xFactory, aMutexHolder, rEntry, xStream, rData, nStreamMode, bIsEncrypted, aMediaType, bRecoveryMode );
}
@@ -511,8 +538,8 @@ ZipEnumeration * SAL_CALL ZipFile::entries( )
return new ZipEnumeration ( aEntries );
}
-Reference< XInputStream > SAL_CALL ZipFile::getInputStream( ZipEntry& rEntry,
- const vos::ORef < EncryptionData > &rData,
+uno::Reference< XInputStream > SAL_CALL ZipFile::getInputStream( ZipEntry& rEntry,
+ const ::rtl::Reference< EncryptionData > &rData,
sal_Bool bIsEncrypted,
SotMutexHolderRef aMutexHolder )
throw(IOException, ZipException, RuntimeException)
@@ -529,7 +556,7 @@ Reference< XInputStream > SAL_CALL ZipFile::getInputStream( ZipEntry& rEntry,
// if we have a digest, then this file is an encrypted one and we should
// check if we can decrypt it or not
- if ( bIsEncrypted && !rData.isEmpty() && rData->aDigest.getLength() )
+ if ( bIsEncrypted && rData.is() && rData->m_aDigest.getLength() )
bNeedRawStream = !hasValidPassword ( rEntry, rData );
return createUnbufferedStream ( aMutexHolder,
@@ -539,8 +566,8 @@ Reference< XInputStream > SAL_CALL ZipFile::getInputStream( ZipEntry& rEntry,
bIsEncrypted );
}
-Reference< XInputStream > SAL_CALL ZipFile::getDataStream( ZipEntry& rEntry,
- const vos::ORef < EncryptionData > &rData,
+uno::Reference< XInputStream > SAL_CALL ZipFile::getDataStream( ZipEntry& rEntry,
+ const ::rtl::Reference< EncryptionData > &rData,
sal_Bool bIsEncrypted,
SotMutexHolderRef aMutexHolder )
throw ( packages::WrongPasswordException,
@@ -560,14 +587,14 @@ Reference< XInputStream > SAL_CALL ZipFile::getDataStream( ZipEntry& rEntry,
{
// in case no digest is provided there is no way
// to detect password correctness
- if ( rData.isEmpty() )
+ if ( !rData.is() )
throw ZipException( OUString::createFromAscii( "Encrypted stream without encryption data!\n" ),
- Reference< XInterface >() );
+ uno::Reference< XInterface >() );
// if we have a digest, then this file is an encrypted one and we should
// check if we can decrypt it or not
- OSL_ENSURE( rData->aDigest.getLength(), "Can't detect password correctness without digest!\n" );
- if ( rData->aDigest.getLength() && !hasValidPassword ( rEntry, rData ) )
+ OSL_ENSURE( rData->m_aDigest.getLength(), "Can't detect password correctness without digest!\n" );
+ if ( rData->m_aDigest.getLength() && !hasValidPassword ( rEntry, rData ) )
throw packages::WrongPasswordException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
}
else
@@ -580,8 +607,8 @@ Reference< XInputStream > SAL_CALL ZipFile::getDataStream( ZipEntry& rEntry,
bIsEncrypted );
}
-Reference< XInputStream > SAL_CALL ZipFile::getRawData( ZipEntry& rEntry,
- const vos::ORef < EncryptionData > &rData,
+uno::Reference< XInputStream > SAL_CALL ZipFile::getRawData( ZipEntry& rEntry,
+ const ::rtl::Reference< EncryptionData >& rData,
sal_Bool bIsEncrypted,
SotMutexHolderRef aMutexHolder )
throw(IOException, ZipException, RuntimeException)
@@ -594,9 +621,9 @@ Reference< XInputStream > SAL_CALL ZipFile::getRawData( ZipEntry& rEntry,
return createUnbufferedStream ( aMutexHolder, rEntry, rData, UNBUFF_STREAM_RAW, bIsEncrypted );
}
-Reference< XInputStream > SAL_CALL ZipFile::getWrappedRawStream(
+uno::Reference< XInputStream > SAL_CALL ZipFile::getWrappedRawStream(
ZipEntry& rEntry,
- const vos::ORef < EncryptionData > &rData,
+ const ::rtl::Reference< EncryptionData >& rData,
const ::rtl::OUString& aMediaType,
SotMutexHolderRef aMutexHolder )
throw ( packages::NoEncryptionException,
@@ -606,7 +633,7 @@ Reference< XInputStream > SAL_CALL ZipFile::getWrappedRawStream(
{
::osl::MutexGuard aGuard( m_aMutex );
- if ( rData.isEmpty() )
+ if ( !rData.is() )
throw packages::NoEncryptionException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
if ( rEntry.nOffset <= 0 )
@@ -628,7 +655,7 @@ sal_Bool ZipFile::readLOC( ZipEntry &rEntry )
aGrabber >> nTestSig;
if (nTestSig != LOCSIG)
- throw ZipIOException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "Invalid LOC header (bad signature") ), Reference < XInterface > () );
+ throw ZipIOException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "Invalid LOC header (bad signature") ), uno::Reference < XInterface > () );
aGrabber >> nVersion;
aGrabber >> nFlag;
aGrabber >> nHow;
@@ -665,7 +692,7 @@ sal_Bool ZipFile::readLOC( ZipEntry &rEntry )
if ( bBroken && !bRecoveryMode )
throw ZipIOException( OUString( RTL_CONSTASCII_USTRINGPARAM( "The stream seems to be broken!" ) ),
- Reference< XInterface >() );
+ uno::Reference< XInterface >() );
return sal_True;
}
@@ -699,17 +726,17 @@ sal_Int32 ZipFile::findEND( )
}
catch ( IllegalArgumentException& )
{
- throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "Zip END signature not found!") ), Reference < XInterface > () );
+ throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "Zip END signature not found!") ), uno::Reference < XInterface > () );
}
catch ( NotConnectedException& )
{
- throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "Zip END signature not found!") ), Reference < XInterface > () );
+ throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "Zip END signature not found!") ), uno::Reference < XInterface > () );
}
catch ( BufferSizeExceededException& )
{
- throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "Zip END signature not found!") ), Reference < XInterface > () );
+ throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "Zip END signature not found!") ), uno::Reference < XInterface > () );
}
- throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "Zip END signature not found!") ), Reference < XInterface > () );
+ throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "Zip END signature not found!") ), uno::Reference < XInterface > () );
}
sal_Int32 ZipFile::readCEN()
@@ -730,25 +757,25 @@ sal_Int32 ZipFile::readCEN()
aGrabber >> nCenOff;
if ( nTotal * CENHDR > nCenLen )
- throw ZipException(OUString( RTL_CONSTASCII_USTRINGPARAM ( "invalid END header (bad entry count)") ), Reference < XInterface > () );
+ throw ZipException(OUString( RTL_CONSTASCII_USTRINGPARAM ( "invalid END header (bad entry count)") ), uno::Reference < XInterface > () );
if ( nTotal > ZIP_MAXENTRIES )
- throw ZipException(OUString( RTL_CONSTASCII_USTRINGPARAM ( "too many entries in ZIP File") ), Reference < XInterface > () );
+ throw ZipException(OUString( RTL_CONSTASCII_USTRINGPARAM ( "too many entries in ZIP File") ), uno::Reference < XInterface > () );
if ( nCenLen < 0 || nCenLen > nEndPos )
- throw ZipException(OUString( RTL_CONSTASCII_USTRINGPARAM ( "Invalid END header (bad central directory size)") ), Reference < XInterface > () );
+ throw ZipException(OUString( RTL_CONSTASCII_USTRINGPARAM ( "Invalid END header (bad central directory size)") ), uno::Reference < XInterface > () );
nCenPos = nEndPos - nCenLen;
if ( nCenOff < 0 || nCenOff > nCenPos )
- throw ZipException(OUString( RTL_CONSTASCII_USTRINGPARAM ( "Invalid END header (bad central directory size)") ), Reference < XInterface > () );
+ throw ZipException(OUString( RTL_CONSTASCII_USTRINGPARAM ( "Invalid END header (bad central directory size)") ), uno::Reference < XInterface > () );
nLocPos = nCenPos - nCenOff;
aGrabber.seek( nCenPos );
Sequence < sal_Int8 > aCENBuffer ( nCenLen );
sal_Int64 nRead = aGrabber.readBytes ( aCENBuffer, nCenLen );
if ( static_cast < sal_Int64 > ( nCenLen ) != nRead )
- throw ZipException ( OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Error reading CEN into memory buffer!") ), Reference < XInterface > () );
+ throw ZipException ( OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Error reading CEN into memory buffer!") ), uno::Reference < XInterface > () );
MemoryByteGrabber aMemGrabber ( aCENBuffer );
@@ -760,19 +787,19 @@ sal_Int32 ZipFile::readCEN()
{
aMemGrabber >> nTestSig;
if ( nTestSig != CENSIG )
- throw ZipException(OUString( RTL_CONSTASCII_USTRINGPARAM ( "Invalid CEN header (bad signature)") ), Reference < XInterface > () );
+ throw ZipException(OUString( RTL_CONSTASCII_USTRINGPARAM ( "Invalid CEN header (bad signature)") ), uno::Reference < XInterface > () );
aMemGrabber.skipBytes ( 2 );
aMemGrabber >> aEntry.nVersion;
if ( ( aEntry.nVersion & 1 ) == 1 )
- throw ZipException(OUString( RTL_CONSTASCII_USTRINGPARAM ( "Invalid CEN header (encrypted entry)") ), Reference < XInterface > () );
+ throw ZipException(OUString( RTL_CONSTASCII_USTRINGPARAM ( "Invalid CEN header (encrypted entry)") ), uno::Reference < XInterface > () );
aMemGrabber >> aEntry.nFlag;
aMemGrabber >> aEntry.nMethod;
if ( aEntry.nMethod != STORED && aEntry.nMethod != DEFLATED)
- throw ZipException(OUString( RTL_CONSTASCII_USTRINGPARAM ( "Invalid CEN header (bad compression method)") ), Reference < XInterface > () );
+ throw ZipException(OUString( RTL_CONSTASCII_USTRINGPARAM ( "Invalid CEN header (bad compression method)") ), uno::Reference < XInterface > () );
aMemGrabber >> aEntry.nTime;
aMemGrabber >> aEntry.nCrc;
@@ -788,13 +815,13 @@ sal_Int32 ZipFile::readCEN()
aEntry.nOffset *= -1;
if ( aEntry.nPathLen < 0 )
- throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "unexpected name length" ) ), Reference < XInterface > () );
+ throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "unexpected name length" ) ), uno::Reference < XInterface > () );
if ( nCommentLen < 0 )
- throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "unexpected comment length" ) ), Reference < XInterface > () );
+ throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "unexpected comment length" ) ), uno::Reference < XInterface > () );
if ( aEntry.nExtraLen < 0 )
- throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "unexpected extra header info length") ), Reference < XInterface > () );
+ throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "unexpected extra header info length") ), uno::Reference < XInterface > () );
// read always in UTF8, some tools seem not to set UTF8 bit
aEntry.sPath = rtl::OUString::intern ( (sal_Char *) aMemGrabber.getCurrentPos(),
@@ -802,14 +829,14 @@ sal_Int32 ZipFile::readCEN()
RTL_TEXTENCODING_UTF8 );
if ( !::comphelper::OStorageHelper::IsValidZipEntryFileName( aEntry.sPath, sal_True ) )
- throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "Zip entry has an invalid name.") ), Reference < XInterface > () );
+ throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "Zip entry has an invalid name.") ), uno::Reference < XInterface > () );
aMemGrabber.skipBytes( aEntry.nPathLen + aEntry.nExtraLen + nCommentLen );
aEntries[aEntry.sPath] = aEntry;
}
if (nCount != nTotal)
- throw ZipException(OUString( RTL_CONSTASCII_USTRINGPARAM ( "Count != Total") ), Reference < XInterface > () );
+ throw ZipException(OUString( RTL_CONSTASCII_USTRINGPARAM ( "Count != Total") ), uno::Reference < XInterface > () );
}
catch ( IllegalArgumentException & )
{
@@ -982,15 +1009,15 @@ sal_Int32 ZipFile::recover()
}
catch ( IllegalArgumentException& )
{
- throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "Zip END signature not found!") ), Reference < XInterface > () );
+ throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "Zip END signature not found!") ), uno::Reference < XInterface > () );
}
catch ( NotConnectedException& )
{
- throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "Zip END signature not found!") ), Reference < XInterface > () );
+ throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "Zip END signature not found!") ), uno::Reference < XInterface > () );
}
catch ( BufferSizeExceededException& )
{
- throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "Zip END signature not found!") ), Reference < XInterface > () );
+ throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "Zip END signature not found!") ), uno::Reference < XInterface > () );
}
}
diff --git a/package/source/zipapi/ZipOutputStream.cxx b/package/source/zipapi/ZipOutputStream.cxx
index 16457ec12493..338feb556378 100644
--- a/package/source/zipapi/ZipOutputStream.cxx
+++ b/package/source/zipapi/ZipOutputStream.cxx
@@ -27,19 +27,22 @@
// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_package.hxx"
-#include <ZipOutputStream.hxx>
+
#include <com/sun/star/packages/zip/ZipConstants.hpp>
+#include <com/sun/star/io/XOutputStream.hpp>
+#include <comphelper/storagehelper.hxx>
+
#include <osl/time.h>
+
#include <EncryptionData.hxx>
#include <PackageConstants.hxx>
#include <ZipEntry.hxx>
#include <ZipFile.hxx>
-#include <vos/ref.hxx>
-#include <com/sun/star/io/XOutputStream.hpp>
-
-#include <comphelper/storagehelper.hxx>
+#include <ZipPackageStream.hxx>
+#include <ZipOutputStream.hxx>
using namespace rtl;
+using namespace com::sun::star;
using namespace com::sun::star::io;
using namespace com::sun::star::uno;
using namespace com::sun::star::packages;
@@ -48,17 +51,18 @@ using namespace com::sun::star::packages::zip::ZipConstants;
/** This class is used to write Zip files
*/
-ZipOutputStream::ZipOutputStream( Reference < XOutputStream > &xOStream )
-: xStream(xOStream)
-, aBuffer(n_ConstBufferSize)
+ZipOutputStream::ZipOutputStream( const uno::Reference< lang::XMultiServiceFactory >& xFactory,
+ const uno::Reference < XOutputStream > &xOStream )
+: m_xFactory( xFactory )
+, xStream(xOStream)
+, m_aDeflateBuffer(n_ConstBufferSize)
, aDeflater(DEFAULT_COMPRESSION, sal_True)
, aChucker(xOStream)
, pCurrentEntry(NULL)
, nMethod(DEFLATED)
, bFinished(sal_False)
, bEncryptCurrentEntry(sal_False)
-
-
+, m_pCurrentStream(NULL)
{
}
@@ -80,7 +84,7 @@ void SAL_CALL ZipOutputStream::setLevel( sal_Int32 nNewLevel )
}
void SAL_CALL ZipOutputStream::putNextEntry( ZipEntry& rEntry,
- vos::ORef < EncryptionData > &xEncryptData,
+ ZipPackageStream* pStream,
sal_Bool bEncrypt)
throw(IOException, RuntimeException)
{
@@ -94,18 +98,20 @@ void SAL_CALL ZipOutputStream::putNextEntry( ZipEntry& rEntry,
rEntry.nFlag = 1 << 11;
if (rEntry.nSize == -1 || rEntry.nCompressedSize == -1 ||
rEntry.nCrc == -1)
+ {
+ rEntry.nSize = rEntry.nCompressedSize = 0;
rEntry.nFlag |= 8;
+ }
if (bEncrypt)
{
bEncryptCurrentEntry = sal_True;
- ZipFile::StaticGetCipher( xEncryptData, aCipher, sal_False );
-
- aDigest = rtl_digest_createSHA1();
+ m_xCipherContext = ZipFile::StaticGetCipher( m_xFactory, pStream->GetEncryptionData(), true );
+ m_xDigestContext = ZipFile::StaticGetDigestContextForChecksum( m_xFactory, pStream->GetEncryptionData() );
mnDigested = 0;
rEntry.nFlag |= 1 << 4;
- pCurrentEncryptData = xEncryptData.getBodyPtr();
+ m_pCurrentStream = pStream;
}
sal_Int32 nLOCLength = writeLOC(rEntry);
rEntry.nOffset = static_cast < sal_Int32 > (aChucker.GetPosition()) - nLOCLength;
@@ -145,11 +151,12 @@ void SAL_CALL ZipOutputStream::closeEntry( )
}
else
{
- pEntry->nSize = aDeflater.getTotalIn();
- pEntry->nCompressedSize = aDeflater.getTotalOut();
+ if ( !bEncryptCurrentEntry )
+ {
+ pEntry->nSize = aDeflater.getTotalIn();
+ pEntry->nCompressedSize = aDeflater.getTotalOut();
+ }
pEntry->nCrc = aCRC.getValue();
- if ( bEncryptCurrentEntry )
- pEntry->nSize = pEntry->nCompressedSize;
writeEXT(*pEntry);
}
aDeflater.reset();
@@ -166,18 +173,22 @@ void SAL_CALL ZipOutputStream::closeEntry( )
if (bEncryptCurrentEntry)
{
- rtlDigestError aDigestResult;
- aEncryptionBuffer.realloc ( 0 );
bEncryptCurrentEntry = sal_False;
- rtl_cipher_destroy ( aCipher );
- pCurrentEncryptData->aDigest.realloc ( RTL_DIGEST_LENGTH_SHA1 );
- aDigestResult = rtl_digest_getSHA1 ( aDigest,
- reinterpret_cast < sal_uInt8 * > ( pCurrentEncryptData->aDigest.getArray() ),
- RTL_DIGEST_LENGTH_SHA1 );
- OSL_ASSERT( aDigestResult == rtl_Digest_E_None );
- rtl_digest_destroySHA1 ( aDigest );
+
+ m_xCipherContext.clear();
+
+ uno::Sequence< sal_Int8 > aDigestSeq;
+ if ( m_xDigestContext.is() )
+ {
+ aDigestSeq = m_xDigestContext->finalizeDigestAndDispose();
+ m_xDigestContext.clear();
+ }
+
+ if ( m_pCurrentStream )
+ m_pCurrentStream->setDigest( aDigestSeq );
}
pCurrentEntry = NULL;
+ m_pCurrentStream = NULL;
}
}
@@ -242,41 +253,53 @@ void SAL_CALL ZipOutputStream::finish( )
void ZipOutputStream::doDeflate()
{
- sal_Int32 nLength = aDeflater.doDeflateSegment(aBuffer, 0, aBuffer.getLength());
- sal_Int32 nOldLength = aBuffer.getLength();
+ sal_Int32 nLength = aDeflater.doDeflateSegment(m_aDeflateBuffer, 0, m_aDeflateBuffer.getLength());
if ( nLength > 0 )
{
- Sequence < sal_Int8 > aTmpBuffer ( aBuffer.getConstArray(), nLength );
- const void *pTmpBuffer = static_cast < const void * > ( aTmpBuffer.getConstArray() );
- if (bEncryptCurrentEntry)
+ uno::Sequence< sal_Int8 > aTmpBuffer( m_aDeflateBuffer.getConstArray(), nLength );
+ if ( bEncryptCurrentEntry && m_xDigestContext.is() && m_xCipherContext.is() )
{
// Need to update our digest before encryption...
- rtlDigestError aDigestResult = rtl_Digest_E_None;
- sal_Int16 nDiff = n_ConstDigestLength - mnDigested;
+ sal_Int32 nDiff = n_ConstDigestLength - mnDigested;
if ( nDiff )
{
- sal_Int16 nEat = static_cast < sal_Int16 > ( nDiff > nLength ? nLength : nDiff );
- aDigestResult = rtl_digest_updateSHA1 ( aDigest, pTmpBuffer, nEat );
- mnDigested = mnDigested + nEat;
+ sal_Int32 nEat = ::std::min( nLength, nDiff );
+ uno::Sequence< sal_Int8 > aTmpSeq( aTmpBuffer.getConstArray(), nEat );
+ m_xDigestContext->updateDigest( aTmpSeq );
+ mnDigested = mnDigested + static_cast< sal_Int16 >( nEat );
}
- OSL_ASSERT( aDigestResult == rtl_Digest_E_None );
-
- aEncryptionBuffer.realloc ( nLength );
- rtlCipherError aCipherResult;
- aCipherResult = rtl_cipher_encode ( aCipher, pTmpBuffer,
- nLength, reinterpret_cast < sal_uInt8 * > (aEncryptionBuffer.getArray()), nLength );
- OSL_ASSERT( aCipherResult == rtl_Cipher_E_None );
+ uno::Sequence< sal_Int8 > aEncryptionBuffer = m_xCipherContext->convertWithCipherContext( aTmpBuffer );
aChucker.WriteBytes( aEncryptionBuffer );
- aCRC.update ( aEncryptionBuffer );
- aEncryptionBuffer.realloc ( nOldLength );
+
+ // the sizes as well as checksum for encrypted streams is calculated here
+ pCurrentEntry->nCompressedSize += aEncryptionBuffer.getLength();
+ pCurrentEntry->nSize = pCurrentEntry->nCompressedSize;
+ aCRC.update( aEncryptionBuffer );
}
else
+ {
aChucker.WriteBytes ( aTmpBuffer );
+ }
+ }
+
+ if ( aDeflater.finished() && bEncryptCurrentEntry && m_xDigestContext.is() && m_xCipherContext.is() )
+ {
+ uno::Sequence< sal_Int8 > aEncryptionBuffer = m_xCipherContext->finalizeCipherContextAndDispose();
+ if ( aEncryptionBuffer.getLength() )
+ {
+ aChucker.WriteBytes( aEncryptionBuffer );
+
+ // the sizes as well as checksum for encrypted streams is calculated hier
+ pCurrentEntry->nCompressedSize += aEncryptionBuffer.getLength();
+ pCurrentEntry->nSize = pCurrentEntry->nCompressedSize;
+ aCRC.update( aEncryptionBuffer );
+ }
}
}
+
void ZipOutputStream::writeEND(sal_uInt32 nOffset, sal_uInt32 nLength)
throw(IOException, RuntimeException)
{
@@ -293,7 +316,7 @@ void ZipOutputStream::writeCEN( const ZipEntry &rEntry )
throw(IOException, RuntimeException)
{
if ( !::comphelper::OStorageHelper::IsValidZipEntryFileName( rEntry.sPath, sal_True ) )
- throw IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Unexpected character is used in file name." ) ), Reference< XInterface >() );
+ throw IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Unexpected character is used in file name." ) ), uno::Reference< XInterface >() );
::rtl::OString sUTF8Name = ::rtl::OUStringToOString( rEntry.sPath, RTL_TEXTENCODING_UTF8 );
sal_Int16 nNameLength = static_cast < sal_Int16 > ( sUTF8Name.getLength() );
@@ -342,7 +365,7 @@ sal_Int32 ZipOutputStream::writeLOC( const ZipEntry &rEntry )
throw(IOException, RuntimeException)
{
if ( !::comphelper::OStorageHelper::IsValidZipEntryFileName( rEntry.sPath, sal_True ) )
- throw IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Unexpected character is used in file name." ) ), Reference< XInterface >() );
+ throw IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Unexpected character is used in file name." ) ), uno::Reference< XInterface >() );
::rtl::OString sUTF8Name = ::rtl::OUStringToOString( rEntry.sPath, RTL_TEXTENCODING_UTF8 );
sal_Int16 nNameLength = static_cast < sal_Int16 > ( sUTF8Name.getLength() );
diff --git a/package/source/zipapi/blowfishcontext.cxx b/package/source/zipapi/blowfishcontext.cxx
new file mode 100644
index 000000000000..1739bb15cde8
--- /dev/null
+++ b/package/source/zipapi/blowfishcontext.cxx
@@ -0,0 +1,122 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_package.hxx"
+
+#include <rtl/cipher.h>
+#include <rtl/ref.hxx>
+
+#include "blowfishcontext.hxx"
+
+using namespace ::com::sun::star;
+
+// static
+uno::Reference< xml::crypto::XCipherContext > BlowfishCFB8CipherContext::Create( const uno::Sequence< sal_Int8 >& aDerivedKey, const uno::Sequence< sal_Int8 >& aInitVector, bool bEncrypt )
+{
+ ::rtl::Reference< BlowfishCFB8CipherContext > xResult = new BlowfishCFB8CipherContext();
+ xResult->m_pCipher = rtl_cipher_create( rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeStream );
+ if ( !xResult->m_pCipher )
+ throw uno::RuntimeException( ::rtl::OUString::createFromAscii( "Can not create cipher!\n" ),
+ uno::Reference< XInterface >() );
+
+ if ( rtl_Cipher_E_None != rtl_cipher_init(
+ xResult->m_pCipher,
+ bEncrypt ? rtl_Cipher_DirectionEncode : rtl_Cipher_DirectionDecode,
+ reinterpret_cast< const sal_uInt8* >( aDerivedKey.getConstArray() ),
+ aDerivedKey.getLength(),
+ reinterpret_cast< const sal_uInt8* >( aInitVector.getConstArray() ),
+ aInitVector.getLength() ) )
+ {
+ throw uno::RuntimeException( ::rtl::OUString::createFromAscii( "Can not initialize cipher!\n" ),
+ uno::Reference< XInterface >() );
+ }
+
+ xResult->m_bEncrypt = bEncrypt;
+
+ return uno::Reference< xml::crypto::XCipherContext >( xResult.get() );
+}
+
+BlowfishCFB8CipherContext::~BlowfishCFB8CipherContext()
+{
+ if ( m_pCipher )
+ {
+ rtl_cipher_destroy ( m_pCipher );
+ m_pCipher = NULL;
+ }
+}
+
+uno::Sequence< sal_Int8 > SAL_CALL BlowfishCFB8CipherContext::convertWithCipherContext( const uno::Sequence< ::sal_Int8 >& aData )
+ throw( lang::IllegalArgumentException, lang::DisposedException, uno::RuntimeException )
+{
+ ::osl::MutexGuard aGuard( m_aMutex );
+ if ( !m_pCipher )
+ throw lang::DisposedException();
+
+ uno::Sequence< sal_Int8 > aResult( aData.getLength() );
+ rtlCipherError nError = rtl_Cipher_E_None;
+
+ if ( m_bEncrypt )
+ {
+ rtl_cipher_encode( m_pCipher,
+ aData.getConstArray(),
+ aData.getLength(),
+ reinterpret_cast< sal_uInt8* >( aResult.getArray() ),
+ aResult.getLength() );
+ }
+ else
+ {
+ rtl_cipher_decode( m_pCipher,
+ aData.getConstArray(),
+ aData.getLength(),
+ reinterpret_cast< sal_uInt8* >( aResult.getArray() ),
+ aResult.getLength() );
+ }
+
+ if ( rtl_Cipher_E_None != nError )
+ {
+ throw uno::RuntimeException( ::rtl::OUString::createFromAscii( "Can not decrypt/encrypt with cipher!\n" ),
+ uno::Reference< uno::XInterface >() );
+ }
+
+ return aResult;
+}
+
+uno::Sequence< ::sal_Int8 > SAL_CALL BlowfishCFB8CipherContext::finalizeCipherContextAndDispose()
+ throw( lang::DisposedException, uno::RuntimeException )
+{
+ ::osl::MutexGuard aGuard( m_aMutex );
+ if ( !m_pCipher )
+ throw lang::DisposedException();
+
+ rtl_cipher_destroy ( m_pCipher );
+ m_pCipher = NULL;
+
+ return uno::Sequence< sal_Int8 >();
+}
+
+
diff --git a/package/source/zipapi/blowfishcontext.hxx b/package/source/zipapi/blowfishcontext.hxx
new file mode 100644
index 000000000000..49cce2fc0e65
--- /dev/null
+++ b/package/source/zipapi/blowfishcontext.hxx
@@ -0,0 +1,58 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+#ifndef _BLOWFISHCONTEXT_HXX
+#define _BLOWFISHCONTEXT_HXX
+
+#include <com/sun/star/xml/crypto/XCipherContext.hpp>
+
+#include <cppuhelper/implbase1.hxx>
+#include <osl/mutex.hxx>
+
+class BlowfishCFB8CipherContext : public cppu::WeakImplHelper1< ::com::sun::star::xml::crypto::XCipherContext >
+{
+ ::osl::Mutex m_aMutex;
+ void* m_pCipher;
+ bool m_bEncrypt;
+
+ BlowfishCFB8CipherContext()
+ : m_pCipher( NULL )
+ , m_bEncrypt( false )
+ {}
+
+public:
+
+ virtual ~BlowfishCFB8CipherContext();
+
+ static ::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XCipherContext >
+ Create( const ::com::sun::star::uno::Sequence< sal_Int8 >& aDerivedKey, const ::com::sun::star::uno::Sequence< sal_Int8 >& aInitVector, bool bEncrypt );
+
+ virtual ::com::sun::star::uno::Sequence< ::sal_Int8 > SAL_CALL convertWithCipherContext( const ::com::sun::star::uno::Sequence< ::sal_Int8 >& aData ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::DisposedException, ::com::sun::star::uno::RuntimeException);
+ virtual ::com::sun::star::uno::Sequence< ::sal_Int8 > SAL_CALL finalizeCipherContextAndDispose( ) throw (::com::sun::star::lang::DisposedException, ::com::sun::star::uno::RuntimeException);
+};
+
+#endif // _BLOWFISHCONTEXT_HXX
+
diff --git a/package/source/zipapi/makefile.mk b/package/source/zipapi/makefile.mk
index a9548ace659b..79dbb0289a1c 100644
--- a/package/source/zipapi/makefile.mk
+++ b/package/source/zipapi/makefile.mk
@@ -45,8 +45,10 @@ SLOFILES= \
$(SLO)$/CRC32.obj \
$(SLO)$/ByteChucker.obj \
$(SLO)$/ByteGrabber.obj \
+ $(SLO)$/blowfishcontext.obj \
$(SLO)$/Inflater.obj \
$(SLO)$/Deflater.obj \
+ $(SLO)$/sha1context.obj \
$(SLO)$/ZipEnumeration.obj \
$(SLO)$/ZipFile.obj \
$(SLO)$/ZipOutputStream.obj \
diff --git a/package/source/zipapi/sha1context.cxx b/package/source/zipapi/sha1context.cxx
new file mode 100644
index 000000000000..a71f20ad6f36
--- /dev/null
+++ b/package/source/zipapi/sha1context.cxx
@@ -0,0 +1,97 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_package.hxx"
+
+#include <rtl/digest.h>
+#include <rtl/ref.hxx>
+
+#include "sha1context.hxx"
+
+using namespace ::com::sun::star;
+
+// static
+uno::Reference< xml::crypto::XDigestContext > SHA1DigestContext::Create()
+{
+ ::rtl::Reference< SHA1DigestContext > xResult = new SHA1DigestContext();
+ xResult->m_pDigest = rtl_digest_createSHA1();
+ if ( !xResult->m_pDigest )
+ throw uno::RuntimeException( ::rtl::OUString::createFromAscii( "Can not create cipher!\n" ),
+ uno::Reference< XInterface >() );
+
+ return uno::Reference< xml::crypto::XDigestContext >( xResult.get() );
+}
+
+SHA1DigestContext::~SHA1DigestContext()
+{
+ if ( m_pDigest )
+ {
+ rtl_digest_destroySHA1( m_pDigest );
+ m_pDigest = NULL;
+ }
+}
+
+void SAL_CALL SHA1DigestContext::updateDigest( const uno::Sequence< ::sal_Int8 >& aData )
+ throw( lang::DisposedException, uno::RuntimeException )
+{
+ ::osl::MutexGuard aGuard( m_aMutex );
+ if ( !m_pDigest )
+ throw lang::DisposedException();
+
+ if ( rtl_Digest_E_None != rtl_digest_updateSHA1( m_pDigest, aData.getConstArray(), aData.getLength() ) )
+ {
+ rtl_digest_destroySHA1( m_pDigest );
+ m_pDigest = NULL;
+
+ throw uno::RuntimeException();
+ }
+}
+
+uno::Sequence< ::sal_Int8 > SAL_CALL SHA1DigestContext::finalizeDigestAndDispose()
+ throw( lang::DisposedException, uno::RuntimeException )
+{
+ ::osl::MutexGuard aGuard( m_aMutex );
+ if ( !m_pDigest )
+ throw lang::DisposedException();
+
+ uno::Sequence< sal_Int8 > aResult( RTL_DIGEST_LENGTH_SHA1 );
+ if ( rtl_Digest_E_None != rtl_digest_getSHA1( m_pDigest, reinterpret_cast< sal_uInt8* >( aResult.getArray() ), aResult.getLength() ) )
+ {
+ rtl_digest_destroySHA1( m_pDigest );
+ m_pDigest = NULL;
+
+ throw uno::RuntimeException();
+ }
+
+ rtl_digest_destroySHA1( m_pDigest );
+ m_pDigest = NULL;
+
+ return aResult;
+}
+
+
diff --git a/package/source/zipapi/XMemoryStream.hxx b/package/source/zipapi/sha1context.hxx
index 89db08a6c4ed..dbd1207ca792 100644
--- a/package/source/zipapi/XMemoryStream.hxx
+++ b/package/source/zipapi/sha1context.hxx
@@ -24,19 +24,34 @@
* for a copy of the LGPLv3 License.
*
************************************************************************/
-#ifndef _XMEMORY_STREAM_HXX
-#define _XMEMORY_STREAM_HXX
+#ifndef _SHA1CONTEXT_HXX
+#define _SHA1CONTEXT_HXX
-#include <ZipPackageBuffer.hxx>
+#include <com/sun/star/xml/crypto/XDigestContext.hpp>
-class ZipPackage;
+#include <cppuhelper/implbase1.hxx>
+#include <osl/mutex.hxx>
-class XMemoryStream: public ZipPackageBuffer
+class SHA1DigestContext : public cppu::WeakImplHelper1< ::com::sun::star::xml::crypto::XDigestContext >
{
+ ::osl::Mutex m_aMutex;
+ void* m_pDigest;
+
+ SHA1DigestContext()
+ : m_pDigest( NULL )
+ {}
+
public:
- XMemoryStream ( com::sun::star::uno::Sequence < sal_Int8 > & rNewBuffer );
- virtual ~XMemoryStream(void);
- virtual com::sun::star::uno::Any SAL_CALL queryInterface( const com::sun::star::uno::Type& rType )
- throw(com::sun::star::uno::RuntimeException);
+
+ virtual ~SHA1DigestContext();
+
+ static ::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XDigestContext >
+ Create();
+
+ virtual void SAL_CALL updateDigest( const ::com::sun::star::uno::Sequence< ::sal_Int8 >& aData ) throw (::com::sun::star::lang::DisposedException, ::com::sun::star::uno::RuntimeException);
+ virtual ::com::sun::star::uno::Sequence< ::sal_Int8 > SAL_CALL finalizeDigestAndDispose() throw (::com::sun::star::lang::DisposedException, ::com::sun::star::uno::RuntimeException);
+
};
-#endif
+
+#endif // _SHA1CONTEXT_HXX
+