summaryrefslogtreecommitdiff
path: root/xmlsecurity/source/helper
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2024-09-10 10:11:54 +0200
committerMiklos Vajna <vmiklos@collabora.com>2024-09-10 11:27:46 +0200
commit07df95e75a728fbbce03f6d6efdf9dbceab6c581 (patch)
tree337f1f072bda7ac4e81e64f0c4016572afba94eb /xmlsecurity/source/helper
parent854107d275aac0f4042a154145b95c34543f24c5 (diff)
cool#9992 lok doc sign: async DocumentDigitalSignatures::ImplViewSignatures()
Currently SfxObjectShell::CheckIsReadonly() has a hack for the LOK case to show the signatures dialog read-only, as only that is async. The next step is to make DocumentDigitalSignatures::ImplViewSignatures() async, though that requires all callers of the function to be async, so make DocumentDigitalSignatures::signScriptingContent() async as well. There is also DocumentDigitalSignatures::signPackage(), but turns out that's dead code, so just remove it. Once this is in place, we had a problem that the callbacks tried to interact with libxmlsec, but the dialog was still alive in DocumentDigitalSignatures::ImplViewSignatures() by the time the callback was running, so there were two DocumentSignatureManager instances at the same time, and both assumes it should call the global libxmlsec init/uninit, which resulted in failing to verify the just created signature. Fix this similar to how Tomaz fixed the same problem around pdfium in commit 067a8a954c8e1d8d6465a4ab5fb61e93f16c26c2 (pdfium: only init pdfium library one and destroy on LO exit, 2020-06-03). Change-Id: I3fb63c06195564732e1576dbd755157e676fb762 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/173117 Tested-by: Jenkins Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Diffstat (limited to 'xmlsecurity/source/helper')
-rw-r--r--xmlsecurity/source/helper/documentsignaturemanager.cxx31
1 files changed, 29 insertions, 2 deletions
diff --git a/xmlsecurity/source/helper/documentsignaturemanager.cxx b/xmlsecurity/source/helper/documentsignaturemanager.cxx
index 620c85458afe..f3931a9cdd31 100644
--- a/xmlsecurity/source/helper/documentsignaturemanager.cxx
+++ b/xmlsecurity/source/helper/documentsignaturemanager.cxx
@@ -56,6 +56,33 @@ using namespace css;
using namespace css::graphic;
using namespace css::uno;
+/// RAII class to init / shut down libxmlsec.
+class Xmlsec
+{
+public:
+ Xmlsec();
+ ~Xmlsec();
+};
+
+Xmlsec::Xmlsec() { initXmlSec(); }
+
+Xmlsec::~Xmlsec() { deInitXmlSec(); }
+
+namespace
+{
+/// Shared access to libxmlsec, to avoid double init.
+struct XmlsecLibrary
+{
+ static std::shared_ptr<Xmlsec>& get();
+};
+
+std::shared_ptr<Xmlsec>& XmlsecLibrary::get()
+{
+ static std::shared_ptr<Xmlsec> pInstance = std::make_shared<Xmlsec>();
+ return pInstance;
+}
+}
+
DocumentSignatureManager::DocumentSignatureManager(
const uno::Reference<uno::XComponentContext>& xContext, DocumentSignatureMode eMode)
: mxContext(xContext)
@@ -64,7 +91,7 @@ DocumentSignatureManager::DocumentSignatureManager(
{
}
-DocumentSignatureManager::~DocumentSignatureManager() { deInitXmlSec(); }
+DocumentSignatureManager::~DocumentSignatureManager() { mpXmlsecLibrary.reset(); }
bool DocumentSignatureManager::init()
{
@@ -76,7 +103,7 @@ bool DocumentSignatureManager::init()
"DocumentSignatureManager::Init - mxGpgSEInitializer already set!");
// xmlsec is needed by both services, so init before those
- initXmlSec();
+ mpXmlsecLibrary = XmlsecLibrary::get();
mxSEInitializer = xml::crypto::SEInitializer::create(mxContext);
#if HAVE_FEATURE_GPGME