diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2020-06-25 14:32:11 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2020-06-25 15:41:03 +0200 |
commit | c3f8702241b625db994bcb059d8c91c25fd43e53 (patch) | |
tree | cce24d3abf7bb2b4d64b73d27d9840b00004a7a7 /xmlsecurity | |
parent | 029a6f72f88612e21093f56939aaf5aefbeadeb1 (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 'xmlsecurity')
-rw-r--r-- | xmlsecurity/inc/documentsignaturemanager.hxx | 6 | ||||
-rw-r--r-- | xmlsecurity/inc/pdfsignaturehelper.hxx | 7 | ||||
-rw-r--r-- | xmlsecurity/source/component/documentdigitalsignatures.cxx | 51 | ||||
-rw-r--r-- | xmlsecurity/source/helper/documentsignaturemanager.cxx | 8 | ||||
-rw-r--r-- | xmlsecurity/source/helper/pdfsignaturehelper.cxx | 15 |
5 files changed, 63 insertions, 24 deletions
diff --git a/xmlsecurity/inc/documentsignaturemanager.hxx b/xmlsecurity/inc/documentsignaturemanager.hxx index 3d001966f3b0..e7149c3fe195 100644 --- a/xmlsecurity/inc/documentsignaturemanager.hxx +++ b/xmlsecurity/inc/documentsignaturemanager.hxx @@ -44,6 +44,10 @@ namespace embed { class XStorage; } +namespace frame +{ +class XModel; +} namespace graphic { class XGraphic; @@ -69,6 +73,7 @@ private: DocumentSignatureMode const meSignatureMode; css::uno::Sequence<css::uno::Sequence<css::beans::PropertyValue>> m_manifest; css::uno::Reference<css::io::XStream> mxSignatureStream; + css::uno::Reference<css::frame::XModel> mxModel; css::uno::Reference<css::io::XStream> mxTempSignatureStream; /// Storage containing all OOXML signatures, unused for ODF. css::uno::Reference<css::embed::XStorage> mxTempSignatureStorage; @@ -125,6 +130,7 @@ public: { mxSignatureStream = xSignatureStream; } + void setModel(const css::uno::Reference<css::frame::XModel>& xModel); const css::uno::Reference<css::embed::XStorage>& getStore() const { return mxStore; } DocumentSignatureMode getSignatureMode() const { return meSignatureMode; } SignatureInformations& getCurrentSignatureInformations() diff --git a/xmlsecurity/inc/pdfsignaturehelper.hxx b/xmlsecurity/inc/pdfsignaturehelper.hxx index f23a371d2820..f8f1e893beb2 100644 --- a/xmlsecurity/inc/pdfsignaturehelper.hxx +++ b/xmlsecurity/inc/pdfsignaturehelper.hxx @@ -21,6 +21,10 @@ namespace sun { namespace star { +namespace frame +{ +class XModel; +} namespace io { class XInputStream; @@ -67,7 +71,8 @@ public: /// Comment / reason to be used next time signing is performed. void SetDescription(const OUString& rDescription); /// Append a new signature at the end of xInputStream. - bool Sign(const css::uno::Reference<css::io::XInputStream>& xInputStream, bool bAdES); + bool Sign(const css::uno::Reference<css::frame::XModel>& xModel, + const css::uno::Reference<css::io::XInputStream>& xInputStream, bool bAdES); /// 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); diff --git a/xmlsecurity/source/component/documentdigitalsignatures.cxx b/xmlsecurity/source/component/documentdigitalsignatures.cxx index d149bf5e30b2..3baab59e03ac 100644 --- a/xmlsecurity/source/component/documentdigitalsignatures.cxx +++ b/xmlsecurity/source/component/documentdigitalsignatures.cxx @@ -57,6 +57,7 @@ #include <com/sun/star/lang/IllegalArgumentException.hpp> #include <com/sun/star/security/XDocumentDigitalSignatures.hpp> #include <com/sun/star/xml/crypto/XXMLSecurityContext.hpp> +#include <sfx2/digitalsignatures.hxx> #include <map> @@ -67,10 +68,10 @@ using namespace css::security; using namespace css::xml::crypto; namespace { - class DocumentDigitalSignatures : public cppu::WeakImplHelper<css::security::XDocumentDigitalSignatures, - css::lang::XInitialization, css::lang::XServiceInfo> + css::lang::XInitialization, css::lang::XServiceInfo>, + public sfx2::DigitalSignatures { private: css::uno::Reference<css::uno::XComponentContext> mxCtx; @@ -103,12 +104,14 @@ private: chooseCertificatesImpl(std::map<OUString, OUString>& rProperties, const UserAction eAction, const CertificateKind certificateKind=CertificateKind_NONE); - bool signWithCertificateImpl( - css::uno::Reference<css::security::XCertificate> const& xCertificate, - css::uno::Reference<css::embed::XStorage> const& xStorage, - css::uno::Reference<css::io::XStream> const& xStream, DocumentSignatureMode eMode); + bool + signWithCertificateImpl(const uno::Reference<frame::XModel>& /*xModel*/, + css::uno::Reference<css::security::XCertificate> const& xCertificate, + css::uno::Reference<css::embed::XStorage> const& xStorage, + css::uno::Reference<css::io::XStream> const& xStream, + DocumentSignatureMode eMode); - public: +public: explicit DocumentDigitalSignatures( const css::uno::Reference<css::uno::XComponentContext>& rxCtx); @@ -205,6 +208,13 @@ private: { mxParentWindow = rParentwindow; } + + /// See sfx2::DigitalSignatures::SignModelWithCertificate(). + bool + SignModelWithCertificate(const css::uno::Reference<css::frame::XModel>& xModel, + const css::uno::Reference<css::security::XCertificate>& xCertificate, + const css::uno::Reference<css::embed::XStorage>& xStorage, + const css::uno::Reference<css::io::XStream>& xStream) override; }; } @@ -785,7 +795,19 @@ sal_Bool DocumentDigitalSignatures::signDocumentWithCertificate( css::uno::Reference<css::embed::XStorage> const & xStorage, css::uno::Reference<css::io::XStream> const & xStream) { - return signWithCertificateImpl(xCertificate, xStorage, xStream, DocumentSignatureMode::Content); + uno::Reference<frame::XModel> xModel; + return signWithCertificateImpl(xModel, xCertificate, xStorage, xStream, + DocumentSignatureMode::Content); +} + +bool DocumentDigitalSignatures::SignModelWithCertificate( + const uno::Reference<frame::XModel>& xModel, + const css::uno::Reference<css::security::XCertificate>& xCertificate, + const css::uno::Reference<css::embed::XStorage>& xStorage, + const css::uno::Reference<css::io::XStream>& xStream) +{ + return signWithCertificateImpl(xModel, xCertificate, xStorage, xStream, + DocumentSignatureMode::Content); } sal_Bool DocumentDigitalSignatures::signPackageWithCertificate( @@ -793,7 +815,9 @@ sal_Bool DocumentDigitalSignatures::signPackageWithCertificate( css::uno::Reference<css::embed::XStorage> const& xStorage, css::uno::Reference<css::io::XStream> const& xStream) { - return signWithCertificateImpl(xCertificate, xStorage, xStream, DocumentSignatureMode::Package); + uno::Reference<frame::XModel> xModel; + return signWithCertificateImpl(xModel, xCertificate, xStorage, xStream, + DocumentSignatureMode::Package); } sal_Bool DocumentDigitalSignatures::signScriptingContentWithCertificate( @@ -801,14 +825,16 @@ sal_Bool DocumentDigitalSignatures::signScriptingContentWithCertificate( css::uno::Reference<css::embed::XStorage> const& xStorage, css::uno::Reference<css::io::XStream> const& xStream) { - return signWithCertificateImpl(xCertificate, xStorage, xStream, DocumentSignatureMode::Macros); + uno::Reference<frame::XModel> xModel; + return signWithCertificateImpl(xModel, xCertificate, xStorage, xStream, + DocumentSignatureMode::Macros); } bool DocumentDigitalSignatures::signWithCertificateImpl( + const uno::Reference<frame::XModel>& xModel, css::uno::Reference<css::security::XCertificate> const& xCertificate, css::uno::Reference<css::embed::XStorage> const& xStorage, - css::uno::Reference<css::io::XStream> const& xStream, - DocumentSignatureMode eMode) + css::uno::Reference<css::io::XStream> const& xStream, DocumentSignatureMode eMode) { OSL_ENSURE(!m_sODFVersion.isEmpty(), "DocumentDigitalSignatures: ODF Version not set, assuming minimum 1.2"); @@ -821,6 +847,7 @@ bool DocumentDigitalSignatures::signWithCertificateImpl( aSignatureManager.setStore(xStorage); aSignatureManager.getSignatureHelper().SetStorage(xStorage, m_sODFVersion); aSignatureManager.setSignatureStream(xStream); + aSignatureManager.setModel(xModel); Reference<XXMLSecurityContext> xSecurityContext = aSignatureManager.getSecurityContext(); diff --git a/xmlsecurity/source/helper/documentsignaturemanager.cxx b/xmlsecurity/source/helper/documentsignaturemanager.cxx index 79d2cdf26b61..295522775951 100644 --- a/xmlsecurity/source/helper/documentsignaturemanager.cxx +++ b/xmlsecurity/source/helper/documentsignaturemanager.cxx @@ -35,6 +35,7 @@ #include <com/sun/star/container/XNameAccess.hpp> #include <com/sun/star/xml/sax/XDocumentHandler.hpp> #include <com/sun/star/xml/sax/XWriter.hpp> +#include <com/sun/star/frame/XModel.hpp> #include <comphelper/base64.hxx> #include <comphelper/storagehelper.hxx> @@ -359,7 +360,7 @@ bool DocumentSignatureManager::add( getPDFSignatureHelper().SetX509Certificate(xCert); getPDFSignatureHelper().SetDescription(rDescription); uno::Reference<io::XInputStream> xInputStream(mxSignatureStream, uno::UNO_QUERY); - if (!getPDFSignatureHelper().Sign(xInputStream, bAdESCompliant)) + if (!getPDFSignatureHelper().Sign(mxModel, xInputStream, bAdESCompliant)) { SAL_WARN("xmlsecurity.helper", "PDFSignatureHelper::Sign() failed"); return false; @@ -684,4 +685,9 @@ DocumentSignatureManager::getGpgSecurityContext() const return mxGpgSecurityContext; } +void DocumentSignatureManager::setModel(const uno::Reference<frame::XModel>& xModel) +{ + mxModel = xModel; +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmlsecurity/source/helper/pdfsignaturehelper.cxx b/xmlsecurity/source/helper/pdfsignaturehelper.cxx index 79979c715bff..fe65745b3e90 100644 --- a/xmlsecurity/source/helper/pdfsignaturehelper.cxx +++ b/xmlsecurity/source/helper/pdfsignaturehelper.cxx @@ -57,15 +57,9 @@ bool GetSignatureLinePage(const uno::Reference<frame::XModel>& xModel, sal_Int32 } /// If the currently selected shape is a Draw signature line, export that to PDF. -void GetSignatureLineShape(sal_Int32& rPage, std::vector<sal_Int8>& rSignatureLineShape) +void GetSignatureLineShape(const uno::Reference<frame::XModel>& xModel, sal_Int32& rPage, + std::vector<sal_Int8>& rSignatureLineShape) { - SfxObjectShell* pObjectShell = SfxObjectShell::Current(); - if (!pObjectShell) - { - return; - } - - uno::Reference<frame::XModel> xModel = pObjectShell->GetBaseModel(); if (!xModel.is()) { return; @@ -214,7 +208,8 @@ void PDFSignatureHelper::SetDescription(const OUString& rDescription) m_aDescription = rDescription; } -bool PDFSignatureHelper::Sign(const uno::Reference<io::XInputStream>& xInputStream, bool bAdES) +bool PDFSignatureHelper::Sign(const uno::Reference<frame::XModel>& xModel, + const uno::Reference<io::XInputStream>& xInputStream, bool bAdES) { std::unique_ptr<SvStream> pStream(utl::UcbStreamHelper::CreateStream(xInputStream, true)); vcl::filter::PDFDocument aDocument; @@ -226,7 +221,7 @@ bool PDFSignatureHelper::Sign(const uno::Reference<io::XInputStream>& xInputStre sal_Int32 nPage = 0; std::vector<sal_Int8> aSignatureLineShape; - GetSignatureLineShape(nPage, aSignatureLineShape); + GetSignatureLineShape(xModel, nPage, aSignatureLineShape); if (nPage > 0) { // UNO page number is 1-based. |