Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / xmlsecurity / source / xmlsec / nss / seinitializer_nssimpl.cxx
blob707f050330f1c7735153d2e665dfc5ff6a10090a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 #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>
25 #include "seinitializer_nssimpl.hxx"
26 #include "securityenvironment_nssimpl.hxx"
28 #include <cert.h>
31 namespace cssxc = css::xml::crypto;
33 using namespace com::sun::star;
36 SEInitializer_NssImpl::SEInitializer_NssImpl( const css::uno::Reference< css::uno::XComponentContext > &rxContext )
38 m_xContext = rxContext;
41 SEInitializer_NssImpl::~SEInitializer_NssImpl()
45 /* XSEInitializer */
46 uno::Reference< cssxc::XXMLSecurityContext > SAL_CALL
47 SEInitializer_NssImpl::createSecurityContext( const OUString& )
49 CERTCertDBHandle *pCertHandle = nullptr ;
51 if( !initNSS( m_xContext ) )
52 return nullptr;
54 pCertHandle = CERT_GetDefaultCertDB() ;
56 try
58 /* Build XML Security Context */
59 uno::Reference< cssxc::XXMLSecurityContext > xSecCtx = cssxc::XMLSecurityContext::create( m_xContext );
61 uno::Reference< cssxc::XSecurityEnvironment > xSecEnv = cssxc::SecurityEnvironment::create( m_xContext );
62 uno::Reference< lang::XUnoTunnel > xSecEnvTunnel(xSecEnv, uno::UNO_QUERY_THROW);
63 SecurityEnvironment_NssImpl* pSecEnv = reinterpret_cast<SecurityEnvironment_NssImpl*>(
64 sal::static_int_cast<sal_uIntPtr>(
65 xSecEnvTunnel->getSomething(SecurityEnvironment_NssImpl::getUnoTunnelId() ))) ;
66 pSecEnv->setCertDb(pCertHandle);
68 sal_Int32 n = xSecCtx->addSecurityEnvironment(xSecEnv);
69 //originally the SecurityEnvironment with the internal slot was set as default
70 xSecCtx->setDefaultSecurityEnvironmentIndex( n );
71 return xSecCtx;
73 catch( const uno::Exception& )
75 //PK11_LogoutAll();
76 //NSS_Shutdown();
77 return nullptr;
81 void SAL_CALL SEInitializer_NssImpl::freeSecurityContext( const uno::Reference< cssxc::XXMLSecurityContext >& )
84 * because the security context will free all its content when it
85 * is destructed, so here no free process for the security context
86 * is needed.
88 //PK11_LogoutAll();
89 //NSS_Shutdown();
92 /* XServiceInfo */
93 OUString SAL_CALL SEInitializer_NssImpl::getImplementationName( )
95 return "com.sun.star.xml.crypto.SEInitializer";
97 sal_Bool SAL_CALL SEInitializer_NssImpl::supportsService( const OUString& rServiceName )
99 return cppu::supportsService( this, rServiceName );
101 uno::Sequence< OUString > SAL_CALL SEInitializer_NssImpl::getSupportedServiceNames( )
103 uno::Sequence<OUString> seqServiceNames{ "com.sun.star.xml.crypto.SEInitializer" };
104 return seqServiceNames;
107 class NSSInitializer_NssImpl : public SEInitializer_NssImpl
109 public:
110 explicit NSSInitializer_NssImpl(const uno::Reference<uno::XComponentContext>& xContext);
111 OUString SAL_CALL getImplementationName() override;
112 uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override;
115 NSSInitializer_NssImpl::NSSInitializer_NssImpl(const uno::Reference<uno::XComponentContext>& xContext)
116 : SEInitializer_NssImpl(xContext)
120 OUString NSSInitializer_NssImpl::getImplementationName()
122 return "com.sun.star.xml.crypto.NSSInitializer";
125 uno::Sequence<OUString> SAL_CALL NSSInitializer_NssImpl::getSupportedServiceNames()
127 uno::Sequence<OUString> seqServiceNames{ "com.sun.star.xml.crypto.NSSInitializer" };
128 return seqServiceNames;
131 extern "C" SAL_DLLPUBLIC_EXPORT uno::XInterface*
132 com_sun_star_xml_crypto_NSSInitializer_get_implementation(
133 uno::XComponentContext* pCtx, uno::Sequence<uno::Any> const& /*rSeq*/)
135 return cppu::acquire(new NSSInitializer_NssImpl(pCtx));
138 extern "C" SAL_DLLPUBLIC_EXPORT uno::XInterface*
139 com_sun_star_xml_crypto_SEInitializer_get_implementation(
140 uno::XComponentContext* pCtx, uno::Sequence<uno::Any> const& /*rSeq*/)
142 return cppu::acquire(new SEInitializer_NssImpl(pCtx));
145 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */