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 SecurityEnvironment_NssImpl
* pSecEnv
= dynamic_cast<SecurityEnvironment_NssImpl
*>(xSecEnv
.get());
61 assert(pSecEnv
&& "can only succeed");
62 pSecEnv
->setCertDb(pCertHandle
);
64 sal_Int32 n
= xSecCtx
->addSecurityEnvironment(xSecEnv
);
65 //originally the SecurityEnvironment with the internal slot was set as default
66 xSecCtx
->setDefaultSecurityEnvironmentIndex( n
);
69 catch( const uno::Exception
& )
77 void SAL_CALL
SEInitializer_NssImpl::freeSecurityContext( const uno::Reference
< css::xml::crypto::XXMLSecurityContext
>& )
80 * because the security context will free all its content when it
81 * is destructed, so here no free process for the security context
89 OUString SAL_CALL
SEInitializer_NssImpl::getImplementationName( )
91 return u
"com.sun.star.xml.crypto.SEInitializer"_ustr
;
93 sal_Bool SAL_CALL
SEInitializer_NssImpl::supportsService( const OUString
& rServiceName
)
95 return cppu::supportsService( this, rServiceName
);
97 uno::Sequence
< OUString
> SAL_CALL
SEInitializer_NssImpl::getSupportedServiceNames( )
99 return { u
"com.sun.star.xml.crypto.SEInitializer"_ustr
};
104 class NSSInitializer_NssImpl
: public SEInitializer_NssImpl
107 explicit NSSInitializer_NssImpl(const uno::Reference
<uno::XComponentContext
>& xContext
);
108 OUString SAL_CALL
getImplementationName() override
;
109 uno::Sequence
<OUString
> SAL_CALL
getSupportedServiceNames() override
;
114 NSSInitializer_NssImpl::NSSInitializer_NssImpl(const uno::Reference
<uno::XComponentContext
>& xContext
)
115 : SEInitializer_NssImpl(xContext
)
119 OUString
NSSInitializer_NssImpl::getImplementationName()
121 return u
"com.sun.star.xml.crypto.NSSInitializer"_ustr
;
124 uno::Sequence
<OUString
> SAL_CALL
NSSInitializer_NssImpl::getSupportedServiceNames()
126 return { u
"com.sun.star.xml.crypto.NSSInitializer"_ustr
};
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*/)
133 return cppu::acquire(new NSSInitializer_NssImpl(pCtx
));
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*/)
140 return cppu::acquire(new SEInitializer_NssImpl(pCtx
));
143 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */