qt: Remove job for refreshing OpenPGP keys

* lang/qt/src/qgpgmerefreshopenpgpkeysjob.cpp,
lang/qt/src/qgpgmerefreshopenpgpkeysjob.h,
lang/qt/src/refreshopenpgpkeysjob.h: Remove.
* lang/qt/src/Makefile.am, lang/qt/src/job.cpp: Update accordingly.
* lang/qt/src/protocol.h (class Protocol): Remove pure virtual member
function refreshOpenPGPKeysJob.
* lang/qt/src/protocol_p.h (Protocol::refreshOpenPGPKeysJob): Remove.

* lang/qt/tests/run-refreshkeysjob.cpp (main): Use ReceiveKeysJob for
OpenPGP keys.
--

The RefreshOpenPGPKeysJob did more than it was intended to do, e.g. it
imported new keys with the email addresses of the key to be refreshed
via the configured auto-key-locate methods, but only a refresh from the
key servers is wanted. For this we can use the ReceiveKeysJob.

This commit mostly reverts the commits
e12861f18c
c64a8daf50

The changes are source- and binary-compatible to the last release.

GnuPG-bug-id: 5951
This commit is contained in:
Ingo Klöcker 2022-08-04 12:06:15 +02:00
parent cc37447b62
commit c3b183831d
8 changed files with 5 additions and 303 deletions

View File

@ -35,7 +35,6 @@ qgpgme_sources = \
qgpgmeimportjob.cpp qgpgmekeygenerationjob.cpp qgpgmekeylistjob.cpp \ qgpgmeimportjob.cpp qgpgmekeygenerationjob.cpp qgpgmekeylistjob.cpp \
qgpgmelistallkeysjob.cpp qgpgmenewcryptoconfig.cpp \ qgpgmelistallkeysjob.cpp qgpgmenewcryptoconfig.cpp \
qgpgmereceivekeysjob.cpp \ qgpgmereceivekeysjob.cpp \
qgpgmerefreshopenpgpkeysjob.cpp \
qgpgmerefreshsmimekeysjob.cpp \ qgpgmerefreshsmimekeysjob.cpp \
qgpgmerevokekeyjob.cpp \ qgpgmerevokekeyjob.cpp \
qgpgmesignencryptjob.cpp \ qgpgmesignencryptjob.cpp \
@ -80,7 +79,6 @@ qgpgme_headers= \
signencryptjob.h \ signencryptjob.h \
verifyopaquejob.h \ verifyopaquejob.h \
refreshkeysjob.h \ refreshkeysjob.h \
refreshopenpgpkeysjob.h \
cryptoconfig.h \ cryptoconfig.h \
deletejob.h \ deletejob.h \
importfromkeyserverjob.h \ importfromkeyserverjob.h \
@ -126,7 +124,6 @@ camelcase_headers= \
SignEncryptJob \ SignEncryptJob \
VerifyOpaqueJob \ VerifyOpaqueJob \
RefreshKeysJob \ RefreshKeysJob \
RefreshOpenPGPKeysJob \
CryptoConfig \ CryptoConfig \
DeleteJob \ DeleteJob \
ImportFromKeyserverJob \ ImportFromKeyserverJob \
@ -165,7 +162,6 @@ private_qgpgme_headers = \
qgpgmekeylistjob.h \ qgpgmekeylistjob.h \
qgpgmelistallkeysjob.h \ qgpgmelistallkeysjob.h \
qgpgmereceivekeysjob.h \ qgpgmereceivekeysjob.h \
qgpgmerefreshopenpgpkeysjob.h \
qgpgmerefreshsmimekeysjob.h \ qgpgmerefreshsmimekeysjob.h \
qgpgmerevokekeyjob.h \ qgpgmerevokekeyjob.h \
qgpgmesignencryptjob.h \ qgpgmesignencryptjob.h \
@ -220,7 +216,6 @@ qgpgme_moc_sources = \
qgpgmekeylistjob.moc \ qgpgmekeylistjob.moc \
qgpgmelistallkeysjob.moc \ qgpgmelistallkeysjob.moc \
qgpgmereceivekeysjob.moc \ qgpgmereceivekeysjob.moc \
qgpgmerefreshopenpgpkeysjob.moc \
qgpgmerefreshsmimekeysjob.moc \ qgpgmerefreshsmimekeysjob.moc \
qgpgmerevokekeyjob.moc \ qgpgmerevokekeyjob.moc \
qgpgmesignencryptjob.moc \ qgpgmesignencryptjob.moc \
@ -234,7 +229,6 @@ qgpgme_moc_sources = \
qgpgmetofupolicyjob.moc \ qgpgmetofupolicyjob.moc \
receivekeysjob.moc \ receivekeysjob.moc \
refreshkeysjob.moc \ refreshkeysjob.moc \
refreshopenpgpkeysjob.moc \
revokekeyjob.moc \ revokekeyjob.moc \
signencryptjob.moc \ signencryptjob.moc \
signjob.moc \ signjob.moc \

