diff options
author | Ingo Klöcker <[email protected]> | 2024-08-06 14:57:14 +0000 |
---|---|---|
committer | Ingo Klöcker <[email protected]> | 2024-08-07 08:53:21 +0000 |
commit | 63822343dfaac8b638ef475d441c4379da3a9804 (patch) | |
tree | a72fc7cdfea56eed20c09aadc1ab31ac755edbcc | |
parent | cpp: Add support for setting owner trust and for disabling keys (diff) | |
download | gpgme-63822343dfaac8b638ef475d441c4379da3a9804.tar.gz gpgme-63822343dfaac8b638ef475d441c4379da3a9804.zip |
qt: Support disabling and enabling of keys
* lang/qt/src/Makefile.am: Add new files.
* lang/qt/src/job.cpp (QuickJob): Move definition of constructor and
destructor and inclusion of the moc file to quickjob.cpp.
* lang/qt/src/qgpgmequickjob.cpp (class QGpgMEQuickJobPrivate): New.
(QGpgMEQuickJob::QGpgMEQuickJob): Instantiate private job class.
(set_key_enabled): New.
* lang/qt/src/quickjob.cpp: New.
* lang/qt/src/quickjob.h (class QuickJob): Add member function
startSetKeyEnabled.
* lang/qt/src/quickjob_p.h: New.
* lang/qt/tests/Makefile.am: Add new test for Qt 5 and Qt 6.
* lang/qt/tests/t-disablekey.cpp: New.
--
GnuPG-bug-id: 7239
-rw-r--r-- | NEWS | 3 | ||||
-rw-r--r-- | lang/qt/src/Makefile.am | 2 | ||||
-rw-r--r-- | lang/qt/src/job.cpp | 3 | ||||
-rw-r--r-- | lang/qt/src/qgpgmequickjob.cpp | 62 | ||||
-rw-r--r-- | lang/qt/src/quickjob.cpp | 52 | ||||
-rw-r--r-- | lang/qt/src/quickjob.h | 8 | ||||
-rw-r--r-- | lang/qt/src/quickjob_p.h | 51 | ||||
-rw-r--r-- | lang/qt/tests/Makefile.am | 8 | ||||
-rw-r--r-- | lang/qt/tests/t-disablekey.cpp | 118 |
9 files changed, 300 insertions, 7 deletions
@@ -38,6 +38,8 @@ Noteworthy changes in version 1.24.0 (unrelease) * qt: Allow appending a detached signature to an existing file. [T6867] + * qt: Add support for enabling and disabling keys. [T7239] + * Interface changes relative to the 1.23.2 release: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ GPGME_ENCRYPT_FILE NEW. @@ -101,6 +103,7 @@ Noteworthy changes in version 1.24.0 (unrelease) qt: VerifyOpaqueJob::outputFile NEW. qt: ImportJob::setImportOptions NEW. qt: ImportJob::importOptions NEW. + qt: QuickJob::startSetKeyEnabled NEW. Noteworthy changes in version 1.23.2 (2023-11-28) diff --git a/lang/qt/src/Makefile.am b/lang/qt/src/Makefile.am index 74eca04d..1ba61fab 100644 --- a/lang/qt/src/Makefile.am +++ b/lang/qt/src/Makefile.am @@ -64,6 +64,7 @@ qgpgme_sources = \ qgpgmetofupolicyjob.cpp qgpgmequickjob.cpp \ defaultkeygenerationjob.cpp qgpgmewkspublishjob.cpp \ qgpgmegpgcardjob.cpp changeexpiryjob.cpp encryptjob.cpp importjob.cpp \ + quickjob.cpp \ signarchivejob.cpp \ signencryptjob.cpp \ signencryptarchivejob.cpp \ @@ -229,6 +230,7 @@ private_qgpgme_headers = \ qgpgmetofupolicyjob.h \ qgpgmegpgcardjob.h \ qgpgmequickjob.h \ + quickjob_p.h \ signarchivejob_p.h \ signencryptjob_p.h \ signencryptarchivejob_p.h \ diff --git a/lang/qt/src/job.cpp b/lang/qt/src/job.cpp index 8150d9a3..bbbca293 100644 --- a/lang/qt/src/job.cpp +++ b/lang/qt/src/job.cpp @@ -63,7 +63,6 @@ #include "wkspublishjob.h" #include "tofupolicyjob.h" #include "threadedjobmixin.h" -#include "quickjob.h" #include "gpgcardjob.h" #include "receivekeysjob.h" #include "revokekeyjob.h" @@ -179,7 +178,6 @@ make_job_subclass(KeyForMailboxJob) make_job_subclass(WKDLookupJob) make_job_subclass(WKSPublishJob) make_job_subclass(TofuPolicyJob) -make_job_subclass(QuickJob) make_job_subclass(GpgCardJob) make_job_subclass(RevokeKeyJob) make_job_subclass(SetPrimaryUserIDJob) @@ -210,7 +208,6 @@ make_job_subclass(SetPrimaryUserIDJob) #include "wkdlookupjob.moc" #include "wkspublishjob.moc" #include "tofupolicyjob.moc" -#include "quickjob.moc" #include "gpgcardjob.moc" #include "receivekeysjob.moc" #include "revokekeyjob.moc" diff --git a/lang/qt/src/qgpgmequickjob.cpp b/lang/qt/src/qgpgmequickjob.cpp index 8da1f9a0..d65afd7d 100644 --- a/lang/qt/src/qgpgmequickjob.cpp +++ b/lang/qt/src/qgpgmequickjob.cpp @@ -37,23 +37,58 @@ #include "qgpgmequickjob.h" +#include "qgpgme_debug.h" +#include "quickjob_p.h" +#include "util.h" + #include <gpgme++/context.h> #include <gpgme++/key.h> -#include "util.h" using namespace QGpgME; using namespace GpgME; +namespace +{ + +class QGpgMEQuickJobPrivate : public QuickJobPrivate +{ + QGpgMEQuickJob *q = nullptr; + +public: + QGpgMEQuickJobPrivate(QGpgMEQuickJob *qq) + : q{qq} + { + } + + ~QGpgMEQuickJobPrivate() override = default; + +private: + GpgME::Error startIt() override + { + Q_ASSERT(!"Not supported by this Job class."); + return Error::fromCode(GPG_ERR_NOT_SUPPORTED); + } + + void startNow() override + { + Q_ASSERT(!"Not supported by this Job class."); + q->run(); + } + + GpgME::Error startSetKeyEnabled(const GpgME::Key &key, bool enable) override; +}; + +} + QGpgMEQuickJob::QGpgMEQuickJob(Context *context) : mixin_type(context) { + setJobPrivate(this, std::unique_ptr<QGpgMEQuickJobPrivate>{new QGpgMEQuickJobPrivate{this}}); lateInitialization(); } -QGpgMEQuickJob::~QGpgMEQuickJob() -{ -} +QGpgMEQuickJob::~QGpgMEQuickJob() = default; static QGpgMEQuickJob::result_type createWorker(GpgME::Context *ctx, const QString &uid, @@ -154,4 +189,23 @@ void QGpgMEQuickJob::startAddAdsk(const GpgME::Key &key, const char *adsk) run(std::bind(&addAdskWorker, std::placeholders::_1, key, adsk)); } +static QGpgMEQuickJob::result_type set_key_enabled(Context *ctx, const Key &key, bool enabled) +{ + const auto err = ctx->setKeyEnabled(key, enabled); + return std::make_tuple(err, QString(), Error()); +} + +Error QGpgMEQuickJobPrivate::startSetKeyEnabled(const Key &key, bool enabled) +{ + if (key.isNull()) { + return Error::fromCode(GPG_ERR_INV_VALUE); + } + + q->run([=](Context *ctx) { + return set_key_enabled(ctx, key, enabled); + }); + + return {}; +} + #include "qgpgmequickjob.moc" diff --git a/lang/qt/src/quickjob.cpp b/lang/qt/src/quickjob.cpp new file mode 100644 index 00000000..1c9343da --- /dev/null +++ b/lang/qt/src/quickjob.cpp @@ -0,0 +1,52 @@ +/* + quickjob.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. +*/ + +#include "quickjob.h" +#include "quickjob_p.h" + +using namespace QGpgME; + +QuickJob::QuickJob(QObject *parent) + : Job{parent} +{ +} + +QuickJob::~QuickJob() = default; + +GpgME::Error QuickJob::startSetKeyEnabled(const GpgME::Key &key, bool enabled) +{ + auto d = jobPrivate<QuickJobPrivate>(this); + return d->startSetKeyEnabled(key, enabled); +} + +#include "quickjob.moc" diff --git a/lang/qt/src/quickjob.h b/lang/qt/src/quickjob.h index 049438d6..df8ac2b5 100644 --- a/lang/qt/src/quickjob.h +++ b/lang/qt/src/quickjob.h @@ -84,6 +84,14 @@ public: /** Start --quick-add-adsk */ virtual void startAddAdsk(const GpgME::Key &key, const char *adsk) = 0; + /** + * Starts the operation to enable or disable the OpenPGP key \a key. + * If \a enabled is \c true then the key is enabled. Otherwise, the key is disabled. + * + * \note Requires gpg 2.4.6. + */ + GpgME::Error startSetKeyEnabled(const GpgME::Key &key, bool enabled); + Q_SIGNALS: void result(const GpgME::Error &error, const QString &auditLogAsHtml = QString(), const GpgME::Error &auditLogError = GpgME::Error()); diff --git a/lang/qt/src/quickjob_p.h b/lang/qt/src/quickjob_p.h new file mode 100644 index 00000000..a8c993a2 --- /dev/null +++ b/lang/qt/src/quickjob_p.h @@ -0,0 +1,51 @@ +/* + quickjob_p.h + + 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. +*/ + +#ifndef __QGPGME_QUICKJOB_P_H__ +#define __QGPGME_QUICKJOB_P_H__ + +#include "job_p.h" + +#include "quickjob.h" + +namespace QGpgME +{ + +struct QuickJobPrivate : public JobPrivate +{ + virtual GpgME::Error startSetKeyEnabled(const GpgME::Key &key, bool enabled) = 0; +}; + +} + +#endif // __QGPGME_QUICKJOB_P_H__ diff --git a/lang/qt/tests/Makefile.am b/lang/qt/tests/Makefile.am index 2747a63c..cf6dbd55 100644 --- a/lang/qt/tests/Makefile.am +++ b/lang/qt/tests/Makefile.am @@ -33,6 +33,7 @@ the_tests5 = \ t-changeexpiryjob5 \ t-config5 \ t-decryptverify5 \ + t-disablekey5 \ t-encrypt5 \ t-import5 \ t-keylist5 \ @@ -69,6 +70,7 @@ the_tests6 = \ t-changeexpiryjob6 \ t-config6 \ t-decryptverify6 \ + t-disablekey6 \ t-encrypt6 \ t-import6 \ t-keylist6 \ @@ -188,6 +190,9 @@ 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) @@ -288,6 +293,9 @@ 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) diff --git a/lang/qt/tests/t-disablekey.cpp b/lang/qt/tests/t-disablekey.cpp new file mode 100644 index 00000000..40581719 --- /dev/null +++ b/lang/qt/tests/t-disablekey.cpp @@ -0,0 +1,118 @@ +/* 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" |