[Libreoffice-commits] core.git: 3 commits - xmlsecurity/CppunitTest_xmlsecurity_signing.mk xmlsecurity/qa xmlsecurity/source

Miklos Vajna vmiklos at collabora.co.uk
Thu Feb 4 09:04:57 UTC 2016


 xmlsecurity/CppunitTest_xmlsecurity_signing.mk         |    1 
 xmlsecurity/qa/unit/signing/data/bad.docx              |binary
 xmlsecurity/qa/unit/signing/data/partial.docx          |binary
 xmlsecurity/qa/unit/signing/signing.cxx                |   41 ++++++++++++-
 xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx |   50 +++++++++--------
 5 files changed, 68 insertions(+), 24 deletions(-)

New commits:
commit d165f035d2155da47b99a8035707c392d0627382
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Thu Feb 4 09:39:32 2016 +0100

    CppunitTest_xmlsecurity_signing: add invalid OOXML testcase
    
    Test the case when the manifest reference has invalid hash: this is the
    more complex situation. A simple situation is when a direct
    (non-manifest) reference is broken.
    
    Change-Id: Iaea139abc460050768cfbc236cacb1fd94418b36

diff --git a/xmlsecurity/qa/unit/signing/data/bad.docx b/xmlsecurity/qa/unit/signing/data/bad.docx
new file mode 100644
index 0000000..86d0eda
Binary files /dev/null and b/xmlsecurity/qa/unit/signing/data/bad.docx differ
diff --git a/xmlsecurity/qa/unit/signing/signing.cxx b/xmlsecurity/qa/unit/signing/signing.cxx
index 771475d..7d85750 100644
--- a/xmlsecurity/qa/unit/signing/signing.cxx
+++ b/xmlsecurity/qa/unit/signing/signing.cxx
@@ -55,10 +55,13 @@ public:
     void testDescription();
     /// Test a typical OOXML where a number of (but not all) streams are signed.
     void testOOXMLPartial();
+    /// Test a typical broken OOXML signature where one stream is corrupted.
+    void testOOXMLBroken();
 
     CPPUNIT_TEST_SUITE(SigningTest);
     CPPUNIT_TEST(testDescription);
     CPPUNIT_TEST(testOOXMLPartial);
+    CPPUNIT_TEST(testOOXMLBroken);
     CPPUNIT_TEST_SUITE_END();
 
 private:
@@ -206,6 +209,17 @@ void SigningTest::testOOXMLPartial()
     CPPUNIT_ASSERT(nActual == static_cast<int>(SignatureState::NOTVALIDATED) || nActual == static_cast<int>(SignatureState::PARTIAL_OK));
 }
 