View File

@ -61,7 +61,6 @@
#include "downloadjob.h" #include "downloadjob.h"
#include "deletejob.h" #include "deletejob.h"
#include "refreshkeysjob.h" #include "refreshkeysjob.h"
#include "refreshopenpgpkeysjob.h"
#include "addexistingsubkeyjob.h" #include "addexistingsubkeyjob.h"
#include "adduseridjob.h" #include "adduseridjob.h"
#include "specialjob.h" #include "specialjob.h"
@ -158,7 +157,6 @@ make_job_subclass(AbstractImportJob)
make_job_subclass_ext(ImportJob, AbstractImportJob) make_job_subclass_ext(ImportJob, AbstractImportJob)
make_job_subclass_ext(ImportFromKeyserverJob, AbstractImportJob) make_job_subclass_ext(ImportFromKeyserverJob, AbstractImportJob)
make_job_subclass_ext(ReceiveKeysJob, AbstractImportJob) make_job_subclass_ext(ReceiveKeysJob, AbstractImportJob)
make_job_subclass_ext(RefreshOpenPGPKeysJob, AbstractImportJob)
make_job_subclass(ExportJob) make_job_subclass(ExportJob)
make_job_subclass(ChangeExpiryJob) make_job_subclass(ChangeExpiryJob)
make_job_subclass(ChangeOwnerTrustJob) make_job_subclass(ChangeOwnerTrustJob)
@ -202,7 +200,6 @@ make_job_subclass(RevokeKeyJob)
#include "downloadjob.moc" #include "downloadjob.moc"
#include "deletejob.moc" #include "deletejob.moc"
#include "refreshkeysjob.moc" #include "refreshkeysjob.moc"
#include "refreshopenpgpkeysjob.moc"
#include "addexistingsubkeyjob.moc" #include "addexistingsubkeyjob.moc"
#include "adduseridjob.moc" #include "adduseridjob.moc"
#include "specialjob.moc" #include "specialjob.moc"

View File

