1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_xmlsecurity.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include <sal/config.h> 32*cdf0e10cSrcweir #include <rtl/uuid.h> 33*cdf0e10cSrcweir #include "xmlencryption_mscryptimpl.hxx" 34*cdf0e10cSrcweir 35*cdf0e10cSrcweir #ifndef _XMLDOCUMENTWRAPPER_XMLSECIMPL_HXX_ 36*cdf0e10cSrcweir #include "xmldocumentwrapper_xmlsecimpl.hxx" 37*cdf0e10cSrcweir #endif 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir #ifndef _XMLELEMENTWRAPPER_XMLSECIMPL_HXX_ 40*cdf0e10cSrcweir #include "xmlelementwrapper_xmlsecimpl.hxx" 41*cdf0e10cSrcweir #endif 42*cdf0e10cSrcweir 43*cdf0e10cSrcweir #ifndef _SECURITYENVIRONMENT_MSCRYPTIMPL_HXX_ 44*cdf0e10cSrcweir #include "securityenvironment_mscryptimpl.hxx" 45*cdf0e10cSrcweir #endif 46*cdf0e10cSrcweir #include "errorcallback.hxx" 47*cdf0e10cSrcweir 48*cdf0e10cSrcweir #include "xmlsec/xmlsec.h" 49*cdf0e10cSrcweir #include "xmlsec/xmltree.h" 50*cdf0e10cSrcweir #include "xmlsec/xmlenc.h" 51*cdf0e10cSrcweir #include "xmlsec/crypto.h" 52*cdf0e10cSrcweir 53*cdf0e10cSrcweir #ifdef UNX 54*cdf0e10cSrcweir #define stricmp strcasecmp 55*cdf0e10cSrcweir #endif 56*cdf0e10cSrcweir 57*cdf0e10cSrcweir using namespace ::com::sun::star::uno ; 58*cdf0e10cSrcweir using namespace ::com::sun::star::lang ; 59*cdf0e10cSrcweir using ::com::sun::star::lang::XMultiServiceFactory ; 60*cdf0e10cSrcweir using ::com::sun::star::lang::XSingleServiceFactory ; 61*cdf0e10cSrcweir using ::rtl::OUString ; 62*cdf0e10cSrcweir 63*cdf0e10cSrcweir using ::com::sun::star::xml::wrapper::XXMLElementWrapper ; 64*cdf0e10cSrcweir using ::com::sun::star::xml::wrapper::XXMLDocumentWrapper ; 65*cdf0e10cSrcweir using ::com::sun::star::xml::crypto::XSecurityEnvironment ; 66*cdf0e10cSrcweir using ::com::sun::star::xml::crypto::XXMLEncryption ; 67*cdf0e10cSrcweir using ::com::sun::star::xml::crypto::XXMLEncryptionTemplate ; 68*cdf0e10cSrcweir using ::com::sun::star::xml::crypto::XXMLSecurityContext ; 69*cdf0e10cSrcweir using ::com::sun::star::xml::crypto::XMLEncryptionException ; 70*cdf0e10cSrcweir 71*cdf0e10cSrcweir XMLEncryption_MSCryptImpl :: XMLEncryption_MSCryptImpl( const Reference< XMultiServiceFactory >& aFactory ) : m_xServiceManager( aFactory ) { 72*cdf0e10cSrcweir } 73*cdf0e10cSrcweir 74*cdf0e10cSrcweir XMLEncryption_MSCryptImpl :: ~XMLEncryption_MSCryptImpl() { 75*cdf0e10cSrcweir } 76*cdf0e10cSrcweir 77*cdf0e10cSrcweir /* XXMLEncryption */ 78*cdf0e10cSrcweir Reference< XXMLEncryptionTemplate > 79*cdf0e10cSrcweir SAL_CALL XMLEncryption_MSCryptImpl :: encrypt( 80*cdf0e10cSrcweir const Reference< XXMLEncryptionTemplate >& aTemplate , 81*cdf0e10cSrcweir const Reference< XSecurityEnvironment >& aEnvironment 82*cdf0e10cSrcweir ) throw( com::sun::star::xml::crypto::XMLEncryptionException, 83*cdf0e10cSrcweir com::sun::star::uno::SecurityException ) 84*cdf0e10cSrcweir { 85*cdf0e10cSrcweir xmlSecKeysMngrPtr pMngr = NULL ; 86*cdf0e10cSrcweir xmlSecEncCtxPtr pEncCtx = NULL ; 87*cdf0e10cSrcweir xmlNodePtr pEncryptedData = NULL ; 88*cdf0e10cSrcweir xmlNodePtr pContent = NULL ; 89*cdf0e10cSrcweir 90*cdf0e10cSrcweir if( !aTemplate.is() ) 91*cdf0e10cSrcweir throw RuntimeException() ; 92*cdf0e10cSrcweir 93*cdf0e10cSrcweir if( !aEnvironment.is() ) 94*cdf0e10cSrcweir throw RuntimeException() ; 95*cdf0e10cSrcweir 96*cdf0e10cSrcweir //Get Keys Manager 97*cdf0e10cSrcweir Reference< XUnoTunnel > xSecTunnel( aEnvironment , UNO_QUERY ) ; 98*cdf0e10cSrcweir if( !xSecTunnel.is() ) { 99*cdf0e10cSrcweir throw RuntimeException() ; 100*cdf0e10cSrcweir } 101*cdf0e10cSrcweir 102*cdf0e10cSrcweir SecurityEnvironment_MSCryptImpl* pSecEnv = ( SecurityEnvironment_MSCryptImpl* )xSecTunnel->getSomething( SecurityEnvironment_MSCryptImpl::getUnoTunnelId() ) ; 103*cdf0e10cSrcweir if( pSecEnv == NULL ) 104*cdf0e10cSrcweir throw RuntimeException() ; 105*cdf0e10cSrcweir 106*cdf0e10cSrcweir //Get the encryption template 107*cdf0e10cSrcweir Reference< XXMLElementWrapper > xTemplate = aTemplate->getTemplate() ; 108*cdf0e10cSrcweir if( !xTemplate.is() ) { 109*cdf0e10cSrcweir throw RuntimeException() ; 110*cdf0e10cSrcweir } 111*cdf0e10cSrcweir 112*cdf0e10cSrcweir Reference< XUnoTunnel > xTplTunnel( xTemplate , UNO_QUERY ) ; 113*cdf0e10cSrcweir if( !xTplTunnel.is() ) { 114*cdf0e10cSrcweir throw RuntimeException() ; 115*cdf0e10cSrcweir } 116*cdf0e10cSrcweir 117*cdf0e10cSrcweir XMLElementWrapper_XmlSecImpl* pTemplate = ( XMLElementWrapper_XmlSecImpl* )xTplTunnel->getSomething( XMLElementWrapper_XmlSecImpl::getUnoTunnelImplementationId() ) ; 118*cdf0e10cSrcweir if( pTemplate == NULL ) { 119*cdf0e10cSrcweir throw RuntimeException() ; 120*cdf0e10cSrcweir } 121*cdf0e10cSrcweir 122*cdf0e10cSrcweir pEncryptedData = pTemplate->getNativeElement() ; 123*cdf0e10cSrcweir 124*cdf0e10cSrcweir //Find the element to be encrypted. 125*cdf0e10cSrcweir //This element is wrapped in the CipherValue sub-element. 126*cdf0e10cSrcweir xmlNodePtr pCipherData = pEncryptedData->children; 127*cdf0e10cSrcweir while (pCipherData != NULL && stricmp((const char *)(pCipherData->name), "CipherData")) 128*cdf0e10cSrcweir { 129*cdf0e10cSrcweir pCipherData = pCipherData->next; 130*cdf0e10cSrcweir } 131*cdf0e10cSrcweir 132*cdf0e10cSrcweir if( pCipherData == NULL ) { 133*cdf0e10cSrcweir throw XMLEncryptionException() ; 134*cdf0e10cSrcweir } 135*cdf0e10cSrcweir 136*cdf0e10cSrcweir xmlNodePtr pCipherValue = pCipherData->children; 137*cdf0e10cSrcweir while (pCipherValue != NULL && stricmp((const char *)(pCipherValue->name), "CipherValue")) 138*cdf0e10cSrcweir { 139*cdf0e10cSrcweir pCipherValue = pCipherValue->next; 140*cdf0e10cSrcweir } 141*cdf0e10cSrcweir 142*cdf0e10cSrcweir if( pCipherValue == NULL ) { 143*cdf0e10cSrcweir throw XMLEncryptionException() ; 144*cdf0e10cSrcweir } 145*cdf0e10cSrcweir 146*cdf0e10cSrcweir pContent = pCipherValue->children; 147*cdf0e10cSrcweir 148*cdf0e10cSrcweir if( pContent == NULL ) { 149*cdf0e10cSrcweir throw XMLEncryptionException() ; 150*cdf0e10cSrcweir } 151*cdf0e10cSrcweir 152*cdf0e10cSrcweir xmlUnlinkNode(pContent); 153*cdf0e10cSrcweir xmlAddNextSibling(pEncryptedData, pContent); 154*cdf0e10cSrcweir 155*cdf0e10cSrcweir //remember the position of the element to be signed 156*cdf0e10cSrcweir sal_Bool isParentRef = sal_True; 157*cdf0e10cSrcweir xmlNodePtr pParent = pEncryptedData->parent; 158*cdf0e10cSrcweir xmlNodePtr referenceNode; 159*cdf0e10cSrcweir 160*cdf0e10cSrcweir if (pEncryptedData == pParent->children) 161*cdf0e10cSrcweir { 162*cdf0e10cSrcweir referenceNode = pParent; 163*cdf0e10cSrcweir } 164*cdf0e10cSrcweir else 165*cdf0e10cSrcweir { 166*cdf0e10cSrcweir referenceNode = pEncryptedData->prev; 167*cdf0e10cSrcweir isParentRef = sal_False; 168*cdf0e10cSrcweir } 169*cdf0e10cSrcweir 170*cdf0e10cSrcweir setErrorRecorder( ); 171*cdf0e10cSrcweir 172*cdf0e10cSrcweir pMngr = pSecEnv->createKeysManager() ; //i39448 173*cdf0e10cSrcweir if( !pMngr ) { 174*cdf0e10cSrcweir throw RuntimeException() ; 175*cdf0e10cSrcweir } 176*cdf0e10cSrcweir 177*cdf0e10cSrcweir //Create Encryption context 178*cdf0e10cSrcweir pEncCtx = xmlSecEncCtxCreate( pMngr ) ; 179*cdf0e10cSrcweir if( pEncCtx == NULL ) 180*cdf0e10cSrcweir { 181*cdf0e10cSrcweir pSecEnv->destroyKeysManager( pMngr ) ; //i39448 182*cdf0e10cSrcweir //throw XMLEncryptionException() ; 183*cdf0e10cSrcweir clearErrorRecorder(); 184*cdf0e10cSrcweir return aTemplate; 185*cdf0e10cSrcweir } 186*cdf0e10cSrcweir 187*cdf0e10cSrcweir //Encrypt the template 188*cdf0e10cSrcweir if( xmlSecEncCtxXmlEncrypt( pEncCtx , pEncryptedData , pContent ) < 0 ) { 189*cdf0e10cSrcweir aTemplate->setStatus(::com::sun::star::xml::crypto::SecurityOperationStatus_UNKNOWN); 190*cdf0e10cSrcweir xmlSecEncCtxDestroy( pEncCtx ) ; 191*cdf0e10cSrcweir pSecEnv->destroyKeysManager( pMngr ) ; //i39448 192*cdf0e10cSrcweir clearErrorRecorder(); 193*cdf0e10cSrcweir return aTemplate; 194*cdf0e10cSrcweir } 195*cdf0e10cSrcweir aTemplate->setStatus(::com::sun::star::xml::crypto::SecurityOperationStatus_OPERATION_SUCCEEDED); 196*cdf0e10cSrcweir xmlSecEncCtxDestroy( pEncCtx ) ; 197*cdf0e10cSrcweir pSecEnv->destroyKeysManager( pMngr ) ; //i39448 198*cdf0e10cSrcweir 199*cdf0e10cSrcweir //get the new EncryptedData element 200*cdf0e10cSrcweir if (isParentRef) 201*cdf0e10cSrcweir { 202*cdf0e10cSrcweir pTemplate->setNativeElement(referenceNode->children) ; 203*cdf0e10cSrcweir } 204*cdf0e10cSrcweir else 205*cdf0e10cSrcweir { 206*cdf0e10cSrcweir pTemplate->setNativeElement(referenceNode->next); 207*cdf0e10cSrcweir } 208*cdf0e10cSrcweir 209*cdf0e10cSrcweir clearErrorRecorder(); 210*cdf0e10cSrcweir return aTemplate ; 211*cdf0e10cSrcweir } 212*cdf0e10cSrcweir 213*cdf0e10cSrcweir /* XXMLEncryption */ 214*cdf0e10cSrcweir Reference< XXMLEncryptionTemplate > SAL_CALL 215*cdf0e10cSrcweir XMLEncryption_MSCryptImpl :: decrypt( 216*cdf0e10cSrcweir const Reference< XXMLEncryptionTemplate >& aTemplate , 217*cdf0e10cSrcweir const Reference< XXMLSecurityContext >& aSecurityCtx 218*cdf0e10cSrcweir ) throw( com::sun::star::xml::crypto::XMLEncryptionException , 219*cdf0e10cSrcweir com::sun::star::uno::SecurityException) { 220*cdf0e10cSrcweir xmlSecKeysMngrPtr pMngr = NULL ; 221*cdf0e10cSrcweir xmlSecEncCtxPtr pEncCtx = NULL ; 222*cdf0e10cSrcweir xmlNodePtr pEncryptedData = NULL ; 223*cdf0e10cSrcweir 224*cdf0e10cSrcweir if( !aTemplate.is() ) 225*cdf0e10cSrcweir throw RuntimeException() ; 226*cdf0e10cSrcweir 227*cdf0e10cSrcweir if( !aSecurityCtx.is() ) 228*cdf0e10cSrcweir throw RuntimeException() ; 229*cdf0e10cSrcweir 230*cdf0e10cSrcweir //Get Keys Manager 231*cdf0e10cSrcweir Reference< XSecurityEnvironment > xSecEnv 232*cdf0e10cSrcweir = aSecurityCtx->getSecurityEnvironmentByIndex( 233*cdf0e10cSrcweir aSecurityCtx->getDefaultSecurityEnvironmentIndex()); 234*cdf0e10cSrcweir Reference< XUnoTunnel > xSecTunnel( xSecEnv , UNO_QUERY ) ; 235*cdf0e10cSrcweir if( !xSecTunnel.is() ) { 236*cdf0e10cSrcweir throw RuntimeException() ; 237*cdf0e10cSrcweir } 238*cdf0e10cSrcweir 239*cdf0e10cSrcweir SecurityEnvironment_MSCryptImpl* pSecEnv = ( SecurityEnvironment_MSCryptImpl* )xSecTunnel->getSomething( SecurityEnvironment_MSCryptImpl::getUnoTunnelId() ) ; 240*cdf0e10cSrcweir if( pSecEnv == NULL ) 241*cdf0e10cSrcweir throw RuntimeException() ; 242*cdf0e10cSrcweir 243*cdf0e10cSrcweir //Get the encryption template 244*cdf0e10cSrcweir Reference< XXMLElementWrapper > xTemplate = aTemplate->getTemplate() ; 245*cdf0e10cSrcweir if( !xTemplate.is() ) { 246*cdf0e10cSrcweir throw RuntimeException() ; 247*cdf0e10cSrcweir } 248*cdf0e10cSrcweir 249*cdf0e10cSrcweir Reference< XUnoTunnel > xTplTunnel( xTemplate , UNO_QUERY ) ; 250*cdf0e10cSrcweir if( !xTplTunnel.is() ) { 251*cdf0e10cSrcweir throw RuntimeException() ; 252*cdf0e10cSrcweir } 253*cdf0e10cSrcweir 254*cdf0e10cSrcweir XMLElementWrapper_XmlSecImpl* pTemplate = ( XMLElementWrapper_XmlSecImpl* )xTplTunnel->getSomething( XMLElementWrapper_XmlSecImpl::getUnoTunnelImplementationId() ) ; 255*cdf0e10cSrcweir if( pTemplate == NULL ) { 256*cdf0e10cSrcweir throw RuntimeException() ; 257*cdf0e10cSrcweir } 258*cdf0e10cSrcweir 259*cdf0e10cSrcweir pEncryptedData = pTemplate->getNativeElement() ; 260*cdf0e10cSrcweir 261*cdf0e10cSrcweir //remember the position of the element to be signed 262*cdf0e10cSrcweir sal_Bool isParentRef = sal_True; 263*cdf0e10cSrcweir xmlNodePtr pParent = pEncryptedData->parent; 264*cdf0e10cSrcweir xmlNodePtr referenceNode; 265*cdf0e10cSrcweir 266*cdf0e10cSrcweir if (pEncryptedData == pParent->children) 267*cdf0e10cSrcweir { 268*cdf0e10cSrcweir referenceNode = pParent; 269*cdf0e10cSrcweir } 270*cdf0e10cSrcweir else 271*cdf0e10cSrcweir { 272*cdf0e10cSrcweir referenceNode = pEncryptedData->prev; 273*cdf0e10cSrcweir isParentRef = sal_False; 274*cdf0e10cSrcweir } 275*cdf0e10cSrcweir 276*cdf0e10cSrcweir setErrorRecorder( ); 277*cdf0e10cSrcweir 278*cdf0e10cSrcweir pMngr = pSecEnv->createKeysManager() ; //i39448 279*cdf0e10cSrcweir if( !pMngr ) { 280*cdf0e10cSrcweir throw RuntimeException() ; 281*cdf0e10cSrcweir } 282*cdf0e10cSrcweir 283*cdf0e10cSrcweir //Create Encryption context 284*cdf0e10cSrcweir pEncCtx = xmlSecEncCtxCreate( pMngr ) ; 285*cdf0e10cSrcweir if( pEncCtx == NULL ) 286*cdf0e10cSrcweir { 287*cdf0e10cSrcweir pSecEnv->destroyKeysManager( pMngr ) ; //i39448 288*cdf0e10cSrcweir //throw XMLEncryptionException() ; 289*cdf0e10cSrcweir clearErrorRecorder(); 290*cdf0e10cSrcweir return aTemplate; 291*cdf0e10cSrcweir } 292*cdf0e10cSrcweir 293*cdf0e10cSrcweir //Decrypt the template 294*cdf0e10cSrcweir if( xmlSecEncCtxDecrypt( pEncCtx , pEncryptedData ) < 0 || pEncCtx->result == NULL ) { 295*cdf0e10cSrcweir aTemplate->setStatus(::com::sun::star::xml::crypto::SecurityOperationStatus_UNKNOWN); 296*cdf0e10cSrcweir xmlSecEncCtxDestroy( pEncCtx ) ; 297*cdf0e10cSrcweir pSecEnv->destroyKeysManager( pMngr ) ; //i39448 298*cdf0e10cSrcweir 299*cdf0e10cSrcweir //throw XMLEncryptionException() ; 300*cdf0e10cSrcweir clearErrorRecorder(); 301*cdf0e10cSrcweir return aTemplate; 302*cdf0e10cSrcweir } 303*cdf0e10cSrcweir aTemplate->setStatus(::com::sun::star::xml::crypto::SecurityOperationStatus_OPERATION_SUCCEEDED); 304*cdf0e10cSrcweir /*---------------------------------------- 305*cdf0e10cSrcweir if( pEncCtx->resultReplaced != 0 ) { 306*cdf0e10cSrcweir pContent = pEncryptedData ; 307*cdf0e10cSrcweir 308*cdf0e10cSrcweir Reference< XUnoTunnel > xTunnel( ret , UNO_QUERY ) ; 309*cdf0e10cSrcweir if( !xTunnel.is() ) { 310*cdf0e10cSrcweir xmlSecEncCtxDestroy( pEncCtx ) ; 311*cdf0e10cSrcweir throw RuntimeException() ; 312*cdf0e10cSrcweir } 313*cdf0e10cSrcweir XMLElementWrapper_XmlSecImpl* pNode = ( XMLElementWrapper_XmlSecImpl* )xTunnel->getSomething( XMLElementWrapper_XmlSecImpl::getUnoTunnelImplementationId() ) ; 314*cdf0e10cSrcweir if( pNode == NULL ) { 315*cdf0e10cSrcweir xmlSecEncCtxDestroy( pEncCtx ) ; 316*cdf0e10cSrcweir throw RuntimeException() ; 317*cdf0e10cSrcweir } 318*cdf0e10cSrcweir 319*cdf0e10cSrcweir pNode->setNativeElement( pContent ) ; 320*cdf0e10cSrcweir } else { 321*cdf0e10cSrcweir xmlSecEncCtxDestroy( pEncCtx ) ; 322*cdf0e10cSrcweir throw RuntimeException() ; 323*cdf0e10cSrcweir } 324*cdf0e10cSrcweir ----------------------------------------*/ 325*cdf0e10cSrcweir 326*cdf0e10cSrcweir //Destroy the encryption context 327*cdf0e10cSrcweir xmlSecEncCtxDestroy( pEncCtx ) ; 328*cdf0e10cSrcweir pSecEnv->destroyKeysManager( pMngr ) ; //i39448 329*cdf0e10cSrcweir 330*cdf0e10cSrcweir //get the decrypted element 331*cdf0e10cSrcweir XMLElementWrapper_XmlSecImpl * ret = new XMLElementWrapper_XmlSecImpl(isParentRef? 332*cdf0e10cSrcweir (referenceNode->children):(referenceNode->next)); 333*cdf0e10cSrcweir 334*cdf0e10cSrcweir //return ret; 335*cdf0e10cSrcweir aTemplate->setTemplate(ret); 336*cdf0e10cSrcweir 337*cdf0e10cSrcweir clearErrorRecorder(); 338*cdf0e10cSrcweir return aTemplate; 339*cdf0e10cSrcweir } 340*cdf0e10cSrcweir 341*cdf0e10cSrcweir /* XInitialization */ 342*cdf0e10cSrcweir void SAL_CALL XMLEncryption_MSCryptImpl :: initialize( const Sequence< Any >& /*aArguments*/ ) throw( Exception, RuntimeException ) { 343*cdf0e10cSrcweir // TBD 344*cdf0e10cSrcweir } ; 345*cdf0e10cSrcweir 346*cdf0e10cSrcweir /* XServiceInfo */ 347*cdf0e10cSrcweir OUString SAL_CALL XMLEncryption_MSCryptImpl :: getImplementationName() throw( RuntimeException ) { 348*cdf0e10cSrcweir return impl_getImplementationName() ; 349*cdf0e10cSrcweir } 350*cdf0e10cSrcweir 351*cdf0e10cSrcweir /* XServiceInfo */ 352*cdf0e10cSrcweir sal_Bool SAL_CALL XMLEncryption_MSCryptImpl :: supportsService( const OUString& serviceName) throw( RuntimeException ) { 353*cdf0e10cSrcweir Sequence< OUString > seqServiceNames = getSupportedServiceNames() ; 354*cdf0e10cSrcweir const OUString* pArray = seqServiceNames.getConstArray() ; 355*cdf0e10cSrcweir for( sal_Int32 i = 0 ; i < seqServiceNames.getLength() ; i ++ ) { 356*cdf0e10cSrcweir if( *( pArray + i ) == serviceName ) 357*cdf0e10cSrcweir return sal_True ; 358*cdf0e10cSrcweir } 359*cdf0e10cSrcweir return sal_False ; 360*cdf0e10cSrcweir } 361*cdf0e10cSrcweir 362*cdf0e10cSrcweir /* XServiceInfo */ 363*cdf0e10cSrcweir Sequence< OUString > SAL_CALL XMLEncryption_MSCryptImpl :: getSupportedServiceNames() throw( RuntimeException ) { 364*cdf0e10cSrcweir return impl_getSupportedServiceNames() ; 365*cdf0e10cSrcweir } 366*cdf0e10cSrcweir 367*cdf0e10cSrcweir //Helper for XServiceInfo 368*cdf0e10cSrcweir Sequence< OUString > XMLEncryption_MSCryptImpl :: impl_getSupportedServiceNames() { 369*cdf0e10cSrcweir ::osl::Guard< ::osl::Mutex > aGuard( ::osl::Mutex::getGlobalMutex() ) ; 370*cdf0e10cSrcweir Sequence< OUString > seqServiceNames( 1 ) ; 371*cdf0e10cSrcweir seqServiceNames.getArray()[0] = OUString::createFromAscii( "com.sun.star.xml.crypto.XMLEncryption" ) ; 372*cdf0e10cSrcweir return seqServiceNames ; 373*cdf0e10cSrcweir } 374*cdf0e10cSrcweir 375*cdf0e10cSrcweir OUString XMLEncryption_MSCryptImpl :: impl_getImplementationName() throw( RuntimeException ) { 376*cdf0e10cSrcweir return OUString::createFromAscii( "com.sun.star.xml.security.bridge.xmlsec.XMLEncryption_MSCryptImpl" ) ; 377*cdf0e10cSrcweir } 378*cdf0e10cSrcweir 379*cdf0e10cSrcweir //Helper for registry 380*cdf0e10cSrcweir Reference< XInterface > SAL_CALL XMLEncryption_MSCryptImpl :: impl_createInstance( const Reference< XMultiServiceFactory >& aServiceManager ) throw( RuntimeException ) { 381*cdf0e10cSrcweir return Reference< XInterface >( *new XMLEncryption_MSCryptImpl( aServiceManager ) ) ; 382*cdf0e10cSrcweir } 383*cdf0e10cSrcweir 384*cdf0e10cSrcweir Reference< XSingleServiceFactory > XMLEncryption_MSCryptImpl :: impl_createFactory( const Reference< XMultiServiceFactory >& aServiceManager ) { 385*cdf0e10cSrcweir //Reference< XSingleServiceFactory > xFactory ; 386*cdf0e10cSrcweir //xFactory = ::cppu::createSingleFactory( aServiceManager , impl_getImplementationName , impl_createInstance , impl_getSupportedServiceNames ) ; 387*cdf0e10cSrcweir //return xFactory ; 388*cdf0e10cSrcweir return ::cppu::createSingleFactory( aServiceManager , impl_getImplementationName() , impl_createInstance , impl_getSupportedServiceNames() ) ; 389*cdf0e10cSrcweir } 390*cdf0e10cSrcweir 391