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
This commit is contained in:
parent
d96e8a7a6b
commit
41297520da
4
NEWS
4
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)
|
||||
|
@ -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 \
|
||||
|
@ -72,6 +72,7 @@
|
||||
#include "quickjob.h"
|
||||
#include "gpgcardjob.h"
|
||||
#include "receivekeysjob.h"
|
||||
#include "revokekeyjob.h"
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QDebug>
|
||||
@ -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"
|
||||
|
@ -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.
|
||||
|
@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
96
lang/qt/src/qgpgmerevokekeyjob.cpp
Normal file
96
lang/qt/src/qgpgmerevokekeyjob.cpp
Normal file
@ -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 <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 "qgpgmerevokekeyjob.h"
|
||||
|
||||
#include "dataprovider.h"
|
||||
|
||||
#include <context.h>
|
||||
#include <data.h>
|
||||
#include <gpgrevokekeyeditinteractor.h>
|
||||
#include <key.h>
|
||||
|
||||
#include <gpg-error.h>
|
||||
|
||||
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<std::string> &description)
|
||||
{
|
||||
std::unique_ptr<GpgRevokeKeyEditInteractor> 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<EditInteractor>(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<std::string> &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<std::string> &description)
|
||||
{
|
||||
const result_type r = revoke_key(context(), key, reason, description);
|
||||
resultHook(r);
|
||||
return std::get<0>(r);
|
||||
}
|
||||
|
||||
#include "qgpgmerevokekeyjob.moc"
|
70
lang/qt/src/qgpgmerevokekeyjob.h
Normal file
70
lang/qt/src/qgpgmerevokekeyjob.h
Normal file
@ -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 <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_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<RevokeKeyJob>
|
||||
#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<std::string> &description = {}) override;
|
||||
|
||||
GpgME::Error exec(const GpgME::Key &key,
|
||||
GpgME::RevocationReason reason = GpgME::RevocationReason::Unspecified,
|
||||
const std::vector<std::string> &description = {}) override;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // __QGPGME_QGPGMEREVOKEKEYJOB_H__
|
86
lang/qt/src/revokekeyjob.h
Normal file
86
lang/qt/src/revokekeyjob.h
Normal file
@ -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 <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_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<std::string> &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<std::string> &description = {}) = 0;
|
||||
|
||||
Q_SIGNALS:
|
||||
void result(const GpgME::Error &result, const QString &auditLogAsHtml = {}, const GpgME::Error &auditLogError = {});
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // __QGPGME_REVOKEKEYJOB_H__
|
@ -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~ \
|
||||
|
210
lang/qt/tests/t-revokekey.cpp
Normal file
210
lang/qt/tests/t-revokekey.cpp
Normal file
@ -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 <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 "t-support.h"
|
||||
|
||||
#include <protocol.h>
|
||||
#include <revokekeyjob.h>
|
||||
|
||||
#include <QSignalSpy>
|
||||
#include <QTest>
|
||||
|
||||
#include <context.h>
|
||||
#include <data.h>
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
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<RevokeKeyJob>{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<RevokeKeyJob>{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<RevokeKeyJob>{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<RevokeKeyJob>{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<QTemporaryDir> mGnupgHomeTestCopy;
|
||||
};
|
||||
|
||||
QTEST_MAIN(RevokeKeyJobTest)
|
||||
|
||||
#include "t-revokekey.moc"
|
Loading…
Reference in New Issue
Block a user