diff options
Diffstat (limited to 'lang/qt/src')
-rw-r--r-- | lang/qt/src/Makefile.am | 8 | ||||
-rw-r--r-- | lang/qt/src/protocol.h | 2 | ||||
-rw-r--r-- | lang/qt/src/protocol_p.h | 13 | ||||
-rw-r--r-- | lang/qt/src/qgpgmesignarchivejob.cpp | 141 | ||||
-rw-r--r-- | lang/qt/src/qgpgmesignarchivejob.h | 76 | ||||
-rw-r--r-- | lang/qt/src/signarchivejob.cpp | 62 | ||||
-rw-r--r-- | lang/qt/src/signarchivejob.h | 88 | ||||
-rw-r--r-- | lang/qt/src/signarchivejob_p.h | 49 |
8 files changed, 439 insertions, 0 deletions
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 @@ -49,6 +49,7 @@ qgpgme_sources = \ qgpgmerefreshsmimekeysjob.cpp \ qgpgmerevokekeyjob.cpp \ qgpgmesetprimaryuseridjob.cpp \ + qgpgmesignarchivejob.cpp \ qgpgmesignencryptjob.cpp \ qgpgmesignjob.cpp qgpgmesignkeyjob.cpp qgpgmeverifydetachedjob.cpp \ qgpgmeverifyopaquejob.cpp qgpgmewkdlookupjob.cpp threadedjobmixin.cpp \ @@ -56,6 +57,7 @@ qgpgme_sources = \ 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 @@ -89,6 +91,7 @@ qgpgme_headers= \ revokekeyjob.h \ setprimaryuseridjob.h \ specialjob.h \ + signarchivejob.h \ signjob.h \ signkeyjob.h \ signencryptjob.h \ @@ -137,6 +140,7 @@ camelcase_headers= \ RevokeKeyJob \ SetPrimaryUserIDJob \ SpecialJob \ + SignArchiveJob \ SignJob \ SignKeyJob \ SignEncryptJob \ @@ -189,6 +193,7 @@ private_qgpgme_headers = \ qgpgmerefreshsmimekeysjob.h \ qgpgmerevokekeyjob.h \ qgpgmesetprimaryuseridjob.h \ + qgpgmesignarchivejob.h \ qgpgmesignencryptjob.h \ qgpgmesignjob.h \ qgpgmesignkeyjob.h \ @@ -200,6 +205,7 @@ private_qgpgme_headers = \ qgpgmetofupolicyjob.h \ qgpgmegpgcardjob.h \ qgpgmequickjob.h \ + signarchivejob_p.h \ signencryptjob_p.h \ threadedjobmixin.h \ util.h @@ -247,6 +253,7 @@ qgpgme_moc_sources = \ qgpgmerefreshsmimekeysjob.moc \ qgpgmerevokekeyjob.moc \ qgpgmesetprimaryuseridjob.moc \ + qgpgmesignarchivejob.moc \ qgpgmesignencryptjob.moc \ qgpgmesignjob.moc \ qgpgmesignkeyjob.moc \ @@ -260,6 +267,7 @@ qgpgme_moc_sources = \ refreshkeysjob.moc \ revokekeyjob.moc \ setprimaryuseridjob.moc \ + signarchivejob.moc \ signencryptjob.moc \ signjob.moc \ signkeyjob.moc \ 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 @@ -53,6 +53,7 @@ class DeleteJob; class EncryptArchiveJob; class EncryptJob; class DecryptJob; +class SignArchiveJob; class SignJob; class SignKeyJob; class VerifyDetachedJob; @@ -192,6 +193,7 @@ public: 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. 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 @@ -48,6 +48,7 @@ #include "qgpgmesignencryptjob.h" #include "qgpgmeencryptarchivejob.h" #include "qgpgmeencryptjob.h" +#include "qgpgmesignarchivejob.h" #include "qgpgmesignjob.h" #include "qgpgmesignkeyjob.h" #include "qgpgmeexportjob.h" @@ -519,6 +520,18 @@ public: } 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; + } }; } 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 <[email protected]> + + 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 <data.h> + +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<QGpgMESignArchiveJobPrivate>{new QGpgMESignArchiveJobPrivate{this}}); + lateInitialization(); +} + +static QGpgMESignArchiveJob::result_type sign(Context *ctx, + QThread *thread, + const std::vector<Key> &signers, + const std::vector<QString> &paths, + const std::weak_ptr<QIODevice> &output_, + const QString &baseDirectory) +{ + const std::shared_ptr<QIODevice> 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<GpgME::Key> &signers, + const std::vector<QString> &paths, + const std::shared_ptr<QIODevice> &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 <[email protected]> + + 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 <signingresult.h> +#include <key.h> + +namespace QGpgME +{ + +class QGpgMESignArchiveJob +#ifdef Q_MOC_RUN + : public SignArchiveJob +#else + : public _detail::ThreadedJobMixin<SignArchiveJob, std::tuple<GpgME::SigningResult, QString, GpgME::Error>> +#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<GpgME::Key> &signers, + const std::vector<QString> &paths, + const std::shared_ptr<QIODevice> &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 <[email protected]> + + 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<SignArchiveJobPrivate>(this); + d->m_baseDirectory = baseDirectory; +} + +QString SignArchiveJob::baseDirectory() const +{ + auto d = jobPrivate<SignArchiveJobPrivate>(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 <[email protected]> + + 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 <gpgme++/context.h> +#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<GpgME::Key> &signers, + const std::vector<QString> &paths, + const std::shared_ptr<QIODevice> &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 <[email protected]> + + 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__ |