+void SigningTest::testOOXMLBroken()
+{
+    createDoc(getURLFromSrc(DATA_DIRECTORY) + "bad.docx");
+    SfxBaseModel* pBaseModel = dynamic_cast<SfxBaseModel*>(mxComponent.get());
+    CPPUNIT_ASSERT(pBaseModel);
+    SfxObjectShell* pObjectShell = pBaseModel->GetObjectShell();
+    CPPUNIT_ASSERT(pObjectShell);
+    // This was SignatureState::NOTVALIDATED/PARTIAL_OK as we did not validate manifest references.
+    CPPUNIT_ASSERT_EQUAL(static_cast<int>(SignatureState::BROKEN), static_cast<int>(pObjectShell->GetDocumentSignatureState()));
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(SigningTest);
 
 CPPUNIT_PLUGIN_IMPLEMENT();
commit 50d4306476874b5d279e4e9f4f21ba473405da6b
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Thu Feb 4 09:31:16 2016 +0100

    CppunitTest_xmlsecurity_signing: add valid OOXML testcase
    
    In reality we can't detect that it's partially signed, as the unit test
    doesn't have a mozilla profile -> certificate validation fails -> we
    only know that the signature is valid.
    
    Change-Id: Ib6aaccb4cb471e543d368d0318b90c67e9876619

diff --git a/xmlsecurity/CppunitTest_xmlsecurity_signing.mk b/xmlsecurity/CppunitTest_xmlsecurity_signing.mk
index f7739ef..e22a2ca 100644
--- a/xmlsecurity/CppunitTest_xmlsecurity_signing.mk
+++ b/xmlsecurity/CppunitTest_xmlsecurity_signing.mk
@@ -21,6 +21,7 @@ $(eval $(call gb_CppunitTest_use_libraries,xmlsecurity_signing, \
 	cppu \
 	sal \
 	sax \
+	sfx \
 	test \
 	tl \
 	unotest \
diff --git a/xmlsecurity/qa/unit/signing/data/partial.docx b/xmlsecurity/qa/unit/signing/data/partial.docx
new file mode 100644
index 0000000..3d6ca46
Binary files /dev/null and b/xmlsecurity/qa/unit/signing/data/partial.docx differ
diff --git a/xmlsecurity/qa/unit/signing/signing.cxx b/xmlsecurity/qa/unit/signing/signing.cxx
index c68a872..771475d 100644
--- a/xmlsecurity/qa/unit/signing/signing.cxx
+++ b/xmlsecurity/qa/unit/signing/signing.cxx
@@ -28,6 +28,8 @@
 #include <comphelper/storagehelper.hxx>
 #include <tools/date.hxx>
 #include <tools/time.hxx>
+#include <sfx2/sfxbasemodel.hxx>
+#include <sfx2/objsh.hxx>
 
 #include <xmlsecurity/documentsignaturehelper.hxx>
 #include <xmlsecurity/xmlsignaturehelper.hxx>
@@ -51,13 +53,16 @@ public:
     virtual void tearDown() override;
 
     void testDescription();
+    /// Test a typical OOXML where a number of (but not all) streams are signed.
+    void testOOXMLPartial();
 
     CPPUNIT_TEST_SUITE(SigningTest);
     CPPUNIT_TEST(testDescription);
+    CPPUNIT_TEST(testOOXMLPartial);
     CPPUNIT_TEST_SUITE_END();
 
 private:
-    void createDoc();
+    void createDoc(const OUString& rURL = OUString());
     uno::Reference<security::XCertificate> getCertificate(XMLSignatureHelper& rSignatureHelper);
     void sign(utl::TempFile& rTempFile, XMLSignatureHelper& rSignatureHelper, const uno::Reference<io::XOutputStream>& xOutputStream);
     std::vector<SignatureInformation> verify(XMLSignatureHelper& rSignatureHelper, const uno::Reference<io::XInputStream>& xInputStream);
@@ -83,11 +88,14 @@ void SigningTest::tearDown()
     test::BootstrapFixture::tearDown();
 }
 
-void SigningTest::createDoc()
+void SigningTest::createDoc(const OUString& rURL)
 {
     if (mxComponent.is())
         mxComponent->dispose();
-    mxComponent = loadFromDesktop("private:factory/swriter", "com.sun.star.text.TextDocument");
+    if (rURL.isEmpty())
+        mxComponent = loadFromDesktop("private:factory/swriter", "com.sun.star.text.TextDocument");
+    else
+        mxComponent = loadFromDesktop(rURL, "com.sun.star.text.TextDocument");
 }
 
 uno::Reference<security::XCertificate> SigningTest::getCertificate(XMLSignatureHelper& rSignatureHelper)
@@ -185,6 +193,19 @@ void SigningTest::testDescription()
     CPPUNIT_ASSERT_EQUAL(OUString("SigningTest::sign"), aSignatureInformations[0].ouDescription);
 }
 
+void SigningTest::testOOXMLPartial()
+{
+    createDoc(getURLFromSrc(DATA_DIRECTORY) + "partial.docx");
+    SfxBaseModel* pBaseModel = dynamic_cast<SfxBaseModel*>(mxComponent.get());
+    CPPUNIT_ASSERT(pBaseModel);
+    SfxObjectShell* pObjectShell = pBaseModel->GetObjectShell();
+    CPPUNIT_ASSERT(pObjectShell);
+    // This was SignatureState::BROKEN due to missing RelationshipTransform and SHA-256 support.
+    // We expect NOTVALIDATED in case the root CA is not imported on the system, and PARTIAL_OK otherwise, so accept both.
+    int nActual = static_cast<int>(pObjectShell->GetDocumentSignatureState());
+    CPPUNIT_ASSERT(nActual == static_cast<int>(SignatureState::NOTVALIDATED) || nActual == static_cast<int>(SignatureState::PARTIAL_OK));
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(SigningTest);
 
 CPPUNIT_PLUGIN_IMPLEMENT();
commit c0870b2a15cde89d9f64803828bbfbf458eed918
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Thu Feb 4 09:29:00 2016 +0100

    xmlsecurity: fix crash on closing DigitalSignaturesDialog without ...
    
    ... a signature stream. ODF has a signature stream, OOXML has a
    signature storage instead.
    
    Code tries to export all signatures on closing the dialog, but OOXML at
    the moment has only an importer; so just fail gracefully in case we only
    have a storage, not a stream.
    
    With this, closing the dialog no longer results in a crash for OOXML
    documents.
    
    Change-Id: I3e6580ddb20ec31fb0c5a4abe1fab3d8046d0ee5

diff --git a/xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx b/xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx
index ea2430b..212dbe7 100644
--- a/xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx
+++ b/xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx
@@ -393,25 +393,30 @@ IMPL_LINK_NOARG_TYPED(DigitalSignaturesDialog, OKButtonHdl, Button*, void)
     // Export all other signatures...
     SignatureStreamHelper aStreamHelper = ImplOpenSignatureStream(
         embed::ElementModes::WRITE|embed::ElementModes::TRUNCATE, false );
-    uno::Reference< io::XOutputStream > xOutputStream(
-        aStreamHelper.xSignatureStream, uno::UNO_QUERY );
-    uno::Reference< com::sun::star::xml::sax::XWriter> xSaxWriter =
-        maSignatureHelper.CreateDocumentHandlerWithHeader( xOutputStream );
 
-    uno::Reference< xml::sax::XDocumentHandler> xDocumentHandler(xSaxWriter, UNO_QUERY_THROW);
-    size_t nInfos = maCurrentSignatureInformations.size();
-    for( size_t n = 0 ; n < nInfos ; ++n )
-        XMLSignatureHelper::ExportSignature(
-        xDocumentHandler, maCurrentSignatureInformations[ n ] );
-
-    XMLSignatureHelper::CloseDocumentHandler( xDocumentHandler);
-
-    // If stream was not provided, we are responsible for committing it....
-    if ( !mxSignatureStream.is() )
+    if (aStreamHelper.xSignatureStream.is())
     {
-        uno::Reference< embed::XTransactedObject > xTrans(
-            aStreamHelper.xSignatureStorage, uno::UNO_QUERY );
-        xTrans->commit();
+        // ODF
+        uno::Reference< io::XOutputStream > xOutputStream(
+            aStreamHelper.xSignatureStream, uno::UNO_QUERY );
+        uno::Reference< com::sun::star::xml::sax::XWriter> xSaxWriter =
+            maSignatureHelper.CreateDocumentHandlerWithHeader( xOutputStream );
+
+        uno::Reference< xml::sax::XDocumentHandler> xDocumentHandler(xSaxWriter, UNO_QUERY_THROW);
+        size_t nInfos = maCurrentSignatureInformations.size();
+        for( size_t n = 0 ; n < nInfos ; ++n )
+            XMLSignatureHelper::ExportSignature(
+            xDocumentHandler, maCurrentSignatureInformations[ n ] );
+
+        XMLSignatureHelper::CloseDocumentHandler( xDocumentHandler);
+
+        // If stream was not provided, we are responsible for committing it....
+        if ( !mxSignatureStream.is() )
+        {
+            uno::Reference< embed::XTransactedObject > xTrans(
+                aStreamHelper.xSignatureStorage, uno::UNO_QUERY );
+            xTrans->commit();
+        }
     }
 
     EndDialog(RET_OK);
@@ -828,10 +833,13 @@ SignatureStreamHelper DigitalSignaturesDialog::ImplOpenSignatureStream(
 
     if (nStreamOpenMode & css::embed::ElementModes::TRUNCATE)
     {
-        css::uno::Reference < css::io::XTruncate > xTruncate(
-            aHelper.xSignatureStream, UNO_QUERY_THROW);
-        DBG_ASSERT( xTruncate.is(), "ImplOpenSignatureStream - Stream does not support xTruncate!" );
-        xTruncate->truncate();
+        if (aHelper.xSignatureStream.is())
+        {
+            css::uno::Reference < css::io::XTruncate > xTruncate(
+                aHelper.xSignatureStream, UNO_QUERY_THROW);
+            DBG_ASSERT( xTruncate.is(), "ImplOpenSignatureStream - Stream does not support xTruncate!" );
+            xTruncate->truncate();
+        }
     }
     else if ( bTempStream || mxSignatureStream.is())
     {


More information about the Libreoffice-commits mailing list