diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2020-06-25 14:32:11 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2020-06-29 09:12:12 +0200 |
commit | adb55d56a99107e6c6205e193c3efc9844fb1553 (patch) | |
tree | 4e33699abc4fdda0ae3e6caa83c037d26f98ca38 /sfx2 | |
parent | 424deb432a3ff394bd8d9c1c52cefca9e4b31e3d (diff) |
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 <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Diffstat (limited to 'sfx2')
-rw-r--r-- | sfx2/source/doc/docfile.cxx | 22 | ||||
-rw-r--r-- | sfx2/source/doc/objserv.cxx | 3 |
2 files changed, 18 insertions, 7 deletions
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 <com/sun/star/embed/ElementModes.hpp> #include <com/sun/star/embed/UseBackupException.hpp> #include <com/sun/star/embed/XOptimizedStorage.hpp> +#include <com/sun/star/frame/XModel.hpp> #include <com/sun/star/graphic/XGraphic.hpp> #include <com/sun/star/ucb/ContentCreationException.hpp> #include <com/sun/star/ucb/InteractiveIOException.hpp> @@ -139,6 +140,7 @@ #include <vcl/svapp.hxx> #include <tools/diagnose_ex.h> #include <unotools/fltrcfg.hxx> +#include <sfx2/digitalsignatures.hxx> #include <com/sun/star/io/WrongFormatException.hpp> @@ -3784,8 +3786,9 @@ void SfxMedium::CreateTempFileNoCopy() CloseStorage(); } -bool SfxMedium::SignDocumentContentUsingCertificate(bool bHasValidDocumentSignature, - const Reference<XCertificate>& xCertificate) +bool SfxMedium::SignDocumentContentUsingCertificate( + const css::uno::Reference<css::frame::XModel>& xModel, bool bHasValidDocumentSignature, + const Reference<XCertificate>& 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<sfx2::DigitalSignatures*>(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<io::XStream> 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<SvStream> pStream(utl::UcbStreamHelper::CreateStream(GetName(), StreamMode::READ | StreamMode::WRITE)); uno::Reference<io::XStream> xStream(new utl::OStreamWrapper(*pStream)); - if (xSigner->signDocumentWithCertificate(xCertificate, uno::Reference<embed::XStorage>(), xStream)) + if (xModelSigner->SignModelWithCertificate( + xModel, xCertificate, uno::Reference<embed::XStorage>(), 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 Reference<XCertif return false; // 3. Sign - bool bSignSuccess = GetMedium()->SignDocumentContentUsingCertificate(HasValidSignatures(), xCertificate); + bool bSignSuccess = GetMedium()->SignDocumentContentUsingCertificate( + GetBaseModel(), HasValidSignatures(), xCertificate); // 4. AfterSigning AfterSigning(bSignSuccess, false); |