1*b1cdbd2cSJim Jagielski /**************************************************************
2*b1cdbd2cSJim Jagielski  *
3*b1cdbd2cSJim Jagielski  * Licensed to the Apache Software Foundation (ASF) under one
4*b1cdbd2cSJim Jagielski  * or more contributor license agreements.  See the NOTICE file
5*b1cdbd2cSJim Jagielski  * distributed with this work for additional information
6*b1cdbd2cSJim Jagielski  * regarding copyright ownership.  The ASF licenses this file
7*b1cdbd2cSJim Jagielski  * to you under the Apache License, Version 2.0 (the
8*b1cdbd2cSJim Jagielski  * "License"); you may not use this file except in compliance
9*b1cdbd2cSJim Jagielski  * with the License.  You may obtain a copy of the License at
10*b1cdbd2cSJim Jagielski  *
11*b1cdbd2cSJim Jagielski  *   http://www.apache.org/licenses/LICENSE-2.0
12*b1cdbd2cSJim Jagielski  *
13*b1cdbd2cSJim Jagielski  * Unless required by applicable law or agreed to in writing,
14*b1cdbd2cSJim Jagielski  * software distributed under the License is distributed on an
15*b1cdbd2cSJim Jagielski  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*b1cdbd2cSJim Jagielski  * KIND, either express or implied.  See the License for the
17*b1cdbd2cSJim Jagielski  * specific language governing permissions and limitations
18*b1cdbd2cSJim Jagielski  * under the License.
19*b1cdbd2cSJim Jagielski  *
20*b1cdbd2cSJim Jagielski  *************************************************************/
21*b1cdbd2cSJim Jagielski 
22*b1cdbd2cSJim Jagielski 
23*b1cdbd2cSJim Jagielski 
24*b1cdbd2cSJim Jagielski #ifndef _XSECURITYENVIRONMENT_NSSIMPL_HXX_
25*b1cdbd2cSJim Jagielski #define _XSECURITYENVIRONMENT_NSSIMPL_HXX_
26*b1cdbd2cSJim Jagielski 
27*b1cdbd2cSJim Jagielski #include <sal/config.h>
28*b1cdbd2cSJim Jagielski #include <rtl/ustring.hxx>
29*b1cdbd2cSJim Jagielski #include <cppuhelper/factory.hxx>
30*b1cdbd2cSJim Jagielski #include <cppuhelper/implbase4.hxx>
31*b1cdbd2cSJim Jagielski #include <com/sun/star/uno/Exception.hpp>
32*b1cdbd2cSJim Jagielski 
33*b1cdbd2cSJim Jagielski #ifndef _COM_SUN_STAR_UNO_REFERENCE_HPP_
34*b1cdbd2cSJim Jagielski #include <com/sun/star/uno/Reference.hxx>
35*b1cdbd2cSJim Jagielski #endif
36*b1cdbd2cSJim Jagielski #include <com/sun/star/lang/XSingleServiceFactory.hpp>
37*b1cdbd2cSJim Jagielski 
38*b1cdbd2cSJim Jagielski #ifndef _COM_SUN_STAR_LANG_XSECVICEINFO_HPP_
39*b1cdbd2cSJim Jagielski #include <com/sun/star/lang/XServiceInfo.hpp>
40*b1cdbd2cSJim Jagielski #endif
41*b1cdbd2cSJim Jagielski #include <com/sun/star/lang/XInitialization.hpp>
42*b1cdbd2cSJim Jagielski #include <com/sun/star/xml/crypto/XSecurityEnvironment.hpp>
43*b1cdbd2cSJim Jagielski #include <com/sun/star/security/XCertificate.hpp>
44*b1cdbd2cSJim Jagielski #include <com/sun/star/security/CertificateCharacters.hpp>
45*b1cdbd2cSJim Jagielski #include <com/sun/star/security/CertificateValidity.hpp>
46*b1cdbd2cSJim Jagielski #include <com/sun/star/lang/XUnoTunnel.hpp>
47*b1cdbd2cSJim Jagielski 
48*b1cdbd2cSJim Jagielski #include "osl/mutex.hxx"
49*b1cdbd2cSJim Jagielski 
50*b1cdbd2cSJim Jagielski #include "pk11func.h"
51*b1cdbd2cSJim Jagielski #include "keyhi.h"
52*b1cdbd2cSJim Jagielski #include "certdb.h"
53*b1cdbd2cSJim Jagielski #include "list"
54*b1cdbd2cSJim Jagielski 
55*b1cdbd2cSJim Jagielski #include <sal/types.h>
56*b1cdbd2cSJim Jagielski //For reasons that escape me, this is what xmlsec does when size_t is not 4
57*b1cdbd2cSJim Jagielski #if SAL_TYPES_SIZEOFPOINTER != 4
58*b1cdbd2cSJim Jagielski #    define XMLSEC_NO_SIZE_T
59*b1cdbd2cSJim Jagielski #endif
60*b1cdbd2cSJim Jagielski #include "xmlsec/xmlsec.h"
61*b1cdbd2cSJim Jagielski 
62*b1cdbd2cSJim Jagielski class SecurityEnvironment_NssImpl : public ::cppu::WeakImplHelper4<
63*b1cdbd2cSJim Jagielski 	::com::sun::star::xml::crypto::XSecurityEnvironment ,
64*b1cdbd2cSJim Jagielski 	::com::sun::star::lang::XInitialization ,
65*b1cdbd2cSJim Jagielski 	::com::sun::star::lang::XServiceInfo ,
66*b1cdbd2cSJim Jagielski 	::com::sun::star::lang::XUnoTunnel >
67*b1cdbd2cSJim Jagielski {
68*b1cdbd2cSJim Jagielski private :
69*b1cdbd2cSJim Jagielski 
70*b1cdbd2cSJim Jagielski     std::list< PK11SlotInfo* > m_Slots;
71*b1cdbd2cSJim Jagielski     typedef std::list< PK11SlotInfo* >::const_iterator CIT_SLOTS;
72*b1cdbd2cSJim Jagielski 
73*b1cdbd2cSJim Jagielski     osl::Mutex m_mutex;
74*b1cdbd2cSJim Jagielski 
75*b1cdbd2cSJim Jagielski 		CERTCertDBHandle*					m_pHandler ;
76*b1cdbd2cSJim Jagielski 		std::list< PK11SymKey* >			m_tSymKeyList ;
77*b1cdbd2cSJim Jagielski 		std::list< SECKEYPublicKey* >		m_tPubKeyList ;
78*b1cdbd2cSJim Jagielski 		std::list< SECKEYPrivateKey* >		m_tPriKeyList ;
79*b1cdbd2cSJim Jagielski 		::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > m_xServiceManager ;
80*b1cdbd2cSJim Jagielski 
81*b1cdbd2cSJim Jagielski 	public :
82*b1cdbd2cSJim Jagielski 		SecurityEnvironment_NssImpl( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& aFactory ) ;
83*b1cdbd2cSJim Jagielski 		virtual ~SecurityEnvironment_NssImpl() ;
84*b1cdbd2cSJim Jagielski 
85*b1cdbd2cSJim Jagielski 		//Methods from XSecurityEnvironment
86*b1cdbd2cSJim Jagielski 
87*b1cdbd2cSJim Jagielski 		//Methods from XInitialization
88*b1cdbd2cSJim Jagielski 		virtual void SAL_CALL initialize(
89*b1cdbd2cSJim Jagielski 			const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments
90*b1cdbd2cSJim Jagielski 		) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;
91*b1cdbd2cSJim Jagielski 
92*b1cdbd2cSJim Jagielski 		//Methods from XServiceInfo
93*b1cdbd2cSJim Jagielski 		virtual ::rtl::OUString SAL_CALL getImplementationName() throw( ::com::sun::star::uno::RuntimeException ) ;
94*b1cdbd2cSJim Jagielski 
95*b1cdbd2cSJim Jagielski 		virtual sal_Bool SAL_CALL supportsService(
96*b1cdbd2cSJim Jagielski 			const ::rtl::OUString& ServiceName
97*b1cdbd2cSJim Jagielski 		) throw( ::com::sun::star::uno::RuntimeException ) ;
98*b1cdbd2cSJim Jagielski 
99*b1cdbd2cSJim Jagielski 		virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames() throw( ::com::sun::star::uno::RuntimeException ) ;
100*b1cdbd2cSJim Jagielski 
101*b1cdbd2cSJim Jagielski 		//Helper for XServiceInfo
102*b1cdbd2cSJim Jagielski 		static ::com::sun::star::uno::Sequence< ::rtl::OUString > impl_getSupportedServiceNames() ;
103*b1cdbd2cSJim Jagielski 
104*b1cdbd2cSJim Jagielski 		static ::rtl::OUString impl_getImplementationName() throw( ::com::sun::star::uno::RuntimeException ) ;
105*b1cdbd2cSJim Jagielski 
106*b1cdbd2cSJim Jagielski 		//Helper for registry
107*b1cdbd2cSJim Jagielski 		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 ) ;
108*b1cdbd2cSJim Jagielski 
109*b1cdbd2cSJim Jagielski 		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 ) ;
110*b1cdbd2cSJim Jagielski 
111*b1cdbd2cSJim Jagielski 		virtual ::sal_Int32 SAL_CALL verifyCertificate(
112*b1cdbd2cSJim Jagielski             const ::com::sun::star::uno::Reference<
113*b1cdbd2cSJim Jagielski             ::com::sun::star::security::XCertificate >& xCert,
114*b1cdbd2cSJim Jagielski             const ::com::sun::star::uno::Sequence<
115*b1cdbd2cSJim Jagielski             ::com::sun::star::uno::Reference< ::com::sun::star::security::XCertificate > > &
116*b1cdbd2cSJim Jagielski             intermediateCerts)
117*b1cdbd2cSJim Jagielski             throw (::com::sun::star::uno::SecurityException, ::com::sun::star::uno::RuntimeException) ;
118*b1cdbd2cSJim Jagielski 
119*b1cdbd2cSJim Jagielski 		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) ;
120*b1cdbd2cSJim Jagielski 
121*b1cdbd2cSJim Jagielski 		virtual ::rtl::OUString SAL_CALL getSecurityEnvironmentInformation(  ) throw (::com::sun::star::uno::RuntimeException);
122*b1cdbd2cSJim Jagielski 
123*b1cdbd2cSJim Jagielski 		//Methods from XUnoTunnel
124*b1cdbd2cSJim Jagielski 		virtual sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& aIdentifier )
125*b1cdbd2cSJim Jagielski 			throw (::com::sun::star::uno::RuntimeException);
126*b1cdbd2cSJim Jagielski 
127*b1cdbd2cSJim Jagielski 		static const ::com::sun::star::uno::Sequence< sal_Int8 >& getUnoTunnelId() ;
128*b1cdbd2cSJim Jagielski 		static SecurityEnvironment_NssImpl* getImplementation( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > xObj ) ;
129*b1cdbd2cSJim Jagielski 
130*b1cdbd2cSJim Jagielski 		//Native mehtods
131*b1cdbd2cSJim Jagielski 		virtual CERTCertDBHandle* getCertDb() throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;
132*b1cdbd2cSJim Jagielski 
133*b1cdbd2cSJim Jagielski 		virtual void setCertDb( CERTCertDBHandle* aCertDb ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;
134*b1cdbd2cSJim Jagielski 
135*b1cdbd2cSJim Jagielski 		virtual void adoptSymKey( PK11SymKey* aSymKey ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;
136*b1cdbd2cSJim Jagielski 
137*b1cdbd2cSJim Jagielski 		virtual void rejectSymKey( PK11SymKey* aSymKey ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;
138*b1cdbd2cSJim Jagielski 
139*b1cdbd2cSJim Jagielski 		virtual PK11SymKey* getSymKey( unsigned int position ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;
140*b1cdbd2cSJim Jagielski 
141*b1cdbd2cSJim Jagielski 		virtual void adoptPubKey( SECKEYPublicKey* aPubKey ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;
142*b1cdbd2cSJim Jagielski 
143*b1cdbd2cSJim Jagielski 		virtual void rejectPubKey( SECKEYPublicKey* aPubKey ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;
144*b1cdbd2cSJim Jagielski 
145*b1cdbd2cSJim Jagielski 		virtual SECKEYPublicKey* getPubKey( unsigned int position ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;
146*b1cdbd2cSJim Jagielski 
147*b1cdbd2cSJim Jagielski 		virtual void adoptPriKey( SECKEYPrivateKey* aPriKey ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;
148*b1cdbd2cSJim Jagielski 
149*b1cdbd2cSJim Jagielski 		virtual void rejectPriKey( SECKEYPrivateKey* aPriKey ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;
150*b1cdbd2cSJim Jagielski 
151*b1cdbd2cSJim Jagielski 		virtual SECKEYPrivateKey* getPriKey( unsigned int position ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;
152*b1cdbd2cSJim Jagielski 
153*b1cdbd2cSJim Jagielski 		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 ) ;
154*b1cdbd2cSJim Jagielski 
155*b1cdbd2cSJim Jagielski 		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 ) ;
156*b1cdbd2cSJim Jagielski 
157*b1cdbd2cSJim Jagielski 		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 ) ;
158*b1cdbd2cSJim Jagielski 
159*b1cdbd2cSJim Jagielski 		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 ) ;
160*b1cdbd2cSJim Jagielski 
161*b1cdbd2cSJim Jagielski 		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 ) ;
162*b1cdbd2cSJim Jagielski 
163*b1cdbd2cSJim Jagielski 		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 ) ;
164*b1cdbd2cSJim Jagielski 
165*b1cdbd2cSJim Jagielski 
166*b1cdbd2cSJim Jagielski 		//Native mehtods
167*b1cdbd2cSJim Jagielski 		virtual xmlSecKeysMngrPtr createKeysManager() throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;
168*b1cdbd2cSJim Jagielski 		virtual void destroyKeysManager(xmlSecKeysMngrPtr pKeysMngr) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;
169*b1cdbd2cSJim Jagielski 
170*b1cdbd2cSJim Jagielski private:
171*b1cdbd2cSJim Jagielski         void updateSlots();
172*b1cdbd2cSJim Jagielski 
173*b1cdbd2cSJim Jagielski   		virtual void addCryptoSlot( PK11SlotInfo* aSlot ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;
174*b1cdbd2cSJim Jagielski 
175*b1cdbd2cSJim Jagielski 
176*b1cdbd2cSJim Jagielski } ;
177*b1cdbd2cSJim Jagielski 
178*b1cdbd2cSJim Jagielski #endif	// _XSECURITYENVIRONMENT_NSSIMPL_HXX_
179*b1cdbd2cSJim Jagielski 
180