From ed92db7a50be36fcfe6e9b316f4b7f7570060c0d Mon Sep 17 00:00:00 2001 From: Samuel Mehrbrodt Date: Tue, 20 Jun 2017 14:49:10 +0200 Subject: gpg4libre: Init xmlsec in one place before creating the gpg/x509 services Change-Id: I0308d586344b5e52ad327f6650b62ac0eac7ecb9 --- xmlsecurity/Library_xsec_xmlsec.mk | 1 + xmlsecurity/inc/xmlsec/xmlsec_init.hxx | 20 +++++++++ xmlsecurity/source/gpg/XMLSecurityContext.cxx | 22 ---------- .../source/helper/documentsignaturemanager.cxx | 10 ++++- .../xmlsec/nss/xmlsecuritycontext_nssimpl.cxx | 27 ------------- xmlsecurity/source/xmlsec/xmlsec_init.cxx | 47 ++++++++++++++++++++++ 6 files changed, 77 insertions(+), 50 deletions(-) create mode 100644 xmlsecurity/inc/xmlsec/xmlsec_init.hxx create mode 100644 xmlsecurity/source/xmlsec/xmlsec_init.cxx diff --git a/xmlsecurity/Library_xsec_xmlsec.mk b/xmlsecurity/Library_xsec_xmlsec.mk index 249523ae1d1e..d35bc848930e 100644 --- a/xmlsecurity/Library_xsec_xmlsec.mk +++ b/xmlsecurity/Library_xsec_xmlsec.mk @@ -67,6 +67,7 @@ $(eval $(call gb_Library_add_exception_objects,xsec_xmlsec,\ xmlsecurity/source/xmlsec/serialnumberadapter \ xmlsecurity/source/xmlsec/xmldocumentwrapper_xmlsecimpl \ xmlsecurity/source/xmlsec/xmlelementwrapper_xmlsecimpl \ + xmlsecurity/source/xmlsec/xmlsec_init \ xmlsecurity/source/xmlsec/xmlstreamio \ xmlsecurity/source/xmlsec/xsec_xmlsec \ xmlsecurity/source/xmlsec/nss/ciphercontext \ diff --git a/xmlsecurity/inc/xmlsec/xmlsec_init.hxx b/xmlsecurity/inc/xmlsec/xmlsec_init.hxx new file mode 100644 index 000000000000..6dc4de2a63cf --- /dev/null +++ b/xmlsecurity/inc/xmlsec/xmlsec_init.hxx @@ -0,0 +1,20 @@ +/* -*- 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/. + */ + +#ifndef INCLUDED_XMLSECURITY_SOURCE_XMLSEC_XMLSEC_INIT_HXX +#define INCLUDED_XMLSECURITY_SOURCE_XMLSEC_XMLSEC_INIT_HXX + +#include + +XSECXMLSEC_DLLPUBLIC void initXmlSec(); +XSECXMLSEC_DLLPUBLIC void deInitXmlSec(); + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmlsecurity/source/gpg/XMLSecurityContext.cxx b/xmlsecurity/source/gpg/XMLSecurityContext.cxx index cfc391f56ec1..0919f4dbc2b6 100644 --- a/xmlsecurity/source/gpg/XMLSecurityContext.cxx +++ b/xmlsecurity/source/gpg/XMLSecurityContext.cxx @@ -22,32 +22,10 @@ using namespace css::xml::crypto; XMLSecurityContextGpg::XMLSecurityContextGpg() : m_nDefaultEnvIndex(-1) { - // TODO: same code in XMLSecurityContext_NssImpl, not a good idea - // prolly to initialize twice ... - //Init xmlsec library - if( xmlSecInit() < 0 ) { - throw RuntimeException() ; - } - - //Init xmlsec crypto engine library - if( xmlSecCryptoInit() < 0 ) { - xmlSecShutdown() ; - throw RuntimeException() ; - } - - //Enable external stream handlers - if( xmlEnableStreamInputCallbacks() < 0 ) { - xmlSecCryptoShutdown() ; - xmlSecShutdown() ; - throw RuntimeException() ; - } } XMLSecurityContextGpg::~XMLSecurityContextGpg() { - xmlDisableStreamInputCallbacks() ; - xmlSecCryptoShutdown() ; - xmlSecShutdown() ; } sal_Int32 SAL_CALL XMLSecurityContextGpg::addSecurityEnvironment( diff --git a/xmlsecurity/source/helper/documentsignaturemanager.cxx b/xmlsecurity/source/helper/documentsignaturemanager.cxx index 042b5d7065a8..041c3f2a0113 100644 --- a/xmlsecurity/source/helper/documentsignaturemanager.cxx +++ b/xmlsecurity/source/helper/documentsignaturemanager.cxx @@ -37,6 +37,8 @@ #include #include +#include + using namespace css; DocumentSignatureManager::DocumentSignatureManager(const uno::Reference& xContext, DocumentSignatureMode eMode) @@ -46,7 +48,10 @@ DocumentSignatureManager::DocumentSignatureManager(const uno::Reference + +#include "xmlsec/xmlstreamio.hxx" +#include "xmlsec-wrapper.h" + +using namespace css::uno; + +XSECXMLSEC_DLLPUBLIC void initXmlSec() +{ + //Init xmlsec library + if( xmlSecInit() < 0 ) { + throw RuntimeException() ; + } + + //Init xmlsec crypto engine library + if( xmlSecCryptoInit() < 0 ) { + xmlSecShutdown() ; + throw RuntimeException() ; + } + + //Enable external stream handlers + if( xmlEnableStreamInputCallbacks() < 0 ) { + xmlSecCryptoShutdown() ; + xmlSecShutdown() ; + throw RuntimeException() ; + } +} + +XSECXMLSEC_DLLPUBLIC void deInitXmlSec() +{ + xmlDisableStreamInputCallbacks(); + xmlSecCryptoShutdown(); + xmlSecShutdown(); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit