summaryrefslogtreecommitdiff
path: root/sfx2
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2020-06-25 14:32:11 +0200
committerMiklos Vajna <vmiklos@collabora.com>2020-06-25 15:41:03 +0200
commitc3f8702241b625db994bcb059d8c91c25fd43e53 (patch)
treecce24d3abf7bb2b4d64b73d27d9840b00004a7a7 /sfx2
parent029a6f72f88612e21093f56939aaf5aefbeadeb1 (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. Change-Id: Ie81996b8f1e8851975b27c43a53f9d23e316004e Reviewed-on: https://gerrit.libreoffice.org/c/core/+/97116 Reviewed-by: Miklos Vajna <vmiklos@collabora.com> Tested-by: Jenkins
Diffstat (limited to 'sfx2')
-rw-r--r--sfx2/source/doc/docfile.cxx22
-rw-r--r--sfx2/source/doc/objserv.cxx3
2 files changed, 18 insertions, 7 deletions
diff --git a/sfx2/source/doc/docfile.cxx b/sfx2/source/doc/docfile.cxx
index 09c6f8cbb6ed..908802be2f33 100644
--- a/sfx2/source/doc/docfile.cxx
+++ b/sfx2/source/doc/docfile.cxx
@@ -42,6 +42,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>
@@ -117,6 +118,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>
@@ -3767,8 +3769,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;
@@ -3784,6 +3787,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;
@@ -3830,7 +3838,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)
{
@@ -3850,8 +3859,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)
{
@@ -3868,7 +3877,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 c2280edfd34b..85406b99ace3 100644
--- a/sfx2/source/doc/objserv.cxx
+++ b/sfx2/source/doc/objserv.cxx
@@ -1928,7 +1928,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);