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 #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"
31 using namespace com::sun::star
;
34 SEInitializer_NssImpl::SEInitializer_NssImpl( const css::uno::Reference
< css::uno::XComponentContext
> &rxContext
)
36 m_xContext
= rxContext
;
39 SEInitializer_NssImpl::~SEInitializer_NssImpl()
44 uno::Reference
< css::xml::crypto::XXMLSecurityContext
> SAL_CALL
45 SEInitializer_NssImpl::createSecurityContext( const OUString
& )
47 CERTCertDBHandle
*pCertHandle
= nullptr ;
49 if( !initNSS( m_xContext
) )
52 pCertHandle
= CERT_GetDefaultCertDB() ;
56 /* Build XML Security Context */
57 uno::Reference
< css::xml::crypto::XXMLSecurityContext
> xSecCtx
= css::xml::crypto::XMLSecurityContext::create( m_xContext
);
59 uno::Reference
< css::xml::crypto::XSecurityEnvironment
> xSecEnv
= css::xml::crypto::SecurityEnvironment::create( m_xContext
);
60 uno::Reference
< lang::XUnoTunnel
> xSecEnvTunnel(xSecEnv
, uno::UNO_QUERY_THROW
);
61 SecurityEnvironment_NssImpl
* pSecEnv
= reinterpret_cast<SecurityEnvironment_NssImpl
*>(
62 sal::static_int_cast
<sal_uIntPtr
>(
63 xSecEnvTunnel
->getSomething(SecurityEnvironment_NssImpl::getUnoTunnelId() ))) ;
64 pSecEnv
->setCertDb(pCertHandle
);
66 sal_Int32 n
= xSecCtx
->addSecurityEnvironment(xSecEnv
);
67 //originally the SecurityEnvironment with the internal slot was set as default
68 xSecCtx
->setDefaultSecurityEnvironmentIndex( n
);
71 catch( const uno::Exception
& )
79 void SAL_CALL
SEInitializer_NssImpl::freeSecurityContext( const uno::Reference
< css::xml::crypto::XXMLSecurityContext
>& )
82 * because the security context will free all its content when it
83 * is destructed, so here no free process for the security context
91 OUString SAL_CALL
SEInitializer_NssImpl::getImplementationName( )
93 return "com.sun.star.xml.crypto.SEInitializer";
95 sal_Bool SAL_CALL
SEInitializer_NssImpl::supportsService( const OUString
& rServiceName
)
97 return cppu::supportsService( this, rServiceName
);
99 uno::Sequence
< OUString
> SAL_CALL
SEInitializer_NssImpl::getSupportedServiceNames( )
101 return { "com.sun.star.xml.crypto.SEInitializer" };
106 class NSSInitializer_NssImpl
: public SEInitializer_NssImpl
109 explicit NSSInitializer_NssImpl(const uno::Reference
<uno::XComponentContext
>& xContext
);
110 OUString SAL_CALL
getImplementationName() override
;
111 uno::Sequence
<OUString
> SAL_CALL
getSupportedServiceNames() override
;
116 NSSInitializer_NssImpl::NSSInitializer_NssImpl(const uno::Reference
<uno::XComponentContext
>& xContext
)
117 : SEInitializer_NssImpl(xContext
)
121 OUString
NSSInitializer_NssImpl::getImplementationName()
123 return "com.sun.star.xml.crypto.NSSInitializer";
126 uno::Sequence
<OUString
> SAL_CALL
NSSInitializer_NssImpl::getSupportedServiceNames()
128 return { "com.sun.star.xml.crypto.NSSInitializer" };
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: */