[Libreoffice-commits] core.git: 4 commits - xmlsecurity/Library_xmlsecurity.mk xmlsecurity/source

Miklos Vajna vmiklos at collabora.co.uk
Wed Jan 13 06:24:35 PST 2016


 xmlsecurity/Library_xmlsecurity.mk               |    1 
 xmlsecurity/source/helper/ooxmlsecparser.cxx     |   86 +++++++++++++++++++++++
 xmlsecurity/source/helper/ooxmlsecparser.hxx     |   60 ++++++++++++++++
 xmlsecurity/source/helper/xmlsignaturehelper.cxx |    3 
 xmlsecurity/source/helper/xsecctl.hxx            |    3 
 xmlsecurity/source/helper/xsecverify.cxx         |    9 +-
 6 files changed, 158 insertions(+), 4 deletions(-)

New commits:
commit a6d1b4b17a74bd2af03cd090b80c98bc9a275aa3
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Wed Jan 13 15:24:04 2016 +0100

    xmlsecurity: import OOXML <Reference>
    
    Only non-stream ones as a start.
    
    Change-Id: Ifacf391e78463004c17106905019ec2ed3430efe

diff --git a/xmlsecurity/source/helper/ooxmlsecparser.cxx b/xmlsecurity/source/helper/ooxmlsecparser.cxx
index a070e8f..6f71a39 100644
--- a/xmlsecurity/source/helper/ooxmlsecparser.cxx
+++ b/xmlsecurity/source/helper/ooxmlsecparser.cxx
@@ -42,12 +42,25 @@ throw (xml::sax::SAXException, uno::RuntimeException, std::exception)
         if (!aId.isEmpty())
             m_pXSecController->setId(aId);
     }
+    else if (rName == "Reference")
+    {
+        OUString aURI = xAttribs->getValueByName("URI");
+        if (aURI.startsWith("#"))
+            m_pXSecController->addReference(aURI.copy(1));
+        // TODO else
+    }
 }
 
 void SAL_CALL OOXMLSecParser::endElement(const OUString& rName) throw (xml::sax::SAXException, uno::RuntimeException, std::exception)
 {
     if (rName == "SignedInfo")
         m_pXSecController->setReferenceCount();
+    else if (rName == "Reference")
+    {
+        // TODO import digest value
+        OUString aDigestValue;
+        m_pXSecController->setDigestValue(aDigestValue);
+    }
 }
 
 void SAL_CALL OOXMLSecParser::characters(const OUString& /*rChars*/) throw (xml::sax::SAXException, uno::RuntimeException, std::exception)
commit 143f310f1c699de9ea3f146c2cc7c1cf21493f79
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Wed Jan 13 11:25:12 2016 +0100

    xmlsecurity: import OOXML <SignedInfo>
    
    Change-Id: I5591b33b41fdfe2e84a6462d0d2db5304cb909cb

diff --git a/xmlsecurity/source/helper/ooxmlsecparser.cxx b/xmlsecurity/source/helper/ooxmlsecparser.cxx
index d08073e..a070e8f 100644
--- a/xmlsecurity/source/helper/ooxmlsecparser.cxx
+++ b/xmlsecurity/source/helper/ooxmlsecparser.cxx
@@ -44,8 +44,10 @@ throw (xml::sax::SAXException, uno::RuntimeException, std::exception)
     }
 }
 
-void SAL_CALL OOXMLSecParser::endElement(const OUString& /*rName*/) throw (xml::sax::SAXException, uno::RuntimeException, std::exception)
+void SAL_CALL OOXMLSecParser::endElement(const OUString& rName) throw (xml::sax::SAXException, uno::RuntimeException, std::exception)
 {
+    if (rName == "SignedInfo")
+        m_pXSecController->setReferenceCount();
 }
 
 void SAL_CALL OOXMLSecParser::characters(const OUString& /*rChars*/) throw (xml::sax::SAXException, uno::RuntimeException, std::exception)
commit aac43335e2acdba57e3bb5567decb157f2d0bda4
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Wed Jan 13 11:22:07 2016 +0100

    xmlsecurity: import OOXML <Signature>
    
    Change-Id: I5925440347c04b2fff243261ba677c718d8fc312

diff --git a/xmlsecurity/source/helper/ooxmlsecparser.cxx b/xmlsecurity/source/helper/ooxmlsecparser.cxx
index 671a680..d08073e 100644
--- a/xmlsecurity/source/helper/ooxmlsecparser.cxx
+++ b/xmlsecurity/source/helper/ooxmlsecparser.cxx
@@ -29,9 +29,19 @@ void SAL_CALL OOXMLSecParser::endDocument() throw (xml::sax::SAXException, uno::
 {
 }
 
-void SAL_CALL OOXMLSecParser::startElement(const OUString& /*rName*/, const uno::Reference<xml::sax::XAttributeList>& /*xAttribs*/)
+void SAL_CALL OOXMLSecParser::startElement(const OUString& rName, const uno::Reference<xml::sax::XAttributeList>& xAttribs)
 throw (xml::sax::SAXException, uno::RuntimeException, std::exception)
 {
+    OUString aId = xAttribs->getValueByName("Id");
+    if (!aId.isEmpty())
+        m_pXSecController->collectToVerify(aId);
+
+    if (rName == "Signature")
+    {
+        //m_pXSecController->addSignature();
+        if (!aId.isEmpty())
+            m_pXSecController->setId(aId);
+    }
 }
 
 void SAL_CALL OOXMLSecParser::endElement(const OUString& /*rName*/) throw (xml::sax::SAXException, uno::RuntimeException, std::exception)
diff --git a/xmlsecurity/source/helper/xsecctl.hxx b/xmlsecurity/source/helper/xsecctl.hxx
index 8e9d1f9..b48b8cd 100644
--- a/xmlsecurity/source/helper/xsecctl.hxx
+++ b/xmlsecurity/source/helper/xsecctl.hxx
@@ -166,6 +166,7 @@ class XSecController : public cppu::WeakImplHelper
  ******************************************************************************/
 {
     friend class XSecParser;
+    friend class OOXMLSecParser;
 
 private:
     com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext> mxCtx;
commit 829e236d39707437475b7d7fd599a385ed3cf5e4
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Tue Jan 12 18:54:29 2016 +0100

    xmlsecurity: initial OOXMLSecParser
    
    Change-Id: Idba2eb384756e72c8b60cb2e810110d6b95b66ad

diff --git a/xmlsecurity/Library_xmlsecurity.mk b/xmlsecurity/Library_xmlsecurity.mk
index 7ba5b46..ecbade5 100644
--- a/xmlsecurity/Library_xmlsecurity.mk
+++ b/xmlsecurity/Library_xmlsecurity.mk
@@ -54,6 +54,7 @@ $(eval $(call gb_Library_add_exception_objects,xmlsecurity,\
 	xmlsecurity/source/dialogs/macrosecurity \
 	xmlsecurity/source/dialogs/resourcemanager \
 	xmlsecurity/source/helper/documentsignaturehelper \
+	xmlsecurity/source/helper/ooxmlsecparser \
 	xmlsecurity/source/helper/xmlsignaturehelper2 \
 	xmlsecurity/source/helper/xmlsignaturehelper \
 	xmlsecurity/source/helper/xsecctl \
diff --git a/xmlsecurity/source/helper/ooxmlsecparser.cxx b/xmlsecurity/source/helper/ooxmlsecparser.cxx
new file mode 100644
index 0000000..671a680
--- /dev/null
+++ b/xmlsecurity/source/helper/ooxmlsecparser.cxx
@@ -0,0 +1,61 @@
+/* -*- 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/.
+ */
+
+
+#include "ooxmlsecparser.hxx"
+
+using namespace com::sun::star;
+
+OOXMLSecParser::OOXMLSecParser(XSecController* pXSecController)
+    : m_pXSecController(pXSecController)
+{
+}
+
+OOXMLSecParser::~OOXMLSecParser()
+{
+}
+
+void SAL_CALL OOXMLSecParser::startDocument() throw (xml::sax::SAXException, uno::RuntimeException, std::exception)
+{
+}
+
+void SAL_CALL OOXMLSecParser::endDocument() throw (xml::sax::SAXException, uno::RuntimeException, std::exception)
+{
+}
+
+void SAL_CALL OOXMLSecParser::startElement(const OUString& /*rName*/, const uno::Reference<xml::sax::XAttributeList>& /*xAttribs*/)
+throw (xml::sax::SAXException, uno::RuntimeException, std::exception)
+{
+}
+
+void SAL_CALL OOXMLSecParser::endElement(const OUString& /*rName*/) throw (xml::sax::SAXException, uno::RuntimeException, std::exception)
+{
+}
+
+void SAL_CALL OOXMLSecParser::characters(const OUString& /*rChars*/) throw (xml::sax::SAXException, uno::RuntimeException, std::exception)
+{
+}
+
+void SAL_CALL OOXMLSecParser::ignorableWhitespace(const OUString& /*rWhitespace*/) throw (xml::sax::SAXException, uno::RuntimeException, std::exception)
+{
+}
+
+void SAL_CALL OOXMLSecParser::processingInstruction(const OUString& /*rTarget*/, const OUString& /*rData*/) throw (xml::sax::SAXException, uno::RuntimeException, std::exception)
+{
+}
+
+void SAL_CALL OOXMLSecParser::setDocumentLocator(const uno::Reference<xml::sax::XLocator>& /*xLocator*/) throw (xml::sax::SAXException, uno::RuntimeException, std::exception)
+{
+}
+
+void SAL_CALL OOXMLSecParser::initialize(const uno::Sequence<uno::Any>& /*rArguments*/) throw (uno::Exception, uno::RuntimeException, std::exception)
+{
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/xmlsecurity/source/helper/ooxmlsecparser.hxx b/xmlsecurity/source/helper/ooxmlsecparser.hxx
new file mode 100644
index 0000000..84ce2fc
--- /dev/null
+++ b/xmlsecurity/source/helper/ooxmlsecparser.hxx
@@ -0,0 +1,60 @@
+/* -*- 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_HELPER_OOXMLSECPARSER_HXX
+#define INCLUDED_XMLSECURITY_SOURCE_HELPER_OOXMLSECPARSER_HXX
+
+#include <com/sun/star/xml/sax/XParser.hpp>
+#include <com/sun/star/lang/XInitialization.hpp>
+#include <com/sun/star/xml/sax/XDocumentHandler.hpp>
+#include <com/sun/star/xml/sax/XAttributeList.hpp>
+
+#include <cppuhelper/implbase.hxx>
+
+#include "xsecctl.hxx"
+
+/// Parses an OOXML digital signature.
+class OOXMLSecParser: public cppu::WeakImplHelper
+    <
+    css::xml::sax::XDocumentHandler,
+    css::lang::XInitialization
+    >
+{
+    XSecController* m_pXSecController;
+
+public:
+    OOXMLSecParser(XSecController* pXSecController);
+    virtual ~OOXMLSecParser();
+
+    // XDocumentHandler
+    virtual void SAL_CALL startDocument() throw (css::xml::sax::SAXException, css::uno::RuntimeException, std::exception) override;
+
+    virtual void SAL_CALL endDocument() throw (css::xml::sax::SAXException, css::uno::RuntimeException, std::exception) override;
+
+    virtual void SAL_CALL startElement(const OUString& aName, const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs)
+    throw (css::xml::sax::SAXException, css::uno::RuntimeException, std::exception) override;
+
+    virtual void SAL_CALL endElement(const OUString& aName) throw (css::xml::sax::SAXException, css::uno::RuntimeException, std::exception) override;
+
+    virtual void SAL_CALL characters(const OUString& aChars) throw (css::xml::sax::SAXException, css::uno::RuntimeException, std::exception) override;
+
+    virtual void SAL_CALL ignorableWhitespace(const OUString& aWhitespaces) throw (css::xml::sax::SAXException, css::uno::RuntimeException, std::exception) override;
+
+    virtual void SAL_CALL processingInstruction(const OUString& aTarget, const OUString& aData) throw (css::xml::sax::SAXException, css::uno::RuntimeException, std::exception) override;
+
+    virtual void SAL_CALL setDocumentLocator(const css::uno::Reference<css::xml::sax::XLocator>& xLocator)
+    throw (css::xml::sax::SAXException, css::uno::RuntimeException, std::exception) override;
+
+    // XInitialization
+    virtual void SAL_CALL initialize(const css::uno::Sequence<css::uno::Any>& rArguments) throw (css::uno::Exception, css::uno::RuntimeException, std::exception) override;
+};
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/xmlsecurity/source/helper/xmlsignaturehelper.cxx b/xmlsecurity/source/helper/xmlsignaturehelper.cxx
index 95f26e3..e2f60f5 100644
--- a/xmlsecurity/source/helper/xmlsignaturehelper.cxx
+++ b/xmlsecurity/source/helper/xmlsignaturehelper.cxx
@@ -41,6 +41,7 @@
 #include <com/sun/star/xml/crypto/SEInitializer.hpp>
 #include <com/sun/star/embed/ElementModes.hpp>
 #include <com/sun/star/embed/XStorage.hpp>
+#include <com/sun/star/embed/StorageFormats.hpp>
 
 #include <tools/date.hxx>
 #include <tools/time.hxx>
@@ -390,7 +391,7 @@ 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();
+    uno::Reference<xml::sax::XDocumentHandler> xHandler = mpXSecController->createSignatureReader(embed::StorageFormats::OFOPXML);
 
     // Create the signature listener.
     ImplXMLSignatureListener* pSignatureListener = new ImplXMLSignatureListener(
diff --git a/xmlsecurity/source/helper/xsecctl.hxx b/xmlsecurity/source/helper/xsecctl.hxx
index 734ecdb..8e9d1f9 100644
--- a/xmlsecurity/source/helper/xsecctl.hxx
+++ b/xmlsecurity/source/helper/xsecctl.hxx
@@ -463,7 +463,7 @@ public:
      */
     void collectToVerify( const OUString& referenceId );
     void addSignature( sal_Int32 nSignatureId );
-    com::sun::star::uno::Reference< com::sun::star::xml::sax::XDocumentHandler > createSignatureReader();
+    com::sun::star::uno::Reference< com::sun::star::xml::sax::XDocumentHandler > createSignatureReader(sal_Int32 nType = 0);
     void releaseSignatureReader();
 
 public:
diff --git a/xmlsecurity/source/helper/xsecverify.cxx b/xmlsecurity/source/helper/xsecverify.cxx
index ba89bad..856fdf7 100644
--- a/xmlsecurity/source/helper/xsecverify.cxx
+++ b/xmlsecurity/source/helper/xsecverify.cxx
@@ -20,6 +20,7 @@
 
 #include "xsecctl.hxx"
 #include "xsecparser.hxx"
+#include "ooxmlsecparser.hxx"
 #include <tools/debug.hxx>
 
 #include <com/sun/star/xml/crypto/sax/XKeyCollector.hpp>
@@ -28,6 +29,7 @@
 #include <com/sun/star/xml/crypto/sax/XReferenceCollector.hpp>
 #include <com/sun/star/xml/crypto/sax/XSignatureVerifyResultBroadcaster.hpp>
 #include <com/sun/star/xml/sax/SAXParseException.hpp>
+#include <com/sun/star/embed/StorageFormats.hpp>
 #include <sal/log.hxx>
 #include <unotools/datetime.hxx>
 
@@ -378,9 +380,12 @@ void XSecController::addSignature( sal_Int32 nSignatureId )
     m_bVerifyCurrentSignature = true;
 }
 
-cssu::Reference< cssxs::XDocumentHandler > XSecController::createSignatureReader()
+cssu::Reference< cssxs::XDocumentHandler > XSecController::createSignatureReader(sal_Int32 nType)
 {
-    m_xSecParser = new XSecParser( this, nullptr );
+    if (nType == embed::StorageFormats::OFOPXML)
+        m_xSecParser = new OOXMLSecParser(this);
+    else
+        m_xSecParser = new XSecParser( this, nullptr );
     cssu::Reference< cssl::XInitialization > xInitialization(m_xSecParser, uno::UNO_QUERY);
 
     setSAXChainConnector(xInitialization, nullptr, nullptr);


More information about the Libreoffice-commits mailing list