From 99e3106a3e2185f521930f5a42adc4e5c1287245 Mon Sep 17 00:00:00 2001 From: Mikhail Voytenko Date: Thu, 17 Mar 2011 09:16:41 +0100 Subject: mav60: #164341# support AES encryption --- package/inc/EncryptionData.hxx | 6 +++--- package/inc/PackageConstants.hxx | 22 +++++++++++++--------- package/inc/ZipFile.hxx | 26 +++++++++++++++++++++----- package/inc/ZipOutputStream.hxx | 33 ++++++++++++++++++--------------- package/inc/ZipPackageStream.hxx | 14 ++++++++------ 5 files changed, 63 insertions(+), 38 deletions(-) (limited to 'package/inc') diff --git a/package/inc/EncryptionData.hxx b/package/inc/EncryptionData.hxx index 1182ee66e14b..a3df8b550768 100644 --- a/package/inc/EncryptionData.hxx +++ b/package/inc/EncryptionData.hxx @@ -33,9 +33,9 @@ class BaseEncryptionData : public cppu::OWeakObject { public: - ::com::sun::star::uno::Sequence< sal_uInt8 > m_aSalt; - ::com::sun::star::uno::Sequence< sal_uInt8 > m_aInitVector; - ::com::sun::star::uno::Sequence< sal_uInt8 > m_aDigest; + ::com::sun::star::uno::Sequence< sal_Int8 > m_aSalt; + ::com::sun::star::uno::Sequence< sal_Int8 > m_aInitVector; + ::com::sun::star::uno::Sequence< sal_Int8 > m_aDigest; sal_Int32 m_nIterationCount; BaseEncryptionData() diff --git a/package/inc/PackageConstants.hxx b/package/inc/PackageConstants.hxx index 9314d0866cef..3695f023ec58 100644 --- a/package/inc/PackageConstants.hxx +++ b/package/inc/PackageConstants.hxx @@ -34,15 +34,19 @@ const sal_Int32 n_ConstMaxMemoryStreamSize = 20480; const sal_Int32 n_ConstDigestLength = 1024; // the constants related to the manifest.xml entries -#define PKG_MNFST_MEDIATYPE 0 -#define PKG_MNFST_VERSION 1 -#define PKG_MNFST_FULLPATH 2 - -#define PKG_MNFST_INIVECTOR 3 -#define PKG_MNFST_SALT 4 -#define PKG_MNFST_ITERATION 5 -#define PKG_MNFST_UCOMPSIZE 6 -#define PKG_MNFST_DIGEST 7 +#define PKG_MNFST_MEDIATYPE 0 +#define PKG_MNFST_VERSION 1 +#define PKG_MNFST_FULLPATH 2 + +#define PKG_MNFST_INIVECTOR 3 +#define PKG_MNFST_SALT 4 +#define PKG_MNFST_ITERATION 5 +#define PKG_MNFST_UCOMPSIZE 6 +#define PKG_MNFST_DIGEST 7 +#define PKG_MNFST_ENCALG 8 +#define PKG_MNFST_STARTALG 9 +#define PKG_MNFST_DIGESTALG 10 +#define PKG_MNFST_DERKEYSIZE 11 #define PKG_SIZE_NOENCR_MNFST 3 #define PKG_SIZE_ENCR_MNFST 8 diff --git a/package/inc/ZipFile.hxx b/package/inc/ZipFile.hxx index 7ea53e78602b..fcb5d17713c2 100644 --- a/package/inc/ZipFile.hxx +++ b/package/inc/ZipFile.hxx @@ -31,6 +31,8 @@ #include #include #include +#include +#include #include @@ -54,7 +56,6 @@ namespace com { namespace sun { namespace star { #define ZIP_MAXEXTRA 256 #define ZIP_MAXENTRIES (0x10000 - 2) -typedef void* rtlCipher; class ZipEnumeration; class ZipFile @@ -68,7 +69,7 @@ protected: Inflater aInflater; com::sun::star::uno::Reference < com::sun::star::io::XInputStream > xStream; com::sun::star::uno::Reference < com::sun::star::io::XSeekable > xSeek; - const ::com::sun::star::uno::Reference < com::sun::star::lang::XMultiServiceFactory > xFactory; + const ::com::sun::star::uno::Reference < com::sun::star::lang::XMultiServiceFactory > m_xFactory; ::com::sun::star::uno::Reference < ::com::sun::star::ucb::XProgressHandler > xProgressHandler; sal_Bool bRecoveryMode; @@ -130,7 +131,15 @@ public: SotMutexHolderRef aMutexHolder ) throw(::com::sun::star::io::IOException, ::com::sun::star::packages::zip::ZipException, ::com::sun::star::uno::RuntimeException); - static sal_Bool StaticGetCipher ( const ::rtl::Reference < EncryptionData > & xEncryptionData, rtlCipher &rCipher, sal_Bool bDecode ); + + static ::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XDigestContext > StaticGetDigestContextForChecksum( + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xArgFactory, + const ::rtl::Reference< EncryptionData >& xEncryptionData ); + + static ::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XCipherContext > StaticGetCipher( + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xArgFactory, + const ::rtl::Reference< EncryptionData >& xEncryptionData, + bool bEncrypt ); static void StaticFillHeader ( const ::rtl::Reference < EncryptionData > & rData, sal_Int32 nSize, @@ -146,14 +155,21 @@ public: ::com::sun::star::uno::Reference < com::sun::star::io::XInputStream > &rStream ); static ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > StaticGetDataFromRawStream( + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory, const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& xStream, const ::rtl::Reference < EncryptionData > &rData ) throw ( ::com::sun::star::packages::WrongPasswordException, ::com::sun::star::packages::zip::ZipIOException, ::com::sun::star::uno::RuntimeException ); - static sal_Bool StaticHasValidPassword ( const ::com::sun::star::uno::Sequence< sal_Int8 > &aReadBuffer, - const ::rtl::Reference < EncryptionData > &rData ); + static void StaticRemoveW3CPadding( + const ::rtl::Reference< EncryptionData >& rEncData, + ::com::sun::star::uno::Sequence< sal_Int8 >& o_rPaddedData ); + + static sal_Bool StaticHasValidPassword ( + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory, + const ::com::sun::star::uno::Sequence< sal_Int8 > &aReadBuffer, + const ::rtl::Reference < EncryptionData > &rData ); ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getInputStream( diff --git a/package/inc/ZipOutputStream.hxx b/package/inc/ZipOutputStream.hxx index ebfb6f52f944..b33e7c13a243 100644 --- a/package/inc/ZipOutputStream.hxx +++ b/package/inc/ZipOutputStream.hxx @@ -27,34 +27,35 @@ #ifndef _ZIP_OUTPUT_STREAM_HXX #define _ZIP_OUTPUT_STREAM_HXX +#include +#include +#include +#include +#include + #include -#ifndef _DEFLATER_HXX #include -#endif #include -#include -#ifndef RTL_DIGEST_H_ -#include -#endif #include struct ZipEntry; class ZipPackageStream; -namespace vos -{ - template < class T > class ORef; -} + class ZipOutputStream { protected: - com::sun::star::uno::Reference < com::sun::star::io::XOutputStream > xStream; + ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > m_xFactory; + ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream > xStream; + ::std::vector < ZipEntry * > aZipList; - com::sun::star::uno::Sequence < sal_Int8 > aBuffer, aEncryptionBuffer; + ::com::sun::star::uno::Sequence< sal_Int8 > aBuffer; ::rtl::OUString sComment; Deflater aDeflater; - rtlCipher aCipher; - rtlDigest aDigest; + + ::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XCipherContext > m_xCipherContext; + ::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XDigestContext > m_xDigestContext; + CRC32 aCRC; ByteChucker aChucker; ZipEntry *pCurrentEntry; @@ -63,7 +64,9 @@ protected: ZipPackageStream* m_pCurrentStream; public: - ZipOutputStream( com::sun::star::uno::Reference < com::sun::star::io::XOutputStream > &xOStream ); + ZipOutputStream( + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory, + const ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream > &xOStream ); ~ZipOutputStream(); // rawWrite to support a direct write to the output stream diff --git a/package/inc/ZipPackageStream.hxx b/package/inc/ZipPackageStream.hxx index 5ea0c82ce047..7d22bf71a86d 100644 --- a/package/inc/ZipPackageStream.hxx +++ b/package/inc/ZipPackageStream.hxx @@ -97,11 +97,13 @@ public: ::com::sun::star::uno::Sequence< sal_Int8 > GetEncryptionKey( bool bWinEncoding = false ); - const com::sun::star::uno::Sequence < sal_uInt8 >& getInitialisationVector () const + sal_Int32 GetKeyGenID(); + + const com::sun::star::uno::Sequence < sal_Int8 >& getInitialisationVector () const { return m_xBaseEncryptionData->m_aInitVector;} - const com::sun::star::uno::Sequence < sal_uInt8 >& getDigest () const + const com::sun::star::uno::Sequence < sal_Int8 >& getDigest () const { return m_xBaseEncryptionData->m_aDigest;} - const com::sun::star::uno::Sequence < sal_uInt8 >& getSalt () const + const com::sun::star::uno::Sequence < sal_Int8 >& getSalt () const { return m_xBaseEncryptionData->m_aSalt;} sal_Int32 getIterationCount () const { return m_xBaseEncryptionData->m_nIterationCount;} @@ -129,11 +131,11 @@ public: void setKey (const com::sun::star::uno::Sequence < sal_Int8 >& rNewKey ) { m_aEncryptionKey = rNewKey; m_aStorageEncryptionKeys.realloc( 0 ); } - void setInitialisationVector (const com::sun::star::uno::Sequence < sal_uInt8 >& rNewVector ) + void setInitialisationVector (const com::sun::star::uno::Sequence < sal_Int8 >& rNewVector ) { m_xBaseEncryptionData->m_aInitVector = rNewVector;} - void setSalt (const com::sun::star::uno::Sequence < sal_uInt8 >& rNewSalt ) + void setSalt (const com::sun::star::uno::Sequence < sal_Int8 >& rNewSalt ) { m_xBaseEncryptionData->m_aSalt = rNewSalt;} - void setDigest (const com::sun::star::uno::Sequence < sal_uInt8 >& rNewDigest ) + void setDigest (const com::sun::star::uno::Sequence < sal_Int8 >& rNewDigest ) { m_xBaseEncryptionData->m_aDigest = rNewDigest;} void setIterationCount (const sal_Int32 nNewCount) { m_xBaseEncryptionData->m_nIterationCount = nNewCount;} -- cgit