From 3406cc852d8fac3aa1fedadd5ce936d72ef681eb Mon Sep 17 00:00:00 2001 From: Mathias Bauer Date: Tue, 13 Nov 2001 09:31:51 +0000 Subject: #92268#: support individually encrypted streams --- sot/inc/stg.hxx | 12 ++++++------ sot/source/sdstor/stg.cxx | 8 +++++--- sot/source/sdstor/storage.cxx | 31 ++++++++++++++++++++++++++++--- sot/source/sdstor/ucbstorage.cxx | 38 +++++++++++++++++++++++++++----------- 4 files changed, 66 insertions(+), 23 deletions(-) (limited to 'sot') diff --git a/sot/inc/stg.hxx b/sot/inc/stg.hxx index 57a1709c9c47..fc884630cbea 100644 --- a/sot/inc/stg.hxx +++ b/sot/inc/stg.hxx @@ -2,9 +2,9 @@ * * $RCSfile: stg.hxx,v $ * - * $Revision: 1.14 $ + * $Revision: 1.15 $ * - * last change: $Author: mba $ $Date: 2001-08-21 10:51:05 $ + * last change: $Author: mba $ $Date: 2001-11-13 10:28:28 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -153,7 +153,7 @@ public: virtual BOOL Revert() = 0; virtual BaseStorageStream* OpenStream( const String & rEleName, StreamMode = STREAM_STD_READWRITE, - BOOL bDirect = TRUE ) = 0; + BOOL bDirect = TRUE, const ByteString* pKey=0 ) = 0; virtual BaseStorage* OpenStorage( const String & rEleName, StreamMode = STREAM_STD_READWRITE, BOOL bDirect = FALSE ) = 0; @@ -250,7 +250,7 @@ public: virtual BOOL Revert(); virtual BaseStorageStream* OpenStream( const String & rEleName, StreamMode = STREAM_STD_READWRITE, - BOOL bDirect = TRUE ); + BOOL bDirect = TRUE, const ByteString* pKey=0 ); virtual BaseStorage* OpenStorage( const String & rEleName, StreamMode = STREAM_STD_READWRITE, BOOL bDirect = FALSE ); @@ -286,7 +286,7 @@ protected: ~UCBStorageStream(); public: TYPEINFO(); - UCBStorageStream( const String& rName, StreamMode nMode, BOOL bDirect ); + UCBStorageStream( const String& rName, StreamMode nMode, BOOL bDirect, const ByteString* pKey=0 ); UCBStorageStream( UCBStorageStream_Impl* ); virtual ULONG Read( void * pData, ULONG nSize ); @@ -352,7 +352,7 @@ public: virtual BOOL Revert(); virtual BaseStorageStream* OpenStream( const String & rEleName, StreamMode = STREAM_STD_READWRITE, - BOOL bDirect = TRUE ); + BOOL bDirect = TRUE, const ByteString* pKey=0 ); virtual BaseStorage* OpenStorage( const String & rEleName, StreamMode = STREAM_STD_READWRITE, BOOL bDirect = FALSE ); diff --git a/sot/source/sdstor/stg.cxx b/sot/source/sdstor/stg.cxx index f5b168f2237a..e663de84e161 100644 --- a/sot/source/sdstor/stg.cxx +++ b/sot/source/sdstor/stg.cxx @@ -2,9 +2,9 @@ * * $RCSfile: stg.cxx,v $ * - * $Revision: 1.9 $ + * $Revision: 1.10 $ * - * last change: $Author: mba $ $Date: 2001-02-26 16:16:55 $ + * last change: $Author: mba $ $Date: 2001-11-13 10:31:51 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -625,8 +625,10 @@ BaseStorage* Storage::OpenStorage( const String& rName, StreamMode m, BOOL bDire // Open a stream -BaseStorageStream* Storage::OpenStream( const String& rName, StreamMode m, BOOL ) +BaseStorageStream* Storage::OpenStream( const String& rName, StreamMode m, BOOL, const ByteString* pB ) { + DBG_ASSERT(!pB, "Encryption not supported"); + if( !Validate() || !ValidateMode( m ) ) return new StorageStream( pIo, NULL, m ); StgDirEntry* p = pIo->pTOC->Find( *pEntry, rName ); diff --git a/sot/source/sdstor/storage.cxx b/sot/source/sdstor/storage.cxx index 456c6acd9ce1..88eb6cd3f4c6 100644 --- a/sot/source/sdstor/storage.cxx +++ b/sot/source/sdstor/storage.cxx @@ -2,9 +2,9 @@ * * $RCSfile: storage.cxx,v $ * - * $Revision: 1.26 $ + * $Revision: 1.27 $ * - * last change: $Author: mm $ $Date: 2001-09-06 10:50:06 $ + * last change: $Author: mba $ $Date: 2001-11-13 10:31:51 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -972,12 +972,37 @@ BOOL SotStorage::Revert() |* |* Beschreibung *************************************************************************/ -SotStorageStream * SotStorage::OpenSotStream( const String & rEleName, +SotStorageStream * SotStorage::OpenEncryptedSotStream( const String & rEleName, const ByteString& rKey, StreamMode nMode, StorageMode nStorageMode ) { DBG_ASSERT( !nStorageMode, "StorageModes ignored" ) + SotStorageStream * pStm = NULL; + DBG_ASSERT( Owner(), "must be owner" ) + if( pOwnStg ) + { + // volle Ole-Patches einschalten + // egal was kommt, nur exclusiv gestattet + nMode |= STREAM_SHARE_DENYALL; + ErrCode nE = pOwnStg->GetError(); + BaseStorageStream* p = pOwnStg->OpenStream( rEleName, nMode, + (nStorageMode & STORAGE_TRANSACTED) ? FALSE : TRUE, &rKey ); + pStm = new SotStorageStream( p ); + if( !nE ) + pOwnStg->ResetError(); // kein Fehler setzen + if( nMode & STREAM_TRUNC ) + pStm->SetSize( 0 ); + } + else + SetError( SVSTREAM_GENERALERROR ); + return pStm; +} +SotStorageStream * SotStorage::OpenSotStream( const String & rEleName, + StreamMode nMode, + StorageMode nStorageMode ) +{ + DBG_ASSERT( !nStorageMode, "StorageModes ignored" ) SotStorageStream * pStm = NULL; DBG_ASSERT( Owner(), "must be owner" ) if( pOwnStg ) diff --git a/sot/source/sdstor/ucbstorage.cxx b/sot/source/sdstor/ucbstorage.cxx index 3c4174149cfe..58b9ba70adbd 100644 --- a/sot/source/sdstor/ucbstorage.cxx +++ b/sot/source/sdstor/ucbstorage.cxx @@ -2,9 +2,9 @@ * * $RCSfile: ucbstorage.cxx,v $ * - * $Revision: 1.53 $ + * $Revision: 1.54 $ * - * last change: $Author: mh $ $Date: 2001-11-06 21:36:50 $ + * last change: $Author: mba $ $Date: 2001-11-13 10:31:51 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -112,6 +112,7 @@ #include #endif +#include #include #include #include @@ -236,7 +237,7 @@ public: // reference is destroyed BOOL m_bIsOLEStorage;// an OLEStorage on a UCBStorageStream makes this an Autocommit-stream - UCBStorageStream_Impl( const String&, StreamMode, UCBStorageStream*, BOOL ); + UCBStorageStream_Impl( const String&, StreamMode, UCBStorageStream*, BOOL, const ByteString* pKey=0 ); BOOL Clear(); sal_Int16 Commit(); // if modified and commited: transfer an XInputStream to the content @@ -299,7 +300,7 @@ public: BOOL Revert(); BOOL Insert( ::ucb::Content *pContent ); UCBStorage_Impl* OpenStorage( UCBStorageElement_Impl* pElement, StreamMode nMode, BOOL bDirect ); - UCBStorageStream_Impl* OpenStream( UCBStorageElement_Impl* pElement, StreamMode nMode, BOOL bDirect ); + UCBStorageStream_Impl* OpenStream( UCBStorageElement_Impl*, StreamMode, BOOL, const ByteString* pKey=0 ); void SetProps( const Sequence < Sequence < PropertyValue > >& rSequence, const String& ); void GetProps( sal_Int32&, Sequence < Sequence < PropertyValue > >& rSequence, const String& ); sal_Int32 GetObjectCount(); @@ -413,7 +414,7 @@ BOOL UCBStorageElement_Impl::IsModified() return bModified; } -UCBStorageStream_Impl::UCBStorageStream_Impl( const String& rName, StreamMode nMode, UCBStorageStream* pStream, BOOL bDirect ) +UCBStorageStream_Impl::UCBStorageStream_Impl( const String& rName, StreamMode nMode, UCBStorageStream* pStream, BOOL bDirect, const ByteString* pKey ) : m_pAntiImpl( pStream ) , m_bModified( FALSE ) , m_bCommited( FALSE ) @@ -436,6 +437,21 @@ UCBStorageStream_Impl::UCBStorageStream_Impl( const String& rName, StreamMode nM // create the content m_pContent = new ::ucb::Content( rName, Reference< ::com::sun::star::ucb::XCommandEnvironment > () ); + if ( pKey ) + { + // stream is encrypted and should be decrypted (without setting the key we'll get the raw data) + sal_uInt8 aBuffer[RTL_DIGEST_LENGTH_SHA1]; + rtlDigestError nError = rtl_digest_SHA1( pKey->GetBuffer(), pKey->Len(), aBuffer, RTL_DIGEST_LENGTH_SHA1 ); + if ( nError == rtl_Digest_E_None ) + { + sal_uInt8* pBuffer = aBuffer; + ::com::sun::star::uno::Sequence < sal_Int8 > aSequ( (sal_Int8*) pBuffer, RTL_DIGEST_LENGTH_SHA1 ); + ::com::sun::star::uno::Any aAny; + aAny <<= aSequ; + m_pContent->setPropertyValue( ::rtl::OUString::createFromAscii("EncryptionKey"), aAny ); + } + } + // open it using ( readonly, because writing is never done directly into the original stream ) m_pSource = ::utl::UcbStreamHelper::CreateStream( rName, STREAM_STD_READ ); @@ -684,11 +700,11 @@ BOOL UCBStorageStream_Impl::Clear() return bRet; } -UCBStorageStream::UCBStorageStream( const String& rName, StreamMode nMode, BOOL bDirect ) +UCBStorageStream::UCBStorageStream( const String& rName, StreamMode nMode, BOOL bDirect, const ByteString* pKey ) { // pImp must be initialized in the body, because otherwise the vtable of the stream is not initialized // to class UCBStorageStream ! - pImp = new UCBStorageStream_Impl( rName, nMode, this, bDirect ); + pImp = new UCBStorageStream_Impl( rName, nMode, this, bDirect, pKey ); pImp->AddRef(); // use direct refcounting because in header file only a pointer should be used StorageBase::nMode = pImp->m_nMode; } @@ -2032,7 +2048,7 @@ BOOL UCBStorage::Revert() return pImp->Revert(); } -BaseStorageStream* UCBStorage::OpenStream( const String& rEleName, StreamMode nMode, BOOL bDirect ) +BaseStorageStream* UCBStorage::OpenStream( const String& rEleName, StreamMode nMode, BOOL bDirect, const ByteString* pKey ) { if( !rEleName.Len() ) return NULL; @@ -2048,7 +2064,7 @@ BaseStorageStream* UCBStorage::OpenStream( const String& rEleName, StreamMode nM String aName( pImp->m_aURL ); aName += '/'; aName += rEleName; - UCBStorageStream* pStream = new UCBStorageStream( aName, nMode, bDirect ); + UCBStorageStream* pStream = new UCBStorageStream( aName, nMode, bDirect, pKey ); pStream->SetError( GetError() ); pStream->pImp->m_aName = rEleName; return pStream; @@ -2097,12 +2113,12 @@ BaseStorageStream* UCBStorage::OpenStream( const String& rEleName, StreamMode nM return NULL; } -UCBStorageStream_Impl* UCBStorage_Impl::OpenStream( UCBStorageElement_Impl* pElement, StreamMode nMode, BOOL bDirect ) +UCBStorageStream_Impl* UCBStorage_Impl::OpenStream( UCBStorageElement_Impl* pElement, StreamMode nMode, BOOL bDirect, const ByteString* pKey ) { String aName( m_aURL ); aName += '/'; aName += pElement->m_aOriginalName; - pElement->m_xStream = new UCBStorageStream_Impl( aName, nMode, NULL, bDirect ); + pElement->m_xStream = new UCBStorageStream_Impl( aName, nMode, NULL, bDirect, pKey ); return pElement->m_xStream; } -- cgit