summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThorsten Behrens <Thorsten.Behrens@CIB.de>2017-06-21 18:00:55 +0200
committerThorsten Behrens <Thorsten.Behrens@CIB.de>2017-06-21 20:59:54 +0200
commit7d6a00f3a79d75dd4cb4badb722dce15e05e5dce (patch)
treede7b10b8bfadf7f2241bed15173f9a779f484319
parent1f0e966e4c432928bc67a0112219b995faaec984 (diff)
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.hxx3
-rw-r--r--xmlsecurity/inc/gpg/SEInitializer.hxx5
-rw-r--r--xmlsecurity/inc/xsecctl.hxx1
-rw-r--r--xmlsecurity/source/gpg/SEInitializer.cxx4
-rw-r--r--xmlsecurity/source/helper/documentsignaturemanager.cxx2
-rw-r--r--xmlsecurity/source/helper/xsecparser.cxx4
-rw-r--r--xmlsecurity/source/helper/xsecverify.cxx24
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 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 <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())