From adb55d56a99107e6c6205e193c3efc9844fb1553 Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Thu, 25 Jun 2020 14:32:11 +0200 Subject: sd signature line: pass the model down to xmlsecurity So it can avoid SfxObjectShell::Current(), which is only correct when a single document is open. Also add an sfx2::DigitalSignatures interface so this can be done without UNO API changes. (cherry picked from commit c3f8702241b625db994bcb059d8c91c25fd43e53) Conflicts: xmlsecurity/source/component/documentdigitalsignatures.cxx xmlsecurity/source/helper/documentsignaturemanager.cxx Change-Id: Ie81996b8f1e8851975b27c43a53f9d23e316004e Reviewed-on: https://gerrit.libreoffice.org/c/core/+/97258 Tested-by: Jenkins CollaboraOffice Reviewed-by: Miklos Vajna --- sfx2/source/doc/docfile.cxx | 22 ++++++++++++++++------ sfx2/source/doc/objserv.cxx | 3 ++- 2 files changed, 18 insertions(+), 7 deletions(-) (limited to 'sfx2') diff --git a/sfx2/source/doc/docfile.cxx b/sfx2/source/doc/docfile.cxx index b1ef5fa0e5f2..81005e08790f 100644 --- a/sfx2/source/doc/docfile.cxx +++ b/sfx2/source/doc/docfile.cxx @@ -44,6 +44,7 @@ #include #include #include +#include #include #include #include @@ -139,6 +140,7 @@ #include #include #include +#include #include @@ -3784,8 +3786,9 @@ void SfxMedium::CreateTempFileNoCopy() CloseStorage(); } -bool SfxMedium::SignDocumentContentUsingCertificate(bool bHasValidDocumentSignature, - const Reference& xCertificate) +bool SfxMedium::SignDocumentContentUsingCertificate( + const css::uno::Reference& xModel, bool bHasValidDocumentSignature, + const Reference& xCertificate) { bool bChanges = false; @@ -3801,6 +3804,11 @@ bool SfxMedium::SignDocumentContentUsingCertificate(bool bHasValidDocumentSignat uno::Reference< security::XDocumentDigitalSignatures > xSigner( security::DocumentDigitalSignatures::createWithVersionAndValidSignature( comphelper::getProcessComponentContext(), aODFVersion, bHasValidDocumentSignature ) ); + auto xModelSigner = dynamic_cast(xSigner.get()); + if (!xModelSigner) + { + return bChanges; + } uno::Reference< embed::XStorage > xWriteableZipStor; @@ -3847,7 +3855,8 @@ bool SfxMedium::SignDocumentContentUsingCertificate(bool bHasValidDocumentSignat if (GetFilter() && GetFilter()->IsOwnFormat()) xStream.set(xMetaInf->openStreamElement(xSigner->getDocumentContentSignatureDefaultStreamName(), embed::ElementModes::READWRITE), uno::UNO_SET_THROW); - bool bSuccess = xSigner->signDocumentWithCertificate(xCertificate, GetZipStorageToSign_Impl(), xStream); + bool bSuccess = xModelSigner->SignModelWithCertificate( + xModel, xCertificate, GetZipStorageToSign_Impl(), xStream); if (bSuccess) { @@ -3867,8 +3876,8 @@ bool SfxMedium::SignDocumentContentUsingCertificate(bool bHasValidDocumentSignat uno::Reference xStream; // We need read-write to be able to add the signature relation. - bool bSuccess =xSigner->signDocumentWithCertificate( - xCertificate, GetZipStorageToSign_Impl(/*bReadOnly=*/false), xStream); + bool bSuccess = xModelSigner->SignModelWithCertificate( + xModel, xCertificate, GetZipStorageToSign_Impl(/*bReadOnly=*/false), xStream); if (bSuccess) { @@ -3885,7 +3894,8 @@ bool SfxMedium::SignDocumentContentUsingCertificate(bool bHasValidDocumentSignat // Something not ZIP based: e.g. PDF. std::unique_ptr pStream(utl::UcbStreamHelper::CreateStream(GetName(), StreamMode::READ | StreamMode::WRITE)); uno::Reference xStream(new utl::OStreamWrapper(*pStream)); - if (xSigner->signDocumentWithCertificate(xCertificate, uno::Reference(), xStream)) + if (xModelSigner->SignModelWithCertificate( + xModel, xCertificate, uno::Reference(), xStream)) bChanges = true; } } diff --git a/sfx2/source/doc/objserv.cxx b/sfx2/source/doc/objserv.cxx index b931ed90c3e7..55e36ff69cbb 100644 --- a/sfx2/source/doc/objserv.cxx +++ b/sfx2/source/doc/objserv.cxx @@ -1954,7 +1954,8 @@ bool SfxObjectShell::SignDocumentContentUsingCertificate(const ReferenceSignDocumentContentUsingCertificate(HasValidSignatures(), xCertificate); + bool bSignSuccess = GetMedium()->SignDocumentContentUsingCertificate( + GetBaseModel(), HasValidSignatures(), xCertificate); // 4. AfterSigning AfterSigning(bSignSuccess, false); -- cgit