xref: /AOO41X/main/xmlsecurity/source/xmlsec/mscrypt/securityenvironment_mscryptimpl.hxx (revision ec61c6ed669d81c7df08233ccc38d0040f129ece)
1*ec61c6edSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*ec61c6edSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*ec61c6edSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*ec61c6edSAndrew Rist  * distributed with this work for additional information
6*ec61c6edSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*ec61c6edSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*ec61c6edSAndrew Rist  * "License"); you may not use this file except in compliance
9*ec61c6edSAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*ec61c6edSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*ec61c6edSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*ec61c6edSAndrew Rist  * software distributed under the License is distributed on an
15*ec61c6edSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*ec61c6edSAndrew Rist  * KIND, either express or implied.  See the License for the
17*ec61c6edSAndrew Rist  * specific language governing permissions and limitations
18*ec61c6edSAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*ec61c6edSAndrew Rist  *************************************************************/
21*ec61c6edSAndrew Rist 
22*ec61c6edSAndrew 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 
79cdf0e10cSrcweir 		//Enable default system cryptography setting
80cdf0e10cSrcweir 		sal_Bool							m_bEnableDefault ;
81cdf0e10cSrcweir 
82cdf0e10cSrcweir 		//External keys
83cdf0e10cSrcweir 		std::list< HCRYPTKEY >				m_tSymKeyList ;
84cdf0e10cSrcweir 		std::list< HCRYPTKEY >				m_tPubKeyList ;
85cdf0e10cSrcweir 		std::list< HCRYPTKEY >				m_tPriKeyList ;
86cdf0e10cSrcweir 
87cdf0e10cSrcweir 		//Service manager
88cdf0e10cSrcweir 		::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > m_xServiceManager ;
89cdf0e10cSrcweir 
90cdf0e10cSrcweir 	public :
91cdf0e10cSrcweir 		SecurityEnvironment_MSCryptImpl( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& aFactory ) ;
92cdf0e10cSrcweir 		virtual ~SecurityEnvironment_MSCryptImpl() ;
93cdf0e10cSrcweir 
94cdf0e10cSrcweir 		//Methods from XSecurityEnvironment
95cdf0e10cSrcweir 		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 ) ;
96cdf0e10cSrcweir 
97cdf0e10cSrcweir 		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 ) ;
98cdf0e10cSrcweir 
99cdf0e10cSrcweir 		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 ) ;
100cdf0e10cSrcweir 
101cdf0e10cSrcweir 		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 ) ;
102cdf0e10cSrcweir 
103cdf0e10cSrcweir 		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 ) ;
104cdf0e10cSrcweir 
105cdf0e10cSrcweir 		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 ) ;
106cdf0e10cSrcweir 
107cdf0e10cSrcweir 		virtual ::sal_Int32 SAL_CALL verifyCertificate(
108cdf0e10cSrcweir             const ::com::sun::star::uno::Reference< ::com::sun::star::security::XCertificate >& xCert,
109cdf0e10cSrcweir             const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference<
110cdf0e10cSrcweir             ::com::sun::star::security::XCertificate > >& intermediateCertificates)
111cdf0e10cSrcweir             throw (::com::sun::star::uno::SecurityException, ::com::sun::star::uno::RuntimeException) ;
112cdf0e10cSrcweir 	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) ;
113cdf0e10cSrcweir 
114cdf0e10cSrcweir 		virtual ::rtl::OUString SAL_CALL getSecurityEnvironmentInformation(  ) throw (::com::sun::star::uno::RuntimeException);
115cdf0e10cSrcweir 
116cdf0e10cSrcweir 
117cdf0e10cSrcweir 		//Methods from XInitialization
118cdf0e10cSrcweir 		virtual void SAL_CALL initialize(
119cdf0e10cSrcweir 			const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments
120cdf0e10cSrcweir 		) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;
121cdf0e10cSrcweir 
122cdf0e10cSrcweir 		//Methods from XServiceInfo
123cdf0e10cSrcweir 		virtual ::rtl::OUString SAL_CALL getImplementationName() throw( ::com::sun::star::uno::RuntimeException ) ;
124cdf0e10cSrcweir 
125cdf0e10cSrcweir 		virtual sal_Bool SAL_CALL supportsService(
126cdf0e10cSrcweir 			const ::rtl::OUString& ServiceName
127cdf0e10cSrcweir 		) throw( ::com::sun::star::uno::RuntimeException ) ;
128cdf0e10cSrcweir 
129cdf0e10cSrcweir 		virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames() throw( ::com::sun::star::uno::RuntimeException ) ;
130cdf0e10cSrcweir 
131cdf0e10cSrcweir 		//Helper for XServiceInfo
132cdf0e10cSrcweir 		static ::com::sun::star::uno::Sequence< ::rtl::OUString > impl_getSupportedServiceNames() ;
133cdf0e10cSrcweir 
134cdf0e10cSrcweir 		static ::rtl::OUString impl_getImplementationName() throw( ::com::sun::star::uno::RuntimeException ) ;
135cdf0e10cSrcweir 
136cdf0e10cSrcweir 		//Helper for registry
137cdf0e10cSrcweir 		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 ) ;
138cdf0e10cSrcweir 
139cdf0e10cSrcweir 		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 ) ;
140cdf0e10cSrcweir 
141cdf0e10cSrcweir 		//Methods from XUnoTunnel
142cdf0e10cSrcweir 		virtual sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& aIdentifier )
143cdf0e10cSrcweir 			throw (::com::sun::star::uno::RuntimeException);
144cdf0e10cSrcweir 
145cdf0e10cSrcweir 		static const ::com::sun::star::uno::Sequence< sal_Int8 >& getUnoTunnelId() ;
146cdf0e10cSrcweir 		static SecurityEnvironment_MSCryptImpl* getImplementation( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > xObj ) ;
147cdf0e10cSrcweir 
148cdf0e10cSrcweir 		//Native mehtods
149cdf0e10cSrcweir 		virtual HCRYPTPROV getCryptoProvider() throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;
150cdf0e10cSrcweir 
151cdf0e10cSrcweir 		virtual void setCryptoProvider( HCRYPTPROV aProv ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;
152cdf0e10cSrcweir 
153cdf0e10cSrcweir 		virtual LPCTSTR getKeyContainer() throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;
154cdf0e10cSrcweir 
155cdf0e10cSrcweir 		virtual void setKeyContainer( LPCTSTR aKeyContainer ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;
156cdf0e10cSrcweir 
157cdf0e10cSrcweir 		virtual HCERTSTORE getCryptoSlot() throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;
158cdf0e10cSrcweir 
159cdf0e10cSrcweir 		virtual void setCryptoSlot( HCERTSTORE aKeyStore ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;
160cdf0e10cSrcweir 
161cdf0e10cSrcweir 		virtual HCERTSTORE getCertDb() throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;
162cdf0e10cSrcweir 
163cdf0e10cSrcweir 		virtual void setCertDb( HCERTSTORE aCertDb ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;
164cdf0e10cSrcweir 
165cdf0e10cSrcweir 		virtual void adoptSymKey( HCRYPTKEY aSymKey ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;
166cdf0e10cSrcweir 
167cdf0e10cSrcweir 		virtual void rejectSymKey( HCRYPTKEY aSymKey ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;
168cdf0e10cSrcweir 
169cdf0e10cSrcweir 		virtual HCRYPTKEY getSymKey( unsigned int position ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;
170cdf0e10cSrcweir 
171cdf0e10cSrcweir 		virtual void adoptPubKey( HCRYPTKEY aPubKey ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;
172cdf0e10cSrcweir 
173cdf0e10cSrcweir 		virtual void rejectPubKey( HCRYPTKEY aPubKey ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;
174cdf0e10cSrcweir 
175cdf0e10cSrcweir 		virtual HCRYPTKEY getPubKey( unsigned int position ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;
176cdf0e10cSrcweir 
177cdf0e10cSrcweir 		virtual void adoptPriKey( HCRYPTKEY aPriKey ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;
178cdf0e10cSrcweir 
179cdf0e10cSrcweir 		virtual void rejectPriKey( HCRYPTKEY aPriKey ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;
180cdf0e10cSrcweir 
181cdf0e10cSrcweir 		virtual HCRYPTKEY getPriKey( unsigned int position ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;
182cdf0e10cSrcweir 
183cdf0e10cSrcweir 		virtual void enableDefaultCrypt( sal_Bool enable ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;
184cdf0e10cSrcweir 
185cdf0e10cSrcweir 		virtual sal_Bool defaultEnabled() throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;
186cdf0e10cSrcweir 
187cdf0e10cSrcweir 		//Native mehtods
188cdf0e10cSrcweir 		virtual xmlSecKeysMngrPtr createKeysManager() throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;
189cdf0e10cSrcweir 
190cdf0e10cSrcweir 		virtual void destroyKeysManager(xmlSecKeysMngrPtr pKeysMngr) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;
191cdf0e10cSrcweir } ;
192cdf0e10cSrcweir 
193cdf0e10cSrcweir #endif	// _XSECURITYENVIRONMENT_MSCRYPTIMPL_HXX_
194cdf0e10cSrcweir 
195