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