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 .
21 * and turn off the additional virtual methods which are part of some interfaces when compiled
28 #include <comphelper/processfactory.hxx>
29 #include <sal/types.h>
30 #include <rtl/bootstrap.hxx>
31 #include <rtl/string.hxx>
32 #include <rtl/strbuf.hxx>
33 #include <osl/file.hxx>
34 #include <osl/thread.h>
35 #include <com/sun/star/xml/crypto/SecurityEnvironment.hpp>
36 #include <com/sun/star/xml/crypto/XMLSecurityContext.hpp>
37 #include <cppuhelper/supportsservice.hxx>
39 #include "seinitializer_nssimpl.hxx"
40 #include "securityenvironment_nssimpl.hxx"
50 namespace cssxc
= css::xml::crypto
;
52 using namespace com::sun::star
;
55 SEInitializer_NssImpl::SEInitializer_NssImpl( const css::uno::Reference
< css::uno::XComponentContext
> &rxContext
)
57 m_xContext
= rxContext
;
60 SEInitializer_NssImpl::~SEInitializer_NssImpl()
65 uno::Reference
< cssxc::XXMLSecurityContext
> SAL_CALL
66 SEInitializer_NssImpl::createSecurityContext( const OUString
& )
68 CERTCertDBHandle
*pCertHandle
= nullptr ;
70 if( !initNSS( m_xContext
) )
73 pCertHandle
= CERT_GetDefaultCertDB() ;
77 /* Build XML Security Context */
78 uno::Reference
< cssxc::XXMLSecurityContext
> xSecCtx
= cssxc::XMLSecurityContext::create( m_xContext
);
80 uno::Reference
< cssxc::XSecurityEnvironment
> xSecEnv
= cssxc::SecurityEnvironment::create( m_xContext
);
81 uno::Reference
< lang::XUnoTunnel
> xSecEnvTunnel(xSecEnv
, uno::UNO_QUERY_THROW
);
82 SecurityEnvironment_NssImpl
* pSecEnv
= reinterpret_cast<SecurityEnvironment_NssImpl
*>(
83 sal::static_int_cast
<sal_uIntPtr
>(
84 xSecEnvTunnel
->getSomething(SecurityEnvironment_NssImpl::getUnoTunnelId() ))) ;
85 pSecEnv
->setCertDb(pCertHandle
);
87 sal_Int32 n
= xSecCtx
->addSecurityEnvironment(xSecEnv
);
88 //originally the SecurityEnvironment with the internal slot was set as default
89 xSecCtx
->setDefaultSecurityEnvironmentIndex( n
);
92 catch( const uno::Exception
& )
100 void SAL_CALL
SEInitializer_NssImpl::freeSecurityContext( const uno::Reference
< cssxc::XXMLSecurityContext
>& )
103 * because the security context will free all its content when it
104 * is destructed, so here no free process for the security context
111 OUString
SEInitializer_NssImpl_getImplementationName ()
113 return OUString ("com.sun.star.xml.security.bridge.xmlsec.SEInitializer_NssImpl" );
116 uno::Sequence
< OUString
> SAL_CALL
SEInitializer_NssImpl_getSupportedServiceNames( )
118 uno::Sequence
< OUString
> aRet(2);
119 OUString
* pArray
= aRet
.getArray();
120 pArray
[0] = "com.sun.star.xml.crypto.SEInitializer";
121 pArray
[1] = NSS_SERVICE_NAME
;
125 uno::Reference
< uno::XInterface
> SAL_CALL
SEInitializer_NssImpl_createInstance( const uno::Reference
< lang::XMultiServiceFactory
> & rxMSF
)
127 return static_cast<cppu::OWeakObject
*>(new SEInitializer_NssImpl(comphelper::getComponentContext(rxMSF
)));
131 OUString SAL_CALL
SEInitializer_NssImpl::getImplementationName( )
133 return SEInitializer_NssImpl_getImplementationName();
135 sal_Bool SAL_CALL
SEInitializer_NssImpl::supportsService( const OUString
& rServiceName
)
137 return cppu::supportsService( this, rServiceName
);
139 uno::Sequence
< OUString
> SAL_CALL
SEInitializer_NssImpl::getSupportedServiceNames( )
141 return SEInitializer_NssImpl_getSupportedServiceNames();
144 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */