Kaydet (Commit) 8865a3b0 authored tarafından Miklos Vajna's avatar Miklos Vajna

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
üst 8f2f1258
...@@ -3545,11 +3545,16 @@ bool SfxMedium::SignContents_Impl( bool bScriptingContent, const OUString& aODFV ...@@ -3545,11 +3545,16 @@ bool SfxMedium::SignContents_Impl( bool bScriptingContent, const OUString& aODFV
if ( !xWriteableZipStor.is() ) if ( !xWriteableZipStor.is() )
throw uno::RuntimeException(); throw uno::RuntimeException();
uno::Reference< embed::XStorage > xMetaInf = xWriteableZipStor->openStorageElement( uno::Reference< embed::XStorage > xMetaInf;
"META-INF", uno::Reference<container::XNameAccess> xNameAccess(xWriteableZipStor, uno::UNO_QUERY);
embed::ElementModes::READWRITE ); if (xNameAccess.is() && xNameAccess->hasByName("META-INF"))
if ( !xMetaInf.is() ) {
throw uno::RuntimeException(); xMetaInf = xWriteableZipStor->openStorageElement(
"META-INF",
embed::ElementModes::READWRITE );
if ( !xMetaInf.is() )
throw uno::RuntimeException();
}
if ( bScriptingContent ) if ( bScriptingContent )
{ {
...@@ -3579,20 +3584,38 @@ bool SfxMedium::SignContents_Impl( bool bScriptingContent, const OUString& aODFV ...@@ -3579,20 +3584,38 @@ bool SfxMedium::SignContents_Impl( bool bScriptingContent, const OUString& aODFV
} }
else else
{ {
uno::Reference< io::XStream > xStream; if (xMetaInf.is())
if (GetFilter() && GetFilter()->IsOwnFormat()) {
xStream.set(xMetaInf->openStreamElement(xSigner->getDocumentContentSignatureDefaultStreamName(), embed::ElementModes::READWRITE), uno::UNO_SET_THROW); // 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 ); // OOXML.
xTransact->commit(); uno::Reference<io::XStream> xStream;
xTransact.set( xWriteableZipStor, uno::UNO_QUERY_THROW ); if (xSigner->signDocumentContent(GetZipStorageToSign_Impl(), xStream))
xTransact->commit(); {
uno::Reference<embed::XTransactedObject> xTransact(xWriteableZipStor, uno::UNO_QUERY_THROW);
xTransact->commit();
// the temporary file has been written, commit it to the original file // the temporary file has been written, commit it to the original file
Commit(); Commit();
bChanges = true; bChanges = true;
}
} }
} }
} }
......
...@@ -395,7 +395,7 @@ IMPL_LINK_NOARG_TYPED(DigitalSignaturesDialog, OKButtonHdl, Button*, void) ...@@ -395,7 +395,7 @@ IMPL_LINK_NOARG_TYPED(DigitalSignaturesDialog, OKButtonHdl, Button*, void)
SignatureStreamHelper aStreamHelper = ImplOpenSignatureStream( SignatureStreamHelper aStreamHelper = ImplOpenSignatureStream(
embed::ElementModes::WRITE|embed::ElementModes::TRUNCATE, false ); embed::ElementModes::WRITE|embed::ElementModes::TRUNCATE, false );
if (aStreamHelper.xSignatureStream.is()) if (aStreamHelper.xSignatureStream.is() && aStreamHelper.nStorageFormat != embed::StorageFormats::OFOPXML)
{ {
// ODF // ODF
uno::Reference< io::XOutputStream > xOutputStream( uno::Reference< io::XOutputStream > xOutputStream(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment