[Libreoffice-commits] core.git: xmlsecurity/inc xmlsecurity/source

Miklos Vajna vmiklos at collabora.co.uk
Fri Apr 21 08:55:43 UTC 2017


 xmlsecurity/inc/xsecctl.hxx                       |    3 
 xmlsecurity/source/helper/ooxmlsecparser.cxx      |    5 +
 xmlsecurity/source/helper/ooxmlsecparser.hxx      |    3 
 xmlsecurity/source/helper/xmlsignaturehelper.cxx  |   37 +--------
 xmlsecurity/source/helper/xmlsignaturehelper2.cxx |   85 ----------------------
 xmlsecurity/source/helper/xmlsignaturehelper2.hxx |   41 ----------
 xmlsecurity/source/helper/xsecparser.cxx          |    6 +
 xmlsecurity/source/helper/xsecparser.hxx          |    3 
 xmlsecurity/source/helper/xsecverify.cxx          |    6 -
 9 files changed, 24 insertions(+), 165 deletions(-)

New commits:
commit db3683b43f1055af831874e8a89f0e0d532e1d6a
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Fri Apr 21 08:17:42 2017 +0200

    xmlsecurity: remove no longer needed ImplXMLSignatureListener
    
    The only remaining task it did was StartVerifySignatureElement() in
    startElement(), but that can be done in OOXMLSecParser / XSecParser
    easily, no need to have separate class for that.
    
    Change-Id: I0863019d3a92a911df0d60bf872dd0978eac03d5
    Reviewed-on: https://gerrit.libreoffice.org/36770
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
    Tested-by: Jenkins <ci at libreoffice.org>

diff --git a/xmlsecurity/inc/xsecctl.hxx b/xmlsecurity/inc/xsecctl.hxx
index 731004e5ddf2..89457ddffd4e 100644
--- a/xmlsecurity/inc/xsecctl.hxx
+++ b/xmlsecurity/inc/xsecctl.hxx
@@ -62,6 +62,7 @@
 class XSecParser;
 class XMLDocumentWrapper_XmlSecImpl;
 class SAXEventKeeperImpl;
