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 .
20 #ifndef INCLUDED_XMLSECURITY_SOURCE_XMLSEC_NSS_SECURITYENVIRONMENT_NSSIMPL_HXX
21 #define INCLUDED_XMLSECURITY_SOURCE_XMLSEC_NSS_SECURITYENVIRONMENT_NSSIMPL_HXX
23 #include <sal/config.h>
24 #include <rtl/ustring.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>
32 #include <com/sun/star/lang/XUnoTunnel.hpp>
34 #include <osl/mutex.hxx>
40 #include <xmlsec-wrapper.h>
42 namespace com
{ namespace sun
{ namespace star
{ namespace security
{ class XCertificate
; } } } }
43 class X509Certificate_NssImpl
;
45 class SecurityEnvironment_NssImpl
: public ::cppu::WeakImplHelper
<
46 css::xml::crypto::XSecurityEnvironment
,
47 css::xml::crypto::XCertificateCreator
,
48 css::lang::XServiceInfo
,
49 css::lang::XUnoTunnel
>
53 std::vector
< PK11SlotInfo
* > m_Slots
;
54 /// The last used certificate which has the private key for signing.
55 css::uno::Reference
<css::security::XCertificate
> 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 //Methods from XUnoTunnel
89 virtual sal_Int64 SAL_CALL
getSomething( const css::uno::Sequence
< sal_Int8
>& aIdentifier
) override
;
91 static const css::uno::Sequence
< sal_Int8
>& getUnoTunnelId() ;
93 /// @throws css::uno::Exception
94 /// @throws css::uno::RuntimeException
95 void setCertDb( CERTCertDBHandle
* aCertDb
) ;
97 /// @throws css::uno::Exception
98 /// @throws css::uno::RuntimeException
99 void adoptSymKey( PK11SymKey
* aSymKey
) ;
101 virtual css::uno::Sequence
< css::uno::Reference
< css::security::XCertificate
> > SAL_CALL
getPersonalCertificates() override
;
102 virtual css::uno::Sequence
< css::uno::Reference
< css::security::XCertificate
> > SAL_CALL
getAllCertificates() override
103 { return css::uno::Sequence
< css::uno::Reference
< css::security::XCertificate
> >(); }
105 virtual css::uno::Reference
< css::security::XCertificate
> SAL_CALL
getCertificate( const OUString
& issuerName
, const css::uno::Sequence
< sal_Int8
>& serialNumber
) override
;
107 virtual css::uno::Sequence
< css::uno::Reference
< css::security::XCertificate
> > SAL_CALL
buildCertificatePath( const css::uno::Reference
< css::security::XCertificate
>& beginCert
) override
;
109 virtual css::uno::Reference
< css::security::XCertificate
> SAL_CALL
createCertificateFromRaw( const css::uno::Sequence
< sal_Int8
>& rawCertificate
) override
;
110 virtual css::uno::Reference
< css::security::XCertificate
> SAL_CALL
createCertificateFromAscii( const OUString
& asciiCertificate
) override
;
112 // Methods of XCertificateCreator
113 css::uno::Reference
<css::security::XCertificate
> SAL_CALL
addDERCertificateToTheDatabase(
114 css::uno::Sequence
<sal_Int8
> const & raDERCertificate
,
115 OUString
const & raTrustString
) override
;
117 css::uno::Reference
<css::security::XCertificate
> SAL_CALL
createDERCertificateWithPrivateKey(
118 css::uno::Sequence
<sal_Int8
> const & raDERCertificate
,
119 css::uno::Sequence
<sal_Int8
> const & raPrivateKey
) override
;
122 /// @throws css::uno::RuntimeException
123 xmlSecKeysMngrPtr
createKeysManager() ;
124 /// @throws css::uno::Exception
125 /// @throws css::uno::RuntimeException
126 static void destroyKeysManager(xmlSecKeysMngrPtr pKeysMngr
) ;
132 static X509Certificate_NssImpl
* createAndAddCertificateFromPackage(
133 const css::uno::Sequence
<sal_Int8
>& raDerCertificate
,
134 OUString
const & raString
);
135 static SECKEYPrivateKey
* insertPrivateKey(css::uno::Sequence
<sal_Int8
> const & raPrivateKey
);
137 static X509Certificate_NssImpl
* createX509CertificateFromDER(const css::uno::Sequence
<sal_Int8
>& raDerCertificate
);
139 /// @throws css::uno::Exception
140 /// @throws css::uno::RuntimeException
141 void addCryptoSlot( PK11SlotInfo
* aSlot
) ;
144 #endif // INCLUDED_XMLSECURITY_SOURCE_XMLSEC_NSS_SECURITYENVIRONMENT_NSSIMPL_HXX
146 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */