sfx2/source/doc/docfile.cxx | 55 ++++++++++++----- xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx | 2 2 files changed, 40 insertions(+), 17 deletions(-)
New commits: commit 8865a3b092a4b34530d8ca67286aa3765181d235 Author: Miklos Vajna <vmik...@collabora.co.uk> Date: Thu Feb 4 18:13:18 2016 +0100 sfx2: avoid writing META-INF/ when signing OOXML files Instead just pass an empty stream, xmlsecurity knows how to look up its signature storage from the root one. With this, opening the digital signatures dialog, clicking on add, and then OK in both dialogs no longer results in an (empty) META-INF storage written to an OOXML file. Change-Id: I7e4a93687465ec19be307917ec00cde08ed8092f diff --git a/sfx2/source/doc/docfile.cxx b/sfx2/source/doc/docfile.cxx index bb44a1c..af4224a 100644 --- a/sfx2/source/doc/docfile.cxx +++ b/sfx2/source/doc/docfile.cxx @@ -3545,11 +3545,16 @@ bool SfxMedium::SignContents_Impl( bool bScriptingContent, const OUString& aODFV if ( !xWriteableZipStor.is() ) throw uno::RuntimeException(); - uno::Reference< embed::XStorage > xMetaInf = xWriteableZipStor->openStorageElement( - "META-INF", - embed::ElementModes::READWRITE ); - if ( !xMetaInf.is() ) - throw uno::RuntimeException(); + uno::Reference< embed::XStorage > xMetaInf; + uno::Reference<container::XNameAccess> xNameAccess(xWriteableZipStor, uno::UNO_QUERY); + if (xNameAccess.is() && xNameAccess->hasByName("META-INF")) + { + xMetaInf = xWriteableZipStor->openStorageElement( + "META-INF", + embed::ElementModes::READWRITE ); + if ( !xMetaInf.is() ) + throw uno::RuntimeException(); + } if ( bScriptingContent ) { @@ -3579,20 +3584,38 @@ bool SfxMedium::SignContents_Impl( bool bScriptingContent, const OUString& aODFV } else { - uno::Reference< io::XStream > xStream; - if (GetFilter() && GetFilter()->IsOwnFormat()) - xStream.set(xMetaInf->openStreamElement(xSigner->getDocumentContentSignatureDefaultStreamName(), embed::ElementModes::READWRITE), uno::UNO_SET_THROW); + if (xMetaInf.is()) + { + // ODF. + uno::Reference< io::XStream > xStream; + if (GetFilter() && GetFilter()->IsOwnFormat()) + xStream.set(xMetaInf->openStreamElement(xSigner->getDocumentContentSignatureDefaultStreamName(), embed::ElementModes::READWRITE), uno::UNO_SET_THROW); - if ( xSigner->signDocumentContent( GetZipStorageToSign_Impl(), xStream ) ) + if ( xSigner->signDocumentContent( GetZipStorageToSign_Impl(), xStream ) ) + { + uno::Reference< embed::XTransactedObject > xTransact( xMetaInf, uno::UNO_QUERY_THROW ); + xTransact->commit(); + xTransact.set( xWriteableZipStor, uno::UNO_QUERY_THROW ); + xTransact->commit(); + + // the temporary file has been written, commit it to the original file + Commit(); + bChanges = true; + } + } + else { - uno::Reference< embed::XTransactedObject > xTransact( xMetaInf, uno::UNO_QUERY_THROW ); - xTransact->commit(); - xTransact.set( xWriteableZipStor, uno::UNO_QUERY_THROW ); - xTransact->commit(); + // OOXML. + uno::Reference<io::XStream> xStream; + if (xSigner->signDocumentContent(GetZipStorageToSign_Impl(), xStream)) + { + uno::Reference<embed::XTransactedObject> xTransact(xWriteableZipStor, uno::UNO_QUERY_THROW); + xTransact->commit(); - // the temporary file has been written, commit it to the original file - Commit(); - bChanges = true; + // the temporary file has been written, commit it to the original file + Commit(); + bChanges = true; + } } } } diff --git a/xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx b/xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx index 6601bbe..a5effe9 100644 --- a/xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx +++ b/xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx @@ -395,7 +395,7 @@ IMPL_LINK_NOARG_TYPED(DigitalSignaturesDialog, OKButtonHdl, Button*, void) SignatureStreamHelper aStreamHelper = ImplOpenSignatureStream( embed::ElementModes::WRITE|embed::ElementModes::TRUNCATE, false ); - if (aStreamHelper.xSignatureStream.is()) + if (aStreamHelper.xSignatureStream.is() && aStreamHelper.nStorageFormat != embed::StorageFormats::OFOPXML) { // ODF uno::Reference< io::XOutputStream > xOutputStream( _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits