1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
22 #include <sal/config.h>
23 #include <rtl/ustring.hxx>
24 #include <rtl/ref.hxx>
25 #include <cppuhelper/implbase.hxx>
27 #include <com/sun/star/uno/Reference.hxx>
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>
38 #include <string_view>
41 #include <xmlsec/xmlsec.h>
43 namespace com::sun::star::security
{ class XCertificate
; }
44 class X509Certificate_NssImpl
;
46 class SecurityEnvironment_NssImpl
: public ::cppu::WeakImplHelper
<
47 css::xml::crypto::XSecurityEnvironment
,
48 css::xml::crypto::XCertificateCreator
,
49 css::lang::XServiceInfo
>
53 std::vector
< PK11SlotInfo
* > m_Slots
;
54 /// The last used certificate which has the private key for signing.
55 rtl::Reference
<X509Certificate_NssImpl
> m_xSigningCertificate
;
59 CERTCertDBHandle
* m_pHandler
;
60 std::vector
< PK11SymKey
* > m_tSymKeyList
;
63 SecurityEnvironment_NssImpl();
64 virtual ~SecurityEnvironment_NssImpl() override
;
66 //Methods from XSecurityEnvironment
68 //Methods from XServiceInfo
69 virtual OUString SAL_CALL
getImplementationName() override
;
71 virtual sal_Bool SAL_CALL
supportsService(
72 const OUString
& ServiceName
75 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames() override
;
77 virtual ::sal_Int32 SAL_CALL
verifyCertificate(
78 const css::uno::Reference
<
79 css::security::XCertificate
>& xCert
,
80 const css::uno::Sequence
<
81 css::uno::Reference
< css::security::XCertificate
> > &
82 intermediateCerts
) override
;
84 virtual ::sal_Int32 SAL_CALL
getCertificateCharacters( const css::uno::Reference
< css::security::XCertificate
>& xCert
) override
;
86 virtual OUString SAL_CALL
getSecurityEnvironmentInformation( ) override
;
88 /// @throws css::uno::Exception
89 /// @throws css::uno::RuntimeException
90 void setCertDb( CERTCertDBHandle
* aCertDb
) ;
92 /// @throws css::uno::Exception
93 /// @throws css::uno::RuntimeException
94 void adoptSymKey( PK11SymKey
* aSymKey
) ;
96 virtual css::uno::Sequence
< css::uno::Reference
< css::security::XCertificate
> > SAL_CALL
getPersonalCertificates() override
;
97 virtual css::uno::Sequence
< css::uno::Reference
< css::security::XCertificate
> > SAL_CALL
getAllCertificates() override
98 { return css::uno::Sequence
< css::uno::Reference
< css::security::XCertificate
> >(); }
100 virtual css::uno::Reference
< css::security::XCertificate
> SAL_CALL
getCertificate( const OUString
& issuerName
, const css::uno::Sequence
< sal_Int8
>& serialNumber
) override
;
102 virtual css::uno::Sequence
< css::uno::Reference
< css::security::XCertificate
> > SAL_CALL
buildCertificatePath( const css::uno::Reference
< css::security::XCertificate
>& beginCert
) override
;
104 virtual css::uno::Reference
< css::security::XCertificate
> SAL_CALL
createCertificateFromRaw( const css::uno::Sequence
< sal_Int8
>& rawCertificate
) override
;
105 virtual css::uno::Reference
< css::security::XCertificate
> SAL_CALL
createCertificateFromAscii( const OUString
& asciiCertificate
) override
;
107 // Methods of XCertificateCreator
108 css::uno::Reference
<css::security::XCertificate
> SAL_CALL
addDERCertificateToTheDatabase(
109 css::uno::Sequence
<sal_Int8
> const & raDERCertificate
,
110 OUString
const & raTrustString
) override
;
112 css::uno::Reference
<css::security::XCertificate
> SAL_CALL
createDERCertificateWithPrivateKey(
113 css::uno::Sequence
<sal_Int8
> const & raDERCertificate
,
114 css::uno::Sequence
<sal_Int8
> const & raPrivateKey
) override
;
117 /// @throws css::uno::RuntimeException
118 xmlSecKeysMngrPtr
createKeysManager() ;
119 /// @throws css::uno::Exception
120 /// @throws css::uno::RuntimeException
121 static void destroyKeysManager(xmlSecKeysMngrPtr pKeysMngr
) ;
127 static rtl::Reference
<X509Certificate_NssImpl
> createAndAddCertificateFromPackage(
128 const css::uno::Sequence
<sal_Int8
>& raDerCertificate
,
129 std::u16string_view raString
);
130 static SECKEYPrivateKey
* insertPrivateKey(css::uno::Sequence
<sal_Int8
> const & raPrivateKey
);
132 static rtl::Reference
<X509Certificate_NssImpl
> createX509CertificateFromDER(const css::uno::Sequence
<sal_Int8
>& raDerCertificate
);
134 /// @throws css::uno::Exception
135 /// @throws css::uno::RuntimeException
136 void addCryptoSlot( PK11SlotInfo
* aSlot
) ;
139 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */