diff options
author | Thorsten Behrens <Thorsten.Behrens@CIB.de> | 2017-06-21 18:00:55 +0200 |
---|---|---|
committer | Thorsten Behrens <Thorsten.Behrens@CIB.de> | 2017-06-21 22:16:56 +0200 |
commit | ba53bd4e7234c771e6e655a492f0416807669027 (patch) | |
tree | 19c30c526611e36b907f4e389b9567ff2b76eb49 | |
parent | gpg4libre: some code improvements, add metadata for OpenPGP keys (diff) | |
download | core-ba53bd4e7234c771e6e655a492f0416807669027.tar.gz core-ba53bd4e7234c771e6e655a492f0416807669027.zip |
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
-rw-r--r-- | xmlsecurity/inc/framework/signatureverifierimpl.hxx | 3 | ||||
-rw-r--r-- | xmlsecurity/inc/gpg/SEInitializer.hxx | 5 | ||||
-rw-r--r-- | xmlsecurity/inc/xsecctl.hxx | 1 | ||||
-rw-r--r-- | xmlsecurity/source/gpg/SEInitializer.cxx | 4 | ||||
-rw-r--r-- | xmlsecurity/source/helper/documentsignaturemanager.cxx | 2 | ||||
-rw-r--r-- | xmlsecurity/source/helper/xsecparser.cxx | 4 | ||||
-rw-r--r-- | 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<css::uno::XComponentContext > &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 0fb46efb2b67..360d39e326f4 100644 --- a/xmlsecurity/source/helper/xsecparser.cxx +++ b/xmlsecurity/source/helper/xsecparser.cxx @@ -178,6 +178,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 0e030f37de07..bd9e7dbf7839 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 <com/sun/star/xml/crypto/sax/XKeyCollector.hpp> #include <com/sun/star/xml/crypto/sax/ElementMarkPriority.hpp> #include <com/sun/star/xml/crypto/sax/XReferenceResolvedBroadcaster.hpp> #include <com/sun/star/xml/crypto/sax/XReferenceCollector.hpp> #include <com/sun/star/xml/crypto/sax/XSignatureVerifyResultBroadcaster.hpp> +#include <com/sun/star/xml/crypto/XSEInitializer.hpp> #include <com/sun/star/xml/sax/SAXParseException.hpp> #include <com/sun/star/embed/StorageFormats.hpp> #include <sal/log.hxx> @@ -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<SignatureVerifierImpl*>( + m_vInternalSignatureInformations.back().xReferenceResolvedListener.get()); + if (pImpl) + { + css::uno::Reference<css::xml::crypto::XSEInitializer> 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()) |