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 #ifndef _XSECURITYENVIRONMENT_NSSIMPL_HXX_
29 #define _XSECURITYENVIRONMENT_NSSIMPL_HXX_
31 #include <sal/config.h>
32 #include <rtl/ustring.hxx>
33 #include <cppuhelper/factory.hxx>
34 #include <cppuhelper/implbase4.hxx>
35 #include <com/sun/star/uno/Exception.hpp>
37 #ifndef _COM_SUN_STAR_UNO_REFERENCE_HPP_
38 #include <com/sun/star/uno/Reference.hxx>
40 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
42 #ifndef _COM_SUN_STAR_LANG_XSECVICEINFO_HPP_
43 #include <com/sun/star/lang/XServiceInfo.hpp>
45 #include <com/sun/star/lang/XInitialization.hpp>
46 #include <com/sun/star/xml/crypto/XSecurityEnvironment.hpp>
47 #include <com/sun/star/security/XCertificate.hpp>
48 #include <com/sun/star/security/CertificateCharacters.hpp>
49 #include <com/sun/star/security/CertificateValidity.hpp>
50 #include <com/sun/star/lang/XUnoTunnel.hpp>
52 #include "osl/mutex.hxx"
59 #include <sal/types.h>
60 //For reasons that escape me, this is what xmlsec does when size_t is not 4
61 #if SAL_TYPES_SIZEOFPOINTER != 4
62 # define XMLSEC_NO_SIZE_T
64 #include "xmlsec/xmlsec.h"
66 class SecurityEnvironment_NssImpl
: public ::cppu::WeakImplHelper4
<
67 ::com::sun::star::xml::crypto::XSecurityEnvironment
,
68 ::com::sun::star::lang::XInitialization
,
69 ::com::sun::star::lang::XServiceInfo
,
70 ::com::sun::star::lang::XUnoTunnel
>
74 std::list
< PK11SlotInfo
* > m_Slots
;
75 typedef std::list
< PK11SlotInfo
* >::const_iterator CIT_SLOTS
;
79 CERTCertDBHandle
* m_pHandler
;
80 std::list
< PK11SymKey
* > m_tSymKeyList
;
81 std::list
< SECKEYPublicKey
* > m_tPubKeyList
;
82 std::list
< SECKEYPrivateKey
* > m_tPriKeyList
;
83 ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
> m_xServiceManager
;
86 SecurityEnvironment_NssImpl( const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
>& aFactory
) ;
87 virtual ~SecurityEnvironment_NssImpl() ;
89 //Methods from XSecurityEnvironment
91 //Methods from XInitialization
92 virtual void SAL_CALL
initialize(
93 const ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Any
>& aArguments
94 ) throw( ::com::sun::star::uno::Exception
, ::com::sun::star::uno::RuntimeException
) ;
96 //Methods from XServiceInfo
97 virtual ::rtl::OUString SAL_CALL
getImplementationName() throw( ::com::sun::star::uno::RuntimeException
) ;
99 virtual sal_Bool SAL_CALL
supportsService(
100 const ::rtl::OUString
& ServiceName
101 ) throw( ::com::sun::star::uno::RuntimeException
) ;
103 virtual ::com::sun::star::uno::Sequence
< ::rtl::OUString
> SAL_CALL
getSupportedServiceNames() throw( ::com::sun::star::uno::RuntimeException
) ;
105 //Helper for XServiceInfo
106 static ::com::sun::star::uno::Sequence
< ::rtl::OUString
> impl_getSupportedServiceNames() ;
108 static ::rtl::OUString
impl_getImplementationName() throw( ::com::sun::star::uno::RuntimeException
) ;
110 //Helper for registry
111 static ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
> SAL_CALL
impl_createInstance( const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
>& aServiceManager
) throw( ::com::sun::star::uno::RuntimeException
) ;
113 static ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XSingleServiceFactory
> impl_createFactory( const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
>& aServiceManager
) ;
115 virtual ::sal_Int32 SAL_CALL
verifyCertificate(
116 const ::com::sun::star::uno::Reference
<
117 ::com::sun::star::security::XCertificate
>& xCert
,
118 const ::com::sun::star::uno::Sequence
<
119 ::com::sun::star::uno::Reference
< ::com::sun::star::security::XCertificate
> > &
121 throw (::com::sun::star::uno::SecurityException
, ::com::sun::star::uno::RuntimeException
) ;
123 virtual ::sal_Int32 SAL_CALL
getCertificateCharacters( const ::com::sun::star::uno::Reference
< ::com::sun::star::security::XCertificate
>& xCert
) throw (::com::sun::star::uno::SecurityException
, ::com::sun::star::uno::RuntimeException
) ;
125 virtual ::rtl::OUString SAL_CALL
getSecurityEnvironmentInformation( ) throw (::com::sun::star::uno::RuntimeException
);
127 //Methods from XUnoTunnel
128 virtual sal_Int64 SAL_CALL
getSomething( const ::com::sun::star::uno::Sequence
< sal_Int8
>& aIdentifier
)
129 throw (::com::sun::star::uno::RuntimeException
);
131 static const ::com::sun::star::uno::Sequence
< sal_Int8
>& getUnoTunnelId() ;
132 static SecurityEnvironment_NssImpl
* getImplementation( const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
> xObj
) ;
135 virtual CERTCertDBHandle
* getCertDb() throw( ::com::sun::star::uno::Exception
, ::com::sun::star::uno::RuntimeException
) ;
137 virtual void setCertDb( CERTCertDBHandle
* aCertDb
) throw( ::com::sun::star::uno::Exception
, ::com::sun::star::uno::RuntimeException
) ;
139 virtual void adoptSymKey( PK11SymKey
* aSymKey
) throw( ::com::sun::star::uno::Exception
, ::com::sun::star::uno::RuntimeException
) ;
141 virtual void rejectSymKey( PK11SymKey
* aSymKey
) throw( ::com::sun::star::uno::Exception
, ::com::sun::star::uno::RuntimeException
) ;
143 virtual PK11SymKey
* getSymKey( unsigned int position
) throw( ::com::sun::star::uno::Exception
, ::com::sun::star::uno::RuntimeException
) ;
145 virtual void adoptPubKey( SECKEYPublicKey
* aPubKey
) throw( ::com::sun::star::uno::Exception
, ::com::sun::star::uno::RuntimeException
) ;
147 virtual void rejectPubKey( SECKEYPublicKey
* aPubKey
) throw( ::com::sun::star::uno::Exception
, ::com::sun::star::uno::RuntimeException
) ;
149 virtual SECKEYPublicKey
* getPubKey( unsigned int position
) throw( ::com::sun::star::uno::Exception
, ::com::sun::star::uno::RuntimeException
) ;
151 virtual void adoptPriKey( SECKEYPrivateKey
* aPriKey
) throw( ::com::sun::star::uno::Exception
, ::com::sun::star::uno::RuntimeException
) ;
153 virtual void rejectPriKey( SECKEYPrivateKey
* aPriKey
) throw( ::com::sun::star::uno::Exception
, ::com::sun::star::uno::RuntimeException
) ;
155 virtual SECKEYPrivateKey
* getPriKey( unsigned int position
) throw( ::com::sun::star::uno::Exception
, ::com::sun::star::uno::RuntimeException
) ;
157 virtual ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Reference
< ::com::sun::star::security::XCertificate
> > SAL_CALL
getPersonalCertificates() throw( ::com::sun::star::uno::SecurityException
, ::com::sun::star::uno::RuntimeException
) ;
159 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::security::XCertificate
> SAL_CALL
getCertificate( const ::rtl::OUString
& issuerName
, const ::com::sun::star::uno::Sequence
< sal_Int8
>& serialNumber
) throw( ::com::sun::star::uno::SecurityException
, ::com::sun::star::uno::RuntimeException
) ;
161 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::security::XCertificate
> SAL_CALL
getCertificate( const ::rtl::OUString
& issuerName
, const ::rtl::OUString
& serialNumber
) throw( ::com::sun::star::uno::SecurityException
, ::com::sun::star::uno::RuntimeException
) ;
163 virtual ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Reference
< ::com::sun::star::security::XCertificate
> > SAL_CALL
buildCertificatePath( const ::com::sun::star::uno::Reference
< ::com::sun::star::security::XCertificate
>& beginCert
) throw( ::com::sun::star::uno::SecurityException
, ::com::sun::star::uno::RuntimeException
) ;
165 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::security::XCertificate
> SAL_CALL
createCertificateFromRaw( const ::com::sun::star::uno::Sequence
< sal_Int8
>& rawCertificate
) throw( ::com::sun::star::uno::SecurityException
, ::com::sun::star::uno::RuntimeException
) ;
167 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::security::XCertificate
> SAL_CALL
createCertificateFromAscii( const ::rtl::OUString
& asciiCertificate
) throw( ::com::sun::star::uno::SecurityException
, ::com::sun::star::uno::RuntimeException
) ;
171 virtual xmlSecKeysMngrPtr
createKeysManager() throw( ::com::sun::star::uno::Exception
, ::com::sun::star::uno::RuntimeException
) ;
172 virtual void destroyKeysManager(xmlSecKeysMngrPtr pKeysMngr
) throw( ::com::sun::star::uno::Exception
, ::com::sun::star::uno::RuntimeException
) ;
177 virtual void addCryptoSlot( PK11SlotInfo
* aSlot
) throw( ::com::sun::star::uno::Exception
, ::com::sun::star::uno::RuntimeException
) ;
182 #endif // _XSECURITYENVIRONMENT_NSSIMPL_HXX_