From f26019532bb03ea1a3d276be90adbecca6759a77 Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Fri, 5 Feb 2016 15:21:02 +0100 Subject: xmlsecurity: write OOXML signature relations on export _rels/origin.sigs.rels of the _xmlsignatures temporary storage now contains references to the individual signature streams. Change-Id: I619bd81989e3b62fc4282e0e72fbfa780d1fb8bd --- xmlsecurity/inc/xmlsecurity/xmlsignaturehelper.hxx | 2 +- .../source/dialogs/digitalsignaturesdialog.cxx | 5 +++-- xmlsecurity/source/helper/xmlsignaturehelper.cxx | 22 ++++++++++++++++++++-- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/xmlsecurity/inc/xmlsecurity/xmlsignaturehelper.hxx b/xmlsecurity/inc/xmlsecurity/xmlsignaturehelper.hxx index 4cb3002021ce..a7947ed8dade 100644 --- a/xmlsecurity/inc/xmlsecurity/xmlsignaturehelper.hxx +++ b/xmlsecurity/inc/xmlsecurity/xmlsignaturehelper.hxx @@ -185,7 +185,7 @@ public: /// Adds an OOXML digital signature relation to _rels/.rels if there wasn't any before. void EnsureSignaturesRelation(css::uno::Reference xStorage); /// Given that xStorage is an OOXML _xmlsignatures storage, create origin.sigs and its relations. - static void ExportSignatureRelations(css::uno::Reference xStorage, int nSignatureCount); + void ExportSignatureRelations(css::uno::Reference xStorage, int nSignatureCount); }; #endif // INCLUDED_XMLSECURITY_INC_XMLSECURITY_XMLSIGNATUREHELPER_HXX diff --git a/xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx b/xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx index 6f395012d097..fa3f37734379 100644 --- a/xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx +++ b/xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx @@ -515,11 +515,12 @@ IMPL_LINK_NOARG_TYPED(DigitalSignaturesDialog, AddButtonHdl, Button*, void) else { // OOXML - maSignatureHelper.EnsureSignaturesRelation(mxStore); + // Handle relations. + maSignatureHelper.EnsureSignaturesRelation(mxStore); // Old signatures + the new one. int nSignatureCount = maCurrentSignatureInformations.size() + 1; - XMLSignatureHelper::ExportSignatureRelations(aStreamHelper.xSignatureStorage, nSignatureCount); + maSignatureHelper.ExportSignatureRelations(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 cfd0c621c2c4..43afcdcfd55b 100644 --- a/xmlsecurity/source/helper/xmlsignaturehelper.cxx +++ b/xmlsecurity/source/helper/xmlsignaturehelper.cxx @@ -54,6 +54,7 @@ #define NS_DOCUMENTSIGNATURES "http://openoffice.org/2004/documentsignatures" #define NS_DOCUMENTSIGNATURES_ODF_1_2 "urn:oasis:names:tc:opendocument:xmlns:digitalsignature:1.0" #define OOXML_SIGNATURE_ORIGIN "http://schemas.openxmlformats.org/package/2006/relationships/digital-signature/origin" +#define OOXML_SIGNATURE_SIGNATURE "http://schemas.openxmlformats.org/package/2006/relationships/digital-signature/signature" using namespace ::com::sun::star; using namespace ::com::sun::star::uno; @@ -352,7 +353,7 @@ namespace { bool lcl_isSignatureType(const beans::StringPair& rPair) { - return rPair.First == "Type" && rPair.Second == "http://schemas.openxmlformats.org/package/2006/relationships/digital-signature/signature"; + return rPair.First == "Type" && rPair.Second == OOXML_SIGNATURE_SIGNATURE; } bool lcl_isSignatureOriginType(const beans::StringPair& rPair) { @@ -465,13 +466,30 @@ void XMLSignatureHelper::EnsureSignaturesRelation(css::uno::Referencecommit(); } -void XMLSignatureHelper::ExportSignatureRelations(css::uno::Reference xStorage, int /*nSignatureCount*/) +void XMLSignatureHelper::ExportSignatureRelations(css::uno::Reference xStorage, int nSignatureCount) { + // Write the empty file, its relations will be the signatures. sal_Int32 nOpenMode = embed::ElementModes::READWRITE; uno::Reference xOriginStream(xStorage->openStreamElement("origin.sigs", nOpenMode), uno::UNO_QUERY); uno::Reference xTruncate(xOriginStream, uno::UNO_QUERY); xTruncate->truncate(); xOriginStream->closeOutput(); + + // Write the relations. + uno::Reference xSubStorage(xStorage->openStorageElement("_rels", nOpenMode), uno::UNO_QUERY); + uno::Reference xRelStream(xSubStorage->openStreamElement("origin.sigs.rels", nOpenMode), uno::UNO_QUERY); + std::vector< uno::Sequence > aRelations; + for (int i = 0; i < nSignatureCount; ++i) + { + std::vector aRelation; + aRelation.push_back(beans::StringPair("Id", "rId" + OUString::number(i + 1))); + aRelation.push_back(beans::StringPair("Type", OOXML_SIGNATURE_SIGNATURE)); + aRelation.push_back(beans::StringPair("Target", "sig" + OUString::number(i + 1) + ".xml")); + aRelations.push_back(comphelper::containerToSequence(aRelation)); + } + comphelper::OFOPXMLHelper::WriteRelationsInfoSequence(xRelStream, comphelper::containerToSequence(aRelations), mxCtx); + uno::Reference xTransact(xSubStorage, uno::UNO_QUERY); + xTransact->commit(); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit