| 1 |
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
| 2 |
/* |
| 3 |
* This file is part of the LibreOffice project. |
| 4 |
* |
| 5 |
* This Source Code Form is subject to the terms of the Mozilla Public |
| 6 |
* License, v. 2.0. If a copy of the MPL was not distributed with this |
| 7 |
* file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 8 |
* |
| 9 |
* This file incorporates work covered by the following license notice: |
| 10 |
* |
| 11 |
* Licensed to the Apache Software Foundation (ASF) under one or more |
| 12 |
* contributor license agreements. See the NOTICE file distributed |
| 13 |
* with this work for additional information regarding copyright |
| 14 |
* ownership. The ASF licenses this file to you under the Apache |
| 15 |
* License, Version 2.0 (the "License"); you may not use this file |
| 16 |
* except in compliance with the License. You may obtain a copy of |
| 17 |
* the License at http://www.apache.org/licenses/LICENSE-2.0 . |
| 18 |
*/ |
| 19 |
|
| 20 |
#pragma once |
| 21 |
|
| 22 |
#if !defined WIN32_LEAN_AND_MEAN |
| 23 |
# define WIN32_LEAN_AND_MEAN |
| 24 |
#endif |
| 25 |
#include <windows.h> |
| 26 |
#include <wincrypt.h> |
| 27 |
#include <sal/config.h> |
| 28 |
|
| 29 |
#include <xmlsec/keysmngr.h> |
| 30 |
|
| 31 |
#include <rtl/ustring.hxx> |
| 32 |
#include <comphelper/servicehelper.hxx> |
| 33 |
#include <cppuhelper/factory.hxx> |
| 34 |
#include <cppuhelper/implbase.hxx> |
| 35 |
#include <com/sun/star/uno/Exception.hpp> |
| 36 |
|
| 37 |
#include <com/sun/star/uno/Reference.hxx> |
| 38 |
#include <com/sun/star/lang/XSingleServiceFactory.hpp> |
| 39 |
|
| 40 |
#include <com/sun/star/lang/XServiceInfo.hpp> |
| 41 |
#include <com/sun/star/xml/crypto/XSecurityEnvironment.hpp> |
| 42 |
#include <com/sun/star/security/XCertificate.hpp> |
| 43 |
#include <com/sun/star/security/CertificateCharacters.hpp> |
| 44 |
#include <com/sun/star/security/CertificateValidity.hpp> |
| 45 |
|
| 46 |
#include <vector> |
| 47 |
|
| 48 |
#include <sal/types.h> |
| 49 |
|
| 50 |
|
| 51 |
class SecurityEnvironment_MSCryptImpl : public ::cppu::WeakImplHelper< |
| 52 |
css::xml::crypto::XSecurityEnvironment , |
| 53 |
css::lang::XServiceInfo > |
| 54 |
{ |
| 55 |
private: |
| 56 |
//crypto provider and key container |
| 57 |
HCRYPTPROV m_hProv ; |
| 58 |
LPCTSTR m_pszContainer ; |
| 59 |
|
| 60 |
//Key store |
| 61 |
HCERTSTORE m_hKeyStore ; |
| 62 |
|
| 63 |
//Certificate store |
| 64 |
HCERTSTORE m_hCertStore ; |
| 65 |
|
| 66 |
// i120675, save the store handles |
| 67 |
HCERTSTORE m_hMySystemStore; |
| 68 |
HCERTSTORE m_hRootSystemStore; |
| 69 |
HCERTSTORE m_hTrustSystemStore; |
| 70 |
HCERTSTORE m_hCaSystemStore; |
| 71 |
|
| 72 |
//Enable default system cryptography setting |
| 73 |
bool m_bEnableDefault ; |
| 74 |
|
| 75 |
//Service manager |
| 76 |
css::uno::Reference< css::lang::XMultiServiceFactory > m_xServiceManager ; |
| 77 |
|
| 78 |
public: |
| 79 |
explicit SecurityEnvironment_MSCryptImpl( const css::uno::Reference< css::uno::XComponentContext >& xContext ) ; |
| 80 |
virtual ~SecurityEnvironment_MSCryptImpl() override; |
| 81 |
|
| 82 |
//Methods from XSecurityEnvironment |
| 83 |
virtual css::uno::Sequence< css::uno::Reference< css::security::XCertificate > > SAL_CALL getPersonalCertificates() override; |
| 84 |
virtual css::uno::Sequence< css::uno::Reference< css::security::XCertificate > > SAL_CALL getAllCertificates() override |
| 85 |
{ return css::uno::Sequence< css::uno::Reference< css::security::XCertificate > >(); } |
| 86 |
|
| 87 |
virtual css::uno::Reference< css::security::XCertificate > SAL_CALL getCertificate( |
| 88 |
const OUString& issuerName, |
| 89 |
const css::uno::Sequence< sal_Int8 >& serialNumber ) override; |
| 90 |
|
| 91 |
/// @throws css::uno::SecurityException |
| 92 |
/// @throws css::uno::RuntimeException |
| 93 |
virtual css::uno::Reference< css::security::XCertificate > getCertificate( |
| 94 |
const OUString& issuerName, |
| 95 |
const OUString& serialNumber ) ; |
| 96 |
|
| 97 |
virtual css::uno::Sequence< css::uno::Reference< css::security::XCertificate > > SAL_CALL buildCertificatePath( |
| 98 |
const css::uno::Reference< css::security::XCertificate >& beginCert ) override; |
| 99 |
|
| 100 |
virtual css::uno::Reference< css::security::XCertificate > SAL_CALL createCertificateFromRaw( |
| 101 |
const css::uno::Sequence< sal_Int8 >& rawCertificate ) override; |
| 102 |
|
| 103 |
virtual css::uno::Reference< css::security::XCertificate > SAL_CALL createCertificateFromAscii( |
| 104 |
const OUString& asciiCertificate ) override; |
| 105 |
|
| 106 |
virtual ::sal_Int32 SAL_CALL verifyCertificate( |
| 107 |
const css::uno::Reference< css::security::XCertificate >& xCert, |
| 108 |
const css::uno::Sequence< css::uno::Reference< |
| 109 |
css::security::XCertificate > >& intermediateCertificates) override; |
| 110 |
|
| 111 |
virtual ::sal_Int32 SAL_CALL getCertificateCharacters( |
| 112 |
const css::uno::Reference< css::security::XCertificate >& xCert ) override; |
| 113 |
|
| 114 |
virtual OUString SAL_CALL getSecurityEnvironmentInformation( ) override; |
| 115 |
|
| 116 |
|
| 117 |
//Methods from XServiceInfo |
| 118 |
virtual OUString SAL_CALL getImplementationName() override; |
| 119 |
|
| 120 |
virtual sal_Bool SAL_CALL supportsService( |
| 121 |
const OUString& ServiceName |
| 122 |
) override; |
| 123 |
|
| 124 |
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override; |
| 125 |
|
| 126 |
/// @throws css::uno::Exception |
| 127 |
/// @throws css::uno::RuntimeException |
| 128 |
HCRYPTPROV getCryptoProvider() ; |
| 129 |
/// @throws css::uno::Exception |
| 130 |
/// @throws css::uno::RuntimeException |
| 131 |
void setCryptoProvider( HCRYPTPROV aProv ) ; |
| 132 |
|
| 133 |
/// @throws css::uno::Exception |
| 134 |
/// @throws css::uno::RuntimeException |
| 135 |
LPCTSTR getKeyContainer() ; |
| 136 |
/// @throws css::uno::Exception |
| 137 |
/// @throws css::uno::RuntimeException |
| 138 |
void setKeyContainer( LPCTSTR aKeyContainer ) ; |
| 139 |
|
| 140 |
/// @throws css::uno::Exception |
| 141 |
/// @throws css::uno::RuntimeException |
| 142 |
HCERTSTORE getCryptoSlot() ; |
| 143 |
/// @throws css::uno::Exception |
| 144 |
/// @throws css::uno::RuntimeException |
| 145 |
void setCryptoSlot( HCERTSTORE aKeyStore ) ; |
| 146 |
|
| 147 |
/// @throws css::uno::Exception |
| 148 |
/// @throws css::uno::RuntimeException |
| 149 |
HCERTSTORE getCertDb() ; |
| 150 |
/// @throws css::uno::Exception |
| 151 |
/// @throws css::uno::RuntimeException |
| 152 |
void setCertDb( HCERTSTORE aCertDb ) ; |
| 153 |
|
| 154 |
/// @throws css::uno::Exception |
| 155 |
/// @throws css::uno::RuntimeException |
| 156 |
void enableDefaultCrypt( bool enable ) ; |
| 157 |
/// @throws css::uno::Exception |
| 158 |
/// @throws css::uno::RuntimeException |
| 159 |
bool defaultEnabled() ; |
| 160 |
|
| 161 |
/// @throws css::uno::Exception |
| 162 |
/// @throws css::uno::RuntimeException |
| 163 |
xmlSecKeysMngrPtr createKeysManager() ; |
| 164 |
|
| 165 |
/// @throws css::uno::Exception |
| 166 |
/// @throws css::uno::RuntimeException |
| 167 |
static void destroyKeysManager(xmlSecKeysMngrPtr pKeysMngr) ; |
| 168 |
} ; |
| 169 |
|
| 170 |
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |