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

Miklos Vajna vmiklos at collabora.co.uk
Wed Feb 10 16:53:34 UTC 2016


 xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx |    4 
 xmlsecurity/source/helper/documentsignaturehelper.cxx  |    4 
 xmlsecurity/source/helper/xsecctl.cxx                  |   98 +++++++++++++++++
 xmlsecurity/source/helper/xsecctl.hxx                  |    3 
 4 files changed, 106 insertions(+), 3 deletions(-)

New commits:
commit 600a7a79ecffc47a68438d308f5829868c2f37e6
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Wed Feb 10 17:34:21 2016 +0100

    xmlsecurity: handle creation of OOXML _xmlsignatures sub-storage
    
    Previously this code worked only for reading, as we assumed if it
    doesn't exist, then the storage is not OOXML, either.
    
    With this, DigitalSignaturesDialog::OKButtonHdl() gets a valid storage,
    where it'll be able to write the actual signatures.
    
    Change-Id: Iadf63a88c962386abc31225c02398761aea818cb

diff --git a/xmlsecurity/source/helper/documentsignaturehelper.cxx b/xmlsecurity/source/helper/documentsignaturehelper.cxx
index 1249a8a..46b270e 100644
--- a/xmlsecurity/source/helper/documentsignaturehelper.cxx
+++ b/xmlsecurity/source/helper/documentsignaturehelper.cxx
@@ -382,7 +382,7 @@ SignatureStreamHelper DocumentSignatureHelper::OpenSignatureStream(
             DBG_ASSERT( nOpenMode == css::embed::ElementModes::READ, "Error creating signature stream..." );
         }
     }
