diff options
author | Miklos Vajna <vmiklos@collabora.co.uk> | 2016-02-04 18:13:18 +0100 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2016-02-04 18:30:44 +0100 |
commit | 8865a3b092a4b34530d8ca67286aa3765181d235 (patch) | |
tree | bc2e1403b7bd226bcd86b0a023fd42941709d576 /sfx2 | |
parent | xmlsecurity: don't write the stream of an OOXML storage (diff) | |
download | core-8865a3b092a4b34530d8ca67286aa3765181d235.tar.gz core-8865a3b092a4b34530d8ca67286aa3765181d235.zip |
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
Diffstat (limited to 'sfx2')
-rw-r--r-- | sfx2/source/doc/docfile.cxx | 55 |
1 files changed, 39 insertions, 16 deletions
diff --git a/sfx2/source/doc/docfile.cxx b/sfx2/source/doc/docfile.cxx index bb44a1c9e1f1..af4224a1cb44 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; + } } } } |