diff --git a/lang/qt/src/Makefile.am b/lang/qt/src/Makefile.am index 261eff60..b9171a60 100644 --- a/lang/qt/src/Makefile.am +++ b/lang/qt/src/Makefile.am @@ -1,296 +1,296 @@ # Makefile.am for GPGMEPP. # Copyright (C) 2016 Bundesamt für Sicherheit in der Informationstechnik # Software engineering by Intevation GmbH # # This file is part of GPGMEPP. # # GPGME-CL 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. # # GPGME-CL 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 Lesser 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., 59 Temple Place - Suite 330, Boston, MA # 02111-1307, USA lib_LTLIBRARIES = libqgpgme.la EXTRA_DIST = QGpgmeConfig.cmake.in.in QGpgmeConfigVersion.cmake.in \ qgpgme_debug.h qgpgme_version.h.in \ QGpgmeConfig.cmake.in.in qgpgme_sources = \ dataprovider.cpp \ debug.cpp \ job.cpp multideletejob.cpp qgpgmeadduseridjob.cpp \ qgpgmebackend.cpp qgpgmechangeexpiryjob.cpp qgpgmechangeownertrustjob.cpp \ qgpgmechangepasswdjob.cpp qgpgmedecryptjob.cpp \ qgpgmedecryptverifyjob.cpp qgpgmedeletejob.cpp qgpgmedownloadjob.cpp \ qgpgmeencryptjob.cpp qgpgmeexportjob.cpp qgpgmeimportfromkeyserverjob.cpp \ qgpgmeimportjob.cpp qgpgmekeygenerationjob.cpp qgpgmekeylistjob.cpp \ qgpgmelistallkeysjob.cpp qgpgmenewcryptoconfig.cpp \ qgpgmerefreshkeysjob.cpp \ qgpgmesecretkeyexportjob.cpp qgpgmesignencryptjob.cpp \ qgpgmesignjob.cpp qgpgmesignkeyjob.cpp qgpgmeverifydetachedjob.cpp \ qgpgmeverifyopaquejob.cpp qgpgmewkdlookupjob.cpp threadedjobmixin.cpp \ qgpgmekeyformailboxjob.cpp qgpgme_debug.cpp \ qgpgmetofupolicyjob.cpp qgpgmequickjob.cpp \ defaultkeygenerationjob.cpp qgpgmewkspublishjob.cpp \ - qgpgmegpgcardjob.cpp changeexpiryjob.cpp \ + qgpgmegpgcardjob.cpp changeexpiryjob.cpp importjob.cpp \ dn.cpp cryptoconfig.cpp wkdlookupresult.cpp # If you add one here make sure that you also add one in camelcase qgpgme_headers= \ abstractimportjob.h \ adduseridjob.h \ changeexpiryjob.h \ changeownertrustjob.h \ changepasswdjob.h \ dataprovider.h \ debug.h \ decryptjob.h \ decryptverifyjob.h \ downloadjob.h \ encryptjob.h \ exportjob.h \ hierarchicalkeylistjob.h \ job.h \ keyformailboxjob.h \ multideletejob.h \ protocol.h \ qgpgme_export.h \ qgpgmenewcryptoconfig.h \ quickjob.h \ specialjob.h \ signjob.h \ signkeyjob.h \ signencryptjob.h \ verifyopaquejob.h \ refreshkeysjob.h \ cryptoconfig.h \ deletejob.h \ importfromkeyserverjob.h \ importjob.h \ keygenerationjob.h \ keylistjob.h \ listallkeysjob.h \ verifydetachedjob.h \ defaultkeygenerationjob.h \ tofupolicyjob.h \ wkdlookupjob.h \ wkdlookupresult.h \ wkspublishjob.h \ gpgcardjob.h \ dn.h camelcase_headers= \ AddUserIDJob \ AbstractImportJob \ ChangeExpiryJob \ ChangeOwnerTrustJob \ ChangePasswdJob \ DataProvider \ Debug \ DecryptJob \ DecryptVerifyJob \ DN \ DownloadJob \ EncryptJob \ ExportJob \ HierarchicalKeyKistJob \ Job \ MultiDeleteJob \ Protocol \ QGpgMENewCryptoConfig \ QuickJob \ SpecialJob \ SignJob \ SignKeyJob \ SignEncryptJob \ VerifyOpaqueJob \ RefreshKeysJob \ CryptoConfig \ DeleteJob \ ImportFromKeyserverJob \ ImportJob \ KeyGenerationJob \ KeyListJob \ ListAllKeysJob \ VerifyDetachedJob \ KeyForMailboxJob \ DefaultKeyGenerationJob \ WKDLookupJob \ WKDLookupResult \ WKSPublishJob \ TofuPolicyJob \ GpgCardJob private_qgpgme_headers = \ qgpgme_export.h \ protocol_p.h \ job_p.h \ qgpgmeadduseridjob.h \ qgpgmebackend.h \ qgpgmechangeexpiryjob.h \ qgpgmechangeownertrustjob.h \ qgpgmechangepasswdjob.h \ qgpgmedecryptjob.h \ qgpgmedecryptverifyjob.h \ qgpgmedeletejob.h \ qgpgmedownloadjob.h \ qgpgmeencryptjob.h \ qgpgmeexportjob.h \ qgpgmeimportfromkeyserverjob.h \ qgpgmeimportjob.h \ qgpgmekeygenerationjob.h \ qgpgmekeylistjob.h \ qgpgmelistallkeysjob.h \ qgpgmerefreshkeysjob.h \ qgpgmesecretkeyexportjob.h \ qgpgmesignencryptjob.h \ qgpgmesignjob.h \ qgpgmesignkeyjob.h \ qgpgmeverifydetachedjob.h \ qgpgmeverifyopaquejob.h \ qgpgmewkdlookupjob.h \ qgpgmekeyformailboxjob.h \ qgpgmewkspublishjob.h \ qgpgmetofupolicyjob.h \ qgpgmegpgcardjob.h \ qgpgmequickjob.h \ threadedjobmixin.h qgpgme_moc_sources = \ abstractimportjob.moc \ adduseridjob.moc \ changeexpiryjob.moc \ changeownertrustjob.moc \ changepasswdjob.moc \ decryptjob.moc \ decryptverifyjob.moc \ deletejob.moc \ downloadjob.moc \ encryptjob.moc \ exportjob.moc \ hierarchicalkeylistjob.moc \ importfromkeyserverjob.moc \ importjob.moc \ job.moc \ keygenerationjob.moc \ keylistjob.moc \ listallkeysjob.moc \ multideletejob.moc \ qgpgmeadduseridjob.moc \ qgpgmechangeexpiryjob.moc \ qgpgmechangeownertrustjob.moc \ qgpgmechangepasswdjob.moc \ qgpgmedecryptjob.moc \ qgpgmedecryptverifyjob.moc \ qgpgmedeletejob.moc \ qgpgmedownloadjob.moc \ qgpgmeencryptjob.moc \ qgpgmeexportjob.moc \ qgpgmeimportfromkeyserverjob.moc \ qgpgmeimportjob.moc \ qgpgmekeygenerationjob.moc \ qgpgmekeylistjob.moc \ qgpgmelistallkeysjob.moc \ qgpgmerefreshkeysjob.moc \ qgpgmesecretkeyexportjob.moc \ qgpgmesignencryptjob.moc \ qgpgmesignjob.moc \ qgpgmesignkeyjob.moc \ qgpgmeverifydetachedjob.moc \ qgpgmeverifyopaquejob.moc \ qgpgmewkdlookupjob.moc \ qgpgmewkspublishjob.moc \ tofupolicyjob.moc \ qgpgmetofupolicyjob.moc \ refreshkeysjob.moc \ signencryptjob.moc \ signjob.moc \ signkeyjob.moc \ specialjob.moc \ verifydetachedjob.moc \ verifyopaquejob.moc \ wkdlookupjob.moc \ keyformailboxjob.moc \ wkspublishjob.moc \ qgpgmekeyformailboxjob.moc \ defaultkeygenerationjob.moc \ quickjob.moc \ qgpgmequickjob.moc \ gpgcardjob.moc \ qgpgmegpgcardjob.moc qgpgmeincludedir = $(includedir)/qgpgme qgpgmeinclude_HEADERS = $(qgpgme_headers) camelcaseincludedir = $(includedir)/QGpgME camelcaseinclude_HEADERS = $(camelcase_headers) nodist_qgpgmeinclude_HEADERS = qgpgme_version.h libqgpgme_la_SOURCES = $(qgpgme_sources) $(qgpgme_headers) $(private_qgpgme_headers) AM_CPPFLAGS = -I$(top_srcdir)/lang/cpp/src -I$(top_builddir)/src \ @GPGME_QT_CFLAGS@ @GPG_ERROR_CFLAGS@ @LIBASSUAN_CFLAGS@ \ -DBUILDING_QGPGME -Wsuggest-override \ -Wzero-as-null-pointer-constant libqgpgme_la_LIBADD = ../../cpp/src/libgpgmepp.la ../../../src/libgpgme.la \ @LIBASSUAN_LIBS@ @GPG_ERROR_LIBS@ @GPGME_QT_LIBS@ libqgpgme_la_LDFLAGS = -no-undefined -version-info \ @LIBQGPGME_LT_CURRENT@:@LIBQGPGME_LT_REVISION@:@LIBQGPGME_LT_AGE@ if HAVE_MACOS_SYSTEM libsuffix=.dylib else libsuffix=.so endif if HAVE_W32_SYSTEM QGpgmeConfig.cmake: QGpgmeConfig-w32.cmake.in sed -e 's|[@]resolved_bindir@|$(bindir)|g' < "$<" | \ sed -e 's|[@]resolved_libdir@|$(libdir)|g' | \ sed -e 's|[@]resolved_includedir@|$(includedir)|g' > $@ else QGpgmeConfig.cmake: QGpgmeConfig.cmake.in sed -e 's|[@]resolved_libdir@|$(libdir)|g' < "$<" | \ sed -e 's|[@]libsuffix@|$(libsuffix)|g' | \ sed -e 's|[@]resolved_includedir@|$(includedir)|g' > $@ endif $(camelcase_headers): Makefile.am echo -n "#include \"qgpgme/" > "$@" echo -n "$@" | tr '[:upper:]' '[:lower:]' >> "$@" echo ".h\"" >> "$@" install-cmake-files: QGpgmeConfig.cmake QGpgmeConfigVersion.cmake -$(INSTALL) -d $(DESTDIR)$(libdir)/cmake/QGpgme $(INSTALL) -m 644 QGpgmeConfig.cmake \ $(DESTDIR)$(libdir)/cmake/QGpgme/QGpgmeConfig.cmake $(INSTALL) -m 644 QGpgmeConfigVersion.cmake \ $(DESTDIR)$(libdir)/cmake/QGpgme/QGpgmeConfigVersion.cmake uninstall-cmake-files: -rm $(DESTDIR)$(libdir)/cmake/QGpgme/QGpgmeConfigVersion.cmake -rm $(DESTDIR)$(libdir)/cmake/QGpgme/QGpgmeConfig.cmake -rmdir $(DESTDIR)$(libdir)/cmake/QGpgme/ install-data-local: install-cmake-files uninstall-local: uninstall-cmake-files BUILT_SOURCES = $(qgpgme_moc_sources) $(camelcase_headers) CLEANFILES = $(qgpgme_moc_sources) $(camelcase_headers) QGpgmeConfig.cmake \ qgpgme_version.h QGpgmeConfig.cmake.in \ QGpgmeConfigVersion.cmake nodist_libqgpgme_la_SOURCES = $(qgpgme_moc_sources) .h.moc: $(MOC) `test -f '$<' || echo '$(srcdir)/'`$< -o $@ diff --git a/lang/qt/src/importjob.h b/lang/qt/src/importjob.cpp similarity index 51% copy from lang/qt/src/importjob.h copy to lang/qt/src/importjob.cpp index 7437fbdc..3f28606f 100644 --- a/lang/qt/src/importjob.h +++ b/lang/qt/src/importjob.cpp @@ -1,84 +1,78 @@ /* - importjob.h + importjob.cpp 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 + 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 __KLEO_IMPORTJOB_H__ -#define __KLEO_IMPORTJOB_H__ +#ifdef HAVE_CONFIG_H + #include "config.h" +#endif -#include "abstractimportjob.h" -#include "qgpgme_export.h" +#include "importjob.h" +#include "job_p.h" -#include +#include -namespace GpgME -{ -class Error; -class ImportResult; -} +using namespace GpgME; +using namespace QGpgME; -namespace QGpgME +namespace { - -/** - @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 +struct ImportJobPrivate : public JobPrivate { - Q_OBJECT -protected: - explicit ImportJob(QObject *parent); -public: - ~ImportJob(); + ImportJobPrivate() + { + } - /** - Starts the importing operation. \a keyData contains the data to - import from. - */ - virtual GpgME::Error start(const QByteArray &keyData) = 0; + ~ImportJobPrivate() override = default; - virtual GpgME::ImportResult exec(const QByteArray &keyData) = 0; + Key::Origin m_keyOrigin = Key::OriginUnknown; + QString m_keyOriginUrl; }; +} +void ImportJob::setKeyOrigin(GpgME::Key::Origin origin, const QString &url) +{ + const auto d = jobPrivate(this); + d->m_keyOrigin = origin; + d->m_keyOriginUrl = url; +} + +GpgME::Key::Origin ImportJob::keyOrigin() const +{ + const auto d = jobPrivate(this); + return d->m_keyOrigin; } -#endif // __KLEO_IMPORTJOB_H__ +QString ImportJob::keyOriginUrl() const +{ + const auto d = jobPrivate(this); + return d->m_keyOriginUrl; +} diff --git a/lang/qt/src/importjob.h b/lang/qt/src/importjob.h index 7437fbdc..1ded1cde 100644 --- a/lang/qt/src/importjob.h +++ b/lang/qt/src/importjob.h @@ -1,84 +1,90 @@ /* 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 + 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(); + ~ImportJob() override; + + 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 a62d05f9..ad5c2aee 100644 --- a/lang/qt/src/qgpgmeimportjob.cpp +++ b/lang/qt/src/qgpgmeimportjob.cpp @@ -1,90 +1,116 @@ /* 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 "context.h" #include "data.h" #include "key.h" #include using namespace QGpgME; using namespace GpgME; QGpgMEImportJob::QGpgMEImportJob(Context *context) : mixin_type(context) { lateInitialization(); } -QGpgMEImportJob::~QGpgMEImportJob() {} +QGpgMEImportJob::~QGpgMEImportJob() = default; -static QGpgMEImportJob::result_type import_qba(Context *ctx, const QByteArray &certData) +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, Key::Origin keyOrigin, const QString &keyOriginUrl) +{ + 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); const ImportResult res = ctx->importKeys(data); 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)); + run(std::bind(&import_qba, std::placeholders::_1, certData, keyOrigin(), keyOriginUrl())); return Error(); } GpgME::ImportResult QGpgME::QGpgMEImportJob::exec(const QByteArray &keyData) { - const result_type r = import_qba(context(), keyData); + const result_type r = import_qba(context(), keyData, 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/tests/Makefile.am b/lang/qt/tests/Makefile.am index b7ec546e..4537c7f8 100644 --- a/lang/qt/tests/Makefile.am +++ b/lang/qt/tests/Makefile.am @@ -1,105 +1,106 @@ # Makefile.am - Makefile for GPGME Qt tests. # Copyright (C) 2016 Bundesamt für Sicherheit in der Informationstechnik # Software engineering by Intevation GmbH # # This file is part of GPGME. # # GPGME is free software; you can redistribute it and/or modify it # under the terms of the GNU Lesser General Public License as # published by the Free Software Foundation; either version 2.1 of the # License, or (at your option) any later version. # # GPGME 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 Lesser General # Public License for more details. # # You should have received a copy of the GNU Lesser General Public # License along with this program; if not, see . ## Process this file with automake to produce Makefile.in GPG = gpg GNUPGHOME=$(abs_builddir) TESTS_ENVIRONMENT = GNUPGHOME=$(GNUPGHOME) EXTRA_DIST = initial.test final.test the_tests = \ 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-changeexpiryjob t-wkdlookup t-import TESTS = initial.test $(the_tests) final.test 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-changeexpiryjob.moc t-wkdlookup.moc t-import.moc AM_LDFLAGS = -no-install LDADD = ../../cpp/src/libgpgmepp.la ../src/libqgpgme.la \ ../../../src/libgpgme.la @GPGME_QT_LIBS@ @GPG_ERROR_LIBS@ \ @GPGME_QTTEST_LIBS@ @LDADD_FOR_TESTS_KLUDGE@ -lstdc++ AM_CPPFLAGS = -I$(top_srcdir)/lang/cpp/src -I$(top_builddir)/src \ @GPG_ERROR_CFLAGS@ @GPGME_QT_CFLAGS@ @GPG_ERROR_CFLAGS@ \ @LIBASSUAN_CFLAGS@ @GPGME_QTTEST_CFLAGS@ -DBUILDING_QGPGME \ -I$(top_srcdir)/lang/qt/src \ -DTOP_SRCDIR="$(top_srcdir)" support_src = t-support.h t-support.cpp t_keylist_SOURCES = t-keylist.cpp $(support_src) t_keylocate_SOURCES = t-keylocate.cpp $(support_src) t_ownertrust_SOURCES = t-ownertrust.cpp $(support_src) t_tofuinfo_SOURCES = t-tofuinfo.cpp $(support_src) t_encrypt_SOURCES = t-encrypt.cpp $(support_src) t_wkspublish_SOURCES = t-wkspublish.cpp $(support_src) t_verify_SOURCES = t-verify.cpp $(support_src) t_various_SOURCES = t-various.cpp $(support_src) t_config_SOURCES = t-config.cpp $(support_src) t_remarks_SOURCES = t-remarks.cpp $(support_src) 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) run_keyformailboxjob_SOURCES = run-keyformailboxjob.cpp nodist_t_keylist_SOURCES = $(moc_files) BUILT_SOURCES = $(moc_files) pubring-stamp noinst_PROGRAMS = 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-trustsignatures t-changeexpiryjob t-wkdlookup t-import CLEANFILES = secring.gpg pubring.gpg pubring.kbx trustdb.gpg dirmngr.conf \ gpg-agent.conf pubring.kbx~ S.gpg-agent gpg.conf pubring.gpg~ \ random_seed S.gpg-agent .gpg-v21-migrated pubring-stamp $(moc_files) \ gpg.conf tofu.db reader_0.status reader_1.status clean-local: -$(TESTS_ENVIRONMENT) $(top_srcdir)/tests/start-stop-agent --stop -rm -fR private-keys-v1.d crls.d pubring-stamp: $(top_srcdir)/tests/gpg/pubdemo.asc \ $(top_srcdir)/tests/gpg/secdemo.asc -$(TESTS_ENVIRONMENT) gpgconf --kill all echo "ignore-invalid-option allow-loopback-pinentry" > $(abs_builddir)/gpg-agent.conf echo "allow-loopback-pinentry" >> gpg-agent.conf echo "ignore-invalid-option pinentry-mode" > gpg.conf echo "pinentry-mode loopback" >> gpg.conf $(TESTS_ENVIRONMENT) $(GPG) --no-permission-warning \ --import $(top_srcdir)/tests/gpg/pubdemo.asc $(TESTS_ENVIRONMENT) $(GPG) --no-permission-warning \ --passphrase "abc" \ --import $(top_srcdir)/tests/gpg/secdemo.asc touch pubring-stamp .cpp.moc: $(MOC) `test -f '$<' || echo '$(srcdir)/'`$< -o $@ .h.hmoc: $(MOC) `test -f '$<' || echo '$(srcdir)/'`$< -o $@ diff --git a/lang/qt/tests/t-import.cpp b/lang/qt/tests/t-import.cpp new file mode 100644 index 00000000..aaa05c0d --- /dev/null +++ b/lang/qt/tests/t-import.cpp @@ -0,0 +1,109 @@ +/* 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 + +using namespace QGpgME; +using namespace GpgME; + +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"; + +class ImportTest : public QGpgMETest +{ + Q_OBJECT + +Q_SIGNALS: + void asyncDone(); + +private Q_SLOTS: + + void testImportWithKeyOrigin() + { + if (GpgME::engineInfo(GpgME::GpgEngine).engineVersion() < "2.1.22") { + QSKIP("gpg does not yet support the --key-origin option"); + } + + 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"