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 //Certificate 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() ; 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 ) ; 104 105 virtual ::com::sun::star::uno::Reference< ::com::sun::star::security::XCertificate > SAL_CALL getCertificate( const ::rtl::OUString& issuerName, const ::rtl::OUString& serialNumber ) ; 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 ) ; 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 ) ; 110 111 virtual ::com::sun::star::uno::Reference< ::com::sun::star::security::XCertificate > SAL_CALL createCertificateFromAscii( const ::rtl::OUString& asciiCertificate ) ; 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 virtual ::sal_Int32 SAL_CALL getCertificateCharacters( const ::com::sun::star::uno::Reference< ::com::sun::star::security::XCertificate >& xCert ) ; 118 119 virtual ::rtl::OUString SAL_CALL getSecurityEnvironmentInformation( ); 120 121 122 //Methods from XInitialization 123 virtual void SAL_CALL initialize( 124 const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments 125 ) ; 126 127 //Methods from XServiceInfo 128 virtual ::rtl::OUString SAL_CALL getImplementationName() ; 129 130 virtual sal_Bool SAL_CALL supportsService( 131 const ::rtl::OUString& ServiceName 132 ) ; 133 134 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames() ; 135 136 //Helper for XServiceInfo 137 static ::com::sun::star::uno::Sequence< ::rtl::OUString > impl_getSupportedServiceNames() ; 138 139 static ::rtl::OUString impl_getImplementationName() ; 140 141 //Helper for registry 142 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 ) ; 143 144 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 ) ; 145 146 //Methods from XUnoTunnel 147 virtual sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& aIdentifier ); 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 methods 153 virtual HCRYPTPROV getCryptoProvider() ; 154 155 virtual void setCryptoProvider( HCRYPTPROV aProv ) ; 156 157 virtual LPCTSTR getKeyContainer() ; 158 159 virtual void setKeyContainer( LPCTSTR aKeyContainer ) ; 160 161 virtual HCERTSTORE getCryptoSlot() ; 162 163 virtual void setCryptoSlot( HCERTSTORE aKeyStore ) ; 164 165 virtual HCERTSTORE getCertDb() ; 166 167 virtual void setCertDb( HCERTSTORE aCertDb ) ; 168 169 virtual void adoptSymKey( HCRYPTKEY aSymKey ) ; 170 171 virtual void rejectSymKey( HCRYPTKEY aSymKey ) ; 172 173 virtual HCRYPTKEY getSymKey( unsigned int position ) ; 174 175 virtual void adoptPubKey( HCRYPTKEY aPubKey ) ; 176 177 virtual void rejectPubKey( HCRYPTKEY aPubKey ) ; 178 179 virtual HCRYPTKEY getPubKey( unsigned int position ) ; 180 181 virtual void adoptPriKey( HCRYPTKEY aPriKey ) ; 182 183 virtual void rejectPriKey( HCRYPTKEY aPriKey ) ; 184 185 virtual HCRYPTKEY getPriKey( unsigned int position ) ; 186 187 virtual void enableDefaultCrypt( sal_Bool enable ) ; 188 189 virtual sal_Bool defaultEnabled() ; 190 191 //Native methods 192 virtual xmlSecKeysMngrPtr createKeysManager() ; 193 194 virtual void destroyKeysManager(xmlSecKeysMngrPtr pKeysMngr) ; 195 } ; 196 197 #endif // _XSECURITYENVIRONMENT_MSCRYPTIMPL_HXX_ 198