From 7d6a00f3a79d75dd4cb4badb722dce15e05e5dce Mon Sep 17 00:00:00 2001 From: Thorsten Behrens Date: Wed, 21 Jun 2017 18:00:55 +0200 Subject: gpg4libre: make signature impl swappable in-situ during validation Sadly we only know whether its a OpenPGP or X509 signature during parsing, so we need to switch the implementation mid-way Change-Id: Ib48a9da0105de62cfecda095df8c154b59ba8c40 --- .../inc/framework/signatureverifierimpl.hxx | 3 +++ xmlsecurity/inc/gpg/SEInitializer.hxx | 5 +---- xmlsecurity/inc/xsecctl.hxx | 1 + xmlsecurity/source/gpg/SEInitializer.cxx | 4 +--- .../source/helper/documentsignaturemanager.cxx | 2 +- xmlsecurity/source/helper/xsecparser.cxx | 4 ++++ xmlsecurity/source/helper/xsecverify.cxx | 24 ++++++++++++++++++++++ 7 files changed, 35 insertions(+), 8 deletions(-) diff --git a/xmlsecurity/inc/framework/signatureverifierimpl.hxx b/xmlsecurity/inc/framework/signatureverifierimpl.hxx index 8c20c8385de9..592e4740c714 100644 --- a/xmlsecurity/inc/framework/signatureverifierimpl.hxx +++ b/xmlsecurity/inc/framework/signatureverifierimpl.hxx @@ -76,6 +76,9 @@ public: 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; + + void updateSignature( const css::uno::Reference< css::xml::crypto::XXMLSignature >& xSignature, + const css::uno::Reference< css::xml::crypto::XXMLSecurityContext >& xContext ) { m_xXMLSignature = xSignature; m_xXMLSecurityContext = xContext; } }; /// @throws css::uno::RuntimeException diff --git a/xmlsecurity/inc/gpg/SEInitializer.hxx b/xmlsecurity/inc/gpg/SEInitializer.hxx index d4f375bfd41c..db73d621f7be 100644 --- a/xmlsecurity/inc/gpg/SEInitializer.hxx +++ b/xmlsecurity/inc/gpg/SEInitializer.hxx @@ -22,11 +22,8 @@ class XSECGPG_DLLPUBLIC SEInitializerGpg : public cppu::WeakImplHelper< css::xml::crypto::XSEInitializer > { -protected: - css::uno::Reference< css::uno::XComponentContext > m_xContext; - public: - explicit SEInitializerGpg(const css::uno::Reference &rxContext); + SEInitializerGpg(); virtual ~SEInitializerGpg() override; /* XSEInitializer */ diff --git a/xmlsecurity/inc/xsecctl.hxx b/xmlsecurity/inc/xsecctl.hxx index 3e4037c3ce41..a38c1cbf8e3d 100644 --- a/xmlsecurity/inc/xsecctl.hxx +++ b/xmlsecurity/inc/xsecctl.hxx @@ -292,6 +292,7 @@ private: * For signature verification */ void addSignature(); + void switchGpgSignature(); void addReference( const OUString& ouUri, sal_Int32 nDigestID ); diff --git a/xmlsecurity/source/gpg/SEInitializer.cxx b/xmlsecurity/source/gpg/SEInitializer.cxx index 0e4cbd9d8cc8..919161d86554 100644 --- a/xmlsecurity/source/gpg/SEInitializer.cxx +++ b/xmlsecurity/source/gpg/SEInitializer.cxx @@ -20,10 +20,8 @@ using namespace css::uno; using namespace css::xml::crypto; -SEInitializerGpg::SEInitializerGpg( const css::uno::Reference< css::uno::XComponentContext > &rxContext ) +SEInitializerGpg::SEInitializerGpg() { - m_xContext = rxContext; - // Also init GpgME while we're at it GpgME::initializeLibrary(); } diff --git a/xmlsecurity/source/helper/documentsignaturemanager.cxx b/xmlsecurity/source/helper/documentsignaturemanager.cxx index b2e42076be5e..ded3de8d9960 100644 --- a/xmlsecurity/source/helper/documentsignaturemanager.cxx +++ b/xmlsecurity/source/helper/documentsignaturemanager.cxx @@ -66,7 +66,7 @@ bool DocumentSignatureManager::init() mxSEInitializer = xml::crypto::SEInitializer::create(mxContext); #if !defined(MACOSX) && !defined(WNT) - mxGpgSEInitializer.set(new SEInitializerGpg(mxContext)); + mxGpgSEInitializer.set(new SEInitializerGpg()); #endif if (mxSEInitializer.is()) diff --git a/xmlsecurity/source/helper/xsecparser.cxx b/xmlsecurity/source/helper/xsecparser.cxx index d0c024406e2b..6c402e73e0cb 100644 --- a/xmlsecurity/source/helper/xsecparser.cxx +++ b/xmlsecurity/source/helper/xsecparser.cxx @@ -180,6 +180,10 @@ void SAL_CALL XSecParser::startElement( m_ouX509Certificate.clear(); m_bInX509Certificate = true; } + else if (aName == "PGPData") + { + m_pXSecController->switchGpgSignature(); + } else if (aName == "PGPKeyID") { m_ouGpgKeyID.clear(); diff --git a/xmlsecurity/source/helper/xsecverify.cxx b/xmlsecurity/source/helper/xsecverify.cxx index 3f0856667b8f..ab2a8dec6100 100644 --- a/xmlsecurity/source/helper/xsecverify.cxx +++ b/xmlsecurity/source/helper/xsecverify.cxx @@ -23,12 +23,15 @@ #include "ooxmlsecparser.hxx" #include "framework/signatureverifierimpl.hxx" #include "framework/saxeventkeeperimpl.hxx" +#include "gpg/xmlsignature_gpgimpl.hxx" +#include "gpg/SEInitializer.hxx" #include #include #include #include #include +#include #include #include #include @@ -105,6 +108,27 @@ void XSecController::addSignature() m_vInternalSignatureInformations.push_back( isi ); } +void XSecController::switchGpgSignature() +{ +#if !defined(MACOSX) && !defined(WNT) + // swap signature verifier for the Gpg one + m_xXMLSignature.set(new XMLSignature_GpgImpl()); + if (!m_vInternalSignatureInformations.empty()) + { + SignatureVerifierImpl* pImpl= + dynamic_cast( + m_vInternalSignatureInformations.back().xReferenceResolvedListener.get()); + if (pImpl) + { + css::uno::Reference xGpgSEInitializer( + new SEInitializerGpg()); + pImpl->updateSignature(new XMLSignature_GpgImpl(), + xGpgSEInitializer->createSecurityContext(OUString())); + } + } +#endif +} + void XSecController::addReference( const OUString& ouUri, sal_Int32 nDigestID ) { if (m_vInternalSignatureInformations.empty()) -- cgit v1.2.3