diff --git a/lang/qt/src/importjob.h b/lang/qt/src/importjob.h index 03b0bcf9..24589852 100644 --- a/lang/qt/src/importjob.h +++ b/lang/qt/src/importjob.h @@ -1,93 +1,97 @@ /* importjob.h This file is part of qgpgme, the Qt API binding for gpgme Copyright (c) 2004 Klarälvdalens Datakonsult AB Copyright (c) 2016 by Bundesamt für Sicherheit in der Informationstechnik Software engineering by Intevation GmbH 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_IMPORTJOB_H__ #define __KLEO_IMPORTJOB_H__ #include "abstractimportjob.h" #include "qgpgme_export.h" #include -#include +#ifdef BUILDING_QGPGME +# include +#else +# include +#endif namespace GpgME { class Error; class ImportResult; } namespace QGpgME { /** @short An abstract base class for asynchronous importers To use a ImportJob, first obtain an instance from the CryptoBackend implementation, connect the progress() and result() signals to suitable slots and then start the import with a call to start(). This call might fail, in which case the ImportJob instance will have scheduled it's own destruction with a call to QObject::deleteLater(). After result() is emitted, the ImportJob will schedule it's own destruction by calling QObject::deleteLater(). */ class QGPGME_EXPORT ImportJob : public AbstractImportJob { Q_OBJECT protected: explicit ImportJob(QObject *parent); public: ~ImportJob() override; void setImportFilter(const QString &filter); QString importFilter() const; void setKeyOrigin(GpgME::Key::Origin origin, const QString &url = {}); GpgME::Key::Origin keyOrigin() const; QString keyOriginUrl() const; /** Starts the importing operation. \a keyData contains the data to import from. */ virtual GpgME::Error start(const QByteArray &keyData) = 0; virtual GpgME::ImportResult exec(const QByteArray &keyData) = 0; }; } #endif // __KLEO_IMPORTJOB_H__ diff --git a/lang/qt/src/qgpgmeimportjob.cpp b/lang/qt/src/qgpgmeimportjob.cpp index ebd8a269..d609c5f1 100644 --- a/lang/qt/src/qgpgmeimportjob.cpp +++ b/lang/qt/src/qgpgmeimportjob.cpp @@ -1,134 +1,134 @@ /* qgpgmeimportjob.cpp This file is part of qgpgme, the Qt API binding for gpgme Copyright (c) 2004,2008 Klarälvdalens Datakonsult AB Copyright (c) 2016 by Bundesamt für Sicherheit in der Informationstechnik Software engineering by Intevation GmbH 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 "qgpgmeimportjob.h" #include "dataprovider.h" -#include -#include -#include +#include +#include +#include using namespace QGpgME; using namespace GpgME; QGpgMEImportJob::QGpgMEImportJob(Context *context) : mixin_type(context) { lateInitialization(); } QGpgMEImportJob::~QGpgMEImportJob() = default; static const char *originToString(Key::Origin origin) { static const std::map mapping = { { Key::OriginUnknown, "unknown" }, { Key::OriginKS, "ks" }, { Key::OriginDane, "dane" }, { Key::OriginWKD, "wkd" }, { Key::OriginURL, "url" }, { Key::OriginFile, "file" }, { Key::OriginSelf, "self" }, }; const auto it = mapping.find(origin); return (it != std::end(mapping)) ? it->second : nullptr; } static QGpgMEImportJob::result_type import_qba(Context *ctx, const QByteArray &certData, const QString &importFilter, Key::Origin keyOrigin, const QString &keyOriginUrl) { if (!importFilter.isEmpty()) { ctx->setFlag("import-filter", importFilter.toStdString().c_str()); } if (keyOrigin != Key::OriginUnknown) { if (const auto origin = originToString(keyOrigin)) { std::string value{origin}; if (!keyOriginUrl.isEmpty()) { value += ","; value += keyOriginUrl.toStdString(); } ctx->setFlag("key-origin", value.c_str()); } } QGpgME::QByteArrayDataProvider dp(certData); Data data(&dp); ImportResult res = ctx->importKeys(data); // HACK: If the import failed with an error, then check if res.imports() // contains only import statuses with "bad passphrase" error; if yes, this // means that the user probably entered a wrong password to decrypt an // encrypted key for import. In this case, return a result with "bad // passphrase" error instead of the original error. // We check if all import statuses instead of any import status has a // "bad passphrase" error to avoid breaking imports that partially worked. // See https://dev.gnupg.org/T5713. const auto imports = res.imports(); if (res.error() && !imports.empty() && std::all_of(std::begin(imports), std::end(imports), [](const Import &import) { return import.error().code() == GPG_ERR_BAD_PASSPHRASE; })) { res = ImportResult{Error{GPG_ERR_BAD_PASSPHRASE}}; } Error ae; const QString log = _detail::audit_log_as_html(ctx, ae); return std::make_tuple(res, log, ae); } Error QGpgMEImportJob::start(const QByteArray &certData) { run(std::bind(&import_qba, std::placeholders::_1, certData, importFilter(), keyOrigin(), keyOriginUrl())); return Error(); } GpgME::ImportResult QGpgME::QGpgMEImportJob::exec(const QByteArray &keyData) { const result_type r = import_qba(context(), keyData, importFilter(), keyOrigin(), keyOriginUrl()); resultHook(r); return mResult; } // PENDING(marc) implement showErrorDialog() void QGpgME::QGpgMEImportJob::resultHook(const result_type &tuple) { mResult = std::get<0>(tuple); } #include "qgpgmeimportjob.moc" diff --git a/lang/qt/src/qgpgmewkdlookupjob.cpp b/lang/qt/src/qgpgmewkdlookupjob.cpp index b8622167..266da0d5 100644 --- a/lang/qt/src/qgpgmewkdlookupjob.cpp +++ b/lang/qt/src/qgpgmewkdlookupjob.cpp @@ -1,183 +1,183 @@ /* qgpgmewkdlookupjob.cpp This file is part of qgpgme, the Qt API binding for gpgme Copyright (c) 2021 g10 Code GmbH Software engineering by Ingo Klöcker 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 "qgpgmewkdlookupjob.h" #include "qgpgme_debug.h" -#include -#include -#include +#include +#include +#include #include using namespace QGpgME; using namespace GpgME; QGpgMEWKDLookupJob::QGpgMEWKDLookupJob(Context *context) : mixin_type{context} { lateInitialization(); } QGpgMEWKDLookupJob::~QGpgMEWKDLookupJob() = default; static GpgME::Error startDirmngr(Context *assuanCtx) { Error err; auto spawnCtx = std::unique_ptr{Context::createForEngine(SpawnEngine, &err)}; if (err) { qCDebug(QGPGME_LOG) << "Error: Failed to get context for spawn engine (" << err.asString() << ")"; } const auto dirmngrProgram = GpgME::dirInfo("dirmngr-name"); const auto homedir = GpgME::dirInfo("homedir"); const char *argv[] = { dirmngrProgram, "--homedir", homedir, "--daemon", NULL }; auto ignoreIO = Data{Data::null}; if (!err) { qCDebug(QGPGME_LOG) << "Starting dirmngr ..."; err = spawnCtx->spawnAsync(dirmngrProgram, argv, ignoreIO, ignoreIO, ignoreIO, Context::SpawnDetached); } if (!err) { // wait for socket to become available int cnt = 0; do { ++cnt; qCDebug(QGPGME_LOG) << "Waiting for dirmngr to start ..."; QThread::msleep(250 * cnt); err = assuanCtx->assuanTransact("GETINFO version"); } while (err.code() == GPG_ERR_ASS_CONNECT_FAILED && cnt < 5); } return err; } static GpgME::Error setUpDirmngrAssuanConnection(Context *ctx) { Error err; const std::string dirmngrSocket = GpgME::dirInfo("dirmngr-socket"); err = ctx->setEngineFileName(dirmngrSocket.c_str()); if (!err) { err = ctx->setEngineHomeDirectory(""); } if (!err) { // try do connect to dirmngr err = ctx->assuanTransact("GETINFO version"); if (err.code() == GPG_ERR_ASS_CONNECT_FAILED) { err = startDirmngr(ctx); } } return err; } static GpgME::Error run_wkd_get(Context *ctx, const std::string &email) { Error err; const auto cmd = std::string{"WKD_GET "} + email; err = ctx->assuanTransact(cmd.c_str()); if (err.code() == GPG_ERR_NO_NAME || err.code() == GPG_ERR_NO_DATA) { // ignore those benign errors; GPG_ERR_NO_NAME indicates that the domain // doesn't exist (on first request); GPG_ERR_NO_DATA indicates that // no key for email is available via WKD or that the domain doesn't // support WKD or that the domain doesn't exist (on subsequent requests // using dirmngr's internal cache) qCDebug(QGPGME_LOG) << "WKD_GET returned" << err.asString() << "; ignoring..."; err = {}; } if (err) { qCDebug(QGPGME_LOG) << "WKD_GET failed with" << err.asString(); } return err; } static QGpgMEWKDLookupJob::result_type lookup_keys(Context *ctx, const QString &email) { WKDLookupResult result; Error err = setUpDirmngrAssuanConnection(ctx); const auto pattern = email.toUtf8().toStdString(); if (!err) { err = run_wkd_get(ctx, pattern); } if (!err) { const auto transaction = std::unique_ptr(dynamic_cast(ctx->takeLastAssuanTransaction().release())); const auto source = transaction->firstStatusLine("SOURCE"); const auto rawData = transaction->data(); if (rawData.size() == 0) { qCDebug(QGPGME_LOG) << "No key found for" << email; result = WKDLookupResult{pattern, GpgME::Data::null, {}, {}}; } else { qCDebug(QGPGME_LOG) << "Found key for" << email << "at" << source.c_str(); result = WKDLookupResult{pattern, GpgME::Data{rawData.c_str(), rawData.size()}, source, {}}; } } return std::make_tuple(err ? WKDLookupResult{pattern, err} : result, QString{}, Error{}); } Error QGpgMEWKDLookupJob::start(const QString &email) { run(std::bind(&lookup_keys, std::placeholders::_1, email)); return Error(); } WKDLookupResult QGpgMEWKDLookupJob::exec(const QString &email) { const result_type r = lookup_keys(context(), email); resultHook(r); return std::get<0>(r); } #include "qgpgmewkdlookupjob.moc" diff --git a/lang/qt/src/wkdlookupresult.cpp b/lang/qt/src/wkdlookupresult.cpp index ac1a89e9..c44b7370 100644 --- a/lang/qt/src/wkdlookupresult.cpp +++ b/lang/qt/src/wkdlookupresult.cpp @@ -1,117 +1,117 @@ /* wkdlookupresult.cpp - wraps the result of a WKDLookupJob This file is part of qgpgme, the Qt API binding for gpgme Copyright (c) 2021 g10 Code GmbH Software engineering by Ingo Klöcker 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 "wkdlookupresult.h" -#include +#include using namespace QGpgME; using namespace GpgME; class WKDLookupResult::Private { public: std::string pattern; GpgME::Data keyData; std::string source; }; WKDLookupResult::WKDLookupResult() = default; WKDLookupResult::~WKDLookupResult() = default; WKDLookupResult::WKDLookupResult(const std::string &pattern, const Error &error) : Result{error} , d{new Private{pattern, {}, {}}} { } WKDLookupResult::WKDLookupResult(const std::string &pattern, const Data &keyData, const std::string &source, const Error &error) : Result{error} , d{new Private{pattern, keyData, source}} { } WKDLookupResult::WKDLookupResult(const WKDLookupResult &other) : Result{other} { if (other.d) { d.reset(new Private{*other.d}); } } WKDLookupResult &WKDLookupResult::operator=(const WKDLookupResult &other) { auto tmp = other; swap(tmp); return *this; } WKDLookupResult::WKDLookupResult(WKDLookupResult &&other) = default; WKDLookupResult &WKDLookupResult::operator=(WKDLookupResult &&other) = default; void WKDLookupResult::swap(WKDLookupResult &other) noexcept { Result::swap(other); std::swap(this->d, other.d); } bool WKDLookupResult::isNull() const { return !d && !bool(error()); } std::string WKDLookupResult::pattern() const { return d ? d->pattern : std::string{}; } Data WKDLookupResult::keyData() const { return d ? d->keyData : Data{}; } std::string WKDLookupResult::source() const { return d ? d->source : std::string{}; } void QGpgME::swap(WKDLookupResult &a, WKDLookupResult &b) { a.swap(b); } diff --git a/lang/qt/src/wkdlookupresult.h b/lang/qt/src/wkdlookupresult.h index 5696fb6d..1e91d055 100644 --- a/lang/qt/src/wkdlookupresult.h +++ b/lang/qt/src/wkdlookupresult.h @@ -1,84 +1,88 @@ /* wkdlookupresult.h - wraps the result of a WKDLookupJob This file is part of qgpgme, the Qt API binding for gpgme Copyright (c) 2021 g10 Code GmbH Software engineering by Ingo Klöcker 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_WKDLOOKUPRESULT_H__ #define __QGPGME_WKDLOOKUPRESULT_H__ #include "qgpgme_export.h" -#include +#ifdef BUILDING_QGPGME +# include +#else +# include +#endif #include namespace GpgME { class Data; class Error; } namespace QGpgME { class QGPGME_EXPORT WKDLookupResult : public GpgME::Result { public: WKDLookupResult(); ~WKDLookupResult(); explicit WKDLookupResult(const std::string &pattern, const GpgME::Error &err); explicit WKDLookupResult(const std::string &pattern, const GpgME::Data &keyData, const std::string &source, const GpgME::Error &err); WKDLookupResult(const WKDLookupResult &other); WKDLookupResult &operator=(const WKDLookupResult &other); WKDLookupResult(WKDLookupResult &&other); WKDLookupResult &operator=(WKDLookupResult &&other); void swap(WKDLookupResult &other) noexcept; bool isNull() const; std::string pattern() const; GpgME::Data keyData() const; std::string source() const; private: class Private; std::unique_ptr d; }; QGPGME_EXPORT void swap(WKDLookupResult &a, WKDLookupResult &b); } #endif // __QGPGME_WKDLOOKUPRESULT_H__ diff --git a/lang/qt/tests/t-import.cpp b/lang/qt/tests/t-import.cpp index 456d7d64..33e242f0 100644 --- a/lang/qt/tests/t-import.cpp +++ b/lang/qt/tests/t-import.cpp @@ -1,169 +1,169 @@ /* t-import.cpp This file is part of qgpgme, the Qt API binding for gpgme Copyright (c) 2021 g10 Code GmbH Software engineering by Ingo Klöcker 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 "context.h" #include "engineinfo.h" #include "protocol.h" #include "importjob.h" -#include +#include #include #include #include #include using namespace QGpgME; using namespace GpgME; class ImportTest : public QGpgMETest { Q_OBJECT private: QTemporaryDir tempGpgHome; private Q_SLOTS: void initTestCase() { QGpgMETest::initTestCase(); QVERIFY2(tempGpgHome.isValid(), "Failed to create temporary GNUPGHOME"); qputenv("GNUPGHOME", tempGpgHome.path().toLocal8Bit()); } void testImportWithImportFilter() { if (GpgME::engineInfo(GpgME::GpgEngine).engineVersion() < "2.1.14") { QSKIP("gpg does not yet support the --import-filter option"); } // pub ed25519 2021-12-15 [SC] // E7A0841292ACC9465D3142652FB3A6F51FBF28A2 // uid [ultimate] importWithImportFilter@example.com // uid [ultimate] importWithImportFilter@example.net // sub cv25519 2021-12-15 [E] static const char keyFpr[] = "E7A0841292ACC9465D3142652FB3A6F51FBF28A2"; static const char keyData[] = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" "\n" "mDMEYbm2PhYJKwYBBAHaRw8BAQdACzxBWtNNsmJ6rzpZkjh1yBe+Ajsk9NR8umEu\n" "Da3HLgG0ImltcG9ydFdpdGhJbXBvcnRGaWx0ZXJAZXhhbXBsZS5uZXSIlAQTFgoA\n" "PBYhBOeghBKSrMlGXTFCZS+zpvUfvyiiBQJhubY+AhsDBQsJCAcCAyICAQYVCgkI\n" "CwIEFgIDAQIeBwIXgAAKCRAvs6b1H78oosRgAQCc/ke6q076nvzIE2UzT83JK/B6\n" "lxSV7Fb8bKltOMpvsAD+Phap3EzA8jdMyKoO0FM926bw5lX7QROfeZ/JBYqyPwC0\n" "ImltcG9ydFdpdGhJbXBvcnRGaWx0ZXJAZXhhbXBsZS5jb22IlAQTFgoAPBYhBOeg\n" "hBKSrMlGXTFCZS+zpvUfvyiiBQJhubZlAhsDBQsJCAcCAyICAQYVCgkICwIEFgID\n" "AQIeBwIXgAAKCRAvs6b1H78oohPWAQC/u9UXzkxRkrB2huaTZCsyimWEGZIMmxWd\n" "tE+vN9/IvQD/Yzia+xRS6yca3Yz6iW8xS844ZqRxvkUEHjtJXSOzagm4OARhubY+\n" "EgorBgEEAZdVAQUBAQdANQFjmDctY3N0/ELPZtj9tapwFs4vrmTVpx/SCfZmihkD\n" "AQgHiHgEGBYKACAWIQTnoIQSkqzJRl0xQmUvs6b1H78oogUCYbm2PgIbDAAKCRAv\n" "s6b1H78oovGyAP41ySzvvDpV7XDJBOAFxvWLmywa5IcO7Lrg7y1efoWj0AD+Kk/B\n" "s7jGLdoG51h670h50MMoYCANB6MwAdSP+qZUlQg=\n" "=/3O0\n" "-----END PGP PUBLIC KEY BLOCK-----\n"; auto *job = openpgp()->importJob(); job->setImportFilter(QLatin1String{"keep-uid=mbox = importWithImportFilter@example.net"}); connect(job, &ImportJob::result, this, [this](ImportResult result, QString, Error) { QVERIFY(!result.error()); QVERIFY(!result.imports().empty()); QVERIFY(result.numImported()); Q_EMIT asyncDone(); }); job->start(QByteArray{keyData}); QSignalSpy spy (this, SIGNAL(asyncDone())); QVERIFY(spy.wait()); auto ctx = Context::createForProtocol(GpgME::OpenPGP); GpgME::Error err; const auto key = ctx->key(keyFpr, err, false); QVERIFY(!key.isNull()); QCOMPARE(key.numUserIDs(), 1); QCOMPARE(key.userID(0).id(), "importWithImportFilter@example.net"); } void testImportWithKeyOrigin() { if (GpgME::engineInfo(GpgME::GpgEngine).engineVersion() < "2.1.22") { QSKIP("gpg does not yet support the --key-origin option"); } static const char keyFpr[] = "5C5C428FABCC20F6913464BCCA6FB442887289B3"; static const char keyData[] = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" "\n" "mDMEYbhuixYJKwYBBAHaRw8BAQdAulOM3IksCjdOJluEVlwalD8oZ5oa6wCw3EgW\n" "NswXXb60H2ltcG9ydFdpdGhLZXlPcmlnaW5AZXhhbXBsZS5uZXSIlAQTFgoAPBYh\n" "BFxcQo+rzCD2kTRkvMpvtEKIcomzBQJhuG6LAhsDBQsJCAcCAyICAQYVCgkICwIE\n" "FgIDAQIeBwIXgAAKCRDKb7RCiHKJs+cIAQDaeoOw1OCAGpZQb8xJmLJHul5dLLzU\n" "RBdHauMx9NROmQEA23QUVedc7walQjNKFzyIJA/YqRdbAKPiLonRBmxk9Ay4OARh\n" "uG6LEgorBgEEAZdVAQUBAQdAMVdO9mNWIP/q8PtNOnBGlPyhx/vs07sF5sXk50A+\n" "61QDAQgHiHgEGBYKACAWIQRcXEKPq8wg9pE0ZLzKb7RCiHKJswUCYbhuiwIbDAAK\n" "CRDKb7RCiHKJs/x6AP0SEbZqW4iLCz2i1JntQghK5qpSZOVqsBTcARd6pcJ/cwEA\n" "mrwskWazuS9+GVbHT5RATWOXnGaj+AICSDPE6qHtGgA=\n" "=putz\n" "-----END PGP PUBLIC KEY BLOCK-----\n"; auto *job = openpgp()->importJob(); job->setKeyOrigin(GpgME::Key::OriginWKD, "https://example.net"); connect(job, &ImportJob::result, this, [this](ImportResult result, QString, Error) { QVERIFY(!result.error()); QVERIFY(!result.imports().empty()); QVERIFY(result.numImported()); Q_EMIT asyncDone(); }); job->start(QByteArray{keyData}); QSignalSpy spy (this, SIGNAL(asyncDone())); QVERIFY(spy.wait()); auto ctx = Context::createForProtocol(GpgME::OpenPGP); GpgME::Error err; const auto key = ctx->key(keyFpr, err, false); QVERIFY(!key.isNull()); QVERIFY(key.origin() == Key::OriginWKD); // the origin URL is currently not available in GpgME } }; QTEST_MAIN(ImportTest) #include "t-import.moc"