summaryrefslogtreecommitdiff
path: root/sc/source/filter/excel/xistream.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'sc/source/filter/excel/xistream.cxx')
-rw-r--r--sc/source/filter/excel/xistream.cxx110
1 files changed, 87 insertions, 23 deletions
diff --git a/sc/source/filter/excel/xistream.cxx b/sc/source/filter/excel/xistream.cxx
index 98db9dcb4471..534d40fa5cd5 100644
--- a/sc/source/filter/excel/xistream.cxx
+++ b/sc/source/filter/excel/xistream.cxx
@@ -28,6 +28,9 @@
// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_sc.hxx"
+#include <comphelper/docpasswordhelper.hxx>
+#include <comphelper/sequenceashashmap.hxx>
+
#include "xistream.hxx"
#include "xlstring.hxx"
#include "xiroot.hxx"
@@ -38,6 +41,8 @@ using ::rtl::OString;
using ::rtl::OUString;
using ::rtl::OUStringToOString;
+using namespace ::com::sun::star;
+
// ============================================================================
// Decryption
// ============================================================================
@@ -69,9 +74,16 @@ XclImpDecrypterRef XclImpDecrypter::Clone() const
return xNewDecr;
}
-::comphelper::DocPasswordVerifierResult XclImpDecrypter::verifyPassword( const OUString& rPassword )
+::comphelper::DocPasswordVerifierResult XclImpDecrypter::verifyPassword( const ::rtl::OUString& rPassword, uno::Sequence< beans::NamedValue >& o_rEncryptionData )
+{
+ o_rEncryptionData = OnVerifyPassword( rPassword );
+ mnError = o_rEncryptionData.getLength() ? ERRCODE_NONE : ERRCODE_ABORT;
+ return o_rEncryptionData.getLength() ? ::comphelper::DocPasswordVerifierResult_OK : ::comphelper::DocPasswordVerifierResult_WRONG_PASSWORD;
+}
+
+::comphelper::DocPasswordVerifierResult XclImpDecrypter::verifyEncryptionData( const uno::Sequence< beans::NamedValue >& rEncryptionData )
{
- bool bValid = OnVerify( rPassword );
+ bool bValid = OnVerifyEncryptionData( rEncryptionData );
mnError = bValid ? ERRCODE_NONE : ERRCODE_ABORT;
return bValid ? ::comphelper::DocPasswordVerifierResult_OK : ::comphelper::DocPasswordVerifierResult_WRONG_PASSWORD;
}
@@ -110,7 +122,6 @@ sal_uInt16 XclImpDecrypter::Read( SvStream& rStrm, void* pData, sal_uInt16 nByte
// ----------------------------------------------------------------------------
XclImpBiff5Decrypter::XclImpBiff5Decrypter( sal_uInt16 nKey, sal_uInt16 nHash ) :
- maPassword( 16 ),
mnKey( nKey ),
mnHash( nHash )
{
@@ -118,12 +129,12 @@ XclImpBiff5Decrypter::XclImpBiff5Decrypter( sal_uInt16 nKey, sal_uInt16 nHash )
XclImpBiff5Decrypter::XclImpBiff5Decrypter( const XclImpBiff5Decrypter& rSrc ) :
XclImpDecrypter( rSrc ),
- maPassword( rSrc.maPassword ),
+ maEncryptionData( rSrc.maEncryptionData ),
mnKey( rSrc.mnKey ),
mnHash( rSrc.mnHash )
{
if( IsValid() )
- maCodec.InitKey( &maPassword.front() );
+ maCodec.InitCodec( maEncryptionData );
}
XclImpBiff5Decrypter* XclImpBiff5Decrypter::OnClone() const
@@ -131,24 +142,59 @@ XclImpBiff5Decrypter* XclImpBiff5Decrypter::OnClone() const
return new XclImpBiff5Decrypter( *this );
}
-bool XclImpBiff5Decrypter::OnVerify( const OUString& rPassword )
+uno::Sequence< beans::NamedValue > XclImpBiff5Decrypter::OnVerifyPassword( const ::rtl::OUString& rPassword )
{
+ maEncryptionData.realloc( 0 );
+
/* Convert password to a byte string. TODO: this needs some finetuning
according to the spec... */
OString aBytePassword = OUStringToOString( rPassword, osl_getThreadTextEncoding() );
sal_Int32 nLen = aBytePassword.getLength();
if( (0 < nLen) && (nLen < 16) )
{
- // copy byte string to sal_uInt8 array
- maPassword.clear();
- maPassword.resize( 16, 0 );
- memcpy( &maPassword.front(), aBytePassword.getStr(), static_cast< size_t >( nLen ) );
+ // init codec
+ maCodec.InitKey( (sal_uInt8*)aBytePassword.getStr() );
+
+ if ( maCodec.VerifyKey( mnKey, mnHash ) )
+ {
+ maEncryptionData = maCodec.GetEncryptionData();
+
+ // since the export uses Std97 encryption always we have to request it here
+ ::std::vector< sal_uInt16 > aPassVect( 16 );
+ ::std::vector< sal_uInt16 >::iterator aIt = aPassVect.begin();
+ for( sal_Int32 nInd = 0; nInd < nLen; ++nInd, ++aIt )
+ *aIt = static_cast< sal_uInt16 >( rPassword.getStr()[nInd] );
+
+ uno::Sequence< sal_Int8 > aDocId = ::comphelper::DocPasswordHelper::GenerateRandomByteSequence( 16 );
+ OSL_ENSURE( aDocId.getLength() == 16, "Unexpected length of the senquence!" );
+
+ ::msfilter::MSCodec_Std97 aCodec97;
+ aCodec97.InitKey( &aPassVect.front(), (sal_uInt8*)aDocId.getConstArray() );
+
+ // merge the EncryptionData, there should be no conflicts
+ ::comphelper::SequenceAsHashMap aEncryptionHash( maEncryptionData );
+ aEncryptionHash.update( ::comphelper::SequenceAsHashMap( aCodec97.GetEncryptionData() ) );
+ aEncryptionHash >> maEncryptionData;
+ }
+ }
+
+ return maEncryptionData;
+}
+bool XclImpBiff5Decrypter::OnVerifyEncryptionData( const uno::Sequence< beans::NamedValue >& rEncryptionData )
+{
+ maEncryptionData.realloc( 0 );
+
+ if( rEncryptionData.getLength() )
+ {
// init codec
- maCodec.InitKey( &maPassword.front() );
- return maCodec.VerifyKey( mnKey, mnHash );
+ maCodec.InitCodec( rEncryptionData );
+
+ if ( maCodec.VerifyKey( mnKey, mnHash ) )
+ maEncryptionData = rEncryptionData;
}
- return false;
+
+ return maEncryptionData.getLength();
}
void XclImpBiff5Decrypter::OnUpdate( sal_Size /*nOldStrmPos*/, sal_Size nNewStrmPos, sal_uInt16 nRecSize )
@@ -168,7 +214,6 @@ sal_uInt16 XclImpBiff5Decrypter::OnRead( SvStream& rStrm, sal_uInt8* pnData, sal
XclImpBiff8Decrypter::XclImpBiff8Decrypter( sal_uInt8 pnSalt[ 16 ],
sal_uInt8 pnVerifier[ 16 ], sal_uInt8 pnVerifierHash[ 16 ] ) :
- maPassword( 16, 0 ),
maSalt( pnSalt, pnSalt + 16 ),
maVerifier( pnVerifier, pnVerifier + 16 ),
maVerifierHash( pnVerifierHash, pnVerifierHash + 16 )
@@ -177,13 +222,13 @@ XclImpBiff8Decrypter::XclImpBiff8Decrypter( sal_uInt8 pnSalt[ 16 ],
XclImpBiff8Decrypter::XclImpBiff8Decrypter( const XclImpBiff8Decrypter& rSrc ) :
XclImpDecrypter( rSrc ),
- maPassword( rSrc.maPassword ),
+ maEncryptionData( rSrc.maEncryptionData ),
maSalt( rSrc.maSalt ),
maVerifier( rSrc.maVerifier ),
maVerifierHash( rSrc.maVerifierHash )
{
if( IsValid() )
- maCodec.InitKey( &maPassword.front(), &maSalt.front() );
+ maCodec.InitCodec( maEncryptionData );
}
XclImpBiff8Decrypter* XclImpBiff8Decrypter::OnClone() const
@@ -191,25 +236,44 @@ XclImpBiff8Decrypter* XclImpBiff8Decrypter::OnClone() const
return new XclImpBiff8Decrypter( *this );
}
-bool XclImpBiff8Decrypter::OnVerify( const OUString& rPassword )
+uno::Sequence< beans::NamedValue > XclImpBiff8Decrypter::OnVerifyPassword( const ::rtl::OUString& rPassword )
{
+ maEncryptionData.realloc( 0 );
+
sal_Int32 nLen = rPassword.getLength();
if( (0 < nLen) && (nLen < 16) )
{
// copy string to sal_uInt16 array
- maPassword.clear();
- maPassword.resize( 16, 0 );
+ ::std::vector< sal_uInt16 > aPassVect( 16 );
const sal_Unicode* pcChar = rPassword.getStr();
const sal_Unicode* pcCharEnd = pcChar + nLen;
- ::std::vector< sal_uInt16 >::iterator aIt = maPassword.begin();
+ ::std::vector< sal_uInt16 >::iterator aIt = aPassVect.begin();
for( ; pcChar < pcCharEnd; ++pcChar, ++aIt )
*aIt = static_cast< sal_uInt16 >( *pcChar );
// init codec
- maCodec.InitKey( &maPassword.front(), &maSalt.front() );
- return maCodec.VerifyKey( &maVerifier.front(), &maVerifierHash.front() );
+ maCodec.InitKey( &aPassVect.front(), &maSalt.front() );
+ if ( maCodec.VerifyKey( &maVerifier.front(), &maVerifierHash.front() ) )
+ maEncryptionData = maCodec.GetEncryptionData();
+ }
+
+ return maEncryptionData;
+}
+
+bool XclImpBiff8Decrypter::OnVerifyEncryptionData( const uno::Sequence< beans::NamedValue >& rEncryptionData )
+{
+ maEncryptionData.realloc( 0 );
+
+ if( rEncryptionData.getLength() )
+ {
+ // init codec
+ maCodec.InitCodec( rEncryptionData );
+
+ if ( maCodec.VerifyKey( &maVerifier.front(), &maVerifierHash.front() ) )
+ maEncryptionData = rEncryptionData;
}
- return false;
+
+ return maEncryptionData.getLength();
}
void XclImpBiff8Decrypter::OnUpdate( sal_Size nOldStrmPos, sal_Size nNewStrmPos, sal_uInt16 /*nRecSize*/ )