@ -59,7 +59,6 @@ class VerifyOpaqueJob;
class SignEncryptJob; class SignEncryptJob;
class DecryptVerifyJob; class DecryptVerifyJob;
class RefreshKeysJob; class RefreshKeysJob;
class RefreshOpenPGPKeysJob;
class ChangeExpiryJob; class ChangeExpiryJob;
class ChangeOwnerTrustJob; class ChangeOwnerTrustJob;
class ChangePasswdJob; class ChangePasswdJob;
@ -140,7 +139,7 @@ public:
/** /**
* For S/MIME keys this job performs a full validation check of the keys * For S/MIME keys this job performs a full validation check of the keys
* with updated CRLs. * with updated CRLs.
* For OpenPGP keys, use refreshOpenPGPKeysJob. * For OpenPGP keys, use receiveKeysJob.
*/ */
virtual RefreshKeysJob *refreshKeysJob() const = 0; virtual RefreshKeysJob *refreshKeysJob() const = 0;
virtual ChangeExpiryJob *changeExpiryJob() const = 0; virtual ChangeExpiryJob *changeExpiryJob() const = 0;
@ -183,13 +182,6 @@ public:
virtual ReceiveKeysJob *receiveKeysJob() const = 0; virtual ReceiveKeysJob *receiveKeysJob() const = 0;
virtual RevokeKeyJob *revokeKeyJob() const = 0; virtual RevokeKeyJob *revokeKeyJob() const = 0;
/**
* This job performs a refresh of OpenPGP keys via the external methods
* as defined by the \c auto-key-locate option and via an import from the
* configured keyserver.
*/
virtual RefreshOpenPGPKeysJob *refreshOpenPGPKeysJob() const = 0;
}; };
/** Obtain a reference to the OpenPGP Protocol. /** Obtain a reference to the OpenPGP Protocol.

View File

@ -42,7 +42,6 @@
#include "qgpgmelistallkeysjob.h" #include "qgpgmelistallkeysjob.h"
#include "qgpgmedecryptjob.h" #include "qgpgmedecryptjob.h"
#include "qgpgmedecryptverifyjob.h" #include "qgpgmedecryptverifyjob.h"
#include "qgpgmerefreshopenpgpkeysjob.h"
#include "qgpgmerefreshsmimekeysjob.h" #include "qgpgmerefreshsmimekeysjob.h"
#include "qgpgmedeletejob.h" #include "qgpgmedeletejob.h"
#include "qgpgmedownloadjob.h" #include "qgpgmedownloadjob.h"
@ -291,19 +290,6 @@ public:
return new QGpgME::QGpgMERefreshSMIMEKeysJob; return new QGpgME::QGpgMERefreshSMIMEKeysJob;
} }
QGpgME::RefreshOpenPGPKeysJob *refreshOpenPGPKeysJob() const Q_DECL_OVERRIDE
{
if (mProtocol != GpgME::OpenPGP) {
return nullptr;
}
GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
if (!context) {
return nullptr;
}
return new QGpgME::QGpgMERefreshOpenPGPKeysJob{context};
}
QGpgME::DownloadJob *downloadJob(bool armor) const Q_DECL_OVERRIDE QGpgME::DownloadJob *downloadJob(bool armor) const Q_DECL_OVERRIDE
{ {
GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol); GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);

View File

@ -1,130 +0,0 @@
/*
qgpgmerefreshopenpgpkeysjob.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 "qgpgmerefreshopenpgpkeysjob.h"
#include "qgpgmekeylistjob.h"
#include "qgpgmereceivekeysjob.h"
#include "util.h"
#include <context.h>
#include <key.h>
#include <memory>
#include "qgpgme_debug.h"
using namespace QGpgME;
using namespace GpgME;
QStringList toEmailAddresses(const std::vector<GpgME::Key> &keys)
{
const auto numUserIDs = std::accumulate(std::begin(keys), std::end(keys), 0, [](auto num, const auto &key) {
return num + key.numUserIDs();
});
QStringList emails;
emails.reserve(numUserIDs);
emails = std::accumulate(std::begin(keys), std::end(keys), emails, [](auto &emails, const auto &key) {
const auto userIDs = key.userIDs();
emails = std::accumulate(std::begin(userIDs), std::end(userIDs), emails, [](auto &emails, const auto &userID) {
if (!userID.isRevoked() && !userID.addrSpec().empty()) {
emails.push_back(QString::fromStdString(userID.addrSpec()));
}
return emails;
});
return emails;
});
return emails;
}
QGpgMERefreshOpenPGPKeysJob::QGpgMERefreshOpenPGPKeysJob(Context *context)
: mixin_type{context}
{
lateInitialization();
}
QGpgMERefreshOpenPGPKeysJob::~QGpgMERefreshOpenPGPKeysJob() = default;
static ImportResult locate_external_keys(Context *ctx, const std::vector<Key> &keys)
{
Context::KeyListModeSaver saver{ctx};
ctx->setKeyListMode(GpgME::LocateExternal);
const auto emails = toEmailAddresses(keys);
std::vector<Key> dummy;
auto job = std::unique_ptr<KeyListJob>{new QGpgMEKeyListJob{ctx}};
(void) job->exec(emails, false, dummy);
const auto result = ctx->importResult();
job.release();
return result;
}
static ImportResult receive_keys(Context *ctx, const std::vector<Key> &keys)
{
const auto fprs = toFingerprints(keys);
auto job = std::unique_ptr<ReceiveKeysJob>{new QGpgMEReceiveKeysJob{ctx}};
const auto result = job->exec(fprs);
job.release();
return result;
}
static QGpgMERefreshOpenPGPKeysJob::result_type refresh_keys(Context *ctx, const std::vector<Key> &keys)
{
ImportResult result;
result = locate_external_keys(ctx, keys);
if (!result.error()) {
const auto res2 = receive_keys(ctx, keys);
if (!res2.error()) {
result.mergeWith(res2);
}
}
return std::make_tuple(result, QString{}, Error{});
}
GpgME::Error QGpgMERefreshOpenPGPKeysJob::start(const std::vector<GpgME::Key> &keys)
{
run([keys](Context *ctx) { return refresh_keys(ctx, keys); });
return Error{};
}
#include "qgpgmerefreshopenpgpkeysjob.moc"

View File

@ -1,70 +0,0 @@
/*
qgpgmerefreshopenpgpkeysjob.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 <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.
*/
#ifndef __QGPGME_QGPGMEREFRESHOPENPGPKEYSJOB_H__
#define __QGPGME_QGPGMEREFRESHOPENPGPKEYSJOB_H__
#include "refreshopenpgpkeysjob.h"
#include "threadedjobmixin.h"
#ifdef BUILDING_QGPGME
# include "importresult.h"
#else
# include <gpgme++/importresult.h>
#endif
namespace QGpgME
{
class QGpgMERefreshOpenPGPKeysJob
#ifdef Q_MOC_RUN
: public RefreshOpenPGPKeysJob
#else
: public _detail::ThreadedJobMixin<RefreshOpenPGPKeysJob, std::tuple<GpgME::ImportResult, QString, GpgME::Error>>
#endif
{
Q_OBJECT
#ifdef Q_MOC_RUN
public Q_SLOTS:
void slotFinished();
#endif
public:
explicit QGpgMERefreshOpenPGPKeysJob(GpgME::Context *context);
~QGpgMERefreshOpenPGPKeysJob() override;
GpgME::Error start(const std::vector<GpgME::Key> &keys) override;
};
}
#endif // __QGPGME_QGPGMEREFRESHOPENPGPKEYSJOB_H__

