| 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 |
#include <sal/config.h> |
| 23 |
#include <rtl/ustring.hxx> |
| 24 |
#include <rtl/ref.hxx> |
| 25 |
#include <cppuhelper/implbase.hxx> |
| 26 |
|
| 27 |
#include <com/sun/star/uno/Reference.hxx> |
| 28 |
|
| 29 |
#include <com/sun/star/lang/XServiceInfo.hpp> |
| 30 |
#include <com/sun/star/xml/crypto/XSecurityEnvironment.hpp> |
| 31 |
#include <com/sun/star/xml/crypto/XCertificateCreator.hpp> |
| 32 |
|
| 33 |
#include <mutex> |
| 34 |
|
| 35 |
#include <keythi.h> |
| 36 |
#include <certt.h> |
| 37 |
|
| 38 |
#include <string_view> |
| 39 |
#include <vector> |
| 40 |
|
| 41 |
#include <xmlsec/xmlsec.h> |
| 42 |
|
| 43 |
class X509Certificate_NssImpl; |
| 44 |
|
| 45 |
class SecurityEnvironment_NssImpl : public ::cppu::WeakImplHelper< |
| 46 |
css::xml::crypto::XSecurityEnvironment, |
| 47 |
css::xml::crypto::XCertificateCreator, |
| 48 |
css::lang::XServiceInfo > |
| 49 |
{ |
| 50 |
private: |
| 51 |
|
| 52 |
std::vector< PK11SlotInfo* > m_Slots; |
| 53 |
/// The last used certificate which has the private key for signing. |
| 54 |
rtl::Reference<X509Certificate_NssImpl> m_xSigningCertificate; |
| 55 |
|
| 56 |
std::mutex m_mutex; |
| 57 |
|
| 58 |
CERTCertDBHandle* m_pHandler ; |
| 59 |
std::vector< PK11SymKey* > m_tSymKeyList ; |
| 60 |
|
| 61 |
public: |
| 62 |
SecurityEnvironment_NssImpl(); |
| 63 |
virtual ~SecurityEnvironment_NssImpl() override; |
| 64 |
|
| 65 |
//Methods from XSecurityEnvironment |
| 66 |
|
| 67 |
//Methods from XServiceInfo |
| 68 |
virtual OUString SAL_CALL getImplementationName() override ; |
| 69 |
|
| 70 |
virtual sal_Bool SAL_CALL supportsService( |
| 71 |
const OUString& ServiceName |
| 72 |
) override ; |
| 73 |
|
| 74 |
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override ; |
| 75 |
|
| 76 |
virtual ::sal_Int32 SAL_CALL verifyCertificate( |
| 77 |
const css::uno::Reference< |
| 78 |
css::security::XCertificate >& xCert, |
| 79 |
const css::uno::Sequence< |
| 80 |
css::uno::Reference< css::security::XCertificate > > & |
| 81 |
intermediateCerts) override ; |
| 82 |
|
| 83 |
virtual ::sal_Int32 SAL_CALL getCertificateCharacters( const css::uno::Reference< css::security::XCertificate >& xCert ) override ; |
| 84 |
|
| 85 |
virtual OUString SAL_CALL getSecurityEnvironmentInformation( ) override; |
| 86 |
|
| 87 |
/// @throws css::uno::Exception |
| 88 |
/// @throws css::uno::RuntimeException |
| 89 |
void setCertDb( CERTCertDBHandle* aCertDb ) ; |
| 90 |
|
| 91 |
/// @throws css::uno::Exception |
| 92 |
/// @throws css::uno::RuntimeException |
| 93 |
void adoptSymKey( PK11SymKey* aSymKey ) ; |
| 94 |
|
| 95 |
virtual css::uno::Sequence< css::uno::Reference< css::security::XCertificate > > SAL_CALL getPersonalCertificates() override ; |
| 96 |
virtual css::uno::Sequence< css::uno::Reference< css::security::XCertificate > > SAL_CALL getAllCertificates() override |
| 97 |
{ return css::uno::Sequence< css::uno::Reference< css::security::XCertificate > >(); } |
| 98 |
|
| 99 |
virtual css::uno::Reference< css::security::XCertificate > SAL_CALL getCertificate( const OUString& issuerName, const css::uno::Sequence< sal_Int8 >& serialNumber ) override ; |
| 100 |
|
| 101 |
virtual css::uno::Sequence< css::uno::Reference< css::security::XCertificate > > SAL_CALL buildCertificatePath( const css::uno::Reference< css::security::XCertificate >& beginCert ) override ; |
| 102 |
|
| 103 |
virtual css::uno::Reference< css::security::XCertificate > SAL_CALL createCertificateFromRaw( const css::uno::Sequence< sal_Int8 >& rawCertificate ) override ; |
| 104 |
virtual css::uno::Reference< css::security::XCertificate > SAL_CALL createCertificateFromAscii( const OUString& asciiCertificate ) override ; |
| 105 |
|
| 106 |
// Methods of XCertificateCreator |
| 107 |
css::uno::Reference<css::security::XCertificate> SAL_CALL addDERCertificateToTheDatabase( |
| 108 |
css::uno::Sequence<sal_Int8> const & raDERCertificate, |
| 109 |
OUString const & raTrustString) override; |
| 110 |
|
| 111 |
css::uno::Reference<css::security::XCertificate> SAL_CALL createDERCertificateWithPrivateKey( |
| 112 |
css::uno::Sequence<sal_Int8> const & raDERCertificate, |
| 113 |
css::uno::Sequence<sal_Int8> const & raPrivateKey) override; |
| 114 |
|
| 115 |
//Native methods |
| 116 |
/// @throws css::uno::RuntimeException |
| 117 |
xmlSecKeysMngrPtr createKeysManager() ; |
| 118 |
/// @throws css::uno::Exception |
| 119 |
/// @throws css::uno::RuntimeException |
| 120 |
static void destroyKeysManager(xmlSecKeysMngrPtr pKeysMngr) ; |
| 121 |
|
| 122 |
private: |
| 123 |
|
| 124 |
void updateSlots(); |
| 125 |
|
| 126 |
static rtl::Reference<X509Certificate_NssImpl> createAndAddCertificateFromPackage( |
| 127 |
const css::uno::Sequence<sal_Int8>& raDerCertificate, |
| 128 |
std::u16string_view raString); |
| 129 |
static SECKEYPrivateKey* insertPrivateKey(css::uno::Sequence<sal_Int8> const & raPrivateKey); |
| 130 |
|
| 131 |
static rtl::Reference<X509Certificate_NssImpl> createX509CertificateFromDER(const css::uno::Sequence<sal_Int8>& raDerCertificate); |
| 132 |
|
| 133 |
/// @throws css::uno::Exception |
| 134 |
/// @throws css::uno::RuntimeException |
| 135 |
void addCryptoSlot( PK11SlotInfo* aSlot ) ; |
| 136 |
} ; |
| 137 |
|
| 138 |
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |