Kaydet (Commit) 0833bab2 authored tarafından Miklos Vajna's avatar Miklos Vajna

xmlsecurity: create CertificateContainer instances with a constructor

Change-Id: I42f0218a46c67062ea6eb0845d978f2630793ec0
Reviewed-on: https://gerrit.libreoffice.org/49304Reviewed-by: 's avatarMiklos Vajna <vmiklos@collabora.co.uk>
Tested-by: 's avatarJenkins <ci@libreoffice.org>
üst c4257244
......@@ -48,7 +48,6 @@ $(eval $(call gb_Library_use_libraries,xmlsecurity,\
$(eval $(call gb_Library_add_exception_objects,xmlsecurity,\
xmlsecurity/source/component/certificatecontainer \
xmlsecurity/source/component/documentdigitalsignatures \
xmlsecurity/source/component/registerservices \
xmlsecurity/source/dialogs/certificatechooser \
xmlsecurity/source/dialogs/certificateviewer \
xmlsecurity/source/dialogs/digitalsignaturesdialog \
......
......@@ -17,8 +17,15 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include "certificatecontainer.hxx"
#include <map>
#include <cppuhelper/implbase.hxx>
#include <com/sun/star/security/XCertificateContainer.hpp>
#include <com/sun/star/lang/XServiceInfo.hpp>
#include <com/sun/star/uno/XComponentContext.hpp>
#include <cppuhelper/supportsservice.hxx>
#include <rtl/ref.hxx>
#include <sal/config.h>
......@@ -26,6 +33,34 @@ using namespace ::com::sun::star;
using namespace ::com::sun::star::lang;
using namespace ::com::sun::star::uno;
class CertificateContainer
: public ::cppu::WeakImplHelper<css::lang::XServiceInfo, css::security::XCertificateContainer>
{
private:
typedef std::map<OUString, OUString> Map;
Map certMap;
Map certTrustMap;
static bool searchMap(const OUString& url, const OUString& certificate_name, Map& _certMap);
/// @throws css::uno::RuntimeException
bool isTemporaryCertificate(const OUString& url, const OUString& certificate_name);
/// @throws css::uno::RuntimeException
bool isCertificateTrust(const OUString& url, const OUString& certificate_name);
public:
explicit CertificateContainer(const uno::Reference<uno::XComponentContext>&) {}
virtual sal_Bool SAL_CALL addCertificate(const OUString& url, const OUString& certificate_name,
sal_Bool trust) override;
virtual css::security::CertificateContainerStatus SAL_CALL
hasCertificate(const OUString& url, const OUString& certificate_name) override;
// XServiceInfo
virtual OUString SAL_CALL getImplementationName() override;
virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override;
virtual css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override;
};
bool
CertificateContainer::searchMap( const OUString & url, const OUString & certificate_name, Map &_certMap )
{
......@@ -86,7 +121,7 @@ CertificateContainer::hasCertificate( const OUString & url, const OUString & cer
OUString SAL_CALL
CertificateContainer::getImplementationName( )
{
return impl_getStaticImplementationName();
return OUString("com.sun.star.security.CertificateContainer");
}
sal_Bool SAL_CALL
......@@ -97,26 +132,35 @@ CertificateContainer::supportsService( const OUString& ServiceName )
Sequence< OUString > SAL_CALL
CertificateContainer::getSupportedServiceNames( )
{
return impl_getStaticSupportedServiceNames();
}
Sequence< OUString >
CertificateContainer::impl_getStaticSupportedServiceNames( )
{
Sequence< OUString > aRet { "com.sun.star.security.CertificateContainer" };
return aRet;
}
OUString
CertificateContainer::impl_getStaticImplementationName()
namespace
{
return OUString("com.sun.star.security.CertificateContainer");
struct Instance
{
explicit Instance(css::uno::Reference<css::uno::XComponentContext> const& context)
: instance(new CertificateContainer(context))
{
}
rtl::Reference<CertificateContainer> instance;
};
struct Singleton
: public rtl::StaticWithArg<Instance, css::uno::Reference<css::uno::XComponentContext>,
Singleton>
{
};
}
Reference< XInterface > CertificateContainer::impl_createInstance( const Reference< XMultiServiceFactory >& xServiceManager )
extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
com_sun_star_security_CertificateContainer_get_implementation(
css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const&)
{
return Reference< XInterface >( *new CertificateContainer( xServiceManager ) );
return cppu::acquire(Singleton::get(context).instance.get());
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#ifndef INCLUDED_XMLSECURITY_SOURCE_COMPONENT_CERTIFICATECONTAINER_HXX
#define INCLUDED_XMLSECURITY_SOURCE_COMPONENT_CERTIFICATECONTAINER_HXX
#include <com/sun/star/lang/XServiceInfo.hpp>
#include <com/sun/star/lang/XSingleServiceFactory.hpp>
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
#include <cppuhelper/factory.hxx>
#include <cppuhelper/implbase.hxx>
#include <com/sun/star/security/XCertificateContainer.hpp>
#include <com/sun/star/security/CertificateContainerStatus.hpp>
#include <vector>
#include <map>
class CertificateContainer : public ::cppu::WeakImplHelper< css::lang::XServiceInfo, css::security::XCertificateContainer >
{
private:
typedef std::map< OUString, OUString > Map;
Map certMap;
Map certTrustMap;
static bool searchMap( const OUString & url, const OUString & certificate_name, Map &_certMap );
/// @throws css::uno::RuntimeException
bool isTemporaryCertificate( const OUString & url, const OUString & certificate_name );
/// @throws css::uno::RuntimeException
bool isCertificateTrust( const OUString & url, const OUString & certificate_name );
public:
explicit CertificateContainer(const css::uno::Reference< css::lang::XMultiServiceFactory >& ) {}
virtual sal_Bool SAL_CALL addCertificate( const OUString & url, const OUString & certificate_name, sal_Bool trust ) override;
virtual css::security::CertificateContainerStatus SAL_CALL hasCertificate( const OUString & url, const OUString & certificate_name ) override;
// provide factory
/// @throws css::uno::RuntimeException
static OUString impl_getStaticImplementationName( );
/// @throws css::uno::RuntimeException
static css::uno::Sequence< OUString >
impl_getStaticSupportedServiceNames( );
/// @throws css::uno::RuntimeException
static css::uno::Reference< css::uno::XInterface >
impl_createInstance( const css::uno::Reference< css::lang::XMultiServiceFactory >& xServiceManager );
// XServiceInfo
virtual OUString SAL_CALL getImplementationName( ) override;
virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
virtual css::uno::Sequence< OUString > SAL_CALL
getSupportedServiceNames( ) override;
};
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include <com/sun/star/lang/XSingleServiceFactory.hpp>
#include <cppuhelper/factory.hxx>
#include "certificatecontainer.hxx"
using namespace ::com::sun::star;
using namespace ::com::sun::star::uno;
extern "C"
{
SAL_DLLPUBLIC_EXPORT void* xmlsecurity_component_getFactory( const sal_Char * pImplName, void * pServiceManager, void * /*pRegistryKey*/ )
{
void* pRet = nullptr;
uno::Reference< XInterface > xFactory;
//Decryptor
OUString implName = OUString::createFromAscii( pImplName );
if (pServiceManager && implName == CertificateContainer::impl_getStaticImplementationName())
{
// CertificateContainer
xFactory = cppu::createOneInstanceFactory(
static_cast< lang::XMultiServiceFactory * >( pServiceManager ),
OUString::createFromAscii( pImplName ),
CertificateContainer::impl_createInstance,
CertificateContainer::impl_getStaticSupportedServiceNames() );
}
if (xFactory.is())
{
xFactory->acquire();
pRet = xFactory.get();
}
return pRet;
}
} // extern "C"
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -18,8 +18,9 @@
-->
<component loader="com.sun.star.loader.SharedLibrary" environment="@CPPU_ENV@"
prefix="xmlsecurity" xmlns="http://openoffice.org/2010/uno-components">
<implementation name="com.sun.star.security.CertificateContainer">
xmlns="http://openoffice.org/2010/uno-components">
<implementation name="com.sun.star.security.CertificateContainer"
constructor="com_sun_star_security_CertificateContainer_get_implementation">
<service name="com.sun.star.security.CertificateContainer"/>
</implementation>
<implementation name="com.sun.star.security.DocumentDigitalSignatures"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment