diff options
author | Malte Timmermann <mt@openoffice.org> | 2004-07-14 10:06:31 +0000 |
---|---|---|
committer | Malte Timmermann <mt@openoffice.org> | 2004-07-14 10:06:31 +0000 |
commit | 9a4ece8af2609336269fddd7710d01a59a99b3e3 (patch) | |
tree | 4ffb2e1f622968696d81033aa988db766974beb4 /xmlsecurity/source | |
parent | f8ceb18df9a64a49fea567aab8347988b18a0575 (diff) |
component...
Diffstat (limited to 'xmlsecurity/source')
-rw-r--r-- | xmlsecurity/source/component/documentdigitalsignatures.cxx | 96 | ||||
-rw-r--r-- | xmlsecurity/source/component/documentdigitalsignatures.hxx | 19 | ||||
-rw-r--r-- | xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx | 205 | ||||
-rw-r--r-- | xmlsecurity/source/helper/documentsignaturehelper.cxx | 235 | ||||
-rw-r--r-- | xmlsecurity/source/helper/makefile.mk | 5 | ||||
-rw-r--r-- | xmlsecurity/source/helper/xmlsignaturehelper.cxx | 14 | ||||
-rw-r--r-- | xmlsecurity/source/helper/xsecctl.hxx | 6 | ||||
-rw-r--r-- | xmlsecurity/source/helper/xsecsign.cxx | 6 |
8 files changed, 382 insertions, 204 deletions
diff --git a/xmlsecurity/source/component/documentdigitalsignatures.cxx b/xmlsecurity/source/component/documentdigitalsignatures.cxx index d000b23a33bd..1b0efa72f835 100644 --- a/xmlsecurity/source/component/documentdigitalsignatures.cxx +++ b/xmlsecurity/source/component/documentdigitalsignatures.cxx @@ -2,9 +2,9 @@ * * $RCSfile: documentdigitalsignatures.cxx,v $ * - * $Revision: 1.1.1.1 $ + * $Revision: 1.2 $ * - * last change: $Author: mt $ $Date: 2004-07-12 13:15:24 $ + * last change: $Author: mt $ $Date: 2004-07-14 11:05:44 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -66,6 +66,10 @@ #ifndef _COM_SUN_STAR_EMBED_XSTORAGE_HPP_ #include <com/sun/star/embed/XStorage.hpp> #endif +#ifndef _COM_SUN_STAR_EMBED_ELEMENTMODES_HPP_ +#include <com/sun/star/embed/ElementModes.hpp> +#endif + using namespace ::com::sun::star; @@ -77,28 +81,99 @@ DocumentDigitalSignatures::DocumentDigitalSignatures( const com::sun::star::uno: mxMSF = rxMSF; } +sal_Bool DocumentDigitalSignatures::SignDocumentContent( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& rxStorage ) throw (::com::sun::star::uno::RuntimeException) +{ + return ImplViewSignatures( rxStorage, SignatureModeDocumentContent, false ); +} + +::com::sun::star::uno::Sequence< ::com::sun::star::security::DocumentSignaturesInformation > DocumentDigitalSignatures::VerifyDocumentContentSignatures( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& rxStorage ) throw (::com::sun::star::uno::RuntimeException) +{ + return ImplVerifySignatures( rxStorage, SignatureModeDocumentContent ); +} + +void DocumentDigitalSignatures::ShowDocumentContentSignatures( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& rxStorage ) throw (::com::sun::star::uno::RuntimeException) +{ + ImplViewSignatures( rxStorage, SignatureModeDocumentContent, true ); +} + +sal_Bool DocumentDigitalSignatures::SignScriptingContent( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& rxStorage ) throw (::com::sun::star::uno::RuntimeException) +{ + return ImplViewSignatures( rxStorage, SignatureModeMacros, false ); +} + +::com::sun::star::uno::Sequence< ::com::sun::star::security::DocumentSignaturesInformation > DocumentDigitalSignatures::VerifyScriptingContentSignatures( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& rxStorage ) throw (::com::sun::star::uno::RuntimeException) +{ + return ImplVerifySignatures( rxStorage, SignatureModeMacros ); +} + +void DocumentDigitalSignatures::ShowScriptingContentSignatures( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& rxStorage ) throw (::com::sun::star::uno::RuntimeException) +{ + ImplViewSignatures( rxStorage, SignatureModeMacros, true ); +} + +sal_Bool DocumentDigitalSignatures::SignPackage( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& rxStorage ) throw (::com::sun::star::uno::RuntimeException) +{ + return ImplViewSignatures( rxStorage, SignatureModePackage, false ); +} + +::com::sun::star::uno::Sequence< ::com::sun::star::security::DocumentSignaturesInformation > DocumentDigitalSignatures::VerifyPackageSignatures( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& rxStorage ) throw (::com::sun::star::uno::RuntimeException) +{ + return ImplVerifySignatures( rxStorage, SignatureModePackage ); +} -sal_Bool DocumentDigitalSignatures::SignDocumentContent( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& rxStorage, const ::rtl::OUString& rStorageName, const ::rtl::OUString& rTokenName ) throw (::com::sun::star::uno::RuntimeException) +void DocumentDigitalSignatures::ShowPackageSignatures( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& rxStorage ) throw (::com::sun::star::uno::RuntimeException) { - DigitalSignaturesDialog aSignaturesDialog( NULL, mxMSF, SignatureModeDocumentContent ); + ImplViewSignatures( rxStorage, SignatureModePackage, true ); +} - bool bInit = aSignaturesDialog.Init( rTokenName ); +sal_Bool DocumentDigitalSignatures::ImplViewSignatures( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& rxStorage, DocumentSignatureMode eMode, bool bReadOnly ) throw (::com::sun::star::uno::RuntimeException) +{ + DigitalSignaturesDialog aSignaturesDialog( NULL, mxMSF, eMode, bReadOnly ); + bool bInit = aSignaturesDialog.Init( rtl::OUString() ); DBG_ASSERT( bInit, "Error initializing security context!" ); if ( bInit ) { aSignaturesDialog.SetStorage( rxStorage ); - aSignaturesDialog.SetSignatureFileName( rStorageName ); aSignaturesDialog.Execute(); } - return 0; + return aSignaturesDialog.SignaturesChanged(); } -::com::sun::star::uno::Sequence< ::com::sun::star::security::DocumentSignaturesInformation > DocumentDigitalSignatures::VerifyDocumentContentSignatures( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& Storage, const ::rtl::OUString& StorageName, const ::rtl::OUString& rTokenName ) throw (::com::sun::star::uno::RuntimeException) +com::sun::star::uno::Sequence< ::com::sun::star::security::DocumentSignaturesInformation > DocumentDigitalSignatures::ImplVerifySignatures( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& rxStorage, DocumentSignatureMode eMode ) throw (::com::sun::star::uno::RuntimeException) { + std::vector< rtl::OUString > aElementsToBeVerified = DocumentSignatureHelper::CreateElementList( rxStorage, ::rtl::OUString(), eMode ); + + XMLSignatureHelper aSignatureHelper( mxMSF ); + aSignatureHelper.Init( rtl::OUString() ); + aSignatureHelper.SetStorage( rxStorage ); + + aSignatureHelper.StartMission(); + + SignatureStreamHelper aStreamHelper = DocumentSignatureHelper::OpenSignatureStream( rxStorage, embed::ElementModes::READ, eMode ); + if ( aStreamHelper.xSignatureStream.is() ) + { + uno::Reference< io::XInputStream > xInputStream( aStreamHelper.xSignatureStream, uno::UNO_QUERY ); + bool bVerifyOK = aSignatureHelper.ReadAndVerifySignature( xInputStream ); + + if ( bVerifyOK ) + { + // SignatureInformations aInformations = aSignatureHelper.GetSignatureInformations(); + // ... + } + } + + aStreamHelper.Clear(); + + aSignatureHelper.EndMission(); + + // MT: LATER... + // = aHelper.GetSignatureInformations(); + ::com::sun::star::uno::Sequence< ::com::sun::star::security::DocumentSignaturesInformation > aInfos; return aInfos; + } rtl::OUString DocumentDigitalSignatures::GetImplementationName() throw (uno::RuntimeException) @@ -106,7 +181,7 @@ rtl::OUString DocumentDigitalSignatures::GetImplementationName() throw (uno::Run return rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.security.DocumentDigitalSignatures" ) ); } -uno::Sequence< rtl::OUString > SAL_CALL DocumentDigitalSignatures::GetSupportedServiceNames() throw (cssu::RuntimeException) +uno::Sequence< rtl::OUString > DocumentDigitalSignatures::GetSupportedServiceNames() throw (cssu::RuntimeException) { uno::Sequence < rtl::OUString > aRet(1); rtl::OUString* pArray = aRet.getArray(); @@ -115,9 +190,8 @@ uno::Sequence< rtl::OUString > SAL_CALL DocumentDigitalSignatures::GetSupportedS } -com::sun::star::uno::Reference< com::sun::star::uno::XInterface > SAL_CALL DocumentDigitalSignatures_CreateInstance( +com::sun::star::uno::Reference< com::sun::star::uno::XInterface > DocumentDigitalSignatures_CreateInstance( const com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >& rSMgr) throw ( com::sun::star::uno::Exception ) { return (cppu::OWeakObject*) new DocumentDigitalSignatures( rSMgr ); } - diff --git a/xmlsecurity/source/component/documentdigitalsignatures.hxx b/xmlsecurity/source/component/documentdigitalsignatures.hxx index 50d10ad85084..96f874129b91 100644 --- a/xmlsecurity/source/component/documentdigitalsignatures.hxx +++ b/xmlsecurity/source/component/documentdigitalsignatures.hxx @@ -2,9 +2,9 @@ * * $RCSfile: documentdigitalsignatures.hxx,v $ * - * $Revision: 1.1.1.1 $ + * $Revision: 1.2 $ * - * last change: $Author: mt $ $Date: 2004-07-12 13:15:24 $ + * last change: $Author: mt $ $Date: 2004-07-14 11:05:45 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -65,6 +65,7 @@ #include <cppuhelper/implbase1.hxx> #include <com/sun/star/security/XDocumentDigitalSignatures.hpp> +#include <xmlsecurity/documentsignaturehelper.hxx> class DocumentDigitalSignatures : public cppu::WeakImplHelper1 @@ -75,6 +76,9 @@ class DocumentDigitalSignatures : public cppu::WeakImplHelper1 private: com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > mxMSF; + sal_Bool ImplViewSignatures( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& rxStorage, DocumentSignatureMode eMode, bool bReadOnly ) throw (::com::sun::star::uno::RuntimeException); + com::sun::star::uno::Sequence< ::com::sun::star::security::DocumentSignaturesInformation > ImplVerifySignatures( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& rxStorage, DocumentSignatureMode eMode ) throw (::com::sun::star::uno::RuntimeException); + public: DocumentDigitalSignatures( const com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory> rxMSF ); @@ -83,8 +87,15 @@ public: static ::com::sun::star::uno::Sequence < ::rtl::OUString > GetSupportedServiceNames() throw (com::sun::star::uno::RuntimeException); // XDocumentDigitalSignatures - virtual sal_Bool SAL_CALL SignDocumentContent( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& Storage, const ::rtl::OUString& StorageName, const ::rtl::OUString& rTokenName ) throw (::com::sun::star::uno::RuntimeException); - virtual ::com::sun::star::uno::Sequence< ::com::sun::star::security::DocumentSignaturesInformation > SAL_CALL VerifyDocumentContentSignatures( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& Storage, const ::rtl::OUString& StorageName, const ::rtl::OUString& rTokenName ) throw (::com::sun::star::uno::RuntimeException); + sal_Bool SAL_CALL SignDocumentContent( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& rxStorage ) throw (::com::sun::star::uno::RuntimeException); + com::sun::star::uno::Sequence< ::com::sun::star::security::DocumentSignaturesInformation > SAL_CALL VerifyDocumentContentSignatures( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& rxStorage ) throw (::com::sun::star::uno::RuntimeException); + void SAL_CALL ShowDocumentContentSignatures( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& Storage ) throw (::com::sun::star::uno::RuntimeException); + sal_Bool SAL_CALL SignScriptingContent( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& rxStorage ) throw (::com::sun::star::uno::RuntimeException); + com::sun::star::uno::Sequence< ::com::sun::star::security::DocumentSignaturesInformation > SAL_CALL VerifyScriptingContentSignatures( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& rxStorage ) throw (::com::sun::star::uno::RuntimeException); + void SAL_CALL ShowScriptingContentSignatures( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& Storage ) throw (::com::sun::star::uno::RuntimeException); + sal_Bool SAL_CALL SignPackage( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& rxStorage ) throw (::com::sun::star::uno::RuntimeException); + com::sun::star::uno::Sequence< ::com::sun::star::security::DocumentSignaturesInformation > SAL_CALL VerifyPackageSignatures( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& rxStorage ) throw (::com::sun::star::uno::RuntimeException); + void SAL_CALL ShowPackageSignatures( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& Storage ) throw (::com::sun::star::uno::RuntimeException); }; diff --git a/xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx b/xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx index bcabfa2b04c6..c1a617c82fab 100644 --- a/xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx +++ b/xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx @@ -2,9 +2,9 @@ * * $RCSfile: digitalsignaturesdialog.cxx,v $ * - * $Revision: 1.2 $ + * $Revision: 1.3 $ * - * last change: $Author: mt $ $Date: 2004-07-13 11:02:46 $ + * last change: $Author: mt $ $Date: 2004-07-14 11:05:45 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -90,7 +90,7 @@ using namespace ::com::sun::star::security; using namespace ::com::sun::star; using namespace ::com::sun::star; -DigitalSignaturesDialog::DigitalSignaturesDialog( Window* pParent, uno::Reference< lang::XMultiServiceFactory >& rxMSF, DocumentSignatureMode eMode ) +DigitalSignaturesDialog::DigitalSignaturesDialog( Window* pParent, uno::Reference< lang::XMultiServiceFactory >& rxMSF, DocumentSignatureMode eMode, sal_Bool bReadOnly ) :ModalDialog ( pParent, XMLSEC_RES( RID_XMLSECDLG_DIGSIG ) ) ,maSignatureHelper ( rxMSF ) ,meSignatureMode ( eMode ) @@ -112,6 +112,7 @@ DigitalSignaturesDialog::DigitalSignaturesDialog( Window* pParent, uno::Referenc FreeResource(); mbVerifySignatures = true; + mbSignaturesChanged = false; maSignaturesLB.SetSelectHdl( LINK( this, DigitalSignaturesDialog, SignatureHighlightHdl ) ); maSignaturesLB.SetDoubleClickHdl( LINK( this, DigitalSignaturesDialog, SignatureSelectHdl ) ); @@ -120,6 +121,8 @@ DigitalSignaturesDialog::DigitalSignaturesDialog( Window* pParent, uno::Referenc maViewBtn.Disable(); maAddBtn.SetClickHdl( LINK( this, DigitalSignaturesDialog, AddButtonHdl ) ); + if ( bReadOnly ) + maAddBtn.Disable(); maRemoveBtn.SetClickHdl( LINK( this, DigitalSignaturesDialog, RemoveButtonHdl ) ); maRemoveBtn.Disable(); @@ -176,9 +179,11 @@ short DigitalSignaturesDialog::Execute() IMPL_LINK( DigitalSignaturesDialog, SignatureHighlightHdl, void*, EMPTYARG ) { - bool bSel = maSignaturesLB.FirstSelected() != 0; + bool bSel = maSignaturesLB.FirstSelected() ? true : false; maViewBtn.Enable( bSel ); - maRemoveBtn.Enable( bSel ); + if ( maAddBtn.IsEnabled() ) // not read only + maRemoveBtn.Enable( bSel ); + return 0; } @@ -212,7 +217,7 @@ IMPL_LINK( DigitalSignaturesDialog, AddButtonHdl, Button*, EMPTYARG ) uno::Reference< ::com::sun::star::security::XCertificate > xCert = aChooser.GetSelectedCertificate(); maSignatureHelper.SetX509Certificate( nSecurityId, xCert->getIssuerName(), bigIntegerToNumericString( xCert->getSerialNumber() ) ); - std::vector< rtl::OUString > aElements = CreateElementList( mxStore, rtl::OUString(), meSignatureMode ); + std::vector< rtl::OUString > aElements = DocumentSignatureHelper::CreateElementList( mxStore, rtl::OUString(), meSignatureMode ); ::rtl::OUString aXMLExt( RTL_CONSTASCII_USTRINGPARAM( "XML" ) ); sal_Int32 nElements = aElements.size(); @@ -229,7 +234,7 @@ IMPL_LINK( DigitalSignaturesDialog, AddButtonHdl, Button*, EMPTYARG ) maSignatureHelper.AddForSigning( nSecurityId, aElements[n], aElements[n], bBinaryMode ); } - SignatureStreamHelper aStreamHelper = OpenSignatureStream( mxStore, embed::ElementModes::WRITE|embed::ElementModes::TRUNCATE, meSignatureMode ); + SignatureStreamHelper aStreamHelper = DocumentSignatureHelper::OpenSignatureStream( mxStore, embed::ElementModes::WRITE|embed::ElementModes::TRUNCATE, meSignatureMode ); uno::Reference< io::XOutputStream > xOutputStream( aStreamHelper.xSignatureStream, uno::UNO_QUERY ); uno::Reference< com::sun::star::xml::sax::XDocumentHandler> xDocumentHandler = maSignatureHelper.CreateDocumentHandlerWithHeader( xOutputStream ); @@ -239,28 +244,31 @@ IMPL_LINK( DigitalSignaturesDialog, AddButtonHdl, Button*, EMPTYARG ) maSignatureHelper.ExportSignature( xDocumentHandler, aCurrentSignatureInformations[n]); // Create a new one... - bool bDone = maSignatureHelper.CreateAndWriteSignatue( xDocumentHandler ); + bool bDone = maSignatureHelper.CreateAndWriteSignature( xDocumentHandler ); // That's it... maSignatureHelper.CloseDocumentHandler( xDocumentHandler); - uno::Reference< embed::XTransactedObject > xTrans( aStreamHelper.xSignatureStorage, uno::UNO_QUERY ); - xTrans->commit(); - - uno::Reference< embed::XTransactedObject > xTrans2( mxStore, uno::UNO_QUERY ); - xTrans2->commit(); - - aStreamHelper.Dispose(); - maSignatureHelper.EndMission(); if ( bDone ) { + uno::Reference< embed::XTransactedObject > xTrans( aStreamHelper.xSignatureStorage, uno::UNO_QUERY ); + xTrans->commit(); + + uno::Reference< embed::XTransactedObject > xTrans2( mxStore, uno::UNO_QUERY ); + xTrans2->commit(); + + aStreamHelper.Clear(); + + mbSignaturesChanged = true; + // Can't simply remember current information, need parsing for getting full information :( ImplGetSignatureInformations(); ImplFillSignaturesBox(); } + aStreamHelper.Clear(); } } catch (NoPasswordException&) @@ -278,7 +286,7 @@ IMPL_LINK( DigitalSignaturesDialog, RemoveButtonHdl, Button*, EMPTYARG ) aCurrentSignatureInformations.erase( aCurrentSignatureInformations.begin()+nSelected ); // Export all other signatures... - SignatureStreamHelper aStreamHelper = OpenSignatureStream( mxStore, embed::ElementModes::WRITE|embed::ElementModes::TRUNCATE, meSignatureMode ); + SignatureStreamHelper aStreamHelper = DocumentSignatureHelper::OpenSignatureStream( mxStore, embed::ElementModes::WRITE|embed::ElementModes::TRUNCATE, meSignatureMode ); uno::Reference< io::XOutputStream > xOutputStream( aStreamHelper.xSignatureStream, uno::UNO_QUERY ); uno::Reference< com::sun::star::xml::sax::XDocumentHandler> xDocumentHandler = maSignatureHelper.CreateDocumentHandlerWithHeader( xOutputStream ); @@ -294,7 +302,9 @@ IMPL_LINK( DigitalSignaturesDialog, RemoveButtonHdl, Button*, EMPTYARG ) uno::Reference< embed::XTransactedObject > xTrans2( mxStore, uno::UNO_QUERY ); xTrans2->commit(); - aStreamHelper.Dispose(); + mbSignaturesChanged = true; + + aStreamHelper.Clear(); ImplFillSignaturesBox(); } @@ -358,17 +368,17 @@ void DigitalSignaturesDialog::ImplGetSignatureInformations() maSignatureHelper.StartMission(); - SignatureStreamHelper aStreamHelper = OpenSignatureStream( mxStore, embed::ElementModes::READ, meSignatureMode ); + SignatureStreamHelper aStreamHelper = DocumentSignatureHelper::OpenSignatureStream( mxStore, embed::ElementModes::READ, meSignatureMode ); if ( aStreamHelper.xSignatureStream.is() ) { uno::Reference< io::XInputStream > xInputStream( aStreamHelper.xSignatureStream, uno::UNO_QUERY ); - bool bVerifyOK = maSignatureHelper.ReadAndVerifySignatue( xInputStream ); + bool bVerifyOK = maSignatureHelper.ReadAndVerifySignature( xInputStream ); if ( bVerifyOK ) aCurrentSignatureInformations = maSignatureHelper.GetSignatureInformations(); } - aStreamHelper.Dispose(); + aStreamHelper.Clear(); maSignatureHelper.EndMission(); @@ -394,156 +404,3 @@ void DigitalSignaturesDialog::ImplShowSignaturesDetails() aViewer.Execute(); } } - -void ImplFillElementList( std::vector< rtl::OUString >& rList, uno::Reference < embed::XStorage >& rxStore, const ::rtl::OUString rRootStorageName, bool bRecursive ) -{ - ::rtl::OUString aMetaInfName( RTL_CONSTASCII_USTRINGPARAM( "META-INF" ) ); - ::rtl::OUString aSep( RTL_CONSTASCII_USTRINGPARAM( "/" ) ); - - uno::Reference < container::XNameAccess > xElements( rxStore, uno::UNO_QUERY ); - uno::Sequence< ::rtl::OUString > aElements = xElements->getElementNames(); - sal_Int32 nElements = aElements.getLength(); - const ::rtl::OUString* pNames = aElements.getConstArray(); - for ( sal_Int32 n = 0; n < nElements; n++ ) - { - if ( pNames[n] != aMetaInfName ) - { - if ( rxStore->isStreamElement( pNames[n] ) ) - { - ::rtl::OUString aFullName( rRootStorageName + pNames[n] ); - rList.push_back( aFullName ); - } - else if ( bRecursive && rxStore->isStorageElement( pNames[n] ) ) - { - uno::Reference < embed::XStorage > xSubStore = rxStore->openStorageElement( pNames[n], embed::ElementModes::READ ); - rtl::OUString aFullRootName( rRootStorageName + pNames[n] + aSep ); - ImplFillElementList( rList, rxStore, aFullRootName, bRecursive ); - } - } - } -} - -std::vector< rtl::OUString > DigitalSignaturesDialog::CreateElementList( uno::Reference < embed::XStorage >& rxStore, const ::rtl::OUString rRootStorageName, DocumentSignatureMode eMode ) -{ - std::vector< rtl::OUString > aElements; - ::rtl::OUString aSep( RTL_CONSTASCII_USTRINGPARAM( "/" ) ); - - - switch ( eMode ) - { - case SignatureModeDocumentContent: - { - // 1) Main content - ImplFillElementList( aElements, rxStore, ::rtl::OUString(), false ); - - // 2) Pictures... - rtl::OUString aSubStorageName( rtl::OUString::createFromAscii( "Pictures" ) ); - try - { - uno::Reference < embed::XStorage > xSubStore = rxStore->openStorageElement( aSubStorageName, embed::ElementModes::READ ); - ImplFillElementList( aElements, xSubStore, aSubStorageName+aSep, true ); - } - catch( com::sun::star::io::IOException& ) - { - ; // Doesn't have to exist... - } - } - break; - case SignatureModeMacros: - { - // 1) Macros - rtl::OUString aSubStorageName( rtl::OUString::createFromAscii( "Basic" ) ); - try - { - uno::Reference < embed::XStorage > xSubStore = rxStore->openStorageElement( aSubStorageName, embed::ElementModes::READ ); - ImplFillElementList( aElements, xSubStore, aSubStorageName+aSep, true ); - } - catch( com::sun::star::io::IOException& ) - { - ; // Doesn't have to exist... - } - - // 2) Dialogs - aSubStorageName = rtl::OUString::createFromAscii( "Dialogs") ; - try - { - uno::Reference < embed::XStorage > xSubStore = rxStore->openStorageElement( aSubStorageName, embed::ElementModes::READ ); - ImplFillElementList( aElements, xSubStore, aSubStorageName+aSep, true ); - } - catch( com::sun::star::io::IOException& ) - { - ; // Doesn't have to exist... - } - } - break; - case SignatureModePackage: - { - // Everything except META-INF - ImplFillElementList( aElements, rxStore, ::rtl::OUString(), true ); - } - break; - } - - return aElements; -} - -SignatureStreamHelper DigitalSignaturesDialog::OpenSignatureStream( uno::Reference < embed::XStorage >& rxStore, sal_Int32 nOpenMode, DocumentSignatureMode eDocSigMode ) -{ - sal_Int32 nSubStorageOpenMode = embed::ElementModes::READ; - if ( nOpenMode & embed::ElementModes::WRITE ) - nSubStorageOpenMode = embed::ElementModes::WRITE; - - SignatureStreamHelper aHelper; - - try - { - ::rtl::OUString aSIGStoreName( RTL_CONSTASCII_USTRINGPARAM( "META-INF" ) ); - aHelper.xSignatureStorage = rxStore->openStorageElement( aSIGStoreName, nSubStorageOpenMode ); - if ( aHelper.xSignatureStorage.is() ) - { - ::rtl::OUString aSIGStreamName; - if ( eDocSigMode == SignatureModeDocumentContent ) - aSIGStreamName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DocumentSignatures.xml" ) ); - else if ( eDocSigMode == SignatureModeMacros ) - aSIGStreamName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MacroSignatures.xml" ) ); - else - aSIGStreamName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PackageSignatures.xml" ) ); - - aHelper.xSignatureStream = aHelper.xSignatureStorage->openStreamElement( aSIGStreamName, nOpenMode ); - } - } - catch( com::sun::star::io::IOException& ) - { - // Doesn't have to exist... - DBG_ASSERT( nOpenMode == embed::ElementModes::READ, "Error creating signature stream..." ); - } - - return aHelper; -} - -void SignatureStreamHelper::Dispose() -{ - if ( xSignatureStorage.is() ) - { - try - { - uno::Reference< lang::XComponent > xComp( xSignatureStorage, uno::UNO_QUERY ); - xComp->dispose(); - } - catch ( lang::DisposedException ) - { - } - } - - if ( xSignatureStream.is() ) - { - try - { - uno::Reference< lang::XComponent > xComp( xSignatureStream, uno::UNO_QUERY ); - xComp->dispose(); - } - catch ( lang::DisposedException ) - { - } - } -}
\ No newline at end of file diff --git a/xmlsecurity/source/helper/documentsignaturehelper.cxx b/xmlsecurity/source/helper/documentsignaturehelper.cxx new file mode 100644 index 000000000000..931162e7fcb0 --- /dev/null +++ b/xmlsecurity/source/helper/documentsignaturehelper.cxx @@ -0,0 +1,235 @@ +/************************************************************************* + * + * $RCSfile: documentsignaturehelper.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: mt $ $Date: 2004-07-14 11:06:31 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#include <xmlsecurity/documentsignaturehelper.hxx> + +#include <com/sun/star/container/XNameAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/lang/DisposedException.hpp> + +#ifndef _COM_SUN_STAR_EMBED_XSTORAGE_HPP_ +#include <com/sun/star/embed/XStorage.hpp> +#endif +#ifndef _COM_SUN_STAR_EMBED_ELEMENTMODES_HPP_ +#include <com/sun/star/embed/ElementModes.hpp> +#endif + +#include <tools/debug.hxx> + +using namespace ::com::sun::star; + + +void ImplFillElementList( std::vector< rtl::OUString >& rList, const uno::Reference < embed::XStorage >& rxStore, const ::rtl::OUString rRootStorageName, bool bRecursive ) +{ + ::rtl::OUString aMetaInfName( RTL_CONSTASCII_USTRINGPARAM( "META-INF" ) ); + ::rtl::OUString aSep( RTL_CONSTASCII_USTRINGPARAM( "/" ) ); + + uno::Reference < container::XNameAccess > xElements( rxStore, uno::UNO_QUERY ); + uno::Sequence< ::rtl::OUString > aElements = xElements->getElementNames(); + sal_Int32 nElements = aElements.getLength(); + const ::rtl::OUString* pNames = aElements.getConstArray(); + for ( sal_Int32 n = 0; n < nElements; n++ ) + { + if ( pNames[n] != aMetaInfName ) + { + if ( rxStore->isStreamElement( pNames[n] ) ) + { + ::rtl::OUString aFullName( rRootStorageName + pNames[n] ); + rList.push_back( aFullName ); + } + else if ( bRecursive && rxStore->isStorageElement( pNames[n] ) ) + { + uno::Reference < embed::XStorage > xSubStore = rxStore->openStorageElement( pNames[n], embed::ElementModes::READ ); + rtl::OUString aFullRootName( rRootStorageName + pNames[n] + aSep ); + ImplFillElementList( rList, rxStore, aFullRootName, bRecursive ); + } + } + } +} + +std::vector< rtl::OUString > DocumentSignatureHelper::CreateElementList( const uno::Reference < embed::XStorage >& rxStore, const ::rtl::OUString rRootStorageName, DocumentSignatureMode eMode ) +{ + std::vector< rtl::OUString > aElements; + ::rtl::OUString aSep( RTL_CONSTASCII_USTRINGPARAM( "/" ) ); + + + switch ( eMode ) + { + case SignatureModeDocumentContent: + { + // 1) Main content + ImplFillElementList( aElements, rxStore, ::rtl::OUString(), false ); + + // 2) Pictures... + rtl::OUString aSubStorageName( rtl::OUString::createFromAscii( "Pictures" ) ); + try + { + uno::Reference < embed::XStorage > xSubStore = rxStore->openStorageElement( aSubStorageName, embed::ElementModes::READ ); + ImplFillElementList( aElements, xSubStore, aSubStorageName+aSep, true ); + } + catch( com::sun::star::io::IOException& ) + { + ; // Doesn't have to exist... + } + } + break; + case SignatureModeMacros: + { + // 1) Macros + rtl::OUString aSubStorageName( rtl::OUString::createFromAscii( "Basic" ) ); + try + { + uno::Reference < embed::XStorage > xSubStore = rxStore->openStorageElement( aSubStorageName, embed::ElementModes::READ ); + ImplFillElementList( aElements, xSubStore, aSubStorageName+aSep, true ); + } + catch( com::sun::star::io::IOException& ) + { + ; // Doesn't have to exist... + } + + // 2) Dialogs + aSubStorageName = rtl::OUString::createFromAscii( "Dialogs") ; + try + { + uno::Reference < embed::XStorage > xSubStore = rxStore->openStorageElement( aSubStorageName, embed::ElementModes::READ ); + ImplFillElementList( aElements, xSubStore, aSubStorageName+aSep, true ); + } + catch( com::sun::star::io::IOException& ) + { + ; // Doesn't have to exist... + } + } + break; + case SignatureModePackage: + { + // Everything except META-INF + ImplFillElementList( aElements, rxStore, ::rtl::OUString(), true ); + } + break; + } + + return aElements; +} + +SignatureStreamHelper DocumentSignatureHelper::OpenSignatureStream( const uno::Reference < embed::XStorage >& rxStore, sal_Int32 nOpenMode, DocumentSignatureMode eDocSigMode ) +{ + sal_Int32 nSubStorageOpenMode = embed::ElementModes::READ; + if ( nOpenMode & embed::ElementModes::WRITE ) + nSubStorageOpenMode = embed::ElementModes::WRITE; + + SignatureStreamHelper aHelper; + + try + { + ::rtl::OUString aSIGStoreName( RTL_CONSTASCII_USTRINGPARAM( "META-INF" ) ); + aHelper.xSignatureStorage = rxStore->openStorageElement( aSIGStoreName, nSubStorageOpenMode ); + if ( aHelper.xSignatureStorage.is() ) + { + ::rtl::OUString aSIGStreamName; + if ( eDocSigMode == SignatureModeDocumentContent ) + aSIGStreamName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DocumentSignatures.xml" ) ); + else if ( eDocSigMode == SignatureModeMacros ) + aSIGStreamName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MacroSignatures.xml" ) ); + else + aSIGStreamName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PackageSignatures.xml" ) ); + + aHelper.xSignatureStream = aHelper.xSignatureStorage->openStreamElement( aSIGStreamName, nOpenMode ); + } + } + catch( com::sun::star::io::IOException& ) + { + // Doesn't have to exist... + DBG_ASSERT( nOpenMode == embed::ElementModes::READ, "Error creating signature stream..." ); + } + + return aHelper; +} + +void SignatureStreamHelper::Clear() +{ + // MT: bug in storage implementation, shouldn't be necessary + if ( xSignatureStorage.is() ) + { + try + { + uno::Reference< lang::XComponent > xComp( xSignatureStorage, uno::UNO_QUERY ); + xComp->dispose(); + } + catch ( lang::DisposedException ) + { + } + } + + if ( xSignatureStream.is() ) + { + try + { + uno::Reference< lang::XComponent > xComp( xSignatureStream, uno::UNO_QUERY ); + xComp->dispose(); + } + catch ( lang::DisposedException ) + { + } + } + + xSignatureStream = NULL; + xSignatureStorage = NULL; +} diff --git a/xmlsecurity/source/helper/makefile.mk b/xmlsecurity/source/helper/makefile.mk index 0d5fec4a5bdb..b896d18927d2 100644 --- a/xmlsecurity/source/helper/makefile.mk +++ b/xmlsecurity/source/helper/makefile.mk @@ -2,9 +2,9 @@ # # $RCSfile: makefile.mk,v $ # -# $Revision: 1.1.1.1 $ +# $Revision: 1.2 $ # -# last change: $Author: mt $ $Date: 2004-07-12 13:15:22 $ +# last change: $Author: mt $ $Date: 2004-07-14 11:05:46 $ # # The Contents of this file are made available subject to the terms of # either of the following licenses @@ -77,6 +77,7 @@ ENABLE_EXCEPTIONS=TRUE # --- Files -------------------------------------------------------- SLOFILES= \ + $(SLO)$/documentsignaturehelper.obj \ $(SLO)$/xmlsignaturehelper.obj \ $(SLO)$/xmlsignaturehelper2.obj \ $(SLO)$/xsecctl.obj \ diff --git a/xmlsecurity/source/helper/xmlsignaturehelper.cxx b/xmlsecurity/source/helper/xmlsignaturehelper.cxx index ffca2ddb6c78..3b3a4befe741 100644 --- a/xmlsecurity/source/helper/xmlsignaturehelper.cxx +++ b/xmlsecurity/source/helper/xmlsignaturehelper.cxx @@ -2,9 +2,9 @@ * * $RCSfile: xmlsignaturehelper.cxx,v $ * - * $Revision: 1.1.1.1 $ + * $Revision: 1.2 $ * - * last change: $Author: mt $ $Date: 2004-07-12 13:15:22 $ + * last change: $Author: mt $ $Date: 2004-07-14 11:05:46 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -230,7 +230,7 @@ void XMLSignatureHelper::ExportSignature( mpXSecController->exportSignature(xDocumentHandler, signatureInfo); } -bool XMLSignatureHelper::CreateAndWriteSignatue( const uno::Reference< xml::sax::XDocumentHandler >& xDocumentHandler ) +bool XMLSignatureHelper::CreateAndWriteSignature( const uno::Reference< xml::sax::XDocumentHandler >& xDocumentHandler ) { mbError = false; @@ -250,7 +250,7 @@ bool XMLSignatureHelper::CreateAndWriteSignatue( const uno::Reference< xml::sax: /* * write signatures */ - if ( !mpXSecController->WriteSignatue( xDocumentHandler ) ) + if ( !mpXSecController->WriteSignature( xDocumentHandler ) ) { mbError = true; } @@ -263,19 +263,19 @@ bool XMLSignatureHelper::CreateAndWriteSignatue( const uno::Reference< xml::sax: return !mbError; } -bool XMLSignatureHelper::CreateAndWriteSignatue( const com::sun::star::uno::Reference< com::sun::star::io::XOutputStream >& xOutputStream ) +bool XMLSignatureHelper::CreateAndWriteSignature( const com::sun::star::uno::Reference< com::sun::star::io::XOutputStream >& xOutputStream ) { uno::Reference<xml::sax::XDocumentHandler> xDocHandler = CreateDocumentHandlerWithHeader(xOutputStream); - bool rc = CreateAndWriteSignatue( xDocHandler ); + bool rc = CreateAndWriteSignature( xDocHandler ); CloseDocumentHandler(xDocHandler); return rc; } -bool XMLSignatureHelper::ReadAndVerifySignatue( const com::sun::star::uno::Reference< com::sun::star::io::XInputStream >& xInputStream ) +bool XMLSignatureHelper::ReadAndVerifySignature( const com::sun::star::uno::Reference< com::sun::star::io::XInputStream >& xInputStream ) { mbError = false; diff --git a/xmlsecurity/source/helper/xsecctl.hxx b/xmlsecurity/source/helper/xsecctl.hxx index 7d3a939f93af..7e2cc53f38cc 100644 --- a/xmlsecurity/source/helper/xsecctl.hxx +++ b/xmlsecurity/source/helper/xsecctl.hxx @@ -2,9 +2,9 @@ * * $RCSfile: xsecctl.hxx,v $ * - * $Revision: 1.1.1.1 $ + * $Revision: 1.2 $ * - * last change: $Author: mt $ $Date: 2004-07-12 13:15:22 $ + * last change: $Author: mt $ $Date: 2004-07-14 11:05:46 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -510,7 +510,7 @@ public: const rtl::OUString& ouDate, const rtl::OUString& ouTime); - bool WriteSignatue( + bool WriteSignature( const com::sun::star::uno::Reference< com::sun::star::xml::sax::XDocumentHandler >& xDocumentHandler ); diff --git a/xmlsecurity/source/helper/xsecsign.cxx b/xmlsecurity/source/helper/xsecsign.cxx index 8b5bfaa1653e..50603a155ab6 100644 --- a/xmlsecurity/source/helper/xsecsign.cxx +++ b/xmlsecurity/source/helper/xsecsign.cxx @@ -2,9 +2,9 @@ * * $RCSfile: xsecsign.cxx,v $ * - * $Revision: 1.1.1.1 $ + * $Revision: 1.2 $ * - * last change: $Author: mt $ $Date: 2004-07-12 13:15:22 $ + * last change: $Author: mt $ $Date: 2004-07-14 11:05:46 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -319,7 +319,7 @@ void XSecController::setDateTime( } } -bool XSecController::WriteSignatue( +bool XSecController::WriteSignature( const cssu::Reference<cssxs::XDocumentHandler>& xDocumentHandler ) { bool rc = false; |