1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_xmlsecurity.hxx"
31 #include <sal/config.h>
34 #include <osl/mutex.hxx>
35 #include <osl/thread.h>
36 #include <cppuhelper/factory.hxx>
37 #include <cppuhelper/implbase1.hxx>
38 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
39 #include <com/sun/star/security/XSerialNumberAdapter.hpp>
41 #include "xmlelementwrapper_xmlsecimpl.hxx"
42 #include "xmldocumentwrapper_xmlsecimpl.hxx"
43 #include "xmlsecurity/biginteger.hxx"
45 using namespace ::rtl
;
46 using namespace ::cppu
;
47 using namespace ::com::sun::star::uno
;
48 using namespace ::com::sun::star::lang
;
49 using namespace ::com::sun::star::registry
;
53 class SerialNumberAdapterImpl
: public WeakImplHelper1
<
54 ::com::sun::star::security::XSerialNumberAdapter
>
56 virtual OUString SAL_CALL
toString( const Sequence
< sal_Int8
>& rSerialNumber
)
57 throw (RuntimeException
)
59 return bigIntegerToNumericString(rSerialNumber
);
61 virtual Sequence
< sal_Int8
> SAL_CALL
toSequence( const OUString
& rSerialNumber
)
62 throw (RuntimeException
)
64 return numericStringToBigInteger(rSerialNumber
);
68 OUString
SerialNumberAdapterImpl_getImplementationName()
69 throw (RuntimeException
)
71 return OUString(RTL_CONSTASCII_USTRINGPARAM(
72 "com.sun.star.security.SerialNumberAdapter"));
75 Sequence
< OUString
> SerialNumberAdapterImpl_getSupportedServiceNames()
76 throw (RuntimeException
)
78 Sequence
< OUString
> aRet(1);
79 OUString
* pArray
= aRet
.getArray();
80 pArray
[0] = OUString(RTL_CONSTASCII_USTRINGPARAM(
81 "com.sun.star.security.SerialNumberAdapter" ) );
85 Reference
< XInterface
> SerialNumberAdapterImpl_createInstance(
86 const Reference
< XComponentContext
> &) throw( Exception
)
88 return Reference
< XInterface
>( *new SerialNumberAdapterImpl() );
96 #if defined( XMLSEC_CRYPTO_NSS )
97 extern sal_Bool
nss_component_writeInfo( void*, void* );
98 extern void* nss_component_getFactory( const sal_Char
*, void*, void* );
101 #if defined( XMLSEC_CRYPTO_MSCRYPTO )
102 extern sal_Bool
mscrypt_component_writeInfo( void*, void* );
103 extern void* mscrypt_component_getFactory( const sal_Char
*, void*, void* );
106 void SAL_CALL
component_getImplementationEnvironment(
107 const sal_Char
** ppEnvTypeName
, uno_Environment
**)
109 *ppEnvTypeName
= CPPU_CURRENT_LANGUAGE_BINDING_NAME
;
113 sal_Bool SAL_CALL
component_writeInfo( void* pServiceManager
, void* pRegistryKey
)
115 sal_Bool result
= sal_False
;
118 Reference
< XRegistryKey
> xNewKey
;
119 Sequence
< OUString
> seqServices
;
120 Reference
< XRegistryKey
> xKey( reinterpret_cast< XRegistryKey
* >( pRegistryKey
) ) ;
124 // XMLElementWrapper_XmlSecImpl
125 sKeyName
= OUString( RTL_CONSTASCII_USTRINGPARAM( "/" ) ) ;
126 sKeyName
+= XMLElementWrapper_XmlSecImpl_getImplementationName() ;
127 sKeyName
+= OUString::createFromAscii( "/UNO/SERVICES" ) ;
129 xNewKey
= xKey
->createKey( sKeyName
) ;
131 seqServices
= XMLElementWrapper_XmlSecImpl_getSupportedServiceNames() ;
132 for( i
= seqServices
.getLength() ; i
-- ; )
133 xNewKey
->createKey( seqServices
.getConstArray()[i
] ) ;
136 // XMLDocumentWrapper_XmlSecImpl
137 sKeyName
= OUString( RTL_CONSTASCII_USTRINGPARAM( "/" ) ) ;
138 sKeyName
+= XMLDocumentWrapper_XmlSecImpl_getImplementationName() ;
139 sKeyName
+= OUString::createFromAscii( "/UNO/SERVICES" ) ;
141 xNewKey
= xKey
->createKey( sKeyName
) ;
143 seqServices
= XMLDocumentWrapper_XmlSecImpl_getSupportedServiceNames() ;
144 for( i
= seqServices
.getLength() ; i
-- ; )
145 xNewKey
->createKey( seqServices
.getConstArray()[i
] ) ;
148 // SerialNumberAdapterImpl
149 sKeyName
= OUString( RTL_CONSTASCII_USTRINGPARAM( "/" ) ) ;
150 sKeyName
+= SerialNumberAdapterImpl_getImplementationName() ;
151 sKeyName
+= OUString::createFromAscii( "/UNO/SERVICES" ) ;
153 xNewKey
= xKey
->createKey( sKeyName
) ;
155 seqServices
= SerialNumberAdapterImpl_getSupportedServiceNames() ;
156 for( i
= seqServices
.getLength() ; i
-- ; )
157 xNewKey
->createKey( seqServices
.getConstArray()[i
] ) ;
160 #if defined( XMLSEC_CRYPTO_NSS )
161 result
= nss_component_writeInfo( pServiceManager
, pRegistryKey
) ;
166 #if defined( XMLSEC_CRYPTO_MSCRYPTO )
167 result
= mscrypt_component_writeInfo( pServiceManager
, pRegistryKey
) ;
172 //} catch( InvalidRegistryException & ) {
173 // //we should not ignore exceptions
174 // return sal_False ;
181 void* SAL_CALL
component_getFactory( const sal_Char
* pImplName
, void* pServiceManager
, void* pRegistryKey
)
184 Reference
< XInterface
> xFactory
;
186 if( pImplName
!= NULL
&& pServiceManager
!= NULL
) {
187 if( XMLElementWrapper_XmlSecImpl_getImplementationName().equals( OUString::createFromAscii( pImplName
) ) )
189 xFactory
= Reference
< XSingleServiceFactory
>( createSingleFactory(
190 reinterpret_cast< XMultiServiceFactory
* >( pServiceManager
),
191 OUString::createFromAscii( pImplName
),
192 XMLElementWrapper_XmlSecImpl_createInstance
, XMLElementWrapper_XmlSecImpl_getSupportedServiceNames() ) );
194 else if( XMLDocumentWrapper_XmlSecImpl_getImplementationName().equals( OUString::createFromAscii( pImplName
) ) )
196 xFactory
= Reference
< XSingleServiceFactory
>( createSingleFactory(
197 reinterpret_cast< XMultiServiceFactory
* >( pServiceManager
),
198 OUString::createFromAscii( pImplName
),
199 XMLDocumentWrapper_XmlSecImpl_createInstance
, XMLDocumentWrapper_XmlSecImpl_getSupportedServiceNames() ) );
201 else if( SerialNumberAdapterImpl_getImplementationName().equals( OUString::createFromAscii( pImplName
) ) )
203 xFactory
= ::cppu::createSingleComponentFactory(
204 SerialNumberAdapterImpl_createInstance
,
205 OUString::createFromAscii( pImplName
),
206 SerialNumberAdapterImpl_getSupportedServiceNames() );
210 if( xFactory
.is() ) {
211 xFactory
->acquire() ;
212 pRet
= xFactory
.get() ;
214 #if defined( XMLSEC_CRYPTO_NSS )
215 pRet
= nss_component_getFactory( pImplName
, pServiceManager
, pRegistryKey
) ;
220 #if defined( XMLSEC_CRYPTO_MSCRYPTO )
221 pRet
= mscrypt_component_getFactory( pImplName
, pServiceManager
, pRegistryKey
) ;