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 #include <sal/config.h>
31*cdf0e10cSrcweir #include <rtl/uuid.h>
32*cdf0e10cSrcweir #include "securityenvironment_mscryptimpl.hxx"
33*cdf0e10cSrcweir 
34*cdf0e10cSrcweir #ifndef _XMLSECURITYCONTEXT_MSCRYPTIMPL_HXX_
35*cdf0e10cSrcweir #include "xmlsecuritycontext_mscryptimpl.hxx"
36*cdf0e10cSrcweir #endif
37*cdf0e10cSrcweir #include "xmlstreamio.hxx"
38*cdf0e10cSrcweir 
39*cdf0e10cSrcweir #include "xmlsec/xmlsec.h"
40*cdf0e10cSrcweir #include "xmlsec/keysmngr.h"
41*cdf0e10cSrcweir #include "xmlsec/crypto.h"
42*cdf0e10cSrcweir #include "xmlsec/mscrypto/akmngr.h"
43*cdf0e10cSrcweir 
44*cdf0e10cSrcweir using namespace ::com::sun::star::uno ;
45*cdf0e10cSrcweir using namespace ::com::sun::star::lang ;
46*cdf0e10cSrcweir using ::com::sun::star::lang::XMultiServiceFactory ;
47*cdf0e10cSrcweir using ::com::sun::star::lang::XSingleServiceFactory ;
48*cdf0e10cSrcweir using ::rtl::OUString ;
49*cdf0e10cSrcweir 
50*cdf0e10cSrcweir using ::com::sun::star::xml::crypto::XSecurityEnvironment ;
51*cdf0e10cSrcweir using ::com::sun::star::xml::crypto::XXMLSecurityContext ;
52*cdf0e10cSrcweir 
53*cdf0e10cSrcweir XMLSecurityContext_MSCryptImpl :: XMLSecurityContext_MSCryptImpl( const Reference< XMultiServiceFactory >& aFactory )
54*cdf0e10cSrcweir 	://m_pKeysMngr( NULL ) ,
55*cdf0e10cSrcweir 	 m_xServiceManager( aFactory ),
56*cdf0e10cSrcweir 	 m_xSecurityEnvironment( NULL )
57*cdf0e10cSrcweir {
58*cdf0e10cSrcweir 	//Init xmlsec library
59*cdf0e10cSrcweir 	if( xmlSecInit() < 0 ) {
60*cdf0e10cSrcweir 		throw RuntimeException() ;
61*cdf0e10cSrcweir 	}
62*cdf0e10cSrcweir 
63*cdf0e10cSrcweir 	//Init xmlsec crypto engine library
64*cdf0e10cSrcweir 	if( xmlSecCryptoInit() < 0 ) {
65*cdf0e10cSrcweir 		xmlSecShutdown() ;
66*cdf0e10cSrcweir 		throw RuntimeException() ;
67*cdf0e10cSrcweir 	}
68*cdf0e10cSrcweir 
69*cdf0e10cSrcweir 	//Enable external stream handlers
70*cdf0e10cSrcweir 	if( xmlEnableStreamInputCallbacks() < 0 ) {
71*cdf0e10cSrcweir 		xmlSecCryptoShutdown() ;
72*cdf0e10cSrcweir 		xmlSecShutdown() ;
73*cdf0e10cSrcweir 		throw RuntimeException() ;
74*cdf0e10cSrcweir 	}
75*cdf0e10cSrcweir }
76*cdf0e10cSrcweir 
77*cdf0e10cSrcweir XMLSecurityContext_MSCryptImpl :: ~XMLSecurityContext_MSCryptImpl() {
78*cdf0e10cSrcweir 	xmlDisableStreamInputCallbacks() ;
79*cdf0e10cSrcweir 	xmlSecCryptoShutdown() ;
80*cdf0e10cSrcweir 	xmlSecShutdown() ;
81*cdf0e10cSrcweir }
82*cdf0e10cSrcweir 
83*cdf0e10cSrcweir //i39448 : new methods
84*cdf0e10cSrcweir sal_Int32 SAL_CALL XMLSecurityContext_MSCryptImpl::addSecurityEnvironment(
85*cdf0e10cSrcweir 	const ::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XSecurityEnvironment >& aSecurityEnvironment)
86*cdf0e10cSrcweir 	throw (::com::sun::star::security::SecurityInfrastructureException, ::com::sun::star::uno::RuntimeException)
87*cdf0e10cSrcweir {
88*cdf0e10cSrcweir 	if( !aSecurityEnvironment.is() )
89*cdf0e10cSrcweir 	{
90*cdf0e10cSrcweir 		throw RuntimeException() ;
91*cdf0e10cSrcweir 	}
92*cdf0e10cSrcweir 
93*cdf0e10cSrcweir 	m_xSecurityEnvironment = aSecurityEnvironment;
94*cdf0e10cSrcweir 
95*cdf0e10cSrcweir 	return 0;
96*cdf0e10cSrcweir }
97*cdf0e10cSrcweir 
98*cdf0e10cSrcweir 
99*cdf0e10cSrcweir sal_Int32 SAL_CALL XMLSecurityContext_MSCryptImpl::getSecurityEnvironmentNumber(  )
100*cdf0e10cSrcweir 	throw (::com::sun::star::uno::RuntimeException)
101*cdf0e10cSrcweir {
102*cdf0e10cSrcweir 	return 1;
103*cdf0e10cSrcweir }
104*cdf0e10cSrcweir 
105*cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XSecurityEnvironment > SAL_CALL
106*cdf0e10cSrcweir 	XMLSecurityContext_MSCryptImpl::getSecurityEnvironmentByIndex( sal_Int32 index )
107*cdf0e10cSrcweir 	throw (::com::sun::star::uno::RuntimeException)
108*cdf0e10cSrcweir {
109*cdf0e10cSrcweir 	if (index == 0)
110*cdf0e10cSrcweir 	{
111*cdf0e10cSrcweir 		return m_xSecurityEnvironment;
112*cdf0e10cSrcweir 	}
113*cdf0e10cSrcweir 	else
114*cdf0e10cSrcweir 		throw RuntimeException() ;
115*cdf0e10cSrcweir }
116*cdf0e10cSrcweir 
117*cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XSecurityEnvironment > SAL_CALL
118*cdf0e10cSrcweir 	XMLSecurityContext_MSCryptImpl::getSecurityEnvironment(  )
119*cdf0e10cSrcweir 	throw (::com::sun::star::uno::RuntimeException)
120*cdf0e10cSrcweir {
121*cdf0e10cSrcweir 	return m_xSecurityEnvironment;
122*cdf0e10cSrcweir }
123*cdf0e10cSrcweir 
124*cdf0e10cSrcweir sal_Int32 SAL_CALL XMLSecurityContext_MSCryptImpl::getDefaultSecurityEnvironmentIndex(  )
125*cdf0e10cSrcweir 	throw (::com::sun::star::uno::RuntimeException)
126*cdf0e10cSrcweir {
127*cdf0e10cSrcweir 	return 0;
128*cdf0e10cSrcweir }
129*cdf0e10cSrcweir 
130*cdf0e10cSrcweir void SAL_CALL XMLSecurityContext_MSCryptImpl::setDefaultSecurityEnvironmentIndex( sal_Int32 /*nDefaultEnvIndex*/ )
131*cdf0e10cSrcweir 	throw (::com::sun::star::uno::RuntimeException)
132*cdf0e10cSrcweir {
133*cdf0e10cSrcweir 	//dummy
134*cdf0e10cSrcweir }
135*cdf0e10cSrcweir 
136*cdf0e10cSrcweir #if 0
137*cdf0e10cSrcweir /* XXMLSecurityContext */
138*cdf0e10cSrcweir void SAL_CALL XMLSecurityContext_MSCryptImpl :: setSecurityEnvironment( const Reference< XSecurityEnvironment >& aSecurityEnvironment ) throw( com::sun::star::security::SecurityInfrastructureException ) {
139*cdf0e10cSrcweir 	HCERTSTORE hkeyStore ;
140*cdf0e10cSrcweir 	HCERTSTORE hCertStore ;
141*cdf0e10cSrcweir 	HCRYPTKEY symKey ;
142*cdf0e10cSrcweir 	HCRYPTKEY pubKey ;
143*cdf0e10cSrcweir 	HCRYPTKEY priKey ;
144*cdf0e10cSrcweir 	unsigned int i ;
145*cdf0e10cSrcweir 
146*cdf0e10cSrcweir 	if( !aSecurityEnvironment.is() )
147*cdf0e10cSrcweir 		throw RuntimeException() ;
148*cdf0e10cSrcweir 
149*cdf0e10cSrcweir 	m_xSecurityEnvironment = aSecurityEnvironment ;
150*cdf0e10cSrcweir 
151*cdf0e10cSrcweir 	//Clear key manager
152*cdf0e10cSrcweir 	if( m_pKeysMngr != NULL ) {
153*cdf0e10cSrcweir 		xmlSecKeysMngrDestroy( m_pKeysMngr ) ;
154*cdf0e10cSrcweir 		m_pKeysMngr = NULL ;
155*cdf0e10cSrcweir 	}
156*cdf0e10cSrcweir 
157*cdf0e10cSrcweir 	//Create key manager
158*cdf0e10cSrcweir 	Reference< XUnoTunnel > xEnvTunnel( m_xSecurityEnvironment , UNO_QUERY ) ;
159*cdf0e10cSrcweir 	if( !xEnvTunnel.is() ) {
160*cdf0e10cSrcweir 		throw RuntimeException() ;
161*cdf0e10cSrcweir 	}
162*cdf0e10cSrcweir 
163*cdf0e10cSrcweir 	SecurityEnvironment_MSCryptImpl* pSecEnv = ( SecurityEnvironment_MSCryptImpl* )xEnvTunnel->getSomething( SecurityEnvironment_MSCryptImpl::getUnoTunnelId() ) ;
164*cdf0e10cSrcweir 	if( pSecEnv == NULL )
165*cdf0e10cSrcweir 		throw RuntimeException() ;
166*cdf0e10cSrcweir 
167*cdf0e10cSrcweir 	hkeyStore = pSecEnv->getCryptoSlot() ;
168*cdf0e10cSrcweir 	hCertStore = pSecEnv->getCertDb() ;
169*cdf0e10cSrcweir 
170*cdf0e10cSrcweir 	/*-
171*cdf0e10cSrcweir 	 * The following lines is based on the of xmlsec-mscrypto crypto engine
172*cdf0e10cSrcweir 	 */
173*cdf0e10cSrcweir 	m_pKeysMngr = xmlSecMSCryptoAppliedKeysMngrCreate( hkeyStore , hCertStore ) ;
174*cdf0e10cSrcweir 	if( m_pKeysMngr == NULL )
175*cdf0e10cSrcweir 		throw RuntimeException() ;
176*cdf0e10cSrcweir 
177*cdf0e10cSrcweir 	/*-
178*cdf0e10cSrcweir 	 * Adopt symmetric key into keys manager
179*cdf0e10cSrcweir 	 */
180*cdf0e10cSrcweir 	for( i = 0 ; ( symKey = pSecEnv->getSymKey( i ) ) != NULL ; i ++ ) {
181*cdf0e10cSrcweir 		if( xmlSecMSCryptoAppliedKeysMngrSymKeyLoad( m_pKeysMngr, symKey ) < 0 ) {
182*cdf0e10cSrcweir 			throw RuntimeException() ;
183*cdf0e10cSrcweir 		}
184*cdf0e10cSrcweir 	}
185*cdf0e10cSrcweir 
186*cdf0e10cSrcweir 	/*-
187*cdf0e10cSrcweir 	 * Adopt asymmetric public key into keys manager
188*cdf0e10cSrcweir 	 */
189*cdf0e10cSrcweir 	for( i = 0 ; ( pubKey = pSecEnv->getPubKey( i ) ) != NULL ; i ++ ) {
190*cdf0e10cSrcweir 		if( xmlSecMSCryptoAppliedKeysMngrPubKeyLoad( m_pKeysMngr, pubKey ) < 0 ) {
191*cdf0e10cSrcweir 			throw RuntimeException() ;
192*cdf0e10cSrcweir 		}
193*cdf0e10cSrcweir 	}
194*cdf0e10cSrcweir 
195*cdf0e10cSrcweir 	/*-
196*cdf0e10cSrcweir 	 * Adopt asymmetric private key into keys manager
197*cdf0e10cSrcweir 	 */
198*cdf0e10cSrcweir 	for( i = 0 ; ( priKey = pSecEnv->getPriKey( i ) ) != NULL ; i ++ ) {
199*cdf0e10cSrcweir 		if( xmlSecMSCryptoAppliedKeysMngrPriKeyLoad( m_pKeysMngr, priKey ) < 0 ) {
200*cdf0e10cSrcweir 			throw RuntimeException() ;
201*cdf0e10cSrcweir 		}
202*cdf0e10cSrcweir 	}
203*cdf0e10cSrcweir 
204*cdf0e10cSrcweir 	/*-
205*cdf0e10cSrcweir 	 * Adopt system default certificate store.
206*cdf0e10cSrcweir 	 */
207*cdf0e10cSrcweir 	if( pSecEnv->defaultEnabled() ) {
208*cdf0e10cSrcweir 		HCERTSTORE hSystemStore ;
209*cdf0e10cSrcweir 
210*cdf0e10cSrcweir 		//Add system key store into the keys manager.
211*cdf0e10cSrcweir 		hSystemStore = CertOpenSystemStore( 0, "MY" ) ;
212*cdf0e10cSrcweir 		if( hSystemStore != NULL ) {
213*cdf0e10cSrcweir 			if( xmlSecMSCryptoAppliedKeysMngrAdoptKeyStore( m_pKeysMngr, hSystemStore ) < 0 ) {
214*cdf0e10cSrcweir 				CertCloseStore( hSystemStore, CERT_CLOSE_STORE_CHECK_FLAG ) ;
215*cdf0e10cSrcweir 				throw RuntimeException() ;
216*cdf0e10cSrcweir 			}
217*cdf0e10cSrcweir 		}
218*cdf0e10cSrcweir 
219*cdf0e10cSrcweir 		//Add system root store into the keys manager.
220*cdf0e10cSrcweir 		hSystemStore = CertOpenSystemStore( 0, "Root" ) ;
221*cdf0e10cSrcweir 		if( hSystemStore != NULL ) {
222*cdf0e10cSrcweir 			if( xmlSecMSCryptoAppliedKeysMngrAdoptTrustedStore( m_pKeysMngr, hSystemStore ) < 0 ) {
223*cdf0e10cSrcweir 				CertCloseStore( hSystemStore, CERT_CLOSE_STORE_CHECK_FLAG ) ;
224*cdf0e10cSrcweir 				throw RuntimeException() ;
225*cdf0e10cSrcweir 			}
226*cdf0e10cSrcweir 		}
227*cdf0e10cSrcweir 
228*cdf0e10cSrcweir 		//Add system trusted store into the keys manager.
229*cdf0e10cSrcweir 		hSystemStore = CertOpenSystemStore( 0, "Trust" ) ;
230*cdf0e10cSrcweir 		if( hSystemStore != NULL ) {
231*cdf0e10cSrcweir 			if( xmlSecMSCryptoAppliedKeysMngrAdoptUntrustedStore( m_pKeysMngr, hSystemStore ) < 0 ) {
232*cdf0e10cSrcweir 				CertCloseStore( hSystemStore, CERT_CLOSE_STORE_CHECK_FLAG ) ;
233*cdf0e10cSrcweir 				throw RuntimeException() ;
234*cdf0e10cSrcweir 			}
235*cdf0e10cSrcweir 		}
236*cdf0e10cSrcweir 
237*cdf0e10cSrcweir 		//Add system CA store into the keys manager.
238*cdf0e10cSrcweir 		hSystemStore = CertOpenSystemStore( 0, "CA" ) ;
239*cdf0e10cSrcweir 		if( hSystemStore != NULL ) {
240*cdf0e10cSrcweir 			if( xmlSecMSCryptoAppliedKeysMngrAdoptUntrustedStore( m_pKeysMngr, hSystemStore ) < 0 ) {
241*cdf0e10cSrcweir 				CertCloseStore( hSystemStore, CERT_CLOSE_STORE_CHECK_FLAG ) ;
242*cdf0e10cSrcweir 				throw RuntimeException() ;
243*cdf0e10cSrcweir 			}
244*cdf0e10cSrcweir 		}
245*cdf0e10cSrcweir 	}
246*cdf0e10cSrcweir }
247*cdf0e10cSrcweir 
248*cdf0e10cSrcweir /* XXMLSecurityContext */
249*cdf0e10cSrcweir Reference< XSecurityEnvironment > SAL_CALL XMLSecurityContext_MSCryptImpl :: getSecurityEnvironment()
250*cdf0e10cSrcweir 	throw (RuntimeException)
251*cdf0e10cSrcweir {
252*cdf0e10cSrcweir 	return	m_xSecurityEnvironment ;
253*cdf0e10cSrcweir }
254*cdf0e10cSrcweir #endif
255*cdf0e10cSrcweir 
256*cdf0e10cSrcweir /* XInitialization */
257*cdf0e10cSrcweir void SAL_CALL XMLSecurityContext_MSCryptImpl :: initialize( const Sequence< Any >& /*aArguments*/ ) throw( Exception, RuntimeException ) {
258*cdf0e10cSrcweir 	// TBD
259*cdf0e10cSrcweir } ;
260*cdf0e10cSrcweir 
261*cdf0e10cSrcweir /* XServiceInfo */
262*cdf0e10cSrcweir OUString SAL_CALL XMLSecurityContext_MSCryptImpl :: getImplementationName() throw( RuntimeException ) {
263*cdf0e10cSrcweir 	return impl_getImplementationName() ;
264*cdf0e10cSrcweir }
265*cdf0e10cSrcweir 
266*cdf0e10cSrcweir /* XServiceInfo */
267*cdf0e10cSrcweir sal_Bool SAL_CALL XMLSecurityContext_MSCryptImpl :: supportsService( const OUString& serviceName) throw( RuntimeException ) {
268*cdf0e10cSrcweir 	Sequence< OUString > seqServiceNames = getSupportedServiceNames() ;
269*cdf0e10cSrcweir 	const OUString* pArray = seqServiceNames.getConstArray() ;
270*cdf0e10cSrcweir 	for( sal_Int32 i = 0 ; i < seqServiceNames.getLength() ; i ++ ) {
271*cdf0e10cSrcweir 		if( *( pArray + i ) == serviceName )
272*cdf0e10cSrcweir 			return sal_True ;
273*cdf0e10cSrcweir 	}
274*cdf0e10cSrcweir 	return sal_False ;
275*cdf0e10cSrcweir }
276*cdf0e10cSrcweir 
277*cdf0e10cSrcweir /* XServiceInfo */
278*cdf0e10cSrcweir Sequence< OUString > SAL_CALL XMLSecurityContext_MSCryptImpl :: getSupportedServiceNames() throw( RuntimeException ) {
279*cdf0e10cSrcweir 	return impl_getSupportedServiceNames() ;
280*cdf0e10cSrcweir }
281*cdf0e10cSrcweir 
282*cdf0e10cSrcweir //Helper for XServiceInfo
283*cdf0e10cSrcweir Sequence< OUString > XMLSecurityContext_MSCryptImpl :: impl_getSupportedServiceNames() {
284*cdf0e10cSrcweir 	::osl::Guard< ::osl::Mutex > aGuard( ::osl::Mutex::getGlobalMutex() ) ;
285*cdf0e10cSrcweir 	Sequence< OUString > seqServiceNames( 1 ) ;
286*cdf0e10cSrcweir 	seqServiceNames.getArray()[0] = OUString::createFromAscii( "com.sun.star.xml.crypto.XMLSecurityContext" ) ;
287*cdf0e10cSrcweir 	return seqServiceNames ;
288*cdf0e10cSrcweir }
289*cdf0e10cSrcweir 
290*cdf0e10cSrcweir OUString XMLSecurityContext_MSCryptImpl :: impl_getImplementationName() throw( RuntimeException ) {
291*cdf0e10cSrcweir 	return OUString::createFromAscii( "com.sun.star.xml.security.bridge.xmlsec.XMLSecurityContext_MSCryptImpl" ) ;
292*cdf0e10cSrcweir }
293*cdf0e10cSrcweir 
294*cdf0e10cSrcweir //Helper for registry
295*cdf0e10cSrcweir Reference< XInterface > SAL_CALL XMLSecurityContext_MSCryptImpl :: impl_createInstance( const Reference< XMultiServiceFactory >& aServiceManager ) throw( RuntimeException ) {
296*cdf0e10cSrcweir 	return Reference< XInterface >( *new XMLSecurityContext_MSCryptImpl( aServiceManager ) ) ;
297*cdf0e10cSrcweir }
298*cdf0e10cSrcweir 
299*cdf0e10cSrcweir Reference< XSingleServiceFactory > XMLSecurityContext_MSCryptImpl :: impl_createFactory( const Reference< XMultiServiceFactory >& aServiceManager ) {
300*cdf0e10cSrcweir 	//Reference< XSingleServiceFactory > xFactory ;
301*cdf0e10cSrcweir 	//xFactory = ::cppu::createSingleFactory( aServiceManager , impl_getImplementationName , impl_createInstance , impl_getSupportedServiceNames ) ;
302*cdf0e10cSrcweir 	//return xFactory ;
303*cdf0e10cSrcweir 	return ::cppu::createSingleFactory( aServiceManager , impl_getImplementationName() , impl_createInstance , impl_getSupportedServiceNames() ) ;
304*cdf0e10cSrcweir }
305*cdf0e10cSrcweir 
306*cdf0e10cSrcweir #if 0
307*cdf0e10cSrcweir /* XUnoTunnel */
308*cdf0e10cSrcweir sal_Int64 SAL_CALL XMLSecurityContext_MSCryptImpl :: getSomething( const Sequence< sal_Int8 >& aIdentifier )
309*cdf0e10cSrcweir throw (RuntimeException)
310*cdf0e10cSrcweir {
311*cdf0e10cSrcweir 	if( aIdentifier.getLength() == 16 && 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(), aIdentifier.getConstArray(), 16 ) ) {
312*cdf0e10cSrcweir 		return ( sal_Int64 )this ;
313*cdf0e10cSrcweir 	}
314*cdf0e10cSrcweir 	return 0 ;
315*cdf0e10cSrcweir }
316*cdf0e10cSrcweir 
317*cdf0e10cSrcweir /* XUnoTunnel extension */
318*cdf0e10cSrcweir const Sequence< sal_Int8>& XMLSecurityContext_MSCryptImpl :: getUnoTunnelId() {
319*cdf0e10cSrcweir 	static Sequence< sal_Int8 >* pSeq = 0 ;
320*cdf0e10cSrcweir 	if( !pSeq ) {
321*cdf0e10cSrcweir 		::osl::Guard< ::osl::Mutex > aGuard( ::osl::Mutex::getGlobalMutex() ) ;
322*cdf0e10cSrcweir 		if( !pSeq ) {
323*cdf0e10cSrcweir 			static Sequence< sal_Int8> aSeq( 16 ) ;
324*cdf0e10cSrcweir 			rtl_createUuid( ( sal_uInt8* )aSeq.getArray() , 0 , sal_True ) ;
325*cdf0e10cSrcweir 			pSeq = &aSeq ;
326*cdf0e10cSrcweir 		}
327*cdf0e10cSrcweir 	}
328*cdf0e10cSrcweir 	return *pSeq ;
329*cdf0e10cSrcweir }
330*cdf0e10cSrcweir 
331*cdf0e10cSrcweir /* XUnoTunnel extension */
332*cdf0e10cSrcweir XMLSecurityContext_MSCryptImpl* XMLSecurityContext_MSCryptImpl :: getImplementation( const Reference< XInterface > xObj ) {
333*cdf0e10cSrcweir 	Reference< XUnoTunnel > xUT( xObj , UNO_QUERY ) ;
334*cdf0e10cSrcweir 	if( xUT.is() ) {
335*cdf0e10cSrcweir 		return ( XMLSecurityContext_MSCryptImpl* )xUT->getSomething( getUnoTunnelId() ) ;
336*cdf0e10cSrcweir 	} else
337*cdf0e10cSrcweir 		return NULL ;
338*cdf0e10cSrcweir }
339*cdf0e10cSrcweir 
340*cdf0e10cSrcweir /* Native methods */
341*cdf0e10cSrcweir xmlSecKeysMngrPtr XMLSecurityContext_MSCryptImpl :: keysManager() throw( Exception, RuntimeException ) {
342*cdf0e10cSrcweir 	return m_pKeysMngr ;
343*cdf0e10cSrcweir }
344*cdf0e10cSrcweir #endif
345*cdf0e10cSrcweir 
346