1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 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. 14 * 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). 20 * 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. 25 * 26 ************************************************************************/ 27 28 #ifndef _XSECURITYENVIRONMENT_MSCRYPTIMPL_HXX_ 29 #define _XSECURITYENVIRONMENT_MSCRYPTIMPL_HXX_ 30 31 #ifdef _MSC_VER 32 #pragma warning(push,1) 33 #endif 34 #include <windows.h> 35 #include <wincrypt.h> 36 #ifdef _MSC_VER 37 #pragma warning(pop) 38 #endif 39 #include <sal/config.h> 40 #include <rtl/ustring.hxx> 41 #include <cppuhelper/factory.hxx> 42 #include <cppuhelper/implbase4.hxx> 43 #include <com/sun/star/uno/Exception.hpp> 44 45 #ifndef _COM_SUN_STAR_UNO_REFERENCE_HPP_ 46 #include <com/sun/star/uno/Reference.hxx> 47 #endif 48 #include <com/sun/star/lang/XSingleServiceFactory.hpp> 49 50 #ifndef _COM_SUN_STAR_LANG_XSECVICEINFO_HPP_ 51 #include <com/sun/star/lang/XServiceInfo.hpp> 52 #endif 53 #include <com/sun/star/lang/XInitialization.hpp> 54 #include <com/sun/star/xml/crypto/XSecurityEnvironment.hpp> 55 #include <com/sun/star/security/XCertificate.hpp> 56 #include <com/sun/star/security/CertificateCharacters.hpp> 57 #include <com/sun/star/security/CertificateValidity.hpp> 58 #include <com/sun/star/lang/XUnoTunnel.hpp> 59 60 #include <list> 61 #include "xmlsec/xmlsec.h" 62 63 #include "sal/types.h" 64 65 66 class SecurityEnvironment_MSCryptImpl : 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 > 71 { 72 private : 73 //cyrpto provider and key container 74 HCRYPTPROV m_hProv ; 75 LPCTSTR m_pszContainer ; 76 77 //Key store 78 HCERTSTORE m_hKeyStore ; 79 80 //Certiticate store 81 HCERTSTORE m_hCertStore ; 82 83 //Enable default system cryptography setting 84 sal_Bool m_bEnableDefault ; 85 86 //External keys 87 std::list< HCRYPTKEY > m_tSymKeyList ; 88 std::list< HCRYPTKEY > m_tPubKeyList ; 89 std::list< HCRYPTKEY > m_tPriKeyList ; 90 91 //Service manager 92 ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > m_xServiceManager ; 93 94 public : 95 SecurityEnvironment_MSCryptImpl( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& aFactory ) ; 96 virtual ~SecurityEnvironment_MSCryptImpl() ; 97 98 //Methods from XSecurityEnvironment 99 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 ) ; 100 101 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 ) ; 102 103 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 ) ; 104 105 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 ) ; 106 107 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 ) ; 108 109 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 ) ; 110 111 virtual ::sal_Int32 SAL_CALL verifyCertificate( 112 const ::com::sun::star::uno::Reference< ::com::sun::star::security::XCertificate >& xCert, 113 const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< 114 ::com::sun::star::security::XCertificate > >& intermediateCertificates) 115 throw (::com::sun::star::uno::SecurityException, ::com::sun::star::uno::RuntimeException) ; 116 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) ; 117 118 virtual ::rtl::OUString SAL_CALL getSecurityEnvironmentInformation( ) throw (::com::sun::star::uno::RuntimeException); 119 120 121 //Methods from XInitialization 122 virtual void SAL_CALL initialize( 123 const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments 124 ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ; 125 126 //Methods from XServiceInfo 127 virtual ::rtl::OUString SAL_CALL getImplementationName() throw( ::com::sun::star::uno::RuntimeException ) ; 128 129 virtual sal_Bool SAL_CALL supportsService( 130 const ::rtl::OUString& ServiceName 131 ) throw( ::com::sun::star::uno::RuntimeException ) ; 132 133 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames() throw( ::com::sun::star::uno::RuntimeException ) ; 134 135 //Helper for XServiceInfo 136 static ::com::sun::star::uno::Sequence< ::rtl::OUString > impl_getSupportedServiceNames() ; 137 138 static ::rtl::OUString impl_getImplementationName() throw( ::com::sun::star::uno::RuntimeException ) ; 139 140 //Helper for registry 141 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 ) ; 142 143 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 ) ; 144 145 //Methods from XUnoTunnel 146 virtual sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& aIdentifier ) 147 throw (::com::sun::star::uno::RuntimeException); 148 149 static const ::com::sun::star::uno::Sequence< sal_Int8 >& getUnoTunnelId() ; 150 static SecurityEnvironment_MSCryptImpl* getImplementation( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > xObj ) ; 151 152 //Native mehtods 153 virtual HCRYPTPROV getCryptoProvider() throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ; 154 155 virtual void setCryptoProvider( HCRYPTPROV aProv ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ; 156 157 virtual LPCTSTR getKeyContainer() throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ; 158 159 virtual void setKeyContainer( LPCTSTR aKeyContainer ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ; 160 161 virtual HCERTSTORE getCryptoSlot() throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ; 162 163 virtual void setCryptoSlot( HCERTSTORE aKeyStore ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ; 164 165 virtual HCERTSTORE getCertDb() throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ; 166 167 virtual void setCertDb( HCERTSTORE aCertDb ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ; 168 169 virtual void adoptSymKey( HCRYPTKEY aSymKey ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ; 170 171 virtual void rejectSymKey( HCRYPTKEY aSymKey ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ; 172 173 virtual HCRYPTKEY getSymKey( unsigned int position ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ; 174 175 virtual void adoptPubKey( HCRYPTKEY aPubKey ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ; 176 177 virtual void rejectPubKey( HCRYPTKEY aPubKey ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ; 178 179 virtual HCRYPTKEY getPubKey( unsigned int position ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ; 180 181 virtual void adoptPriKey( HCRYPTKEY aPriKey ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ; 182 183 virtual void rejectPriKey( HCRYPTKEY aPriKey ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ; 184 185 virtual HCRYPTKEY getPriKey( unsigned int position ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ; 186 187 virtual void enableDefaultCrypt( sal_Bool enable ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ; 188 189 virtual sal_Bool defaultEnabled() throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ; 190 191 //Native mehtods 192 virtual xmlSecKeysMngrPtr createKeysManager() throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ; 193 194 virtual void destroyKeysManager(xmlSecKeysMngrPtr pKeysMngr) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ; 195 } ; 196 197 #endif // _XSECURITYENVIRONMENT_MSCRYPTIMPL_HXX_ 198 199