From 559765ca62f5e581dd5040bdf24e504cf38b0397 Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Tue, 16 Jun 2020 12:04:09 +0200 Subject: sd signature line: export shape with signature to PDF So that later this can be used when writing the appearance object of the pdf signature. Change-Id: I98517b88723de8ffdc982d4eaae7225289603f1c Reviewed-on: https://gerrit.libreoffice.org/c/core/+/96451 Reviewed-by: Miklos Vajna Tested-by: Jenkins --- xmlsecurity/Library_xmlsecurity.mk | 1 + xmlsecurity/source/helper/pdfsignaturehelper.cxx | 77 +++++++++++++++++++++++- 2 files changed, 76 insertions(+), 2 deletions(-) (limited to 'xmlsecurity') diff --git a/xmlsecurity/Library_xmlsecurity.mk b/xmlsecurity/Library_xmlsecurity.mk index 038276c1725b..0071357881c7 100644 --- a/xmlsecurity/Library_xmlsecurity.mk +++ b/xmlsecurity/Library_xmlsecurity.mk @@ -33,6 +33,7 @@ $(eval $(call gb_Library_use_libraries,xmlsecurity,\ sal \ sax \ svl \ + sfx \ svt \ svxcore \ tl \ diff --git a/xmlsecurity/source/helper/pdfsignaturehelper.cxx b/xmlsecurity/source/helper/pdfsignaturehelper.cxx index 809e089b0f4f..614d8e694e07 100644 --- a/xmlsecurity/source/helper/pdfsignaturehelper.cxx +++ b/xmlsecurity/source/helper/pdfsignaturehelper.cxx @@ -17,16 +17,86 @@ #include #include #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include #include -#include -#include using namespace ::com::sun::star; +namespace +{ +/// If the currently selected shape is a Draw signature line, export that to PDF. +void GetSignatureLineShape(std::vector& rSignatureLineShape) +{ + SfxObjectShell* pObjectShell = SfxObjectShell::Current(); + if (!pObjectShell) + { + return; + } + + uno::Reference xModel = pObjectShell->GetBaseModel(); + if (!xModel.is()) + { + return; + } + + uno::Reference xShapes(xModel->getCurrentSelection(), uno::UNO_QUERY); + if (!xShapes.is() || xShapes->getCount() < 1) + { + return; + } + + uno::Reference xShapeProps(xShapes->getByIndex(0), uno::UNO_QUERY); + if (!xShapeProps.is()) + { + return; + } + + comphelper::SequenceAsHashMap aMap(xShapeProps->getPropertyValue("InteropGrabBag")); + auto it = aMap.find("SignatureCertificate"); + if (it == aMap.end()) + { + return; + } + + // We know that we add a signature line shape to an existing PDF at this point. + + uno::Reference xStorable(xModel, uno::UNO_QUERY); + if (!xStorable.is()) + { + return; + } + + // Export just the signature line. + utl::MediaDescriptor aMediaDescriptor; + aMediaDescriptor["FilterName"] <<= OUString("draw_pdf_Export"); + SvMemoryStream aStream; + uno::Reference xStream(new utl::OStreamWrapper(aStream)); + aMediaDescriptor["OutputStream"] <<= xStream; + uno::Sequence aFilterData( + comphelper::InitPropertySequence({ { "Selection", uno::Any(xShapes) } })); + aMediaDescriptor["FilterData"] <<= aFilterData; + xStorable->storeToURL("private:stream", aMediaDescriptor.getAsConstPropertyValueList()); + xStream->flush(); + + aStream.Seek(0); + rSignatureLineShape = std::vector(aStream.GetSize()); + aStream.ReadBytes(rSignatureLineShape.data(), rSignatureLineShape.size()); +} +} + PDFSignatureHelper::PDFSignatureHelper() = default; bool PDFSignatureHelper::ReadAndVerifySignature( @@ -130,6 +200,9 @@ bool PDFSignatureHelper::Sign(const uno::Reference& xInputStre return false; } + std::vector aSignatureLineShape; + GetSignatureLineShape(aSignatureLineShape); + if (!aDocument.Sign(m_xCertificate, m_aDescription, bAdES)) { SAL_WARN("xmlsecurity.helper", "failed to sign"); -- cgit