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
This commit is contained in:
Ingo Klöcker 2022-11-04 10:39:30 +01:00
parent 4f874ea431
commit b6593bda1f
No known key found for this signature in database
GPG Key ID: F5A5D1692277A1E9
5 changed files with 102 additions and 4 deletions

7
NEWS
View File

@ -15,12 +15,19 @@ Noteworthy changes in version 1.18.1 (unreleased)
* cpp: Allow setting the curve to use when generating ECC keys * cpp: Allow setting the curve to use when generating ECC keys
for smart cards. [T4429] 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: * Interface changes relative to the 1.18.0 release:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
gpgme_get_ctx_flag EXTENDED: New flag 'no-auto-check-trustdb'. gpgme_get_ctx_flag EXTENDED: New flag 'no-auto-check-trustdb'.
gpgme_set_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::Curve NEW.
cpp: GpgGenCardKeyInteractor::setCurve 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) Noteworthy changes in version 1.18.0 (2022-08-10)

View File

@ -41,7 +41,7 @@ qgpgme_sources = \
qgpgmedecryptverifyjob.cpp qgpgmedeletejob.cpp qgpgmedownloadjob.cpp \ qgpgmedecryptverifyjob.cpp qgpgmedeletejob.cpp qgpgmedownloadjob.cpp \
qgpgmeencryptjob.cpp qgpgmeexportjob.cpp qgpgmeimportfromkeyserverjob.cpp \ qgpgmeencryptjob.cpp qgpgmeexportjob.cpp qgpgmeimportfromkeyserverjob.cpp \
qgpgmeimportjob.cpp qgpgmekeygenerationjob.cpp qgpgmekeylistjob.cpp \ qgpgmeimportjob.cpp qgpgmekeygenerationjob.cpp qgpgmekeylistjob.cpp \
qgpgmelistallkeysjob.cpp qgpgmenewcryptoconfig.cpp \ listallkeysjob.cpp qgpgmelistallkeysjob.cpp qgpgmenewcryptoconfig.cpp \
qgpgmereceivekeysjob.cpp \ qgpgmereceivekeysjob.cpp \
qgpgmerefreshsmimekeysjob.cpp \ qgpgmerefreshsmimekeysjob.cpp \
qgpgmerevokekeyjob.cpp \ qgpgmerevokekeyjob.cpp \

View File

@ -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 <dev@ingo-kloecker.de>
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;
}

View File

@ -5,6 +5,8 @@
Copyright (c) 2004 Klarälvdalens Datakonsult AB Copyright (c) 2004 Klarälvdalens Datakonsult AB
Copyright (c) 2016 by Bundesamt für Sicherheit in der Informationstechnik Copyright (c) 2016 by Bundesamt für Sicherheit in der Informationstechnik
Software engineering by Intevation GmbH Software engineering by Intevation GmbH
Copyright (c) 2022 g10 Code GmbH
Software engineering by Ingo Klöcker <dev@ingo-kloecker.de>
QGpgME is free software; you can redistribute it and/or QGpgME is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as modify it under the terms of the GNU General Public License as
@ -74,12 +76,22 @@ namespace QGpgME
class QGPGME_EXPORT ListAllKeysJob : public Job class QGPGME_EXPORT ListAllKeysJob : public Job
{ {
Q_OBJECT Q_OBJECT
public:
enum Option {
Default = 0x00,
DisableAutomaticTrustDatabaseCheck = 0x01,
};
Q_DECLARE_FLAGS(Options, Option)
protected: protected:
explicit ListAllKeysJob(QObject *parent); explicit ListAllKeysJob(QObject *parent);
public: public:
~ListAllKeysJob(); ~ListAllKeysJob();
void setOptions(Options options);
Options options() const;
/** /**
Starts the listallkeys operation. In general, all keys are Starts the listallkeys operation. In general, all keys are
returned (however, the backend is free to truncate the result 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()); 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__ #endif // __KLEO_LISTALLKEYSJOB_H__

View File

@ -5,6 +5,8 @@
Copyright (c) 2004,2008 Klarälvdalens Datakonsult AB Copyright (c) 2004,2008 Klarälvdalens Datakonsult AB
Copyright (c) 2016 by Bundesamt für Sicherheit in der Informationstechnik Copyright (c) 2016 by Bundesamt für Sicherheit in der Informationstechnik
Software engineering by Intevation GmbH Software engineering by Intevation GmbH
Copyright (c) 2022 g10 Code GmbH
Software engineering by Ingo Klöcker <dev@ingo-kloecker.de>
QGpgME is free software; you can redistribute it and/or QGpgME is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as modify it under the terms of the GNU General Public License as
@ -38,11 +40,13 @@
#include "qgpgmelistallkeysjob.h" #include "qgpgmelistallkeysjob.h"
#include "debug.h"
#include "key.h" #include "key.h"
#include "context.h" #include "context.h"
#include "engineinfo.h" #include "engineinfo.h"
#include "global.h" #include "global.h"
#include "keylistresult.h" #include "keylistresult.h"
#include "qgpgme_debug.h"
#include <gpg-error.h> #include <gpg-error.h>
@ -162,12 +166,20 @@ static KeyListResult do_list_keys(Context *ctx, std::vector<Key> &keys)
return result; 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") { if (GpgME::engineInfo(GpgME::GpgEngine).engineVersion() < "2.1.0") {
return list_keys_legacy(ctx, mergeKeys); 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; std::vector<Key> keys;
KeyListResult r = do_list_keys(ctx, keys); KeyListResult r = do_list_keys(ctx, keys);
std::sort(keys.begin(), keys.end(), ByFingerprint<std::less>()); 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) 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(); return Error();
} }
KeyListResult QGpgMEListAllKeysJob::exec(std::vector<Key> &pub, std::vector<Key> &sec, bool mergeKeys) 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); resultHook(r);
pub = std::get<1>(r); pub = std::get<1>(r);
sec = std::get<2>(r); sec = std::get<2>(r);