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 #if !defined WIN32_LEAN_AND_MEAN
23 # define WIN32_LEAN_AND_MEAN
27 #include <sal/config.h>
29 #include <xmlsec/keysmngr.h>
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>
37 #include <com/sun/star/uno/Reference.hxx>
38 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
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>
48 #include <sal/types.h>
51 class SecurityEnvironment_MSCryptImpl
: public ::cppu::WeakImplHelper
<
52 css::xml::crypto::XSecurityEnvironment
,
53 css::lang::XServiceInfo
>
56 //crypto provider and key container
58 LPCTSTR m_pszContainer
;
61 HCERTSTORE m_hKeyStore
;
64 HCERTSTORE m_hCertStore
;
66 // i120675, save the store handles
67 HCERTSTORE m_hMySystemStore
;
68 HCERTSTORE m_hRootSystemStore
;
69 HCERTSTORE m_hTrustSystemStore
;
70 HCERTSTORE m_hCaSystemStore
;
72 //Enable default system cryptography setting
73 bool m_bEnableDefault
;
76 css::uno::Reference
< css::lang::XMultiServiceFactory
> m_xServiceManager
;
79 explicit SecurityEnvironment_MSCryptImpl( const css::uno::Reference
< css::uno::XComponentContext
>& xContext
) ;
80 virtual ~SecurityEnvironment_MSCryptImpl() override
;
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
> >(); }
87 virtual css::uno::Reference
< css::security::XCertificate
> SAL_CALL
getCertificate(
88 const OUString
& issuerName
,
89 const css::uno::Sequence
< sal_Int8
>& serialNumber
) override
;
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
) ;
97 virtual css::uno::Sequence
< css::uno::Reference
< css::security::XCertificate
> > SAL_CALL
buildCertificatePath(
98 const css::uno::Reference
< css::security::XCertificate
>& beginCert
) override
;
100 virtual css::uno::Reference
< css::security::XCertificate
> SAL_CALL
createCertificateFromRaw(
101 const css::uno::Sequence
< sal_Int8
>& rawCertificate
) override
;
103 virtual css::uno::Reference
< css::security::XCertificate
> SAL_CALL
createCertificateFromAscii(
104 const OUString
& asciiCertificate
) override
;
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
;
111 virtual ::sal_Int32 SAL_CALL
getCertificateCharacters(
112 const css::uno::Reference
< css::security::XCertificate
>& xCert
) override
;
114 virtual OUString SAL_CALL
getSecurityEnvironmentInformation( ) override
;
117 //Methods from XServiceInfo
118 virtual OUString SAL_CALL
getImplementationName() override
;
120 virtual sal_Bool SAL_CALL
supportsService(
121 const OUString
& ServiceName
124 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames() override
;
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
) ;
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
) ;
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
) ;
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
) ;
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() ;
161 /// @throws css::uno::Exception
162 /// @throws css::uno::RuntimeException
163 xmlSecKeysMngrPtr
createKeysManager() ;
165 /// @throws css::uno::Exception
166 /// @throws css::uno::RuntimeException
167 static void destroyKeysManager(xmlSecKeysMngrPtr pKeysMngr
) ;
170 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */