diff --git a/lang/qt/src/Makefile.am b/lang/qt/src/Makefile.am index 240e5716..928b6913 100644 --- a/lang/qt/src/Makefile.am +++ b/lang/qt/src/Makefile.am @@ -1,397 +1,405 @@ # 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 if WANT_QT5 lib_LTLIBRARIES = libqgpgme.la endif if WANT_QT6 lib_LTLIBRARIES = libqgpgmeqt6.la endif EXTRA_DIST = QGpgmeConfig.cmake.in.in QGpgmeConfigVersion.cmake.in \ qgpgme_debug.h qgpgme_version.h.in \ QGpgmeConfig-w32.cmake.in.in QGpgmeQt6Config.cmake.in.in \ QGpgmeQt6Config-w32.cmake.in.in QGpgmeQt6ConfigVersion.cmake.in qgpgme_sources = \ dataprovider.cpp \ debug.cpp \ encryptarchivejob.cpp \ filelistdataprovider.cpp \ job.cpp multideletejob.cpp qgpgmeadduseridjob.cpp \ qgpgmeaddexistingsubkeyjob.cpp \ qgpgmebackend.cpp qgpgmechangeexpiryjob.cpp qgpgmechangeownertrustjob.cpp \ qgpgmechangepasswdjob.cpp qgpgmedecryptjob.cpp \ qgpgmedecryptverifyjob.cpp qgpgmedeletejob.cpp qgpgmedownloadjob.cpp \ qgpgmeencryptarchivejob.cpp \ qgpgmeencryptjob.cpp qgpgmeexportjob.cpp qgpgmeimportfromkeyserverjob.cpp \ qgpgmeimportjob.cpp qgpgmekeygenerationjob.cpp qgpgmekeylistjob.cpp \ listallkeysjob.cpp qgpgmelistallkeysjob.cpp qgpgmenewcryptoconfig.cpp \ qgpgmereceivekeysjob.cpp \ qgpgmerefreshsmimekeysjob.cpp \ qgpgmerevokekeyjob.cpp \ qgpgmesetprimaryuseridjob.cpp \ + qgpgmesignarchivejob.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 encryptjob.cpp importjob.cpp \ + signarchivejob.cpp \ signencryptjob.cpp \ dn.cpp cryptoconfig.cpp wkdlookupresult.cpp \ util.cpp # If you add one here make sure that you also add one in camelcase qgpgme_headers= \ abstractimportjob.h \ addexistingsubkeyjob.h \ adduseridjob.h \ changeexpiryjob.h \ changeownertrustjob.h \ changepasswdjob.h \ dataprovider.h \ debug.h \ decryptjob.h \ decryptverifyjob.h \ downloadjob.h \ encryptarchivejob.h \ encryptjob.h \ exportjob.h \ filelistdataprovider.h \ hierarchicalkeylistjob.h \ job.h \ keyformailboxjob.h \ multideletejob.h \ protocol.h \ qgpgme_export.h \ qgpgmenewcryptoconfig.h \ quickjob.h \ receivekeysjob.h \ revokekeyjob.h \ setprimaryuseridjob.h \ specialjob.h \ + signarchivejob.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= \ AddExistingSubkeyJob \ AddUserIDJob \ AbstractImportJob \ ChangeExpiryJob \ ChangeOwnerTrustJob \ ChangePasswdJob \ DataProvider \ Debug \ DecryptJob \ DecryptVerifyJob \ DN \ DownloadJob \ EncryptArchiveJob \ EncryptJob \ ExportJob \ FileListDataProvider \ HierarchicalKeyKistJob \ Job \ MultiDeleteJob \ Protocol \ QGpgMENewCryptoConfig \ QuickJob \ ReceiveKeysJob \ RevokeKeyJob \ SetPrimaryUserIDJob \ SpecialJob \ + SignArchiveJob \ SignJob \ SignKeyJob \ SignEncryptJob \ VerifyOpaqueJob \ RefreshKeysJob \ CryptoConfig \ DeleteJob \ ImportFromKeyserverJob \ ImportJob \ KeyGenerationJob \ KeyListJob \ ListAllKeysJob \ VerifyDetachedJob \ KeyForMailboxJob \ DefaultKeyGenerationJob \ WKDLookupJob \ WKDLookupResult \ WKSPublishJob \ TofuPolicyJob \ GpgCardJob private_qgpgme_headers = \ changeexpiryjob_p.h \ encryptarchivejob_p.h \ encryptjob_p.h \ importjob_p.h \ listallkeysjob_p.h \ qgpgme_export.h \ protocol_p.h \ job_p.h \ qgpgmeaddexistingsubkeyjob.h \ qgpgmeadduseridjob.h \ qgpgmebackend.h \ qgpgmechangeexpiryjob.h \ qgpgmechangeownertrustjob.h \ qgpgmechangepasswdjob.h \ qgpgmedecryptjob.h \ qgpgmedecryptverifyjob.h \ qgpgmedeletejob.h \ qgpgmedownloadjob.h \ qgpgmeencryptarchivejob.h \ qgpgmeencryptjob.h \ qgpgmeexportjob.h \ qgpgmeimportfromkeyserverjob.h \ qgpgmeimportjob.h \ qgpgmekeygenerationjob.h \ qgpgmekeylistjob.h \ qgpgmelistallkeysjob.h \ qgpgmereceivekeysjob.h \ qgpgmerefreshsmimekeysjob.h \ qgpgmerevokekeyjob.h \ qgpgmesetprimaryuseridjob.h \ + qgpgmesignarchivejob.h \ qgpgmesignencryptjob.h \ qgpgmesignjob.h \ qgpgmesignkeyjob.h \ qgpgmeverifydetachedjob.h \ qgpgmeverifyopaquejob.h \ qgpgmewkdlookupjob.h \ qgpgmekeyformailboxjob.h \ qgpgmewkspublishjob.h \ qgpgmetofupolicyjob.h \ qgpgmegpgcardjob.h \ qgpgmequickjob.h \ + signarchivejob_p.h \ signencryptjob_p.h \ threadedjobmixin.h \ util.h qgpgme_moc_sources = \ abstractimportjob.moc \ addexistingsubkeyjob.moc \ adduseridjob.moc \ changeexpiryjob.moc \ changeownertrustjob.moc \ changepasswdjob.moc \ decryptjob.moc \ decryptverifyjob.moc \ deletejob.moc \ downloadjob.moc \ encryptarchivejob.moc \ encryptjob.moc \ exportjob.moc \ hierarchicalkeylistjob.moc \ importfromkeyserverjob.moc \ importjob.moc \ job.moc \ keygenerationjob.moc \ keylistjob.moc \ listallkeysjob.moc \ multideletejob.moc \ qgpgmeaddexistingsubkeyjob.moc \ qgpgmeadduseridjob.moc \ qgpgmechangeexpiryjob.moc \ qgpgmechangeownertrustjob.moc \ qgpgmechangepasswdjob.moc \ qgpgmedecryptjob.moc \ qgpgmedecryptverifyjob.moc \ qgpgmedeletejob.moc \ qgpgmedownloadjob.moc \ qgpgmeencryptarchivejob.moc \ qgpgmeencryptjob.moc \ qgpgmeexportjob.moc \ qgpgmeimportfromkeyserverjob.moc \ qgpgmeimportjob.moc \ qgpgmekeygenerationjob.moc \ qgpgmekeylistjob.moc \ qgpgmelistallkeysjob.moc \ qgpgmereceivekeysjob.moc \ qgpgmerefreshsmimekeysjob.moc \ qgpgmerevokekeyjob.moc \ qgpgmesetprimaryuseridjob.moc \ + qgpgmesignarchivejob.moc \ qgpgmesignencryptjob.moc \ qgpgmesignjob.moc \ qgpgmesignkeyjob.moc \ qgpgmeverifydetachedjob.moc \ qgpgmeverifyopaquejob.moc \ qgpgmewkdlookupjob.moc \ qgpgmewkspublishjob.moc \ tofupolicyjob.moc \ qgpgmetofupolicyjob.moc \ receivekeysjob.moc \ refreshkeysjob.moc \ revokekeyjob.moc \ setprimaryuseridjob.moc \ + signarchivejob.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 if WANT_QT5 AM_CPPFLAGS = -I$(top_srcdir)/lang/cpp/src -I$(top_builddir)/src \ @GPGME_QT5_CFLAGS@ @GPG_ERROR_CFLAGS@ @LIBASSUAN_CFLAGS@ \ -DBUILDING_QGPGME -Wsuggest-override \ -Wzero-as-null-pointer-constant libqgpgme_la_SOURCES = $(qgpgme_sources) $(qgpgme_headers) $(private_qgpgme_headers) libqgpgme_la_LIBADD = ../../cpp/src/libgpgmepp.la ../../../src/libgpgme.la \ @LIBASSUAN_LIBS@ @GPG_ERROR_LIBS@ @GPGME_QT5_LIBS@ libqgpgme_la_LDFLAGS = -no-undefined -version-info \ @LIBQGPGME_LT_CURRENT@:@LIBQGPGME_LT_REVISION@:@LIBQGPGME_LT_AGE@ endif if WANT_QT6 AM_CPPFLAGS = -I$(top_srcdir)/lang/cpp/src -I$(top_builddir)/src \ @GPGME_QT6_CFLAGS@ @GPG_ERROR_CFLAGS@ @LIBASSUAN_CFLAGS@ \ -DBUILDING_QGPGME -Wsuggest-override \ -Wzero-as-null-pointer-constant libqgpgmeqt6_la_SOURCES = $(qgpgme_sources) $(qgpgme_headers) $(private_qgpgme_headers) libqgpgmeqt6_la_LIBADD = ../../cpp/src/libgpgmepp.la ../../../src/libgpgme.la \ @LIBASSUAN_LIBS@ @GPG_ERROR_LIBS@ @GPGME_QT6_LIBS@ libqgpgmeqt6_la_LDFLAGS = -no-undefined -version-info \ @LIBQGPGME_LT_CURRENT@:@LIBQGPGME_LT_REVISION@:@LIBQGPGME_LT_AGE@ endif if HAVE_MACOS_SYSTEM libsuffix=.dylib else libsuffix=.so endif if WANT_QT5 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 endif if WANT_QT6 if HAVE_W32_SYSTEM QGpgmeQt6Config.cmake: QGpgmeQt6Config-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 QGpgmeQt6Config.cmake: QGpgmeQt6Config.cmake.in sed -e 's|[@]resolved_libdir@|$(libdir)|g' < "$<" | \ sed -e 's|[@]libsuffix@|$(libsuffix)|g' | \ sed -e 's|[@]resolved_includedir@|$(includedir)|g' > $@ endif endif $(camelcase_headers): Makefile.am echo -n "#include \"qgpgme/" > "$@" echo -n "$@" | tr '[:upper:]' '[:lower:]' >> "$@" echo ".h\"" >> "$@" if WANT_QT5 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/ endif if WANT_QT6 install-cmake-files: QGpgmeQt6Config.cmake QGpgmeQt6ConfigVersion.cmake -$(INSTALL) -d $(DESTDIR)$(libdir)/cmake/QGpgmeQt6 $(INSTALL) -m 644 QGpgmeQt6Config.cmake \ $(DESTDIR)$(libdir)/cmake/QGpgmeQt6/QGpgmeQt6Config.cmake $(INSTALL) -m 644 QGpgmeQt6ConfigVersion.cmake \ $(DESTDIR)$(libdir)/cmake/QGpgmeQt6/QGpgmeQt6ConfigVersion.cmake uninstall-cmake-files: -rm $(DESTDIR)$(libdir)/cmake/QGpgmeQt6/QGpgmeQt6ConfigVersion.cmake -rm $(DESTDIR)$(libdir)/cmake/QGpgmeQt6/QGpgmeQt6Config.cmake -rmdir $(DESTDIR)$(libdir)/cmake/QGpgmeQt6/ endif 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 \ QGpgmeConfig-w32.cmake.in QGpgmeConfigVersion.cmake \ QGpgmeQt6Config.cmake.in QGpgmeQt6Config-w32.cmake.in \ QGpgmeQt6Config.cmake QGpgmeQt6ConfigVersion.cmake if WANT_QT5 nodist_libqgpgme_la_SOURCES = $(qgpgme_moc_sources) endif if WANT_QT6 nodist_libqgpgmeqt6_la_SOURCES = $(qgpgme_moc_sources) endif .h.moc: $(MOC) `test -f '$<' || echo '$(srcdir)/'`$< -o $@ diff --git a/lang/qt/src/protocol.h b/lang/qt/src/protocol.h index bb9f060b..0f3e5b28 100644 --- a/lang/qt/src/protocol.h +++ b/lang/qt/src/protocol.h @@ -1,226 +1,228 @@ /* protocol.h This file is part of qgpgme, the Qt API binding for gpgme Copyright (c) 2004,2005 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 __QGPGME_PROTOCOL_H__ #define __QGPGME_PROTOCOL_H__ #include #include #include "qgpgme_export.h" namespace QGpgME { class AddExistingSubkeyJob; class CryptoConfig; class KeyListJob; class ListAllKeysJob; class KeyGenerationJob; class ImportJob; class ImportFromKeyserverJob; class ExportJob; class DownloadJob; class DeleteJob; class EncryptArchiveJob; class EncryptJob; class DecryptJob; +class SignArchiveJob; class SignJob; class SignKeyJob; class VerifyDetachedJob; class VerifyOpaqueJob; class SignEncryptJob; class DecryptVerifyJob; class RefreshKeysJob; class ChangeExpiryJob; class ChangeOwnerTrustJob; class ChangePasswdJob; class AddUserIDJob; class SpecialJob; class KeyForMailboxJob; class WKDLookupJob; class WKSPublishJob; class TofuPolicyJob; class QuickJob; class GpgCardJob; class ReceiveKeysJob; class RevokeKeyJob; class SetPrimaryUserIDJob; /** The main entry point for QGpgME Comes in OpenPGP and SMIME(CMS) flavors. * * Use the proctocol class to obtain an instance of a job. Jobs * provide async API for GnuPG that can be connected to signals / slots. * * A job is usually started with start() and emits a result signal. * The parameters of the result signal depend on the job but the last * two are always a QString for the auditlog and an GpgME::Error for * an eventual error. * * In case async API is used and the result signal is emitted a * job schedules its own deletion. * * Most jobs also provide a synchronous call exec in which case * you have to explicitly delete the job if you don't need it anymore. * * \code * // Async example: * KeyListJob *job = openpgp()->keyListJob(); * connect(job, &KeyListJob::result, job, [this, job](KeyListResult, std::vector keys, QString, Error) * { * // keys and resuls can now be used. * }); * job->start({QStringLiteral("alfa@example.net")}, false); * \endcode * * \code * // Sync eaxmple: * KeyListJob *job = openpgp()->keyListJob(false, false, false); * std::vector keys; * GpgME::KeyListResult result = job->exec(QStringList() << * QStringLiteral("alfa@example.net"), * false, keys); * delete job; * \endcode */ class QGPGME_EXPORT Protocol { public: virtual ~Protocol() {} virtual QString name() const = 0; virtual QString displayName() const = 0; virtual KeyListJob *keyListJob(bool remote = false, bool includeSigs = false, bool validate = false) const = 0; virtual ListAllKeysJob *listAllKeysJob(bool includeSigs = false, bool validate = false) const = 0; virtual EncryptJob *encryptJob(bool armor = false, bool textmode = false) const = 0; virtual DecryptJob *decryptJob() const = 0; virtual SignJob *signJob(bool armor = false, bool textMode = false) const = 0; virtual VerifyDetachedJob *verifyDetachedJob(bool textmode = false) const = 0; virtual VerifyOpaqueJob *verifyOpaqueJob(bool textmode = false) const = 0; virtual KeyGenerationJob *keyGenerationJob() const = 0; virtual ImportJob *importJob() const = 0; virtual ImportFromKeyserverJob *importFromKeyserverJob() const = 0; virtual ExportJob *publicKeyExportJob(bool armor = false) const = 0; // the second parameter is ignored; the passphrase in the exported file is always utf-8 encoded virtual ExportJob *secretKeyExportJob(bool armor = false, const QString & = QString()) const = 0; virtual DownloadJob *downloadJob(bool armor = false) const = 0; virtual DeleteJob *deleteJob() const = 0; virtual SignEncryptJob *signEncryptJob(bool armor = false, bool textMode = false) const = 0; virtual DecryptVerifyJob *decryptVerifyJob(bool textmode = false) const = 0; /** * For S/MIME keys this job performs a full validation check of the keys * with updated CRLs. * For OpenPGP keys, use receiveKeysJob. */ virtual RefreshKeysJob *refreshKeysJob() const = 0; virtual ChangeExpiryJob *changeExpiryJob() const = 0; virtual SignKeyJob *signKeyJob() const = 0; virtual ChangePasswdJob *changePasswdJob() const = 0; virtual ChangeOwnerTrustJob *changeOwnerTrustJob() const = 0; virtual AddUserIDJob *addUserIDJob() const = 0; virtual SpecialJob *specialJob(const char *type, const QMap &args) const = 0; /** A key locate job. * * This tries to find a key in local * and remote sources, if the key was remote it is imported * by GnuPG. Same as KeyListJob but intended to be used * to locate keys automatically. This ends up calling --locate-keys. * * Only available for OpenPGP * * Results are validated. As if keyListJob was called * with both includeSigs and validate options. */ virtual KeyListJob *locateKeysJob() const = 0; /** Find the best key to use for a mailbox. */ virtual KeyForMailboxJob *keyForMailboxJob() const = 0; /** A Job for interacting with gnupg's wks tools. */ virtual WKSPublishJob *wksPublishJob() const = 0; /** A Job to set tofu policy */ virtual TofuPolicyJob *tofuPolicyJob() const = 0; /** A Job for the quick commands */ virtual QuickJob *quickJob() const = 0; /** This job looks up a key via WKD without importing it. */ virtual WKDLookupJob *wkdLookupJob() const = 0; virtual ExportJob *secretSubkeyExportJob(bool armor = false) const = 0; virtual AddExistingSubkeyJob *addExistingSubkeyJob() const = 0; virtual ReceiveKeysJob *receiveKeysJob() const = 0; virtual RevokeKeyJob *revokeKeyJob() const = 0; /** * Returns a job for flagging a user ID as the primary user ID of an * OpenPGP key. */ virtual SetPrimaryUserIDJob *setPrimaryUserIDJob() const = 0; virtual EncryptArchiveJob *encryptArchiveJob(bool armor = false) const = 0; + virtual SignArchiveJob *signArchiveJob(bool armor = false) const = 0; }; /** Obtain a reference to the OpenPGP Protocol. * * The reference is to a static object. * @returns Reference to the OpenPGP Protocol. */ QGPGME_EXPORT Protocol *openpgp(); /** Obtain a reference to the smime Protocol. * * The reference is to a static object. * @returns Reference to the smime Protocol. */ QGPGME_EXPORT Protocol *smime(); /** Obtain a reference to a cryptoConfig object. * * The reference is to a static object. * @returns reference to cryptoConfig object. */ QGPGME_EXPORT CryptoConfig *cryptoConfig(); /** Obtain a reference to a protocol agnostic GpgCardJob. * * The reference is to a static object. * @returns reference to a GpgCardJob following the job pattern. */ QGPGME_EXPORT GpgCardJob *gpgCardJob(); } #endif diff --git a/lang/qt/src/protocol_p.h b/lang/qt/src/protocol_p.h index e6b2b8a8..73405c6d 100644 --- a/lang/qt/src/protocol_p.h +++ b/lang/qt/src/protocol_p.h @@ -1,525 +1,538 @@ /* protocol_p.h This file is part of qgpgme, the Qt API binding for gpgme Copyright (c) 2004,2005 Klarälvdalens Datakonsult AB Copyright (c) 2016 by Bundesamt für Sicherheit in der Informationstechnik Software engineering by Intevation GmbH Copyright (c) 2022 by 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_PROTOCOL_P_H__ #define __QGPGME_PROTOCOL_P_H__ #include "qgpgmenewcryptoconfig.h" #include "qgpgmekeygenerationjob.h" #include "qgpgmekeylistjob.h" #include "qgpgmelistallkeysjob.h" #include "qgpgmedecryptjob.h" #include "qgpgmedecryptverifyjob.h" #include "qgpgmerefreshsmimekeysjob.h" #include "qgpgmedeletejob.h" #include "qgpgmedownloadjob.h" #include "qgpgmesignencryptjob.h" #include "qgpgmeencryptarchivejob.h" #include "qgpgmeencryptjob.h" +#include "qgpgmesignarchivejob.h" #include "qgpgmesignjob.h" #include "qgpgmesignkeyjob.h" #include "qgpgmeexportjob.h" #include "qgpgmeverifydetachedjob.h" #include "qgpgmeimportjob.h" #include "qgpgmeimportfromkeyserverjob.h" #include "qgpgmeverifyopaquejob.h" #include "qgpgmechangeexpiryjob.h" #include "qgpgmechangeownertrustjob.h" #include "qgpgmechangepasswdjob.h" #include "qgpgmeaddexistingsubkeyjob.h" #include "qgpgmeadduseridjob.h" #include "qgpgmekeyformailboxjob.h" #include "qgpgmewkdlookupjob.h" #include "qgpgmewkspublishjob.h" #include "qgpgmetofupolicyjob.h" #include "qgpgmequickjob.h" #include "qgpgmereceivekeysjob.h" #include "qgpgmerevokekeyjob.h" #include "qgpgmesetprimaryuseridjob.h" namespace { class Protocol : public QGpgME::Protocol { GpgME::Protocol mProtocol; public: explicit Protocol(GpgME::Protocol proto) : mProtocol(proto) {} QString name() const override { switch (mProtocol) { case GpgME::OpenPGP: return QStringLiteral("OpenPGP"); case GpgME::CMS: return QStringLiteral("SMIME"); default: return QString(); } } QString displayName() const override { // ah (2.4.16): Where is this used and isn't this inverted // with name switch (mProtocol) { case GpgME::OpenPGP: return QStringLiteral("gpg"); case GpgME::CMS: return QStringLiteral("gpgsm"); default: return QStringLiteral("unknown"); } } QGpgME::SpecialJob *specialJob(const char *, const QMap &) const override { return nullptr; } QGpgME::KeyListJob *keyListJob(bool remote, bool includeSigs, bool validate) const override { GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol); if (!context) { return nullptr; } unsigned int mode = context->keyListMode(); if (remote) { mode |= GpgME::Extern; mode &= ~GpgME::Local; } else { mode |= GpgME::Local; mode &= ~GpgME::Extern; } if (includeSigs) { mode |= GpgME::Signatures; } if (validate) { mode |= GpgME::Validate; } context->setKeyListMode(mode); return new QGpgME::QGpgMEKeyListJob(context); } QGpgME::ListAllKeysJob *listAllKeysJob(bool includeSigs, bool validate) const override { GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol); if (!context) { return nullptr; } unsigned int mode = context->keyListMode(); mode |= GpgME::Local; mode &= ~GpgME::Extern; if (includeSigs) { mode |= GpgME::Signatures; } if (validate) { mode |= GpgME::Validate; /* Setting the context to offline mode disables CRL / OCSP checks in this Job. Otherwise we would try to fetch the CRL's for all CMS keys in the users keyring because GpgME::Validate includes remote resources by default in the validity check. This setting only has any effect if gpgsm >= 2.1.6 is used. */ context->setOffline(true); } context->setKeyListMode(mode); return new QGpgME::QGpgMEListAllKeysJob(context); } QGpgME::EncryptJob *encryptJob(bool armor, bool textmode) const override { GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol); if (!context) { return nullptr; } context->setArmor(armor); context->setTextMode(textmode); return new QGpgME::QGpgMEEncryptJob(context); } QGpgME::DecryptJob *decryptJob() const override { GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol); if (!context) { return nullptr; } return new QGpgME::QGpgMEDecryptJob(context); } QGpgME::SignJob *signJob(bool armor, bool textMode) const override { GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol); if (!context) { return nullptr; } context->setArmor(armor); context->setTextMode(textMode); return new QGpgME::QGpgMESignJob(context); } QGpgME::VerifyDetachedJob *verifyDetachedJob(bool textMode) const override { GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol); if (!context) { return nullptr; } context->setTextMode(textMode); return new QGpgME::QGpgMEVerifyDetachedJob(context); } QGpgME::VerifyOpaqueJob *verifyOpaqueJob(bool textMode) const override { GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol); if (!context) { return nullptr; } context->setTextMode(textMode); return new QGpgME::QGpgMEVerifyOpaqueJob(context); } QGpgME::KeyGenerationJob *keyGenerationJob() const override { GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol); if (!context) { return nullptr; } return new QGpgME::QGpgMEKeyGenerationJob(context); } QGpgME::ImportJob *importJob() const override { GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol); if (!context) { return nullptr; } return new QGpgME::QGpgMEImportJob(context); } QGpgME::ImportFromKeyserverJob *importFromKeyserverJob() const override { GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol); if (!context) { return nullptr; } return new QGpgME::QGpgMEImportFromKeyserverJob(context); } QGpgME::ReceiveKeysJob *receiveKeysJob() const override { if (mProtocol != GpgME::OpenPGP) { return nullptr; } GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol); if (!context) { return nullptr; } return new QGpgME::QGpgMEReceiveKeysJob{context}; } QGpgME::ExportJob *publicKeyExportJob(bool armor) const override { GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol); if (!context) { return nullptr; } context->setArmor(armor); return new QGpgME::QGpgMEExportJob(context); } QGpgME::ExportJob *secretKeyExportJob(bool armor, const QString &) const override { GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol); if (!context) { return nullptr; } context->setArmor(armor); return new QGpgME::QGpgMEExportJob(context, GpgME::Context::ExportSecret); } QGpgME::ExportJob *secretSubkeyExportJob(bool armor) const override { GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol); if (!context) { return nullptr; } context->setArmor(armor); return new QGpgME::QGpgMEExportJob(context, GpgME::Context::ExportSecretSubkey); } QGpgME::RefreshKeysJob *refreshKeysJob() const override { if (mProtocol != GpgME::CMS) { return nullptr; } return new QGpgME::QGpgMERefreshSMIMEKeysJob; } QGpgME::DownloadJob *downloadJob(bool armor) const override { GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol); if (!context) { return nullptr; } context->setArmor(armor); // this is the hackish interface for downloading from keyserers currently: context->setKeyListMode(GpgME::Extern); return new QGpgME::QGpgMEDownloadJob(context); } QGpgME::DeleteJob *deleteJob() const override { GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol); if (!context) { return nullptr; } return new QGpgME::QGpgMEDeleteJob(context); } QGpgME::SignEncryptJob *signEncryptJob(bool armor, bool textMode) const override { GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol); if (!context) { return nullptr; } context->setArmor(armor); context->setTextMode(textMode); return new QGpgME::QGpgMESignEncryptJob(context); } QGpgME::DecryptVerifyJob *decryptVerifyJob(bool textMode) const override { GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol); if (!context) { return nullptr; } context->setTextMode(textMode); return new QGpgME::QGpgMEDecryptVerifyJob(context); } QGpgME::ChangeExpiryJob *changeExpiryJob() const override { if (mProtocol != GpgME::OpenPGP) { return nullptr; // only supported by gpg } GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol); if (!context) { return nullptr; } return new QGpgME::QGpgMEChangeExpiryJob(context); } QGpgME::ChangePasswdJob *changePasswdJob() const override { if (!GpgME::hasFeature(GpgME::PasswdFeature, 0)) { return nullptr; } GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol); if (!context) { return nullptr; } return new QGpgME::QGpgMEChangePasswdJob(context); } QGpgME::SignKeyJob *signKeyJob() const override { if (mProtocol != GpgME::OpenPGP) { return nullptr; // only supported by gpg } GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol); if (!context) { return nullptr; } return new QGpgME::QGpgMESignKeyJob(context); } QGpgME::ChangeOwnerTrustJob *changeOwnerTrustJob() const override { if (mProtocol != GpgME::OpenPGP) { return nullptr; // only supported by gpg } GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol); if (!context) { return nullptr; } return new QGpgME::QGpgMEChangeOwnerTrustJob(context); } QGpgME:: AddExistingSubkeyJob *addExistingSubkeyJob() const override { if (mProtocol != GpgME::OpenPGP) { return nullptr; // only supported by gpg } GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol); if (!context) { return nullptr; } return new QGpgME::QGpgMEAddExistingSubkeyJob{context}; } QGpgME::AddUserIDJob *addUserIDJob() const override { if (mProtocol != GpgME::OpenPGP) { return nullptr; // only supported by gpg } GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol); if (!context) { return nullptr; } return new QGpgME::QGpgMEAddUserIDJob(context); } QGpgME::KeyListJob *locateKeysJob() const override { if (mProtocol != GpgME::OpenPGP) { return nullptr; } GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol); if (!context) { return nullptr; } context->setKeyListMode(GpgME::Locate | GpgME::Signatures | GpgME::Validate); return new QGpgME::QGpgMEKeyListJob(context); } QGpgME::KeyForMailboxJob *keyForMailboxJob() const override { GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol); if (!context) { return nullptr; } return new QGpgME::QGpgMEKeyForMailboxJob(context); } QGpgME::WKDLookupJob *wkdLookupJob() const override { if (mProtocol != GpgME::OpenPGP) { return nullptr; } auto context = GpgME::Context::createForEngine(GpgME::AssuanEngine); if (!context) { return nullptr; } return new QGpgME::QGpgMEWKDLookupJob(context.release()); } QGpgME::WKSPublishJob *wksPublishJob() const override { if (mProtocol != GpgME::OpenPGP) { return nullptr; } auto context = GpgME::Context::createForEngine(GpgME::SpawnEngine); if (!context) { return nullptr; } return new QGpgME::QGpgMEWKSPublishJob(context.release()); } QGpgME::TofuPolicyJob *tofuPolicyJob() const override { if (mProtocol != GpgME::OpenPGP) { return nullptr; } GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol); if (!context) { return nullptr; } return new QGpgME::QGpgMETofuPolicyJob(context); } QGpgME::QuickJob *quickJob() const override { if (mProtocol != GpgME::OpenPGP) { return nullptr; } GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol); if (!context) { return nullptr; } return new QGpgME::QGpgMEQuickJob(context); } QGpgME::RevokeKeyJob *revokeKeyJob() const override { if (mProtocol != GpgME::OpenPGP) { return nullptr; } GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol); if (!context) { return nullptr; } return new QGpgME::QGpgMERevokeKeyJob(context); } QGpgME::SetPrimaryUserIDJob *setPrimaryUserIDJob() const override { if (mProtocol != GpgME::OpenPGP) { return nullptr; } GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol); if (!context) { return nullptr; } return new QGpgME::QGpgMESetPrimaryUserIDJob{context}; } QGpgME::EncryptArchiveJob *encryptArchiveJob(bool armor) const override { if (mProtocol != GpgME::OpenPGP) { return nullptr; } if (auto context = GpgME::Context::createForProtocol(mProtocol)) { context->setArmor(armor); return new QGpgME::QGpgMEEncryptArchiveJob{context}; } return nullptr; } + + QGpgME::SignArchiveJob *signArchiveJob(bool armor) const override + { + if (mProtocol != GpgME::OpenPGP) { + return nullptr; + } + if (auto context = GpgME::Context::createForProtocol(mProtocol)) { + context->setArmor(armor); + return new QGpgME::QGpgMESignArchiveJob{context}; + } + return nullptr; + } }; } #endif diff --git a/lang/qt/src/qgpgmesignarchivejob.cpp b/lang/qt/src/qgpgmesignarchivejob.cpp new file mode 100644 index 00000000..d9abec42 --- /dev/null +++ b/lang/qt/src/qgpgmesignarchivejob.cpp @@ -0,0 +1,141 @@ +/* + qgpgmesignarchivejob.cpp + + This file is part of qgpgme, the Qt API binding for gpgme + Copyright (c) 2004,2007,2008 Klarälvdalens Datakonsult AB + Copyright (c) 2016 by Bundesamt für Sicherheit in der Informationstechnik + Software engineering by Intevation GmbH + Copyright (c) 2022,2023 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 "qgpgmesignarchivejob.h" + +#include "dataprovider.h" +#include "signarchivejob_p.h" +#include "filelistdataprovider.h" + +#include + +using namespace QGpgME; +using namespace GpgME; + +namespace +{ + +class QGpgMESignArchiveJobPrivate : public SignArchiveJobPrivate +{ + QGpgMESignArchiveJob *q = nullptr; + +public: + QGpgMESignArchiveJobPrivate(QGpgMESignArchiveJob *qq) + : q{qq} + { + } + + ~QGpgMESignArchiveJobPrivate() override = default; + +private: + void start() override + { + q->run(); + } +}; + +} + +QGpgMESignArchiveJob::QGpgMESignArchiveJob(Context *context) + : mixin_type{context} +{ + setJobPrivate(this, std::unique_ptr{new QGpgMESignArchiveJobPrivate{this}}); + lateInitialization(); +} + +static QGpgMESignArchiveJob::result_type sign(Context *ctx, + QThread *thread, + const std::vector &signers, + const std::vector &paths, + const std::weak_ptr &output_, + const QString &baseDirectory) +{ + const std::shared_ptr output = output_.lock(); + const _detail::ToThreadMover ctMover(output, thread); + + QGpgME::FileListDataProvider in{paths}; + Data indata(&in); + if (!baseDirectory.isEmpty()) { + indata.setFileName(baseDirectory.toStdString()); + } + + QGpgME::QIODeviceDataProvider out{output}; + Data outdata(&out); + + ctx->clearSigningKeys(); + for (const Key &signer : signers) { + if (!signer.isNull()) { + if (const Error err = ctx->addSigningKey(signer)) { + return std::make_tuple(SigningResult{err}, QString{}, Error{}); + } + } + } + + const SigningResult res = ctx->sign(indata, outdata, GpgME::SignArchive); + Error ae; + const QString log = _detail::audit_log_as_html(ctx, ae); + return std::make_tuple(res, log, ae); +} + +GpgME::Error QGpgMESignArchiveJob::start(const std::vector &signers, + const std::vector &paths, + const std::shared_ptr &output) +{ + if (!output) { + return Error::fromCode(GPG_ERR_INV_VALUE); + } + + run(std::bind(&sign, + std::placeholders::_1, + std::placeholders::_2, + signers, + paths, + std::placeholders::_3, + baseDirectory()), + output); + return {}; +} + +void QGpgMESignArchiveJob::resultHook(const result_type &tuple) +{ + mResult = std::get<0>(tuple); +} + +#include "qgpgmesignarchivejob.moc" diff --git a/lang/qt/src/qgpgmesignarchivejob.h b/lang/qt/src/qgpgmesignarchivejob.h new file mode 100644 index 00000000..ade4e8dc --- /dev/null +++ b/lang/qt/src/qgpgmesignarchivejob.h @@ -0,0 +1,76 @@ +/* + qgpgmesignarchivejob.h + + This file is part of qgpgme, the Qt API binding for gpgme + Copyright (c) 2023 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_QGPGMESIGNARCHIVEJOB_H__ +#define __QGPGME_QGPGMESIGNARCHIVEJOB_H__ + +#include "signarchivejob.h" + +#include "threadedjobmixin.h" + +#include +#include + +namespace QGpgME +{ + +class QGpgMESignArchiveJob +#ifdef Q_MOC_RUN + : public SignArchiveJob +#else + : public _detail::ThreadedJobMixin> +#endif +{ + Q_OBJECT +#ifdef Q_MOC_RUN +public Q_SLOTS: + void slotFinished(); +#endif +public: + explicit QGpgMESignArchiveJob(GpgME::Context *context); + ~QGpgMESignArchiveJob() = default; + + GpgME::Error start(const std::vector &signers, + const std::vector &paths, + const std::shared_ptr &output) override; + + /* from ThreadedJobMixin */ + void resultHook(const result_type &r) override; + +private: + GpgME::SigningResult mResult; +}; + +} + +#endif // __QGPGME_QGPGMESIGNARCHIVEJOB_H__ diff --git a/lang/qt/src/signarchivejob.cpp b/lang/qt/src/signarchivejob.cpp new file mode 100644 index 00000000..fcdf241d --- /dev/null +++ b/lang/qt/src/signarchivejob.cpp @@ -0,0 +1,62 @@ +/* + signarchivejob.cpp + + This file is part of qgpgme, the Qt API binding for gpgme + Copyright (c) 2023 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 "signarchivejob.h" +#include "signarchivejob_p.h" + +using namespace QGpgME; + +SignArchiveJob::SignArchiveJob(QObject *parent) + : Job{parent} +{ +} + +SignArchiveJob::~SignArchiveJob() = default; + +void SignArchiveJob::setBaseDirectory(const QString &baseDirectory) +{ + auto d = jobPrivate(this); + d->m_baseDirectory = baseDirectory; +} + +QString SignArchiveJob::baseDirectory() const +{ + auto d = jobPrivate(this); + return d->m_baseDirectory; +} + +#include "signarchivejob.moc" diff --git a/lang/qt/src/signarchivejob.h b/lang/qt/src/signarchivejob.h new file mode 100644 index 00000000..6b8cd175 --- /dev/null +++ b/lang/qt/src/signarchivejob.h @@ -0,0 +1,88 @@ +/* + signarchivejob.h + + This file is part of qgpgme, the Qt API binding for gpgme + Copyright (c) 2023 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_SIGNARCHIVEJOB_H__ +#define __QGPGME_SIGNARCHIVEJOB_H__ + +#include "job.h" + +#ifdef BUILDING_QGPGME +# include "context.h" +#else +# include +#endif + +namespace GpgME +{ +class Key; +} + +namespace QGpgME +{ + +/** + * Abstract base class for job for creating signed archives + */ +class QGPGME_EXPORT SignArchiveJob : public Job +{ + Q_OBJECT +protected: + explicit SignArchiveJob(QObject *parent); +public: + ~SignArchiveJob() override; + + void setBaseDirectory(const QString &baseDirectory); + QString baseDirectory() const; + + /** + * Starts the creation of a signed archive. + * + * Creates a signed archive with the files and directories in \a paths. + * The archive is signed with the keys in \a signers or with the default + * key, if \a signers is empty. The signed archive is written to \a output. + * + * Emits result() when the job has finished. + */ + virtual GpgME::Error start(const std::vector &signers, + const std::vector &paths, + const std::shared_ptr &output) = 0; + +Q_SIGNALS: + void result(const GpgME::SigningResult &result, + const QString &auditLogAsHtml = {}, + const GpgME::Error &auditLogError = {}); +}; + +} + +#endif // __QGPGME_SIGNARCHIVEJOB_H__ diff --git a/lang/qt/src/signarchivejob_p.h b/lang/qt/src/signarchivejob_p.h new file mode 100644 index 00000000..9176e7b4 --- /dev/null +++ b/lang/qt/src/signarchivejob_p.h @@ -0,0 +1,49 @@ +/* + signarchivejob_p.h + + This file is part of qgpgme, the Qt API binding for gpgme + Copyright (c) 2023 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_SIGNARCHIVEJOB_P_H__ +#define __QGPGME_SIGNARCHIVEJOB_P_H__ + +#include "job_p.h" + +namespace QGpgME +{ + +struct SignArchiveJobPrivate : public JobPrivate +{ + QString m_baseDirectory; +}; + +} + +#endif // __QGPGME_SIGNARCHIVEJOB_P_H__ diff --git a/lang/qt/tests/Makefile.am b/lang/qt/tests/Makefile.am index 97e2b417..4e43d986 100644 --- a/lang/qt/tests/Makefile.am +++ b/lang/qt/tests/Makefile.am @@ -1,136 +1,139 @@ # 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-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-revokekey t-setprimaryuserid TESTS = initial.test $(the_tests) final.test moc_files = \ t-addexistingsubkey.moc \ 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-revokekey.moc \ t-setprimaryuserid.moc AM_LDFLAGS = -no-install if WANT_QT5 LDADD = ../../cpp/src/libgpgmepp.la ../src/libqgpgme.la \ ../../../src/libgpgme.la @GPGME_QT5_LIBS@ @GPG_ERROR_LIBS@ \ @GPGME_QT5TEST_LIBS@ @LDADD_FOR_TESTS_KLUDGE@ -lstdc++ AM_CPPFLAGS = -I$(top_srcdir)/lang/cpp/src -I$(top_builddir)/src \ @GPG_ERROR_CFLAGS@ @GPGME_QT5_CFLAGS@ @GPG_ERROR_CFLAGS@ \ @LIBASSUAN_CFLAGS@ @GPGME_QT5TEST_CFLAGS@ -DBUILDING_QGPGME \ -I$(top_srcdir)/lang/qt/src \ -DTOP_SRCDIR="$(top_srcdir)" endif if WANT_QT6 LDADD = ../../cpp/src/libgpgmepp.la ../src/libqgpgmeqt6.la \ ../../../src/libgpgme.la @GPGME_QT6_LIBS@ @GPG_ERROR_LIBS@ \ @GPGME_QT6TEST_LIBS@ @LDADD_FOR_TESTS_KLUDGE@ -lstdc++ AM_CPPFLAGS = -I$(top_srcdir)/lang/cpp/src -I$(top_builddir)/src \ @GPG_ERROR_CFLAGS@ @GPGME_QT6_CFLAGS@ @GPG_ERROR_CFLAGS@ \ @LIBASSUAN_CFLAGS@ @GPGME_QT6TEST_CFLAGS@ -DBUILDING_QGPGME \ -I$(top_srcdir)/lang/qt/src \ -DTOP_SRCDIR="$(top_srcdir)" endif support_src = t-support.h t-support.cpp t_addexistingsubkey_SOURCES = t-addexistingsubkey.cpp $(support_src) 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) t_revokekey_SOURCES = t-revokekey.cpp $(support_src) t_setprimaryuserid_SOURCES = t-setprimaryuserid.cpp $(support_src) run_encryptarchivejob_SOURCES = run-encryptarchivejob.cpp run_exportjob_SOURCES = run-exportjob.cpp run_importjob_SOURCES = run-importjob.cpp run_keyformailboxjob_SOURCES = run-keyformailboxjob.cpp run_receivekeysjob_SOURCES = run-receivekeysjob.cpp run_refreshkeysjob_SOURCES = run-refreshkeysjob.cpp +run_signarchivejob_SOURCES = run-signarchivejob.cpp nodist_t_keylist_SOURCES = $(moc_files) BUILT_SOURCES = $(moc_files) pubring-stamp 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 t-revokekey \ t-setprimaryuserid \ run-encryptarchivejob \ - run-importjob run-exportjob run-receivekeysjob run-refreshkeysjob + run-importjob run-exportjob run-receivekeysjob run-refreshkeysjob \ + run-signarchivejob + 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/run-signarchivejob.cpp b/lang/qt/tests/run-signarchivejob.cpp new file mode 100644 index 00000000..c426ba93 --- /dev/null +++ b/lang/qt/tests/run-signarchivejob.cpp @@ -0,0 +1,145 @@ +/* + run-signarchivejob.cpp + + This file is part of QGpgME's test suite. + Copyright (c) 2023 by 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, + version 2, as published by the Free Software Foundation. + + 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 +#include + +#include +#include +#include +#include + +#include +#include + +#include + +using namespace GpgME; + +std::ostream &operator<<(std::ostream &os, const QString &s) +{ + return os << s.toLocal8Bit().constData(); +} + +struct CommandLineOptions { + bool armor; + QString archiveName; + QString baseDirectory; + std::vector filesAndDirectories; +}; + +CommandLineOptions parseCommandLine(const QStringList &arguments) +{ + CommandLineOptions options; + + QCommandLineParser parser; + parser.setApplicationDescription("Test program for SignArchiveJob"); + parser.addHelpOption(); + parser.addOptions({ + {{"o", "output"}, "Write output to FILE.", "FILE"}, + {{"a", "armor"}, "Create ASCII armored output."}, + {{"C", "directory"}, "Change to DIRECTORY before creating the archive.", "DIRECTORY"}, + }); + parser.addPositionalArgument("files", "Files and directories to add to the archive", "[files] [directories]"); + + parser.process(arguments); + + const auto args = parser.positionalArguments(); + if (args.empty()) { + parser.showHelp(1); + } + + options.armor = parser.isSet("armor"); + options.archiveName = parser.value("output"); + options.baseDirectory = parser.value("directory"); + std::copy(args.begin(), args.end(), std::back_inserter(options.filesAndDirectories)); + + return options; +} + +std::shared_ptr createOutput(const QString &fileName) +{ + std::shared_ptr output; + + if (fileName.isEmpty()) { + output.reset(new QFile); + output->open(stdout, QIODevice::WriteOnly); + } else { + if (QFile::exists(fileName)) { + qCritical() << "File" << fileName << "exists. Bailing out."; + } else { + output.reset(new QFile{fileName}); + output->open(QIODevice::WriteOnly); + } + } + + return output; +} + +int main(int argc, char **argv) +{ + GpgME::initializeLibrary(); + + QCoreApplication app{argc, argv}; + app.setApplicationName("run-signarchivejob"); + + const auto options = parseCommandLine(app.arguments()); + + auto output = createOutput(options.archiveName); + if (!output) { + return 1; + } + + auto job = QGpgME::openpgp()->signArchiveJob(options.armor); + if (!job) { + std::cerr << "Error: Could not create job" << std::endl; + return 1; + } + job->setBaseDirectory(options.baseDirectory); + QObject::connect(job, &QGpgME::SignArchiveJob::result, &app, [](const GpgME::SigningResult &result, const QString &auditLog, const GpgME::Error &) { + std::cerr << "Diagnostics: " << auditLog << std::endl; + std::cerr << "Result: " << result << std::endl; + qApp->quit(); + }); + + const auto err = job->start({}, options.filesAndDirectories, output); + if (err) { + std::cerr << "Error: Starting the job failed: " << err.asString() << std::endl; + return 1; + } + + return app.exec(); +}