From ff1982dc3f577913b9c15bd5c57776cf72918878 Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Wed, 10 Feb 2016 11:49:16 +0100 Subject: xmlsecurity OOXML export: use RelationshipTransform for relations Change-Id: I5fd400f095998184107c10afa95fe8b12c123d33 --- xmlsecurity/inc/xmlsecurity/xmlsignaturehelper.hxx | 4 +-- .../source/dialogs/digitalsignaturesdialog.cxx | 2 +- xmlsecurity/source/helper/xmlsignaturehelper.cxx | 6 ++-- xmlsecurity/source/helper/xsecctl.cxx | 36 +++++++++++++++++++++- xmlsecurity/source/helper/xsecctl.hxx | 5 +-- xmlsecurity/source/helper/xsecsign.cxx | 4 +-- 6 files changed, 46 insertions(+), 11 deletions(-) (limited to 'xmlsecurity') diff --git a/xmlsecurity/inc/xmlsecurity/xmlsignaturehelper.hxx b/xmlsecurity/inc/xmlsecurity/xmlsignaturehelper.hxx index 52efb06602e5..1a071c9a614a 100644 --- a/xmlsecurity/inc/xmlsecurity/xmlsignaturehelper.hxx +++ b/xmlsecurity/inc/xmlsecurity/xmlsignaturehelper.hxx @@ -185,8 +185,8 @@ public: void EnsureSignaturesRelation(css::uno::Reference xStorage); /// Given that xStorage is an OOXML _xmlsignatures storage, create origin.sigs and its relations. void ExportSignatureRelations(css::uno::Reference xStorage, int nSignatureCount); - /// Given that xStorage is an OOXML _xmlsignatures storage, create and write a new signature. - bool CreateAndWriteOOXMLSignature(css::uno::Reference xStorage, int nSignatureIndex); + /// Given that xSignatureStorage is an OOXML _xmlsignatures storage, create and write a new signature. + bool CreateAndWriteOOXMLSignature(css::uno::Reference xRootStorage, css::uno::Reference xSignatureStorage, int nSignatureIndex); }; #endif // INCLUDED_XMLSECURITY_INC_XMLSECURITY_XMLSIGNATUREHELPER_HXX diff --git a/xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx b/xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx index 85da771d1826..41834d7f7b98 100644 --- a/xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx +++ b/xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx @@ -524,7 +524,7 @@ IMPL_LINK_NOARG_TYPED(DigitalSignaturesDialog, AddButtonHdl, Button*, void) maSignatureHelper.ExportSignatureRelations(aStreamHelper.xSignatureStorage, nSignatureCount); // Create a new signature. - maSignatureHelper.CreateAndWriteOOXMLSignature(aStreamHelper.xSignatureStorage, nSignatureCount); + maSignatureHelper.CreateAndWriteOOXMLSignature(mxStore, aStreamHelper.xSignatureStorage, nSignatureCount); // Flush objects. uno::Reference xTransact(aStreamHelper.xSignatureStorage, uno::UNO_QUERY); diff --git a/xmlsecurity/source/helper/xmlsignaturehelper.cxx b/xmlsecurity/source/helper/xmlsignaturehelper.cxx index bf80548b9d59..5ed47a83fbd4 100644 --- a/xmlsecurity/source/helper/xmlsignaturehelper.cxx +++ b/xmlsecurity/source/helper/xmlsignaturehelper.cxx @@ -492,17 +492,17 @@ void XMLSignatureHelper::ExportSignatureRelations(css::uno::Referencecommit(); } -bool XMLSignatureHelper::CreateAndWriteOOXMLSignature(css::uno::Reference xStorage, int nSignatureIndex) +bool XMLSignatureHelper::CreateAndWriteOOXMLSignature(uno::Reference xRootStorage, uno::Reference xSignatureStorage, int nSignatureIndex) { sal_Int32 nOpenMode = embed::ElementModes::READWRITE; - uno::Reference xOutputStream(xStorage->openStreamElement("sig" + OUString::number(nSignatureIndex) + ".xml", nOpenMode), uno::UNO_QUERY); + uno::Reference xOutputStream(xSignatureStorage->openStreamElement("sig" + OUString::number(nSignatureIndex) + ".xml", nOpenMode), uno::UNO_QUERY); uno::Reference xSaxWriter = xml::sax::Writer::create(mxCtx); xSaxWriter->setOutputStream(xOutputStream); xSaxWriter->startDocument(); mbError = false; uno::Reference xDocumentHandler(xSaxWriter, uno::UNO_QUERY); - if (!mpXSecController->WriteOOXMLSignature(xDocumentHandler)) + if (!mpXSecController->WriteOOXMLSignature(xRootStorage, xDocumentHandler)) mbError = true; xSaxWriter->endDocument(); diff --git a/xmlsecurity/source/helper/xsecctl.cxx b/xmlsecurity/source/helper/xsecctl.cxx index b45e24b8b725..bc60efd6b283 100644 --- a/xmlsecurity/source/helper/xsecctl.cxx +++ b/xmlsecurity/source/helper/xsecctl.cxx @@ -29,6 +29,8 @@ #include #include #include +#include +#include #include #include @@ -994,8 +996,10 @@ static bool lcl_isOOXMLBlacklist(const OUString& rStreamName) return std::find_if(vBlacklist.begin(), vBlacklist.end(), [&](const OUStringLiteral& rLiteral) { return rStreamName.startsWith(rLiteral); }) != vBlacklist.end(); } -void XSecController::exportOOXMLSignature(const uno::Reference& xDocumentHandler, const SignatureInformation& rInformation) +void XSecController::exportOOXMLSignature(const uno::Reference& xRootStorage, const uno::Reference& xDocumentHandler, const SignatureInformation& rInformation) { + uno::Reference xHierarchicalStorageAccess(xRootStorage, uno::UNO_QUERY); + { rtl::Reference pAttributeList(new SvXMLAttributeList()); pAttributeList->AddAttribute(ATTR_XMLNS, NS_XMLDSIG); @@ -1087,6 +1091,36 @@ void XSecController::exportOOXMLSignature(const uno::ReferenceAddAttribute(ATTR_URI, rReference.ouURI); xDocumentHandler->startElement(TAG_REFERENCE, uno::Reference(pAttributeList.get())); } + + // Transforms + if (rReference.ouURI.endsWith("?ContentType=application/vnd.openxmlformats-package.relationships+xml")) + { + OUString aURI = rReference.ouURI; + // Ignore leading slash. + if (aURI.startsWith("/")) + aURI = aURI.copy(1); + // Ignore query part of the URI. + sal_Int32 nQueryPos = aURI.indexOf('?'); + if (nQueryPos != -1) + aURI = aURI.copy(0, nQueryPos); + + uno::Reference xRelStream(xHierarchicalStorageAccess->openStreamElementByHierarchicalName(aURI, embed::ElementModes::READ), uno::UNO_QUERY); + xDocumentHandler->startElement(TAG_TRANSFORMS, uno::Reference(new SvXMLAttributeList())); + { + rtl::Reference pAttributeList(new SvXMLAttributeList()); + pAttributeList->AddAttribute(ATTR_ALGORITHM, ALGO_RELATIONSHIP); + xDocumentHandler->startElement(TAG_TRANSFORM, uno::Reference(pAttributeList.get())); + } + xDocumentHandler->endElement(TAG_TRANSFORM); + { + rtl::Reference pAttributeList(new SvXMLAttributeList()); + pAttributeList->AddAttribute(ATTR_ALGORITHM, ALGO_C14N); + xDocumentHandler->startElement(TAG_TRANSFORM, uno::Reference(pAttributeList.get())); + } + xDocumentHandler->endElement(TAG_TRANSFORM); + xDocumentHandler->endElement(TAG_TRANSFORMS); + } + { rtl::Reference pAttributeList(new SvXMLAttributeList()); pAttributeList->AddAttribute(ATTR_ALGORITHM, ALGO_XMLDSIGSHA256); diff --git a/xmlsecurity/source/helper/xsecctl.hxx b/xmlsecurity/source/helper/xsecctl.hxx index ea436e3e2efe..8e87e1ea1fb4 100644 --- a/xmlsecurity/source/helper/xsecctl.hxx +++ b/xmlsecurity/source/helper/xsecctl.hxx @@ -40,6 +40,7 @@ #include #include #include +#include #include @@ -512,9 +513,9 @@ public: throw (com::sun::star::uno::RuntimeException, std::exception) override; /// Writes XML elements inside a single OOXML signature's element. - bool WriteOOXMLSignature(const css::uno::Reference& xDocumentHandler); + bool WriteOOXMLSignature(const css::uno::Reference& xRootStorage, const css::uno::Reference& xDocumentHandler); /// Exports an OOXML signature, called by WriteOOXMLSignature(). - static void exportOOXMLSignature(const css::uno::Reference& xDocumentHandler, const SignatureInformation& rInformation); + static void exportOOXMLSignature(const css::uno::Reference& xRootStorage, const css::uno::Reference& xDocumentHandler, const SignatureInformation& rInformation); }; #endif diff --git a/xmlsecurity/source/helper/xsecsign.cxx b/xmlsecurity/source/helper/xsecsign.cxx index 778381e13eb3..cacdfcb7cc78 100644 --- a/xmlsecurity/source/helper/xsecsign.cxx +++ b/xmlsecurity/source/helper/xsecsign.cxx @@ -370,7 +370,7 @@ bool XSecController::WriteSignature( return rc; } -bool XSecController::WriteOOXMLSignature(const uno::Reference& xDocumentHandler) +bool XSecController::WriteOOXMLSignature(const uno::Reference& xRootStorage, const uno::Reference& xDocumentHandler) { bool bRet = false; @@ -396,7 +396,7 @@ bool XSecController::WriteOOXMLSignature(const uno::Reference