Debian Codegraph @

xmlsecurity/source/xmlsec/nss/seinitializer_nssimpl.cxx

raw
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 #include <sal/types.h>
21 #include <com/sun/star/xml/crypto/SecurityEnvironment.hpp>
22 #include <com/sun/star/xml/crypto/XMLSecurityContext.hpp>
23 #include <cppuhelper/supportsservice.hxx>
24
25 #include "seinitializer_nssimpl.hxx"
26 #include "securityenvironment_nssimpl.hxx"
27
28 #include <cert.h>
29
30
31 using namespace com::sun::star;
32
33
34 SEInitializer_NssImpl::SEInitializer_NssImpl( const css::uno::Reference< css::uno::XComponentContext > &rxContext )
35 {
36 m_xContext = rxContext;
37 }
38
39 SEInitializer_NssImpl::~SEInitializer_NssImpl()
40 {
41 }
42
43 /* XSEInitializer */
44 uno::Reference< css::xml::crypto::XXMLSecurityContext > SAL_CALL
45 SEInitializer_NssImpl::createSecurityContext( const OUString& )
46 {
47 CERTCertDBHandle *pCertHandle = nullptr ;
48
49 if( !initNSS( m_xContext ) )
50 return nullptr;
51
52 pCertHandle = CERT_GetDefaultCertDB() ;
53
54 try
55 {
56 /* Build XML Security Context */
57 uno::Reference< css::xml::crypto::XXMLSecurityContext > xSecCtx = css::xml::crypto::XMLSecurityContext::create( m_xContext );
58
59 uno::Reference< css::xml::crypto::XSecurityEnvironment > xSecEnv = css::xml::crypto::SecurityEnvironment::create( m_xContext );
60 SecurityEnvironment_NssImpl* pSecEnv = dynamic_cast<SecurityEnvironment_NssImpl*>(xSecEnv.get());
61 assert(pSecEnv && "can only succeed");
62 pSecEnv->setCertDb(pCertHandle);
63
64 sal_Int32 n = xSecCtx->addSecurityEnvironment(xSecEnv);
65 //originally the SecurityEnvironment with the internal slot was set as default
66 xSecCtx->setDefaultSecurityEnvironmentIndex( n );
67 return xSecCtx;
68 }
69 catch( const uno::Exception& )
70 {
71 //PK11_LogoutAll();
72 //NSS_Shutdown();
73 return nullptr;
74 }
75 }
76
77 void SAL_CALL SEInitializer_NssImpl::freeSecurityContext( const uno::Reference< css::xml::crypto::XXMLSecurityContext >& )
78 {
79 /*
80 * because the security context will free all its content when it
81 * is destructed, so here no free process for the security context
82 * is needed.
83 */
84 //PK11_LogoutAll();
85 //NSS_Shutdown();
86 }
87
88 /* XServiceInfo */
89 OUString SAL_CALL SEInitializer_NssImpl::getImplementationName( )
90 {
91 return u"com.sun.star.xml.crypto.SEInitializer"_ustr;
92 }
93 sal_Bool SAL_CALL SEInitializer_NssImpl::supportsService( const OUString& rServiceName )
94 {
95 return cppu::supportsService( this, rServiceName );
96 }
97 uno::Sequence< OUString > SAL_CALL SEInitializer_NssImpl::getSupportedServiceNames( )
98 {
99 return { u"com.sun.star.xml.crypto.SEInitializer"_ustr };
100 }
101
102 namespace {
103
104 class NSSInitializer_NssImpl : public SEInitializer_NssImpl
105 {
106 public:
107 explicit NSSInitializer_NssImpl(const uno::Reference<uno::XComponentContext>& xContext);
108 OUString SAL_CALL getImplementationName() override;
109 uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override;
110 };
111
112 }
113
114 NSSInitializer_NssImpl::NSSInitializer_NssImpl(const uno::Reference<uno::XComponentContext>& xContext)
115 : SEInitializer_NssImpl(xContext)
116 {
117 }
118
119 OUString NSSInitializer_NssImpl::getImplementationName()
120 {
121 return u"com.sun.star.xml.crypto.NSSInitializer"_ustr;
122 }
123
124 uno::Sequence<OUString> SAL_CALL NSSInitializer_NssImpl::getSupportedServiceNames()
125 {
126 return { u"com.sun.star.xml.crypto.NSSInitializer"_ustr };
127 }
128
129 extern "C" SAL_DLLPUBLIC_EXPORT uno::XInterface*
130 com_sun_star_xml_crypto_NSSInitializer_get_implementation(
131 uno::XComponentContext* pCtx, uno::Sequence<uno::Any> const& /*rSeq*/)
132 {
133 return cppu::acquire(new NSSInitializer_NssImpl(pCtx));
134 }
135
136 extern "C" SAL_DLLPUBLIC_EXPORT uno::XInterface*
137 com_sun_star_xml_crypto_SEInitializer_get_implementation(
138 uno::XComponentContext* pCtx, uno::Sequence<uno::Any> const& /*rSeq*/)
139 {
140 return cppu::acquire(new SEInitializer_NssImpl(pCtx));
141 }
142
143 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */