aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIngo Klöcker <[email protected]>2022-11-04 09:39:30 +0000
committerIngo Klöcker <[email protected]>2022-11-04 09:44:07 +0000
commitb6593bda1f7bfaf6cf3b869b8379cbb2b619e00a (patch)
treeb174b4c442120d534056fadb68a8ae6cc7ad03bd
parentcore: New context flag "no-auto-check-trustdb" (diff)
downloadgpgme-b6593bda1f7bfaf6cf3b869b8379cbb2b619e00a.tar.gz
gpgme-b6593bda1f7bfaf6cf3b869b8379cbb2b619e00a.zip
qt: Allow disabling automatic trust database check on key listing
* lang/qt/src/Makefile.am (qgpgme_sources): Add listallkeysjob.cpp. * lang/qt/src/listallkeysjob.cpp: New. * lang/qt/src/listallkeysjob.h (enum ListAllKeysJob::Option, typedef ListAllKeysJob::Options, ListAllKeysJob::setOptions, ListAllKeysJob::options): New. * lang/qt/src/qgpgmelistallkeysjob.cpp (list_keys): Set context flag "no-auto-check-trustdb" if requested. (QGpgMEListAllKeysJob::start, QGpgMEListAllKeysJob::exec): Add options to call of list_keys. -- GnuPG-bug-id: 6261
-rw-r--r--NEWS7
-rw-r--r--lang/qt/src/Makefile.am2
-rw-r--r--lang/qt/src/listallkeysjob.cpp65
-rw-r--r--lang/qt/src/listallkeysjob.h14
-rw-r--r--lang/qt/src/qgpgmelistallkeysjob.cpp18
5 files changed, 102 insertions, 4 deletions
diff --git a/NEWS b/NEWS
index c6cec593..c5f457a3 100644
--- a/NEWS
+++ b/NEWS
@@ -15,12 +15,19 @@ Noteworthy changes in version 1.18.1 (unreleased)
* cpp: Allow setting the curve to use when generating ECC keys
for smart cards. [T4429]
+ * qt: Extend ListAllKeysJob to allow disabling the automatic trust database
+ check when listing all keys. [T6261]
+
* Interface changes relative to the 1.18.0 release:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
gpgme_get_ctx_flag EXTENDED: New flag 'no-auto-check-trustdb'.
gpgme_set_ctx_flag EXTENDED: New flag 'no-auto-check-trustdb'.
cpp: GpgGenCardKeyInteractor::Curve NEW.
cpp: GpgGenCardKeyInteractor::setCurve NEW.
+ qt: ListAllKeysJob::Option NEW.
+ qt: ListAllKeysJob::Options NEW.
+ qt: ListAllKeysJob::setOptions NEW.
+ qt: ListAllKeysJob::options NEW.
Noteworthy changes in version 1.18.0 (2022-08-10)
diff --git a/lang/qt/src/Makefile.am b/lang/qt/src/Makefile.am
index a9b54c94..e5358b49 100644
--- a/lang/qt/src/Makefile.am
+++ b/lang/qt/src/Makefile.am
@@ -41,7 +41,7 @@ qgpgme_sources = \
qgpgmedecryptverifyjob.cpp qgpgmedeletejob.cpp qgpgmedownloadjob.cpp \
qgpgmeencryptjob.cpp qgpgmeexportjob.cpp qgpgmeimportfromkeyserverjob.cpp \
qgpgmeimportjob.cpp qgpgmekeygenerationjob.cpp qgpgmekeylistjob.cpp \
- qgpgmelistallkeysjob.cpp qgpgmenewcryptoconfig.cpp \
+ listallkeysjob.cpp qgpgmelistallkeysjob.cpp qgpgmenewcryptoconfig.cpp \
qgpgmereceivekeysjob.cpp \
qgpgmerefreshsmimekeysjob.cpp \
qgpgmerevokekeyjob.cpp \
diff --git a/lang/qt/src/listallkeysjob.cpp b/lang/qt/src/listallkeysjob.cpp
new file mode 100644
index 00000000..f72a45d1
--- /dev/null
+++ b/lang/qt/src/listallkeysjob.cpp
@@ -0,0 +1,65 @@
+/*
+ listallkeysjob.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 "listallkeysjob.h"
+#include "job_p.h"
+
+using namespace QGpgME;
+
+namespace
+{
+struct ListAllKeysJobPrivate : public JobPrivate
+{
+ ListAllKeysJobPrivate() = default;
+
+ ~ListAllKeysJobPrivate() override = default;
+
+ ListAllKeysJob::Options m_options = ListAllKeysJob::Default;
+};
+}
+
+void ListAllKeysJob::setOptions(ListAllKeysJob::Options options)
+{
+ auto d = jobPrivate<ListAllKeysJobPrivate>(this);
+ d->m_options = options;
+}
+
+ListAllKeysJob::Options ListAllKeysJob::options() const
+{
+ auto d = jobPrivate<ListAllKeysJobPrivate>(this);
+ return d->m_options;
+}
diff --git a/lang/qt/src/listallkeysjob.h b/lang/qt/src/listallkeysjob.h
index 85cd04b1..561293ca 100644
--- a/lang/qt/src/listallkeysjob.h
+++ b/lang/qt/src/listallkeysjob.h
@@ -5,6 +5,8 @@
Copyright (c) 2004 Klarälvdalens Datakonsult AB
Copyright (c) 2016 by Bundesamt für Sicherheit in der Informationstechnik
Software engineering by Intevation GmbH
+ 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
@@ -74,12 +76,22 @@ namespace QGpgME
class QGPGME_EXPORT ListAllKeysJob : public Job
{
Q_OBJECT
+public:
+ enum Option {
+ Default = 0x00,
+ DisableAutomaticTrustDatabaseCheck = 0x01,
+ };
+ Q_DECLARE_FLAGS(Options, Option)
+
protected:
explicit ListAllKeysJob(QObject *parent);
public:
~ListAllKeysJob();
+ void setOptions(Options options);
+ Options options() const;
+
/**
Starts the listallkeys operation. In general, all keys are
returned (however, the backend is free to truncate the result
@@ -101,6 +113,8 @@ Q_SIGNALS:
void result(const GpgME::KeyListResult &result, const std::vector<GpgME::Key> &pub = std::vector<GpgME::Key>(), const std::vector<GpgME::Key> &sec = std::vector<GpgME::Key>(), const QString &auditLogAsHtml = QString(), const GpgME::Error &auditLogError = GpgME::Error());
};
+Q_DECLARE_OPERATORS_FOR_FLAGS(ListAllKeysJob::Options)
+
}
#endif // __KLEO_LISTALLKEYSJOB_H__
diff --git a/lang/qt/src/qgpgmelistallkeysjob.cpp b/lang/qt/src/qgpgmelistallkeysjob.cpp
index 6f169ac9..2d1dc091 100644
--- a/lang/qt/src/qgpgmelistallkeysjob.cpp
+++ b/lang/qt/src/qgpgmelistallkeysjob.cpp
@@ -5,6 +5,8 @@
Copyright (c) 2004,2008 Klarälvdalens Datakonsult AB
Copyright (c) 2016 by Bundesamt für Sicherheit in der Informationstechnik
Software engineering by Intevation GmbH
+ 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
@@ -38,11 +40,13 @@
#include "qgpgmelistallkeysjob.h"
+#include "debug.h"
#include "key.h"
#include "context.h"
#include "engineinfo.h"
#include "global.h"
#include "keylistresult.h"
+#include "qgpgme_debug.h"
#include <gpg-error.h>
@@ -162,12 +166,20 @@ static KeyListResult do_list_keys(Context *ctx, std::vector<Key> &keys)
return result;
}
-static QGpgMEListAllKeysJob::result_type list_keys(Context *ctx, bool mergeKeys)
+static QGpgMEListAllKeysJob::result_type list_keys(Context *ctx, bool mergeKeys, ListAllKeysJob::Options options)
{
if (GpgME::engineInfo(GpgME::GpgEngine).engineVersion() < "2.1.0") {
return list_keys_legacy(ctx, mergeKeys);
}
+ if (options & ListAllKeysJob::DisableAutomaticTrustDatabaseCheck) {
+ auto err = ctx->setFlag("no-auto-check-trustdb", "1");
+ if (err) {
+ // ignore error, but log a warning
+ qCWarning(QGPGME_LOG) << "Setting context flag no-auto-check-trustdb failed:" << err;
+ }
+ }
+
std::vector<Key> keys;
KeyListResult r = do_list_keys(ctx, keys);
std::sort(keys.begin(), keys.end(), ByFingerprint<std::less>());
@@ -182,13 +194,13 @@ static QGpgMEListAllKeysJob::result_type list_keys(Context *ctx, bool mergeKeys)
Error QGpgMEListAllKeysJob::start(bool mergeKeys)
{
- run(std::bind(&list_keys, std::placeholders::_1, mergeKeys));
+ run(std::bind(&list_keys, std::placeholders::_1, mergeKeys, options()));
return Error();
}
KeyListResult QGpgMEListAllKeysJob::exec(std::vector<Key> &pub, std::vector<Key> &sec, bool mergeKeys)
{
- const result_type r = list_keys(context(), mergeKeys);
+ const result_type r = list_keys(context(), mergeKeys, options());
resultHook(r);
pub = std::get<1>(r);
sec = std::get<2>(r);