From 41297520da32081d0a34ac2799812f210b7a9335 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ingo=20Kl=C3=B6cker?= Date: Tue, 29 Mar 2022 15:45:52 +0200 Subject: [PATCH] qt: Add job to revoke own OpenPGP keys * lang/qt/src/revokekeyjob.h, lang/qt/src/qgpgmerevokekeyjob.h, lang/qt/src/qgpgmerevokekeyjob.cpp: New. * lang/qt/src/protocol.h (class Protocol): Add pure virtual member function revokeKeyJob. * lang/qt/src/protocol_p.h (Protocol::revokeKeyJob): New. * lang/qt/src/job.cpp, lang/qt/src/Makefile.am: Update accordingly. * lang/qt/tests/Makefile.am (the_tests, moc_files, noinst_PROGRAMS): Add new test. (t_revokekey_SOURCES): New. * lang/qt/tests/t-revokekey.cpp: New. -- The new job allows revoking own OpenPGP keys as with the "revkey" edit-key command of gpg. GnuPG-bug-id: 5904 --- NEWS | 4 +- lang/qt/src/Makefile.am | 6 + lang/qt/src/job.cpp | 3 + lang/qt/src/protocol.h | 3 + lang/qt/src/protocol_p.h | 13 ++ lang/qt/src/qgpgmerevokekeyjob.cpp | 96 +++++++++++++ lang/qt/src/qgpgmerevokekeyjob.h | 70 ++++++++++ lang/qt/src/revokekeyjob.h | 86 ++++++++++++ lang/qt/tests/Makefile.am | 9 +- lang/qt/tests/t-revokekey.cpp | 210 +++++++++++++++++++++++++++++ 10 files changed, 495 insertions(+), 5 deletions(-) create mode 100644 lang/qt/src/qgpgmerevokekeyjob.cpp create mode 100644 lang/qt/src/qgpgmerevokekeyjob.h create mode 100644 lang/qt/src/revokekeyjob.h create mode 100644 lang/qt/tests/t-revokekey.cpp diff --git a/NEWS b/NEWS index 98e6d648..339f2ee4 100644 --- a/NEWS +++ b/NEWS @@ -5,12 +5,14 @@ Noteworthy changes in version 1.17.2 (unreleased) * cpp, qt: Do not export internal symbols anymore. [T5906] - * cpp: Support revocation of own OpenPGP keys. [#5904] + * cpp, qt: Support revocation of own OpenPGP keys. [#5904] * Interface changes relative to the 1.17.1 release: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ cpp: RevocationReason NEW. cpp: GpgRevokeKeyEditInteractor NEW. + qt: RevokeKeyJob NEW. + qt: Protocol::revokeKeyJob NEW. Noteworthy changes in version 1.17.1 (2022-03-06) diff --git a/lang/qt/src/Makefile.am b/lang/qt/src/Makefile.am index d47da895..3b0b9c3c 100644 --- a/lang/qt/src/Makefile.am +++ b/lang/qt/src/Makefile.am @@ -36,6 +36,7 @@ qgpgme_sources = \ qgpgmelistallkeysjob.cpp qgpgmenewcryptoconfig.cpp \ qgpgmereceivekeysjob.cpp \ qgpgmerefreshkeysjob.cpp \ + qgpgmerevokekeyjob.cpp \ qgpgmesignencryptjob.cpp \ qgpgmesignjob.cpp qgpgmesignkeyjob.cpp qgpgmeverifydetachedjob.cpp \ qgpgmeverifyopaquejob.cpp qgpgmewkdlookupjob.cpp threadedjobmixin.cpp \ @@ -70,6 +71,7 @@ qgpgme_headers= \ qgpgmenewcryptoconfig.h \ quickjob.h \ receivekeysjob.h \ + revokekeyjob.h \ specialjob.h \ signjob.h \ signkeyjob.h \ @@ -114,6 +116,7 @@ camelcase_headers= \ QGpgMENewCryptoConfig \ QuickJob \ ReceiveKeysJob \ + RevokeKeyJob \ SpecialJob \ SignJob \ SignKeyJob \ @@ -159,6 +162,7 @@ private_qgpgme_headers = \ qgpgmelistallkeysjob.h \ qgpgmereceivekeysjob.h \ qgpgmerefreshkeysjob.h \ + qgpgmerevokekeyjob.h \ qgpgmesignencryptjob.h \ qgpgmesignjob.h \ qgpgmesignkeyjob.h \ @@ -212,6 +216,7 @@ qgpgme_moc_sources = \ qgpgmelistallkeysjob.moc \ qgpgmereceivekeysjob.moc \ qgpgmerefreshkeysjob.moc \ + qgpgmerevokekeyjob.moc \ qgpgmesignencryptjob.moc \ qgpgmesignjob.moc \ qgpgmesignkeyjob.moc \ @@ -223,6 +228,7 @@ qgpgme_moc_sources = \ qgpgmetofupolicyjob.moc \ receivekeysjob.moc \ refreshkeysjob.moc \ + revokekeyjob.moc \ signencryptjob.moc \ signjob.moc \ signkeyjob.moc \ diff --git a/lang/qt/src/job.cpp b/lang/qt/src/job.cpp index a9edc8ea..dba7556b 100644 --- a/lang/qt/src/job.cpp +++ b/lang/qt/src/job.cpp @@ -72,6 +72,7 @@ #include "quickjob.h" #include "gpgcardjob.h" #include "receivekeysjob.h" +#include "revokekeyjob.h" #include #include @@ -172,6 +173,7 @@ make_job_subclass(WKSPublishJob) make_job_subclass(TofuPolicyJob) make_job_subclass(QuickJob) make_job_subclass(GpgCardJob) +make_job_subclass(RevokeKeyJob) #undef make_job_subclass @@ -208,3 +210,4 @@ make_job_subclass(GpgCardJob) #include "quickjob.moc" #include "gpgcardjob.moc" #include "receivekeysjob.moc" +#include "revokekeyjob.moc" diff --git a/lang/qt/src/protocol.h b/lang/qt/src/protocol.h index 62b2cb2f..8538bd8d 100644 --- a/lang/qt/src/protocol.h +++ b/lang/qt/src/protocol.h @@ -71,6 +71,7 @@ class TofuPolicyJob; class QuickJob; class GpgCardJob; class ReceiveKeysJob; +class RevokeKeyJob; /** The main entry point for QGpgME Comes in OpenPGP and SMIME(CMS) flavors. * @@ -173,6 +174,8 @@ public: virtual ExportJob *secretSubkeyExportJob(bool armor = false) const = 0; virtual AddExistingSubkeyJob *addExistingSubkeyJob() const = 0; virtual ReceiveKeysJob *receiveKeysJob() const = 0; + + virtual RevokeKeyJob *revokeKeyJob() const = 0; }; /** Obtain a reference to the OpenPGP Protocol. diff --git a/lang/qt/src/protocol_p.h b/lang/qt/src/protocol_p.h index 4211e001..2ca1cf18 100644 --- a/lang/qt/src/protocol_p.h +++ b/lang/qt/src/protocol_p.h @@ -65,6 +65,7 @@ #include "qgpgmetofupolicyjob.h" #include "qgpgmequickjob.h" #include "qgpgmereceivekeysjob.h" +#include "qgpgmerevokekeyjob.h" namespace { @@ -481,6 +482,18 @@ public: } return new QGpgME::QGpgMEQuickJob(context); } + + QGpgME::RevokeKeyJob *revokeKeyJob() const Q_DECL_OVERRIDE + { + if (mProtocol != GpgME::OpenPGP) { + return nullptr; + } + GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol); + if (!context) { + return nullptr; + } + return new QGpgME::QGpgMERevokeKeyJob(context); + } }; } diff --git a/lang/qt/src/qgpgmerevokekeyjob.cpp b/lang/qt/src/qgpgmerevokekeyjob.cpp new file mode 100644 index 00000000..08585414 --- /dev/null +++ b/lang/qt/src/qgpgmerevokekeyjob.cpp @@ -0,0 +1,96 @@ +/* + qgpgmerevokekeyjob.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 + + 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 "qgpgmerevokekeyjob.h" + +#include "dataprovider.h" + +#include +#include +#include +#include + +#include + +using namespace QGpgME; +using namespace GpgME; + +QGpgMERevokeKeyJob::QGpgMERevokeKeyJob(Context *context) + : mixin_type{context} +{ + lateInitialization(); +} + +QGpgMERevokeKeyJob::~QGpgMERevokeKeyJob() = default; + +static QGpgMERevokeKeyJob::result_type revoke_key(Context *ctx, const Key &key, + RevocationReason reason, + const std::vector &description) +{ + std::unique_ptr interactor{new GpgRevokeKeyEditInteractor}; + interactor->setReason(reason, description); + + QGpgME::QByteArrayDataProvider dp; + Data outData(&dp); + assert(!outData.isNull()); + + ctx->setFlag("extended-edit", "1"); + + const Error err = ctx->edit(key, std::unique_ptr(interactor.release()), outData); + Error ae; + const QString log = _detail::audit_log_as_html(ctx, ae); + return std::make_tuple(err, log, ae); +} + +Error QGpgMERevokeKeyJob::start(const GpgME::Key &key, + GpgME::RevocationReason reason, + const std::vector &description) +{ + run(std::bind(&revoke_key, std::placeholders::_1, key, reason, description)); + return {}; +} + +Error QGpgMERevokeKeyJob::exec(const GpgME::Key &key, + GpgME::RevocationReason reason, + const std::vector &description) +{ + const result_type r = revoke_key(context(), key, reason, description); + resultHook(r); + return std::get<0>(r); +} + +#include "qgpgmerevokekeyjob.moc" diff --git a/lang/qt/src/qgpgmerevokekeyjob.h b/lang/qt/src/qgpgmerevokekeyjob.h new file mode 100644 index 00000000..0eba5cb7 --- /dev/null +++ b/lang/qt/src/qgpgmerevokekeyjob.h @@ -0,0 +1,70 @@ +/* + qgpgmerevokekeyjob.h + + This file is part of qgpgme, the Qt API binding for gpgme + Copyright (c) 2022 g10 Code GmbH + Software engineering by Ingo Klöcker + + 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 __QGPGME_QGPGMEREVOKEKEYJOB_H__ +#define __QGPGME_QGPGMEREVOKEKEYJOB_H__ + +#include "threadedjobmixin.h" +#include "revokekeyjob.h" + +namespace QGpgME +{ + +class QGpgMERevokeKeyJob +#ifdef Q_MOC_RUN + : public RevokeKeyJob +#else + : public _detail::ThreadedJobMixin +#endif +{ + Q_OBJECT +#ifdef Q_MOC_RUN +public Q_SLOTS: + void slotFinished(); +#endif +public: + explicit QGpgMERevokeKeyJob(GpgME::Context *context); + ~QGpgMERevokeKeyJob() override; + + GpgME::Error start(const GpgME::Key &key, + GpgME::RevocationReason reason = GpgME::RevocationReason::Unspecified, + const std::vector &description = {}) override; + + GpgME::Error exec(const GpgME::Key &key, + GpgME::RevocationReason reason = GpgME::RevocationReason::Unspecified, + const std::vector &description = {}) override; +}; + +} + +#endif // __QGPGME_QGPGMEREVOKEKEYJOB_H__ diff --git a/lang/qt/src/revokekeyjob.h b/lang/qt/src/revokekeyjob.h new file mode 100644 index 00000000..69aef062 --- /dev/null +++ b/lang/qt/src/revokekeyjob.h @@ -0,0 +1,86 @@ +/* + revokekeyjob.h + + This file is part of qgpgme, the Qt API binding for gpgme + Copyright (c) 2022 g10 Code GmbH + Software engineering by Ingo Klöcker + + 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 __QGPGME_REVOKEKEYJOB_H__ +#define __QGPGME_REVOKEKEYJOB_H__ + +#include "job.h" +#include "qgpgme_export.h" + +class QString; + +namespace GpgME +{ +class Error; +class Key; +} + +namespace QGpgME +{ + +class QGPGME_EXPORT RevokeKeyJob : public Job +{ + Q_OBJECT +protected: + explicit RevokeKeyJob(QObject *parent); + +public: + ~RevokeKeyJob(); + + /** + Starts the operation. \a key is the key to revoke with reason \a reason and + optional description \a description. The individual elements of \a description + must be non-empty strings and they must not contain any endline characters. + + The job deletes itself after it has completed the operation. + */ + virtual GpgME::Error start(const GpgME::Key &key, + GpgME::RevocationReason reason = GpgME::RevocationReason::Unspecified, + const std::vector &description = {}) = 0; + + /** + Runs the operation. \a key is the key to revoke with reason \a reason and + optional description \a description. The individual elements of \a description + must be non-empty strings and they must not contain any endline characters. + */ + virtual GpgME::Error exec(const GpgME::Key &key, + GpgME::RevocationReason reason = GpgME::RevocationReason::Unspecified, + const std::vector &description = {}) = 0; + +Q_SIGNALS: + void result(const GpgME::Error &result, const QString &auditLogAsHtml = {}, const GpgME::Error &auditLogError = {}); +}; + +} + +#endif // __QGPGME_REVOKEKEYJOB_H__ diff --git a/lang/qt/tests/Makefile.am b/lang/qt/tests/Makefile.am index 6c082b07..f0bcfad9 100644 --- a/lang/qt/tests/Makefile.am +++ b/lang/qt/tests/Makefile.am @@ -30,7 +30,7 @@ the_tests = \ t-addexistingsubkey \ t-keylist t-keylocate t-ownertrust t-tofuinfo \ t-encrypt t-verify t-various t-config t-remarks t-trustsignatures \ - t-changeexpiryjob t-wkdlookup t-import + t-changeexpiryjob t-wkdlookup t-import t-revokekey TESTS = initial.test $(the_tests) final.test @@ -39,7 +39,7 @@ moc_files = \ t-keylist.moc t-keylocate.moc t-ownertrust.moc t-tofuinfo.moc \ t-encrypt.moc t-support.hmoc t-wkspublish.moc t-verify.moc \ t-various.moc t-config.moc t-remarks.moc t-trustsignatures.moc \ - t-changeexpiryjob.moc t-wkdlookup.moc t-import.moc + t-changeexpiryjob.moc t-wkdlookup.moc t-import.moc t-revokekey.moc AM_LDFLAGS = -no-install @@ -70,6 +70,7 @@ t_trustsignatures_SOURCES = t-trustsignatures.cpp $(support_src) t_changeexpiryjob_SOURCES = t-changeexpiryjob.cpp $(support_src) t_wkdlookup_SOURCES = t-wkdlookup.cpp $(support_src) t_import_SOURCES = t-import.cpp $(support_src) +t_revokekey_SOURCES = t-revokekey.cpp $(support_src) run_exportjob_SOURCES = run-exportjob.cpp run_importjob_SOURCES = run-importjob.cpp run_keyformailboxjob_SOURCES = run-keyformailboxjob.cpp @@ -83,8 +84,8 @@ noinst_PROGRAMS = \ t-addexistingsubkey \ t-keylist t-keylocate t-ownertrust t-tofuinfo t-encrypt \ run-keyformailboxjob t-wkspublish t-verify t-various t-config t-remarks \ - t-trustsignatures t-changeexpiryjob t-wkdlookup t-import run-importjob \ - run-exportjob run-receivekeysjob + t-trustsignatures t-changeexpiryjob t-wkdlookup t-import t-revokekey \ + run-importjob run-exportjob run-receivekeysjob CLEANFILES = secring.gpg pubring.gpg pubring.kbx trustdb.gpg dirmngr.conf \ gpg-agent.conf pubring.kbx~ S.gpg-agent gpg.conf pubring.gpg~ \ diff --git a/lang/qt/tests/t-revokekey.cpp b/lang/qt/tests/t-revokekey.cpp new file mode 100644 index 00000000..3c0c4ca2 --- /dev/null +++ b/lang/qt/tests/t-revokekey.cpp @@ -0,0 +1,210 @@ +/* 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 + + 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 +#include + +#include +#include + +#include +#include + +#include + +using namespace QGpgME; +using namespace GpgME; + +/* Test keys + sec ed25519 2022-03-29 [SC] + 604122B94C86BE846EAFE637FC2BCFB1B19A1CF4 + uid [ultimate] revoke-me@example.net + ssb cv25519 2022-03-29 [E] + * generated with +export GNUPGHOME=$(mktemp -d) +gpg -K +gpg --batch --pinentry-mode loopback --passphrase abc --quick-gen-key revoke-me@example.net default default never +gpg -K +gpg --export-secret-keys --armor --batch --pinentry-mode loopback --passphrase abc --comment revoke-me@example.net revoke-me@example.net | sed 's/\(.*\)/ "\1\\n"/' +#rm -rf ${GNUPGHOME} +unset GNUPGHOME +*/ +static const char *testKeyData = + "-----BEGIN PGP PRIVATE KEY BLOCK-----\n" + "Comment: revoke-me@example.net\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("revoke-me@example.net"); + QVERIFY(!key.isNull()); + QVERIFY(!key.isRevoked()); + + auto job = std::unique_ptr{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()); + } + + void testSync_noReasonDescription() + { + // Get the key that shall be revoked + auto key = getTestKey("revoke-me@example.net"); + QVERIFY(!key.isNull()); + QVERIFY(!key.isRevoked()); + + auto job = std::unique_ptr{openpgp()->revokeKeyJob()}; + hookUpPassphraseProvider(job.get()); + + const auto result = job->exec(key); + + QVERIFY(result.code() == GPG_ERR_NO_ERROR); + key.update(); + QVERIFY(key.isRevoked()); + } + + void testSync_oneLineReasonDescription() + { + // Get the key that shall be revoked + auto key = getTestKey("revoke-me@example.net"); + QVERIFY(!key.isNull()); + QVERIFY(!key.isRevoked()); + + auto job = std::unique_ptr{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()); + } + + void testSync_twoLinesReasonDescription() + { + // Get the key that shall be revoked + auto key = getTestKey("revoke-me@example.net"); + QVERIFY(!key.isNull()); + QVERIFY(!key.isRevoked()); + + auto job = std::unique_ptr{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()); + } + +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; + } + +private: + QTemporaryDir mGnupgHomeTestFixture; + std::unique_ptr mGnupgHomeTestCopy; +}; + +QTEST_MAIN(RevokeKeyJobTest) + +#include "t-revokekey.moc"