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 <comphelper/servicehelper.hxx>
24 #include <cppuhelper/supportsservice.hxx>
26 #include "seinitializer_nssimpl.hxx"
27 #include "securityenvironment_nssimpl.hxx"
32 using namespace com::sun::star
;
35 SEInitializer_NssImpl::SEInitializer_NssImpl( const css::uno::Reference
< css::uno::XComponentContext
> &rxContext
)
37 m_xContext
= rxContext
;
40 SEInitializer_NssImpl::~SEInitializer_NssImpl()
45 uno::Reference
< css::xml::crypto::XXMLSecurityContext
> SAL_CALL
46 SEInitializer_NssImpl::createSecurityContext( const OUString
& )
48 CERTCertDBHandle
*pCertHandle
= nullptr ;
50 if( !initNSS( m_xContext
) )
53 pCertHandle
= CERT_GetDefaultCertDB() ;
57 /* Build XML Security Context */
58 uno::Reference
< css::xml::crypto::XXMLSecurityContext
> xSecCtx
= css::xml::crypto::XMLSecurityContext::create( m_xContext
);
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
);
65 sal_Int32 n
= xSecCtx
->addSecurityEnvironment(xSecEnv
);
66 //originally the SecurityEnvironment with the internal slot was set as default
67 xSecCtx
->setDefaultSecurityEnvironmentIndex( n
);
70 catch( const uno::Exception
& )
78 void SAL_CALL
SEInitializer_NssImpl::freeSecurityContext( const uno::Reference
< css::xml::crypto::XXMLSecurityContext
>& )
81 * because the security context will free all its content when it
82 * is destructed, so here no free process for the security context
90 OUString SAL_CALL
SEInitializer_NssImpl::getImplementationName( )
92 return "com.sun.star.xml.crypto.SEInitializer";
94 sal_Bool SAL_CALL
SEInitializer_NssImpl::supportsService( const OUString
& rServiceName
)
96 return cppu::supportsService( this, rServiceName
);
98 uno::Sequence
< OUString
> SAL_CALL
SEInitializer_NssImpl::getSupportedServiceNames( )
100 return { "com.sun.star.xml.crypto.SEInitializer" };
105 class NSSInitializer_NssImpl
: public SEInitializer_NssImpl
108 explicit NSSInitializer_NssImpl(const uno::Reference
<uno::XComponentContext
>& xContext
);
109 OUString SAL_CALL
getImplementationName() override
;
110 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 return { "com.sun.star.xml.crypto.NSSInitializer" };
130 extern "C" SAL_DLLPUBLIC_EXPORT
uno::XInterface
*
131 com_sun_star_xml_crypto_NSSInitializer_get_implementation(
132 uno::XComponentContext
* pCtx
, uno::Sequence
<uno::Any
> const& /*rSeq*/)
134 return cppu::acquire(new NSSInitializer_NssImpl(pCtx
));
137 extern "C" SAL_DLLPUBLIC_EXPORT
uno::XInterface
*
138 com_sun_star_xml_crypto_SEInitializer_get_implementation(
139 uno::XComponentContext
* pCtx
, uno::Sequence
<uno::Any
> const& /*rSeq*/)
141 return cppu::acquire(new SEInitializer_NssImpl(pCtx
));
144 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */