diff options
Diffstat (limited to 'lang/qt/tests')
38 files changed, 0 insertions, 7756 deletions
diff --git a/lang/qt/tests/Makefile.am b/lang/qt/tests/Makefile.am deleted file mode 100644 index ee168b75..00000000 --- a/lang/qt/tests/Makefile.am +++ /dev/null @@ -1,424 +0,0 @@ -# Makefile.am - Makefile for QGpgME tests. -# Copyright (C) 2016 Bundesamt für Sicherheit in der Informationstechnik -# Software engineering by Intevation GmbH -# -# This file is part of QGpgME. -# -# QGpgME is free software; you can redistribute it and/or modify it -# under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# QGpgME is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, see <https://gnu.org/licenses/>. -# SPDX-License-Identifier: GPL-2.0-or-later - -## Process this file with automake to produce Makefile.in - -GPG = gpg - -GNUPGHOME=$(abs_builddir) -TESTS_ENVIRONMENT = GNUPGHOME=$(GNUPGHOME) - -EXTRA_DIST = initial.test final.test - -if WANT_QT5 -the_tests5 = \ - t-addexistingsubkey5 \ - t-changeexpiryjob5 \ - t-config5 \ - t-decryptverify5 \ - t-disablekey5 \ - t-encrypt5 \ - t-import5 \ - t-keylist5 \ - t-keylocate5 \ - t-ownertrust5 \ - t-remarks5 \ - t-revokekey5 \ - t-setprimaryuserid5 \ - t-tofuinfo5 \ - t-trustsignatures5 \ - t-various5 \ - t-verify5 \ - t-wkdlookup5 -# disabled test: t-wkspublish5 -the_runners5 = \ - run-decryptverifyarchivejob5 \ - run-decryptverifyjob5 \ - run-encryptarchivejob5 \ - run-encryptjob5 \ - run-exportjob5 \ - run-importjob5 \ - run-keyformailboxjob5 \ - run-receivekeysjob5 \ - run-refreshkeysjob5 \ - run-signarchivejob5 \ - run-signjob5 \ - run-verifydetachedjob5 \ - run-verifyopaquejob5 \ - run-wkdrefreshjob5 -endif -if WANT_QT6 -the_tests6 = \ - t-addexistingsubkey6 \ - t-changeexpiryjob6 \ - t-config6 \ - t-decryptverify6 \ - t-disablekey6 \ - t-encrypt6 \ - t-import6 \ - t-keylist6 \ - t-keylocate6 \ - t-ownertrust6 \ - t-remarks6 \ - t-revokekey6 \ - t-setprimaryuserid6 \ - t-tofuinfo6 \ - t-trustsignatures6 \ - t-various6 \ - t-verify6 \ - t-wkdlookup6 -# disabled test: t-wkspublish6 -the_runners6 = \ - run-decryptverifyarchivejob6 \ - run-decryptverifyjob6 \ - run-encryptarchivejob6 \ - run-encryptjob6 \ - run-exportjob6 \ - run-importjob6 \ - run-keyformailboxjob6 \ - run-receivekeysjob6 \ - run-refreshkeysjob6 \ - run-signarchivejob6 \ - run-signjob6 \ - run-verifydetachedjob6 \ - run-verifyopaquejob6 \ - run-wkdrefreshjob6 -endif - -TESTS = initial.test $(the_tests5) $(the_tests6) final.test - -# define .moc files for all tests; we'll moc their .cpp files -# the only header that needs to be moc'd (t-support.h) is handled individually -# moc_files = $(the_tests:%=%.moc) - -# generate the moc files in two steps: -# 1. generate Qt 5/6-specific moc files in builddir with extension .moc5/.moc6; -# this ensures correct dependencies on the source files -# 2. generate forwarding headers in subfolders moc5/moc6 with extension .moc; -# this ensures that the "foo.moc" includes in the source files work and -# include the correct version of the generated moc files for Qt 5/6 -# GNU make's pattern rules would make this easier, but we don't want to use them -if WANT_QT5 -moc5_dir = moc5 -moc5_files = $(moc5_dir)/t-support.hmoc $(the_tests5:%5=%.moc5) -moc5_forward_headers = $(the_tests5:%5=$(moc5_dir)/%.moc) - -$(moc5_dir)/t-support.hmoc: t-support.h | $(moc5_dir) - $(MOC5) `test -f '$<' || echo '$(srcdir)/'`$< -o $@ - -.cpp.moc5: - $(MOC5) `test -f '$<' || echo '$(srcdir)/'`$< -o $@ - -$(moc5_dir): - mkdir $(moc5_dir) - -$(moc5_forward_headers): Makefile.am | $(moc5_dir) - echo "#include \"../$(notdir $@)5\"" > "$@" -endif -if WANT_QT6 -moc6_dir = moc6 -moc6_files = $(moc6_dir)/t-support.hmoc $(the_tests6:%6=%.moc6) -moc6_forward_headers = $(the_tests6:%6=$(moc6_dir)/%.moc) - -$(moc6_dir)/t-support.hmoc: t-support.h | $(moc6_dir) - $(MOC6) `test -f '$<' || echo '$(srcdir)/'`$< -o $@ - -.cpp.moc6: - $(MOC6) `test -f '$<' || echo '$(srcdir)/'`$< -o $@ - -$(moc6_dir): - mkdir $(moc6_dir) - -$(moc6_forward_headers): Makefile.am | $(moc6_dir) - echo "#include \"../$(notdir $@)6\"" > "$@" -endif - -AM_LDFLAGS = -no-install - -if WANT_QT5 -ldadd_qt5 = ../../cpp/src/libgpgmepp.la ../src/libqgpgme.la \ - ../../../src/libgpgme.la @GPGME_QT5_LIBS@ @GPG_ERROR_LIBS@ \ - @GPGME_QT5TEST_LIBS@ @LDADD_FOR_TESTS_KLUDGE@ -lstdc++ - -cppflags_qt5 = -I$(moc5_dir) -I$(top_srcdir)/lang/qt/src -I$(top_builddir)/lang/cpp/src \ - -I$(top_builddir)/src \ - @GPG_ERROR_CFLAGS@ @GPGME_QT5_CFLAGS@ @GPG_ERROR_CFLAGS@ \ - @LIBASSUAN_CFLAGS@ @GPGME_QT5TEST_CFLAGS@ -DBUILDING_QGPGME \ - -DTOP_SRCDIR="$(top_srcdir)" -endif -if WANT_QT6 -ldadd_qt6 = ../../cpp/src/libgpgmepp.la ../src/libqgpgmeqt6.la \ - ../../../src/libgpgme.la @GPGME_QT6_LIBS@ @GPG_ERROR_LIBS@ \ - @GPGME_QT6TEST_LIBS@ @LDADD_FOR_TESTS_KLUDGE@ -lstdc++ - -cppflags_qt6 = -I$(moc6_dir) -I$(top_srcdir)/lang/qt/src -I$(top_builddir)/lang/cpp/src \ - -I$(top_builddir)/src \ - @GPG_ERROR_CFLAGS@ @GPGME_QT6_CFLAGS@ @GPG_ERROR_CFLAGS@ \ - @LIBASSUAN_CFLAGS@ @GPGME_QT6TEST_CFLAGS@ -DBUILDING_QGPGME \ - -DTOP_SRCDIR="$(top_srcdir)" -endif - -support_src = t-support.h t-support.cpp - -if WANT_QT5 -t_addexistingsubkey5_SOURCES = t-addexistingsubkey.cpp $(support_src) -t_addexistingsubkey5_LDADD = $(ldadd_qt5) -t_addexistingsubkey5_CPPFLAGS = $(cppflags_qt5) -t_changeexpiryjob5_SOURCES = t-changeexpiryjob.cpp $(support_src) -t_changeexpiryjob5_LDADD = $(ldadd_qt5) -t_changeexpiryjob5_CPPFLAGS = $(cppflags_qt5) -t_config5_SOURCES = t-config.cpp $(support_src) -t_config5_LDADD = $(ldadd_qt5) -t_config5_CPPFLAGS = $(cppflags_qt5) -t_decryptverify5_SOURCES = t-decryptverify.cpp $(support_src) -t_decryptverify5_LDADD = $(ldadd_qt5) -t_decryptverify5_CPPFLAGS = $(cppflags_qt5) -t_disablekey5_SOURCES = t-disablekey.cpp $(support_src) -t_disablekey5_LDADD = $(ldadd_qt5) -t_disablekey5_CPPFLAGS = $(cppflags_qt5) -t_encrypt5_SOURCES = t-encrypt.cpp $(support_src) -t_encrypt5_LDADD = $(ldadd_qt5) -t_encrypt5_CPPFLAGS = $(cppflags_qt5) -t_import5_SOURCES = t-import.cpp $(support_src) -t_import5_LDADD = $(ldadd_qt5) -t_import5_CPPFLAGS = $(cppflags_qt5) -t_keylist5_SOURCES = t-keylist.cpp $(support_src) -t_keylist5_LDADD = $(ldadd_qt5) -t_keylist5_CPPFLAGS = $(cppflags_qt5) -t_keylocate5_SOURCES = t-keylocate.cpp $(support_src) -t_keylocate5_LDADD = $(ldadd_qt5) -t_keylocate5_CPPFLAGS = $(cppflags_qt5) -t_ownertrust5_SOURCES = t-ownertrust.cpp $(support_src) -t_ownertrust5_LDADD = $(ldadd_qt5) -t_ownertrust5_CPPFLAGS = $(cppflags_qt5) -t_remarks5_SOURCES = t-remarks.cpp $(support_src) -t_remarks5_LDADD = $(ldadd_qt5) -t_remarks5_CPPFLAGS = $(cppflags_qt5) -t_revokekey5_SOURCES = t-revokekey.cpp $(support_src) -t_revokekey5_LDADD = $(ldadd_qt5) -t_revokekey5_CPPFLAGS = $(cppflags_qt5) -t_setprimaryuserid5_SOURCES = t-setprimaryuserid.cpp $(support_src) -t_setprimaryuserid5_LDADD = $(ldadd_qt5) -t_setprimaryuserid5_CPPFLAGS = $(cppflags_qt5) -t_tofuinfo5_SOURCES = t-tofuinfo.cpp $(support_src) -t_tofuinfo5_LDADD = $(ldadd_qt5) -t_tofuinfo5_CPPFLAGS = $(cppflags_qt5) -t_trustsignatures5_SOURCES = t-trustsignatures.cpp $(support_src) -t_trustsignatures5_LDADD = $(ldadd_qt5) -t_trustsignatures5_CPPFLAGS = $(cppflags_qt5) -t_various5_SOURCES = t-various.cpp $(support_src) -t_various5_LDADD = $(ldadd_qt5) -t_various5_CPPFLAGS = $(cppflags_qt5) -t_verify5_SOURCES = t-verify.cpp $(support_src) -t_verify5_LDADD = $(ldadd_qt5) -t_verify5_CPPFLAGS = $(cppflags_qt5) -t_wkdlookup5_SOURCES = t-wkdlookup.cpp $(support_src) -t_wkdlookup5_LDADD = $(ldadd_qt5) -t_wkdlookup5_CPPFLAGS = $(cppflags_qt5) -# t_wkspublish5_SOURCES = t-wkspublish.cpp $(support_src) -# t_wkspublish5_LDADD = $(ldadd_qt5) -# t_wkspublish5_CPPFLAGS = $(cppflags_qt5) -run_decryptverifyarchivejob5_SOURCES = run-decryptverifyarchivejob.cpp -run_decryptverifyarchivejob5_LDADD = $(ldadd_qt5) -run_decryptverifyarchivejob5_CPPFLAGS = $(cppflags_qt5) -run_decryptverifyjob5_SOURCES = run-decryptverifyjob.cpp -run_decryptverifyjob5_LDADD = $(ldadd_qt5) -run_decryptverifyjob5_CPPFLAGS = $(cppflags_qt5) -run_encryptarchivejob5_SOURCES = run-encryptarchivejob.cpp -run_encryptarchivejob5_LDADD = $(ldadd_qt5) -run_encryptarchivejob5_CPPFLAGS = $(cppflags_qt5) -run_encryptjob5_SOURCES = run-encryptjob.cpp -run_encryptjob5_LDADD = $(ldadd_qt5) -run_encryptjob5_CPPFLAGS = $(cppflags_qt5) -run_exportjob5_SOURCES = run-exportjob.cpp -run_exportjob5_LDADD = $(ldadd_qt5) -run_exportjob5_CPPFLAGS = $(cppflags_qt5) -run_importjob5_SOURCES = run-importjob.cpp -run_importjob5_LDADD = $(ldadd_qt5) -run_importjob5_CPPFLAGS = $(cppflags_qt5) -run_keyformailboxjob5_SOURCES = run-keyformailboxjob.cpp -run_keyformailboxjob5_LDADD = $(ldadd_qt5) -run_keyformailboxjob5_CPPFLAGS = $(cppflags_qt5) -run_receivekeysjob5_SOURCES = run-receivekeysjob.cpp -run_receivekeysjob5_LDADD = $(ldadd_qt5) -run_receivekeysjob5_CPPFLAGS = $(cppflags_qt5) -run_refreshkeysjob5_SOURCES = run-refreshkeysjob.cpp -run_refreshkeysjob5_LDADD = $(ldadd_qt5) -run_refreshkeysjob5_CPPFLAGS = $(cppflags_qt5) -run_signarchivejob5_SOURCES = run-signarchivejob.cpp -run_signarchivejob5_LDADD = $(ldadd_qt5) -run_signarchivejob5_CPPFLAGS = $(cppflags_qt5) -run_signjob5_SOURCES = run-signjob.cpp -run_signjob5_LDADD = $(ldadd_qt5) -run_signjob5_CPPFLAGS = $(cppflags_qt5) -run_verifydetachedjob5_SOURCES = run-verifydetachedjob.cpp -run_verifydetachedjob5_LDADD = $(ldadd_qt5) -run_verifydetachedjob5_CPPFLAGS = $(cppflags_qt5) -run_verifyopaquejob5_SOURCES = run-verifyopaquejob.cpp -run_verifyopaquejob5_LDADD = $(ldadd_qt5) -run_verifyopaquejob5_CPPFLAGS = $(cppflags_qt5) -run_wkdrefreshjob5_SOURCES = run-wkdrefreshjob.cpp -run_wkdrefreshjob5_LDADD = $(ldadd_qt5) -run_wkdrefreshjob5_CPPFLAGS = $(cppflags_qt5) - -#nodist_t_keylist5_SOURCES = $(moc5_files) $(moc5_forward_headers) -endif -if WANT_QT6 -t_addexistingsubkey6_SOURCES = t-addexistingsubkey.cpp $(support_src) -t_addexistingsubkey6_LDADD = $(ldadd_qt6) -t_addexistingsubkey6_CPPFLAGS = $(cppflags_qt6) -t_changeexpiryjob6_SOURCES = t-changeexpiryjob.cpp $(support_src) -t_changeexpiryjob6_LDADD = $(ldadd_qt6) -t_changeexpiryjob6_CPPFLAGS = $(cppflags_qt6) -t_config6_SOURCES = t-config.cpp $(support_src) -t_config6_LDADD = $(ldadd_qt6) -t_config6_CPPFLAGS = $(cppflags_qt6) -t_decryptverify6_SOURCES = t-decryptverify.cpp $(support_src) -t_decryptverify6_LDADD = $(ldadd_qt6) -t_decryptverify6_CPPFLAGS = $(cppflags_qt6) -t_disablekey6_SOURCES = t-disablekey.cpp $(support_src) -t_disablekey6_LDADD = $(ldadd_qt6) -t_disablekey6_CPPFLAGS = $(cppflags_qt6) -t_encrypt6_SOURCES = t-encrypt.cpp $(support_src) -t_encrypt6_LDADD = $(ldadd_qt6) -t_encrypt6_CPPFLAGS = $(cppflags_qt6) -t_import6_SOURCES = t-import.cpp $(support_src) -t_import6_LDADD = $(ldadd_qt6) -t_import6_CPPFLAGS = $(cppflags_qt6) -t_keylist6_SOURCES = t-keylist.cpp $(support_src) -t_keylist6_LDADD = $(ldadd_qt6) -t_keylist6_CPPFLAGS = $(cppflags_qt6) -t_keylocate6_SOURCES = t-keylocate.cpp $(support_src) -t_keylocate6_LDADD = $(ldadd_qt6) -t_keylocate6_CPPFLAGS = $(cppflags_qt6) -t_ownertrust6_SOURCES = t-ownertrust.cpp $(support_src) -t_ownertrust6_LDADD = $(ldadd_qt6) -t_ownertrust6_CPPFLAGS = $(cppflags_qt6) -t_remarks6_SOURCES = t-remarks.cpp $(support_src) -t_remarks6_LDADD = $(ldadd_qt6) -t_remarks6_CPPFLAGS = $(cppflags_qt6) -t_revokekey6_SOURCES = t-revokekey.cpp $(support_src) -t_revokekey6_LDADD = $(ldadd_qt6) -t_revokekey6_CPPFLAGS = $(cppflags_qt6) -t_setprimaryuserid6_SOURCES = t-setprimaryuserid.cpp $(support_src) -t_setprimaryuserid6_LDADD = $(ldadd_qt6) -t_setprimaryuserid6_CPPFLAGS = $(cppflags_qt6) -t_tofuinfo6_SOURCES = t-tofuinfo.cpp $(support_src) -t_tofuinfo6_LDADD = $(ldadd_qt6) -t_tofuinfo6_CPPFLAGS = $(cppflags_qt6) -t_trustsignatures6_SOURCES = t-trustsignatures.cpp $(support_src) -t_trustsignatures6_LDADD = $(ldadd_qt6) -t_trustsignatures6_CPPFLAGS = $(cppflags_qt6) -t_various6_SOURCES = t-various.cpp $(support_src) -t_various6_LDADD = $(ldadd_qt6) -t_various6_CPPFLAGS = $(cppflags_qt6) -t_verify6_SOURCES = t-verify.cpp $(support_src) -t_verify6_LDADD = $(ldadd_qt6) -t_verify6_CPPFLAGS = $(cppflags_qt6) -t_wkdlookup6_SOURCES = t-wkdlookup.cpp $(support_src) -t_wkdlookup6_LDADD = $(ldadd_qt6) -t_wkdlookup6_CPPFLAGS = $(cppflags_qt6) -# t_wkspublish6_SOURCES = t-wkspublish.cpp $(support_src) -# t_wkspublish6_LDADD = $(ldadd_qt6) -# t_wkspublish6_CPPFLAGS = $(cppflags_qt6) -run_decryptverifyarchivejob6_SOURCES = run-decryptverifyarchivejob.cpp -run_decryptverifyarchivejob6_LDADD = $(ldadd_qt6) -run_decryptverifyarchivejob6_CPPFLAGS = $(cppflags_qt6) -run_decryptverifyjob6_SOURCES = run-decryptverifyjob.cpp -run_decryptverifyjob6_LDADD = $(ldadd_qt6) -run_decryptverifyjob6_CPPFLAGS = $(cppflags_qt6) -run_encryptarchivejob6_SOURCES = run-encryptarchivejob.cpp -run_encryptarchivejob6_LDADD = $(ldadd_qt6) -run_encryptarchivejob6_CPPFLAGS = $(cppflags_qt6) -run_encryptjob6_SOURCES = run-encryptjob.cpp -run_encryptjob6_LDADD = $(ldadd_qt6) -run_encryptjob6_CPPFLAGS = $(cppflags_qt6) -run_exportjob6_SOURCES = run-exportjob.cpp -run_exportjob6_LDADD = $(ldadd_qt6) -run_exportjob6_CPPFLAGS = $(cppflags_qt6) -run_importjob6_SOURCES = run-importjob.cpp -run_importjob6_LDADD = $(ldadd_qt6) -run_importjob6_CPPFLAGS = $(cppflags_qt6) -run_keyformailboxjob6_SOURCES = run-keyformailboxjob.cpp -run_keyformailboxjob6_LDADD = $(ldadd_qt6) -run_keyformailboxjob6_CPPFLAGS = $(cppflags_qt6) -run_receivekeysjob6_SOURCES = run-receivekeysjob.cpp -run_receivekeysjob6_LDADD = $(ldadd_qt6) -run_receivekeysjob6_CPPFLAGS = $(cppflags_qt6) -run_refreshkeysjob6_SOURCES = run-refreshkeysjob.cpp -run_refreshkeysjob6_LDADD = $(ldadd_qt6) -run_refreshkeysjob6_CPPFLAGS = $(cppflags_qt6) -run_signarchivejob6_SOURCES = run-signarchivejob.cpp -run_signarchivejob6_LDADD = $(ldadd_qt6) -run_signarchivejob6_CPPFLAGS = $(cppflags_qt6) -run_signjob6_SOURCES = run-signjob.cpp -run_signjob6_LDADD = $(ldadd_qt6) -run_signjob6_CPPFLAGS = $(cppflags_qt6) -run_verifydetachedjob6_SOURCES = run-verifydetachedjob.cpp -run_verifydetachedjob6_LDADD = $(ldadd_qt6) -run_verifydetachedjob6_CPPFLAGS = $(cppflags_qt6) -run_verifyopaquejob6_SOURCES = run-verifyopaquejob.cpp -run_verifyopaquejob6_LDADD = $(ldadd_qt6) -run_verifyopaquejob6_CPPFLAGS = $(cppflags_qt6) -run_wkdrefreshjob6_SOURCES = run-wkdrefreshjob.cpp -run_wkdrefreshjob6_LDADD = $(ldadd_qt6) -run_wkdrefreshjob6_CPPFLAGS = $(cppflags_qt6) - -# nodist_t_keylist6_SOURCES = $(moc6_files) $(moc6_forward_headers) -endif - -BUILT_SOURCES = $(moc5_files) $(moc5_forward_headers) \ - $(moc6_files) $(moc6_forward_headers) \ - pubring-stamp - -noinst_PROGRAMS = $(the_tests5) $(the_runners5) $(the_tests6) $(the_runners6) - -CLEANFILES = secring.gpg pubring.gpg pubring.kbx trustdb.gpg dirmngr.conf \ - gpg-agent.conf pubring.kbx~ S.gpg-agent gpg.conf pubring.gpg~ \ - random_seed S.gpg-agent .gpg-v21-migrated pubring-stamp \ - $(moc5_files) $(moc5_forward_headers) \ - $(moc6_files) $(moc6_forward_headers) \ - gpg.conf tofu.db reader_0.status reader_1.status - -clean-local: - -test -z "$(moc5_dir)" || rm -rf $(moc5_dir) - -test -z "$(moc6_dir)" || rm -rf $(moc6_dir) - -$(TESTS_ENVIRONMENT) $(top_srcdir)/tests/start-stop-agent --stop - -rm -fR private-keys-v1.d crls.d - -clean-keyring: - -$(TESTS_ENVIRONMENT) $(top_srcdir)/tests/start-stop-agent --stop - -rm -fR private-keys-v1.d crls.d pubring.gpg pubring.kbx secring.gpg \ - trustdb.gpg pubring-stamp - -pubring-stamp: $(top_srcdir)/tests/gpg/pubdemo.asc \ - $(top_srcdir)/tests/gpg/secdemo.asc - -$(TESTS_ENVIRONMENT) gpgconf --kill all - echo "ignore-invalid-option allow-loopback-pinentry" > $(abs_builddir)/gpg-agent.conf - echo "allow-loopback-pinentry" >> gpg-agent.conf - echo "ignore-invalid-option pinentry-mode" > gpg.conf - echo "pinentry-mode loopback" >> gpg.conf - $(TESTS_ENVIRONMENT) $(GPG) --no-permission-warning \ - --import $(top_srcdir)/tests/gpg/pubdemo.asc - $(TESTS_ENVIRONMENT) $(GPG) --no-permission-warning \ - --passphrase "abc" \ - --import $(top_srcdir)/tests/gpg/secdemo.asc - -$(TESTS_ENVIRONMENT) gpgconf --kill all - touch pubring-stamp diff --git a/lang/qt/tests/final.test b/lang/qt/tests/final.test deleted file mode 100755 index f28aaa4c..00000000 --- a/lang/qt/tests/final.test +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/sh - -# stop the dirmngr that may have been started -gpgconf --kill dirmngr - -exit 0 diff --git a/lang/qt/tests/initial.test b/lang/qt/tests/initial.test deleted file mode 100755 index 039e4d00..00000000 --- a/lang/qt/tests/initial.test +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -exit 0 diff --git a/lang/qt/tests/run-decryptverifyarchivejob.cpp b/lang/qt/tests/run-decryptverifyarchivejob.cpp deleted file mode 100644 index 6d5615c0..00000000 --- a/lang/qt/tests/run-decryptverifyarchivejob.cpp +++ /dev/null @@ -1,127 +0,0 @@ -/* - run-decryptverifyarchivejob.cpp - - This file is part of QGpgME's test suite. - Copyright (c) 2023 by g10 Code GmbH - Software engineering by Ingo Klöcker <[email protected]> - - QGpgME is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License, - version 2, as published by the Free Software Foundation. - - QGpgME is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - - In addition, as a special exception, the copyright holders give - permission to link the code of this program with any edition of - the Qt library by Trolltech AS, Norway (or with modified versions - of Qt that use the same license as Qt), and distribute linked - combinations including the two. You must obey the GNU General - Public License in all respects for all of the code used other than - Qt. If you modify this file, you may extend this exception to - your version of the file, but you are not obligated to do so. If - you do not wish to do so, delete this exception statement from - your version. -*/ - -#ifdef HAVE_CONFIG_H - #include "config.h" -#endif - -#include <debug.h> -#include <decryptverifyarchivejob.h> -#include <protocol.h> - -#include <QCommandLineParser> -#include <QCoreApplication> -#include <QDebug> - -#include <gpgme++/context.h> -#include <gpgme++/decryptionresult.h> -#include <gpgme++/verificationresult.h> - -#include <iostream> - -using namespace GpgME; - -std::ostream &operator<<(std::ostream &os, const QString &s) -{ - return os << s.toLocal8Bit().constData(); -} - -struct CommandLineOptions { - bool processAllSignatures = false; - QString outputDirectory; - QString archiveName; -}; - -CommandLineOptions parseCommandLine(const QStringList &arguments) -{ - CommandLineOptions options; - - QCommandLineParser parser; - parser.setApplicationDescription("Test program for DecryptVerifyArchiveJob"); - parser.addHelpOption(); - parser.addOptions({ - {{"C", "directory"}, "Extract the files into the directory DIRECTORY.", "DIRECTORY"}, - {"process-all-signatures", "Don't stop signature checking after bad signature."}, - }); - parser.addPositionalArgument("archive", "The archive to decrypt and extract"); - - parser.process(arguments); - - const auto args = parser.positionalArguments(); - if (args.size() != 1) { - parser.showHelp(1); - } - - options.processAllSignatures = parser.isSet("process-all-signatures"); - options.outputDirectory = parser.value("directory"); - options.archiveName = args.first(); - - return options; -} - -int main(int argc, char **argv) -{ - GpgME::initializeLibrary(); - - QCoreApplication app{argc, argv}; - app.setApplicationName("run-decryptverifyarchivejob"); - - const auto options = parseCommandLine(app.arguments()); - - if (!QGpgME::DecryptVerifyArchiveJob::isSupported()) { - std::cerr << "Error: Decrypting and extracting archives is not supported by your version of gpg." << std::endl; - return 1; - } - - auto job = QGpgME::openpgp()->decryptVerifyArchiveJob(); - if (!job) { - std::cerr << "Error: Could not create job" << std::endl; - return 1; - } - job->setProcessAllSignatures(options.processAllSignatures); - job->setInputFile(options.archiveName); - job->setOutputDirectory(options.outputDirectory); - QObject::connect(job, &QGpgME::DecryptVerifyArchiveJob::result, &app, [](const GpgME::DecryptionResult &decryptionResult, const GpgME::VerificationResult &verificationResult, const QString &auditLog, const GpgME::Error &) { - std::cerr << "Diagnostics: " << auditLog << std::endl; - std::cerr << "Decryption Result: " << decryptionResult << std::endl; - std::cerr << "Verification Result: " << verificationResult << std::endl; - qApp->quit(); - }); - - const auto err = job->startIt(); - if (err) { - std::cerr << "Error: Starting the job failed: " << err << std::endl; - return 1; - } - - return app.exec(); -} diff --git a/lang/qt/tests/run-decryptverifyjob.cpp b/lang/qt/tests/run-decryptverifyjob.cpp deleted file mode 100644 index 805bad68..00000000 --- a/lang/qt/tests/run-decryptverifyjob.cpp +++ /dev/null @@ -1,168 +0,0 @@ -/* - run-decryptverifyjob.cpp - - This file is part of QGpgME's test suite. - Copyright (c) 2023 by g10 Code GmbH - Software engineering by Ingo Klöcker <[email protected]> - - QGpgME is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License, - version 2, as published by the Free Software Foundation. - - QGpgME is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - - In addition, as a special exception, the copyright holders give - permission to link the code of this program with any edition of - the Qt library by Trolltech AS, Norway (or with modified versions - of Qt that use the same license as Qt), and distribute linked - combinations including the two. You must obey the GNU General - Public License in all respects for all of the code used other than - Qt. If you modify this file, you may extend this exception to - your version of the file, but you are not obligated to do so. If - you do not wish to do so, delete this exception statement from - your version. -*/ - -#ifdef HAVE_CONFIG_H - #include "config.h" -#endif - -#include <debug.h> -#include <protocol.h> -#include <decryptverifyjob.h> - -#include <QCommandLineParser> -#include <QCoreApplication> -#include <QDebug> -#include <QFile> -#include <QTimer> - -#include <gpgme++/context.h> -#include <gpgme++/decryptionresult.h> -#include <gpgme++/verificationresult.h> - -#include <iostream> - -using namespace GpgME; - -std::ostream &operator<<(std::ostream &os, const QString &s) -{ - return os << s.toLocal8Bit().constData(); -} - -struct CommandLineOptions { - bool processAllSignatures = false; - QString inputFile; - QString outputFile; - std::chrono::seconds cancelTimeout{0}; -}; - -CommandLineOptions parseCommandLine(const QStringList &arguments) -{ - CommandLineOptions options; - - QCommandLineParser parser; - parser.setApplicationDescription("Test program for DecryptVerifyJob"); - parser.addHelpOption(); - parser.addOptions({ - {{"o", "output"}, "Write output to FILE.", "FILE"}, - {"cancel-after", "Cancel the running job after SECONDS seconds.", "SECONDS"}, - {"process-all-signatures", "Don't stop signature checking after bad signature."}, - }); - parser.addPositionalArgument("file", "File to decrypt", "FILE"); - - parser.process(arguments); - - const auto args = parser.positionalArguments(); - if (args.size() != 1) { - parser.showHelp(1); - } - - options.processAllSignatures = parser.isSet("process-all-signatures"); - options.inputFile = args.front(); - options.outputFile = parser.value("output"); - if (parser.isSet("cancel-after")) { - bool ok; - options.cancelTimeout = std::chrono::seconds{parser.value("cancel-after").toInt(&ok)}; - if (!ok) { - options.cancelTimeout = std::chrono::seconds{-1}; - } - } - - return options; -} - -int main(int argc, char **argv) -{ - GpgME::initializeLibrary(); - - QCoreApplication app{argc, argv}; - app.setApplicationName("run-decryptverifyjob"); - - const auto options = parseCommandLine(app.arguments()); - if (options.cancelTimeout.count() < 0) { - std::cerr << "Ignoring invalid timeout for cancel." << std::endl; - } - - std::shared_ptr<QFile> output; - if (options.outputFile.isEmpty() || options.outputFile == QLatin1String{"-"}) { - output.reset(new QFile); - output->open(stdout, QIODevice::WriteOnly); - } else { - if (QFile::exists(options.outputFile)) { - qCritical() << "File" << options.outputFile << "exists. Bailing out."; - return 1; - } - } - - auto job = QGpgME::openpgp()->decryptVerifyJob(); - if (!job) { - std::cerr << "Error: Could not create job" << std::endl; - return 1; - } - QObject::connect(job, - &QGpgME::DecryptVerifyJob::result, - &app, - [](const GpgME::DecryptionResult &decryptionResult, - const GpgME::VerificationResult &verificationResult, - const QByteArray &, - const QString &auditLog, - const GpgME::Error &) { - std::cerr << "Diagnostics: " << auditLog << std::endl; - std::cerr << "Decryption Result: " << decryptionResult << std::endl; - std::cerr << "Verification Result: " << verificationResult << std::endl; - qApp->quit(); - }); - if (options.cancelTimeout.count() > 0) { - QTimer::singleShot(options.cancelTimeout, job, [job]() { - std::cerr << "Canceling job" << std::endl; - job->slotCancel(); - }); - } - - std::shared_ptr<QFile> input; - GpgME::Error err; - job->setProcessAllSignatures(options.processAllSignatures); - if (output) { - input.reset(new QFile{options.inputFile}); - input->open(QIODevice::ReadOnly); - job->start(input, output); - } else { - job->setInputFile(options.inputFile); - job->setOutputFile(options.outputFile); - err = job->startIt(); - } - if (err) { - std::cerr << "Error: Starting the job failed: " << err << std::endl; - return 1; - } - - return app.exec(); -} diff --git a/lang/qt/tests/run-encryptarchivejob.cpp b/lang/qt/tests/run-encryptarchivejob.cpp deleted file mode 100644 index 87781fd9..00000000 --- a/lang/qt/tests/run-encryptarchivejob.cpp +++ /dev/null @@ -1,217 +0,0 @@ -/* - run-encryptarchivejob.cpp - - This file is part of QGpgME's test suite. - Copyright (c) 2023 by g10 Code GmbH - Software engineering by Ingo Klöcker <[email protected]> - - QGpgME is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License, - version 2, as published by the Free Software Foundation. - - QGpgME is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - - In addition, as a special exception, the copyright holders give - permission to link the code of this program with any edition of - the Qt library by Trolltech AS, Norway (or with modified versions - of Qt that use the same license as Qt), and distribute linked - combinations including the two. You must obey the GNU General - Public License in all respects for all of the code used other than - Qt. If you modify this file, you may extend this exception to - your version of the file, but you are not obligated to do so. If - you do not wish to do so, delete this exception statement from - your version. -*/ - -#ifdef HAVE_CONFIG_H - #include "config.h" -#endif - -#include <debug.h> -#include <protocol.h> -#include <encryptarchivejob.h> -#include <signencryptarchivejob.h> - -#include <QCommandLineParser> -#include <QCoreApplication> -#include <QDebug> -#include <QDir> -#include <QFile> -#include <QFileInfo> -#include <QTimer> - -#include <gpgme++/context.h> -#include <gpgme++/encryptionresult.h> -#include <gpgme++/signingresult.h> - -#include <iostream> - -using namespace GpgME; - -std::ostream &operator<<(std::ostream &os, const QString &s) -{ - return os << s.toLocal8Bit().constData(); -} - -struct CommandLineOptions { - bool armor = false; - bool sign = false; - QString archiveName; - QString baseDirectory; - std::chrono::seconds cancelTimeout{0}; - std::vector<QString> filesAndDirectories; -}; - -CommandLineOptions parseCommandLine(const QStringList &arguments) -{ - CommandLineOptions options; - - QCommandLineParser parser; - parser.setApplicationDescription("Test program for EncryptArchiveJob and SignEncryptArchiveJob"); - parser.addHelpOption(); - parser.addOptions({ - {{"s", "sign"}, "Sign archive before encryption."}, - {{"o", "output"}, "Write output to FILE.", "FILE"}, - {{"a", "armor"}, "Create ASCII armored output."}, - {{"C", "directory"}, "Change to DIRECTORY before creating the archive.", "DIRECTORY"}, - {"cancel-after", "Cancel the running job after SECONDS seconds.", "SECONDS"}, - }); - parser.addPositionalArgument("files", "Files and directories to add to the archive", "[files] [directories]"); - - parser.process(arguments); - - const auto args = parser.positionalArguments(); - if (args.empty()) { - parser.showHelp(1); - } - - options.armor = parser.isSet("armor"); - options.sign = parser.isSet("sign"); - options.archiveName = parser.value("output"); - options.baseDirectory = parser.value("directory"); - if (parser.isSet("cancel-after")) { - bool ok; - options.cancelTimeout = std::chrono::seconds{parser.value("cancel-after").toInt(&ok)}; - if (!ok) { - options.cancelTimeout = std::chrono::seconds{-1}; - } - } - std::copy(args.begin(), args.end(), std::back_inserter(options.filesAndDirectories)); - - return options; -} - -QString checkOutputFilePath(const QString &fileName, const QString &baseDirectory) -{ - const QFileInfo fi{QDir{baseDirectory}, fileName}; - if (fi.exists()) { - qCritical() << "File" << fi.filePath() << "exists. Bailing out."; - return {}; - } - return fileName; -} - -int main(int argc, char **argv) -{ - GpgME::initializeLibrary(); - - QCoreApplication app{argc, argv}; - app.setApplicationName("run-encryptarchivejob"); - - const auto options = parseCommandLine(app.arguments()); - if (options.cancelTimeout.count() < 0) { - std::cerr << "Ignoring invalid timeout for cancel." << std::endl; - } - - if ((options.sign && !QGpgME::SignEncryptArchiveJob::isSupported()) - || (!options.sign && !QGpgME::EncryptArchiveJob::isSupported())) { - std::cerr << "Error: Encrypting archives is not supported by your version of gpg." << std::endl; - return 1; - } - - std::shared_ptr<QFile> output; - QString outputFilePath; - if (options.archiveName.isEmpty() || options.archiveName == QLatin1String{"-"}) { - output.reset(new QFile); - output->open(stdout, QIODevice::WriteOnly); - } else { - outputFilePath = checkOutputFilePath(options.archiveName, options.baseDirectory); - if (outputFilePath.isEmpty()) { - return 1; - } - } - - if (options.sign) { - auto job = QGpgME::openpgp()->signEncryptArchiveJob(options.armor); - if (!job) { - std::cerr << "Error: Could not create job" << std::endl; - return 1; - } - job->setBaseDirectory(options.baseDirectory); - QObject::connect(job, &QGpgME::SignEncryptArchiveJob::result, &app, [](const GpgME::SigningResult &signingResult, const GpgME::EncryptionResult &encryptionResult, const QString &auditLog, const GpgME::Error &) { - std::cerr << "Diagnostics: " << auditLog << std::endl; - std::cerr << "Signing Result: " << signingResult << std::endl; - std::cerr << "Encryption Result: " << encryptionResult << std::endl; - qApp->quit(); - }); - if (options.cancelTimeout.count() > 0) { - QTimer::singleShot(options.cancelTimeout, job, [job]() { - std::cerr << "Canceling job" << std::endl; - job->slotCancel(); - }); - } - - GpgME::Error err; - if (output) { - err = job->start({}, {}, options.filesAndDirectories, output, GpgME::Context::None); - } else { - job->setInputPaths(options.filesAndDirectories); - job->setOutputFile(outputFilePath); - err = job->startIt(); - } - if (err) { - std::cerr << "Error: Starting the job failed: " << err << std::endl; - return 1; - } - } else { - auto job = QGpgME::openpgp()->encryptArchiveJob(options.armor); - if (!job) { - std::cerr << "Error: Could not create job" << std::endl; - return 1; - } - job->setBaseDirectory(options.baseDirectory); - QObject::connect(job, &QGpgME::EncryptArchiveJob::result, &app, [](const GpgME::EncryptionResult &result, const QString &auditLog, const GpgME::Error &) { - std::cerr << "Diagnostics: " << auditLog << std::endl; - std::cerr << "Result: " << result << std::endl; - qApp->quit(); - }); - if (options.cancelTimeout.count() > 0) { - QTimer::singleShot(options.cancelTimeout, job, [job]() { - std::cerr << "Canceling job" << std::endl; - job->slotCancel(); - }); - } - - GpgME::Error err; - if (output) { - err = job->start({}, options.filesAndDirectories, output, GpgME::Context::None); - } else { - job->setInputPaths(options.filesAndDirectories); - job->setOutputFile(outputFilePath); - err = job->startIt(); - } - if (err) { - std::cerr << "Error: Starting the job failed: " << err << std::endl; - return 1; - } - } - - return app.exec(); -} diff --git a/lang/qt/tests/run-encryptjob.cpp b/lang/qt/tests/run-encryptjob.cpp deleted file mode 100644 index 14c8ea44..00000000 --- a/lang/qt/tests/run-encryptjob.cpp +++ /dev/null @@ -1,199 +0,0 @@ -/* - run-encryptjob.cpp - - This file is part of QGpgME's test suite. - Copyright (c) 2023 by g10 Code GmbH - Software engineering by Ingo Klöcker <[email protected]> - - QGpgME is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License, - version 2, as published by the Free Software Foundation. - - QGpgME is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - - In addition, as a special exception, the copyright holders give - permission to link the code of this program with any edition of - the Qt library by Trolltech AS, Norway (or with modified versions - of Qt that use the same license as Qt), and distribute linked - combinations including the two. You must obey the GNU General - Public License in all respects for all of the code used other than - Qt. If you modify this file, you may extend this exception to - your version of the file, but you are not obligated to do so. If - you do not wish to do so, delete this exception statement from - your version. -*/ - -#ifdef HAVE_CONFIG_H - #include "config.h" -#endif - -#include <debug.h> -#include <protocol.h> -#include <encryptjob.h> -#include <signencryptjob.h> - -#include <QCommandLineParser> -#include <QCoreApplication> -#include <QDebug> -#include <QFile> -#include <QTimer> - -#include <gpgme++/context.h> -#include <gpgme++/encryptionresult.h> -#include <gpgme++/signingresult.h> - -#include <iostream> - -using namespace GpgME; - -std::ostream &operator<<(std::ostream &os, const QString &s) -{ - return os << s.toLocal8Bit().constData(); -} - -struct CommandLineOptions { - bool armor = false; - bool sign = false; - QString inputFile; - QString outputFile; - std::chrono::seconds cancelTimeout{0}; -}; - -CommandLineOptions parseCommandLine(const QStringList &arguments) -{ - CommandLineOptions options; - - QCommandLineParser parser; - parser.setApplicationDescription("Test program for EncryptJob and SignEncryptJob"); - parser.addHelpOption(); - parser.addOptions({ - {{"s", "sign"}, "Sign file before encryption."}, - {{"o", "output"}, "Write output to FILE.", "FILE"}, - {{"a", "armor"}, "Create ASCII armored output."}, - {"cancel-after", "Cancel the running job after SECONDS seconds.", "SECONDS"}, - }); - parser.addPositionalArgument("file", "File to encrypt", "FILE"); - - parser.process(arguments); - - const auto args = parser.positionalArguments(); - if (args.size() != 1) { - parser.showHelp(1); - } - - options.armor = parser.isSet("armor"); - options.sign = parser.isSet("sign"); - options.inputFile = args.front(); - options.outputFile = parser.value("output"); - if (parser.isSet("cancel-after")) { - bool ok; - options.cancelTimeout = std::chrono::seconds{parser.value("cancel-after").toInt(&ok)}; - if (!ok) { - options.cancelTimeout = std::chrono::seconds{-1}; - } - } - - return options; -} - -int main(int argc, char **argv) -{ - GpgME::initializeLibrary(); - - QCoreApplication app{argc, argv}; - app.setApplicationName("run-encryptjob"); - - const auto options = parseCommandLine(app.arguments()); - if (options.cancelTimeout.count() < 0) { - std::cerr << "Ignoring invalid timeout for cancel." << std::endl; - } - - std::shared_ptr<QFile> output; - if (options.outputFile.isEmpty() || options.outputFile == QLatin1String{"-"}) { - output.reset(new QFile); - output->open(stdout, QIODevice::WriteOnly); - } else { - if (QFile::exists(options.outputFile)) { - qCritical() << "File" << options.outputFile << "exists. Bailing out."; - return 1; - } - } - - std::shared_ptr<QFile> input; - - if (options.sign) { - auto job = QGpgME::openpgp()->signEncryptJob(options.armor); - if (!job) { - std::cerr << "Error: Could not create job" << std::endl; - return 1; - } - QObject::connect(job, &QGpgME::SignEncryptJob::result, &app, [](const GpgME::SigningResult &signingResult, const GpgME::EncryptionResult &encryptionResult, const QByteArray &, const QString &auditLog, const GpgME::Error &) { - std::cerr << "Diagnostics: " << auditLog << std::endl; - std::cerr << "Signing Result: " << signingResult << std::endl; - std::cerr << "Encryption Result: " << encryptionResult << std::endl; - qApp->quit(); - }); - if (options.cancelTimeout.count() > 0) { - QTimer::singleShot(options.cancelTimeout, job, [job]() { - std::cerr << "Canceling job" << std::endl; - job->slotCancel(); - }); - } - - GpgME::Error err; - if (output) { - input.reset(new QFile{options.inputFile}); - input->open(QIODevice::ReadOnly); - job->start({}, {}, input, output, GpgME::Context::None); - } else { - job->setInputFile(options.inputFile); - job->setOutputFile(options.outputFile); - err = job->startIt(); - } - if (err) { - std::cerr << "Error: Starting the job failed: " << err << std::endl; - return 1; - } - } else { - auto job = QGpgME::openpgp()->encryptJob(options.armor); - if (!job) { - std::cerr << "Error: Could not create job" << std::endl; - return 1; - } - QObject::connect(job, &QGpgME::EncryptJob::result, &app, [](const GpgME::EncryptionResult &result, const QByteArray &, const QString &auditLog, const GpgME::Error &) { - std::cerr << "Diagnostics: " << auditLog << std::endl; - std::cerr << "Result: " << result << std::endl; - qApp->quit(); - }); - if (options.cancelTimeout.count() > 0) { - QTimer::singleShot(options.cancelTimeout, job, [job]() { - std::cerr << "Canceling job" << std::endl; - job->slotCancel(); - }); - } - - GpgME::Error err; - if (output) { - input.reset(new QFile{options.inputFile}); - input->open(QIODevice::ReadOnly); - job->start({}, input, output, GpgME::Context::None); - } else { - job->setInputFile(options.inputFile); - job->setOutputFile(options.outputFile); - err = job->startIt(); - } - if (err) { - std::cerr << "Error: Starting the job failed: " << err << std::endl; - return 1; - } - } - - return app.exec(); -} diff --git a/lang/qt/tests/run-exportjob.cpp b/lang/qt/tests/run-exportjob.cpp deleted file mode 100644 index ed6f8912..00000000 --- a/lang/qt/tests/run-exportjob.cpp +++ /dev/null @@ -1,120 +0,0 @@ -/* - run-exportjob.cpp - - This file is part of QGpgME's test suite. - Copyright (c) 2022 by g10 Code GmbH - Software engineering by Ingo Klöcker <[email protected]> - - QGpgME is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License, - version 2, as published by the Free Software Foundation. - - QGpgME is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - - In addition, as a special exception, the copyright holders give - permission to link the code of this program with any edition of - the Qt library by Trolltech AS, Norway (or with modified versions - of Qt that use the same license as Qt), and distribute linked - combinations including the two. You must obey the GNU General - Public License in all respects for all of the code used other than - Qt. If you modify this file, you may extend this exception to - your version of the file, but you are not obligated to do so. If - you do not wish to do so, delete this exception statement from - your version. -*/ - -#ifdef HAVE_CONFIG_H - #include "config.h" -#endif - -#include <debug.h> -#include <exportjob.h> -#include <protocol.h> - -#include <gpgme++/context.h> - -#include <QCoreApplication> - -#include <iostream> - -using namespace GpgME; -using std::cout; -using std::cerr; - -static void showUsageAndExitWithCode(int exitCode) -{ - cerr << "Usage: run-exportjob [OPTION]... [PATTERN]...\n" - "Options:\n" - " --secret export secret keys instead of public keys\n" - " --secret-subkey export secret subkeys instead of public keys\n"; - - exit(exitCode); -} - -static QGpgME::ExportJob *createExportJob(unsigned int mode) -{ - if (mode & Context::ExportSecretSubkey) { - return QGpgME::openpgp()->secretSubkeyExportJob(/*armor=*/true); - } else if (mode & Context::ExportSecret) { - return QGpgME::openpgp()->secretKeyExportJob(/*armor=*/true); - } - return QGpgME::openpgp()->publicKeyExportJob(/*armor=*/true); -} - -int main(int argc, char *argv[]) -{ - GpgME::initializeLibrary(); - - QCoreApplication app{argc, argv}; - - unsigned int exportMode = 0; - - auto arguments = app.arguments(); - if (!arguments.isEmpty()) { - arguments.pop_front(); // remove program name - } - while (!arguments.isEmpty()) { - const auto &arg = arguments.front(); - if (!arg.startsWith(QLatin1String{"--"})) { - break; - } - if (arg == QLatin1String{"--"}) { - arguments.pop_front(); - break; - } - if (arg == QLatin1String{"--help"}) { - showUsageAndExitWithCode(0); - } else if (arg == QLatin1String{"--secret"}) { - exportMode = Context::ExportSecret; - arguments.pop_front(); - } else if (arg == QLatin1String{"--secret-subkey"}) { - exportMode = Context::ExportSecretSubkey; - arguments.pop_front(); - } else { - cerr << "Error: Invalid option " << arg.toStdString() << std::endl; - showUsageAndExitWithCode(1); - } - } - - auto job = createExportJob(exportMode); - QObject::connect(job, &QGpgME::ExportJob::result, - &app, [&app] (const GpgME::Error &err, const QByteArray &keyData, const QString &, const GpgME::Error &) { - if (err) { - cerr << "The ChangeExpiryJob failed with" << err << "."; - app.exit(1); - return; - } - cout << "Begin Result:\n" << keyData.toStdString() << "End Result:\n"; - app.exit(); - }); - job->start(arguments); - - return app.exec(); -} diff --git a/lang/qt/tests/run-importjob.cpp b/lang/qt/tests/run-importjob.cpp deleted file mode 100644 index 67ee73f3..00000000 --- a/lang/qt/tests/run-importjob.cpp +++ /dev/null @@ -1,97 +0,0 @@ -/* - run-importjob.cpp - - This file is part of QGpgME's test suite. - Copyright (c) 2021 by g10 Code GmbH - Software engineering by Ingo Klöcker <[email protected]> - - QGpgME is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License, - version 2, as published by the Free Software Foundation. - - QGpgME is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - - In addition, as a special exception, the copyright holders give - permission to link the code of this program with any edition of - the Qt library by Trolltech AS, Norway (or with modified versions - of Qt that use the same license as Qt), and distribute linked - combinations including the two. You must obey the GNU General - Public License in all respects for all of the code used other than - Qt. If you modify this file, you may extend this exception to - your version of the file, but you are not obligated to do so. If - you do not wish to do so, delete this exception statement from - your version. -*/ - -#ifdef HAVE_CONFIG_H - #include "config.h" -#endif - -#include <debug.h> -#include <importjob.h> -#include <gpgme++/importresult.h> -#include <protocol.h> - -#include <QFile> -#include <QFileInfo> - -#include <QDebug> - -#include <set> - -GpgME::Protocol guessProtocol(const QString &filename) -{ - static const std::set<QString> cmsExtensions = {"cer", "crt", "der", "p12", "p7c", "pem", "pfx"}; - static const std::set<QString> pgpExtensions = {"asc", "gpg", "pgp"}; - - const auto extension = QFileInfo{filename}.suffix(); - if (cmsExtensions.find(extension) != cmsExtensions.end()) { - return GpgME::CMS; - } else if (pgpExtensions.find(extension) != pgpExtensions.end()) { - return GpgME::OpenPGP; - } - qDebug() << "Unknown file name extension" << extension; - return GpgME::UnknownProtocol; -} - -int main(int argc, char **argv) -{ - GpgME::initializeLibrary(); - - if (argc != 2) { - qInfo().noquote() << "Usage:" << argv[0] << "<certificate file>"; - return 1; - } - const auto filename = QString::fromLocal8Bit(argv[1]); - - QFile f{filename}; - if (!f.exists()) { - qWarning() << "Error: File not found" << filename; - return 1; - } - const auto protocol = guessProtocol(filename); - if (protocol == GpgME::UnknownProtocol) { - qWarning() << "Error: Unknown file type"; - return 1; - } - if (!f.open(QIODevice::ReadOnly)) { - qWarning() << "Error: Failed to open file" << filename << "for reading."; - return 1; - } - - const auto keyData = f.readAll(); - auto job = (protocol == GpgME::CMS ? QGpgME::smime() : QGpgME::openpgp())->importJob(); - const auto result = job->exec(keyData); - qDebug() << "Result error:" << result.error(); - for (const auto &line : QString::fromStdString(QGpgME::toLogString(result)).split('\n')) { - qDebug().noquote() << line; - } - return 0; -} diff --git a/lang/qt/tests/run-keyformailboxjob.cpp b/lang/qt/tests/run-keyformailboxjob.cpp deleted file mode 100644 index 8ec0c5b3..00000000 --- a/lang/qt/tests/run-keyformailboxjob.cpp +++ /dev/null @@ -1,61 +0,0 @@ -/* - run-keyformailbox.cpp - - This file is part of QGpgME's test suite. - Copyright (c) 2016 by Bundesamt für Sicherheit in der Informationstechnik - Software engineering by Intevation GmbH - - QGpgME is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License, - version 2, as published by the Free Software Foundation. - - QGpgME is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - - In addition, as a special exception, the copyright holders give - permission to link the code of this program with any edition of - the Qt library by Trolltech AS, Norway (or with modified versions - of Qt that use the same license as Qt), and distribute linked - combinations including the two. You must obey the GNU General - Public License in all respects for all of the code used other than - Qt. If you modify this file, you may extend this exception to - your version of the file, but you are not obligated to do so. If - you do not wish to do so, delete this exception statement from - your version. -*/ - -#ifdef HAVE_CONFIG_H - #include "config.h" -#endif - -#include "keyformailboxjob.h" -#include "keylistjob.h" -#include "protocol.h" - -#include <gpgme++/key.h> -#include <gpgme++/keylistresult.h> - -#include <QDebug> - - -int main(int argc, char **argv) -{ - QString mailbox; - if (argc == 2) { - mailbox = QString::fromLocal8Bit(argv[1]); - } - - auto job = QGpgME::openpgp()->keyForMailboxJob(); - GpgME::Key k; - GpgME::UserID uid; - job->exec(mailbox, true, k, uid); - qDebug() << "UID Name: " << uid.name() << " Mail: " << uid.email() << " id: " << uid.id(); - qDebug() << "Key fpr: " << k.primaryFingerprint(); - return 0; -} diff --git a/lang/qt/tests/run-receivekeysjob.cpp b/lang/qt/tests/run-receivekeysjob.cpp deleted file mode 100644 index 44553218..00000000 --- a/lang/qt/tests/run-receivekeysjob.cpp +++ /dev/null @@ -1,66 +0,0 @@ -/* - run-receivekeysjob.cpp - - This file is part of QGpgME's test suite. - Copyright (c) 2022 by g10 Code GmbH - Software engineering by Ingo Klöcker <[email protected]> - - QGpgME is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License, - version 2, as published by the Free Software Foundation. - - QGpgME is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - - In addition, as a special exception, the copyright holders give - permission to link the code of this program with any edition of - the Qt library by Trolltech AS, Norway (or with modified versions - of Qt that use the same license as Qt), and distribute linked - combinations including the two. You must obey the GNU General - Public License in all respects for all of the code used other than - Qt. If you modify this file, you may extend this exception to - your version of the file, but you are not obligated to do so. If - you do not wish to do so, delete this exception statement from - your version. -*/ - -#ifdef HAVE_CONFIG_H - #include "config.h" -#endif - -#include <debug.h> -#include <gpgme++/importresult.h> -#include <protocol.h> -#include <receivekeysjob.h> - -#include <QCoreApplication> -#include <QDebug> - -#include <iostream> - -int main(int argc, char **argv) -{ - GpgME::initializeLibrary(); - - if (argc < 2) { - std::cerr << "Usage: " << argv[0] << " KEYID..." << std::endl; - return 1; - } - - QCoreApplication app(argc, argv); - const QStringList keyIds = qApp->arguments().mid(1); - - auto job = QGpgME::openpgp()->receiveKeysJob(); - const auto result = job->exec(keyIds); - - std::cout << "Result: " << result.error() << std::endl; - std::cout << "Details:\n" << result << std::endl; - - return 0; -} diff --git a/lang/qt/tests/run-refreshkeysjob.cpp b/lang/qt/tests/run-refreshkeysjob.cpp deleted file mode 100644 index ad653a54..00000000 --- a/lang/qt/tests/run-refreshkeysjob.cpp +++ /dev/null @@ -1,156 +0,0 @@ -/* - run-refreshkeysjob.cpp - - This file is part of QGpgME's test suite. - Copyright (c) 2022 by g10 Code GmbH - Software engineering by Ingo Klöcker <[email protected]> - - QGpgME is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License, - version 2, as published by the Free Software Foundation. - - QGpgME is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - - In addition, as a special exception, the copyright holders give - permission to link the code of this program with any edition of - the Qt library by Trolltech AS, Norway (or with modified versions - of Qt that use the same license as Qt), and distribute linked - combinations including the two. You must obey the GNU General - Public License in all respects for all of the code used other than - Qt. If you modify this file, you may extend this exception to - your version of the file, but you are not obligated to do so. If - you do not wish to do so, delete this exception statement from - your version. -*/ - -#ifdef HAVE_CONFIG_H - #include "config.h" -#endif - -#include <debug.h> -#include <protocol.h> -#include <refreshkeysjob.h> -#include <receivekeysjob.h> - -#include <QCoreApplication> -#include <QDebug> - -#include <gpgme++/context.h> -#include <gpgme++/importresult.h> - -#include <iostream> - -using namespace GpgME; - -std::ostream &operator<<(std::ostream &os, const QString &s) -{ - return os << s.toLocal8Bit().constData(); -} - -const char *displayName(Protocol protocol) -{ - switch (protocol) { - case GpgME::OpenPGP: - return "OpenPGP"; - case GpgME::CMS: - return "S/MIME"; - default: - return "Unknown protocol"; - } -} - -struct KeyAndError { - Key key; - Error error; -}; - -KeyAndError getKey(const QString &keyId, Protocol protocol) -{ - KeyAndError result; - - auto ctx = Context::create(protocol); - if (!ctx) { - result.error = Error::fromCode(GPG_ERR_GENERAL); - return result; - } - - result.key = ctx->key(keyId.toLatin1().constData(), result.error); - if (result.error.code() == GPG_ERR_EOF) { - result.error = Error{}; - } - return result; -} - -int main(int argc, char **argv) -{ - GpgME::initializeLibrary(); - - if (argc != 2) { - std::cerr << "Usage: " << argv[0] << " KEYID" << std::endl; - return 1; - } - - QCoreApplication app{argc, argv}; - const auto keyId = qApp->arguments().last(); - - auto openPGPKey = getKey(keyId, GpgME::OpenPGP); - auto smimeKey = getKey(keyId, GpgME::CMS); - if ((!openPGPKey.key.isNull() && !smimeKey.key.isNull()) - || (openPGPKey.error.code() == GPG_ERR_AMBIGUOUS_NAME) - || (smimeKey.error.code() == GPG_ERR_AMBIGUOUS_NAME)) { - std::cerr << "Error: Multiple keys matching '" << keyId << "' found" << std::endl; - return 1; - } else if (openPGPKey.key.isNull() && smimeKey.key.isNull()) { - std::cerr << "Error: No key matching '" << keyId << "' found" << std::endl; - return 1; - } - if (openPGPKey.error) { - std::cerr << "Warning: Error while getting OpenPGP key: " << openPGPKey.error << std::endl; - } - if (smimeKey.error) { - std::cerr << "Warning: Error while getting S/MIME key: " << openPGPKey.error << std::endl; - } - auto key = openPGPKey.key.isNull() ? smimeKey.key : openPGPKey.key; - std::cout << "Refreshing " << displayName(key.protocol()) << " key " << key.userID(0).id() << std::endl; - - if (key.protocol() == GpgME::OpenPGP) { - auto job = QGpgME::openpgp()->receiveKeysJob(); - if (!job) { - std::cerr << "Error: Could not create job to refresh OpenPGP key" << std::endl; - return 1; - } - QObject::connect(job, &QGpgME::ReceiveKeysJob::result, &app, [](const GpgME::ImportResult &result, const QString &, const GpgME::Error &) { - std::cout << "Result: " << result << std::endl; - qApp->quit(); - }); - const auto err = job->start({QString::fromLatin1(key.primaryFingerprint())}); - if (err) { - std::cerr << "Error: " << err << std::endl; - return 1; - } - } else { - auto job = QGpgME::smime()->refreshKeysJob(); - if (!job) { - std::cerr << "Error: Could not create job to refresh S/MIME key" << std::endl; - return 1; - } - QObject::connect(job, &QGpgME::RefreshKeysJob::result, &app, [](const GpgME::Error &err) { - std::cout << "Result: " << err << std::endl; - qApp->quit(); - }); - const auto err = job->start({key}); - if (err) { - std::cerr << "Error: " << err << std::endl; - return 1; - } - } - - return app.exec(); -} diff --git a/lang/qt/tests/run-signarchivejob.cpp b/lang/qt/tests/run-signarchivejob.cpp deleted file mode 100644 index 3152507e..00000000 --- a/lang/qt/tests/run-signarchivejob.cpp +++ /dev/null @@ -1,177 +0,0 @@ -/* - run-signarchivejob.cpp - - This file is part of QGpgME's test suite. - Copyright (c) 2023 by g10 Code GmbH - Software engineering by Ingo Klöcker <[email protected]> - - QGpgME is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License, - version 2, as published by the Free Software Foundation. - - QGpgME is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - - In addition, as a special exception, the copyright holders give - permission to link the code of this program with any edition of - the Qt library by Trolltech AS, Norway (or with modified versions - of Qt that use the same license as Qt), and distribute linked - combinations including the two. You must obey the GNU General - Public License in all respects for all of the code used other than - Qt. If you modify this file, you may extend this exception to - your version of the file, but you are not obligated to do so. If - you do not wish to do so, delete this exception statement from - your version. -*/ - -#ifdef HAVE_CONFIG_H - #include "config.h" -#endif - -#include <debug.h> -#include <protocol.h> -#include <signarchivejob.h> - -#include <QCommandLineParser> -#include <QCoreApplication> -#include <QDebug> -#include <QDir> -#include <QFile> -#include <QFileInfo> -#include <QTimer> - -#include <gpgme++/context.h> -#include <gpgme++/signingresult.h> - -#include <iostream> - -using namespace GpgME; - -std::ostream &operator<<(std::ostream &os, const QString &s) -{ - return os << s.toLocal8Bit().constData(); -} - -struct CommandLineOptions { - bool armor; - QString archiveName; - QString baseDirectory; - std::chrono::seconds cancelTimeout{0}; - std::vector<QString> filesAndDirectories; -}; - -CommandLineOptions parseCommandLine(const QStringList &arguments) -{ - CommandLineOptions options; - - QCommandLineParser parser; - parser.setApplicationDescription("Test program for SignArchiveJob"); - parser.addHelpOption(); - parser.addOptions({ - {{"o", "output"}, "Write output to FILE.", "FILE"}, - {{"a", "armor"}, "Create ASCII armored output."}, - {{"C", "directory"}, "Change to DIRECTORY before creating the archive.", "DIRECTORY"}, - {"cancel-after", "Cancel the running job after SECONDS seconds.", "SECONDS"}, - }); - parser.addPositionalArgument("files", "Files and directories to add to the archive", "[files] [directories]"); - - parser.process(arguments); - - const auto args = parser.positionalArguments(); - if (args.empty()) { - parser.showHelp(1); - } - - options.armor = parser.isSet("armor"); - options.archiveName = parser.value("output"); - options.baseDirectory = parser.value("directory"); - if (parser.isSet("cancel-after")) { - bool ok; - options.cancelTimeout = std::chrono::seconds{parser.value("cancel-after").toInt(&ok)}; - if (!ok) { - options.cancelTimeout = std::chrono::seconds{-1}; - } - } - std::copy(args.begin(), args.end(), std::back_inserter(options.filesAndDirectories)); - - return options; -} - -QString checkOutputFilePath(const QString &fileName, const QString &baseDirectory) -{ - const QFileInfo fi{QDir{baseDirectory}, fileName}; - if (fi.exists()) { - qCritical() << "File" << fi.filePath() << "exists. Bailing out."; - return {}; - } - return fileName; -} - -int main(int argc, char **argv) -{ - GpgME::initializeLibrary(); - - QCoreApplication app{argc, argv}; - app.setApplicationName("run-signarchivejob"); - - const auto options = parseCommandLine(app.arguments()); - if (options.cancelTimeout.count() < 0) { - std::cerr << "Ignoring invalid timeout for cancel." << std::endl; - } - - if (!QGpgME::SignArchiveJob::isSupported()) { - std::cerr << "Error: Signing archives is not supported by your version of gpg." << std::endl; - return 1; - } - - std::shared_ptr<QFile> output; - QString outputFilePath; - if (options.archiveName.isEmpty() || options.archiveName == QLatin1String{"-"}) { - output.reset(new QFile); - output->open(stdout, QIODevice::WriteOnly); - } else { - outputFilePath = checkOutputFilePath(options.archiveName, options.baseDirectory); - if (outputFilePath.isEmpty()) { - return 1; - } - } - - auto job = QGpgME::openpgp()->signArchiveJob(options.armor); - if (!job) { - std::cerr << "Error: Could not create job" << std::endl; - return 1; - } - job->setBaseDirectory(options.baseDirectory); - QObject::connect(job, &QGpgME::SignArchiveJob::result, &app, [](const GpgME::SigningResult &result, const QString &auditLog, const GpgME::Error &) { - std::cerr << "Diagnostics: " << auditLog << std::endl; - std::cerr << "Result: " << result << std::endl; - qApp->quit(); - }); - if (options.cancelTimeout.count() > 0) { - QTimer::singleShot(options.cancelTimeout, job, [job]() { - std::cerr << "Canceling job" << std::endl; - job->slotCancel(); - }); - } - - GpgME::Error err; - if (output) { - err = job->start({}, options.filesAndDirectories, output); - } else { - job->setInputPaths(options.filesAndDirectories); - job->setOutputFile(outputFilePath); - err = job->startIt(); - } - if (err) { - std::cerr << "Error: Starting the job failed: " << err << std::endl; - return 1; - } - - return app.exec(); -} diff --git a/lang/qt/tests/run-signjob.cpp b/lang/qt/tests/run-signjob.cpp deleted file mode 100644 index 9c2ebcc2..00000000 --- a/lang/qt/tests/run-signjob.cpp +++ /dev/null @@ -1,168 +0,0 @@ -/* - run-signjob.cpp - - This file is part of QGpgME's test suite. - Copyright (c) 2023 by g10 Code GmbH - Software engineering by Ingo Klöcker <[email protected]> - - QGpgME is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License, - version 2, as published by the Free Software Foundation. - - QGpgME is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - - In addition, as a special exception, the copyright holders give - permission to link the code of this program with any edition of - the Qt library by Trolltech AS, Norway (or with modified versions - of Qt that use the same license as Qt), and distribute linked - combinations including the two. You must obey the GNU General - Public License in all respects for all of the code used other than - Qt. If you modify this file, you may extend this exception to - your version of the file, but you are not obligated to do so. If - you do not wish to do so, delete this exception statement from - your version. -*/ - -#ifdef HAVE_CONFIG_H - #include "config.h" -#endif - -#include <debug.h> -#include <protocol.h> -#include <signjob.h> - -#include <QCommandLineParser> -#include <QCoreApplication> -#include <QDebug> -#include <QFile> -#include <QTimer> - -#include <gpgme++/context.h> -#include <gpgme++/signingresult.h> - -#include <iostream> - -using namespace GpgME; - -std::ostream &operator<<(std::ostream &os, const QString &s) -{ - return os << s.toLocal8Bit().constData(); -} - -struct CommandLineOptions { - GpgME::SignatureMode signingFlags = GpgME::NormalSignatureMode; - bool armor = false; - bool appendSignature = false; - QString inputFile; - QString outputFile; - std::chrono::seconds cancelTimeout{0}; -}; - -CommandLineOptions parseCommandLine(const QStringList &arguments) -{ - CommandLineOptions options; - - QCommandLineParser parser; - parser.setApplicationDescription("Test program for SignJob"); - parser.addHelpOption(); - parser.addOptions({ - {{"o", "output"}, "Write output to FILE.", "FILE"}, - {{"a", "armor"}, "Create ASCII armored output."}, - {{"b", "detach-sign"}, "Create a detached signature."}, - {"append", "Append new (detached) signature to existing file."}, - {"cancel-after", "Cancel the running job after SECONDS seconds.", "SECONDS"}, - }); - parser.addPositionalArgument("file", "File to sign", "FILE"); - - parser.process(arguments); - - const auto args = parser.positionalArguments(); - if (args.size() != 1) { - parser.showHelp(1); - } - - options.armor = parser.isSet("armor"); - if (parser.isSet("detach-sign")) { - options.signingFlags = GpgME::Detached; - options.appendSignature = parser.isSet("append"); - } - options.inputFile = args.front(); - options.outputFile = parser.value("output"); - if (parser.isSet("cancel-after")) { - bool ok; - options.cancelTimeout = std::chrono::seconds{parser.value("cancel-after").toInt(&ok)}; - if (!ok) { - options.cancelTimeout = std::chrono::seconds{-1}; - } - } - - return options; -} - -int main(int argc, char **argv) -{ - GpgME::initializeLibrary(); - - QCoreApplication app{argc, argv}; - app.setApplicationName("run-signjob"); - - const auto options = parseCommandLine(app.arguments()); - if (options.cancelTimeout.count() < 0) { - std::cerr << "Ignoring invalid timeout for cancel." << std::endl; - } - - std::shared_ptr<QFile> output; - if (options.outputFile.isEmpty() || options.outputFile == QLatin1String{"-"}) { - output.reset(new QFile); - output->open(stdout, QIODevice::WriteOnly); - } else { - if (QFile::exists(options.outputFile) && !options.appendSignature) { - qCritical() << "File" << options.outputFile << "exists. Bailing out."; - return 1; - } - } - - auto job = QGpgME::openpgp()->signJob(options.armor); - if (!job) { - std::cerr << "Error: Could not create job" << std::endl; - return 1; - } - QObject::connect(job, &QGpgME::SignJob::result, &app, [](const GpgME::SigningResult &result, const QByteArray &, const QString &auditLog, const GpgME::Error &) { - std::cerr << "Diagnostics: " << auditLog << std::endl; - std::cerr << "Result: " << result << std::endl; - qApp->quit(); - }); - if (options.cancelTimeout.count() > 0) { - QTimer::singleShot(options.cancelTimeout, job, [job]() { - std::cerr << "Canceling job" << std::endl; - job->slotCancel(); - }); - } - - std::shared_ptr<QFile> input; - GpgME::Error err; - if (output) { - input.reset(new QFile{options.inputFile}); - input->open(QIODevice::ReadOnly); - job->start({}, input, output, GpgME::NormalSignatureMode); - } else { - job->setInputFile(options.inputFile); - job->setOutputFile(options.outputFile); - job->setSigningFlags(options.signingFlags); - job->setAppendSignature(options.appendSignature); - err = job->startIt(); - } - if (err) { - std::cerr << "Error: Starting the job failed: " << err << std::endl; - return 1; - } - - return app.exec(); -} diff --git a/lang/qt/tests/run-verifydetachedjob.cpp b/lang/qt/tests/run-verifydetachedjob.cpp deleted file mode 100644 index 17a719e9..00000000 --- a/lang/qt/tests/run-verifydetachedjob.cpp +++ /dev/null @@ -1,128 +0,0 @@ -/* - run-verifydetachedjob.cpp - - This file is part of QGpgME's test suite. - Copyright (c) 2024 by g10 Code GmbH - Software engineering by Ingo Klöcker <[email protected]> - - QGpgME is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License, - version 2, as published by the Free Software Foundation. - - QGpgME is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - - In addition, as a special exception, the copyright holders give - permission to link the code of this program with any edition of - the Qt library by Trolltech AS, Norway (or with modified versions - of Qt that use the same license as Qt), and distribute linked - combinations including the two. You must obey the GNU General - Public License in all respects for all of the code used other than - Qt. If you modify this file, you may extend this exception to - your version of the file, but you are not obligated to do so. If - you do not wish to do so, delete this exception statement from - your version. -*/ - -#ifdef HAVE_CONFIG_H - #include "config.h" -#endif - -#include <debug.h> -#include <protocol.h> -#include <verifydetachedjob.h> - -#include <QCommandLineParser> -#include <QCoreApplication> -#include <QDebug> -#include <QFile> - -#include <gpgme++/context.h> -#include <gpgme++/verificationresult.h> - -#include <iostream> - -using namespace GpgME; - -std::ostream &operator<<(std::ostream &os, const QString &s) -{ - return os << s.toLocal8Bit().constData(); -} - -struct CommandLineOptions { - bool processAllSignatures = false; - QString signatureFile; - QString signedFile; -}; - -CommandLineOptions parseCommandLine(const QStringList &arguments) -{ - CommandLineOptions options; - - QCommandLineParser parser; - parser.setApplicationDescription("Test program for VerifyDetachedJob"); - parser.addHelpOption(); - parser.addOptions({ - {"process-all-signatures", "Don't stop signature checking after bad signature."}, - }); - parser.addPositionalArgument("signature", "Detached SIGNATURE to verify", "SIGNATURE"); - parser.addPositionalArgument("signed file", "FILE containing the signed data", "FILE"); - - parser.process(arguments); - - const auto args = parser.positionalArguments(); - if (args.size() != 2) { - parser.showHelp(1); - } - - options.processAllSignatures = parser.isSet("process-all-signatures"); - options.signatureFile = args[0]; - options.signedFile = args[1]; - - return options; -} - -int main(int argc, char **argv) -{ - GpgME::initializeLibrary(); - - QCoreApplication app{argc, argv}; - app.setApplicationName("run-verifydetachedjob"); - - const auto options = parseCommandLine(app.arguments()); - - auto job = QGpgME::openpgp()->verifyDetachedJob(); - if (!job) { - std::cerr << "Error: Could not create job" << std::endl; - return 1; - } - QObject::connect(job, - &QGpgME::VerifyDetachedJob::result, - &app, - [](const GpgME::VerificationResult &verificationResult, - const QString &auditLog, - const GpgME::Error &) { - std::cerr << "Diagnostics: " << auditLog << std::endl; - std::cerr << "Verification Result: " << verificationResult << std::endl; - qApp->quit(); - }); - - std::shared_ptr<QFile> input; - GpgME::Error err; - job->setProcessAllSignatures(options.processAllSignatures); - job->setSignatureFile(options.signatureFile); - job->setSignedFile(options.signedFile); - err = job->startIt(); - if (err) { - std::cerr << "Error: Starting the job failed: " << err << std::endl; - return 1; - } - - return app.exec(); -} diff --git a/lang/qt/tests/run-verifyopaquejob.cpp b/lang/qt/tests/run-verifyopaquejob.cpp deleted file mode 100644 index a3245b4f..00000000 --- a/lang/qt/tests/run-verifyopaquejob.cpp +++ /dev/null @@ -1,165 +0,0 @@ -/* - run-verifyopaquejob.cpp - - This file is part of QGpgME's test suite. - Copyright (c) 2023 by g10 Code GmbH - Software engineering by Ingo Klöcker <[email protected]> - - QGpgME is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License, - version 2, as published by the Free Software Foundation. - - QGpgME is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - - In addition, as a special exception, the copyright holders give - permission to link the code of this program with any edition of - the Qt library by Trolltech AS, Norway (or with modified versions - of Qt that use the same license as Qt), and distribute linked - combinations including the two. You must obey the GNU General - Public License in all respects for all of the code used other than - Qt. If you modify this file, you may extend this exception to - your version of the file, but you are not obligated to do so. If - you do not wish to do so, delete this exception statement from - your version. -*/ - -#ifdef HAVE_CONFIG_H - #include "config.h" -#endif - -#include <debug.h> -#include <protocol.h> -#include <verifyopaquejob.h> - -#include <QCommandLineParser> -#include <QCoreApplication> -#include <QDebug> -#include <QFile> -#include <QTimer> - -#include <gpgme++/context.h> -#include <gpgme++/verificationresult.h> - -#include <iostream> - -using namespace GpgME; - -std::ostream &operator<<(std::ostream &os, const QString &s) -{ - return os << s.toLocal8Bit().constData(); -} - -struct CommandLineOptions { - bool processAllSignatures = false; - QString inputFile; - QString outputFile; - std::chrono::seconds cancelTimeout{0}; -}; - -CommandLineOptions parseCommandLine(const QStringList &arguments) -{ - CommandLineOptions options; - - QCommandLineParser parser; - parser.setApplicationDescription("Test program for VerifyOpaqueJob"); - parser.addHelpOption(); - parser.addOptions({ - {{"o", "output"}, "Write output to FILE.", "FILE"}, - {"cancel-after", "Cancel the running job after SECONDS seconds.", "SECONDS"}, - {"process-all-signatures", "Don't stop signature checking after bad signature."}, - }); - parser.addPositionalArgument("file", "File to verify", "FILE"); - - parser.process(arguments); - - const auto args = parser.positionalArguments(); - if (args.size() != 1) { - parser.showHelp(1); - } - - options.processAllSignatures = parser.isSet("process-all-signatures"); - options.inputFile = args.front(); - options.outputFile = parser.value("output"); - if (parser.isSet("cancel-after")) { - bool ok; - options.cancelTimeout = std::chrono::seconds{parser.value("cancel-after").toInt(&ok)}; - if (!ok) { - options.cancelTimeout = std::chrono::seconds{-1}; - } - } - - return options; -} - -int main(int argc, char **argv) -{ - GpgME::initializeLibrary(); - - QCoreApplication app{argc, argv}; - app.setApplicationName("run-verifyopaquejob"); - - const auto options = parseCommandLine(app.arguments()); - if (options.cancelTimeout.count() < 0) { - std::cerr << "Ignoring invalid timeout for cancel." << std::endl; - } - - std::shared_ptr<QFile> output; - if (options.outputFile.isEmpty() || options.outputFile == QLatin1String{"-"}) { - output.reset(new QFile); - output->open(stdout, QIODevice::WriteOnly); - } else { - if (QFile::exists(options.outputFile)) { - qCritical() << "File" << options.outputFile << "exists. Bailing out."; - return 1; - } - } - - auto job = QGpgME::openpgp()->verifyOpaqueJob(); - if (!job) { - std::cerr << "Error: Could not create job" << std::endl; - return 1; - } - QObject::connect(job, - &QGpgME::VerifyOpaqueJob::result, - &app, - [](const GpgME::VerificationResult &verificationResult, - const QByteArray &, - const QString &auditLog, - const GpgME::Error &) { - std::cerr << "Diagnostics: " << auditLog << std::endl; - std::cerr << "Verification Result: " << verificationResult << std::endl; - qApp->quit(); - }); - if (options.cancelTimeout.count() > 0) { - QTimer::singleShot(options.cancelTimeout, job, [job]() { - std::cerr << "Canceling job" << std::endl; - job->slotCancel(); - }); - } - - std::shared_ptr<QFile> input; - GpgME::Error err; - job->setProcessAllSignatures(options.processAllSignatures); - if (output) { - input.reset(new QFile{options.inputFile}); - input->open(QIODevice::ReadOnly); - job->start(input, output); - } else { - job->setInputFile(options.inputFile); - job->setOutputFile(options.outputFile); - err = job->startIt(); - } - if (err) { - std::cerr << "Error: Starting the job failed: " << err << std::endl; - return 1; - } - - return app.exec(); -} diff --git a/lang/qt/tests/run-wkdrefreshjob.cpp b/lang/qt/tests/run-wkdrefreshjob.cpp deleted file mode 100644 index 17bad83d..00000000 --- a/lang/qt/tests/run-wkdrefreshjob.cpp +++ /dev/null @@ -1,154 +0,0 @@ -/* - run-wkdrefreshjob.cpp - - This file is part of QGpgME's test suite. - Copyright (c) 2023 g10 Code GmbH - Software engineering by Ingo Klöcker <[email protected]> - - QGpgME is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - QGpgME is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - - In addition, as a special exception, the copyright holders give - permission to link the code of this program with any edition of - the Qt library by Trolltech AS, Norway (or with modified versions - of Qt that use the same license as Qt), and distribute linked - combinations including the two. You must obey the GNU General - Public License in all respects for all of the code used other than - Qt. If you modify this file, you may extend this exception to - your version of the file, but you are not obligated to do so. If - you do not wish to do so, delete this exception statement from - your version. -*/ - -#ifdef HAVE_CONFIG_H - #include "config.h" -#endif - -#include <debug.h> -#include <protocol.h> -#include <wkdrefreshjob.h> - -#include <QCommandLineParser> -#include <QCoreApplication> -#include <QDebug> - -#include <gpgme++/context.h> -#include <gpgme++/importresult.h> - -#include <iostream> - -using namespace GpgME; - -std::ostream &operator<<(std::ostream &os, const QString &s) -{ - return os << s.toLocal8Bit().constData(); -} - -struct CommandLineOptions { - bool allUserIds; - QString keyId; -}; - -CommandLineOptions parseCommandLine(const QStringList &arguments) -{ - CommandLineOptions options; - - QCommandLineParser parser; - parser.setApplicationDescription("Test program for WKDRefreshJob"); - parser.addHelpOption(); - parser.addOptions({ - {"all-userids", "Query WKD for all user IDs."}, - }); - parser.addPositionalArgument("key ID", "Key to refresh"); - - parser.process(arguments); - - const auto args = parser.positionalArguments(); - if (args.size() != 1) { - parser.showHelp(1); - } - - options.allUserIds = parser.isSet("all-userids"); - options.keyId = args[0]; - - return options; -} - -Key getOpenPGPKey(const QString &keyId, Error &err) -{ - Key key; - - auto ctx = Context::create(GpgME::OpenPGP); - if (!ctx) { - err = Error::fromCode(GPG_ERR_GENERAL); - return key; - } - - key = ctx->key(keyId.toLatin1().constData(), err); - if (err.code() == GPG_ERR_EOF) { - err = Error{}; - } - return key; -} - -int main(int argc, char **argv) -{ - GpgME::initializeLibrary(); - - QCoreApplication app{argc, argv}; - app.setApplicationName("run-wkdrefreshjob"); - - const auto options = parseCommandLine(app.arguments()); - - Error err; - const auto key = getOpenPGPKey(options.keyId, err); - if (err.code() == GPG_ERR_AMBIGUOUS_NAME) { - std::cerr << "Error: Multiple OpenPGP keys matching '" << options.keyId << "' found" << std::endl; - return 1; - } - if (key.isNull()) { - std::cerr << "Error: No OpenPGP key matching '" << options.keyId << "' found" << std::endl; - return 1; - } - if (err) { - std::cerr << "Error while getting OpenPGP key: " << err << std::endl; - return 1; - } - std::cout << "Refreshing OpenPGP key " << key.userID(0).id() << std::endl; - - auto job = QGpgME::openpgp()->wkdRefreshJob(); - if (!job) { - std::cerr << "Error: Could not create job to refresh OpenPGP key" << std::endl; - return 1; - } - QObject::connect(job, &QGpgME::WKDRefreshJob::result, &app, [](const GpgME::ImportResult &result, const QString &, const GpgME::Error &) { - if (result.isNull()) { - std::cout << "Empty result. Lookup via WKD failed or no user ID was originally retrieved via WKD." << std::endl; - } else { - std::cout << "Result: " << result << std::endl; - } - qApp->quit(); - }); - if (options.allUserIds) { - err = job->start(key.userIDs()); - } else { - err = job->start({key}); - } - if (err) { - std::cerr << "Error: " << err << std::endl; - return 1; - } - - return app.exec(); -} diff --git a/lang/qt/tests/t-addexistingsubkey.cpp b/lang/qt/tests/t-addexistingsubkey.cpp deleted file mode 100644 index df620ddb..00000000 --- a/lang/qt/tests/t-addexistingsubkey.cpp +++ /dev/null @@ -1,266 +0,0 @@ -/* t-addexistingsubkey.cpp - - This file is part of qgpgme, the Qt API binding for gpgme - Copyright (c) 2022 g10 Code GmbH - Software engineering by Ingo Klöcker <[email protected]> - - QGpgME is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - QGpgME is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - - In addition, as a special exception, the copyright holders give - permission to link the code of this program with any edition of - the Qt library by Trolltech AS, Norway (or with modified versions - of Qt that use the same license as Qt), and distribute linked - combinations including the two. You must obey the GNU General - Public License in all respects for all of the code used other than - Qt. If you modify this file, you may extend this exception to - your version of the file, but you are not obligated to do so. If - you do not wish to do so, delete this exception statement from - your version. -*/ -#ifdef HAVE_CONFIG_H - #include "config.h" -#endif - -#include "t-support.h" - -#include "addexistingsubkeyjob.h" -#include "protocol.h" - -#include <QSignalSpy> -#include <QTest> - -#include <gpgme++/context.h> -#include <gpgme++/data.h> -#include <gpgme++/engineinfo.h> - -#include <algorithm> - -using namespace QGpgME; -using namespace GpgME; - -static const char *requiredVersion = "2.3.5"; - -/* Test keys - sec# ed25519 2022-01-13 [SC] - 1CB8C6A0317AA83F44FE009932392C82B814C8E0 - uid [ unknown] [email protected] - ssb cv25519 2022-01-13 [E] - ssb cv25519 2022-01-13 [E] [expires: 2100-01-01] - - sec ed25519 2022-01-13 [SC] - C3C87F0A3920B01F9E4450EA2B79F21D4DD10BFC - uid [ unknown] [email protected] - ssb cv25519 2022-01-13 [E] - * generated with -export GNUPGHOME=$(mktemp -d) -gpg -K -gpg --batch --pinentry-mode loopback --passphrase abc --quick-gen-key [email protected] default default never -fpr=$(gpg -k --with-colons [email protected] | grep ^fpr | head -1 | cut -d ':' -f 10) -gpg --batch --pinentry-mode loopback --passphrase abc --quick-add-key ${fpr} default default 21000101T120000 -gpg --batch --pinentry-mode loopback --passphrase abc --quick-gen-key [email protected] default default never -gpg -K -gpg --export-secret-subkeys --armor --batch --pinentry-mode loopback --passphrase abc --comment [email protected] [email protected] | sed 's/\(.*\)/ "\1\\n"/' -gpg --export-secret-keys --armor --batch --pinentry-mode loopback --passphrase abc --comment [email protected] [email protected] | sed 's/\(.*\)/ "\1\\n"/' -#rm -rf ${GNUPGHOME} -unset GNUPGHOME -*/ -static const char *testKeyData = - "-----BEGIN PGP PRIVATE KEY BLOCK-----\n" - "Comment: [email protected]\n" - "\n" - "lDsEYd/ujBYJKwYBBAHaRw8BAQdAwiZPINTcrpgmu6ZWSaPZlcRSd4nDuofVMhe7\n" - "c2XrFyT/AGUAR05VAbQWc291cmNlLWtleUBleGFtcGxlLm5ldIiUBBMWCgA8FiEE\n" - "HLjGoDF6qD9E/gCZMjksgrgUyOAFAmHf7owCGwMFCwkIBwIDIgIBBhUKCQgLAgQW\n" - "AgMBAh4HAheAAAoJEDI5LIK4FMjgupIA/Au2YEAT9dYdJd0eJCJerG5YAeoB+uBs\n" - "mBkgr6xXE0bIAP43b6u1Jtvf/Wm3BhRbLd5Tg67Ba4CIZ8ZLGng73FBoBpyLBGHf\n" - "7owSCisGAQQBl1UBBQEBB0Cpg8Qof/WShxROZZtmPnw24vTk0R8nIAF1CZJ0bG/C\n" - "SwMBCAf+BwMCtzxziVxQEor8w/VVzHp4/hVSCUyrpiX7Djf04cIMs2bFPduZLgxb\n" - "c1SXhlgiqU0YBNntbGGNdKjTP6FMbYWq1+NwQm6ZXtC76LPG7syM94h4BBgWCgAg\n" - "FiEEHLjGoDF6qD9E/gCZMjksgrgUyOAFAmHf7owCGwwACgkQMjksgrgUyOCI0wEA\n" - "+f56fkvDDUwMOMw7n4+GKpfJXpWhVL08ttccbBOa/9IA/2HYA/78ZaD8E5EyqAEK\n" - "Aj9Au+2oJu9V5qo92QEoqwYHnIsEYd/vgxIKKwYBBAGXVQEFAQEHQBa9FxJkm/9D\n" - "xABildkaYMrbJbu8BPk6uv9V8aLmv9FnAwEIB/4HAwIPhcbN8s6OzPz8/g78TrCh\n" - "xqQb2kygCEj+OQ4/XXU3lus2b5xS5h44LGt99Wisqx+wVPDXmPDJOaxjhHXDmJxd\n" - "/LplIEhykojSm3uUDxERiH4EGBYKACYWIQQcuMagMXqoP0T+AJkyOSyCuBTI4AUC\n" - "Yd/vgwIbDAUJkqcQPQAKCRAyOSyCuBTI4IUjAP9BTfOD+jy6lLmzNO9pquRSAxi/\n" - "PQuglGtpS0LQEJMEOwD+PFnsMe2EtQ+WVSDBeB7O0m61EXeY+RhpuhNtsNXVuwc=\n" - "=wIPU\n" - "-----END PGP PRIVATE KEY BLOCK-----\n" - "-----BEGIN PGP PRIVATE KEY BLOCK-----\n" - "Comment: [email protected]\n" - "\n" - "lIYEYd/v/RYJKwYBBAHaRw8BAQdAKoILWXG3yaLb2EniNKQLUjwsrvy5vgAN299J\n" - "W5cFbrz+BwMC/uKbCq3sK5H8QVtEQ/IxGmjWNBpy6c8EDlOG4APi4o4VE+bEYD8w\n" - "J3Kk/lzSm6ZT5vC6DDASks797omjXD+J7zZ0vtTPvheYi/nsVz2UebQWdGFyZ2V0\n" - "LWtleUBleGFtcGxlLm5ldIiUBBMWCgA8FiEEw8h/CjkgsB+eRFDqK3nyHU3RC/wF\n" - "AmHf7/0CGwMFCwkIBwIDIgIBBhUKCQgLAgQWAgMBAh4HAheAAAoJECt58h1N0Qv8\n" - "rXcBAPxnkXqpp4IY3iTKV5XAdo7Uys7U/joUD73rj2XEvgI1AQDhKK4PLxPhf3ki\n" - "FKU0RA7itxzOH+F8bQ5BdYS49jDPCpyLBGHf7/0SCisGAQQBl1UBBQEBB0Dq9rwA\n" - "hAA2UFJShFsLFp7+g4uhWDfuDa3VjeIQRM+9QgMBCAf+BwMCMfCTl0LNqsn836t5\n" - "f2ZHBuMcNs4JWYmdLAIVaewEHq7zhOsX3iB+/yxwu9g2mXc4XUJ1iQzXLOYwgGov\n" - "8jIovrr01hDkSg4rvM9JKMWdd4h4BBgWCgAgFiEEw8h/CjkgsB+eRFDqK3nyHU3R\n" - "C/wFAmHf7/0CGwwACgkQK3nyHU3RC/xyfAEAqnMdSv6FTAwAWrYvJqJtSVoEhjMn\n" - "3c2qMsu34Bk86/MBAKHbLFmdyePvHaxKeO8CkQDoJzK8rYzw3RAmq/5JsQkL\n" - "=rOVf\n" - "-----END PGP PRIVATE KEY BLOCK-----\n"; - -class AddExistingSubkeyJobTest : public QGpgMETest -{ - Q_OBJECT - -private Q_SLOTS: - - void initTestCase() - { - QGpgMETest::initTestCase(); - - // set up the test fixture for this test - qputenv("GNUPGHOME", mGnupgHomeTestFixture.path().toUtf8()); - QVERIFY(importSecretKeys(testKeyData, 2)); - } - - void init() - { - if (GpgME::engineInfo(GpgME::GpgEngine).engineVersion() < requiredVersion) { - QSKIP("gpg does not yet support adding an existing subkey to another key via the command API"); - } - - // set up a copy of the test fixture for each test function - mGnupgHomeTestCopy.reset(new QTemporaryDir{}); - QVERIFY(copyKeyrings(mGnupgHomeTestFixture.path(), mGnupgHomeTestCopy->path())); - qputenv("GNUPGHOME", mGnupgHomeTestCopy->path().toUtf8()); - } - - void testAddExistingSubkeyAsync() - { - // Get the key the subkey should be added to - auto key = getTestKey("[email protected]"); - QVERIFY(!key.isNull()); - - // Get the key with the subkey to add - auto sourceKey = getTestKey("[email protected]", 3); - QVERIFY(!sourceKey.isNull()); - - auto job = std::unique_ptr<AddExistingSubkeyJob>{openpgp()->addExistingSubkeyJob()}; - hookUpPassphraseProvider(job.get()); - - Error result; - connect(job.get(), &AddExistingSubkeyJob::result, - job.get(), [this, &result](const Error &result_) { - result = result_; - Q_EMIT asyncDone(); - }); - QVERIFY(!job->start(key, sourceKey.subkey(1))); - job.release(); // after the job has been started it's on its own - - QSignalSpy spy (this, SIGNAL(asyncDone())); - QVERIFY(spy.wait(QSIGNALSPY_TIMEOUT)); - - QCOMPARE(result.code(), static_cast<int>(GPG_ERR_NO_ERROR)); - key.update(); - QCOMPARE(key.numSubkeys(), 3u); - } - - void testAddExistingSubkeySync() - { - // Get the key the subkey should be added to - auto key = getTestKey("[email protected]"); - QVERIFY(!key.isNull()); - - // Get the key with the subkey to add - auto sourceKey = getTestKey("[email protected]", 3); - QVERIFY(!sourceKey.isNull()); - auto sourceSubkey = sourceKey.subkey(1); - QVERIFY(sourceSubkey.expirationTime() == 0); - - auto job = std::unique_ptr<AddExistingSubkeyJob>{openpgp()->addExistingSubkeyJob()}; - hookUpPassphraseProvider(job.get()); - - const auto result = job->exec(key, sourceSubkey); - - QCOMPARE(result.code(), static_cast<int>(GPG_ERR_NO_ERROR)); - key.update(); - QCOMPARE(key.numSubkeys(), 3u); - QCOMPARE(key.subkey(2).expirationTime(), 0); - } - - void testAddExistingSubkeyWithExpiration() - { - // Get the key the subkey should be added to - auto key = getTestKey("[email protected]"); - QVERIFY(!key.isNull()); - - // Get the key with the subkey to add - auto sourceKey = getTestKey("[email protected]", 3); - QVERIFY(!sourceKey.isNull()); - auto sourceSubkey = sourceKey.subkey(2); - QVERIFY(sourceSubkey.expirationTime() != 0); - - auto job = std::unique_ptr<AddExistingSubkeyJob>{openpgp()->addExistingSubkeyJob()}; - hookUpPassphraseProvider(job.get()); - - const auto result = job->exec(key, sourceSubkey); - - if (sourceSubkey.expirationTime() > 0) { - QCOMPARE(result.code(), static_cast<int>(GPG_ERR_NO_ERROR)); - key.update(); - QCOMPARE(key.numSubkeys(), 3u); - - // allow 1 second different expiration because gpg calculates with - // expiration as difference to current time and takes current time - // several times - const auto allowedDeltaTSeconds = 1; - const auto expectedExpirationRange = std::make_pair( - uint_least32_t(sourceSubkey.expirationTime()) - allowedDeltaTSeconds, - uint_least32_t(sourceSubkey.expirationTime()) + allowedDeltaTSeconds); - const auto actualExpiration = uint_least32_t(key.subkey(2).expirationTime()); - QVERIFY2(actualExpiration >= expectedExpirationRange.first, - ("actual: " + std::to_string(actualExpiration) + - "; expected: " + std::to_string(expectedExpirationRange.first)).c_str()); - QVERIFY2(actualExpiration <= expectedExpirationRange.second, - ("actual: " + std::to_string(actualExpiration) + - "; expected: " + std::to_string(expectedExpirationRange.second)).c_str()); - } else { - // on 32-bit systems the expiration date of the test key overflows; - // in this case we expect an appropriate error code - QCOMPARE(result.code(), static_cast<int>(GPG_ERR_INV_TIME)); - } - } - -private: - Key getTestKey(const char *pattern, unsigned int expectedSubkeys = 2) - { - auto ctx = Context::create(OpenPGP); - VERIFY_OR_OBJECT(ctx); - - Error err; - auto key = ctx->key(pattern, err, /*secret=*/true); - VERIFY_OR_OBJECT(!err); - VERIFY_OR_OBJECT(!key.isNull()); - COMPARE_OR_OBJECT(key.numSubkeys(), expectedSubkeys); - for (unsigned int i = 0; i < key.numSubkeys(); ++i) { - VERIFY_OR_OBJECT(!key.subkey(i).isNull()); - } - return key; - } - -private: - QTemporaryDir mGnupgHomeTestFixture; - std::unique_ptr<QTemporaryDir> mGnupgHomeTestCopy; -}; - -QTEST_MAIN(AddExistingSubkeyJobTest) - -#include "t-addexistingsubkey.moc" diff --git a/lang/qt/tests/t-changeexpiryjob.cpp b/lang/qt/tests/t-changeexpiryjob.cpp deleted file mode 100644 index b64bf798..00000000 --- a/lang/qt/tests/t-changeexpiryjob.cpp +++ /dev/null @@ -1,397 +0,0 @@ -/* t-changeexpiryjob.cpp - - This file is part of qgpgme, the Qt API binding for gpgme - Copyright (c) 2021 g10 Code GmbH - Software engineering by Ingo Klöcker <[email protected]> - - QGpgME is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - QGpgME is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - - In addition, as a special exception, the copyright holders give - permission to link the code of this program with any edition of - the Qt library by Trolltech AS, Norway (or with modified versions - of Qt that use the same license as Qt), and distribute linked - combinations including the two. You must obey the GNU General - Public License in all respects for all of the code used other than - Qt. If you modify this file, you may extend this exception to - your version of the file, but you are not obligated to do so. If - you do not wish to do so, delete this exception statement from - your version. -*/ - -#ifdef HAVE_CONFIG_H - #include "config.h" -#endif - -#include "t-support.h" - -#include "changeexpiryjob.h" -#include <gpgme++/context.h> -#include <gpgme++/engineinfo.h> -#include "protocol.h" -#include "util.h" - -#include <QSignalSpy> -#include <QTemporaryDir> -#include <QTest> - -using namespace QGpgME; -using namespace GpgME; - -class TestChangeExpiryJob: public QGpgMETest -{ - Q_OBJECT - -private Q_SLOTS: - void test_change_expiration_default_without_subkeys() - { - Error err; - - if (!loopbackSupported()) { - return; - } - - auto ctx = Context::create(OpenPGP); - QVERIFY(ctx); - - // Get the key ([email protected]) - auto key = ctx->key("A0FF4590BB6122EDEF6E3C542D727CC768697734", err, true); - QVERIFY(!err); - QVERIFY(!key.isNull()); - QVERIFY(!key.subkey(0).isNull()); - QVERIFY(!key.subkey(1).isNull()); - const auto subkeyExpiration = uint_least32_t(key.subkey(1).expirationTime()); - - { - // Create the job - auto job = std::unique_ptr<ChangeExpiryJob>{openpgp()->changeExpiryJob()}; - QVERIFY(job); - hookUpPassphraseProvider(job.get()); - - // Use defaults of job - - connect(job.get(), &ChangeExpiryJob::result, - this, [this] (const GpgME::Error &err2, const QString &, const GpgME::Error &) { - Q_EMIT asyncDone(); - if (err2) { - QFAIL(qPrintable(QString("The ChangeExpiryJob failed with '%1'.").arg(errorAsString(err2)))); - } - }); - - const auto newExpirationDate = QDateTime::currentDateTime().addDays(1); - job->start(key, newExpirationDate); - QSignalSpy spy (this, SIGNAL(asyncDone())); - QVERIFY(spy.wait(QSIGNALSPY_TIMEOUT)); - - // At this point the expiration date should have been changed. - key.update(); - - // allow a few seconds earlier expiration because job calculates "seconds from now" passed to gpg after it was started - const auto expectedExpirationRange = std::make_pair( - newExpirationDate.toSecsSinceEpoch() - 10, - QDateTime::currentDateTime().addDays(1).toSecsSinceEpoch()); - { - const auto actualExpiration = uint_least32_t(key.subkey(0).expirationTime()); - QVERIFY2(actualExpiration >= expectedExpirationRange.first, - ("actual: " + std::to_string(actualExpiration) + - "; expected: " + std::to_string(expectedExpirationRange.first)).c_str()); - QVERIFY2(actualExpiration <= expectedExpirationRange.second, - ("actual: " + std::to_string(actualExpiration) + - "; expected: " + std::to_string(expectedExpirationRange.second)).c_str()); - } - { - const auto actualExpiration = uint_least32_t(key.subkey(1).expirationTime()); - QCOMPARE(actualExpiration, subkeyExpiration); // unchanged - } - } - } - - void test_change_expiration_default_with_subkeys() - { - Error err; - - if (!loopbackSupported()) { - return; - } - - auto ctx = Context::create(OpenPGP); - QVERIFY(ctx); - - // Get the key ([email protected]) - auto key = ctx->key("A0FF4590BB6122EDEF6E3C542D727CC768697734", err, true); - QVERIFY(!err); - QVERIFY(!key.isNull()); - QVERIFY(!key.subkey(0).isNull()); - QVERIFY(!key.subkey(1).isNull()); - const auto primaryKeyExpiration = uint_least32_t(key.subkey(0).expirationTime()); - - { - // Create the job - auto job = std::unique_ptr<ChangeExpiryJob>{openpgp()->changeExpiryJob()}; - QVERIFY(job); - hookUpPassphraseProvider(job.get()); - - // Use defaults of job - - connect(job.get(), &ChangeExpiryJob::result, - this, [this] (const GpgME::Error &err2, const QString &, const GpgME::Error &) { - Q_EMIT asyncDone(); - if (err2) { - QFAIL(qPrintable(QString("The ChangeExpiryJob failed with '%1'.").arg(errorAsString(err2)))); - } - }); - - const auto newExpirationDate = QDateTime::currentDateTime().addDays(2); - job->start(key, newExpirationDate, {key.subkey(1)}); - QSignalSpy spy (this, SIGNAL(asyncDone())); - QVERIFY(spy.wait(QSIGNALSPY_TIMEOUT)); - - // At this point the expiration date should have been changed. - key.update(); - - // allow a few seconds earlier expiration because job calculates "seconds from now" passed to gpg after it was started - const auto expectedExpirationRange = std::make_pair( - newExpirationDate.toSecsSinceEpoch() - 10, - QDateTime::currentDateTime().addDays(2).toSecsSinceEpoch()); - { - const auto actualExpiration = uint_least32_t(key.subkey(0).expirationTime()); - QCOMPARE(actualExpiration, primaryKeyExpiration); // unchanged - } - { - const auto actualExpiration = uint_least32_t(key.subkey(1).expirationTime()); - QVERIFY2(actualExpiration >= expectedExpirationRange.first, - ("actual: " + std::to_string(actualExpiration) + - "; expected: " + std::to_string(expectedExpirationRange.first)).c_str()); - QVERIFY2(actualExpiration <= expectedExpirationRange.second, - ("actual: " + std::to_string(actualExpiration) + - "; expected: " + std::to_string(expectedExpirationRange.second)).c_str()); - } - } - } - - void test_change_expiration_update_primary_key_without_subkeys() - { - Error err; - - if (!loopbackSupported()) { - return; - } - - auto ctx = Context::create(OpenPGP); - QVERIFY(ctx); - - // Get the key ([email protected]) - auto key = ctx->key("A0FF4590BB6122EDEF6E3C542D727CC768697734", err, true); - QVERIFY(!err); - QVERIFY(!key.isNull()); - QVERIFY(!key.subkey(0).isNull()); - QVERIFY(!key.subkey(1).isNull()); - const auto subkeyExpiration = uint_least32_t(key.subkey(1).expirationTime()); - - { - // Create the job - auto job = std::unique_ptr<ChangeExpiryJob>{openpgp()->changeExpiryJob()}; - QVERIFY(job); - hookUpPassphraseProvider(job.get()); - - // Set up the job - job->setOptions(ChangeExpiryJob::UpdatePrimaryKey); - - connect(job.get(), &ChangeExpiryJob::result, - this, [this] (const GpgME::Error &err2, const QString &, const GpgME::Error &) { - Q_EMIT asyncDone(); - if (err2) { - QFAIL(qPrintable(QString("The ChangeExpiryJob failed with '%1'.").arg(errorAsString(err2)))); - } - }); - - const auto newExpirationDate = QDateTime::currentDateTime().addDays(3); - job->start(key, newExpirationDate, {}); - QSignalSpy spy (this, SIGNAL(asyncDone())); - QVERIFY(spy.wait(QSIGNALSPY_TIMEOUT)); - - // At this point the expiration date should have been changed. - key.update(); - - // allow a few seconds earlier expiration because job calculates "seconds from now" passed to gpg after it was started - const auto expectedExpirationRange = std::make_pair( - newExpirationDate.toSecsSinceEpoch() - 10, - QDateTime::currentDateTime().addDays(3).toSecsSinceEpoch()); - { - const auto actualExpiration = uint_least32_t(key.subkey(0).expirationTime()); - QVERIFY2(actualExpiration >= expectedExpirationRange.first, - ("actual: " + std::to_string(actualExpiration) + - "; expected: " + std::to_string(expectedExpirationRange.first)).c_str()); - QVERIFY2(actualExpiration <= expectedExpirationRange.second, - ("actual: " + std::to_string(actualExpiration) + - "; expected: " + std::to_string(expectedExpirationRange.second)).c_str()); - } - { - const auto actualExpiration = uint_least32_t(key.subkey(1).expirationTime()); - QCOMPARE(actualExpiration, subkeyExpiration); // unchanged - } - } - } - - void test_change_expiration_update_primary_key_with_subkeys() - { - Error err; - - if (!loopbackSupported()) { - return; - } - - auto ctx = Context::create(OpenPGP); - QVERIFY(ctx); - - // Get the key ([email protected]) - auto key = ctx->key("A0FF4590BB6122EDEF6E3C542D727CC768697734", err, true); - QVERIFY(!err); - QVERIFY(!key.isNull()); - QVERIFY(!key.subkey(0).isNull()); - QVERIFY(!key.subkey(1).isNull()); - - { - // Create the job - auto job = std::unique_ptr<ChangeExpiryJob>{openpgp()->changeExpiryJob()}; - QVERIFY(job); - hookUpPassphraseProvider(job.get()); - - // Set up the job - job->setOptions(ChangeExpiryJob::UpdatePrimaryKey); - - connect(job.get(), &ChangeExpiryJob::result, - this, [this] (const GpgME::Error &err2, const QString &, const GpgME::Error &) { - Q_EMIT asyncDone(); - if (err2) { - QFAIL(qPrintable(QString("The ChangeExpiryJob failed with '%1'.").arg(errorAsString(err2)))); - } - }); - - const auto newExpirationDate = QDateTime::currentDateTime().addDays(4); - job->start(key, newExpirationDate, {key.subkey(1)}); - QSignalSpy spy (this, SIGNAL(asyncDone())); - QVERIFY(spy.wait(QSIGNALSPY_TIMEOUT)); - - // At this point the expiration date should have been changed. - key.update(); - - // allow a few seconds earlier expiration because job calculates "seconds from now" passed to gpg after it was started - const auto expectedExpirationRange = std::make_pair( - newExpirationDate.toSecsSinceEpoch() - 10, - QDateTime::currentDateTime().addDays(4).toSecsSinceEpoch()); - { - const auto actualExpiration = uint_least32_t(key.subkey(0).expirationTime()); - QVERIFY2(actualExpiration >= expectedExpirationRange.first, - ("actual: " + std::to_string(actualExpiration) + - "; expected: " + std::to_string(expectedExpirationRange.first)).c_str()); - QVERIFY2(actualExpiration <= expectedExpirationRange.second, - ("actual: " + std::to_string(actualExpiration) + - "; expected: " + std::to_string(expectedExpirationRange.second)).c_str()); - } - { - const auto actualExpiration = uint_least32_t(key.subkey(1).expirationTime()); - QVERIFY2(actualExpiration >= expectedExpirationRange.first, - ("actual: " + std::to_string(actualExpiration) + - "; expected: " + std::to_string(expectedExpirationRange.first)).c_str()); - QVERIFY2(actualExpiration <= expectedExpirationRange.second, - ("actual: " + std::to_string(actualExpiration) + - "; expected: " + std::to_string(expectedExpirationRange.second)).c_str()); - } - } - } - - void test_change_expiration_update_primary_key_and_all_subkeys() - { - Error err; - - if (!loopbackSupported()) { - return; - } - - auto ctx = Context::create(OpenPGP); - QVERIFY(ctx); - - // Get the key ([email protected]) - auto key = ctx->key("A0FF4590BB6122EDEF6E3C542D727CC768697734", err, true); - QVERIFY(!err); - QVERIFY(!key.isNull()); - QVERIFY(!key.subkey(0).isNull()); - QVERIFY(!key.subkey(1).isNull()); - - { - // Create the job - auto job = std::unique_ptr<ChangeExpiryJob>{openpgp()->changeExpiryJob()}; - QVERIFY(job); - hookUpPassphraseProvider(job.get()); - - // Set up the job - job->setOptions(ChangeExpiryJob::UpdatePrimaryKey | ChangeExpiryJob::UpdateAllSubkeys); - - connect(job.get(), &ChangeExpiryJob::result, - this, [this] (const GpgME::Error &err2, const QString &, const GpgME::Error &) { - Q_EMIT asyncDone(); - if (err2) { - QFAIL(qPrintable(QString("The ChangeExpiryJob failed with '%1'.").arg(errorAsString(err2)))); - } - }); - - const auto newExpirationDate = QDateTime::currentDateTime().addDays(5); - job->start(key, newExpirationDate); - QSignalSpy spy (this, SIGNAL(asyncDone())); - QVERIFY(spy.wait(QSIGNALSPY_TIMEOUT)); - - // At this point the expiration date should have been changed. - key.update(); - - // allow a few seconds earlier expiration because job calculates "seconds from now" passed to gpg after it was started - const auto expectedExpirationRange = std::make_pair( - newExpirationDate.toSecsSinceEpoch() - 10, - QDateTime::currentDateTime().addDays(5).toSecsSinceEpoch()); - { - const auto actualExpiration = uint_least32_t(key.subkey(0).expirationTime()); - QVERIFY2(actualExpiration >= expectedExpirationRange.first, - ("actual: " + std::to_string(actualExpiration) + - "; expected: " + std::to_string(expectedExpirationRange.first)).c_str()); - QVERIFY2(actualExpiration <= expectedExpirationRange.second, - ("actual: " + std::to_string(actualExpiration) + - "; expected: " + std::to_string(expectedExpirationRange.second)).c_str()); - } - { - const auto actualExpiration = uint_least32_t(key.subkey(1).expirationTime()); - QVERIFY2(actualExpiration >= expectedExpirationRange.first, - ("actual: " + std::to_string(actualExpiration) + - "; expected: " + std::to_string(expectedExpirationRange.first)).c_str()); - QVERIFY2(actualExpiration <= expectedExpirationRange.second, - ("actual: " + std::to_string(actualExpiration) + - "; expected: " + std::to_string(expectedExpirationRange.second)).c_str()); - } - } - } - - void initTestCase() - { - QGpgMETest::initTestCase(); - const QString gpgHome = qgetenv("GNUPGHOME"); - QVERIFY(copyKeyrings(gpgHome, mDir.path())); - qputenv("GNUPGHOME", mDir.path().toUtf8()); - } - -private: - QTemporaryDir mDir; -}; - -QTEST_MAIN(TestChangeExpiryJob) - -#include "t-changeexpiryjob.moc" diff --git a/lang/qt/tests/t-config.cpp b/lang/qt/tests/t-config.cpp deleted file mode 100644 index 2f73b9a6..00000000 --- a/lang/qt/tests/t-config.cpp +++ /dev/null @@ -1,94 +0,0 @@ -/* t-config.cpp - - This file is part of qgpgme, the Qt API binding for gpgme - Copyright (c) 2016 by Bundesamt für Sicherheit in der Informationstechnik - Software engineering by Intevation GmbH - - QGpgME is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - QGpgME is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - - In addition, as a special exception, the copyright holders give - permission to link the code of this program with any edition of - the Qt library by Trolltech AS, Norway (or with modified versions - of Qt that use the same license as Qt), and distribute linked - combinations including the two. You must obey the GNU General - Public License in all respects for all of the code used other than - Qt. If you modify this file, you may extend this exception to - your version of the file, but you are not obligated to do so. If - you do not wish to do so, delete this exception statement from - your version. -*/ -#ifdef HAVE_CONFIG_H - #include "config.h" -#endif - -#include <QDebug> -#include <QTest> -#include <QTemporaryDir> -#include "t-support.h" -#include "protocol.h" -#include "cryptoconfig.h" -#include <gpgme++/engineinfo.h> - -#include <unistd.h> - -using namespace QGpgME; - -class CryptoConfigTest: public QGpgMETest -{ - Q_OBJECT - -private Q_SLOTS: - void testDefault() - { - if (GpgME::engineInfo(GpgME::GpgEngine).engineVersion() < "2.2.0") { - // We are using compliance here and other options might also - // be unsupported in older versions. - return; - } - auto conf = cryptoConfig(); - QVERIFY(conf); - auto entry = conf->entry(QStringLiteral("gpg"), QStringLiteral("compliance")); - QVERIFY(entry); - const auto defaultValue = entry->defaultValue().toString(); - QCOMPARE(defaultValue, QStringLiteral("gnupg")); - - entry->setStringValue("de-vs"); - conf->sync(true); - conf->clear(); - entry = conf->entry(QStringLiteral("gpg"), QStringLiteral("compliance")); - QCOMPARE(entry->stringValue(), QStringLiteral("de-vs")); - - entry->resetToDefault(); - conf->sync(true); - conf->clear(); - entry = conf->entry(QStringLiteral("gpg"), QStringLiteral("compliance")); - QCOMPARE(entry->stringValue(), defaultValue); - } - - void initTestCase() - { - QGpgMETest::initTestCase(); - const QString gpgHome = qgetenv("GNUPGHOME"); - qputenv("GNUPGHOME", mDir.path().toUtf8()); - QVERIFY(mDir.isValid()); - } -private: - QTemporaryDir mDir; - -}; - -QTEST_MAIN(CryptoConfigTest) - -#include "t-config.moc" diff --git a/lang/qt/tests/t-decryptverify.cpp b/lang/qt/tests/t-decryptverify.cpp deleted file mode 100644 index 9df10933..00000000 --- a/lang/qt/tests/t-decryptverify.cpp +++ /dev/null @@ -1,131 +0,0 @@ -/* t-verifiy.cpp - - This file is part of qgpgme, the Qt API binding for gpgme - Copyright (c) 2016 by Bundesamt für Sicherheit in der Informationstechnik - Software engineering by Intevation GmbH - Copyright (c) 2023 by g10 Code GmbH - Software engineering by Ingo Klöcker <[email protected]> - - QGpgME is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - QGpgME is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - - In addition, as a special exception, the copyright holders give - permission to link the code of this program with any edition of - the Qt library by Trolltech AS, Norway (or with modified versions - of Qt that use the same license as Qt), and distribute linked - combinations including the two. You must obey the GNU General - Public License in all respects for all of the code used other than - Qt. If you modify this file, you may extend this exception to - your version of the file, but you are not obligated to do so. If - you do not wish to do so, delete this exception statement from - your version. -*/ -#ifdef HAVE_CONFIG_H - #include "config.h" -#endif - -#include "t-support.h" - -#include <protocol.h> -#include <decryptverifyjob.h> - -#include <QDebug> -#include <QTest> - -#include <gpgme++/decryptionresult.h> -#include <gpgme++/key.h> -#include <gpgme++/verificationresult.h> - -using namespace QGpgME; -using namespace GpgME; - -static const char encryptedText[] = -"-----BEGIN PGP MESSAGE-----\n" -"\n" -"jA0ECQMCnJt+DX+RJJH90kIBCYlu/LYn57TCNO+O8kYwe4jcyEIaHqSZuvO50nFE\n" -"hQy9p33Y5VwP6uDOYOKxr1W6iE4GvbX+5UNKYdjjPL0m1ak=\n" -"=hgKY\n" -"-----END PGP MESSAGE-----\n"; - -static const char signedText[] = -"-----BEGIN PGP MESSAGE-----\n" -"\n" -"owGbwMvMwCSoW1RzPCOz3IRxjXQSR0lqcYleSUWJTZOvjVdpcYmCu1+oQmaJIleH\n" -"GwuDIBMDGysTSIqBi1MApi+nlGGuwDeHao53HBr+FoVGP3xX+kvuu9fCMJvl6IOf\n" -"y1kvP4y+8D5a11ang0udywsA\n" -"=Crq6\n" -"-----END PGP MESSAGE-----\n"; - -static const char storedText[] = -"-----BEGIN PGP MESSAGE-----\n" -"\n" -"owE7LZzEkHy7X86rtLhEwd0vVCGzRJELAA==\n" -"=VwL6\n" -"-----END PGP MESSAGE-----\n"; - -class DecryptVerifyTest: public QGpgMETest -{ - Q_OBJECT - -private Q_SLOTS: - - void testEncryptedOnlyData() - { - const QByteArray encryptedData{encryptedText}; - std::unique_ptr<DecryptVerifyJob> job{openpgp()->decryptVerifyJob(true)}; - hookUpPassphraseProvider(job.get()); - - QByteArray verified; - const auto result = job->exec(encryptedData, verified); - - const auto decryptionResult = result.first; - QCOMPARE(decryptionResult.error().code(), int{GPG_ERR_NO_ERROR}); - const auto verificationResult = result.second; - QCOMPARE(verificationResult.error().code(), int{GPG_ERR_NO_ERROR}); - QCOMPARE(verificationResult.numSignatures(), 0u); - } - - void testSignedOnlyData() - { - const QByteArray signedData{signedText}; - std::unique_ptr<DecryptVerifyJob> job{openpgp()->decryptVerifyJob(true)}; - - QByteArray verified; - const auto result = job->exec(signedData, verified); - - const auto decryptionResult = result.first; - QCOMPARE(decryptionResult.error().code(), int{GPG_ERR_NO_DATA}); - const auto verificationResult = result.second; - QCOMPARE(verificationResult.error().code(), int{GPG_ERR_NO_ERROR}); - QCOMPARE(verificationResult.numSignatures(), 1u); - } - - void testStoredData() - { - const QByteArray storedData{storedText}; - std::unique_ptr<DecryptVerifyJob> job{openpgp()->decryptVerifyJob(true)}; - - QByteArray verified; - const auto result = job->exec(storedData, verified); - - const auto decryptionResult = result.first; - QCOMPARE(decryptionResult.error().code(), int{GPG_ERR_NO_DATA}); - const auto verificationResult = result.second; - QCOMPARE(verificationResult.error().code(), int{GPG_ERR_NO_DATA}); - QCOMPARE(verificationResult.numSignatures(), 0u); - } -}; - -QTEST_MAIN(DecryptVerifyTest) -#include "t-decryptverify.moc" diff --git a/lang/qt/tests/t-disablekey.cpp b/lang/qt/tests/t-disablekey.cpp deleted file mode 100644 index 40581719..00000000 --- a/lang/qt/tests/t-disablekey.cpp +++ /dev/null @@ -1,118 +0,0 @@ -/* t-disablekey.cpp - - This file is part of qgpgme, the Qt API binding for gpgme - Copyright (c) 2024 g10 Code GmbH - Software engineering by Ingo Klöcker <[email protected]> - - QGpgME is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - QGpgME is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - - In addition, as a special exception, the copyright holders give - permission to link the code of this program with any edition of - the Qt library by Trolltech AS, Norway (or with modified versions - of Qt that use the same license as Qt), and distribute linked - combinations including the two. You must obey the GNU General - Public License in all respects for all of the code used other than - Qt. If you modify this file, you may extend this exception to - your version of the file, but you are not obligated to do so. If - you do not wish to do so, delete this exception statement from - your version. -*/ - -#ifdef HAVE_CONFIG_H - #include "config.h" -#endif - -#include "t-support.h" - -#include "quickjob.h" -#include "debug.h" -#include "keylistjob.h" -#include "protocol.h" - -#include <gpgme++/engineinfo.h> -#include <gpgme++/keylistresult.h> - -#include <QDebug> -#include <QSignalSpy> -#include <QTest> - -using namespace QGpgME; -using namespace GpgME; - -class DisableKeyTest: public QGpgMETest -{ - Q_OBJECT - - Key getTestKey() - { - const std::unique_ptr<KeyListJob> job{openpgp()->keyListJob(false, true, true)}; - std::vector<GpgME::Key> keys; - KeyListResult result = job->exec({QStringLiteral("[email protected]")}, false, keys); - VERIFY_OR_OBJECT(!result.error()); - VERIFY_OR_OBJECT(keys.size() == 1); - return keys.front(); - } - -private Q_SLOTS: - - void testDisableAndEnableKey() - { - if (GpgME::engineInfo(GpgME::GpgEngine).engineVersion() < "2.4.6") { - QSKIP("gpg does not yet support the --quick-set-ownertrust command"); - } - - Key key = getTestKey(); - QVERIFY(!key.isNull()); - QVERIFY(!key.isDisabled()); - - { - const std::unique_ptr<QuickJob> job{openpgp()->quickJob()}; - connect(job.get(), &QuickJob::result, this, [this](Error e) { - if (e) { - qDebug() << "Error in result:" << e; - } - QVERIFY(!e); - Q_EMIT asyncDone(); - }); - job->startSetKeyEnabled(key, false); - QSignalSpy spy{this, SIGNAL(asyncDone())}; - QVERIFY(spy.wait(QSIGNALSPY_TIMEOUT)); - } - key = getTestKey(); - QVERIFY(!key.isNull()); - QVERIFY(key.isDisabled()); - - { - const std::unique_ptr<QuickJob> job{openpgp()->quickJob()}; - connect(job.get(), &QuickJob::result, this, [this](Error e) { - if (e) { - qDebug() << "Error in result:" << e; - } - QVERIFY(!e); - Q_EMIT asyncDone(); - }); - job->startSetKeyEnabled(key, true); - QSignalSpy spy{this, SIGNAL(asyncDone())}; - QVERIFY(spy.wait(QSIGNALSPY_TIMEOUT)); - } - key = getTestKey(); - QVERIFY(!key.isNull()); - QVERIFY(!key.isDisabled()); - } -}; - -QTEST_MAIN(DisableKeyTest) - -#include "t-disablekey.moc" diff --git a/lang/qt/tests/t-encrypt.cpp b/lang/qt/tests/t-encrypt.cpp deleted file mode 100644 index aac49a4b..00000000 --- a/lang/qt/tests/t-encrypt.cpp +++ /dev/null @@ -1,333 +0,0 @@ -/* t-encrypt.cpp - - This file is part of qgpgme, the Qt API binding for gpgme - Copyright (c) 2016 by Bundesamt für Sicherheit in der Informationstechnik - Software engineering by Intevation GmbH - - QGpgME is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - QGpgME is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - - In addition, as a special exception, the copyright holders give - permission to link the code of this program with any edition of - the Qt library by Trolltech AS, Norway (or with modified versions - of Qt that use the same license as Qt), and distribute linked - combinations including the two. You must obey the GNU General - Public License in all respects for all of the code used other than - Qt. If you modify this file, you may extend this exception to - your version of the file, but you are not obligated to do so. If - you do not wish to do so, delete this exception statement from - your version. -*/ -#ifdef HAVE_CONFIG_H - #include "config.h" -#endif - -#include <QDebug> -#include <QTest> -#include <QTemporaryDir> -#include <QSignalSpy> -#include <QBuffer> -#include "keylistjob.h" -#include "encryptjob.h" -#include "signencryptjob.h" -#include <gpgme++/signingresult.h> -#include "encryptjob.h" -#include <gpgme++/encryptionresult.h> -#include <gpgme++/decryptionresult.h> -#include "decryptjob.h" -#include "qgpgmebackend.h" -#include <gpgme++/keylistresult.h> -#include <gpgme++/engineinfo.h> -#include "verifyopaquejob.h" -#include "t-support.h" - -#define PROGRESS_TEST_SIZE 1 * 1024 * 1024 - -using namespace QGpgME; -using namespace GpgME; - - - -class EncryptionTest : public QGpgMETest -{ - Q_OBJECT - -private Q_SLOTS: - - void testSimpleEncryptDecrypt() - { - auto listjob = openpgp()->keyListJob(false, false, false); - std::vector<Key> keys; - auto keylistresult = listjob->exec(QStringList() << QStringLiteral("[email protected]"), - false, keys); - QVERIFY(!keylistresult.error()); - QVERIFY(keys.size() == 1); - delete listjob; - - auto job = openpgp()->encryptJob(/*ASCII Armor */true, /* Textmode */ true); - QVERIFY(job); - QByteArray cipherText; - auto result = job->exec(keys, QStringLiteral("Hello World").toUtf8(), Context::AlwaysTrust, cipherText); - delete job; - QVERIFY(!result.error()); - const auto cipherString = QString::fromUtf8(cipherText); - QVERIFY(cipherString.startsWith("-----BEGIN PGP MESSAGE-----")); - - /* Now decrypt */ - if (!loopbackSupported()) { - return; - } - auto decJob = openpgp()->decryptJob(); - hookUpPassphraseProvider(decJob); - QByteArray plainText; - auto decResult = decJob->exec(cipherText, plainText); - QVERIFY(!decResult.error()); - QVERIFY(QString::fromUtf8(plainText) == QStringLiteral("Hello World")); - delete decJob; - } - - void testProgress() - { - if (GpgME::engineInfo(GpgME::GpgEngine).engineVersion() < "2.1.15") { - // We can only test the progress with 2.1.15 as this started to - // have total progress for memory callbacks - return; - } - auto listjob = openpgp()->keyListJob(false, false, false); - std::vector<Key> keys; - auto keylistresult = listjob->exec(QStringList() << QStringLiteral("[email protected]"), - false, keys); - QVERIFY(!keylistresult.error()); - QVERIFY(keys.size() == 1); - delete listjob; - - auto job = openpgp()->encryptJob(/*ASCII Armor */false, /* Textmode */ false); - QVERIFY(job); - QByteArray plainBa; - plainBa.fill('X', PROGRESS_TEST_SIZE); - QByteArray cipherText; - - bool initSeen = false; - bool finishSeen = false; - connect(job, &Job::jobProgress, this, [&initSeen, &finishSeen] (int current, int total) { - // We only check for progress 0 and max progress as the other progress - // lines depend on the system speed and are as such unreliable to test. - QVERIFY(total == PROGRESS_TEST_SIZE); - if (current == 0) { - initSeen = true; - } - if (current == total) { - finishSeen = true; - } - QVERIFY(current >= 0 && current <= total); - }); - connect(job, &Job::rawProgress, this, [&initSeen, &finishSeen] (const QString &what, int type, int current, int total) { - // `what` is something like "-&12", i.e. a special fd passed to gpg; we only check that it's not empty - QVERIFY(!what.isEmpty()); - QCOMPARE(type, '?'); - // We only check for progress 0 and max progress as the other progress - // lines depend on the system speed and are as such unreliable to test. - QVERIFY(total == PROGRESS_TEST_SIZE); - if (current == 0) { - initSeen = true; - } - if (current == total) { - finishSeen = true; - } - QVERIFY(current >= 0 && current <= total); - }); - connect(job, &EncryptJob::result, this, [this, &initSeen, &finishSeen] (const GpgME::EncryptionResult &, - const QByteArray &, - const QString, - const GpgME::Error) { - QVERIFY(initSeen); - QVERIFY(finishSeen); - Q_EMIT asyncDone(); - }); - - auto inptr = std::shared_ptr<QIODevice>(new QBuffer(&plainBa)); - inptr->open(QIODevice::ReadOnly); - auto outptr = std::shared_ptr<QIODevice>(new QBuffer(&cipherText)); - outptr->open(QIODevice::WriteOnly); - - job->start(keys, inptr, outptr, Context::AlwaysTrust); - QSignalSpy spy (this, SIGNAL(asyncDone())); - QVERIFY(spy.wait(QSIGNALSPY_TIMEOUT)); - } - - void testSymmetricEncryptDecrypt() - { - if (!loopbackSupported()) { - return; - } - auto job = openpgp()->encryptJob(); - hookUpPassphraseProvider(job); - auto ctx = Job::context(job); - ctx->setArmor(true); - ctx->setTextMode(true); - QByteArray cipherText; - auto result = job->exec(std::vector<Key>(), QStringLiteral("Hello symmetric World").toUtf8(), Context::AlwaysTrust, cipherText); - delete job; - QVERIFY(!result.error()); - const auto cipherString = QString::fromUtf8(cipherText); - QVERIFY(cipherString.startsWith("-----BEGIN PGP MESSAGE-----")); - - killAgent(mDir.path()); - - auto decJob = openpgp()->decryptJob(); - hookUpPassphraseProvider(decJob); - QByteArray plainText; - auto decResult = decJob->exec(cipherText, plainText); - QVERIFY(!result.error()); - QVERIFY(QString::fromUtf8(plainText) == QStringLiteral("Hello symmetric World")); - delete decJob; - } - - void testEncryptDecryptNowrap() - { - /* Now decrypt */ - if (!loopbackSupported()) { - return; - } - auto listjob = openpgp()->keyListJob(false, false, false); - std::vector<Key> keys; - auto keylistresult = listjob->exec(QStringList() << QStringLiteral("[email protected]"), - false, keys); - QVERIFY(!keylistresult.error()); - QVERIFY(keys.size() == 1); - delete listjob; - - auto job = openpgp()->signEncryptJob(/*ASCII Armor */true, /* Textmode */ true); - QVERIFY(job); - hookUpPassphraseProvider(job); - - QByteArray cipherText; - auto result = job->exec(keys, keys, QStringLiteral("Hello World").toUtf8(), Context::AlwaysTrust, cipherText); - delete job; - QVERIFY(!result.first.error()); - QVERIFY(!result.second.error()); - const auto cipherString = QString::fromUtf8(cipherText); - QVERIFY(cipherString.startsWith("-----BEGIN PGP MESSAGE-----")); - - /* Now decrypt */ - if (!loopbackSupported()) { - return; - } - - auto decJob = openpgp()->decryptJob(); - hookUpPassphraseProvider(decJob); - auto ctx = Job::context(decJob); - ctx->setDecryptionFlags(Context::DecryptUnwrap); - - QByteArray plainText; - auto decResult = decJob->exec(cipherText, plainText); - - QVERIFY(!decResult.error()); - - delete decJob; - - // Now verify the unwrapeped data. - auto verifyJob = openpgp()->verifyOpaqueJob(true); - QByteArray verified; - - auto verResult = verifyJob->exec(plainText, verified); - QVERIFY(!verResult.error()); - delete verifyJob; - - QVERIFY(verResult.numSignatures() == 1); - auto sig = verResult.signatures()[0]; - - QVERIFY(verified == QStringLiteral("Hello World")); - } - -private: - /* Loopback and passphrase provider don't work for mixed encryption. - * So this test is disabled until gnupg(?) is fixed for this. */ - void testMixedEncryptDecrypt() - { - if (!loopbackSupported()) { - return; - } - auto listjob = openpgp()->keyListJob(false, false, false); - std::vector<Key> keys; - auto keylistresult = listjob->exec(QStringList() << QStringLiteral("[email protected]"), - false, keys); - QVERIFY(!keylistresult.error()); - QVERIFY(keys.size() == 1); - delete listjob; - - auto job = openpgp()->encryptJob(); - hookUpPassphraseProvider(job); - auto ctx = Job::context(job); - ctx->setArmor(true); - ctx->setTextMode(true); - QByteArray cipherText; - printf("Before exec, flags: %x\n", Context::Symmetric | Context::AlwaysTrust); - auto result = job->exec(keys, QStringLiteral("Hello symmetric World").toUtf8(), - static_cast<Context::EncryptionFlags>(Context::Symmetric | Context::AlwaysTrust), - cipherText); - printf("After exec\n"); - delete job; - QVERIFY(!result.error()); - printf("Cipher:\n%s\n", cipherText.constData()); - const auto cipherString = QString::fromUtf8(cipherText); - QVERIFY(cipherString.startsWith("-----BEGIN PGP MESSAGE-----")); - - killAgent(mDir.path()); - - /* Now create a new homedir which with we test symmetric decrypt. */ - QTemporaryDir tmp; - qputenv("GNUPGHOME", tmp.path().toUtf8()); - QFile agentConf(tmp.path() + QStringLiteral("/gpg-agent.conf")); - QVERIFY(agentConf.open(QIODevice::WriteOnly)); - agentConf.write("allow-loopback-pinentry"); - agentConf.close(); - - auto decJob = openpgp()->decryptJob(); - hookUpPassphraseProvider(decJob); - auto ctx2 = Job::context(decJob); - ctx2->setTextMode(true); - QByteArray plainText; - auto decResult = decJob->exec(cipherText, plainText); - QVERIFY(!decResult.error()); - qDebug() << "Plain: " << plainText; - QVERIFY(QString::fromUtf8(plainText) == QStringLiteral("Hello symmetric World")); - delete decJob; - - killAgent(tmp.path()); - qputenv("GNUPGHOME", mDir.path().toUtf8()); - } - -public Q_SLOT: - - void initTestCase() - { - QGpgMETest::initTestCase(); - const QString gpgHome = qgetenv("GNUPGHOME"); - qputenv("GNUPGHOME", mDir.path().toUtf8()); - QVERIFY(mDir.isValid()); - QFile agentConf(mDir.path() + QStringLiteral("/gpg-agent.conf")); - QVERIFY(agentConf.open(QIODevice::WriteOnly)); - agentConf.write("allow-loopback-pinentry"); - agentConf.close(); - QVERIFY(copyKeyrings(gpgHome, mDir.path())); - } - -private: - QTemporaryDir mDir; -}; - -QTEST_MAIN(EncryptionTest) - -#include "t-encrypt.moc" diff --git a/lang/qt/tests/t-import.cpp b/lang/qt/tests/t-import.cpp deleted file mode 100644 index be17a03c..00000000 --- a/lang/qt/tests/t-import.cpp +++ /dev/null @@ -1,250 +0,0 @@ -/* t-import.cpp - - This file is part of qgpgme, the Qt API binding for gpgme - Copyright (c) 2021 g10 Code GmbH - Software engineering by Ingo Klöcker <[email protected]> - - QGpgME is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - QGpgME is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - - In addition, as a special exception, the copyright holders give - permission to link the code of this program with any edition of - the Qt library by Trolltech AS, Norway (or with modified versions - of Qt that use the same license as Qt), and distribute linked - combinations including the two. You must obey the GNU General - Public License in all respects for all of the code used other than - Qt. If you modify this file, you may extend this exception to - your version of the file, but you are not obligated to do so. If - you do not wish to do so, delete this exception statement from - your version. -*/ - -#ifdef HAVE_CONFIG_H - #include "config.h" -#endif - -#include "t-support.h" - -#include <gpgme++/context.h> -#include <gpgme++/engineinfo.h> -#include "protocol.h" -#include "importjob.h" - -#include <gpgme++/importresult.h> - -#include <QDebug> -#include <QSignalSpy> -#include <QTemporaryDir> -#include <QTest> - -#include <memory> - -using namespace QGpgME; -using namespace GpgME; - -class ImportTest : public QGpgMETest -{ - Q_OBJECT - -private: - QTemporaryDir tempGpgHome; - -private Q_SLOTS: - void initTestCase() - { - QGpgMETest::initTestCase(); - QVERIFY2(tempGpgHome.isValid(), "Failed to create temporary GNUPGHOME"); - qputenv("GNUPGHOME", tempGpgHome.path().toLocal8Bit()); - } - - void testImportWithImportFilter() - { - if (GpgME::engineInfo(GpgME::GpgEngine).engineVersion() < "2.1.14") { - QSKIP("gpg does not yet support the --import-filter option"); - } - - // pub ed25519 2021-12-15 [SC] - // E7A0841292ACC9465D3142652FB3A6F51FBF28A2 - // uid [ultimate] [email protected] - // uid [ultimate] [email protected] - // sub cv25519 2021-12-15 [E] - static const char keyFpr[] = "E7A0841292ACC9465D3142652FB3A6F51FBF28A2"; - static const char keyData[] = - "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" - "\n" - "mDMEYbm2PhYJKwYBBAHaRw8BAQdACzxBWtNNsmJ6rzpZkjh1yBe+Ajsk9NR8umEu\n" - "Da3HLgG0ImltcG9ydFdpdGhJbXBvcnRGaWx0ZXJAZXhhbXBsZS5uZXSIlAQTFgoA\n" - "PBYhBOeghBKSrMlGXTFCZS+zpvUfvyiiBQJhubY+AhsDBQsJCAcCAyICAQYVCgkI\n" - "CwIEFgIDAQIeBwIXgAAKCRAvs6b1H78oosRgAQCc/ke6q076nvzIE2UzT83JK/B6\n" - "lxSV7Fb8bKltOMpvsAD+Phap3EzA8jdMyKoO0FM926bw5lX7QROfeZ/JBYqyPwC0\n" - "ImltcG9ydFdpdGhJbXBvcnRGaWx0ZXJAZXhhbXBsZS5jb22IlAQTFgoAPBYhBOeg\n" - "hBKSrMlGXTFCZS+zpvUfvyiiBQJhubZlAhsDBQsJCAcCAyICAQYVCgkICwIEFgID\n" - "AQIeBwIXgAAKCRAvs6b1H78oohPWAQC/u9UXzkxRkrB2huaTZCsyimWEGZIMmxWd\n" - "tE+vN9/IvQD/Yzia+xRS6yca3Yz6iW8xS844ZqRxvkUEHjtJXSOzagm4OARhubY+\n" - "EgorBgEEAZdVAQUBAQdANQFjmDctY3N0/ELPZtj9tapwFs4vrmTVpx/SCfZmihkD\n" - "AQgHiHgEGBYKACAWIQTnoIQSkqzJRl0xQmUvs6b1H78oogUCYbm2PgIbDAAKCRAv\n" - "s6b1H78oovGyAP41ySzvvDpV7XDJBOAFxvWLmywa5IcO7Lrg7y1efoWj0AD+Kk/B\n" - "s7jGLdoG51h670h50MMoYCANB6MwAdSP+qZUlQg=\n" - "=/3O0\n" - "-----END PGP PUBLIC KEY BLOCK-----\n"; - - auto *job = openpgp()->importJob(); - job->setImportFilter(QLatin1String{"keep-uid=mbox = [email protected]"}); - connect(job, &ImportJob::result, this, - [this](ImportResult result, QString, Error) - { - QVERIFY(!result.error()); - QVERIFY(!result.imports().empty()); - QVERIFY(result.numImported()); - Q_EMIT asyncDone(); - }); - job->start(QByteArray{keyData}); - QSignalSpy spy (this, SIGNAL(asyncDone())); - QVERIFY(spy.wait()); - - auto ctx = std::unique_ptr<GpgME::Context>(Context::createForProtocol(GpgME::OpenPGP)); - GpgME::Error err; - const auto key = ctx->key(keyFpr, err, false); - QVERIFY(!key.isNull()); - QCOMPARE(key.numUserIDs(), 1u); - QCOMPARE(key.userID(0).id(), "[email protected]"); - } - - void testImportWithImportOptions() - { - if (GpgME::engineInfo(GpgME::GpgEngine).engineVersion() < "2.1.23") { - QSKIP("gpg does not yet support --import-options show-only"); - } - - // pub ed25519 2024-06-12 [SC] - // A52F4947AF1506F3A7572EFC140278B773CA7C16 - // uid [email protected] - static const char keyFpr[] = "A52F4947AF1506F3A7572EFC140278B773CA7C16"; - static const char keyData[] = - "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" - "\n" - "mDMEZmlpmBYJKwYBBAHaRw8BAQdAZaSopKwccTwnMlJBVCWMT6et1T1WF9EkXdJi\n" - "gzI74xW0GWltcG9ydE9wdGlvbnNAZXhhbXBsZS5uZXSIkwQTFgoAOxYhBKUvSUev\n" - "FQbzp1cu/BQCeLdzynwWBQJmaWmYAhsDBQsJCAcCAiICBhUKCQgLAgQWAgMBAh4H\n" - "AheAAAoJEBQCeLdzynwWjmQBAP4dQEN/M4/dKIAlxNAbWzIkV+eSoUFLJszOJ/xx\n" - "FwJzAP43gkdXkUsHZt/U3mLZqtiHJFd7JxVm7hKRoAVBhZZYDw==\n" - "=7Z1j\n" - "-----END PGP PUBLIC KEY BLOCK-----\n"; - - auto *job = openpgp()->importJob(); - job->setImportOptions({QStringLiteral("show-only")}); - connect(job, &ImportJob::result, this, - [this](ImportResult result, QString, Error) - { - QVERIFY(!result.error()); - QCOMPARE(result.numConsidered(), 0); - QCOMPARE(result.numImported(), 0); - QVERIFY(result.imports().empty()); - Q_EMIT asyncDone(); - }); - job->start(QByteArray{keyData}); - QSignalSpy spy (this, SIGNAL(asyncDone())); - QVERIFY(spy.wait()); - - auto ctx = std::unique_ptr<GpgME::Context>(Context::createForProtocol(GpgME::OpenPGP)); - GpgME::Error err; - const auto key = ctx->key(keyFpr, err, false); - QVERIFY(key.isNull()); - } - - void testImportWithKeyOrigin() - { - if (GpgME::engineInfo(GpgME::GpgEngine).engineVersion() < "2.1.22") { - QSKIP("gpg does not yet support the --key-origin option"); - } - - static const char keyFpr[] = "5C5C428FABCC20F6913464BCCA6FB442887289B3"; - static const char keyData[] = - "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" - "\n" - "mDMEYbhuixYJKwYBBAHaRw8BAQdAulOM3IksCjdOJluEVlwalD8oZ5oa6wCw3EgW\n" - "NswXXb60H2ltcG9ydFdpdGhLZXlPcmlnaW5AZXhhbXBsZS5uZXSIlAQTFgoAPBYh\n" - "BFxcQo+rzCD2kTRkvMpvtEKIcomzBQJhuG6LAhsDBQsJCAcCAyICAQYVCgkICwIE\n" - "FgIDAQIeBwIXgAAKCRDKb7RCiHKJs+cIAQDaeoOw1OCAGpZQb8xJmLJHul5dLLzU\n" - "RBdHauMx9NROmQEA23QUVedc7walQjNKFzyIJA/YqRdbAKPiLonRBmxk9Ay4OARh\n" - "uG6LEgorBgEEAZdVAQUBAQdAMVdO9mNWIP/q8PtNOnBGlPyhx/vs07sF5sXk50A+\n" - "61QDAQgHiHgEGBYKACAWIQRcXEKPq8wg9pE0ZLzKb7RCiHKJswUCYbhuiwIbDAAK\n" - "CRDKb7RCiHKJs/x6AP0SEbZqW4iLCz2i1JntQghK5qpSZOVqsBTcARd6pcJ/cwEA\n" - "mrwskWazuS9+GVbHT5RATWOXnGaj+AICSDPE6qHtGgA=\n" - "=putz\n" - "-----END PGP PUBLIC KEY BLOCK-----\n"; - - auto *job = openpgp()->importJob(); - job->setKeyOrigin(GpgME::Key::OriginWKD, "https://example.net"); - connect(job, &ImportJob::result, this, - [this](ImportResult result, QString, Error) - { - QVERIFY(!result.error()); - QVERIFY(!result.imports().empty()); - QVERIFY(result.numImported()); - Q_EMIT asyncDone(); - }); - job->start(QByteArray{keyData}); - QSignalSpy spy (this, SIGNAL(asyncDone())); - QVERIFY(spy.wait()); - - auto ctx = std::unique_ptr<GpgME::Context>(Context::createForProtocol(GpgME::OpenPGP)); - GpgME::Error err; - const auto key = ctx->key(keyFpr, err, false); - QVERIFY(!key.isNull()); - QVERIFY(key.origin() == Key::OriginWKD); - // the origin URL is currently not available in GpgME - } - - void testDeferredStart() - { - // pub ed25519 2023-01-05 [SC] - // 4D1367FE9AF6334D8A55BA635A817A94C7B37E5D - // uid [email protected] - static const char keyFpr[] = "4D1367FE9AF6334D8A55BA635A817A94C7B37E5D"; - static const char keyData[] = - "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" - "\n" - "mDMEY7bNSxYJKwYBBAHaRw8BAQdAazIWyd/xEMeObDSUnh2+AXQuo0oM+TDBG49z\n" - "KHvTAYG0GmltcG9ydERlZmVycmVkQGV4YW1wbGUubmV0iJMEExYKADsWIQRNE2f+\n" - "mvYzTYpVumNagXqUx7N+XQUCY7bNSwIbAwULCQgHAgIiAgYVCgkICwIEFgIDAQIe\n" - "BwIXgAAKCRBagXqUx7N+XasrAP4qPzLzPd6tWDZvP29ZYPTSrjrTb0U5MOJeIPKX\n" - "73jZswEAwWRvgH+GmhTOigw0UVtinAFvUEFVyvcW/GR19mw5XA0=\n" - "=JnpA\n" - "-----END PGP PUBLIC KEY BLOCK-----\n"; - - auto *job = openpgp()->importJob(); - job->startLater(QByteArray{keyData}); - connect(job, &ImportJob::result, this, - [this](ImportResult result, QString, Error) - { - QVERIFY(!result.error()); - QVERIFY(!result.imports().empty()); - QVERIFY(result.numImported()); - Q_EMIT asyncDone(); - }); - job->startNow(); - QSignalSpy spy (this, SIGNAL(asyncDone())); - QVERIFY(spy.wait()); - - auto ctx = std::unique_ptr<GpgME::Context>(Context::createForProtocol(GpgME::OpenPGP)); - GpgME::Error err; - const auto key = ctx->key(keyFpr, err, false); - QVERIFY(!key.isNull()); - } -}; - -QTEST_MAIN(ImportTest) - -#include "t-import.moc" diff --git a/lang/qt/tests/t-keylist.cpp b/lang/qt/tests/t-keylist.cpp deleted file mode 100644 index 75bc4120..00000000 --- a/lang/qt/tests/t-keylist.cpp +++ /dev/null @@ -1,206 +0,0 @@ -/* t-keylist.cpp - - This file is part of qgpgme, the Qt API binding for gpgme - Copyright (c) 2016 by Bundesamt für Sicherheit in der Informationstechnik - Software engineering by Intevation GmbH - - QGpgME is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - QGpgME is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - - In addition, as a special exception, the copyright holders give - permission to link the code of this program with any edition of - the Qt library by Trolltech AS, Norway (or with modified versions - of Qt that use the same license as Qt), and distribute linked - combinations including the two. You must obey the GNU General - Public License in all respects for all of the code used other than - Qt. If you modify this file, you may extend this exception to - your version of the file, but you are not obligated to do so. If - you do not wish to do so, delete this exception statement from - your version. -*/ - -#ifdef HAVE_CONFIG_H - #include "config.h" -#endif - -#include <QDebug> -#include <QTest> -#include <QSignalSpy> -#include <QMap> -#include "keylistjob.h" -#include "listallkeysjob.h" -#include "qgpgmebackend.h" -#include <gpgme++/keylistresult.h> - -#include <gpgme++/context.h> -#include <gpgme++/engineinfo.h> - -#include <memory> - -#include "t-support.h" - -using namespace QGpgME; -using namespace GpgME; - -class KeyListTest : public QGpgMETest -{ - Q_OBJECT - -private Q_SLOTS: - void testSingleKeyListSync() - { - KeyListJob *job = openpgp()->keyListJob(false, false, false); - std::vector<GpgME::Key> keys; - GpgME::KeyListResult result = job->exec(QStringList() << QStringLiteral("[email protected]"), - false, keys); - delete job; - QVERIFY (!result.error()); - QVERIFY (keys.size() == 1); - const QString kId = QLatin1String(keys.front().keyID()); - QVERIFY (kId == QStringLiteral("2D727CC768697734")); - - QVERIFY (keys[0].subkeys().size() == 2); - QVERIFY (keys[0].subkeys()[0].publicKeyAlgorithm() == Subkey::AlgoDSA); - QVERIFY (keys[0].subkeys()[1].publicKeyAlgorithm() == Subkey::AlgoELG_E); - } - - // This test can help with valgrind to check for memleaks when handling - // keys - void testGetKey() - { - GpgME::Key key; - { - auto ctx = std::unique_ptr<GpgME::Context> (GpgME::Context::createForProtocol(GpgME::OpenPGP)); - ctx->setKeyListMode (GpgME::KeyListMode::Local | - GpgME::KeyListMode::Signatures | - GpgME::KeyListMode::Validate | - GpgME::KeyListMode::WithTofu); - GpgME::Error err; - key = ctx->key ("A0FF4590BB6122EDEF6E3C542D727CC768697734", err, false); - } - QVERIFY(key.primaryFingerprint()); - QVERIFY(!strcmp(key.primaryFingerprint(), "A0FF4590BB6122EDEF6E3C542D727CC768697734")); - { - auto ctx = std::unique_ptr<GpgME::Context> (GpgME::Context::createForProtocol(GpgME::OpenPGP)); - ctx->setKeyListMode (GpgME::KeyListMode::Local | - GpgME::KeyListMode::Signatures | - GpgME::KeyListMode::Validate | - GpgME::KeyListMode::WithTofu); - GpgME::Error err; - key = ctx->key ("A0FF4590BB6122EDEF6E3C542D727CC768697734", err, false); - } - QVERIFY(key.primaryFingerprint()); - QVERIFY(!strcmp(key.primaryFingerprint(), "A0FF4590BB6122EDEF6E3C542D727CC768697734")); - } - - void testPubkeyAlgoAsString() - { - static const QMap<Subkey::PubkeyAlgo, QString> expected { - { Subkey::AlgoRSA, QStringLiteral("RSA") }, - { Subkey::AlgoRSA_E, QStringLiteral("RSA-E") }, - { Subkey::AlgoRSA_S, QStringLiteral("RSA-S") }, - { Subkey::AlgoELG_E, QStringLiteral("ELG-E") }, - { Subkey::AlgoDSA, QStringLiteral("DSA") }, - { Subkey::AlgoECC, QStringLiteral("ECC") }, - { Subkey::AlgoELG, QStringLiteral("ELG") }, - { Subkey::AlgoECDSA, QStringLiteral("ECDSA") }, - { Subkey::AlgoECDH, QStringLiteral("ECDH") }, - { Subkey::AlgoEDDSA, QStringLiteral("EdDSA") }, - { Subkey::AlgoUnknown, QString() } - }; - for (Subkey::PubkeyAlgo algo : expected.keys()) { - QVERIFY(QString::fromUtf8(Subkey::publicKeyAlgorithmAsString(algo)) == - expected.value(algo)); - } - } - - void testKeyListAsync() - { - KeyListJob *job = openpgp()->keyListJob(); - connect(job, &KeyListJob::result, job, [this, job](KeyListResult, std::vector<Key> keys, QString, Error) - { - QVERIFY(keys.size() == 1); - Q_EMIT asyncDone(); - }); - job->start(QStringList() << "[email protected]"); - QSignalSpy spy (this, SIGNAL(asyncDone())); - QVERIFY(spy.wait(QSIGNALSPY_TIMEOUT)); - } - - void testListAllKeysSync() - { - const auto accumulateFingerprints = [](std::vector<std::string> &v, const Key &key) { v.push_back(std::string(key.primaryFingerprint())); return v; }; - - ListAllKeysJob *job = openpgp()->listAllKeysJob(/* includeSigs= */false, /* validate= */false); - std::vector<GpgME::Key> pubKeys, secKeys; - GpgME::KeyListResult result = job->exec(pubKeys, secKeys, /* mergeKeys= */false); // mergeKeys is unused for GnuPG >= 2.1 - delete job; - QVERIFY(!result.error()); - - QCOMPARE(secKeys.size(), static_cast<decltype(secKeys.size())>(2)); - std::vector<std::string> secKeyFingerprints = std::accumulate(secKeys.begin(), secKeys.end(), std::vector<std::string>(), accumulateFingerprints); - QCOMPARE(secKeyFingerprints, std::vector<std::string>({ - "23FD347A419429BACCD5E72D6BC4778054ACD246", - "A0FF4590BB6122EDEF6E3C542D727CC768697734" - })); - QVERIFY(secKeys[0].hasSecret()); - if (!(GpgME::engineInfo(GpgME::GpgEngine).engineVersion() < "2.1.0")) { - QVERIFY(secKeys[0].subkeys()[0].keyGrip()); - } - - QCOMPARE(pubKeys.size(), static_cast<decltype(pubKeys.size())>(26)); - std::vector<std::string> pubKeyFingerprints = std::accumulate(pubKeys.begin(), pubKeys.end(), std::vector<std::string>(), accumulateFingerprints); - QCOMPARE(pubKeyFingerprints, std::vector<std::string>({ - "045B2334ADD69FC221076841A5E67F7FA3AE3EA1", - "04C1DF62EFA0EBB00519B06A8979A6C5567FB34A", - "0DBCAD3F08843B9557C6C4D4A94C0F75653244D6", - "1DDD28CEF714F5B03B8C246937CAB51FB79103F8", - "23FD347A419429BACCD5E72D6BC4778054ACD246", - "2686AA191A278013992C72EBBE794852BE5CF886", - "3531152DE293E26A07F504BC318C1FAEFAEF6D1B", - "38FBE1E4BF6A5E1242C8F6A13BDBEDB1777FBED3", - "3FD11083779196C2ECDD9594AD1B0FAD43C2D0C7", - "43929E89F8F79381678CAE515F6356BA6D9732AC", - "56D33268F7FE693FBB594762D4BF57F37372E243", - "5AB9D6D7BAA1C95B3BAA3D9425B00FD430CEC684", - "61EE841A2A27EB983B3B3C26413F4AF31AFDAB6C", - "6560C59C43D031C54D7C588EEBA9F240EB9DC9E6", - "6FAA9C201E5E26DCBAEC39FD5D15E01D3FF13206", - "9E91CBB11E4D4135583EF90513DB965534C6E3F1", - "A0FF4590BB6122EDEF6E3C542D727CC768697734", - "A7969DA1C3297AA96D49843F1C67EC133C661C84", - "C9C07DCC6621B9FB8D071B1D168410A48FC282E6", - "CD538D6CC9FB3D745ECDA5201FE8FC6F04259677", - "D695676BDCEDCC2CDD6152BCFE180B1DA9E3B0B2", - "E8143C489C8D41124DC40D0B47AF4B6961F04784", - "E8D6C90B683B0982BD557A99DEF0F7B8EC67DBDE", - "ECAC774F4EEEB0620767044A58CB9A4C85A81F38", - "ED9B316F78644A58D042655A9EEF34CD4B11B25F", - "F8F1EDC73995AB739AD54B380C820C71D2699313" - })); - if (!(GpgME::engineInfo(GpgME::GpgEngine).engineVersion() < "2.1.0")) { - // with GnuPG >= 2.1 the job always lists keys with --with-keygrip and --with-secret, - // i.e. the key grips and information about secret keys are always available - QVERIFY(!pubKeys[0].hasSecret()); - QVERIFY(pubKeys[0].subkeys()[0].keyGrip()); - - QVERIFY(pubKeys[4].hasSecret()); - QVERIFY(pubKeys[4].subkeys()[0].keyGrip()); - } - } -}; - -QTEST_MAIN(KeyListTest) - -#include "t-keylist.moc" diff --git a/lang/qt/tests/t-keylocate.cpp b/lang/qt/tests/t-keylocate.cpp deleted file mode 100644 index 88062f50..00000000 --- a/lang/qt/tests/t-keylocate.cpp +++ /dev/null @@ -1,132 +0,0 @@ -/* t-keylocate.cpp - - This file is part of qgpgme, the Qt API binding for gpgme - Copyright (c) 2016 by Bundesamt für Sicherheit in der Informationstechnik - Software engineering by Intevation GmbH - - QGpgME is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - QGpgME is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - - In addition, as a special exception, the copyright holders give - permission to link the code of this program with any edition of - the Qt library by Trolltech AS, Norway (or with modified versions - of Qt that use the same license as Qt), and distribute linked - combinations including the two. You must obey the GNU General - Public License in all respects for all of the code used other than - Qt. If you modify this file, you may extend this exception to - your version of the file, but you are not obligated to do so. If - you do not wish to do so, delete this exception statement from - your version. -*/ -#ifdef HAVE_CONFIG_H - #include "config.h" -#endif - -#include <QDebug> -#include <QTest> -#include <QSignalSpy> -#include <QTemporaryDir> -#include "keylistjob.h" -#include "protocol.h" -#include <gpgme++/keylistresult.h> -#include <gpgme++/engineinfo.h> - -#include "t-support.h" - -using namespace QGpgME; -using namespace GpgME; - -class KeyLocateTest : public QGpgMETest -{ - Q_OBJECT - -private Q_SLOTS: - -#ifdef DO_ONLINE_TESTS - void testDaneKeyLocate() - { - QTemporaryDir dir; - const QString oldHome = qgetenv("GNUPGHOME"); - qputenv("GNUPGHOME", dir.path().toUtf8()); - /* Could do this with gpgconf but this is not a gpgconf test ;-) */ - QFile conf(dir.path() + QStringLiteral("/gpg.conf")); - QVERIFY(conf.open(QIODevice::WriteOnly)); - conf.write("auto-key-locate dane"); - conf.close(); - - auto *job = openpgp()->locateKeysJob(); - mTestpattern = QStringLiteral("[email protected]"); - connect(job, &KeyListJob::result, job, [this, job](KeyListResult result, std::vector<Key> keys, QString, Error) - { - QVERIFY(!result.error()); - QVERIFY(keys.size() == 1); - - Key k = keys.front(); - QVERIFY(k.numUserIDs()); - bool found = false; - for (const UserID &uid : k.userIDs()) { - const QString mailBox = QString::fromUtf8(uid.email()); - if (mTestpattern.toLower() == mailBox.toLower()) { - found = true; - } - } - QVERIFY(found); - Q_EMIT asyncDone(); - }); - job->start(QStringList() << mTestpattern); - QSignalSpy spy (this, SIGNAL(asyncDone())); - QVERIFY(spy.wait(QSIGNALSPY_TIMEOUT)); - qputenv("GNUPGHOME", oldHome.toUtf8()); - } -#endif - - void testKeyLocateSingle() - { - if (GpgME::engineInfo(GpgME::GpgEngine).engineVersion() < "2.0.10") { - return; - } - auto *job = openpgp()->locateKeysJob(); - mTestpattern = QStringLiteral("[email protected]"); - - connect(job, &KeyListJob::result, job, [this, job](KeyListResult result, std::vector<Key> keys, QString, Error) - { - QVERIFY(!result.isNull()); - QVERIFY(!result.isTruncated()); - QVERIFY(!result.error()); - QVERIFY(keys.size() == 1); - - Key k = keys.front(); - QVERIFY(k.numUserIDs()); - bool found = false; - for (const UserID &uid : k.userIDs()) { - const QString mailBox = QString::fromUtf8(uid.email()); - if (mTestpattern.toLower() == mailBox.toLower()) { - found = true; - } - } - QVERIFY(found); - Q_EMIT asyncDone(); - }); - job->start(QStringList() << mTestpattern); - QSignalSpy spy (this, SIGNAL(asyncDone())); - QVERIFY(spy.wait(QSIGNALSPY_TIMEOUT)); - } - -private: - QString mTestpattern; -}; - -QTEST_MAIN(KeyLocateTest) - -#include "t-keylocate.moc" diff --git a/lang/qt/tests/t-ownertrust.cpp b/lang/qt/tests/t-ownertrust.cpp deleted file mode 100644 index a032dfbd..00000000 --- a/lang/qt/tests/t-ownertrust.cpp +++ /dev/null @@ -1,113 +0,0 @@ -/* t-ownertrust.cpp - - This file is part of qgpgme, the Qt API binding for gpgme - Copyright (c) 2016 by Bundesamt für Sicherheit in der Informationstechnik - Software engineering by Intevation GmbH - - QGpgME is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - QGpgME is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - - In addition, as a special exception, the copyright holders give - permission to link the code of this program with any edition of - the Qt library by Trolltech AS, Norway (or with modified versions - of Qt that use the same license as Qt), and distribute linked - combinations including the two. You must obey the GNU General - Public License in all respects for all of the code used other than - Qt. If you modify this file, you may extend this exception to - your version of the file, but you are not obligated to do so. If - you do not wish to do so, delete this exception statement from - your version. -*/ - -#ifdef HAVE_CONFIG_H - #include "config.h" -#endif - -#include <QDebug> -#include <QTest> -#include <QSignalSpy> -#include "debug.h" -#include "keylistjob.h" -#include "protocol.h" -#include <gpgme++/keylistresult.h> -#include "changeownertrustjob.h" - -#include "t-support.h" - -using namespace QGpgME; -using namespace GpgME; - -class ChangeOwnerTrustTest: public QGpgMETest -{ - Q_OBJECT - -private Q_SLOTS: - - void testChangeOwnerTrust() - { - KeyListJob *job = openpgp()->keyListJob(false, true, true); - std::vector<GpgME::Key> keys; - GpgME::KeyListResult result = job->exec(QStringList() << QStringLiteral("[email protected]"), - false, keys); - delete job; - QVERIFY (!result.error()); - QVERIFY (keys.size() == 1); - Key key = keys.front(); - QVERIFY (key.ownerTrust() == Key::Unknown); - - ChangeOwnerTrustJob *job2 = openpgp()->changeOwnerTrustJob(); - connect(job2, &ChangeOwnerTrustJob::result, this, [this](Error e) - { - if (e) { - qDebug() << "Error in result: " << e; - } - QVERIFY(!e); - Q_EMIT asyncDone(); - }); - job2->start(key, Key::Ultimate); - QSignalSpy spy (this, SIGNAL(asyncDone())); - QVERIFY(spy.wait(QSIGNALSPY_TIMEOUT)); - - job = openpgp()->keyListJob(false, true, true); - result = job->exec(QStringList() << QStringLiteral("[email protected]"), - false, keys); - delete job; - key = keys.front(); - QVERIFY (key.ownerTrust() == Key::Ultimate); - - ChangeOwnerTrustJob *job3 = openpgp()->changeOwnerTrustJob(); - connect(job3, &ChangeOwnerTrustJob::result, this, [this](Error e) - { - if (e) { - qDebug() << "Error in result: " << e; - } - QVERIFY(!e); - Q_EMIT asyncDone(); - }); - job3->start(key, Key::Unknown); - QVERIFY(spy.wait(QSIGNALSPY_TIMEOUT)); - - job = openpgp()->keyListJob(false, true, true); - result = job->exec(QStringList() << QStringLiteral("[email protected]"), - false, keys); - delete job; - - key = keys.front(); - QVERIFY (key.ownerTrust() == Key::Unknown); - } -}; - -QTEST_MAIN(ChangeOwnerTrustTest) - -#include "t-ownertrust.moc" diff --git a/lang/qt/tests/t-remarks.cpp b/lang/qt/tests/t-remarks.cpp deleted file mode 100644 index b7de4ac4..00000000 --- a/lang/qt/tests/t-remarks.cpp +++ /dev/null @@ -1,472 +0,0 @@ -/* t-remarks.cpp - - This file is part of qgpgme, the Qt API binding for gpgme - Copyright (c) 2017 by Bundesamt für Sicherheit in der Informationstechnik - Software engineering by Intevation GmbH - - QGpgME is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - QGpgME is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - - In addition, as a special exception, the copyright holders give - permission to link the code of this program with any edition of - the Qt library by Trolltech AS, Norway (or with modified versions - of Qt that use the same license as Qt), and distribute linked - combinations including the two. You must obey the GNU General - Public License in all respects for all of the code used other than - Qt. If you modify this file, you may extend this exception to - your version of the file, but you are not obligated to do so. If - you do not wish to do so, delete this exception statement from - your version. -*/ - - -#ifdef HAVE_CONFIG_H - #include "config.h" -#endif - -#include <QDebug> -#include <QTest> -#include <QSignalSpy> -#include <QTemporaryDir> -#include "debug.h" -#include "keylistjob.h" -#include "protocol.h" -#include "signkeyjob.h" -#include <gpgme++/context.h> -#include <gpgme++/engineinfo.h> - -#include "t-support.h" - -using namespace QGpgME; -using namespace GpgME; - -class TestRemarks: public QGpgMETest -{ - Q_OBJECT - -public: - // This test is disabled (no slot) because the behavior - // is not clearly defined. Better to prevent that - // case in the UI - void testRemarkOwnKey() - { - if (!loopbackSupported()) { - return; - } - // Get the signing key (alfa) - auto ctx = Context::create(OpenPGP); - QVERIFY (ctx); - Error err; - auto seckey = ctx->key("A0FF4590BB6122EDEF6E3C542D727CC768697734", err, true); - QVERIFY (!seckey.isNull()); - QVERIFY (!err); - - // Create the job - auto job = openpgp()->signKeyJob(); - QVERIFY (job); - hookUpPassphraseProvider(job); - - // Set up the job - job->setExportable(false); - std::vector<unsigned int> uids; - uids.push_back(0); - job->setUserIDsToSign(uids); - job->setSigningKey(seckey); - job->setRemark(QStringLiteral("Just GNU it!")); - job->setDupeOk(true); - - connect(job, &SignKeyJob::result, this, [this] (const GpgME::Error &err2, - const QString, - const GpgME::Error) { - Q_EMIT asyncDone(); - if (err2) { - qDebug() << "Error: " << err2; - } - QVERIFY(err2); - }); - - job->start(seckey); - QSignalSpy spy (this, SIGNAL(asyncDone())); - QVERIFY(spy.wait(QSIGNALSPY_TIMEOUT)); - } - - -private Q_SLOTS: - - void testRemarkReplaceSingleUIDExportable() - { - if (!loopbackSupported()) { - return; - } - // Get the signing key (alfa) - auto ctx = Context::create(OpenPGP); - QVERIFY (ctx); - Error err; - auto seckey = ctx->key("A0FF4590BB6122EDEF6E3C542D727CC768697734", err, true); - QVERIFY (!seckey.isNull()); - QVERIFY (!err); - - // Get the target key (tango) - auto target = ctx->key("ECAC774F4EEEB0620767044A58CB9A4C85A81F38", err, false); - QVERIFY (!target.isNull()); - QVERIFY (!err); - QVERIFY (target.numUserIDs()); - - // Create the job - auto job = openpgp()->signKeyJob(); - QVERIFY (job); - hookUpPassphraseProvider(job); - - // Set up the job - job->setExportable(true); - std::vector<unsigned int> uids; - uids.push_back(0); - job->setUserIDsToSign(uids); - job->setSigningKey(seckey); - job->setRemark(QStringLiteral("The quick brown fox jumps over the lazy dog")); - - connect(job, &SignKeyJob::result, this, [this] (const GpgME::Error &err2, - const QString, - const GpgME::Error) { - Q_EMIT asyncDone(); - QVERIFY(!err2); - }); - - job->start(target); - QSignalSpy spy (this, SIGNAL(asyncDone())); - QVERIFY(spy.wait(QSIGNALSPY_TIMEOUT)); - - // At this point the remark should have been added. - target.update(); - const char *remark = target.userID(0).remark(seckey, err); - QVERIFY(!err); - QVERIFY(remark); - QCOMPARE(QString::fromUtf8(remark), QStringLiteral("The quick brown fox " - "jumps over the lazy dog")); - - // Now replace the remark - auto job3 = openpgp()->signKeyJob(); - QVERIFY (job3); - hookUpPassphraseProvider(job3); - - // Set up the job - job3->setExportable(false); - job3->setUserIDsToSign(uids); - job3->setSigningKey(seckey); - job3->setDupeOk(true); - job3->setRemark(QStringLiteral("The quick brown fox fails to jump over Frodo")); - - connect(job3, &SignKeyJob::result, this, [this] (const GpgME::Error &err2, - const QString, - const GpgME::Error) { - Q_EMIT asyncDone(); - QVERIFY(!err2); - }); - - job3->start(target); - QVERIFY(spy.wait(QSIGNALSPY_TIMEOUT)); - - target.update(); - remark = target.userID(0).remark(seckey, err); - QVERIFY(!err); - QVERIFY(remark); - QCOMPARE(QString::fromUtf8(remark), QStringLiteral("The quick brown fox fails " - "to jump over Frodo")); - } - - - void testMultipleRemarks() - { - if (!loopbackSupported()) { - return; - } - // Get the signing key1 (alfa) - auto ctx = Context::create(OpenPGP); - QVERIFY (ctx); - Error err; - auto alpha = ctx->key("A0FF4590BB6122EDEF6E3C542D727CC768697734", err, true); - QVERIFY (!alpha.isNull()); - QVERIFY (!err); - - // Get the signing key2 (zulu) - auto zulu = ctx->key("23FD347A419429BACCD5E72D6BC4778054ACD246", err, true); - QVERIFY (!zulu.isNull()); - QVERIFY (!err); - - // Get the target key (victor) - auto target = ctx->key("E8143C489C8D41124DC40D0B47AF4B6961F04784", err, false); - QVERIFY (!target.isNull()); - QVERIFY (!err); - QVERIFY (target.numUserIDs()); - - // Create the job - auto job = openpgp()->signKeyJob(); - QVERIFY (job); - hookUpPassphraseProvider(job); - - // Setup the first job - job->setExportable(false); - std::vector<unsigned int> uids; - uids.push_back(0); - job->setUserIDsToSign(uids); - job->setSigningKey(alpha); - job->setRemark(QStringLiteral("String one")); - - connect(job, &SignKeyJob::result, this, [this] (const GpgME::Error &err2, - const QString, - const GpgME::Error) { - Q_EMIT asyncDone(); - QVERIFY(!err2); - }); - job->start(target); - QSignalSpy spy (this, SIGNAL(asyncDone())); - QVERIFY(spy.wait(QSIGNALSPY_TIMEOUT)); - - // Now another remark from zulu - auto job3 = openpgp()->signKeyJob(); - QVERIFY (job3); - hookUpPassphraseProvider(job3); - - // Set up the job - job3->setExportable(false); - job3->setUserIDsToSign(uids); - job3->setSigningKey(zulu); - job3->setDupeOk(true); - job3->setRemark(QStringLiteral("String two")); - - connect(job3, &SignKeyJob::result, this, [this] (const GpgME::Error &err2, - const QString, - const GpgME::Error) { - Q_EMIT asyncDone(); - QVERIFY(!err2); - }); - - job3->start(target); - QVERIFY(spy.wait(QSIGNALSPY_TIMEOUT)); - - target.update(); - std::vector<GpgME::Key> keys; - keys.push_back(alpha); - keys.push_back(zulu); - - const auto remarks = target.userID(0).remarks(keys, err); - - QVERIFY(!err); - QVERIFY(remarks.size() == 2); - QCOMPARE(remarks[0], std::string("String one")); - QCOMPARE(remarks[1], std::string("String two")); - } - - void testRemarkReplaceSingleUID() - { - if (!loopbackSupported()) { - return; - } - // Get the signing key (alfa) - auto ctx = Context::create(OpenPGP); - QVERIFY (ctx); - Error err; - auto seckey = ctx->key("A0FF4590BB6122EDEF6E3C542D727CC768697734", err, true); - QVERIFY (!seckey.isNull()); - QVERIFY (!err); - - // Get the target key (xray) - auto target = ctx->key("04C1DF62EFA0EBB00519B06A8979A6C5567FB34A", err, false); - QVERIFY (!target.isNull()); - QVERIFY (!err); - QVERIFY (target.numUserIDs()); - - // Create the job - auto job = openpgp()->signKeyJob(); - QVERIFY (job); - hookUpPassphraseProvider(job); - - // Set up the job - job->setExportable(false); - std::vector<unsigned int> uids; - uids.push_back(0); - job->setUserIDsToSign(uids); - job->setSigningKey(seckey); - job->setRemark(QStringLiteral("The quick brown fox jumps over the lazy dog")); - - connect(job, &SignKeyJob::result, this, [this] (const GpgME::Error &err2, - const QString, - const GpgME::Error) { - Q_EMIT asyncDone(); - QVERIFY(!err2); - }); - - job->start(target); - QSignalSpy spy (this, SIGNAL(asyncDone())); - QVERIFY(spy.wait(QSIGNALSPY_TIMEOUT)); - - // At this point the remark should have been added. - target.update(); - const char *remark = target.userID(0).remark(seckey, err); - QVERIFY(!err); - QVERIFY(remark); - QCOMPARE(QString::fromUtf8(remark), QStringLiteral("The quick brown fox " - "jumps over the lazy dog")); - - // Now replace the remark - auto job3 = openpgp()->signKeyJob(); - QVERIFY (job3); - hookUpPassphraseProvider(job3); - - // Set up the job - job3->setExportable(false); - job3->setUserIDsToSign(uids); - job3->setSigningKey(seckey); - job3->setDupeOk(true); - job3->setRemark(QStringLiteral("The quick brown fox jumps over Frodo")); - - connect(job3, &SignKeyJob::result, this, [this] (const GpgME::Error &err2, - const QString, - const GpgME::Error) { - Q_EMIT asyncDone(); - QVERIFY(!err2); - }); - - job3->start(target); - QVERIFY(spy.wait(QSIGNALSPY_TIMEOUT)); - - target.update(); - remark = target.userID(0).remark(seckey, err); - QVERIFY(!err); - QVERIFY(remark); - QCOMPARE(QString::fromUtf8(remark), QStringLiteral("The quick brown fox " - "jumps over Frodo")); - } - - void testRemarkReplaceMultiUID() - { - if (!loopbackSupported()) { - return; - } - // Get the signing key (alfa) - auto ctx = Context::create(OpenPGP); - QVERIFY (ctx); - Error err; - auto seckey = ctx->key("A0FF4590BB6122EDEF6E3C542D727CC768697734", err, true); - QVERIFY (!seckey.isNull()); - QVERIFY (!err); - - // Get the target key (mallory / mike) - auto target = ctx->key("2686AA191A278013992C72EBBE794852BE5CF886", err, false); - QVERIFY (!target.isNull()); - QVERIFY (!err); - QVERIFY (target.numUserIDs()); - - // Create the job - auto job = openpgp()->signKeyJob(); - QVERIFY (job); - hookUpPassphraseProvider(job); - - // Set up the job - job->setExportable(false); - std::vector<unsigned int> uids; - uids.push_back(0); - job->setUserIDsToSign(uids); - job->setSigningKey(seckey); - job->setRemark(QStringLiteral("Mallory is evil 😠")); - - connect(job, &SignKeyJob::result, this, [this] (const GpgME::Error &err2, - const QString, - const GpgME::Error) { - Q_EMIT asyncDone(); - QVERIFY(!err2); - }); - - job->start(target); - QSignalSpy spy (this, SIGNAL(asyncDone())); - QVERIFY(spy.wait(QSIGNALSPY_TIMEOUT)); - - // At this point the remark should have been added. - target.update(); - const char *remark = target.userID(0).remark(seckey, err); - QVERIFY(!err); - QVERIFY(remark); - QCOMPARE(QString::fromUtf8(remark), QStringLiteral("Mallory is evil 😠")); - - // Try to replace it without dupeOK - auto job2 = openpgp()->signKeyJob(); - QVERIFY (job2); - hookUpPassphraseProvider(job2); - - // Set up the job - job2->setExportable(false); - job2->setUserIDsToSign(uids); - job2->setSigningKey(seckey); - job2->setRemark(QStringLiteral("Mallory is nice")); - - connect(job2, &SignKeyJob::result, this, [this] (const GpgME::Error &err2, - const QString, - const GpgME::Error) { - Q_EMIT asyncDone(); - QVERIFY(err2); - }); - - job2->start(target); - QVERIFY(spy.wait(QSIGNALSPY_TIMEOUT)); - - // Now replace the remark - auto job3 = openpgp()->signKeyJob(); - QVERIFY (job3); - hookUpPassphraseProvider(job3); - - // Set up the job - job3->setExportable(false); - job3->setUserIDsToSign(uids); - job3->setSigningKey(seckey); - job3->setDupeOk(true); - job3->setRemark(QStringLiteral("Mallory is nice")); - - connect(job3, &SignKeyJob::result, this, [this] (const GpgME::Error &err2, - const QString, - const GpgME::Error) { - Q_EMIT asyncDone(); - QVERIFY(!err2); - }); - - job3->start(target); - QVERIFY(spy.wait(QSIGNALSPY_TIMEOUT)); - - target.update(); - remark = target.userID(0).remark(seckey, err); - QVERIFY(!err); - QVERIFY(remark); - QCOMPARE(QString::fromUtf8(remark), QStringLiteral("Mallory is nice")); - } - - void initTestCase() - { - QGpgMETest::initTestCase(); - const QString gpgHome = qgetenv("GNUPGHOME"); - QVERIFY(copyKeyrings(gpgHome, mDir.path())); - qputenv("GNUPGHOME", mDir.path().toUtf8()); - QFile conf(mDir.path() + QStringLiteral("/gpg.conf")); - QVERIFY(conf.open(QIODevice::WriteOnly)); - if (GpgME::engineInfo(GpgME::GpgEngine).engineVersion() >= "2.2.18") { - conf.write("allow-weak-key-signatures"); - } - conf.close(); - } - -private: - QTemporaryDir mDir; -}; - -QTEST_MAIN(TestRemarks) - -#include "t-remarks.moc" diff --git a/lang/qt/tests/t-revokekey.cpp b/lang/qt/tests/t-revokekey.cpp deleted file mode 100644 index 4d8b0ca5..00000000 --- a/lang/qt/tests/t-revokekey.cpp +++ /dev/null @@ -1,338 +0,0 @@ -/* t-revokekey.cpp - - This file is part of qgpgme, the Qt API binding for gpgme - Copyright (c) 2022 g10 Code GmbH - Software engineering by Ingo Klöcker <[email protected]> - - QGpgME is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - QGpgME is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - - In addition, as a special exception, the copyright holders give - permission to link the code of this program with any edition of - the Qt library by Trolltech AS, Norway (or with modified versions - of Qt that use the same license as Qt), and distribute linked - combinations including the two. You must obey the GNU General - Public License in all respects for all of the code used other than - Qt. If you modify this file, you may extend this exception to - your version of the file, but you are not obligated to do so. If - you do not wish to do so, delete this exception statement from - your version. -*/ -#ifdef HAVE_CONFIG_H - #include "config.h" -#endif - -#include "t-support.h" - -#include <protocol.h> -#include <revokekeyjob.h> - -#include <QDebug> -#include <QProcess> -#include <QRegularExpression> -#include <QSignalSpy> -#include <QTest> - -#include <gpgme++/context.h> -#include <gpgme++/data.h> - -#include <algorithm> - -using namespace QGpgME; -using namespace GpgME; - -/* Test keys - sec ed25519 2022-03-29 [SC] - 604122B94C86BE846EAFE637FC2BCFB1B19A1CF4 - uid [ultimate] [email protected] - ssb cv25519 2022-03-29 [E] - * generated with -export GNUPGHOME=$(mktemp -d) -gpg -K -gpg --batch --pinentry-mode loopback --passphrase abc --quick-gen-key [email protected] default default never -gpg -K -gpg --export-secret-keys --armor --batch --pinentry-mode loopback --passphrase abc --comment [email protected] [email protected] | sed 's/\(.*\)/ "\1\\n"/' -#rm -rf ${GNUPGHOME} -unset GNUPGHOME -*/ -static const char *testKeyData = - "-----BEGIN PGP PRIVATE KEY BLOCK-----\n" - "Comment: [email protected]\n" - "\n" - "lIYEYkLSGhYJKwYBBAHaRw8BAQdAWKBjYOZIW33CjwlHKKGIgqXDOGhmbPCStkj1\n" - "+2/cVFL+BwMCXJpRHkD8EcT8DMWdVo84Lx4w7RNDCQx5xnm6rO5kvtmh+PjgM3qt\n" - "CQVGy8H7Dq35yzi0Hihm5zvHxVGYdAu96ShAI2ZqqVL7is0CdAmAibQVcmV2b2tl\n" - "LW1lQGV4YW1wbGUubmV0iJQEExYKADwWIQRgQSK5TIa+hG6v5jf8K8+xsZoc9AUC\n" - "YkLSGgIbAwULCQgHAgMiAgEGFQoJCAsCBBYCAwECHgcCF4AACgkQ/CvPsbGaHPSH\n" - "LAD/RNFgm1Bp6ltDXLS6oS0S5Bgjjg3CBpbdxWTvLjPpaagBAIU2pTLrsGNDKIZq\n" - "EAY7hY50tdcvOfT4OSAySJACJzMFnIsEYkLSGhIKKwYBBAGXVQEFAQEHQIOTbPEz\n" - "hUtL72BHfetUWESlEbh2IF/NEUWASUtQJDghAwEIB/4HAwJGE5naBnwwcfyPC+Nq\n" - "DwY5FO28hQVAzgNu9KAncmPtpST1J8sEPAtJGhtq/9fki9eSvBMbAa64VVpFHKHK\n" - "ravZxr2uCrK6J/u4rTvnR8HgiHgEGBYKACAWIQRgQSK5TIa+hG6v5jf8K8+xsZoc\n" - "9AUCYkLSGgIbDAAKCRD8K8+xsZoc9ANAAP9rX/xanm7YvcGFIxPclmy4h33lLaG8\n" - "dE5RA6zeSg7DqQD8Dae82iKaqKfTpe2+2vIEyxBVy8+WttoElUoXiwr0AQg=\n" - "=/5re\n" - "-----END PGP PRIVATE KEY BLOCK-----\n"; - -class RevokeKeyJobTest : public QGpgMETest -{ - Q_OBJECT - -private Q_SLOTS: - - void initTestCase() - { - QGpgMETest::initTestCase(); - - // set up the test fixture for this test - qputenv("GNUPGHOME", mGnupgHomeTestFixture.path().toUtf8()); - QVERIFY(importSecretKeys(testKeyData, 1)); - } - - void init() - { - // set up a copy of the test fixture for each test function - mGnupgHomeTestCopy.reset(new QTemporaryDir{}); - QVERIFY(copyKeyrings(mGnupgHomeTestFixture.path(), mGnupgHomeTestCopy->path())); - qputenv("GNUPGHOME", mGnupgHomeTestCopy->path().toUtf8()); - } - - void testAsync() - { - // Get the key that shall be revoked - auto key = getTestKey("[email protected]"); - QVERIFY(!key.isNull()); - QVERIFY(!key.isRevoked()); - - auto job = std::unique_ptr<RevokeKeyJob>{openpgp()->revokeKeyJob()}; - hookUpPassphraseProvider(job.get()); - - Error result; - connect(job.get(), &RevokeKeyJob::result, - job.get(), [this, &result](const Error &result_) { - result = result_; - Q_EMIT asyncDone(); - }); - QVERIFY(!job->start(key, RevocationReason::NoLongerUsed, - {"This key is not used anymore."})); - job.release(); // after the job has been started it's on its own - - QSignalSpy spy (this, SIGNAL(asyncDone())); - QVERIFY(spy.wait(QSIGNALSPY_TIMEOUT)); - - QVERIFY(result.code() == GPG_ERR_NO_ERROR); - key.update(); - QVERIFY(key.isRevoked()); - verifyReason(key, RevocationReason::NoLongerUsed, - {"This key is not used anymore."}); - } - - void testSync_noReasonDescription() - { - // Get the key that shall be revoked - auto key = getTestKey("[email protected]"); - QVERIFY(!key.isNull()); - QVERIFY(!key.isRevoked()); - - auto job = std::unique_ptr<RevokeKeyJob>{openpgp()->revokeKeyJob()}; - hookUpPassphraseProvider(job.get()); - - const auto result = job->exec(key); - - QVERIFY(result.code() == GPG_ERR_NO_ERROR); - key.update(); - QVERIFY(key.isRevoked()); - verifyReason(key, RevocationReason::Unspecified, {}); - } - - void testSync_oneLineReasonDescription() - { - // Get the key that shall be revoked - auto key = getTestKey("[email protected]"); - QVERIFY(!key.isNull()); - QVERIFY(!key.isRevoked()); - - auto job = std::unique_ptr<RevokeKeyJob>{openpgp()->revokeKeyJob()}; - hookUpPassphraseProvider(job.get()); - - const auto result = job->exec(key, RevocationReason::Compromised, - {"The secret key was stolen."}); - - QVERIFY(result.code() == GPG_ERR_NO_ERROR); - key.update(); - QVERIFY(key.isRevoked()); - verifyReason(key, RevocationReason::Compromised, - {"The secret key was stolen."}); - } - - void testSync_twoLinesReasonDescription() - { - // Get the key that shall be revoked - auto key = getTestKey("[email protected]"); - QVERIFY(!key.isNull()); - QVERIFY(!key.isRevoked()); - - auto job = std::unique_ptr<RevokeKeyJob>{openpgp()->revokeKeyJob()}; - hookUpPassphraseProvider(job.get()); - - const auto result = job->exec(key, RevocationReason::Superseded, - {"This key has been superseded by key", - "0000 1111 2222 3333 4444 5555 6666 7777 8888 9999."}); - - QVERIFY(result.code() == GPG_ERR_NO_ERROR); - key.update(); - QVERIFY(key.isRevoked()); - verifyReason(key, RevocationReason::Superseded, - {"This key has been superseded by key", - "0000 1111 2222 3333 4444 5555 6666 7777 8888 9999."}); - } - - void testErrorHandling_nullKey() - { - { - auto job = std::unique_ptr<RevokeKeyJob>{openpgp()->revokeKeyJob()}; - QTest::ignoreMessage(QtWarningMsg, "Error: Key is null key"); - const auto result = job->exec(Key{}); - QVERIFY(result.code() == GPG_ERR_INV_ARG); - } - { - auto job = std::unique_ptr<RevokeKeyJob>{openpgp()->revokeKeyJob()}; - QTest::ignoreMessage(QtWarningMsg, "Error: Key is null key"); - const auto result = job->start(Key{}); - QVERIFY(result.code() == GPG_ERR_INV_ARG); - } - } - - void testErrorHandling_invalidReason() - { - // Get the key that shall be revoked - auto key = getTestKey("[email protected]"); - QVERIFY(!key.isNull()); - QVERIFY(!key.isRevoked()); - - { - auto job = std::unique_ptr<RevokeKeyJob>{openpgp()->revokeKeyJob()}; - QTest::ignoreMessage(QtWarningMsg, QRegularExpression{"^Error: Invalid revocation reason"}); - const auto result = job->exec(key, static_cast<RevocationReason>(-1)); - QVERIFY(result.code() == GPG_ERR_INV_VALUE); - } - { - auto job = std::unique_ptr<RevokeKeyJob>{openpgp()->revokeKeyJob()}; - QTest::ignoreMessage(QtWarningMsg, QRegularExpression{"^Error: Invalid revocation reason"}); - const auto result = job->start(key, static_cast<RevocationReason>(4)); - QVERIFY(result.code() == GPG_ERR_INV_VALUE); - } - } - - void testErrorHandling_invalidDescription() - { - // Get the key that shall be revoked - auto key = getTestKey("[email protected]"); - QVERIFY(!key.isNull()); - QVERIFY(!key.isRevoked()); - - { - auto job = std::unique_ptr<RevokeKeyJob>{openpgp()->revokeKeyJob()}; - QTest::ignoreMessage(QtWarningMsg, "Error: Revocation description contains empty lines or lines with endline characters"); - const auto result = job->exec(key, RevocationReason::Unspecified, - {"line1", "", "line3"}); - QVERIFY(result.code() == GPG_ERR_INV_VALUE); - } - { - auto job = std::unique_ptr<RevokeKeyJob>{openpgp()->revokeKeyJob()}; - QTest::ignoreMessage(QtWarningMsg, "Error: Revocation description contains empty lines or lines with endline characters"); - const auto result = job->start(key, RevocationReason::Unspecified, - {"line1\nline2"}); - QVERIFY(result.code() == GPG_ERR_INV_VALUE); - } - } - -private: - Key getTestKey(const char *pattern) - { - auto ctx = Context::create(OpenPGP); - VERIFY_OR_OBJECT(ctx); - - Error err; - auto key = ctx->key(pattern, err, /*secret=*/true); - VERIFY_OR_OBJECT(!err); - VERIFY_OR_OBJECT(!key.isNull()); - return key; - } - - bool verifyReason(const Key &key, RevocationReason reason, const QStringList &description) - { - static const auto startTimeout = std::chrono::milliseconds{1000}; - static const auto finishTimeout = std::chrono::milliseconds{2000}; - static const QStringList hexCodeForReason = { - QStringLiteral("00"), /* no particular reason */ - QStringLiteral("02"), /* key has been compromised */ - QStringLiteral("01"), /* key is superseded */ - QStringLiteral("03") /* key is no longer used */ - }; - - QProcess p; - p.setProgram(dirInfo("gpg-name")); - p.setArguments({QStringLiteral("-K"), - QStringLiteral("--with-colon"), - QStringLiteral("--with-sig-list"), - QLatin1String{key.primaryFingerprint()} - }); - - p.start(); - - if (!p.waitForStarted(startTimeout.count())) { - qWarning() << "Timeout while waiting for start of" << p.program() << p.arguments().join(u' '); - return false; - } - if (!p.waitForFinished(finishTimeout.count())) { - qWarning() << "Timeout while waiting for completion of" << p.program() << p.arguments().join(u' '); - return false; - } - if (p.exitStatus() != QProcess::NormalExit) { - qWarning() << p.program() << "terminated abnormally with exit status" << p.exitStatus(); - return false; - } - - const auto lines = QString::fromUtf8(p.readAllStandardOutput()).split(u'\n'); - for (const auto &l : lines) { - const auto fields = l.split(u':'); - if (fields[0] == QLatin1String{"rev"}) { - // or "rev" the signature class may be followed by a comma - // and a 2 digit hexnumber with the revocation reason - const auto sigClass = fields.value(10); - const auto revReason = sigClass.split(u',').value(1); - COMPARE_OR_FALSE(revReason, hexCodeForReason.value(static_cast<int>(reason))); - - // decode the \n in the C-style quoted comment field - const auto comment = fields.value(20).replace(QStringLiteral("\\n"), QStringLiteral("\n")); - COMPARE_OR_FALSE(comment, description.join(u'\n')); - return true; - } - if (fields[0] == QLatin1String{"uid"}) { - qWarning() << "Found uid before rev in key listing:\n" << stdout; - return false; - } - } - return false; - } - -private: - QTemporaryDir mGnupgHomeTestFixture; - std::unique_ptr<QTemporaryDir> mGnupgHomeTestCopy; -}; - -QTEST_MAIN(RevokeKeyJobTest) - -#include "t-revokekey.moc" diff --git a/lang/qt/tests/t-setprimaryuserid.cpp b/lang/qt/tests/t-setprimaryuserid.cpp deleted file mode 100644 index e57d1c6e..00000000 --- a/lang/qt/tests/t-setprimaryuserid.cpp +++ /dev/null @@ -1,165 +0,0 @@ -/* t-setprimaryuserid.cpp - - This file is part of qgpgme, the Qt API binding for gpgme - Copyright (c) 2022 g10 Code GmbH - Software engineering by Ingo Klöcker <[email protected]> - - QGpgME is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - QGpgME is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - - In addition, as a special exception, the copyright holders give - permission to link the code of this program with any edition of - the Qt library by Trolltech AS, Norway (or with modified versions - of Qt that use the same license as Qt), and distribute linked - combinations including the two. You must obey the GNU General - Public License in all respects for all of the code used other than - Qt. If you modify this file, you may extend this exception to - your version of the file, but you are not obligated to do so. If - you do not wish to do so, delete this exception statement from - your version. -*/ -#ifdef HAVE_CONFIG_H - #include "config.h" -#endif - -#include "t-support.h" - -#include <keylistjob.h> -#include <protocol.h> - -#include <gpgme++/context.h> -#include <gpgme++/engineinfo.h> -#include <gpgme++/keylistresult.h> - -using namespace QGpgME; -using namespace GpgME; - -class TestSetPrimaryUserID: public QGpgMETest -{ - Q_OBJECT - -private Q_SLOTS: - void testSetPrimaryUserID() - { - Key key; - { - std::unique_ptr<KeyListJob> job{openpgp()->keyListJob()}; - std::vector<GpgME::Key> keys; - GpgME::KeyListResult result = job->exec({QStringLiteral("[email protected]")}, true, keys); - QVERIFY(!result.error()); - QVERIFY(keys.size() == 1); - key = keys.front(); - } - - QCOMPARE(key.numUserIDs(), 3u); - const std::string oldPrimaryUserId = key.userID(0).id(); - const std::string newPrimaryUserId = key.userID(1).id(); - const std::string newPrimaryUserIdHash = key.userID(1).uidhash(); - - { - std::unique_ptr<Context> ctx{Context::createForProtocol(key.protocol())}; - QVERIFY(ctx); - hookUpPassphraseProvider(ctx.get()); - - if (GpgME::engineInfo(GpgME::GpgEngine).engineVersion() >= "2.3.8") { - QVERIFY(!ctx->setPrimaryUid(key, newPrimaryUserIdHash.c_str())); - } else { - QVERIFY(!ctx->setPrimaryUid(key, newPrimaryUserId.c_str())); - } - } - key.update(); - - QCOMPARE(key.userID(0).id(), newPrimaryUserId); - - { - std::unique_ptr<Context> ctx{Context::createForProtocol(key.protocol())}; - QVERIFY(ctx); - hookUpPassphraseProvider(ctx.get()); - - QVERIFY(!ctx->setPrimaryUid(key, oldPrimaryUserId.c_str())); - } - key.update(); - - QCOMPARE(key.userID(0).id(), oldPrimaryUserId); - } - - void testErrorHandling_noSecretKey() - { - if (GpgME::engineInfo(GpgME::GpgEngine).engineVersion() < "2.3.8") { - QSKIP("gpg < 2.3.8 does not report status error"); - } - Key key; - { - std::unique_ptr<KeyListJob> job{openpgp()->keyListJob()}; - std::vector<GpgME::Key> keys; - GpgME::KeyListResult result = job->exec({QStringLiteral("[email protected]")}, false, keys); - QVERIFY(!result.error()); - QVERIFY(keys.size() == 1); - key = keys.front(); - } - - QCOMPARE(key.numUserIDs(), 2u); - const std::string newPrimaryUserId = key.userID(1).id(); - - { - std::unique_ptr<Context> ctx{Context::createForProtocol(key.protocol())}; - QVERIFY(ctx); - auto err = ctx->setPrimaryUid(key, newPrimaryUserId.c_str()); - QCOMPARE(err.code(), static_cast<int>(GPG_ERR_NO_SECKEY)); - } - } - - void testErrorHandling_noUserID() - { - if (GpgME::engineInfo(GpgME::GpgEngine).engineVersion() < "2.3.8") { - QSKIP("gpg < 2.3.8 does not report status error"); - } - Key key; - { - std::unique_ptr<KeyListJob> job{openpgp()->keyListJob()}; - std::vector<GpgME::Key> keys; - GpgME::KeyListResult result = job->exec({QStringLiteral("[email protected]")}, true, keys); - QVERIFY(!result.error()); - QVERIFY(keys.size() == 1); - key = keys.front(); - } - { - std::unique_ptr<Context> ctx{Context::createForProtocol(key.protocol())}; - QVERIFY(ctx); - auto err = ctx->setPrimaryUid(key, "bravo"); - QCOMPARE(err.code(), static_cast<int>(GPG_ERR_NO_USER_ID)); - } - } - - void initTestCase() - { - QGpgMETest::initTestCase(); - const QString gpgHome = qgetenv("GNUPGHOME"); - QVERIFY(copyKeyrings(gpgHome, mDir.path())); - qputenv("GNUPGHOME", mDir.path().toUtf8()); - QFile conf(mDir.path() + QStringLiteral("/gpg.conf")); - QVERIFY(conf.open(QIODevice::WriteOnly)); - if (GpgME::engineInfo(GpgME::GpgEngine).engineVersion() >= "2.2.18") { - conf.write("allow-weak-key-signatures\n"); - } - conf.close(); - } - -private: - QTemporaryDir mDir; -}; - -QTEST_MAIN(TestSetPrimaryUserID) - -#include "t-setprimaryuserid.moc" diff --git a/lang/qt/tests/t-support.cpp b/lang/qt/tests/t-support.cpp deleted file mode 100644 index 48ad0cd9..00000000 --- a/lang/qt/tests/t-support.cpp +++ /dev/null @@ -1,170 +0,0 @@ -/* t-support.cpp - - This file is part of qgpgme, the Qt API binding for gpgme - Copyright (c) 2016 by Bundesamt für Sicherheit in der Informationstechnik - Software engineering by Intevation GmbH - - QGpgME is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - QGpgME is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - - In addition, as a special exception, the copyright holders give - permission to link the code of this program with any edition of - the Qt library by Trolltech AS, Norway (or with modified versions - of Qt that use the same license as Qt), and distribute linked - combinations including the two. You must obey the GNU General - Public License in all respects for all of the code used other than - Qt. If you modify this file, you may extend this exception to - your version of the file, but you are not obligated to do so. If - you do not wish to do so, delete this exception statement from - your version. -*/ - -#ifdef HAVE_CONFIG_H - #include "config.h" -#endif - -#include "t-support.h" - -#include "importjob.h" -#include "job.h" -#include "protocol.h" - -#include <QTest> - -#include <QProcess> -#include <QCoreApplication> -#include <QObject> -#include <QDir> -#include <QSignalSpy> - -#include <gpgme++/context.h> -#include <gpgme++/engineinfo.h> -#include <gpgme++/importresult.h> - -using namespace GpgME; -using namespace QGpgME; - -void QGpgMETest::initTestCase() -{ - GpgME::initializeLibrary(); - const QString gpgHome = qgetenv("GNUPGHOME"); - QVERIFY2(!gpgHome.isEmpty(), "GNUPGHOME environment variable is not set."); -} - -void QGpgMETest::cleanupTestCase() -{ - QCoreApplication::sendPostedEvents(); - killAgent(); -} - -// static -bool QGpgMETest::doOnlineTests() -{ - return !qgetenv("DO_ONLINE_TESTS").isEmpty(); -} - -bool QGpgMETest::copyKeyrings(const QString &src, const QString &dest) -{ - bool is21dir = QFileInfo(src + QDir::separator() + QStringLiteral("pubring.kbx")).exists(); - const QString name = is21dir ? QStringLiteral("pubring.kbx") : - QStringLiteral("pubring.gpg"); - if (!QFile::copy(src + QDir::separator() + name, dest + QDir::separator() + name)) { - return false; - } - if (!is21dir) { - return (QFile::copy(src + QDir::separator() + QStringLiteral("secring.gpg"), - dest + QDir::separator() + QStringLiteral("secring.gpg"))); - } - QDir dir (src + QDir::separator() + QStringLiteral("private-keys-v1.d")); - QDir target(dest); - if (!target.mkdir("private-keys-v1.d")) { - return false; - } - foreach (QString f, dir.entryList(QDir::Files)) { - if (!QFile::copy(dir.path() + QDir::separator() + f, - dest + QDir::separator() + - QStringLiteral("private-keys-v1.d") + QDir::separator() + f)) { - return false; - } - } - return true; -} - -bool QGpgMETest::importSecretKeys(const char *keyData, int expectedKeys) -{ - auto job = std::unique_ptr<ImportJob>{openpgp()->importJob()}; - VERIFY_OR_FALSE(job); - hookUpPassphraseProvider(job.get()); - - ImportResult result; - connect(job.get(), &ImportJob::result, - this, [this, &result](const ImportResult &result_) { - result = result_; - Q_EMIT asyncDone(); - }); - VERIFY_OR_FALSE(!job->start(keyData)); - job.release(); // after the job has been started it's on its own - - QSignalSpy spy (this, SIGNAL(asyncDone())); - VERIFY_OR_FALSE(spy.wait(QSIGNALSPY_TIMEOUT)); - VERIFY_OR_FALSE(!result.error()); - VERIFY_OR_FALSE(!result.imports().empty()); - COMPARE_OR_FALSE(result.numSecretKeysImported(), expectedKeys); - - return true; -} - -void QGpgMETest::hookUpPassphraseProvider(GpgME::Context *context) -{ - context->setPassphraseProvider(&mPassphraseProvider); - context->setPinentryMode(Context::PinentryLoopback); -} - -void QGpgMETest::hookUpPassphraseProvider(QGpgME::Job *job) -{ - hookUpPassphraseProvider(Job::context(job)); -} - -void killAgent(const QString& dir) -{ - QProcess proc; - proc.setProgram(QStringLiteral("gpg-connect-agent")); - QStringList arguments; - arguments << "-S " << dir + "/S.gpg-agent"; - proc.start(); - proc.waitForStarted(); - proc.write("KILLAGENT\n"); - proc.write("BYE\n"); - proc.closeWriteChannel(); - proc.waitForFinished(); -} - -bool loopbackSupported() -{ - /* With GnuPG 2.0.x (at least 2.0.26 by default on jessie) - * the passphrase_cb does not work. So the test popped up - * a pinentry. So tests requiring decryption don't work. */ - static auto version = GpgME::engineInfo(GpgME::GpgEngine).engineVersion(); - if (version < "2.0.0") { - /* With 1.4 it just works */ - return true; - } - if (version < "2.1.0") { - /* With 2.1 it works with loopback mode */ - return false; - } - return true; -} - -#include "t-support.hmoc" diff --git a/lang/qt/tests/t-support.h b/lang/qt/tests/t-support.h deleted file mode 100644 index eb4ba57d..00000000 --- a/lang/qt/tests/t-support.h +++ /dev/null @@ -1,134 +0,0 @@ -/* t-support.h - - This file is part of qgpgme, the Qt API binding for gpgme - Copyright (c) 2016 by Bundesamt für Sicherheit in der Informationstechnik - Software engineering by Intevation GmbH - - QGpgME is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - QGpgME is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - - In addition, as a special exception, the copyright holders give - permission to link the code of this program with any edition of - the Qt library by Trolltech AS, Norway (or with modified versions - of Qt that use the same license as Qt), and distribute linked - combinations including the two. You must obey the GNU General - Public License in all respects for all of the code used other than - Qt. If you modify this file, you may extend this exception to - your version of the file, but you are not obligated to do so. If - you do not wish to do so, delete this exception statement from - your version. -*/ -#ifndef T_SUPPORT_H -#define T_SUPPORT_H - -#include <gpgme++/interfaces/passphraseprovider.h> -#include <QObject> -#include <QTest> - -#include <gpg-error.h> - -namespace GpgME -{ -class Context; -} - -namespace QGpgME -{ -class Job; -} - -/// generic variant of QVERIFY returning \a returnValue on failure -#define VERIFY_OR_RETURN_VALUE(statement, returnValue) \ -do {\ - if (!QTest::qVerify(static_cast<bool>(statement), #statement, "", __FILE__, __LINE__))\ - return returnValue;\ -} while (false) - -/// generic variant of QCOMPARE returning \a returnValue on failure -#define COMPARE_OR_RETURN_VALUE(actual, expected, returnValue) \ -do {\ - if (!QTest::qCompare(actual, expected, #actual, #expected, __FILE__, __LINE__))\ - return returnValue;\ -} while (false) - -/// variant of QVERIFY returning a default constructed object on failure -#define VERIFY_OR_OBJECT(statement) VERIFY_OR_RETURN_VALUE(statement, {}) - -/// variant of QCOMPARE returning a default constructed object on failure -#define COMPARE_OR_OBJECT(actual, expected) COMPARE_OR_RETURN_VALUE(actual, expected, {}) - -/// variant of QVERIFY returning \c false on failure -#define VERIFY_OR_FALSE(statement) VERIFY_OR_RETURN_VALUE(statement, false) - -/// variant of QCOMPARE returning \c false on failure -#define COMPARE_OR_FALSE(actual, expected) COMPARE_OR_RETURN_VALUE(actual, expected, false) - -namespace QTest -{ -template <> -inline char *toString(const std::string &s) -{ - return QTest::toString(s.c_str()); -} -} - -namespace GpgME -{ -class TestPassphraseProvider : public PassphraseProvider -{ -public: - char *getPassphrase(const char * /*useridHint*/, const char * /*description*/, - bool /*previousWasBad*/, bool &/*canceled*/) override - { - char *ret; - gpgrt_asprintf(&ret, "abc"); - return ret; - } -}; -} // namespace GpgME - -void killAgent(const QString &dir = qgetenv("GNUPGHOME")); -/* Is the passphrase Provider / loopback Supported */ -bool loopbackSupported(); - -class QGpgMETest : public QObject -{ - Q_OBJECT - -Q_SIGNALS: - void asyncDone(); - -protected: - static bool doOnlineTests(); - - bool copyKeyrings(const QString &from, const QString& to); - - bool importSecretKeys(const char *keyData, int expectedKeys = 1); - - void hookUpPassphraseProvider(GpgME::Context *context); - void hookUpPassphraseProvider(QGpgME::Job *job); - -public Q_SLOTS: - void initTestCase(); - void cleanupTestCase(); - -private: - GpgME::TestPassphraseProvider mPassphraseProvider; -}; - -/* Timeout, in milliseconds, for use with QSignalSpy to wait on - signals. */ -#define QSIGNALSPY_TIMEOUT 60000 - -#endif // T_SUPPORT_H diff --git a/lang/qt/tests/t-tofuinfo.cpp b/lang/qt/tests/t-tofuinfo.cpp deleted file mode 100644 index 852142cf..00000000 --- a/lang/qt/tests/t-tofuinfo.cpp +++ /dev/null @@ -1,530 +0,0 @@ -/* t-tofuinfo.cpp - - This file is part of qgpgme, the Qt API binding for gpgme - Copyright (c) 2016 by Bundesamt für Sicherheit in der Informationstechnik - Software engineering by Intevation GmbH - - QGpgME is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - QGpgME is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - - In addition, as a special exception, the copyright holders give - permission to link the code of this program with any edition of - the Qt library by Trolltech AS, Norway (or with modified versions - of Qt that use the same license as Qt), and distribute linked - combinations including the two. You must obey the GNU General - Public License in all respects for all of the code used other than - Qt. If you modify this file, you may extend this exception to - your version of the file, but you are not obligated to do so. If - you do not wish to do so, delete this exception statement from - your version. -*/ -#ifdef HAVE_CONFIG_H - #include "config.h" -#endif - -#include <QDebug> -#include <QTest> -#include <QTemporaryDir> -#include <QSignalSpy> - -#include "debug.h" -#include "protocol.h" -#include <gpgme++/tofuinfo.h> -#include "tofupolicyjob.h" -#include "verifyopaquejob.h" -#include <gpgme++/verificationresult.h> -#include <gpgme++/signingresult.h> -#include "importjob.h" -#include <gpgme++/importresult.h> -#include "keylistjob.h" -#include <gpgme++/keylistresult.h> -#include "signjob.h" -#include <gpgme++/key.h> - -#include "t-support.h" -#include <gpgme++/engineinfo.h> -#include <gpgme++/context.h> -#include <iostream> - -using namespace QGpgME; -using namespace GpgME; - -static const char testMsg1[] = -"-----BEGIN PGP MESSAGE-----\n" -"\n" -"owGbwMvMwCSoW1RzPCOz3IRxjXQSR0lqcYleSUWJTZOvjVdpcYmCu1+oQmaJIleH\n" -"GwuDIBMDGysTSIqBi1MApi+nlGGuwDeHao53HBr+FoVGP3xX+kvuu9fCMJvl6IOf\n" -"y1kvP4y+8D5a11ang0udywsA\n" -"=Crq6\n" -"-----END PGP MESSAGE-----\n"; - -static const char conflictKey1[] = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" -"\n" -"mDMEXDWgpxYJKwYBBAHaRw8BAQdAguVu4qkx8iw4eU+TQ4vvcKG7IdcZvbMhw3Zc\n" -"npGf0+u0GXRvZnVfY29uZmxpY3RAZXhhbXBsZS5jb22IkAQTFggAOBYhBO6ovNDG\n" -"nLzbR1TlMJYJ0fjlWbUrBQJcNaCnAhsDBQsJCAcCBhUKCQgLAgQWAgMBAh4BAheA\n" -"AAoJEJYJ0fjlWbUrLaMBALegwkv2+sEcmKZqxt8JscYvFiEuycv2+rKHaZA0eDoN\n" -"AP97W4XrJb5x49J5jDDdeko8k00uGqiiuAXJo27/i/phA7g4BFw1oKcSCisGAQQB\n" -"l1UBBQEBB0Crhw24E2lPBhd/y+ZFotQ/2TrYqkUQqGPmff8ofLziNgMBCAeIeAQY\n" -"FggAIBYhBO6ovNDGnLzbR1TlMJYJ0fjlWbUrBQJcNaCnAhsMAAoJEJYJ0fjlWbUr\n" -"/K8BAJWsa+tOZsJw7w5fz6O0We6Xx4Rt17jHf563G6wMcz9+AQDRsedJ7w4zYzS9\n" -"MFiJQ5aN0NDHMRtDFWAgCunVnJ3OBw==\n" -"=fZa5\n" -"-----END PGP PUBLIC KEY BLOCK-----\n"; - -static const char conflictKey2[] = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" -"\n" -"mDMEXDWgixYJKwYBBAHaRw8BAQdAMWOhumYspcvEOTuesOSN4rvnJVOj/6qOWFTu\n" -"x+wPRra0GXRvZnVfY29uZmxpY3RAZXhhbXBsZS5jb22IkAQTFggAOBYhBA64G88Q\n" -"NPXztj8ID/FhC7tiGbeRBQJcNaCLAhsDBQsJCAcCBhUKCQgLAgQWAgMBAh4BAheA\n" -"AAoJEPFhC7tiGbeRUt4A/2hf4Zgz+TYyfeH/4/ZtyL1JuZggqR1s5UopEx2Aiw10\n" -"AP405KiTd31TJQN8Ru+7bskPu0/mzLZMNkRvBNEdc5kbDLg4BFw1oIsSCisGAQQB\n" -"l1UBBQEBB0B5NtSrx7wDDKgwUe5Rxz0vRkaWLtyE0KbfE77oPy5DGAMBCAeIeAQY\n" -"FggAIBYhBA64G88QNPXztj8ID/FhC7tiGbeRBQJcNaCLAhsMAAoJEPFhC7tiGbeR\n" -"km0BAP8TQwraipqb1pJlLsEgDXeM5Jocz4fuePD78BsOBtORAP9gpCyKXdyJYGlA\n" -"qjmG356yG6pCK9aPckTZ9IViPiHWCw==\n" -"=tn3Q\n" -"-----END PGP PUBLIC KEY BLOCK-----\n"; - -static const char conflictMsg1[] = "-----BEGIN PGP MESSAGE-----\n" -"\n" -"owGbwMvMwCE2jfPij6eRW7UZTwsnMcSYLnT0Ki0uUXD3C1XILFHk6ihlYRDjYJAV\n" -"U2R5t2LPhWNz9tx2D3lqANPEygTSwcDFKQAT+RjG8M9of873hQrMpinBVwKYv+rq\n" -"XGmYW+ZcZJ+133KDq+itzlxGhg3L2X/6Khj+2Hd+He+KnXtunF2wNWxl7849e/Sy\n" -"v6tc+8MBAA==\n" -"=fZLe\n" -"-----END PGP MESSAGE-----\n"; - -static const char conflictMsg2[] = "-----BEGIN PGP MESSAGE-----\n" -"\n" -"owGbwMvMwCH2MZF7d5Lk9omMp4WTGGJMFwZ4lRaXKLj7hSpklihydZSyMIhxMMiK\n" -"KbLw7ZA+L2Dy9fM2ew5+mCZWJpAOBi5OAZhIUhIjw7bV+xS+cR0quqhmcY2Dl3WW\n" -"8Ufr+rRNufOPyIdoO6nEXGH47/B+E1+oxS6e5f5n7MJ3aHBO+s345sipGV/4f665\n" -"9mmiGjsA\n" -"=8oJA\n" -"-----END PGP MESSAGE-----\n"; - -class TofuInfoTest: public QGpgMETest -{ - Q_OBJECT - -private: - bool testSupported() - { - static bool initialized, supported; - if (initialized) { - return supported; - } - initialized = true; - if (GpgME::engineInfo(GpgME::GpgEngine).engineVersion() < "2.1.16") { - return false; - } - // If the keylist fails here this means that gnupg does not - // support tofu at all. It can be disabled at compile time. So no - // tests. - auto *job = openpgp()->keyListJob(false, false, false); - job->addMode(GpgME::WithTofu); - std::vector<GpgME::Key> keys; - job->exec(QStringList() << QStringLiteral("[email protected]"), true, keys); - delete job; - supported = !keys.empty(); - return supported; - } - - void testTofuCopy(TofuInfo other, const TofuInfo &orig) - { - QVERIFY(!orig.isNull()); - QVERIFY(!other.isNull()); - QVERIFY(orig.signLast() == other.signLast()); - QVERIFY(orig.signCount() == other.signCount()); - QVERIFY(orig.validity() == other.validity()); - QVERIFY(orig.policy() == other.policy()); - } - - void signAndVerify(const QString &what, const GpgME::Key &key, int expected) - { - auto job = openpgp()->signJob(); - hookUpPassphraseProvider(job); - - std::vector<Key> keys; - keys.push_back(key); - QByteArray signedData; - auto sigResult = job->exec(keys, what.toUtf8(), NormalSignatureMode, signedData); - delete job; - - QVERIFY(!sigResult.error()); - for (const auto &uid : keys[0].userIDs()) { - auto info = uid.tofuInfo(); - QVERIFY(info.signCount() == expected - 1); - } - - auto verifyJob = openpgp()->verifyOpaqueJob(); - QByteArray verified; - - auto result = verifyJob->exec(signedData, verified); - delete verifyJob; - - QVERIFY(!result.error()); - QVERIFY(verified == what.toUtf8()); - - QVERIFY(result.numSignatures() == 1); - auto sig = result.signatures()[0]; - - auto key2 = sig.key(); - QVERIFY(!key.isNull()); - QVERIFY(!strcmp (key2.primaryFingerprint(), key.primaryFingerprint())); - QVERIFY(!strcmp (key.primaryFingerprint(), sig.fingerprint())); - auto stats = key2.userID(0).tofuInfo(); - QVERIFY(!stats.isNull()); - if (stats.signCount() != expected) { - std::cout << "################ Key before verify: " - << key - << "################ Key after verify: " - << key2; - } - QVERIFY(stats.signCount() == expected); - } - -private Q_SLOTS: - void testTofuNull() - { - if (!testSupported()) { - return; - } - TofuInfo tofu; - QVERIFY(tofu.isNull()); - QVERIFY(!tofu.description()); - QVERIFY(!tofu.signCount()); - QVERIFY(!tofu.signLast()); - QVERIFY(!tofu.signFirst()); - QVERIFY(tofu.validity() == TofuInfo::ValidityUnknown); - QVERIFY(tofu.policy() == TofuInfo::PolicyUnknown); - } - - void testTofuInfo() - { - if (!testSupported()) { - return; - } - auto *job = openpgp()->verifyOpaqueJob(true); - const QByteArray data1(testMsg1); - QByteArray plaintext; - - auto ctx = Job::context(job); - QVERIFY(ctx); - ctx->setSender("[email protected]"); - - auto result = job->exec(data1, plaintext); - delete job; - - QVERIFY(!result.isNull()); - QVERIFY(!result.error()); - QVERIFY(!strcmp(plaintext.constData(), "Just GNU it!\n")); - - QVERIFY(result.numSignatures() == 1); - Signature sig = result.signatures()[0]; - /* TOFU is always marginal */ - QVERIFY(sig.validity() == Signature::Marginal); - - auto stats = sig.key().userID(0).tofuInfo(); - QVERIFY(!stats.isNull()); - QVERIFY(sig.key().primaryFingerprint()); - QVERIFY(sig.fingerprint()); - QVERIFY(!strcmp(sig.key().primaryFingerprint(), sig.fingerprint())); - QVERIFY(stats.signFirst() == stats.signLast()); - QVERIFY(stats.signCount() == 1); - QVERIFY(stats.policy() == TofuInfo::PolicyAuto); - QVERIFY(stats.validity() == TofuInfo::LittleHistory); - - testTofuCopy(stats, stats); - - /* Another verify */ - - job = openpgp()->verifyOpaqueJob(true); - result = job->exec(data1, plaintext); - delete job; - - QVERIFY(!result.isNull()); - QVERIFY(!result.error()); - - QVERIFY(result.numSignatures() == 1); - sig = result.signatures()[0]; - /* TOFU is always marginal */ - QVERIFY(sig.validity() == Signature::Marginal); - - stats = sig.key().userID(0).tofuInfo(); - QVERIFY(!stats.isNull()); - QVERIFY(!strcmp(sig.key().primaryFingerprint(), sig.fingerprint())); - QVERIFY(stats.signFirst() == stats.signLast()); - QVERIFY(stats.signCount() == 1); - QVERIFY(stats.policy() == TofuInfo::PolicyAuto); - QVERIFY(stats.validity() == TofuInfo::LittleHistory); - - /* Verify that another call yields the same result */ - job = openpgp()->verifyOpaqueJob(true); - result = job->exec(data1, plaintext); - delete job; - - QVERIFY(!result.isNull()); - QVERIFY(!result.error()); - - QVERIFY(result.numSignatures() == 1); - sig = result.signatures()[0]; - /* TOFU is always marginal */ - QVERIFY(sig.validity() == Signature::Marginal); - - stats = sig.key().userID(0).tofuInfo(); - QVERIFY(!stats.isNull()); - QVERIFY(!strcmp(sig.key().primaryFingerprint(), sig.fingerprint())); - QVERIFY(stats.signFirst() == stats.signLast()); - QVERIFY(stats.signCount() == 1); - QVERIFY(stats.policy() == TofuInfo::PolicyAuto); - QVERIFY(stats.validity() == TofuInfo::LittleHistory); - } - - void testTofuSignCount() - { - if (!testSupported()) { - return; - } - auto *job = openpgp()->keyListJob(false, false, false); - job->addMode(GpgME::WithTofu); - std::vector<GpgME::Key> keys; - GpgME::KeyListResult result = job->exec(QStringList() << QStringLiteral("[email protected]"), - true, keys); - delete job; - QVERIFY(!keys.empty()); - Key key = keys[0]; - QVERIFY(!key.isNull()); - - /* As we sign & verify quickly here we need different - * messages to avoid having them treated as the same - * message if they were created within the same second. - * Alternatively we could use the same message and wait - * a second between each call. But this would slow down - * the testsuite. */ - signAndVerify(QStringLiteral("Hello"), key, 1); - key.update(); - signAndVerify(QStringLiteral("Hello2"), key, 2); - key.update(); - signAndVerify(QStringLiteral("Hello3"), key, 3); - key.update(); - signAndVerify(QStringLiteral("Hello4"), key, 4); - } - - void testTofuKeyList() - { - if (!testSupported()) { - return; - } - - /* First check that the key has no tofu info. */ - auto *job = openpgp()->keyListJob(false, false, false); - std::vector<GpgME::Key> keys; - auto result = job->exec(QStringList() << QStringLiteral("[email protected]"), - true, keys); - delete job; - QVERIFY(!keys.empty()); - auto key = keys[0]; - QVERIFY(!key.isNull()); - QVERIFY(key.userID(0).tofuInfo().isNull()); - auto keyCopy = key; - keyCopy.update(); - auto sigCnt = keyCopy.userID(0).tofuInfo().signCount(); - signAndVerify(QStringLiteral("Hello5"), keyCopy, - sigCnt + 1); - keyCopy.update(); - signAndVerify(QStringLiteral("Hello6"), keyCopy, - sigCnt + 2); - - /* Now another one but with tofu */ - job = openpgp()->keyListJob(false, false, false); - job->addMode(GpgME::WithTofu); - result = job->exec(QStringList() << QStringLiteral("[email protected]"), - true, keys); - delete job; - QVERIFY(!result.error()); - QVERIFY(!keys.empty()); - auto key2 = keys[0]; - QVERIFY(!key2.isNull()); - auto info = key2.userID(0).tofuInfo(); - QVERIFY(!info.isNull()); - QVERIFY(info.signCount()); - } - - void testTofuPolicy() - { - if (!testSupported()) { - return; - } - - /* First check that the key has no tofu info. */ - auto *job = openpgp()->keyListJob(false, false, false); - std::vector<GpgME::Key> keys; - job->addMode(GpgME::WithTofu); - auto result = job->exec(QStringList() << QStringLiteral("[email protected]"), - false, keys); - - if (keys.empty()) { - qDebug() << "[email protected] not found"; - qDebug() << "Error: " << result.error(); - const auto homedir = QString::fromLocal8Bit(qgetenv("GNUPGHOME")); - qDebug() << "Homedir is: " << homedir; - QFileInfo fi(homedir + "/pubring.gpg"); - qDebug () << "pubring exists: " << fi.exists() << " readable? " - << fi.isReadable() << " size: " << fi.size(); - QFileInfo fi2(homedir + "/pubring.kbx"); - qDebug () << "keybox exists: " << fi2.exists() << " readable? " - << fi2.isReadable() << " size: " << fi2.size(); - - result = job->exec(QStringList(), false, keys); - for (const auto &key : keys) { - qDebug() << "Key: " << key.userID(0).name() << " <" - << key.userID(0).email() - << ">\n fpr: " << key.primaryFingerprint(); - } - } - QVERIFY(!result.error()); - QVERIFY(!keys.empty()); - auto key = keys[0]; - QVERIFY(!key.isNull()); - QVERIFY(key.userID(0).tofuInfo().policy() != TofuInfo::PolicyBad); - auto *tofuJob = openpgp()->tofuPolicyJob(); - auto err = tofuJob->exec(key, TofuInfo::PolicyBad); - QVERIFY(!err); - result = job->exec(QStringList() << QStringLiteral("[email protected]"), - false, keys); - QVERIFY(!keys.empty()); - key = keys[0]; - QVERIFY(key.userID(0).tofuInfo().policy() == TofuInfo::PolicyBad); - err = tofuJob->exec(key, TofuInfo::PolicyGood); - - result = job->exec(QStringList() << QStringLiteral("[email protected]"), - false, keys); - key = keys[0]; - QVERIFY(key.userID(0).tofuInfo().policy() == TofuInfo::PolicyGood); - delete tofuJob; - delete job; - } - - void testTofuConflict() - { - if (!testSupported()) { - return; - } - - if (GpgME::engineInfo(GpgME::GpgEngine).engineVersion() < "2.1.19") { - return; - } - - // Import key 1 - auto importjob = openpgp()->importJob(); - connect(importjob, &ImportJob::result, this, - [this](ImportResult result, QString, Error) - { - QVERIFY(!result.error()); - QVERIFY(!result.imports().empty()); - QVERIFY(result.numImported()); - Q_EMIT asyncDone(); - }); - importjob->start(QByteArray(conflictKey1)); - QSignalSpy spy (this, SIGNAL(asyncDone())); - QVERIFY(spy.wait()); - - // Verify Message 1 - const QByteArray signedData(conflictMsg1); - auto verifyJob = openpgp()->verifyOpaqueJob(true); - QByteArray verified; - auto result = verifyJob->exec(signedData, verified); - delete verifyJob; - - QVERIFY(!result.isNull()); - QVERIFY(!result.error()); - - QVERIFY(result.numSignatures() == 1); - auto sig = result.signatures()[0]; - QVERIFY(sig.validity() == Signature::Marginal); - - auto stats = sig.key().userID(0).tofuInfo(); - QVERIFY(!stats.isNull()); - QVERIFY(!strcmp(sig.key().primaryFingerprint(), sig.fingerprint())); - QVERIFY(stats.signFirst() == stats.signLast()); - QVERIFY(stats.signCount() == 1); - QVERIFY(stats.policy() == TofuInfo::PolicyAuto); - QVERIFY(stats.validity() == TofuInfo::LittleHistory); - - // Import key 2 - importjob = openpgp()->importJob(); - connect(importjob, &ImportJob::result, this, - [this](ImportResult result, QString, Error) - { - QVERIFY(!result.error()); - QVERIFY(!result.imports().empty()); - QVERIFY(result.numImported()); - Q_EMIT asyncDone(); - }); - importjob->start(QByteArray(conflictKey2)); - QSignalSpy spy2 (this, SIGNAL(asyncDone())); - QVERIFY(spy2.wait()); - - // Verify Message 2 - const QByteArray signedData2(conflictMsg2); - QByteArray verified2; - verifyJob = openpgp()->verifyOpaqueJob(true); - result = verifyJob->exec(signedData2, verified2); - delete verifyJob; - - QVERIFY(!result.isNull()); - QVERIFY(!result.error()); - - QVERIFY(result.numSignatures() == 1); - sig = result.signatures()[0]; - QVERIFY(sig.validity() == Signature::Unknown); - // TODO activate when implemented - // QVERIFY(sig.summary() == Signature::TofuConflict); - - stats = sig.key().userID(0).tofuInfo(); - QVERIFY(!stats.isNull()); - QVERIFY(!strcmp(sig.key().primaryFingerprint(), sig.fingerprint())); - QVERIFY(stats.signFirst() == stats.signLast()); - QVERIFY(stats.signCount() == 1); - QVERIFY(stats.policy() == TofuInfo::PolicyAsk); - QVERIFY(stats.validity() == TofuInfo::Conflict); - } - - - void initTestCase() - { - QGpgMETest::initTestCase(); - const QString gpgHome = qgetenv("GNUPGHOME"); - qputenv("GNUPGHOME", mDir.path().toUtf8()); - QVERIFY(mDir.isValid()); - QFile conf(mDir.path() + QStringLiteral("/gpg.conf")); - QVERIFY(conf.open(QIODevice::WriteOnly)); - conf.write("trust-model tofu+pgp"); - conf.close(); - QFile agentConf(mDir.path() + QStringLiteral("/gpg-agent.conf")); - QVERIFY(agentConf.open(QIODevice::WriteOnly)); - agentConf.write("allow-loopback-pinentry"); - agentConf.close(); - QVERIFY(copyKeyrings(gpgHome, mDir.path())); - } -private: - QTemporaryDir mDir; - -}; - -QTEST_MAIN(TofuInfoTest) - -#include "t-tofuinfo.moc" diff --git a/lang/qt/tests/t-trustsignatures.cpp b/lang/qt/tests/t-trustsignatures.cpp deleted file mode 100644 index 6d575dff..00000000 --- a/lang/qt/tests/t-trustsignatures.cpp +++ /dev/null @@ -1,524 +0,0 @@ -/* t-trustsignatures.cpp - - This file is part of qgpgme, the Qt API binding for gpgme - Copyright (c) 2021 g10 Code GmbH - Software engineering by Ingo Klöcker <[email protected]> - - QGpgME is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - QGpgME is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - - In addition, as a special exception, the copyright holders give - permission to link the code of this program with any edition of - the Qt library by Trolltech AS, Norway (or with modified versions - of Qt that use the same license as Qt), and distribute linked - combinations including the two. You must obey the GNU General - Public License in all respects for all of the code used other than - Qt. If you modify this file, you may extend this exception to - your version of the file, but you are not obligated to do so. If - you do not wish to do so, delete this exception statement from - your version. -*/ - -#ifdef HAVE_CONFIG_H - #include "config.h" -#endif - -#include "t-support.h" - -#include <gpgme++/context.h> -#include <gpgme++/engineinfo.h> -#include "protocol.h" -#include "signkeyjob.h" -#include "util.h" - -#include <QRegularExpression> -#include <QSignalSpy> -#include <QTemporaryDir> -#include <QTest> - -using namespace QGpgME; -using namespace GpgME; - -class TestTrustSignatures: public QGpgMETest -{ - Q_OBJECT - -private Q_SLOTS: - void test_tsign_single_uid_key_and_then_tsign_it_again() - { - Error err; - - if (!loopbackSupported()) { - return; - } - - auto ctx = Context::create(OpenPGP); - QVERIFY(ctx); - - // Get the signing key ([email protected]) - auto seckey = ctx->key("A0FF4590BB6122EDEF6E3C542D727CC768697734", err, true); - QVERIFY(!err); - QVERIFY(!seckey.isNull()); - - // Get the target key ([email protected]) - auto target = ctx->key("E8143C489C8D41124DC40D0B47AF4B6961F04784", err, false); - QVERIFY(!err); - QVERIFY(!target.isNull()); - QVERIFY(target.numUserIDs() > 0); - - // Create first trust signature - { - // Create the job - auto job = std::unique_ptr<SignKeyJob>{openpgp()->signKeyJob()}; - QVERIFY(job); - hookUpPassphraseProvider(job.get()); - - // Set up the job - job->setExportable(true); - job->setSigningKey(seckey); - job->setTrustSignature(TrustSignatureTrust::Complete, 1, QStringLiteral("example.org")); - - connect(job.get(), &SignKeyJob::result, - this, [this] (const GpgME::Error &err2, const QString &, const GpgME::Error &) { - Q_EMIT asyncDone(); - if (err2) { - if (err2.code() == GPG_ERR_GENERAL) { - QFAIL(qPrintable(QString("The SignKeyJob failed with '%1'.\n" - "Hint: Run with GPGMEPP_INTERACTOR_DEBUG=stderr to debug the edit interaction.").arg(errorAsString(err2)))); - } else { - QFAIL(qPrintable(QString("The SignKeyJob failed with '%1'.").arg(errorAsString(err2)))); - } - } - }); - - job->start(target); - QSignalSpy spy (this, SIGNAL(asyncDone())); - QVERIFY(spy.wait(QSIGNALSPY_TIMEOUT)); - - // At this point the trust signature should have been added. - target.update(); - const auto trustSignature = target.userID(0).signature(target.userID(0).numSignatures() - 1); - QVERIFY(trustSignature.isTrustSignature()); - QCOMPARE(trustSignature.trustDepth(), 1u); - QCOMPARE(trustSignature.trustValue(), TrustSignatureTrust::Complete); - QVERIFY(trustSignature.trustScope()); - const auto trustScope = QString::fromUtf8(trustSignature.trustScope()); - QVERIFY(!trustScope.isEmpty()); - const QRegularExpression regex{trustScope}; - QVERIFY(regex.isValid()); - QVERIFY(regex.match(QStringLiteral("Foo <[email protected]>")).hasMatch()); - } - - // Create second trust signature - { - // Create the job - auto job = std::unique_ptr<SignKeyJob>{openpgp()->signKeyJob()}; - QVERIFY(job); - hookUpPassphraseProvider(job.get()); - - // Set up the job - job->setExportable(true); - job->setSigningKey(seckey); - job->setDupeOk(true); - job->setTrustSignature(TrustSignatureTrust::Partial, 2, QStringLiteral("example.net")); - - connect(job.get(), &SignKeyJob::result, - this, [this] (const GpgME::Error &err2, const QString &, const GpgME::Error &) { - Q_EMIT asyncDone(); - if (err2) { - if (err2.code() == GPG_ERR_GENERAL) { - QFAIL(qPrintable(QString("The SignKeyJob failed with '%1'.\n" - "Hint: Run with GPGMEPP_INTERACTOR_DEBUG=stderr to debug the edit interaction.").arg(errorAsString(err2)))); - } else { - QFAIL(qPrintable(QString("The SignKeyJob failed with '%1'.").arg(errorAsString(err2)))); - } - } - }); - - err = job->start(target); - QVERIFY(!err); - QSignalSpy spy (this, SIGNAL(asyncDone())); - QVERIFY(spy.wait(QSIGNALSPY_TIMEOUT)); - - // At this point the trust signature should have been added. - target.update(); - const auto trustSignature = target.userID(0).signature(target.userID(0).numSignatures() - 1); - QVERIFY(trustSignature.isTrustSignature()); - QCOMPARE(trustSignature.trustDepth(), 2u); - QCOMPARE(trustSignature.trustValue(), TrustSignatureTrust::Partial); - QVERIFY(trustSignature.trustScope()); - const auto trustScope = QString::fromUtf8(trustSignature.trustScope()); - QVERIFY(!trustScope.isEmpty()); - const QRegularExpression regex{trustScope}; - QVERIFY(regex.isValid()); - QVERIFY(regex.match(QStringLiteral("Foo <[email protected]>")).hasMatch()); - } - } - - void test_tsign_multi_uid_key_and_then_tsign_it_again() - { - Error err; - - if (!loopbackSupported()) { - return; - } - - auto ctx = Context::create(OpenPGP); - QVERIFY(ctx); - - // Get the signing key ([email protected]) - auto seckey = ctx->key("A0FF4590BB6122EDEF6E3C542D727CC768697734", err, true); - QVERIFY(!err); - QVERIFY(!seckey.isNull()); - - // Get the target key (Bob / Bravo Test) - auto target = ctx->key("D695676BDCEDCC2CDD6152BCFE180B1DA9E3B0B2", err, false); - QVERIFY(!err); - QVERIFY(!target.isNull()); - QVERIFY(target.numUserIDs() > 0); - - // Create first trust signature - { - // Create the job - auto job = openpgp()->signKeyJob();//std::unique_ptr<SignKeyJob>{openpgp()->signKeyJob()}; - QVERIFY(job); - hookUpPassphraseProvider(job); - - // Set up the job - job->setExportable(true); - job->setSigningKey(seckey); - job->setTrustSignature(TrustSignatureTrust::Complete, 1, QStringLiteral("example.org")); - - connect(job, &SignKeyJob::result, - this, [this] (const GpgME::Error &err2, const QString &, const GpgME::Error &) { - Q_EMIT asyncDone(); - if (err2) { - if (err2.code() == GPG_ERR_GENERAL) { - QFAIL(qPrintable(QString("The SignKeyJob failed with '%1'.\n" - "Hint: Run with GPGMEPP_INTERACTOR_DEBUG=stderr to debug the edit interaction.").arg(errorAsString(err2)))); - } else { - QFAIL(qPrintable(QString("The SignKeyJob failed with '%1'.").arg(errorAsString(err2)))); - } - } - }); - - job->start(target); - QSignalSpy spy (this, SIGNAL(asyncDone())); - QVERIFY(spy.wait(QSIGNALSPY_TIMEOUT)); - - // At this point the trust signature should have been added. - target.update(); - const auto trustSignature = target.userID(0).signature(target.userID(0).numSignatures() - 1); - QVERIFY(trustSignature.isTrustSignature()); - QCOMPARE(trustSignature.trustDepth(), 1u); - QCOMPARE(trustSignature.trustValue(), TrustSignatureTrust::Complete); - QVERIFY(trustSignature.trustScope()); - const auto trustScope = QString::fromUtf8(trustSignature.trustScope()); - QVERIFY(!trustScope.isEmpty()); - const QRegularExpression regex{trustScope}; - QVERIFY(regex.isValid()); - QVERIFY(regex.match(QStringLiteral("Foo <[email protected]>")).hasMatch()); - } - - // Create second trust signature - { - // Create the job - auto job = openpgp()->signKeyJob();//std::unique_ptr<SignKeyJob>{openpgp()->signKeyJob()}; - QVERIFY(job); - hookUpPassphraseProvider(job); - - // Set up the job - job->setExportable(true); - job->setSigningKey(seckey); - job->setDupeOk(true); - job->setTrustSignature(TrustSignatureTrust::Partial, 2, QStringLiteral("example.net")); - - connect(job, &SignKeyJob::result, - this, [this] (const GpgME::Error &err2, const QString &, const GpgME::Error &) { - Q_EMIT asyncDone(); - if (err2) { - if (err2.code() == GPG_ERR_GENERAL) { - QFAIL(qPrintable(QString("The SignKeyJob failed with '%1'.\n" - "Hint: Run with GPGMEPP_INTERACTOR_DEBUG=stderr to debug the edit interaction.").arg(errorAsString(err2)))); - } else { - QFAIL(qPrintable(QString("The SignKeyJob failed with '%1'.").arg(errorAsString(err2)))); - } - } - }); - - err = job->start(target); - QVERIFY(!err); - QSignalSpy spy (this, SIGNAL(asyncDone())); - QVERIFY(spy.wait(QSIGNALSPY_TIMEOUT)); - - // At this point the trust signature should have been added. - target.update(); - const auto trustSignature = target.userID(0).signature(target.userID(0).numSignatures() - 1); - QVERIFY(trustSignature.isTrustSignature()); - QCOMPARE(trustSignature.trustDepth(), 2u); - QCOMPARE(trustSignature.trustValue(), TrustSignatureTrust::Partial); - QVERIFY(trustSignature.trustScope()); - const auto trustScope = QString::fromUtf8(trustSignature.trustScope()); - QVERIFY(!trustScope.isEmpty()); - const QRegularExpression regex{trustScope}; - QVERIFY(regex.isValid()); - QVERIFY(regex.match(QStringLiteral("Foo <[email protected]>")).hasMatch()); - } - } - - void test_tsign_first_uid_and_then_tsign_both_uids() - { - Error err; - - if (!loopbackSupported()) { - return; - } - - auto ctx = Context::create(OpenPGP); - QVERIFY(ctx); - - // Get the signing key ([email protected]) - auto seckey = ctx->key("A0FF4590BB6122EDEF6E3C542D727CC768697734", err, true); - QVERIFY(!err); - QVERIFY(!seckey.isNull()); - - // Get the target key (Mallory / Mike Test) - auto target = ctx->key("2686AA191A278013992C72EBBE794852BE5CF886", err, false); - QVERIFY(!err); - QVERIFY(!target.isNull()); - QVERIFY(target.numUserIDs() > 0); - - // Create first trust signature - { - // Create the job - auto job = openpgp()->signKeyJob();//std::unique_ptr<SignKeyJob>{openpgp()->signKeyJob()}; - QVERIFY(job); - hookUpPassphraseProvider(job); - - // Set up the job - job->setExportable(true); - job->setSigningKey(seckey); - job->setUserIDsToSign({0}); - job->setTrustSignature(TrustSignatureTrust::Complete, 1, QStringLiteral("example.org")); - - connect(job, &SignKeyJob::result, - this, [this] (const GpgME::Error &err2, const QString &, const GpgME::Error &) { - Q_EMIT asyncDone(); - if (err2) { - if (err2.code() == GPG_ERR_GENERAL) { - QFAIL(qPrintable(QString("The SignKeyJob failed with '%1'.\n" - "Hint: Run with GPGMEPP_INTERACTOR_DEBUG=stderr to debug the edit interaction.").arg(errorAsString(err2)))); - } else { - QFAIL(qPrintable(QString("The SignKeyJob failed with '%1'.").arg(errorAsString(err2)))); - } - } - }); - - job->start(target); - QSignalSpy spy (this, SIGNAL(asyncDone())); - QVERIFY(spy.wait(QSIGNALSPY_TIMEOUT)); - - // At this point the trust signature should have been added. - target.update(); - const auto trustSignature = target.userID(0).signature(target.userID(0).numSignatures() - 1); - QVERIFY(trustSignature.isTrustSignature()); - QCOMPARE(trustSignature.trustDepth(), 1u); - QCOMPARE(trustSignature.trustValue(), TrustSignatureTrust::Complete); - QVERIFY(trustSignature.trustScope()); - const auto trustScope = QString::fromUtf8(trustSignature.trustScope()); - QVERIFY(!trustScope.isEmpty()); - const QRegularExpression regex{trustScope}; - QVERIFY(regex.isValid()); - QVERIFY(regex.match(QStringLiteral("Foo <[email protected]>")).hasMatch()); - } - - // Create second trust signature - { - // Create the job - auto job = openpgp()->signKeyJob();//std::unique_ptr<SignKeyJob>{openpgp()->signKeyJob()}; - QVERIFY(job); - hookUpPassphraseProvider(job); - - // Set up the job - job->setExportable(true); - job->setSigningKey(seckey); - job->setDupeOk(true); - job->setTrustSignature(TrustSignatureTrust::Partial, 2, QStringLiteral("example.net")); - - connect(job, &SignKeyJob::result, - this, [this] (const GpgME::Error &err2, const QString &, const GpgME::Error &) { - Q_EMIT asyncDone(); - if (err2) { - if (err2.code() == GPG_ERR_GENERAL) { - QFAIL(qPrintable(QString("The SignKeyJob failed with '%1'.\n" - "Hint: Run with GPGMEPP_INTERACTOR_DEBUG=stderr to debug the edit interaction.").arg(errorAsString(err2)))); - } else { - QFAIL(qPrintable(QString("The SignKeyJob failed with '%1'.").arg(errorAsString(err2)))); - } - } - }); - - err = job->start(target); - QVERIFY(!err); - QSignalSpy spy (this, SIGNAL(asyncDone())); - QVERIFY(spy.wait(QSIGNALSPY_TIMEOUT)); - - // At this point the trust signature should have been added. - target.update(); - const auto trustSignature = target.userID(0).signature(target.userID(0).numSignatures() - 1); - QVERIFY(trustSignature.isTrustSignature()); - QCOMPARE(trustSignature.trustDepth(), 2u); - QCOMPARE(trustSignature.trustValue(), TrustSignatureTrust::Partial); - QVERIFY(trustSignature.trustScope()); - const auto trustScope = QString::fromUtf8(trustSignature.trustScope()); - QVERIFY(!trustScope.isEmpty()); - const QRegularExpression regex{trustScope}; - QVERIFY(regex.isValid()); - QVERIFY(regex.match(QStringLiteral("Foo <[email protected]>")).hasMatch()); - } - } - - void test_tsign_all_uids_and_then_tsign_first_uid() - { - Error err; - - if (!loopbackSupported()) { - return; - } - - auto ctx = Context::create(OpenPGP); - QVERIFY(ctx); - - // Get the signing key ([email protected]) - auto seckey = ctx->key("A0FF4590BB6122EDEF6E3C542D727CC768697734", err, true); - QVERIFY(!err); - QVERIFY(!seckey.isNull()); - - // Get the target key (Echelon / Echo Test / Eve) - auto target = ctx->key("3531152DE293E26A07F504BC318C1FAEFAEF6D1B", err, false); - QVERIFY(!err); - QVERIFY(!target.isNull()); - QVERIFY(target.numUserIDs() > 0); - - // Create first trust signature - { - // Create the job - auto job = openpgp()->signKeyJob();//std::unique_ptr<SignKeyJob>{openpgp()->signKeyJob()}; - QVERIFY(job); - hookUpPassphraseProvider(job); - - // Set up the job - job->setExportable(true); - job->setSigningKey(seckey); - job->setTrustSignature(TrustSignatureTrust::Complete, 1, QStringLiteral("example.org")); - - connect(job, &SignKeyJob::result, - this, [this] (const GpgME::Error &err2, const QString &, const GpgME::Error &) { - Q_EMIT asyncDone(); - if (err2) { - if (err2.code() == GPG_ERR_GENERAL) { - QFAIL(qPrintable(QString("The SignKeyJob failed with '%1'.\n" - "Hint: Run with GPGMEPP_INTERACTOR_DEBUG=stderr to debug the edit interaction.").arg(errorAsString(err2)))); - } else { - QFAIL(qPrintable(QString("The SignKeyJob failed with '%1'.").arg(errorAsString(err2)))); - } - } - }); - - job->start(target); - QSignalSpy spy (this, SIGNAL(asyncDone())); - QVERIFY(spy.wait(QSIGNALSPY_TIMEOUT)); - - // At this point the trust signature should have been added. - target.update(); - const auto trustSignature = target.userID(0).signature(target.userID(0).numSignatures() - 1); - QVERIFY(trustSignature.isTrustSignature()); - QCOMPARE(trustSignature.trustDepth(), 1u); - QCOMPARE(trustSignature.trustValue(), TrustSignatureTrust::Complete); - QVERIFY(trustSignature.trustScope()); - const auto trustScope = QString::fromUtf8(trustSignature.trustScope()); - QVERIFY(!trustScope.isEmpty()); - const QRegularExpression regex{trustScope}; - QVERIFY(regex.isValid()); - QVERIFY(regex.match(QStringLiteral("Foo <[email protected]>")).hasMatch()); - } - - // Create second trust signature - { - // Create the job - auto job = openpgp()->signKeyJob();//std::unique_ptr<SignKeyJob>{openpgp()->signKeyJob()}; - QVERIFY(job); - hookUpPassphraseProvider(job); - - // Set up the job - job->setExportable(true); - job->setSigningKey(seckey); - job->setUserIDsToSign({0}); - job->setDupeOk(true); - job->setTrustSignature(TrustSignatureTrust::Partial, 2, QStringLiteral("example.net")); - - connect(job, &SignKeyJob::result, - this, [this] (const GpgME::Error &err2, const QString &, const GpgME::Error &) { - Q_EMIT asyncDone(); - if (err2) { - if (err2.code() == GPG_ERR_GENERAL) { - QFAIL(qPrintable(QString("The SignKeyJob failed with '%1'.\n" - "Hint: Run with GPGMEPP_INTERACTOR_DEBUG=stderr to debug the edit interaction.").arg(errorAsString(err2)))); - } else { - QFAIL(qPrintable(QString("The SignKeyJob failed with '%1'.").arg(errorAsString(err2)))); - } - } - }); - - err = job->start(target); - QVERIFY(!err); - QSignalSpy spy (this, SIGNAL(asyncDone())); - QVERIFY(spy.wait(QSIGNALSPY_TIMEOUT)); - - // At this point the trust signature should have been added. - target.update(); - const auto trustSignature = target.userID(0).signature(target.userID(0).numSignatures() - 1); - QVERIFY(trustSignature.isTrustSignature()); - QCOMPARE(trustSignature.trustDepth(), 2u); - QCOMPARE(trustSignature.trustValue(), TrustSignatureTrust::Partial); - QVERIFY(trustSignature.trustScope()); - const auto trustScope = QString::fromUtf8(trustSignature.trustScope()); - QVERIFY(!trustScope.isEmpty()); - const QRegularExpression regex{trustScope}; - QVERIFY(regex.isValid()); - QVERIFY(regex.match(QStringLiteral("Foo <[email protected]>")).hasMatch()); - } - } - - void initTestCase() - { - QGpgMETest::initTestCase(); - const QString gpgHome = qgetenv("GNUPGHOME"); - QVERIFY(copyKeyrings(gpgHome, mDir.path())); - qputenv("GNUPGHOME", mDir.path().toUtf8()); - QFile conf(mDir.path() + QStringLiteral("/gpg.conf")); - QVERIFY(conf.open(QIODevice::WriteOnly)); - if (GpgME::engineInfo(GpgME::GpgEngine).engineVersion() >= "2.2.18") { - conf.write("allow-weak-key-signatures"); - } - conf.close(); - } - -private: - QTemporaryDir mDir; -}; - -QTEST_MAIN(TestTrustSignatures) - -#include "t-trustsignatures.moc" diff --git a/lang/qt/tests/t-various.cpp b/lang/qt/tests/t-various.cpp deleted file mode 100644 index 282fffc2..00000000 --- a/lang/qt/tests/t-various.cpp +++ /dev/null @@ -1,418 +0,0 @@ -/* t-various.cpp - - This file is part of qgpgme, the Qt API binding for gpgme - Copyright (c) 2017 by Bundesamt für Sicherheit in der Informationstechnik - Software engineering by Intevation GmbH - - QGpgME is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - QGpgME is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - - In addition, as a special exception, the copyright holders give - permission to link the code of this program with any edition of - the Qt library by Trolltech AS, Norway (or with modified versions - of Qt that use the same license as Qt), and distribute linked - combinations including the two. You must obey the GNU General - Public License in all respects for all of the code used other than - Qt. If you modify this file, you may extend this exception to - your version of the file, but you are not obligated to do so. If - you do not wish to do so, delete this exception statement from - your version. -*/ - -#ifdef HAVE_CONFIG_H - #include "config.h" -#endif - -#include <QDebug> -#include <QTest> -#include <QSignalSpy> -#include <QTemporaryDir> -#include "keylistjob.h" -#include "protocol.h" -#include "util.h" -#include <gpgme++/keylistresult.h> -#include <gpgme++/context.h> -#include <gpgme++/engineinfo.h> -#include "dn.h" -#include <gpgme++/data.h> -#include "dataprovider.h" -#include "signkeyjob.h" - -#include "t-support.h" - -using namespace QGpgME; -using namespace GpgME; - -static const char aKey[] = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" -"\n" -"mDMEWG+w/hYJKwYBBAHaRw8BAQdAiq1oStvDYg8ZfFs5DgisYJo8dJxD+C/AA21O\n" -"K/aif0O0GXRvZnVfY29uZmxpY3RAZXhhbXBsZS5jb22IlgQTFggAPhYhBHoJBLaV\n" -"DamYAgoa1L5BwMOl/x88BQJYb7D+AhsDBQkDwmcABQsJCAcCBhUICQoLAgQWAgMB\n" -"Ah4BAheAAAoJEL5BwMOl/x88GvwA/0SxkbLyAcshGm2PRrPsFQsSVAfwaSYFVmS2\n" -"cMVIw1PfAQDclRH1Z4MpufK07ju4qI33o4s0UFpVRBuSxt7A4P2ZD7g4BFhvsP4S\n" -"CisGAQQBl1UBBQEBB0AmVrgaDNJ7K2BSalsRo2EkRJjHGqnp5bBB0tapnF81CQMB\n" -"CAeIeAQYFggAIBYhBHoJBLaVDamYAgoa1L5BwMOl/x88BQJYb7D+AhsMAAoJEL5B\n" -"wMOl/x88OR0BAMq4/vmJUORRTmzjHcv/DDrQB030DSq666rlckGIKTShAPoDXM9N\n" -"0gZK+YzvrinSKZXHmn0aSwmC1/hyPybJPEljBw==\n" -"=p2Oj\n" -"-----END PGP PUBLIC KEY BLOCK-----\n"; - -class TestVarious: public QGpgMETest -{ - Q_OBJECT - -private Q_SLOTS: - void testDN() - { - DN dn(QStringLiteral("CN=Before\\0DAfter,OU=Test,DC=North America,DC=Fabrikam,DC=COM")); - QVERIFY(dn.dn() == QStringLiteral("CN=Before\rAfter,OU=Test,DC=North America,DC=Fabrikam,DC=COM")); - QStringList attrOrder; - attrOrder << QStringLiteral("DC") << QStringLiteral("OU") << QStringLiteral("CN"); - dn.setAttributeOrder(attrOrder); - QVERIFY(dn.prettyDN() == QStringLiteral("DC=North America,DC=Fabrikam,DC=COM,OU=Test,CN=Before\rAfter")); - } - - void testKeyFromFile() - { - if (GpgME::engineInfo(GpgME::GpgEngine).engineVersion() < "2.1.14") { - return; - } - QGpgME::QByteArrayDataProvider dp(aKey); - Data data(&dp); - const auto keys = data.toKeys(); - QVERIFY(keys.size() == 1); - const auto key = keys[0]; - QVERIFY(!key.isNull()); - QVERIFY(key.primaryFingerprint() == QStringLiteral("7A0904B6950DA998020A1AD4BE41C0C3A5FF1F3C")); - } - - void testDataRewind() - { - if (GpgME::engineInfo(GpgME::GpgEngine).engineVersion() < "2.1.14") { - return; - } - QGpgME::QByteArrayDataProvider dp(aKey); - Data data(&dp); - char buf[20]; - data.read(buf, 20); - - auto keys = data.toKeys(); - QVERIFY(keys.size() == 0); - - data.rewind(); - - keys = data.toKeys(); - QVERIFY(keys.size() == 1); - } - - void testQuickUid() - { - if (GpgME::engineInfo(GpgME::GpgEngine).engineVersion() < "2.1.13") { - return; - } - KeyListJob *job = openpgp()->keyListJob(false, true, true); - std::vector<GpgME::Key> keys; - GpgME::KeyListResult result = job->exec(QStringList() << QStringLiteral("[email protected]"), - false, keys); - delete job; - QVERIFY (!result.error()); - QVERIFY (keys.size() == 1); - Key key = keys.front(); - - QVERIFY (key.numUserIDs() == 3); - const char uid[] = "Foo Bar (with comment) <[email protected]>"; - - auto ctx = Context::createForProtocol(key.protocol()); - QVERIFY (ctx); - hookUpPassphraseProvider(ctx); - - QVERIFY(!ctx->addUid(key, uid)); - delete ctx; - key.update(); - - QVERIFY (key.numUserIDs() == 4); - bool id_found = false;; - for (const auto &u: key.userIDs()) { - if (!strcmp (u.id(), uid)) { - QVERIFY (!u.isRevoked()); - id_found = true; - break; - } - } - QVERIFY (id_found); - - ctx = Context::createForProtocol(key.protocol()); - QVERIFY (!ctx->revUid(key, uid)); - delete ctx; - key.update(); - - bool id_revoked = false;; - for (const auto &u: key.userIDs()) { - if (!strcmp (u.id(), uid)) { - id_revoked = true; - break; - } - } - QVERIFY(id_revoked); - } - - void testSetExpire() - { - if (GpgME::engineInfo(GpgME::GpgEngine).engineVersion() < "2.1.22") { - return; - } - KeyListJob *job = openpgp()->keyListJob(false, true, true); - std::vector<GpgME::Key> keys; - GpgME::KeyListResult result = job->exec(QStringList() << QStringLiteral("[email protected]"), - false, keys); - delete job; - QVERIFY (!result.error()); - QVERIFY (keys.size() == 1); - Key key = keys.front(); - - QVERIFY (key.subkey(0).expirationTime() == time_t(0)); - QVERIFY (key.subkey(1).expirationTime() == time_t(0)); - - auto ctx = Context::createForProtocol(key.protocol()); - QVERIFY (ctx); - hookUpPassphraseProvider(ctx); - - // change expiration of the main key - QVERIFY(!ctx->setExpire(key, 1000)); - delete ctx; - key.update(); - - QVERIFY (key.subkey(0).expirationTime() != time_t(0)); - QVERIFY (key.subkey(1).expirationTime() == time_t(0)); - time_t keyExpiration = key.subkey(0).expirationTime(); - - // change expiration of all subkeys - ctx = Context::createForProtocol(key.protocol()); - QVERIFY(!ctx->setExpire(key, 2000, std::vector<Subkey>(), Context::SetExpireAllSubkeys)); - delete ctx; - key.update(); - - QVERIFY (key.subkey(0).expirationTime() == keyExpiration); - QVERIFY (key.subkey(1).expirationTime() != time_t(0)); - time_t subkeyExpiration = key.subkey(1).expirationTime(); - - // change expiration of specific subkey(s) - ctx = Context::createForProtocol(key.protocol()); - std::vector<Subkey> specificSubkeys; - specificSubkeys.push_back(key.subkey(1)); - QVERIFY(!ctx->setExpire(key, 3000, specificSubkeys)); - delete ctx; - key.update(); - - QVERIFY (key.subkey(0).expirationTime() == keyExpiration); - QVERIFY (key.subkey(1).expirationTime() != subkeyExpiration); - - // test error handling: calling setExpire() with the primary key as - // subkey should fail with "subkey <primary key fpr> not found" - ctx = Context::createForProtocol(key.protocol()); - std::vector<Subkey> primaryKey; - primaryKey.push_back(key.subkey(0)); - const auto err = ctx->setExpire(key, 3000, primaryKey); - QCOMPARE(err.code(), static_cast<int>(GPG_ERR_NOT_FOUND)); - delete ctx; - } - - void testSignKeyWithoutExpiration() - { - Error err; - - if (!loopbackSupported()) { - return; - } - - auto ctx = Context::create(OpenPGP); - QVERIFY(ctx); - - // Get the signing key ([email protected]) - auto seckey = ctx->key("A0FF4590BB6122EDEF6E3C542D727CC768697734", err, true); - QVERIFY(!err); - QVERIFY(!seckey.isNull()); - - // Get the target key (Bob / Bravo Test) - auto target = ctx->key("D695676BDCEDCC2CDD6152BCFE180B1DA9E3B0B2", err, false); - QVERIFY(!err); - QVERIFY(!target.isNull()); - QVERIFY(target.numUserIDs() > 0); - - // Create the job - auto job = std::unique_ptr<SignKeyJob>{openpgp()->signKeyJob()}; - QVERIFY(job); - hookUpPassphraseProvider(job.get()); - - // Set up the job - job->setExportable(true); - job->setSigningKey(seckey); - job->setDupeOk(true); - - connect(job.get(), &SignKeyJob::result, - this, [this] (const GpgME::Error &err2, const QString &, const GpgME::Error &) { - Q_EMIT asyncDone(); - if (err2) { - if (err2.code() == GPG_ERR_GENERAL) { - QFAIL(qPrintable(QString("The SignKeyJob failed with '%1'.\n" - "Hint: Run with GPGMEPP_INTERACTOR_DEBUG=stderr to debug the edit interaction.").arg(errorAsString(err2)))); - } else { - QFAIL(qPrintable(QString("The SignKeyJob failed with '%1'.").arg(errorAsString(err2)))); - } - } - }); - - job->start(target); - QSignalSpy spy{this, &TestVarious::asyncDone}; - QVERIFY(spy.wait(QSIGNALSPY_TIMEOUT)); - - // At this point the signature should have been added. - target.update(); - const auto keySignature = target.userID(0).signature(target.userID(0).numSignatures() - 1); - QVERIFY(keySignature.neverExpires()); - } - - void testSignKeyWithExpiration() - { - Error err; - - if (!loopbackSupported()) { - return; - } - - auto ctx = Context::create(OpenPGP); - QVERIFY(ctx); - - // Get the signing key ([email protected]) - auto seckey = ctx->key("A0FF4590BB6122EDEF6E3C542D727CC768697734", err, true); - QVERIFY(!err); - QVERIFY(!seckey.isNull()); - - // Get the target key (Bob / Bravo Test) - auto target = ctx->key("D695676BDCEDCC2CDD6152BCFE180B1DA9E3B0B2", err, false); - QVERIFY(!err); - QVERIFY(!target.isNull()); - QVERIFY(target.numUserIDs() > 0); - - // Create the job - auto job = std::unique_ptr<SignKeyJob>{openpgp()->signKeyJob()}; - QVERIFY(job); - hookUpPassphraseProvider(job.get()); - - // Set up the job - job->setExportable(true); - job->setSigningKey(seckey); - job->setDupeOk(true); - job->setExpirationDate(QDate{2222, 2, 22}); - - connect(job.get(), &SignKeyJob::result, - this, [this] (const GpgME::Error &err2, const QString &, const GpgME::Error &) { - Q_EMIT asyncDone(); - if (err2) { - if (err2.code() == GPG_ERR_GENERAL) { - QFAIL(qPrintable(QString("The SignKeyJob failed with '%1'.\n" - "Hint: Run with GPGMEPP_INTERACTOR_DEBUG=stderr to debug the edit interaction.").arg(errorAsString(err2)))); - } else { - QFAIL(qPrintable(QString("The SignKeyJob failed with '%1'.").arg(errorAsString(err2)))); - } - } - }); - - job->start(target); - QSignalSpy spy{this, &TestVarious::asyncDone}; - QVERIFY(spy.wait(QSIGNALSPY_TIMEOUT)); - - // At this point the signature should have been added. - target.update(); - const auto keySignature = target.userID(0).signature(target.userID(0).numSignatures() - 1); - QVERIFY(!keySignature.neverExpires()); - const auto expirationDate = QDateTime::fromSecsSinceEpoch(uint_least32_t(keySignature.expirationTime())).date(); - // expiration date is capped at 2106-02-05; we also allow 2106-02-04 as expiration date because for locations that use DST - // the expiration date may be 2106-02-04-23:xx:xx (in local non-DST time) if the current time is 00:xx::xx (in local DST time) - const auto expectedExpirationRange = std::make_pair(QDate{2106, 2, 4}, QDate{2106, 2, 5}); - QVERIFY2(expirationDate >= expectedExpirationRange.first, - ("\n Actual : " + expirationDate.toString(Qt::ISODate).toLatin1() + - "\n Expected: " + expectedExpirationRange.first.toString(Qt::ISODate).toLatin1()).constData()); - QVERIFY2(expirationDate <= expectedExpirationRange.second, - ("\n Actual : " + expirationDate.toString(Qt::ISODate).toLatin1() + - "\n Expected: " + expectedExpirationRange.second.toString(Qt::ISODate).toLatin1()).constData()); - } - - void testVersion() - { - QVERIFY(EngineInfo::Version("2.1.0") < EngineInfo::Version("2.1.1")); - QVERIFY(EngineInfo::Version("2.1.10") < EngineInfo::Version("2.1.11")); - QVERIFY(EngineInfo::Version("2.2.0") > EngineInfo::Version("2.1.19")); - QVERIFY(EngineInfo::Version("1.0.0") < EngineInfo::Version("2.0.0")); - QVERIFY(EngineInfo::Version("0.1.0") < EngineInfo::Version("1.0.0")); - QVERIFY(!(EngineInfo::Version("2.0.0") < EngineInfo::Version("2.0.0"))); - QVERIFY(!(EngineInfo::Version("2.0.0") > EngineInfo::Version("2.0.0"))); - QVERIFY(EngineInfo::Version("3.0.0") > EngineInfo::Version("2.3.20")); - QVERIFY(EngineInfo::Version("3.0.1") > EngineInfo::Version("3.0.0")); - QVERIFY(EngineInfo::Version("3.1.0") > EngineInfo::Version("3.0.20")); - - QVERIFY(EngineInfo::Version("1.1.1") <= "2.0.0"); - QVERIFY(EngineInfo::Version("1.1.1") <= "1.2.0"); - QVERIFY(EngineInfo::Version("1.1.1") <= "1.1.2"); - QVERIFY(EngineInfo::Version("1.1.1") <= "1.1.1"); - QVERIFY(!(EngineInfo::Version("1.1.1") <= "1.1.0")); - QVERIFY(!(EngineInfo::Version("1.1.1") <= "1.0.9")); - QVERIFY(!(EngineInfo::Version("1.1.1") <= "0.9.9")); - - QVERIFY(!(EngineInfo::Version("1.1.1") == "2.0.0")); - QVERIFY(!(EngineInfo::Version("1.1.1") == "1.2.0")); - QVERIFY(!(EngineInfo::Version("1.1.1") == "1.1.2")); - QVERIFY(EngineInfo::Version("1.1.1") == "1.1.1"); - QVERIFY(!(EngineInfo::Version("1.1.1") == "1.1.0")); - QVERIFY(!(EngineInfo::Version("1.1.1") == "1.0.9")); - QVERIFY(!(EngineInfo::Version("1.1.1") == "0.9.9")); - - QVERIFY(EngineInfo::Version("1.1.1") != "2.0.0"); - QVERIFY(EngineInfo::Version("1.1.1") != "1.2.0"); - QVERIFY(EngineInfo::Version("1.1.1") != "1.1.2"); - QVERIFY(!(EngineInfo::Version("1.1.1") != "1.1.1")); - QVERIFY(EngineInfo::Version("1.1.1") != "1.1.0"); - QVERIFY(EngineInfo::Version("1.1.1") != "1.0.9"); - QVERIFY(EngineInfo::Version("1.1.1") != "0.9.9"); - - QVERIFY(!(EngineInfo::Version("1.1.1") >= "2.0.0")); - QVERIFY(!(EngineInfo::Version("1.1.1") >= "1.2.0")); - QVERIFY(!(EngineInfo::Version("1.1.1") >= "1.1.2")); - QVERIFY(EngineInfo::Version("1.1.1") >= "1.1.1"); - QVERIFY(EngineInfo::Version("1.1.1") >= "1.1.0"); - QVERIFY(EngineInfo::Version("1.1.1") >= "1.0.9"); - QVERIFY(EngineInfo::Version("1.1.1") >= "0.9.9"); - } - - void initTestCase() - { - QGpgMETest::initTestCase(); - const QString gpgHome = qgetenv("GNUPGHOME"); - QVERIFY(copyKeyrings(gpgHome, mDir.path())); - qputenv("GNUPGHOME", mDir.path().toUtf8()); - QFile conf(mDir.path() + QStringLiteral("/gpg.conf")); - QVERIFY(conf.open(QIODevice::WriteOnly)); - if (GpgME::engineInfo(GpgME::GpgEngine).engineVersion() >= "2.2.18") { - conf.write("allow-weak-key-signatures"); - } - conf.close(); - } - -private: - QTemporaryDir mDir; -}; - -QTEST_MAIN(TestVarious) - -#include "t-various.moc" diff --git a/lang/qt/tests/t-verify.cpp b/lang/qt/tests/t-verify.cpp deleted file mode 100644 index f1bba08f..00000000 --- a/lang/qt/tests/t-verify.cpp +++ /dev/null @@ -1,95 +0,0 @@ -/* t-verifiy.cpp - - This file is part of qgpgme, the Qt API binding for gpgme - Copyright (c) 2016 by Bundesamt für Sicherheit in der Informationstechnik - Software engineering by Intevation GmbH - - QGpgME is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - QGpgME is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - - In addition, as a special exception, the copyright holders give - permission to link the code of this program with any edition of - the Qt library by Trolltech AS, Norway (or with modified versions - of Qt that use the same license as Qt), and distribute linked - combinations including the two. You must obey the GNU General - Public License in all respects for all of the code used other than - Qt. If you modify this file, you may extend this exception to - your version of the file, but you are not obligated to do so. If - you do not wish to do so, delete this exception statement from - your version. -*/ -#ifdef HAVE_CONFIG_H - #include "config.h" -#endif - -#include <QDebug> -#include <QTest> - - -#include "protocol.h" - -#include "verifyopaquejob.h" -#include <gpgme++/verificationresult.h> -#include <gpgme++/key.h> - -#include "t-support.h" - -using namespace QGpgME; -using namespace GpgME; - -static const char testMsg1[] = -"-----BEGIN PGP MESSAGE-----\n" -"\n" -"owGbwMvMwCSoW1RzPCOz3IRxjXQSR0lqcYleSUWJTZOvjVdpcYmCu1+oQmaJIleH\n" -"GwuDIBMDGysTSIqBi1MApi+nlGGuwDeHao53HBr+FoVGP3xX+kvuu9fCMJvl6IOf\n" -"y1kvP4y+8D5a11ang0udywsA\n" -"=Crq6\n" -"-----END PGP MESSAGE-----\n"; - - -class VerifyTest: public QGpgMETest -{ - Q_OBJECT - -private Q_SLOTS: - - /* Check that a signature always has a key. */ - void testSignatureKey() - { - const QByteArray signedData(testMsg1); - auto verifyJob = openpgp()->verifyOpaqueJob(true); - QByteArray verified; - - auto result = verifyJob->exec(signedData, verified); - QVERIFY(!result.error()); - delete verifyJob; - - QVERIFY(result.numSignatures() == 1); - auto sig = result.signatures()[0]; - - const auto key = sig.key(true, false); - QVERIFY(!key.isNull()); - - bool found = false; - for (const auto &subkey: key.subkeys()) { - if (!strcmp (subkey.fingerprint(), sig.fingerprint())) { - found = true; - } - } - QVERIFY(found); - } -}; - -QTEST_MAIN(VerifyTest) -#include "t-verify.moc" diff --git a/lang/qt/tests/t-wkdlookup.cpp b/lang/qt/tests/t-wkdlookup.cpp deleted file mode 100644 index 03b7823a..00000000 --- a/lang/qt/tests/t-wkdlookup.cpp +++ /dev/null @@ -1,155 +0,0 @@ -/* t-wkdlookup.cpp - - This file is part of qgpgme, the Qt API binding for gpgme - Copyright (c) 2021 g10 Code GmbH - Software engineering by Ingo Klöcker <[email protected]> - - QGpgME is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - QGpgME is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - - In addition, as a special exception, the copyright holders give - permission to link the code of this program with any edition of - the Qt library by Trolltech AS, Norway (or with modified versions - of Qt that use the same license as Qt), and distribute linked - combinations including the two. You must obey the GNU General - Public License in all respects for all of the code used other than - Qt. If you modify this file, you may extend this exception to - your version of the file, but you are not obligated to do so. If - you do not wish to do so, delete this exception statement from - your version. -*/ -#ifdef HAVE_CONFIG_H - #include "config.h" -#endif - -#include "t-support.h" - -#include <gpgme++/data.h> -#include <gpgme++/engineinfo.h> -#include "protocol.h" -#include "wkdlookupjob.h" -#include "wkdlookupresult.h" - -#include <QDebug> -#include <QSignalSpy> -#include <QTest> - -#include <algorithm> - -using namespace QGpgME; -using namespace GpgME; - -static const char *requiredVersion = "2.1.12"; - -namespace -{ -bool keyHasUserIDWithMatchingEmailAddress(const Key &key, const QString &expectedEmailAddress) -{ - const auto email = expectedEmailAddress.toLower(); - const auto userIds = key.userIDs(); - return std::any_of( - std::begin(userIds), std::end(userIds), - [email](const UserID &uid) { - return email == QString::fromUtf8(uid.email()).toLower(); - }); -} -} - -class WKDLookupTest : public QGpgMETest -{ - Q_OBJECT - -private Q_SLOTS: - - void testWKDLookupAsync() - { - if (GpgME::engineInfo(GpgME::GpgEngine).engineVersion() < requiredVersion) { - QSKIP("dirmngr does not yet support WKD lookup"); - } - if (!doOnlineTests()) { - QSKIP("Set DO_ONLINE_TESTS environment variable to run this test."); - } - const QString email = QLatin1String{"[email protected]"}; - - WKDLookupResult result; - auto *job = openpgp()->wkdLookupJob(); - connect(job, &WKDLookupJob::result, job, [this, &result](const WKDLookupResult &result_, const QString &, const Error &) - { - result = result_; - Q_EMIT asyncDone(); - }); - job->start(email); - QSignalSpy spy (this, SIGNAL(asyncDone())); - QVERIFY(spy.wait(QSIGNALSPY_TIMEOUT)); - - QVERIFY(result.error().code() == GPG_ERR_NO_ERROR); - QCOMPARE(result.pattern(), "[email protected]"); - QCOMPARE(result.source(), "https://openpgpkey.gnupg.org"); - const auto keys = result.keyData().toKeys(GpgME::OpenPGP); - QVERIFY(keys.size() == 1); - QVERIFY(keyHasUserIDWithMatchingEmailAddress(keys.front(), email)); - } - - void testWKDLookupSync() - { - if (GpgME::engineInfo(GpgME::GpgEngine).engineVersion() < requiredVersion) { - QSKIP("dirmngr does not yet support WKD lookup"); - } - if (!doOnlineTests()) { - QSKIP("Set DO_ONLINE_TESTS environment variable to run this test."); - } - const QString email = QLatin1String{"[email protected]"}; - - auto *job = openpgp()->wkdLookupJob(); - const auto result = job->exec(email); - - QVERIFY(result.error().code() == GPG_ERR_NO_ERROR); - QCOMPARE(result.pattern(), "[email protected]"); - QCOMPARE(result.source(), "https://openpgpkey.gnupg.org"); - const auto keys = result.keyData().toKeys(GpgME::OpenPGP); - QVERIFY(keys.size() == 1); - QVERIFY(keyHasUserIDWithMatchingEmailAddress(keys.front(), email)); - } - - void testLookupWithNoResultAsync() - { - if (GpgME::engineInfo(GpgME::GpgEngine).engineVersion() < requiredVersion) { - QSKIP("dirmngr does not yet support WKD lookup"); - } - if (!doOnlineTests()) { - QSKIP("Set DO_ONLINE_TESTS environment variable to run this test."); - } - const QString email = QLatin1String{"[email protected]"}; - - WKDLookupResult result; - auto *job = openpgp()->wkdLookupJob(); - connect(job, &WKDLookupJob::result, job, [this, &result](const WKDLookupResult &result_, const QString &, const Error &) - { - result = result_; - Q_EMIT asyncDone(); - }); - job->start(email); - QSignalSpy spy (this, SIGNAL(asyncDone())); - QVERIFY(spy.wait(QSIGNALSPY_TIMEOUT)); - - QVERIFY(result.error().code() == GPG_ERR_NO_ERROR); - QCOMPARE(result.pattern(), "[email protected]"); - QCOMPARE(result.source(), ""); - QVERIFY(result.keyData().isNull()); - } -}; - -QTEST_MAIN(WKDLookupTest) - -#include "t-wkdlookup.moc" diff --git a/lang/qt/tests/t-wkspublish.cpp b/lang/qt/tests/t-wkspublish.cpp deleted file mode 100644 index cb75d149..00000000 --- a/lang/qt/tests/t-wkspublish.cpp +++ /dev/null @@ -1,280 +0,0 @@ -/* t-wkspublish.cpp - - This file is part of qgpgme, the Qt API binding for gpgme - Copyright (c) 2016 by Bundesamt für Sicherheit in der Informationstechnik - Software engineering by Intevation GmbH - - QGpgME is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - QGpgME is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - - In addition, as a special exception, the copyright holders give - permission to link the code of this program with any edition of - the Qt library by Trolltech AS, Norway (or with modified versions - of Qt that use the same license as Qt), and distribute linked - combinations including the two. You must obey the GNU General - Public License in all respects for all of the code used other than - Qt. If you modify this file, you may extend this exception to - your version of the file, but you are not obligated to do so. If - you do not wish to do so, delete this exception statement from - your version. -*/ -#ifdef HAVE_CONFIG_H - #include "config.h" -#endif - -#include <QDebug> -#include <QTest> -#include <QSignalSpy> -#include <QTemporaryDir> -#include "wkspublishjob.h" -#include "keygenerationjob.h" -#include <gpgme++/keygenerationresult.h> -#include "importjob.h" -#include <gpgme++/importresult.h> -#include "protocol.h" -#include <gpgme++/engineinfo.h> - -#include "t-support.h" - -using namespace QGpgME; -using namespace GpgME; - -//#define DO_ONLINE_TESTS - -#define TEST_ADDRESS "[email protected]" - -static const char *testSecKey = -"-----BEGIN PGP PRIVATE KEY BLOCK-----\n" -"\n" -"lHgEV77hVhMJKyQDAwIIAQEHAgMEN3qKqBr9EecnfUnpw8RS8DHAjJqhwm2HAoEE\n" -"3yfQQ9w8uB/bKm5dqW4HML3JWRH8YoJaKSVrJY2D1FZUY+vHlgABAKDwEAB0HND8\n" -"5kbxiJmqKIuuNqCJ2jHgs9G0xk4GdKvZEdq0JlRlc3QgVXNlciAyIDx0ZXN0dXNl\n" -"cjJAdGVzdC5nbnVwZy5vcmc+iHkEExMIACEFAle+4VYCGwMFCwkIBwIGFQgJCgsC\n" -"BBYCAwECHgECF4AACgkQRVRoUEJO+6zgFQD7BF3pnS3w3A7J9y+Y3kyGfmscXFWJ\n" -"Kme1PAsAlVSm1y4A+weReMvWFYHJH257v94yhStmV8egGoybsNDttNAW53cbnHwE\n" -"V77hVhIJKyQDAwIIAQEHAgMEX+6cF0HEn4g3ztFvwHyr7uwXMVYUGL3lE3mjhnV3\n" -"SbY6Dmy3OeFVnEVkawHqSv+HobpQTeEqNoQHAoIiXFCRlgMBCAcAAP9FykiyDspm\n" -"T33XWRPD+LAOmaIU7CIhfv9+lVkeExlU1w+qiGEEGBMIAAkFAle+4VYCGwwACgkQ\n" -"RVRoUEJO+6xjhgD/ZJ/MwYZJPk/xPYhTP8+wF+tErVNA8w3pP9D69dgUPdcA/izZ\n" -"Pji6YetVhgsyaHc4PrKynsk5G6nM3KkAOehUQsX8\n" -"=S/Wa\n" -"-----END PGP PRIVATE KEY BLOCK-----\n"; - -static const char *testResponse = -"From [email protected] Thu Aug 25 12:15:54 2016\n" -"Return-Path: <[email protected]>\n" -"From: [email protected]\n" -"To: [email protected]\n" -"Subject: Confirm your key publication\n" -"X-Wks-Loop: webkey.g10code.com\n" -"MIME-Version: 1.0\n" -"Content-Type: multipart/encrypted; protocol=\"application/pgp-encrypted\";\n" -" boundary=\"=-=01-wbu5fr9nu6fix5tcojjo=-=\"\n" -"Date: Thu, 25 Aug 2016 12:15:54 +0000\n" -"Message-Id: <[email protected]>\n" -"Sender: <[email protected]>\n" -"X-Kolab-Scheduling-Message: FALSE\n" -"\n" -" \n" -"\n" -"--=-=01-wbu5fr9nu6fix5tcojjo=-=\n" -"Content-Type: application/pgp-encrypted\n" -"\n" -"Version: 1\n" -"\n" -"--=-=01-wbu5fr9nu6fix5tcojjo=-=\n" -"Content-Type: application/octet-stream\n" -"\n" -"-----BEGIN PGP MESSAGE-----\n" -"Version: GnuPG v2\n" -"\n" -"hH4D8pSp7hUsFUASAgMEg0w39E6d0TkFYxLbT6n3YcoKTT+Ur/c7Sn1ECyL7Rnuk\n" -"cmPO0adt3JxueK7Oz5COlk32SECFODdF3cQuDhkGxzC6Sfc4SfisdILmNhaT/MeW\n" -"8a+yE4skSK70absif4kw5XkvxXNxHeIHfAteP50jPJLSwEsBTEceb9cRMoP7s8w0\n" -"lYyi+RWQ7UKlKKywtcRCL4ow2H7spjx+a+3FzNOAoy7K0/thhLVRk8z+iuPi0/4n\n" -"Z2Ql60USLLUlfV2ZIpXdCd+5GjTJsnGhDos1pas5TZcOOAxO12Cg5TcqHISOaqa8\n" -"6BqxcKCU3NypIynOKHj375KArSs0WsEH8HWHyBBHB+NYtNpnTAuHNKxM+JtNxf+U\n" -"NfD2zptS6kyiHLw+4zjL5pEV7RHS2PBwWBDS6vhnyybNwckleya96U04iYiGRYGE\n" -"lUUR6Fl8H6x04dItFH1/jJA6Ppcu4FoYou04HADWCqJXPTgztjiW1/9QoCeXl5lm\n" -"CcOCcuw7lXp+qTejuns=\n" -"=SsWX\n" -"-----END PGP MESSAGE-----\n" -"\n" -"--=-=01-wbu5fr9nu6fix5tcojjo=-=--\n"; - - -class WKSPublishTest : public QGpgMETest -{ - Q_OBJECT - -private Q_SLOTS: - void testUnsupported() - { - // First check if it is supported - auto job = openpgp()->wksPublishJob(); - connect(job, &WKSPublishJob::result, this, - [this] (Error err, QByteArray, QByteArray, QString, Error) { - QVERIFY(err); - Q_EMIT asyncDone(); - }); - job->startCheck ("testuser1@localhost"); - QSignalSpy spy (this, SIGNAL(asyncDone())); - QVERIFY(spy.wait(QSIGNALSPY_TIMEOUT)); - } -#ifdef DO_ONLINE_TESTS -private Q_SLOTS: -#else -private: -#endif - void testWSKPublishSupport() - { - // First check if it is supported - auto job = openpgp()->wksPublishJob(); - connect(job, &WKSPublishJob::result, this, - [this] (Error err, QByteArray, QByteArray, QString, Error) { - if (GpgME::engineInfo(GpgME::GpgEngine).engineVersion() < "2.0.16") { - std::cout << err; - QVERIFY(err); - } else { - QVERIFY(!err); - } - Q_EMIT asyncDone(); - }); - job->startCheck ("[email protected]"); - QSignalSpy spy (this, SIGNAL(asyncDone())); - QVERIFY(spy.wait(QSIGNALSPY_TIMEOUT)); - } - - void testWKSPublishErrors() { - if (GpgME::engineInfo(GpgME::GpgEngine).engineVersion() < "2.0.16") { - /* Not supported */ - return; - } - auto job = openpgp()->wksPublishJob(); - connect(job, &WKSPublishJob::result, this, - [this] (Error err, QByteArray, QByteArray, QString, Error) { - QVERIFY(err); - Q_EMIT asyncDone(); - }); - job->startCreate("AB874F24E98EBB8487EE7B170F8E3D97FE7011B7", - QStringLiteral("[email protected]")); - QSignalSpy spy (this, SIGNAL(asyncDone())); - QVERIFY(spy.wait(QSIGNALSPY_TIMEOUT)); - } - - void testWKSPublishCreate() { - if (GpgME::engineInfo(GpgME::GpgEngine).engineVersion() < "2.0.16") { - /* Not supported */ - return; - } - /* First generate a test key */ - const QString args = QStringLiteral("<GnupgKeyParms format=\"internal\">\n" - "%no-protection\n" - "%transient-key\n" - "key-type: ECDSA\n" - "key-curve: brainpoolP256r1\n" - "key-usage: sign\n" - "subkey-type: ECDH\n" - "subkey-curve: brainpoolP256r1\n" - "subkey-usage: encrypt\n" - "name-email: %1\n" - "name-real: Test User\n" - "</GnupgKeyParms>").arg(TEST_ADDRESS); - - auto keygenjob = openpgp()->keyGenerationJob(); - QByteArray fpr; - connect(keygenjob, &KeyGenerationJob::result, this, - [this, &fpr](KeyGenerationResult result, QByteArray, QString, Error) - { - QVERIFY(!result.error()); - fpr = QByteArray(result.fingerprint()); - QVERIFY(!fpr.isEmpty()); - Q_EMIT asyncDone(); - }); - keygenjob->start(args); - QSignalSpy spy (this, SIGNAL(asyncDone())); - QVERIFY(spy.wait(QSIGNALSPY_TIMEOUT)); - - /* Then try to create a request. */ - auto job = openpgp()->wksPublishJob(); - connect(job, &WKSPublishJob::result, this, - [this] (Error err, QByteArray out, QByteArray, QString, Error) { - QVERIFY(!err); - Q_EMIT asyncDone(); - const QString outstr = QString(out); - QVERIFY(outstr.contains( - QStringLiteral("-----BEGIN PGP PUBLIC KEY BLOCK-----"))); - QVERIFY(outstr.contains( - QStringLiteral("Content-Type: application/pgp-keys"))); - QVERIFY(outstr.contains( - QStringLiteral("From: " TEST_ADDRESS))); - }); - job->startCreate(fpr.constData(), QLatin1String(TEST_ADDRESS)); - QVERIFY(spy.wait(QSIGNALSPY_TIMEOUT)); - } - - void testWKSPublishReceive() { - if (GpgME::engineInfo(GpgME::GpgEngine).engineVersion() < "2.0.16") { - /* Not supported */ - return; - } - auto importjob = openpgp()->importJob(); - connect(importjob, &ImportJob::result, this, - [this](ImportResult result, QString, Error) - { - QVERIFY(!result.error()); - QVERIFY(!result.imports().empty()); - QVERIFY(result.numSecretKeysImported()); - Q_EMIT asyncDone(); - }); - importjob->start(QByteArray(testSecKey)); - QSignalSpy spy (this, SIGNAL(asyncDone())); - QVERIFY(spy.wait(QSIGNALSPY_TIMEOUT)); - - /* Get a response. */ - auto job = openpgp()->wksPublishJob(); - connect(job, &WKSPublishJob::result, this, - [this] (Error err, QByteArray out, QByteArray, QString, Error) { - QVERIFY(!err); - Q_EMIT asyncDone(); - const QString outstr = QString(out); - QVERIFY(outstr.contains( - QStringLiteral("-----BEGIN PGP MESSAGE-----"))); - QVERIFY(outstr.contains( - QStringLiteral("Content-Type: multipart/encrypted;"))); - QVERIFY(outstr.contains( - QStringLiteral("From: " TEST_ADDRESS))); - }); - job->startReceive(QByteArray(testResponse)); - QVERIFY(spy.wait(QSIGNALSPY_TIMEOUT)); - } - - void initTestCase() - { - QGpgMETest::initTestCase(); - const QString gpgHome = qgetenv("GNUPGHOME"); - qputenv("GNUPGHOME", mDir.path().toUtf8()); - QVERIFY(mDir.isValid()); - QFile agentConf(mDir.path() + QStringLiteral("/gpg-agent.conf")); - QVERIFY(agentConf.open(QIODevice::WriteOnly)); - agentConf.write("allow-loopback-pinentry"); - agentConf.close(); - } -private: - QTemporaryDir mDir; -}; - -QTEST_MAIN(WKSPublishTest) - -#include "t-wkspublish.moc" |