summaryrefslogtreecommitdiff
path: root/xmlsecurity
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2018-11-09 12:11:46 +0100
committerStephan Bergmann <sbergman@redhat.com>2018-11-09 15:05:18 +0100
commitf0305ec0a7d199e605511844d9d6af98b66d4bfd (patch)
treee35d569af7cb12d8514ee95a984086040095232a /xmlsecurity
parenteadba44a0c5dd12989d6b8613d6dd558c94bb4dc (diff)
Fix creation/removal of GPG socketdir
<https://gerrit.libreoffice.org/#/c/50978/> "gpg4libre: fix failing gpg test due to over-long filenames" had introduced the gb_CppunitTest_run_gpgconf target in xmlsecurity/CppunitTest_xmlsecurity_signing.mk, calling `gpgconf --craete-socketdir`. A 2018-03-18 comment there notes that "Stephan's last comment: (and `gpgconf --remove-sockedir` be called after the test?) is not addressed yet, will do in follow-up commit". Follow-up d7ecf4a4e37a9eeffa2b40f9fe5a2e6a8f90c876 "properly check for gpgconf (and --create-socketdir) working" makes gb_CppunitTest_run_gpgconf conditional. However, in configure.ac, HAVE_GPGCONF_SOCKETDIR=TRUE is missing, so even after follow-up 7a95ee8d0badb2cbbd137a6e18af1bada35ae933 "actually add HAVE_GPGCONF_SOCKETDIR to config_host.mk.in...", config_host.mk will always contain export HAVE_GPGCONF_SOCKETDIR= so gb_CppunitTest_run_gpgconf will never be executed (and `pgconf --crate-socketdir` will never called). But even if it were executed, it would not create the socket dir that the test code in xmlsecurity/qa/unit/signing/signing.cxx is actually using, as gb_CppunitTest_run_gpgconf sets GNUPGHOME=.../workdir/CppunitTest/xmlsecurity_signing.test.user while xmlsecurity/qa/unit/signing/signing.cxx's SigningTest::setUp sets GNUPGHOME=.../workdir//CppunitTest/xmlsecurity_signing.test.user/ and the GPG software is apparently picky about extra slashes when computing the socket dir name from the GNUPGHOME env var. (That `gpgconf --create-socketdir` was never executed with the current setup shows that calling it explicitly is probably not really needed, as the GPG software apparently creates it automatically on demand.) However, what is still missing is to remove the socket dir again (see the comment quoted above), and, probably more importantly, to exit any gpg-agent daemon operating on that socket dir that has (indirectly) been started by the tests in xmlsecurity/qa/unit/signing/signing.cxx. At least with Fedora 29 gpgconf from gnupg2-2.2.9-1.fc29.x86_64, that daemon is successfully terminated by calling `gpgconf --remove-socket`. So move the call to `gpgconf --create-socketdir` from the makefile to the test setup code (which makes it easier to guarantee that a single GNUPGHOME value, and thus a single socket dir, is used), and add a corresponding `gpgconf --remove-socketdir` call to the test shutdown code. (As argued above, the `gpgconf --create-socketdir` call shouldn't be stricktly necessary, but it looks cleaner to do it explicitly anyway.) Change-Id: I2ec8f08943ed63ec27f8507461588ee7cdadf372 Reviewed-on: https://gerrit.libreoffice.org/63181 Reviewed-by: Thorsten Behrens <Thorsten.Behrens@CIB.de> Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'xmlsecurity')
-rw-r--r--xmlsecurity/CppunitTest_xmlsecurity_signing.mk11
-rw-r--r--xmlsecurity/qa/unit/signing/signing.cxx29
2 files changed, 29 insertions, 11 deletions
diff --git a/xmlsecurity/CppunitTest_xmlsecurity_signing.mk b/xmlsecurity/CppunitTest_xmlsecurity_signing.mk
index 2f3ed41e2dfb..6a3cbcab2a58 100644
--- a/xmlsecurity/CppunitTest_xmlsecurity_signing.mk
+++ b/xmlsecurity/CppunitTest_xmlsecurity_signing.mk
@@ -58,17 +58,6 @@ ifeq ($(OS),LINUX)
$(call gb_CppunitTest_get_target,xmlsecurity_signing): \
EXTRA_ENV_VARS := \
LIBO_LD_PATH=$$LD_LIBRARY_PATH
-
-ifneq (,$(HAVE_GPGCONF_SOCKETDIR))
-# create socket dir below /run/user/ instead of in workdir
-.PHONY : gb_CppunitTest_run_gpgconf
-gb_CppunitTest_run_gpgconf:
- GNUPGHOME=$(WORKDIR)/CppunitTest/xmlsecurity_signing.test.user \
- $(GPGCONF) --create-socketdir
-
-$(call gb_CppunitTest_get_target,xmlsecurity_signing): \
- gb_CppunitTest_run_gpgconf
-endif
endif
# vim: set noet sw=4 ts=4:
diff --git a/xmlsecurity/qa/unit/signing/signing.cxx b/xmlsecurity/qa/unit/signing/signing.cxx
index 2a2c38945309..675b825c9995 100644
--- a/xmlsecurity/qa/unit/signing/signing.cxx
+++ b/xmlsecurity/qa/unit/signing/signing.cxx
@@ -12,6 +12,7 @@
#include <sal/config.h>
+#include <cstdlib>
#include <type_traits>
#include <test/bootstrapfixture.hxx>
@@ -59,6 +60,10 @@ class SigningTest : public test::BootstrapFixture, public unotest::MacrosTest, p
uno::Reference<xml::crypto::XSEInitializer> mxSEInitializer;
uno::Reference<xml::crypto::XXMLSecurityContext> mxSecurityContext;
+#if HAVE_GPGCONF_SOCKETDIR
+ OString m_gpgconfCommandPrefix;
+#endif
+
public:
SigningTest();
virtual void setUp() override;
@@ -188,6 +193,22 @@ void SigningTest::setUp()
OUString gpgHomeVar("GNUPGHOME");
osl_setEnvironment(gpgHomeVar.pData, aTargetPath.pData);
+#if HAVE_GPGCONF_SOCKETDIR
+ OString path;
+ bool ok = aTargetPath.convertToString(
+ &path, osl_getThreadTextEncoding(),
+ RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR | RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR);
+ CPPUNIT_ASSERT_MESSAGE(OUStringToOString(aTargetPath, RTL_TEXTENCODING_UTF8).getStr(), ok);
+ // if conversion fails, at least provide a best-effort conversion in the message here, for
+ // context
+ m_gpgconfCommandPrefix = "GNUPGHOME=" + path + " " GPGME_GPGCONF;
+ // HAVE_GPGCONF_SOCKETDIR is only defined in configure.ac for Linux for now, so (a) std::system
+ // behavior will conform to POSIX, and (b) gpgconf --create-socketdir should return zero:
+ OString cmd = m_gpgconfCommandPrefix + " --create-socketdir";
+ int res = std::system(cmd.getStr());
+ CPPUNIT_ASSERT_EQUAL_MESSAGE(cmd.getStr(), 0, res);
+#endif
+
// Initialize crypto after setting up the environment variables.
mxComponentContext.set(comphelper::getComponentContext(getMultiServiceFactory()));
mxDesktop.set(frame::Desktop::create(mxComponentContext));
@@ -200,6 +221,14 @@ void SigningTest::tearDown()
if (mxComponent.is())
mxComponent->dispose();
+#if HAVE_GPGCONF_SOCKETDIR
+ // HAVE_GPGCONF_SOCKETDIR is only defined in configure.ac for Linux for now, so (a) std::system
+ // behavior will conform to POSIX, and (b) gpgconf --remove-socketdir should return zero:
+ OString cmd = m_gpgconfCommandPrefix + " --remove-socketdir";
+ int res = std::system(cmd.getStr());
+ CPPUNIT_ASSERT_EQUAL_MESSAGE(cmd.getStr(), 0, res);
+#endif
+
test::BootstrapFixture::tearDown();
}