View File

@ -1,67 +0,0 @@
/*
refreshopenpgpkeysjob.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 <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.
*/
#ifndef __KLEO_REFRESHOPENPGPKEYSJOB_H__
#define __KLEO_REFRESHOPENPGPKEYSJOB_H__
#include "abstractimportjob.h"
#include "qgpgme_export.h"
#include <vector>
namespace GpgME
{
class Error;
class Key;
}
namespace QGpgME
{
class QGPGME_EXPORT RefreshOpenPGPKeysJob : public AbstractImportJob
{
Q_OBJECT
protected:
explicit RefreshOpenPGPKeysJob(QObject *parent);
public:
~RefreshOpenPGPKeysJob() override;
/**
Starts a refresh of the \a keys.
*/
virtual GpgME::Error start(const std::vector<GpgME::Key> &keys) = 0;
};
}
#endif // __KLEO_REFRESHOPENPGPKEYSJOB_H__

View File

@ -36,7 +36,7 @@
#include <protocol.h> #include <protocol.h>
#include <refreshkeysjob.h> #include <refreshkeysjob.h>
#include <refreshopenpgpkeysjob.h> #include <receivekeysjob.h>
#include <QCoreApplication> #include <QCoreApplication>
#include <QDebug> #include <QDebug>
@ -120,16 +120,16 @@ int main(int argc, char **argv)
std::cout << "Refreshing " << displayName(key.protocol()) << " key " << key.userID(0).id() << std::endl; std::cout << "Refreshing " << displayName(key.protocol()) << " key " << key.userID(0).id() << std::endl;
if (key.protocol() == GpgME::OpenPGP) { if (key.protocol() == GpgME::OpenPGP) {
auto job = QGpgME::openpgp()->refreshOpenPGPKeysJob(); auto job = QGpgME::openpgp()->receiveKeysJob();
if (!job) { if (!job) {
std::cerr << "Error: Could not create job to refresh OpenPGP key" << std::endl; std::cerr << "Error: Could not create job to refresh OpenPGP key" << std::endl;
return 1; return 1;
} }
QObject::connect(job, &QGpgME::RefreshOpenPGPKeysJob::result, &app, [](const GpgME::ImportResult &result, const QString &, const GpgME::Error &) { QObject::connect(job, &QGpgME::ReceiveKeysJob::result, &app, [](const GpgME::ImportResult &result, const QString &, const GpgME::Error &) {
std::cout << "Result: " << result << std::endl; std::cout << "Result: " << result << std::endl;
qApp->quit(); qApp->quit();
}); });
const auto err = job->start({key}); const auto err = job->start({QString::fromLatin1(key.primaryFingerprint())});
if (err) { if (err) {
std::cerr << "Error: " << err.asString() << std::endl; std::cerr << "Error: " << err.asString() << std::endl;
return 1; return 1;