diff options
Diffstat (limited to 'xmlsecurity/source')
5 files changed, 51 insertions, 66 deletions
diff --git a/xmlsecurity/source/helper/xmlsignaturehelper.cxx b/xmlsecurity/source/helper/xmlsignaturehelper.cxx index 163e5f600f37..ca9ef0662171 100644 --- a/xmlsecurity/source/helper/xmlsignaturehelper.cxx +++ b/xmlsecurity/source/helper/xmlsignaturehelper.cxx @@ -37,13 +37,11 @@ #include <com/sun/star/beans/XPropertySet.hpp> #include <com/sun/star/xml/sax/Parser.hpp> #include <com/sun/star/xml/sax/Writer.hpp> +#include <com/sun/star/xml/crypto/SEInitializer.hpp> #include <tools/date.hxx> #include <tools/time.hxx> -/* SEInitializer component */ -#define SEINITIALIZER_COMPONENT "com.sun.star.xml.crypto.SEInitializer" - #define TAG_DOCUMENTSIGNATURES "document-signatures" #define NS_DOCUMENTSIGNATURES "http://openoffice.org/2004/documentsignatures" #define NS_DOCUMENTSIGNATURES_ODF_1_2 "urn:oasis:names:tc:opendocument:xmlns:digitalsignature:1.0" @@ -68,7 +66,7 @@ bool XMLSignatureHelper::Init() DBG_ASSERT( !mxSEInitializer.is(), "XMLSignatureHelper::Init - mxSEInitializer already set!" ); DBG_ASSERT( !mxSecurityContext.is(), "XMLSignatureHelper::Init - mxSecurityContext already set!" ); - ImplCreateSEInitializer(); + mxSEInitializer = com::sun::star::xml::crypto::SEInitializer::create( mxCtx ); if ( mxSEInitializer.is() ) mxSecurityContext = mxSEInitializer->createSecurityContext( ::rtl::OUString() ); @@ -76,14 +74,6 @@ bool XMLSignatureHelper::Init() return mxSecurityContext.is(); } -void XMLSignatureHelper::ImplCreateSEInitializer() -{ - rtl::OUString sSEInitializer( SEINITIALIZER_COMPONENT ); - uno::Reference< lang::XMultiComponentFactory > xMCF( mxCtx->getServiceManager() ); - mxSEInitializer = uno::Reference< com::sun::star::xml::crypto::XSEInitializer > ( - xMCF->createInstanceWithContext( sSEInitializer, mxCtx ), uno::UNO_QUERY ); -} - void XMLSignatureHelper::SetStorage( const Reference < css::embed::XStorage >& rxStorage, ::rtl::OUString sODFVersion) diff --git a/xmlsecurity/source/xmlsec/nss/nssinitializer.cxx b/xmlsecurity/source/xmlsec/nss/nssinitializer.cxx index 29dadaf5b37e..b3dae01654da 100644 --- a/xmlsecurity/source/xmlsec/nss/nssinitializer.cxx +++ b/xmlsecurity/source/xmlsec/nss/nssinitializer.cxx @@ -88,14 +88,14 @@ extern "C" void nsscrypto_finalize(); namespace { -bool nsscrypto_initialize( const css::uno::Reference< css::lang::XMultiServiceFactory > &xMSF, bool & out_nss_init ); +bool nsscrypto_initialize( const css::uno::Reference< css::uno::XComponentContext > &rxContext, bool & out_nss_init ); struct InitNSSInitialize { - css::uno::Reference< css::lang::XMultiServiceFactory > mxMSF; + css::uno::Reference< css::uno::XComponentContext > m_xContext; - InitNSSInitialize( const css::uno::Reference< css::lang::XMultiServiceFactory > &xMSF ) - : mxMSF( xMSF ) + InitNSSInitialize( const css::uno::Reference< css::uno::XComponentContext > &rxContext ) + : m_xContext( rxContext ) { } @@ -103,7 +103,7 @@ struct InitNSSInitialize { static bool bInitialized = false; bool bNSSInit = false; - bInitialized = nsscrypto_initialize( mxMSF, bNSSInit ); + bInitialized = nsscrypto_initialize( m_xContext, bNSSInit ); if (bNSSInit) atexit(nsscrypto_finalize ); return & bInitialized; @@ -167,7 +167,7 @@ void deleteRootsModule() } } -::rtl::OString getMozillaCurrentProfile( const css::uno::Reference< css::lang::XMultiServiceFactory > &rxMSF ) +::rtl::OString getMozillaCurrentProfile( const css::uno::Reference< css::uno::XComponentContext > &rxContext ) { // first, try to get the profile from "MOZILLA_CERTIFICATE_FOLDER" const char* pEnv = getenv("MOZILLA_CERTIFICATE_FOLDER"); @@ -195,8 +195,7 @@ void deleteRootsModule() mozilla::MozillaProductType_Mozilla }; int nProduct = SAL_N_ELEMENTS(productTypes); - uno::Reference<uno::XInterface> xInstance = rxMSF->createInstance( - "com.sun.star.mozilla.MozillaBootstrap"); + uno::Reference<uno::XInterface> xInstance = rxContext->getServiceManager()->createInstanceWithContext("com.sun.star.mozilla.MozillaBootstrap", rxContext); OSL_ENSURE( xInstance.is(), "failed to create instance" ); uno::Reference<mozilla::XMozillaBootstrap> xMozillaBootstrap @@ -243,7 +242,7 @@ void deleteRootsModule() //return true - whole initialization was successful //param out_nss_init = true: at least the NSS initialization (NSS_InitReadWrite //was successful and therefor NSS_Shutdown should be called when terminating. -bool nsscrypto_initialize( const css::uno::Reference< css::lang::XMultiServiceFactory > &xMSF, bool & out_nss_init ) +bool nsscrypto_initialize( const css::uno::Reference< css::uno::XComponentContext > &rxContext, bool & out_nss_init ) { bool return_value = true; @@ -251,7 +250,7 @@ bool nsscrypto_initialize( const css::uno::Reference< css::lang::XMultiServiceFa rtl::OString sCertDir; #ifdef XMLSEC_CRYPTO_NSS - sCertDir = getMozillaCurrentProfile(xMSF); + sCertDir = getMozillaCurrentProfile(rxContext); #else (void) xMSF; #endif @@ -389,8 +388,8 @@ extern "C" void nsscrypto_finalize() } // namespace ONSSInitializer::ONSSInitializer( - const css::uno::Reference< css::lang::XMultiServiceFactory > &rxMSF) - :mxMSF( rxMSF ) + const css::uno::Reference< css::uno::XComponentContext > &rxContext) + :m_xContext( rxContext ) { } @@ -398,10 +397,10 @@ ONSSInitializer::~ONSSInitializer() { } -bool ONSSInitializer::initNSS( const css::uno::Reference< css::lang::XMultiServiceFactory > &xMSF ) +bool ONSSInitializer::initNSS( const css::uno::Reference< css::uno::XComponentContext > &rxContext ) { return *rtl_Instance< bool, InitNSSInitialize, ::osl::MutexGuard, GetNSSInitStaticMutex > - ::create( InitNSSInitialize( xMSF ), GetNSSInitStaticMutex() ); + ::create( InitNSSInitialize( rxContext ), GetNSSInitStaticMutex() ); } css::uno::Reference< css::xml::crypto::XDigestContext > SAL_CALL ONSSInitializer::getDigestContext( ::sal_Int32 nDigestID, const css::uno::Sequence< css::beans::NamedValue >& aParams ) @@ -431,7 +430,7 @@ css::uno::Reference< css::xml::crypto::XDigestContext > SAL_CALL ONSSInitializer throw css::lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Unexpected arguments provided for digest creation." ) ), css::uno::Reference< css::uno::XInterface >(), 2 ); css::uno::Reference< css::xml::crypto::XDigestContext > xResult; - if( initNSS( mxMSF ) ) + if( initNSS( m_xContext ) ) { PK11Context* pContext = PK11_CreateDigestContext( nNSSDigestID ); if ( pContext && PK11_DigestBegin( pContext ) == SECSuccess ) @@ -461,7 +460,7 @@ css::uno::Reference< css::xml::crypto::XCipherContext > SAL_CALL ONSSInitializer throw css::lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Unexpected cipher requested." ) ), css::uno::Reference< css::uno::XInterface >(), 1 ); css::uno::Reference< css::xml::crypto::XCipherContext > xResult; - if( initNSS( mxMSF ) ) + if( initNSS( m_xContext ) ) { if ( aInitializationVector.getLength() != PK11_GetIVLength( nNSSCipherID ) ) throw css::lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Unexpected length of initialization vector." ) ), css::uno::Reference< css::uno::XInterface >(), 3 ); @@ -497,7 +496,7 @@ cssu::Sequence< rtl::OUString > SAL_CALL ONSSInitializer_getSupportedServiceName cssu::Reference< cssu::XInterface > SAL_CALL ONSSInitializer_createInstance( const cssu::Reference< cssl::XMultiServiceFactory > & rSMgr) throw( cssu::Exception ) { - return (cppu::OWeakObject*) new ONSSInitializer( rSMgr ); + return (cppu::OWeakObject*) new ONSSInitializer( comphelper::getComponentContext(rSMgr) ); } /* XServiceInfo */ diff --git a/xmlsecurity/source/xmlsec/nss/nssinitializer.hxx b/xmlsecurity/source/xmlsec/nss/nssinitializer.hxx index d88344b991fe..4e6197d0e923 100644 --- a/xmlsecurity/source/xmlsec/nss/nssinitializer.hxx +++ b/xmlsecurity/source/xmlsec/nss/nssinitializer.hxx @@ -20,33 +20,31 @@ #ifndef _NSSINITIALIZER_HXX #define _NSSINITIALIZER_HXX -#include <com/sun/star/xml/crypto/XDigestContextSupplier.hpp> -#include <com/sun/star/xml/crypto/XCipherContextSupplier.hpp> +#include <com/sun/star/xml/crypto/XNSSInitializer.hpp> #include <com/sun/star/lang/XServiceInfo.hpp> #include <com/sun/star/lang/XMultiServiceFactory.hpp> -#include <cppuhelper/implbase3.hxx> +#include <cppuhelper/implbase2.hxx> #define NSS_SERVICE_NAME "com.sun.star.xml.crypto.NSSInitializer" -class ONSSInitializer : public cppu::WeakImplHelper3 +class ONSSInitializer : public cppu::WeakImplHelper2 < - ::com::sun::star::xml::crypto::XDigestContextSupplier, - ::com::sun::star::xml::crypto::XCipherContextSupplier, + ::com::sun::star::xml::crypto::XNSSInitializer, ::com::sun::star::lang::XServiceInfo > { protected: - ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > mxMSF; + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > m_xContext; ONSSInitializer() {} public: - ONSSInitializer( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > &rxMSF ); + ONSSInitializer( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > &rxContext ); virtual ~ONSSInitializer(); - bool initNSS( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > &xMSF ); + bool initNSS( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > &rxContext ); /* XDigestContextSupplier */ virtual ::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XDigestContext > SAL_CALL getDigestContext( ::sal_Int32 nDigestID, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& aParams ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); diff --git a/xmlsecurity/source/xmlsec/nss/seinitializer_nssimpl.cxx b/xmlsecurity/source/xmlsec/nss/seinitializer_nssimpl.cxx index 53741dfae3eb..666e3490ba7f 100644 --- a/xmlsecurity/source/xmlsec/nss/seinitializer_nssimpl.cxx +++ b/xmlsecurity/source/xmlsec/nss/seinitializer_nssimpl.cxx @@ -39,6 +39,7 @@ #undef DEBUG_WAS_DEFINED #endif +#include <comphelper/processfactory.hxx> #include <sal/types.h> #include <rtl/bootstrap.hxx> #include <rtl/string.hxx> @@ -59,7 +60,6 @@ namespace css = ::com::sun::star; -namespace cssu = css::uno; namespace cssl = css::lang; namespace cssxc = css::xml::crypto; @@ -72,11 +72,9 @@ using ::rtl::OString; #define SECURITY_ENVIRONMENT "com.sun.star.xml.crypto.SecurityEnvironment" #define SECURITY_CONTEXT "com.sun.star.xml.crypto.XMLSecurityContext" - int nProduct = 4; -SEInitializer_NssImpl::SEInitializer_NssImpl( - const css::uno::Reference< css::lang::XMultiServiceFactory > &rxMSF ) +SEInitializer_NssImpl::SEInitializer_NssImpl( const css::uno::Reference< css::uno::XComponentContext > &rxContext ) { - mxMSF = rxMSF; + m_xContext = rxContext; } SEInitializer_NssImpl::~SEInitializer_NssImpl() @@ -84,13 +82,13 @@ SEInitializer_NssImpl::~SEInitializer_NssImpl() } /* XSEInitializer */ -cssu::Reference< cssxc::XXMLSecurityContext > SAL_CALL +uno::Reference< cssxc::XXMLSecurityContext > SAL_CALL SEInitializer_NssImpl::createSecurityContext( const ::rtl::OUString& ) - throw (cssu::RuntimeException) + throw (uno::RuntimeException) { CERTCertDBHandle *pCertHandle = NULL ; - if( !initNSS( mxMSF ) ) + if( !initNSS( m_xContext ) ) return NULL; pCertHandle = CERT_GetDefaultCertDB() ; @@ -99,13 +97,13 @@ cssu::Reference< cssxc::XXMLSecurityContext > SAL_CALL { /* Build XML Security Context */ const rtl::OUString sSecyrutyContext ( RTL_CONSTASCII_USTRINGPARAM( SECURITY_CONTEXT ) ); - cssu::Reference< cssxc::XXMLSecurityContext > xSecCtx( mxMSF->createInstance ( sSecyrutyContext ), cssu::UNO_QUERY ); + uno::Reference< cssxc::XXMLSecurityContext > xSecCtx( m_xContext->getServiceManager()->createInstanceWithContext(sSecyrutyContext, m_xContext), uno::UNO_QUERY ); if( !xSecCtx.is() ) return NULL; const rtl::OUString sSecyrutyEnvironment ( RTL_CONSTASCII_USTRINGPARAM( SECURITY_ENVIRONMENT ) ); - cssu::Reference< cssxc::XSecurityEnvironment > xSecEnv( mxMSF->createInstance ( sSecyrutyEnvironment ), cssu::UNO_QUERY ); - cssu::Reference< cssl::XUnoTunnel > xEnvTunnel( xSecEnv , cssu::UNO_QUERY ) ; + uno::Reference< cssxc::XSecurityEnvironment > xSecEnv( m_xContext->getServiceManager()->createInstanceWithContext(sSecyrutyEnvironment, m_xContext), uno::UNO_QUERY ); + uno::Reference< cssl::XUnoTunnel > xEnvTunnel( xSecEnv , uno::UNO_QUERY ) ; if( !xEnvTunnel.is() ) return NULL; SecurityEnvironment_NssImpl* pSecEnv = reinterpret_cast<SecurityEnvironment_NssImpl*>( @@ -118,7 +116,7 @@ cssu::Reference< cssxc::XXMLSecurityContext > SAL_CALL xSecCtx->setDefaultSecurityEnvironmentIndex( n ); return xSecCtx; } - catch( cssu::Exception& ) + catch( const uno::Exception& ) { //PK11_LogoutAll(); //NSS_Shutdown(); @@ -126,8 +124,8 @@ cssu::Reference< cssxc::XXMLSecurityContext > SAL_CALL } } -void SAL_CALL SEInitializer_NssImpl::freeSecurityContext( const cssu::Reference< cssxc::XXMLSecurityContext >& ) - throw (cssu::RuntimeException) +void SAL_CALL SEInitializer_NssImpl::freeSecurityContext( const uno::Reference< cssxc::XXMLSecurityContext >& ) + throw (uno::RuntimeException) { /* * because the security context will free all its content when it @@ -139,47 +137,47 @@ void SAL_CALL SEInitializer_NssImpl::freeSecurityContext( const cssu::Reference< } rtl::OUString SEInitializer_NssImpl_getImplementationName () - throw (cssu::RuntimeException) + throw (uno::RuntimeException) { return rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM ( IMPLEMENTATION_NAME ) ); } sal_Bool SAL_CALL SEInitializer_NssImpl_supportsService( const rtl::OUString& ServiceName ) - throw (cssu::RuntimeException) + throw (uno::RuntimeException) { return ( ServiceName == SE_SERVICE_NAME || ServiceName == NSS_SERVICE_NAME ); } -cssu::Sequence< rtl::OUString > SAL_CALL SEInitializer_NssImpl_getSupportedServiceNames( ) - throw (cssu::RuntimeException) +uno::Sequence< rtl::OUString > SAL_CALL SEInitializer_NssImpl_getSupportedServiceNames( ) + throw (uno::RuntimeException) { - cssu::Sequence < rtl::OUString > aRet(2); + uno::Sequence < rtl::OUString > aRet(2); rtl::OUString* pArray = aRet.getArray(); pArray[0] = rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM ( SE_SERVICE_NAME ) ); pArray[1] = rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM ( NSS_SERVICE_NAME ) ); return aRet; } -cssu::Reference< cssu::XInterface > SAL_CALL SEInitializer_NssImpl_createInstance( const cssu::Reference< cssl::XMultiServiceFactory > & rSMgr) - throw( cssu::Exception ) +uno::Reference< uno::XInterface > SAL_CALL SEInitializer_NssImpl_createInstance( const uno::Reference< lang::XMultiServiceFactory > & rxMSF) + throw( uno::Exception ) { - return (cppu::OWeakObject*) new SEInitializer_NssImpl(rSMgr); + return (cppu::OWeakObject*) new SEInitializer_NssImpl(comphelper::getComponentContext(rxMSF)); } /* XServiceInfo */ rtl::OUString SAL_CALL SEInitializer_NssImpl::getImplementationName( ) - throw (cssu::RuntimeException) + throw (uno::RuntimeException) { return SEInitializer_NssImpl_getImplementationName(); } sal_Bool SAL_CALL SEInitializer_NssImpl::supportsService( const rtl::OUString& rServiceName ) - throw (cssu::RuntimeException) + throw (uno::RuntimeException) { return SEInitializer_NssImpl_supportsService( rServiceName ); } -cssu::Sequence< rtl::OUString > SAL_CALL SEInitializer_NssImpl::getSupportedServiceNames( ) - throw (cssu::RuntimeException) +uno::Sequence< rtl::OUString > SAL_CALL SEInitializer_NssImpl::getSupportedServiceNames( ) + throw (uno::RuntimeException) { return SEInitializer_NssImpl_getSupportedServiceNames(); } diff --git a/xmlsecurity/source/xmlsec/nss/seinitializer_nssimpl.hxx b/xmlsecurity/source/xmlsec/nss/seinitializer_nssimpl.hxx index 35e6f2f92367..f75f8dbb8e83 100644 --- a/xmlsecurity/source/xmlsec/nss/seinitializer_nssimpl.hxx +++ b/xmlsecurity/source/xmlsec/nss/seinitializer_nssimpl.hxx @@ -36,7 +36,7 @@ class SEInitializer_NssImpl : public cppu::ImplInheritanceHelper1 > { public: - SEInitializer_NssImpl( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > &rxMSF ); + SEInitializer_NssImpl( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > &rxContext ); virtual ~SEInitializer_NssImpl(); /* XSEInitializer */ @@ -70,7 +70,7 @@ com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL SEInitializer_NssImpl_ge throw ( ::com::sun::star::uno::RuntimeException ); com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > -SAL_CALL SEInitializer_NssImpl_createInstance( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > & rSMgr) +SAL_CALL SEInitializer_NssImpl_createInstance( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > & rxMSF) throw ( ::com::sun::star::uno::Exception ); #endif |