xref: /AOO41X/main/xmlsecurity/source/xmlsec/mscrypt/securityenvironment_mscryptimpl.hxx (revision 5ea637d9b43ce9969bbd32d03ce3c0cbed3a2df2)
1ec61c6edSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3ec61c6edSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4ec61c6edSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5ec61c6edSAndrew Rist  * distributed with this work for additional information
6ec61c6edSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7ec61c6edSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8ec61c6edSAndrew Rist  * "License"); you may not use this file except in compliance
9ec61c6edSAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11ec61c6edSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13ec61c6edSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14ec61c6edSAndrew Rist  * software distributed under the License is distributed on an
15ec61c6edSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16ec61c6edSAndrew Rist  * KIND, either express or implied.  See the License for the
17ec61c6edSAndrew Rist  * specific language governing permissions and limitations
18ec61c6edSAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20ec61c6edSAndrew Rist  *************************************************************/
21ec61c6edSAndrew Rist 
22ec61c6edSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef _XSECURITYENVIRONMENT_MSCRYPTIMPL_HXX_
25cdf0e10cSrcweir #define _XSECURITYENVIRONMENT_MSCRYPTIMPL_HXX_
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #ifdef _MSC_VER
28cdf0e10cSrcweir #pragma warning(push,1)
29cdf0e10cSrcweir #endif
30cdf0e10cSrcweir #include <windows.h>
31cdf0e10cSrcweir #include <wincrypt.h>
32cdf0e10cSrcweir #ifdef _MSC_VER
33cdf0e10cSrcweir #pragma warning(pop)
34cdf0e10cSrcweir #endif
35cdf0e10cSrcweir #include <sal/config.h>
36cdf0e10cSrcweir #include <rtl/ustring.hxx>
37cdf0e10cSrcweir #include <cppuhelper/factory.hxx>
38cdf0e10cSrcweir #include <cppuhelper/implbase4.hxx>
39cdf0e10cSrcweir #include <com/sun/star/uno/Exception.hpp>
40cdf0e10cSrcweir 
41cdf0e10cSrcweir #ifndef _COM_SUN_STAR_UNO_REFERENCE_HPP_
42cdf0e10cSrcweir #include <com/sun/star/uno/Reference.hxx>
43cdf0e10cSrcweir #endif
44cdf0e10cSrcweir #include <com/sun/star/lang/XSingleServiceFactory.hpp>
45cdf0e10cSrcweir 
46cdf0e10cSrcweir #ifndef _COM_SUN_STAR_LANG_XSECVICEINFO_HPP_
47cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp>
48cdf0e10cSrcweir #endif
49cdf0e10cSrcweir #include <com/sun/star/lang/XInitialization.hpp>
50cdf0e10cSrcweir #include <com/sun/star/xml/crypto/XSecurityEnvironment.hpp>
51cdf0e10cSrcweir #include <com/sun/star/security/XCertificate.hpp>
52cdf0e10cSrcweir #include <com/sun/star/security/CertificateCharacters.hpp>
53cdf0e10cSrcweir #include <com/sun/star/security/CertificateValidity.hpp>
54cdf0e10cSrcweir #include <com/sun/star/lang/XUnoTunnel.hpp>
55cdf0e10cSrcweir 
56cdf0e10cSrcweir #include <list>
57cdf0e10cSrcweir #include "xmlsec/xmlsec.h"
58cdf0e10cSrcweir 
59cdf0e10cSrcweir #include "sal/types.h"
60cdf0e10cSrcweir 
61cdf0e10cSrcweir 
62cdf0e10cSrcweir class SecurityEnvironment_MSCryptImpl : public ::cppu::WeakImplHelper4<
63cdf0e10cSrcweir 	::com::sun::star::xml::crypto::XSecurityEnvironment ,
64cdf0e10cSrcweir 	::com::sun::star::lang::XInitialization ,
65cdf0e10cSrcweir 	::com::sun::star::lang::XServiceInfo ,
66cdf0e10cSrcweir 	::com::sun::star::lang::XUnoTunnel >
67cdf0e10cSrcweir {
68cdf0e10cSrcweir 	private :
69cdf0e10cSrcweir 		//cyrpto provider and key container
70cdf0e10cSrcweir 		HCRYPTPROV							m_hProv ;
71cdf0e10cSrcweir 		LPCTSTR								m_pszContainer ;
72cdf0e10cSrcweir 
73cdf0e10cSrcweir 		//Key store
74cdf0e10cSrcweir 		HCERTSTORE							m_hKeyStore ;
75cdf0e10cSrcweir 
76cdf0e10cSrcweir 		//Certiticate store
77cdf0e10cSrcweir 		HCERTSTORE							m_hCertStore ;
78cdf0e10cSrcweir 
79*5ea637d9SJian Fang Zhang 		// i120675, save the store handles
80*5ea637d9SJian Fang Zhang 		HCERTSTORE 							m_hMySystemStore;
81*5ea637d9SJian Fang Zhang 		HCERTSTORE 							m_hRootSystemStore;
82*5ea637d9SJian Fang Zhang 		HCERTSTORE 							m_hTrustSystemStore;
83*5ea637d9SJian Fang Zhang 		HCERTSTORE 							m_hCaSystemStore;
84*5ea637d9SJian Fang Zhang 
85cdf0e10cSrcweir 		//Enable default system cryptography setting
86cdf0e10cSrcweir 		sal_Bool							m_bEnableDefault ;
87cdf0e10cSrcweir 
88cdf0e10cSrcweir 		//External keys
89cdf0e10cSrcweir 		std::list< HCRYPTKEY >				m_tSymKeyList ;
90cdf0e10cSrcweir 		std::list< HCRYPTKEY >				m_tPubKeyList ;
91cdf0e10cSrcweir 		std::list< HCRYPTKEY >				m_tPriKeyList ;
92cdf0e10cSrcweir 
93cdf0e10cSrcweir 		//Service manager
94cdf0e10cSrcweir 		::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > m_xServiceManager ;
95cdf0e10cSrcweir 
96cdf0e10cSrcweir 	public :
97cdf0e10cSrcweir 		SecurityEnvironment_MSCryptImpl( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& aFactory ) ;
98cdf0e10cSrcweir 		virtual ~SecurityEnvironment_MSCryptImpl() ;
99cdf0e10cSrcweir 
100cdf0e10cSrcweir 		//Methods from XSecurityEnvironment
101cdf0e10cSrcweir 		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 ) ;
102cdf0e10cSrcweir 
103cdf0e10cSrcweir 		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 ) ;
104cdf0e10cSrcweir 
105cdf0e10cSrcweir 		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 ) ;
106cdf0e10cSrcweir 
107cdf0e10cSrcweir 		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 ) ;
108cdf0e10cSrcweir 
109cdf0e10cSrcweir 		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 ) ;
110cdf0e10cSrcweir 
111cdf0e10cSrcweir 		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 ) ;
112cdf0e10cSrcweir 
113cdf0e10cSrcweir 		virtual ::sal_Int32 SAL_CALL verifyCertificate(
114cdf0e10cSrcweir             const ::com::sun::star::uno::Reference< ::com::sun::star::security::XCertificate >& xCert,
115cdf0e10cSrcweir             const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference<
116cdf0e10cSrcweir             ::com::sun::star::security::XCertificate > >& intermediateCertificates)
117cdf0e10cSrcweir             throw (::com::sun::star::uno::SecurityException, ::com::sun::star::uno::RuntimeException) ;
118cdf0e10cSrcweir 	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) ;
119cdf0e10cSrcweir 
120cdf0e10cSrcweir 		virtual ::rtl::OUString SAL_CALL getSecurityEnvironmentInformation(  ) throw (::com::sun::star::uno::RuntimeException);
121cdf0e10cSrcweir 
122cdf0e10cSrcweir 
123cdf0e10cSrcweir 		//Methods from XInitialization
124cdf0e10cSrcweir 		virtual void SAL_CALL initialize(
125cdf0e10cSrcweir 			const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments
126cdf0e10cSrcweir 		) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;
127cdf0e10cSrcweir 
128cdf0e10cSrcweir 		//Methods from XServiceInfo
129cdf0e10cSrcweir 		virtual ::rtl::OUString SAL_CALL getImplementationName() throw( ::com::sun::star::uno::RuntimeException ) ;
130cdf0e10cSrcweir 
131cdf0e10cSrcweir 		virtual sal_Bool SAL_CALL supportsService(
132cdf0e10cSrcweir 			const ::rtl::OUString& ServiceName
133cdf0e10cSrcweir 		) throw( ::com::sun::star::uno::RuntimeException ) ;
134cdf0e10cSrcweir 
135cdf0e10cSrcweir 		virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames() throw( ::com::sun::star::uno::RuntimeException ) ;
136cdf0e10cSrcweir 
137cdf0e10cSrcweir 		//Helper for XServiceInfo
138cdf0e10cSrcweir 		static ::com::sun::star::uno::Sequence< ::rtl::OUString > impl_getSupportedServiceNames() ;
139cdf0e10cSrcweir 
140cdf0e10cSrcweir 		static ::rtl::OUString impl_getImplementationName() throw( ::com::sun::star::uno::RuntimeException ) ;
141cdf0e10cSrcweir 
142cdf0e10cSrcweir 		//Helper for registry
143cdf0e10cSrcweir 		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 ) ;
144cdf0e10cSrcweir 
145cdf0e10cSrcweir 		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 ) ;
146cdf0e10cSrcweir 
147cdf0e10cSrcweir 		//Methods from XUnoTunnel
148cdf0e10cSrcweir 		virtual sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& aIdentifier )
149cdf0e10cSrcweir 			throw (::com::sun::star::uno::RuntimeException);
150cdf0e10cSrcweir 
151cdf0e10cSrcweir 		static const ::com::sun::star::uno::Sequence< sal_Int8 >& getUnoTunnelId() ;
152cdf0e10cSrcweir 		static SecurityEnvironment_MSCryptImpl* getImplementation( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > xObj ) ;
153cdf0e10cSrcweir 
154cdf0e10cSrcweir 		//Native mehtods
155cdf0e10cSrcweir 		virtual HCRYPTPROV getCryptoProvider() throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;
156cdf0e10cSrcweir 
157cdf0e10cSrcweir 		virtual void setCryptoProvider( HCRYPTPROV aProv ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;
158cdf0e10cSrcweir 
159cdf0e10cSrcweir 		virtual LPCTSTR getKeyContainer() throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;
160cdf0e10cSrcweir 
161cdf0e10cSrcweir 		virtual void setKeyContainer( LPCTSTR aKeyContainer ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;
162cdf0e10cSrcweir 
163cdf0e10cSrcweir 		virtual HCERTSTORE getCryptoSlot() throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;
164cdf0e10cSrcweir 
165cdf0e10cSrcweir 		virtual void setCryptoSlot( HCERTSTORE aKeyStore ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;
166cdf0e10cSrcweir 
167cdf0e10cSrcweir 		virtual HCERTSTORE getCertDb() throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;
168cdf0e10cSrcweir 
169cdf0e10cSrcweir 		virtual void setCertDb( HCERTSTORE aCertDb ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;
170cdf0e10cSrcweir 
171cdf0e10cSrcweir 		virtual void adoptSymKey( HCRYPTKEY aSymKey ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;
172cdf0e10cSrcweir 
173cdf0e10cSrcweir 		virtual void rejectSymKey( HCRYPTKEY aSymKey ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;
174cdf0e10cSrcweir 
175cdf0e10cSrcweir 		virtual HCRYPTKEY getSymKey( unsigned int position ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;
176cdf0e10cSrcweir 
177cdf0e10cSrcweir 		virtual void adoptPubKey( HCRYPTKEY aPubKey ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;
178cdf0e10cSrcweir 
179cdf0e10cSrcweir 		virtual void rejectPubKey( HCRYPTKEY aPubKey ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;
180cdf0e10cSrcweir 
181cdf0e10cSrcweir 		virtual HCRYPTKEY getPubKey( unsigned int position ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;
182cdf0e10cSrcweir 
183cdf0e10cSrcweir 		virtual void adoptPriKey( HCRYPTKEY aPriKey ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;
184cdf0e10cSrcweir 
185cdf0e10cSrcweir 		virtual void rejectPriKey( HCRYPTKEY aPriKey ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;
186cdf0e10cSrcweir 
187cdf0e10cSrcweir 		virtual HCRYPTKEY getPriKey( unsigned int position ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;
188cdf0e10cSrcweir 
189cdf0e10cSrcweir 		virtual void enableDefaultCrypt( sal_Bool enable ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;
190cdf0e10cSrcweir 
191cdf0e10cSrcweir 		virtual sal_Bool defaultEnabled() throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;
192cdf0e10cSrcweir 
193cdf0e10cSrcweir 		//Native mehtods
194cdf0e10cSrcweir 		virtual xmlSecKeysMngrPtr createKeysManager() throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;
195cdf0e10cSrcweir 
196cdf0e10cSrcweir 		virtual void destroyKeysManager(xmlSecKeysMngrPtr pKeysMngr) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;
197cdf0e10cSrcweir } ;
198cdf0e10cSrcweir 
199cdf0e10cSrcweir #endif	// _XSECURITYENVIRONMENT_MSCRYPTIMPL_HXX_
200cdf0e10cSrcweir 
201