diff options
author | Caolán McNamara <caolanm@redhat.com> | 2016-10-20 14:52:26 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2016-10-21 11:16:11 +0100 |
commit | 06916c839b16866b47235306d2db50850df0ad7c (patch) | |
tree | ff4aaeee04a2f1f654ddf8668b56a3a6c18692b2 /include/filter | |
parent | 3fabbd0a22219464545f933fc28c869a6fa89546 (diff) |
split MSCodec_Std97 into a baseclass MSCodec97
Change-Id: Ia3c41a048169c78684800def94e53fc9f3201e30
Diffstat (limited to 'include/filter')
-rw-r--r-- | include/filter/msfilter/mscodec.hxx | 154 |
1 files changed, 99 insertions, 55 deletions
diff --git a/include/filter/msfilter/mscodec.hxx b/include/filter/msfilter/mscodec.hxx index fa71a1542a29..afdf163b747b 100644 --- a/include/filter/msfilter/mscodec.hxx +++ b/include/filter/msfilter/mscodec.hxx @@ -174,18 +174,11 @@ public: virtual void Decode( sal_uInt8* pnData, std::size_t nBytes ) override; }; - -/** Encodes and decodes data from protected MSO 97+ documents. - - This is a wrapper class around low level cryptographic functions from RTL. - Implementation is based on the wvDecrypt package by Caolan McNamara: - http://www.csn.ul.ie/~caolan/docs/wvDecrypt.html - */ -class MSFILTER_DLLPUBLIC MSCodec_Std97 +class MSFILTER_DLLPUBLIC MSCodec97 { public: - explicit MSCodec_Std97(); - ~MSCodec_Std97(); + MSCodec97(rtlCipher m_hCipher); + virtual ~MSCodec97(); /** Initializes the algorithm with the encryption data. @@ -193,7 +186,7 @@ public: The sequence contains the necessary data to initialize the codec. */ - bool InitCodec( const css::uno::Sequence< css::beans::NamedValue >& aData ); + virtual bool InitCodec(const css::uno::Sequence< css::beans::NamedValue >& aData) = 0; /** Retrieves the encryption data @@ -201,38 +194,8 @@ public: The sequence contains the necessary data to initialize the codec. */ - css::uno::Sequence< css::beans::NamedValue > GetEncryptionData(); - - - /** Initializes the algorithm with the specified password and document ID. - - @param pPassData - Wide character array containing the password. Must be zero - terminated, which results in a maximum length of 15 characters. - @param pDocId - Unique document identifier read from or written to the file. - */ - void InitKey( - const sal_uInt16 pPassData[ 16 ], - const sal_uInt8 pDocId[ 16 ] ); - - /** Verifies the validity of the password using the passed salt data. - - @precond - The codec must be initialized with InitKey() before this function - can be used. - - @param pSaltData - Salt data block read from the file. - @param pSaltDigest - Salt digest read from the file. + virtual css::uno::Sequence< css::beans::NamedValue > GetEncryptionData() = 0; - @return - true = Test was successful. - */ - bool VerifyKey( - const sal_uInt8 pSaltData[ 16 ], - const sal_uInt8 pSaltDigest[ 16 ] ); /** Rekeys the codec using the specified counter. @@ -249,11 +212,7 @@ public: @param nCounter Block counter used to rekey the cipher. */ - bool InitCipher( sal_uInt32 nCounter ); - - /** Creates an MD5 digest of salt digest. */ - void CreateSaltDigest( - const sal_uInt8 nSaltData[16], sal_uInt8 nSaltDigest[16] ); + virtual bool InitCipher(sal_uInt32 nCounter) = 0; /** Encodes a block of memory. @@ -277,9 +236,8 @@ public: @return true = Encoding was successful (no error occurred). */ - bool Encode( - const void* pData, std::size_t nDatLen, - sal_uInt8* pBuffer, std::size_t nBufLen ); + bool Encode(const void* pData, std::size_t nDatLen, + sal_uInt8* pBuffer, std::size_t nBufLen); /** Decodes a block of memory. @@ -303,9 +261,8 @@ public: @return true = Decoding was successful (no error occurred). */ - bool Decode( - const void* pData, std::size_t nDatLen, - sal_uInt8* pBuffer, std::size_t nBufLen ); + bool Decode(const void* pData, std::size_t nDatLen, + sal_uInt8* pBuffer, std::size_t nBufLen); /** Lets the cipher skip a specific amount of bytes. @@ -319,7 +276,95 @@ public: @param nDatLen Number of bytes to be skipped (cipher "seeks" forward). */ - bool Skip( std::size_t nDatLen ); + bool Skip(std::size_t nDatLen); + +private: + MSCodec97(const MSCodec97&) = delete; + MSCodec97& operator=(const MSCodec97&) = delete; + +protected: + rtlCipher m_hCipher; +}; + +/** Encodes and decodes data from protected MSO 97+ documents. + + This is a wrapper class around low level cryptographic functions from RTL. + Implementation is based on the wvDecrypt package by Caolan McNamara: + http://www.csn.ul.ie/~caolan/docs/wvDecrypt.html + */ +class MSFILTER_DLLPUBLIC MSCodec_Std97 : public MSCodec97 +{ +public: + explicit MSCodec_Std97(); + ~MSCodec_Std97(); + + /** Initializes the algorithm with the encryption data. + + @param aData + The sequence contains the necessary data to initialize + the codec. + */ + virtual bool InitCodec(const css::uno::Sequence< css::beans::NamedValue >& aData) override; + + /** Retrieves the encryption data + + @return + The sequence contains the necessary data to initialize + the codec. + */ + virtual css::uno::Sequence<css::beans::NamedValue> GetEncryptionData() override; + + + /** Initializes the algorithm with the specified password and document ID. + + @param pPassData + Wide character array containing the password. Must be zero + terminated, which results in a maximum length of 15 characters. + @param pDocId + Unique document identifier read from or written to the file. + */ + void InitKey( + const sal_uInt16 pPassData[ 16 ], + const sal_uInt8 pDocId[ 16 ] ); + + /** Verifies the validity of the password using the passed salt data. + + @precond + The codec must be initialized with InitKey() before this function + can be used. + + @param pSaltData + Salt data block read from the file. + @param pSaltDigest + Salt digest read from the file. + + @return + true = Test was successful. + */ + bool VerifyKey( + const sal_uInt8 pSaltData[ 16 ], + const sal_uInt8 pSaltDigest[ 16 ] ); + + /** Rekeys the codec using the specified counter. + + After reading a specific amount of data the cipher algorithm needs to + be rekeyed using a counter that counts the data blocks. + + The block size is for example 512 Bytes for Word files and 1024 Bytes + for Excel files. + + @precond + The codec must be initialized with InitKey() before this function + can be used. + + @param nCounter + Block counter used to rekey the cipher. + */ + virtual bool InitCipher(sal_uInt32 nCounter) override; + + /** Creates an MD5 digest of salt digest. */ + void CreateSaltDigest( + const sal_uInt8 nSaltData[16], sal_uInt8 nSaltDigest[16] ); /** Gets salt data and salt digest. @@ -349,7 +394,6 @@ private: MSCodec_Std97( const MSCodec_Std97& ) = delete; MSCodec_Std97& operator=( const MSCodec_Std97& ) = delete; - rtlCipher m_hCipher; rtlDigest m_hDigest; sal_uInt8 m_pDigestValue[ RTL_DIGEST_LENGTH_MD5 ]; sal_uInt8 m_pDocId[16]; |