diff options
author | Miklos Vajna <vmiklos@collabora.co.uk> | 2016-03-04 12:34:39 +0100 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2016-03-04 16:01:34 +0100 |
commit | c30bf0284c643b6c574fcc5dabb840bb51174b30 (patch) | |
tree | ee444e95a6e55483334d6db68bb0ce7ac7353702 /xmlsecurity | |
parent | 4351ff1f12268a0b97413e811503ac65a51665eb (diff) |
xmlsecurity OOXML export: handle keeping all signatures but one
The removal of the _xmlsignatures sub-storage in
DocumentSignatureHelper::OpenSignatureStream() serves 3 purposes:
1) Remove no longer needed signature streams
2) Truncate signatures relation stream
3) Truncate still needed signature streams
2) and 3) could be done using io::XTruncate as well, but if the whole
storage is removed to handle 1), then individual truncate() calls are
not necessary.
Change-Id: Id9ed9c87c94f340dc947124b28f085561798d361
Diffstat (limited to 'xmlsecurity')
-rw-r--r-- | xmlsecurity/source/helper/documentsignaturehelper.cxx | 4 | ||||
-rw-r--r-- | xmlsecurity/source/helper/documentsignaturemanager.cxx | 41 |
2 files changed, 37 insertions, 8 deletions
diff --git a/xmlsecurity/source/helper/documentsignaturehelper.cxx b/xmlsecurity/source/helper/documentsignaturehelper.cxx index 9c14715ac8cd..b0097368d560 100644 --- a/xmlsecurity/source/helper/documentsignaturehelper.cxx +++ b/xmlsecurity/source/helper/documentsignaturehelper.cxx @@ -390,6 +390,10 @@ SignatureStreamHelper DocumentSignatureHelper::OpenSignatureStream( { try { + if (xNameAccess->hasByName("_xmlsignatures") && (nOpenMode & embed::ElementModes::TRUNCATE)) + // Truncate, then all signatures will be written -> remove previous ones. + rxStore->removeElement("_xmlsignatures"); + aHelper.xSignatureStorage = rxStore->openStorageElement("_xmlsignatures", nSubStorageOpenMode); aHelper.nStorageFormat = embed::StorageFormats::OFOPXML; } diff --git a/xmlsecurity/source/helper/documentsignaturemanager.cxx b/xmlsecurity/source/helper/documentsignaturemanager.cxx index d5066bd0204a..f22d93714720 100644 --- a/xmlsecurity/source/helper/documentsignaturemanager.cxx +++ b/xmlsecurity/source/helper/documentsignaturemanager.cxx @@ -283,7 +283,7 @@ bool DocumentSignatureManager::add(const uno::Reference<security::XCertificate>& xOutputStream->closeOutput(); uno::Reference<io::XTempFile> xTempFile(aStreamHelper.xSignatureStream, uno::UNO_QUERY); - SAL_INFO("xmlsecurity.dialogs", "AddButtonHdl: temporary storage is at " << xTempFile->getUri()); + SAL_INFO("xmlsecurity.helper", "DocumentSignatureManager::add temporary storage at " << xTempFile->getUri()); } maSignatureHelper.EndMission(); @@ -296,15 +296,40 @@ void DocumentSignatureManager::remove(sal_uInt16 nPosition) // Export all other signatures... SignatureStreamHelper aStreamHelper = ImplOpenSignatureStream(embed::ElementModes::WRITE | embed::ElementModes::TRUNCATE, /*bTempStream=*/true); - uno::Reference<io::XOutputStream> xOutputStream(aStreamHelper.xSignatureStream, uno::UNO_QUERY_THROW); - uno::Reference<xml::sax::XWriter> xSaxWriter = maSignatureHelper.CreateDocumentHandlerWithHeader(xOutputStream); - uno::Reference< xml::sax::XDocumentHandler> xDocumentHandler(xSaxWriter, uno::UNO_QUERY_THROW); - size_t nInfos = maCurrentSignatureInformations.size(); - for (size_t n = 0 ; n < nInfos ; ++n) - XMLSignatureHelper::ExportSignature(xDocumentHandler, maCurrentSignatureInformations[n]); + if (aStreamHelper.nStorageFormat != embed::StorageFormats::OFOPXML) + { + uno::Reference<io::XOutputStream> xOutputStream(aStreamHelper.xSignatureStream, uno::UNO_QUERY_THROW); + uno::Reference<xml::sax::XWriter> xSaxWriter = maSignatureHelper.CreateDocumentHandlerWithHeader(xOutputStream); + + uno::Reference< xml::sax::XDocumentHandler> xDocumentHandler(xSaxWriter, uno::UNO_QUERY_THROW); + size_t nInfos = maCurrentSignatureInformations.size(); + for (size_t n = 0 ; n < nInfos ; ++n) + XMLSignatureHelper::ExportSignature(xDocumentHandler, maCurrentSignatureInformations[n]); + + XMLSignatureHelper::CloseDocumentHandler(xDocumentHandler); + } + else + { + // OOXML + + // Handle relations. + int nSignatureCount = maCurrentSignatureInformations.size(); + maSignatureHelper.ExportSignatureRelations(aStreamHelper.xSignatureStorage, nSignatureCount); + + // Export old signatures. + for (size_t i = 0; i < maCurrentSignatureInformations.size(); ++i) + maSignatureHelper.ExportOOXMLSignature(mxStore, aStreamHelper.xSignatureStorage, maCurrentSignatureInformations[i], i + 1); + + // Flush objects. + uno::Reference<embed::XTransactedObject> xTransact(aStreamHelper.xSignatureStorage, uno::UNO_QUERY); + xTransact->commit(); + uno::Reference<io::XOutputStream> xOutputStream(aStreamHelper.xSignatureStream, uno::UNO_QUERY); + xOutputStream->closeOutput(); - XMLSignatureHelper::CloseDocumentHandler(xDocumentHandler); + uno::Reference<io::XTempFile> xTempFile(aStreamHelper.xSignatureStream, uno::UNO_QUERY); + SAL_INFO("xmlsecurity.helper", "DocumentSignatureManager::remove: temporary storage is at " << xTempFile->getUri()); + } } void DocumentSignatureManager::read(bool bUseTempStream, bool bCacheLastSignature) |