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