+class XMLSignatureHelper;
 
 class InternalSignatureInformation
 {
@@ -395,7 +396,7 @@ public:
      */
     void collectToVerify( const OUString& referenceId );
     void addSignature( sal_Int32 nSignatureId );
-    css::uno::Reference< css::xml::sax::XDocumentHandler > const & createSignatureReader(sal_Int32 nType = 0);
+    css::uno::Reference< css::xml::sax::XDocumentHandler > const & createSignatureReader(XMLSignatureHelper& rXMLSignatureHelper, sal_Int32 nType = 0);
     void releaseSignatureReader();
 
 public:
diff --git a/xmlsecurity/source/helper/ooxmlsecparser.cxx b/xmlsecurity/source/helper/ooxmlsecparser.cxx
index aff5c1d302c5..26f82b0ab47c 100644
--- a/xmlsecurity/source/helper/ooxmlsecparser.cxx
+++ b/xmlsecurity/source/helper/ooxmlsecparser.cxx
@@ -9,10 +9,11 @@
 
 
 #include "ooxmlsecparser.hxx"
+#include "xmlsignaturehelper.hxx"
 
 using namespace com::sun::star;
 
-OOXMLSecParser::OOXMLSecParser(XSecController* pXSecController)
+OOXMLSecParser::OOXMLSecParser(XMLSignatureHelper& rXMLSignatureHelper, XSecController* pXSecController)
     : m_pXSecController(pXSecController)
     ,m_bInDigestValue(false)
     ,m_bInSignatureValue(false)
@@ -23,6 +24,7 @@ OOXMLSecParser::OOXMLSecParser(XSecController* pXSecController)
     ,m_bInX509SerialNumber(false)
     ,m_bInCertDigest(false)
     ,m_bReferenceUnresolved(false)
+    ,m_rXMLSignatureHelper(rXMLSignatureHelper)
 {
 }
 
@@ -50,6 +52,7 @@ void SAL_CALL OOXMLSecParser::startElement(const OUString& rName, const uno::Ref
 
     if (rName == "Signature")
     {
+        m_rXMLSignatureHelper.StartVerifySignatureElement();
         m_pXSecController->addSignature();
         if (!aId.isEmpty())
             m_pXSecController->setId(aId);
diff --git a/xmlsecurity/source/helper/ooxmlsecparser.hxx b/xmlsecurity/source/helper/ooxmlsecparser.hxx
index 068ffb22a930..bcaa581e4226 100644
--- a/xmlsecurity/source/helper/ooxmlsecparser.hxx
+++ b/xmlsecurity/source/helper/ooxmlsecparser.hxx
@@ -50,9 +50,10 @@ class OOXMLSecParser: public cppu::WeakImplHelper
     OUString m_aReferenceURI;
     /// Already called addStreamReference() for this reference.
     bool m_bReferenceUnresolved;
+    XMLSignatureHelper& m_rXMLSignatureHelper;
 
 public:
-    explicit OOXMLSecParser(XSecController* pXSecController);
+    explicit OOXMLSecParser(XMLSignatureHelper& rXMLSignatureHelper, XSecController* pXSecController);
     virtual ~OOXMLSecParser() override;
 
     // XDocumentHandler
diff --git a/xmlsecurity/source/helper/xmlsignaturehelper.cxx b/xmlsecurity/source/helper/xmlsignaturehelper.cxx
index cc14bb3c01d0..2de0839d4b82 100644
--- a/xmlsecurity/source/helper/xmlsignaturehelper.cxx
+++ b/xmlsecurity/source/helper/xmlsignaturehelper.cxx
@@ -244,23 +244,13 @@ bool XMLSignatureHelper::ReadAndVerifySignature( const css::uno::Reference< css:
      * create a signature reader
      */
     uno::Reference< xml::sax::XDocumentHandler > xHandler
-        = mpXSecController->createSignatureReader( );
-
-    /*
-     * create a signature listener
-     */
-    ImplXMLSignatureListener* pSignatureListener = new ImplXMLSignatureListener(*this);
-
-    /*
-     * configure the signature verify listener
-     */
+        = mpXSecController->createSignatureReader(*this);
 
     /*
      * setup the connection:
-     * Parser -> SignatureListener -> SignatureReader
+     * Parser -> SignatureReader
      */
-    pSignatureListener->setNextHandler(xHandler);
-    xParser->setDocumentHandler( pSignatureListener );
+    xParser->setDocumentHandler( xHandler );
 
     /*
      * parser the stream
@@ -275,15 +265,6 @@ bool XMLSignatureHelper::ReadAndVerifySignature( const css::uno::Reference< css:
     }
 
     /*
-     * clear up the connection
-     */
-    pSignatureListener->setNextHandler( nullptr );
-
-    /*
-     * clear up the signature verify listener
-     */
-
-    /*
      * release the signature reader
      */
     mpXSecController->releaseSignatureReader( );
@@ -409,15 +390,10 @@ bool XMLSignatureHelper::ReadAndVerifySignatureStorageStream(const css::uno::Ref
     uno::Reference<xml::sax::XParser> xParser = xml::sax::Parser::create(mxCtx);
 
     // Create the signature reader.
-    uno::Reference<xml::sax::XDocumentHandler> xHandler = mpXSecController->createSignatureReader(embed::StorageFormats::OFOPXML);
-
-    // Create the signature listener.
-    ImplXMLSignatureListener* pSignatureListener = new ImplXMLSignatureListener(*this);
-    uno::Reference<xml::sax::XDocumentHandler> xSignatureListener(pSignatureListener);
+    uno::Reference<xml::sax::XDocumentHandler> xHandler = mpXSecController->createSignatureReader(*this, embed::StorageFormats::OFOPXML);
 
-    // Parser -> signature listener -> signature reader.
-    pSignatureListener->setNextHandler(xHandler);
-    xParser->setDocumentHandler(xSignatureListener);
+    // Parser -> signature reader.
+    xParser->setDocumentHandler(xHandler);
 
     // Parse the stream.
     try
@@ -429,7 +405,6 @@ bool XMLSignatureHelper::ReadAndVerifySignatureStorageStream(const css::uno::Ref
         SAL_WARN("xmlsecurity.helper", "XMLSignatureHelper::ReadAndVerifySignatureStorageStream: " << rException.Message);
     }
 
-    pSignatureListener->setNextHandler(nullptr);
     mpXSecController->releaseSignatureReader();
 
     return !mbError;
diff --git a/xmlsecurity/source/helper/xmlsignaturehelper2.cxx b/xmlsecurity/source/helper/xmlsignaturehelper2.cxx
index aa8ac7b4515d..d63052996763 100644
--- a/xmlsecurity/source/helper/xmlsignaturehelper2.cxx
+++ b/xmlsecurity/source/helper/xmlsignaturehelper2.cxx
@@ -32,91 +32,6 @@
 
 using namespace com::sun::star;
 
-ImplXMLSignatureListener::ImplXMLSignatureListener(XMLSignatureHelper& rXMLSignatureHelper)
-    : m_rXMLSignatureHelper(rXMLSignatureHelper)
-{
-}
-
-ImplXMLSignatureListener::~ImplXMLSignatureListener()
-{
-}
-
-void ImplXMLSignatureListener::setNextHandler(
-    const uno::Reference< xml::sax::XDocumentHandler >& xNextHandler)
-{
-    m_xNextHandler = xNextHandler;
-}
-
-// XDocumentHandler
-void SAL_CALL ImplXMLSignatureListener::startDocument(  )
-{
-    if (m_xNextHandler.is())
-    {
-        m_xNextHandler->startDocument();
-    }
-}
-
-void SAL_CALL ImplXMLSignatureListener::endDocument(  )
-{
-    if (m_xNextHandler.is())
-    {
-        m_xNextHandler->endDocument();
-    }
-}
-
-void SAL_CALL ImplXMLSignatureListener::startElement( const OUString& aName, const css::uno::Reference< css::xml::sax::XAttributeList >& xAttribs )
-{
-    if ( aName == "Signature" )
-    {
-        m_rXMLSignatureHelper.StartVerifySignatureElement();
-    }
-
-    if (m_xNextHandler.is())
-    {
-        m_xNextHandler->startElement( aName, xAttribs );
-    }
-}
-
-void SAL_CALL ImplXMLSignatureListener::endElement( const OUString& aName )
-{
-    if (m_xNextHandler.is())
-    {
-        m_xNextHandler->endElement( aName );
-    }
-}
-
-void SAL_CALL ImplXMLSignatureListener::characters( const OUString& aChars )
-{
-    if (m_xNextHandler.is())
-    {
-        m_xNextHandler->characters( aChars );
-    }
-}
-
-void SAL_CALL ImplXMLSignatureListener::ignorableWhitespace( const OUString& aWhitespaces )
-{
-    if (m_xNextHandler.is())
-    {
-        m_xNextHandler->ignorableWhitespace( aWhitespaces );
-    }
-}
-
-void SAL_CALL ImplXMLSignatureListener::processingInstruction( const OUString& aTarget, const OUString& aData )
-{
-    if (m_xNextHandler.is())
-    {
-        m_xNextHandler->processingInstruction( aTarget, aData );
-    }
-}
-
-void SAL_CALL ImplXMLSignatureListener::setDocumentLocator( const css::uno::Reference< css::xml::sax::XLocator >& xLocator )
-{
-    if (m_xNextHandler.is())
-    {
-        m_xNextHandler->setDocumentLocator( xLocator );
-    }
-}
-
 // XUriBinding
 
 UriBindingHelper::UriBindingHelper()
diff --git a/xmlsecurity/source/helper/xmlsignaturehelper2.hxx b/xmlsecurity/source/helper/xmlsignaturehelper2.hxx
index d460c292c137..1b62f601e509 100644
--- a/xmlsecurity/source/helper/xmlsignaturehelper2.hxx
+++ b/xmlsecurity/source/helper/xmlsignaturehelper2.hxx
@@ -36,47 +36,6 @@ namespace embed {
     class XStorage; }
 }}}
 
-// MT: Not needed any more, remove later...
-
-// FIXME: I certainly would love to remove as much as possible of this steaming pile of
-// over-engineering, but I wonder what exactly the above comment means. Certainly it is not
-// straightforward to remove this class, it is used.
-
-class ImplXMLSignatureListener : public cppu::WeakImplHelper
-<
-    css::xml::sax::XDocumentHandler
->
-{
-private:
-    XMLSignatureHelper& m_rXMLSignatureHelper;
-
-    css::uno::Reference<
-        css::xml::sax::XDocumentHandler > m_xNextHandler;
-
-public:
-    ImplXMLSignatureListener(XMLSignatureHelper& rXMLSignatureHelper);
-    virtual ~ImplXMLSignatureListener() override;
-
-    void setNextHandler(const css::uno::Reference< css::xml::sax::XDocumentHandler >& xNextHandler);
-
-    // css::xml::sax::XDocumentHandler
-    virtual void SAL_CALL startElement( const OUString& aName, const css::uno::Reference< css::xml::sax::XAttributeList >& xAttribs ) override;
-
-    virtual void SAL_CALL startDocument(  ) override;
-
-    virtual void SAL_CALL endDocument(  ) override;
-
-    virtual void SAL_CALL endElement( const OUString& aName ) override;
-
-    virtual void SAL_CALL characters( const OUString& aChars ) override;
-
-    virtual void SAL_CALL ignorableWhitespace( const OUString& aWhitespaces ) override;
-
-    virtual void SAL_CALL processingInstruction( const OUString& aTarget, const OUString& aData ) override;
-
-    virtual void SAL_CALL setDocumentLocator( const css::uno::Reference< css::xml::sax::XLocator >& xLocator ) override;
-};
-
 // XUriBinding
 
 class UriBindingHelper : public cppu::WeakImplHelper< css::xml::crypto::XUriBinding >
diff --git a/xmlsecurity/source/helper/xsecparser.cxx b/xmlsecurity/source/helper/xsecparser.cxx
index 7c09d731ab0a..6e6bfc45c426 100644
--- a/xmlsecurity/source/helper/xsecparser.cxx
+++ b/xmlsecurity/source/helper/xsecparser.cxx
@@ -19,6 +19,7 @@
 
 
 #include "xsecparser.hxx"
+#include "xmlsignaturehelper.hxx"
 #include <com/sun/star/xml/sax/SAXException.hpp>
 #include <cppuhelper/exc_hlp.hxx>
 
@@ -28,7 +29,8 @@ namespace cssu = com::sun::star::uno;
 namespace cssxc = com::sun::star::xml::crypto;
 namespace cssxs = com::sun::star::xml::sax;
 
-XSecParser::XSecParser(XSecController* pXSecController,
+XSecParser::XSecParser(XMLSignatureHelper& rXMLSignatureHelper,
+    XSecController* pXSecController,
     const cssu::Reference< cssxs::XDocumentHandler >& xNextHandler)
     : m_bInX509IssuerName(false)
     , m_bInX509SerialNumber(false)
@@ -44,6 +46,7 @@ XSecParser::XSecParser(XSecController* pXSecController,
     , m_xNextHandler(xNextHandler)
     , m_bReferenceUnresolved(false)
     , m_nReferenceDigestID(cssxc::DigestID::SHA1)
+    , m_rXMLSignatureHelper(rXMLSignatureHelper)
 {
 }
 
@@ -100,6 +103,7 @@ void SAL_CALL XSecParser::startElement(
 
         if ( aName == "Signature" )
         {
+            m_rXMLSignatureHelper.StartVerifySignatureElement();
             m_pXSecController->addSignature();
             if (!ouIdAttr.isEmpty())
             {
diff --git a/xmlsecurity/source/helper/xsecparser.hxx b/xmlsecurity/source/helper/xsecparser.hxx
index 9c4503b7ea39..1fc01b74123e 100644
--- a/xmlsecurity/source/helper/xsecparser.hxx
+++ b/xmlsecurity/source/helper/xsecparser.hxx
@@ -103,13 +103,14 @@ private:
     // Relevant for ODF. The digest algorithm selected by the current DigestMethod element's
     // Algorithm attribute in the current Reference element. From css::xml::crypto::DigestID.
     sal_Int32 m_nReferenceDigestID;
+    XMLSignatureHelper& m_rXMLSignatureHelper;
 
 private:
     static OUString getIdAttr(const css::uno::Reference<
             css::xml::sax::XAttributeList >& xAttribs );
 
 public:
-    XSecParser( XSecController* pXSecController,
+    XSecParser(XMLSignatureHelper& rXMLSignatureHelper, XSecController* pXSecController,
         const css::uno::Reference<
             css::xml::sax::XDocumentHandler >& xNextHandler );
 
diff --git a/xmlsecurity/source/helper/xsecverify.cxx b/xmlsecurity/source/helper/xsecverify.cxx
index d5eab0e1a630..41d628fcb5a1 100644
--- a/xmlsecurity/source/helper/xsecverify.cxx
+++ b/xmlsecurity/source/helper/xsecverify.cxx
@@ -400,12 +400,12 @@ void XSecController::addSignature( sal_Int32 nSignatureId )
     m_bVerifyCurrentSignature = true;
 }
 
-cssu::Reference< cssxs::XDocumentHandler > const & XSecController::createSignatureReader(sal_Int32 nType)
+cssu::Reference< cssxs::XDocumentHandler > const & XSecController::createSignatureReader(XMLSignatureHelper& rXMLSignatureHelper, sal_Int32 nType)
 {
     if (nType == embed::StorageFormats::OFOPXML)
-        m_xSecParser = new OOXMLSecParser(this);
+        m_xSecParser = new OOXMLSecParser(rXMLSignatureHelper, this);
     else
-        m_xSecParser = new XSecParser( this, nullptr );
+        m_xSecParser = new XSecParser(rXMLSignatureHelper, this, nullptr);
     cssu::Reference< cssl::XInitialization > xInitialization(m_xSecParser, uno::UNO_QUERY);
 
     setSAXChainConnector(xInitialization, nullptr, nullptr);


More information about the Libreoffice-commits mailing list