diff --git a/lang/qt/src/Makefile.am b/lang/qt/src/Makefile.am index 683b44cd..a965cdea 100644 --- a/lang/qt/src/Makefile.am +++ b/lang/qt/src/Makefile.am @@ -1,288 +1,288 @@ # 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 threadedjobmixin.cpp \ qgpgmekeyformailboxjob.cpp qgpgme_debug.cpp \ qgpgmetofupolicyjob.cpp qgpgmequickjob.cpp \ defaultkeygenerationjob.cpp qgpgmewkspublishjob.cpp \ - qgpgmegpgcardjob.cpp \ + qgpgmegpgcardjob.cpp changeexpiryjob.cpp \ dn.cpp cryptoconfig.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 \ 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 \ WKSPublishJob \ TofuPolicyJob \ GpgCardJob private_qgpgme_headers = \ qgpgme_export.h \ protocol_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 \ 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 \ qgpgmewkspublishjob.moc \ tofupolicyjob.moc \ qgpgmetofupolicyjob.moc \ refreshkeysjob.moc \ signencryptjob.moc \ signjob.moc \ signkeyjob.moc \ specialjob.moc \ verifydetachedjob.moc \ verifyopaquejob.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/changeexpiryjob.cpp b/lang/qt/src/changeexpiryjob.cpp new file mode 100644 index 00000000..49f68cc1 --- /dev/null +++ b/lang/qt/src/changeexpiryjob.cpp @@ -0,0 +1,76 @@ +/* + changeexpiryjob.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 "changeexpiryjob.h" +#include "job_p.h" + +#include + +using namespace GpgME; +using namespace QGpgME; + +namespace +{ +struct ChangeExpiryJobPrivate : public JobPrivate +{ + ChangeExpiryJobPrivate() + { + } + + ~ChangeExpiryJobPrivate() override = default; + + ChangeExpiryJob::Options m_options = ChangeExpiryJob::Default; +}; +} + +void ChangeExpiryJob::setOptions(ChangeExpiryJob::Options options) +{ + auto d = jobPrivate(this); + d->m_options = options; +} + +ChangeExpiryJob::Options ChangeExpiryJob::options() const +{ + auto d = jobPrivate(this); + return d->m_options; +} + +/* For ABI compat not pure virtual. */ +Error ChangeExpiryJob::start(const Key &, const QDateTime &, const std::vector &) +{ + return {}; +} diff --git a/lang/qt/src/changeexpiryjob.h b/lang/qt/src/changeexpiryjob.h index 39ed52ea..0c5e1b2b 100644 --- a/lang/qt/src/changeexpiryjob.h +++ b/lang/qt/src/changeexpiryjob.h @@ -1,102 +1,115 @@ /* changeexpiryjob.h This file is part of qgpgme, the Qt API binding for gpgme Copyright (c) 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. */ #ifndef __KLEO_CHANGEEXPIRYJOB_H__ #define __KLEO_CHANGEEXPIRYJOB_H__ #include "job.h" #ifdef BUILDING_QGPGME # include "key.h" #else # include #endif #include namespace GpgME { class Error; } class QDateTime; namespace QGpgME { /** @short An abstract base class to change expiry asynchronously To use a ChangeExpiryJob, first obtain an instance from the CryptoBackend implementation, connect the progress() and result() signals to suitable slots and then start the job with a call to start(). This call might fail, in which case the ChangeExpiryJob instance will have scheduled it's own destruction with a call to QObject::deleteLater(). After result() is emitted, the ChangeExpiryJob will schedule it's own destruction by calling QObject::deleteLater(). */ class QGPGME_EXPORT ChangeExpiryJob : public Job { Q_OBJECT +public: + enum Option { + Default = 0x00, + UpdatePrimaryKey = 0x01, + UpdateAllSubkeys = 0x02, + }; + Q_DECLARE_FLAGS(Options, Option) + protected: explicit ChangeExpiryJob(QObject *parent); public: ~ChangeExpiryJob(); + void setOptions(Options options); + Options options() const; + /** Starts the change-expiry operation. \a key is the key to change the expiry of. \a expiry is the new expiry time. If \a expiry is not valid, \a key is set to never expire. */ virtual GpgME::Error start(const GpgME::Key &key, const QDateTime &expiry) = 0; /** Starts the change-expiry operation. \a key is the key to change, \a subkeys is a list of subkeys of the key, and \a expiry is the new expiry time. If \a subkeys is empty, then the expiry of \a key is changed. Otherwise, the expiry of \a subkeys is changed. If \a expiry is not valid, then \a key or \a subkeys are set to never expire. */ virtual GpgME::Error start(const GpgME::Key &key, const QDateTime &expiry, const std::vector &subkeys); Q_SIGNALS: void result(const GpgME::Error &result, const QString &auditLogAsHtml = QString(), const GpgME::Error &auditLogError = GpgME::Error()); }; +Q_DECLARE_OPERATORS_FOR_FLAGS(ChangeExpiryJob::Options) + } #endif // __KLEO_CHANGEEXPIRYJOB_H__ diff --git a/lang/qt/src/qgpgmechangeexpiryjob.cpp b/lang/qt/src/qgpgmechangeexpiryjob.cpp index 68591b7e..5d4e8360 100644 --- a/lang/qt/src/qgpgmechangeexpiryjob.cpp +++ b/lang/qt/src/qgpgmechangeexpiryjob.cpp @@ -1,86 +1,100 @@ /* qgpgmechangeexpiryjob.cpp This file is part of qgpgme, the Qt API binding for gpgme Copyright (c) 2008 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. */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include "qgpgmechangeexpiryjob.h" #include "context.h" #include "key.h" #include using namespace QGpgME; using namespace GpgME; QGpgMEChangeExpiryJob::QGpgMEChangeExpiryJob(Context *context) : mixin_type(context) { lateInitialization(); } QGpgMEChangeExpiryJob::~QGpgMEChangeExpiryJob() {} static QGpgMEChangeExpiryJob::result_type change_expiry(Context *ctx, const Key &key, const QDateTime &expiry, - const std::vector &subkeys) + const std::vector &subkeys, ChangeExpiryJob::Options options) { // convert expiry to "seconds from now"; use 1 second from now if expiry is before the current datetime const unsigned long expires = expiry.isValid() ? std::max(QDateTime::currentDateTime().secsTo(expiry), 1) : 0; - auto err = ctx->setExpire(key, expires, subkeys); + // updating the expiration date of the primary key and the subkeys needs to be done in two steps + // because --quick-set-expire does not support updating the expiration date of both at the same time + + if (subkeys.empty() || (options & ChangeExpiryJob::UpdatePrimaryKey)) { + // update the expiration date of the primary key + auto err = ctx->setExpire(key, expires); + if (err) { + return std::make_tuple(err, QString(), Error()); + } + } + + GpgME::Error err; + if (!subkeys.empty()) { + // update the expiration date of the specified subkeys + err = ctx->setExpire(key, expires, subkeys); + } else if (options & ChangeExpiryJob::UpdateAllSubkeys) { + // update the expiration date of all subkeys + err = ctx->setExpire(key, expires, {}, Context::SetExpireAllSubkeys); + } return std::make_tuple(err, QString(), Error()); } Error QGpgMEChangeExpiryJob::start(const Key &key, const QDateTime &expiry) { return start(key, expiry, std::vector()); } Error QGpgMEChangeExpiryJob::start(const Key &key, const QDateTime &expiry, const std::vector &subkeys) { - run(std::bind(&change_expiry, std::placeholders::_1, key, expiry, subkeys)); - return Error(); -} - -/* For ABI compat not pure virtual. */ -Error ChangeExpiryJob::start(const Key &, const QDateTime &, const std::vector &) -{ + run(std::bind(&change_expiry, std::placeholders::_1, key, expiry, subkeys, options())); return Error(); } #include "qgpgmechangeexpiryjob.moc"