xmlsecurity/inc/pdfsignaturehelper.hxx | 2 xmlsecurity/source/helper/documentsignaturemanager.cxx | 15 +++++++ xmlsecurity/source/helper/pdfsignaturehelper.cxx | 35 +++++++++++++++++ 3 files changed, 52 insertions(+)
New commits: commit 51593c41efd7471777adb520814dede4d3f51044 Author: Miklos Vajna <vmik...@collabora.co.uk> Date: Mon Oct 24 14:41:18 2016 +0200 xmlsecurity: implement PDF signature removal UI Unlike with ZIP-based storage, it can happen that the removal fails, so make sure we only remove the signature from the listbox when PDFDocument::RemoveSignature() succeeds. Change-Id: I3241fc11425686bc1ea5452b8f602e053aec0769 Reviewed-on: https://gerrit.libreoffice.org/30224 Reviewed-by: Miklos Vajna <vmik...@collabora.co.uk> Tested-by: Jenkins <c...@libreoffice.org> diff --git a/xmlsecurity/inc/pdfsignaturehelper.hxx b/xmlsecurity/inc/pdfsignaturehelper.hxx index bae8d3c..cd9a3e2 100644 --- a/xmlsecurity/inc/pdfsignaturehelper.hxx +++ b/xmlsecurity/inc/pdfsignaturehelper.hxx @@ -46,6 +46,8 @@ public: void SetDescription(const OUString& rDescription); /// Append a new signature at the end of xInputStream. bool Sign(const css::uno::Reference<css::io::XInputStream>& xInputStream); + /// Remove the signature at nPosition (and all dependent signatures) from xInputStream. + static bool RemoveSignature(const css::uno::Reference<css::io::XInputStream>& xInputStream, sal_uInt16 nPosition); }; #endif // INCLUDED_XMLSECURITY_INC_PDFSIGNATUREHELPER_HXX diff --git a/xmlsecurity/source/helper/documentsignaturemanager.cxx b/xmlsecurity/source/helper/documentsignaturemanager.cxx index 1db2319..0a5568f 100644 --- a/xmlsecurity/source/helper/documentsignaturemanager.cxx +++ b/xmlsecurity/source/helper/documentsignaturemanager.cxx @@ -313,6 +313,21 @@ bool DocumentSignatureManager::add(const uno::Reference<security::XCertificate>& void DocumentSignatureManager::remove(sal_uInt16 nPosition) { + if (!mxStore.is()) + { + // Something not ZIP based, try PDF. + uno::Reference<io::XInputStream> xInputStream(mxSignatureStream, uno::UNO_QUERY); + if (PDFSignatureHelper::RemoveSignature(xInputStream, nPosition)) + { + SAL_WARN("xmlsecurity.helper", "PDFSignatureHelper::RemoveSignature() failed"); + return; + } + + // Only erase when the removal was successfull, it may fail for PDF. + maCurrentSignatureInformations.erase(maCurrentSignatureInformations.begin() + nPosition); + return; + } + maCurrentSignatureInformations.erase(maCurrentSignatureInformations.begin() + nPosition); // Export all other signatures... diff --git a/xmlsecurity/source/helper/pdfsignaturehelper.cxx b/xmlsecurity/source/helper/pdfsignaturehelper.cxx index fdd4ed8..a1b1d20 100644 --- a/xmlsecurity/source/helper/pdfsignaturehelper.cxx +++ b/xmlsecurity/source/helper/pdfsignaturehelper.cxx @@ -11,6 +11,7 @@ #include <memory> +#include <com/sun/star/io/XTruncate.hpp> #include <com/sun/star/security/CertificateValidity.hpp> #include <com/sun/star/xml/crypto/SEInitializer.hpp> @@ -148,4 +149,38 @@ bool PDFSignatureHelper::Sign(const uno::Reference<io::XInputStream>& xInputStre return true; } +bool PDFSignatureHelper::RemoveSignature(const uno::Reference<io::XInputStream>& xInputStream, sal_uInt16 nPosition) +{ + std::unique_ptr<SvStream> pStream(utl::UcbStreamHelper::CreateStream(xInputStream, true)); + xmlsecurity::pdfio::PDFDocument aDocument; + if (!aDocument.Read(*pStream)) + { + SAL_WARN("xmlsecurity.helper", "failed to read the document"); + return false; + } + + if (!aDocument.RemoveSignature(nPosition)) + { + SAL_WARN("xmlsecurity.helper", "failed to remove signature"); + return false; + } + + uno::Reference<io::XStream> xStream(xInputStream, uno::UNO_QUERY); + uno::Reference<io::XTruncate> xTruncate(xStream, uno::UNO_QUERY); + if (!xTruncate.is()) + { + SAL_WARN("xmlsecurity.helper", "failed to truncate"); + return false; + } + xTruncate->truncate(); + std::unique_ptr<SvStream> pOutStream(utl::UcbStreamHelper::CreateStream(xStream, true)); + if (!aDocument.Write(*pOutStream)) + { + SAL_WARN("xmlsecurity.helper", "failed to write without signature"); + return false; + } + + return true; +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits