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