-    else if(xNameAccess->hasByName("_xmlsignatures"))
+    else if(xNameAccess->hasByName("[Content_Types].xml"))
     {
         try
         {
@@ -391,7 +391,7 @@ SignatureStreamHelper DocumentSignatureHelper::OpenSignatureStream(
         }
         catch (const io::IOException& rException)
         {
-            SAL_WARN("xmlsecurity.helper", "DocumentSignatureHelper::OpenSignatureStream: " << rException.Message);
+            SAL_WARN_IF(nOpenMode != css::embed::ElementModes::READ, "xmlsecurity.helper", "DocumentSignatureHelper::OpenSignatureStream: " << rException.Message);
         }
     }
 
commit f4b2e2362513e4442fe1d133302bd9b487866c6a
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Wed Feb 10 16:32:20 2016 +0100

    xmlsecurity: fix reading OOXML signature from temp storage
    
    When reading a signature, we just take the ODF signature stream or OOXML
    signature storage.
    
    When writing, we write to an ODF temporary stream / OOXML temporary
    storage, read it back, and only the signatures dialog close handler
    writes the signature back to the original file.
    
    The underlying OOXML temporary storage's stream is the signature stream,
    so only try to load signatures from the stream if it's not OOXML,
    throwing a ZIP file at an XML parser is not a great idea.
    
    Change-Id: I6e42d117b9c97676aaeaad158e78e39a2c39a5e8

diff --git a/xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx b/xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx
index 41834d7..d3262bb 100644
--- a/xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx
+++ b/xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx
@@ -773,7 +773,7 @@ void DigitalSignaturesDialog::ImplGetSignatureInformations(bool bUseTempStream)
 
     SignatureStreamHelper aStreamHelper = ImplOpenSignatureStream(
         css::embed::ElementModes::READ, bUseTempStream);
-    if ( aStreamHelper.xSignatureStream.is() )
+    if ( aStreamHelper.nStorageFormat != embed::StorageFormats::OFOPXML && aStreamHelper.xSignatureStream.is() )
     {
         uno::Reference< io::XInputStream > xInputStream( aStreamHelper.xSignatureStream, uno::UNO_QUERY );
         maSignatureHelper.ReadAndVerifySignature( xInputStream );
@@ -852,6 +852,8 @@ SignatureStreamHelper DigitalSignaturesDialog::ImplOpenSignatureStream(
             OSL_ASSERT(mxTempSignatureStream.is());
         }
         aHelper.xSignatureStream = mxTempSignatureStream;
+        if (aHelper.nStorageFormat == embed::StorageFormats::OFOPXML)
+            aHelper.xSignatureStorage = mxTempSignatureStorage;
     }
     else
     {
commit d06e6505f454eeff69327b22d5a5592375d31518
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Wed Feb 10 15:12:26 2016 +0100

    xmlsecurity OOXML export: write signature description
    
    Change-Id: I29937cf6baa02bda7821b4bb44c95e5b8a278080

diff --git a/xmlsecurity/source/helper/xsecctl.cxx b/xmlsecurity/source/helper/xsecctl.cxx
index a4ad860..6aec0f6 100644
--- a/xmlsecurity/source/helper/xsecctl.cxx
+++ b/xmlsecurity/source/helper/xsecctl.cxx
@@ -1219,11 +1219,69 @@ void XSecController::exportOOXMLSignature(const uno::Reference<embed::XStorage>&
 
     xDocumentHandler->endElement(TAG_OBJECT);
 
+    // idOfficeObject
     {
         rtl::Reference<SvXMLAttributeList> pAttributeList(new SvXMLAttributeList());
         pAttributeList->AddAttribute(ATTR_ID, "idOfficeObject");
         xDocumentHandler->startElement(TAG_OBJECT, uno::Reference<xml::sax::XAttributeList>(pAttributeList.get()));
     }
+    xDocumentHandler->startElement(TAG_SIGNATUREPROPERTIES, uno::Reference<xml::sax::XAttributeList>(new SvXMLAttributeList()));
+    {
+        rtl::Reference<SvXMLAttributeList> pAttributeList(new SvXMLAttributeList());
+        pAttributeList->AddAttribute(ATTR_ID, "idOfficeV1Details");
+        pAttributeList->AddAttribute(ATTR_TARGET, "#idPackageSignature");
+        xDocumentHandler->startElement(TAG_SIGNATUREPROPERTY, uno::Reference<xml::sax::XAttributeList>(pAttributeList.get()));
+    }
+    {
+        rtl::Reference<SvXMLAttributeList> pAttributeList(new SvXMLAttributeList());
+        pAttributeList->AddAttribute(ATTR_XMLNS, "http://schemas.microsoft.com/office/2006/digsig");
+        xDocumentHandler->startElement("SignatureInfoV1", uno::Reference<xml::sax::XAttributeList>(pAttributeList.get()));
+    }
+    xDocumentHandler->startElement("SetupId", uno::Reference<xml::sax::XAttributeList>(new SvXMLAttributeList()));
+    xDocumentHandler->endElement("SetupId");
+    xDocumentHandler->startElement("SignatureText", uno::Reference<xml::sax::XAttributeList>(new SvXMLAttributeList()));
+    xDocumentHandler->endElement("SignatureText");
+    xDocumentHandler->startElement("SignatureImage", uno::Reference<xml::sax::XAttributeList>(new SvXMLAttributeList()));
+    xDocumentHandler->endElement("SignatureImage");
+    xDocumentHandler->startElement("SignatureComments", uno::Reference<xml::sax::XAttributeList>(new SvXMLAttributeList()));
+    xDocumentHandler->characters(rInformation.ouDescription);
+    xDocumentHandler->endElement("SignatureComments");
+    // Just hardcode something valid according to [MS-OFFCRYPTO].
+    xDocumentHandler->startElement("WindowsVersion", uno::Reference<xml::sax::XAttributeList>(new SvXMLAttributeList()));
+    xDocumentHandler->characters("6.1");
+    xDocumentHandler->endElement("WindowsVersion");
+    xDocumentHandler->startElement("OfficeVersion", uno::Reference<xml::sax::XAttributeList>(new SvXMLAttributeList()));
+    xDocumentHandler->characters("16.0");
+    xDocumentHandler->endElement("OfficeVersion");
+    xDocumentHandler->startElement("ApplicationVersion", uno::Reference<xml::sax::XAttributeList>(new SvXMLAttributeList()));
+    xDocumentHandler->characters("16.0");
+    xDocumentHandler->endElement("ApplicationVersion");
+    xDocumentHandler->startElement("Monitors", uno::Reference<xml::sax::XAttributeList>(new SvXMLAttributeList()));
+    xDocumentHandler->characters("1");
+    xDocumentHandler->endElement("Monitors");
+    xDocumentHandler->startElement("HorizontalResolution", uno::Reference<xml::sax::XAttributeList>(new SvXMLAttributeList()));
+    xDocumentHandler->characters("1280");
+    xDocumentHandler->endElement("HorizontalResolution");
+    xDocumentHandler->startElement("VerticalResolution", uno::Reference<xml::sax::XAttributeList>(new SvXMLAttributeList()));
+    xDocumentHandler->characters("800");
+    xDocumentHandler->endElement("VerticalResolution");
+    xDocumentHandler->startElement("ColorDepth", uno::Reference<xml::sax::XAttributeList>(new SvXMLAttributeList()));
+    xDocumentHandler->characters("32");
+    xDocumentHandler->endElement("ColorDepth");
+    xDocumentHandler->startElement("SignatureProviderId", uno::Reference<xml::sax::XAttributeList>(new SvXMLAttributeList()));
+    xDocumentHandler->characters("{00000000-0000-0000-0000-000000000000}");
+    xDocumentHandler->endElement("SignatureProviderId");
+    xDocumentHandler->startElement("SignatureProviderUrl", uno::Reference<xml::sax::XAttributeList>(new SvXMLAttributeList()));
+    xDocumentHandler->endElement("SignatureProviderUrl");
+    xDocumentHandler->startElement("SignatureProviderDetails", uno::Reference<xml::sax::XAttributeList>(new SvXMLAttributeList()));
+    xDocumentHandler->characters("9"); // This is what MSO 2016 writes, though [MS-OFFCRYPTO] doesn't document what the value means.
+    xDocumentHandler->endElement("SignatureProviderDetails");
+    xDocumentHandler->startElement("SignatureType", uno::Reference<xml::sax::XAttributeList>(new SvXMLAttributeList()));
+    xDocumentHandler->characters("1");
+    xDocumentHandler->endElement("SignatureType");
+    xDocumentHandler->endElement("SignatureInfoV1");
+    xDocumentHandler->endElement(TAG_SIGNATUREPROPERTY);
+    xDocumentHandler->endElement(TAG_SIGNATUREPROPERTIES);
     xDocumentHandler->endElement(TAG_OBJECT);
 
     xDocumentHandler->startElement(TAG_OBJECT, uno::Reference<xml::sax::XAttributeList>(new SvXMLAttributeList()));
commit a2779756374d9e71e9ed6a1d7665f64cc5eacb0f
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Wed Feb 10 14:44:57 2016 +0100

    xmlsecurity OOXML export: write signature time
    
    Change-Id: I88b0be8b375b7698224e08768d867b767c3a98ad

diff --git a/xmlsecurity/source/helper/xsecctl.cxx b/xmlsecurity/source/helper/xsecctl.cxx
index aa7f7b4..a4ad860 100644
--- a/xmlsecurity/source/helper/xsecctl.cxx
+++ b/xmlsecurity/source/helper/xsecctl.cxx
@@ -1177,6 +1177,46 @@ void XSecController::exportOOXMLSignature(const uno::Reference<embed::XStorage>&
         }
     }
     xDocumentHandler->endElement(TAG_MANIFEST);
+
+    // SignatureProperties
+    xDocumentHandler->startElement(TAG_SIGNATUREPROPERTIES, uno::Reference<xml::sax::XAttributeList>(new SvXMLAttributeList()));
+    {
+        rtl::Reference<SvXMLAttributeList> pAttributeList(new SvXMLAttributeList());
+        pAttributeList->AddAttribute(ATTR_ID, "idSignatureTime");
+        pAttributeList->AddAttribute(ATTR_TARGET, "#idPackageSignature");
+        xDocumentHandler->startElement(TAG_SIGNATUREPROPERTY, uno::Reference<xml::sax::XAttributeList>(pAttributeList.get()));
+    }
+    {
+        rtl::Reference<SvXMLAttributeList> pAttributeList(new SvXMLAttributeList());
+        pAttributeList->AddAttribute(ATTR_XMLNS ":" NSTAG_MDSSI, NS_MDSSI);
+        xDocumentHandler->startElement(NSTAG_MDSSI ":" TAG_SIGNATURETIME, uno::Reference<xml::sax::XAttributeList>(pAttributeList.get()));
+    }
+    xDocumentHandler->startElement(NSTAG_MDSSI ":" TAG_FORMAT, uno::Reference<xml::sax::XAttributeList>(new SvXMLAttributeList()));
+    xDocumentHandler->characters("YYYY-MM-DDThh:mm:ssTZD");
+    xDocumentHandler->endElement(NSTAG_MDSSI ":" TAG_FORMAT);
+
+    xDocumentHandler->startElement(NSTAG_MDSSI ":" TAG_VALUE, uno::Reference<xml::sax::XAttributeList>(new SvXMLAttributeList()));
+    OUString aSignatureTimeValue;
+    if (!rInformation.ouDateTime.isEmpty())
+        aSignatureTimeValue = rInformation.ouDateTime;
+    else
+    {
+        aSignatureTimeValue = utl::toISO8601(rInformation.stDateTime);
+        // Ignore sub-seconds.
+        sal_Int32 nCommaPos = aSignatureTimeValue.indexOf(',');
+        if (nCommaPos != -1)
+        {
+            aSignatureTimeValue = aSignatureTimeValue.copy(0, nCommaPos);
+            aSignatureTimeValue += "Z";
+        }
+    }
+    xDocumentHandler->characters(aSignatureTimeValue);
+    xDocumentHandler->endElement(NSTAG_MDSSI ":" TAG_VALUE);
+
+    xDocumentHandler->endElement(NSTAG_MDSSI ":" TAG_SIGNATURETIME);
+    xDocumentHandler->endElement(TAG_SIGNATUREPROPERTY);
+    xDocumentHandler->endElement(TAG_SIGNATUREPROPERTIES);
+
     xDocumentHandler->endElement(TAG_OBJECT);
 
     {
diff --git a/xmlsecurity/source/helper/xsecctl.hxx b/xmlsecurity/source/helper/xsecctl.hxx
index 1bcf180..38b70dc 100644
--- a/xmlsecurity/source/helper/xsecctl.hxx
+++ b/xmlsecurity/source/helper/xsecctl.hxx
@@ -85,6 +85,9 @@
 #define TAG_QUALIFYINGPROPERTIES "QualifyingProperties"
 #define TAG_SIGNEDPROPERTIES "SignedProperties"
 #define TAG_RELATIONSHIPREFERENCE "RelationshipReference"
+#define TAG_SIGNATURETIME "SignatureTime"
+#define TAG_FORMAT "Format"
+#define TAG_VALUE "Value"
 
 #define ATTR_XMLNS          "xmlns"
 #define ATTR_ALGORITHM          "Algorithm"


More information about the Libreoffice-commits mailing list