aboutsummaryrefslogtreecommitdiffstats
path: root/lang/qt/src
diff options
context:
space:
mode:
Diffstat (limited to 'lang/qt/src')
-rw-r--r--lang/qt/src/Makefile.am8
-rw-r--r--lang/qt/src/encryptarchivejob.cpp62
-rw-r--r--lang/qt/src/encryptarchivejob.h101
-rw-r--r--lang/qt/src/encryptarchivejob_p.h49
-rw-r--r--lang/qt/src/protocol.h3
-rw-r--r--lang/qt/src/protocol_p.h13
-rw-r--r--lang/qt/src/qgpgmeencryptarchivejob.cpp152
-rw-r--r--lang/qt/src/qgpgmeencryptarchivejob.h82
8 files changed, 470 insertions, 0 deletions
diff --git a/lang/qt/src/Makefile.am b/lang/qt/src/Makefile.am
index 40a73861..240e5716 100644
--- a/lang/qt/src/Makefile.am
+++ b/lang/qt/src/Makefile.am
@@ -34,12 +34,14 @@ EXTRA_DIST = QGpgmeConfig.cmake.in.in QGpgmeConfigVersion.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 \
@@ -71,6 +73,7 @@ qgpgme_headers= \
decryptjob.h \
decryptverifyjob.h \
downloadjob.h \
+ encryptarchivejob.h \
encryptjob.h \
exportjob.h \
filelistdataprovider.h \
@@ -120,6 +123,7 @@ camelcase_headers= \
DecryptVerifyJob \
DN \
DownloadJob \
+ EncryptArchiveJob \
EncryptJob \
ExportJob \
FileListDataProvider \
@@ -156,6 +160,7 @@ camelcase_headers= \
private_qgpgme_headers = \
changeexpiryjob_p.h \
+ encryptarchivejob_p.h \
encryptjob_p.h \
importjob_p.h \
listallkeysjob_p.h \
@@ -172,6 +177,7 @@ private_qgpgme_headers = \
qgpgmedecryptverifyjob.h \
qgpgmedeletejob.h \
qgpgmedownloadjob.h \
+ qgpgmeencryptarchivejob.h \
qgpgmeencryptjob.h \
qgpgmeexportjob.h \
qgpgmeimportfromkeyserverjob.h \
@@ -209,6 +215,7 @@ qgpgme_moc_sources = \
decryptverifyjob.moc \
deletejob.moc \
downloadjob.moc \
+ encryptarchivejob.moc \
encryptjob.moc \
exportjob.moc \
hierarchicalkeylistjob.moc \
@@ -228,6 +235,7 @@ qgpgme_moc_sources = \
qgpgmedecryptverifyjob.moc \
qgpgmedeletejob.moc \
qgpgmedownloadjob.moc \
+ qgpgmeencryptarchivejob.moc \
qgpgmeencryptjob.moc \
qgpgmeexportjob.moc \
qgpgmeimportfromkeyserverjob.moc \
diff --git a/lang/qt/src/encryptarchivejob.cpp b/lang/qt/src/encryptarchivejob.cpp
new file mode 100644
index 00000000..5c5533be
--- /dev/null
+++ b/lang/qt/src/encryptarchivejob.cpp
@@ -0,0 +1,62 @@
+/*
+ encryptarchivejob.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 "encryptarchivejob.h"
+#include "encryptarchivejob_p.h"
+
+using namespace QGpgME;
+
+EncryptArchiveJob::EncryptArchiveJob(QObject *parent)
+ : Job{parent}
+{
+}
+
+EncryptArchiveJob::~EncryptArchiveJob() = default;
+
+void EncryptArchiveJob::setBaseDirectory(const QString &baseDirectory)
+{
+ auto d = jobPrivate<EncryptArchiveJobPrivate>(this);
+ d->m_baseDirectory = baseDirectory;
+}
+
+QString EncryptArchiveJob::baseDirectory() const
+{
+ auto d = jobPrivate<EncryptArchiveJobPrivate>(this);
+ return d->m_baseDirectory;
+}
+
+#include "encryptarchivejob.moc"
diff --git a/lang/qt/src/encryptarchivejob.h b/lang/qt/src/encryptarchivejob.h
new file mode 100644
index 00000000..1221994f
--- /dev/null
+++ b/lang/qt/src/encryptarchivejob.h
@@ -0,0 +1,101 @@
+/*
+ encryptarchivejob.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_ENCRYPTARCHIVEJOB_H__
+#define __QGPGME_ENCRYPTARCHIVEJOB_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 encrypted archives
+ */
+class QGPGME_EXPORT EncryptArchiveJob : public Job
+{
+ Q_OBJECT
+protected:
+ explicit EncryptArchiveJob(QObject *parent);
+public:
+ ~EncryptArchiveJob() override;
+
+ void setBaseDirectory(const QString &baseDirectory);
+ QString baseDirectory() const;
+
+ /**
+ * Starts the creation of an encrypted archive.
+ *
+ * Encrypts the files and directories in \a paths into an archive for the
+ * keys in \a recipients. If \a recipients is empty, then symmetric
+ * encryption is performed. The encrypted archive is written to \a cipherText.
+ *
+ * Emits result() when the job has finished.
+ */
+ virtual GpgME::Error start(const std::vector<GpgME::Key> &recipients,
+ const std::vector<QString> &paths,
+ const std::shared_ptr<QIODevice> &cipherText,
+ const GpgME::Context::EncryptionFlags flags) = 0;
+
+ /**
+ * Creates an encrypted archive.
+ *
+ * Encrypts the files and directories in \a paths into an archive for the
+ * keys in \a recipients. If \a recipients is empty, then symmetric
+ * encryption is performed. The encrypted archive is written to \a cipherText.
+ */
+ // virtual GpgME::EncryptionResult exec(const std::vector<GpgME::Key> &recipients,
+ // const std::vector<QString> &paths,
+ // const std::shared_ptr<QIODevice> &cipherText,
+ // const GpgME::Context::EncryptionFlags flags) = 0;
+
+Q_SIGNALS:
+ void result(const GpgME::EncryptionResult &result,
+ const QString &auditLogAsHtml = {},
+ const GpgME::Error &auditLogError = {});
+};
+
+}
+
+#endif // __QGPGME_ENCRYPTARCHIVEJOB_H__
diff --git a/lang/qt/src/encryptarchivejob_p.h b/lang/qt/src/encryptarchivejob_p.h
new file mode 100644
index 00000000..798096db
--- /dev/null
+++ b/lang/qt/src/encryptarchivejob_p.h
@@ -0,0 +1,49 @@
+/*
+ encryptarchivejob_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_ENCRYPTARCHIVEJOB_P_H__
+#define __QGPGME_ENCRYPTARCHIVEJOB_P_H__
+
+#include "job_p.h"
+
+namespace QGpgME
+{
+
+struct EncryptArchiveJobPrivate : public JobPrivate
+{
+ QString m_baseDirectory;
+};
+
+}
+
+#endif // __QGPGME_ENCRYPTARCHIVEJOB_P_H__
diff --git a/lang/qt/src/protocol.h b/lang/qt/src/protocol.h
index 019633a8..bb9f060b 100644
--- a/lang/qt/src/protocol.h
+++ b/lang/qt/src/protocol.h
@@ -50,6 +50,7 @@ class ImportFromKeyserverJob;
class ExportJob;
class DownloadJob;
class DeleteJob;
+class EncryptArchiveJob;
class EncryptJob;
class DecryptJob;
class SignJob;
@@ -189,6 +190,8 @@ public:
* OpenPGP key.
*/
virtual SetPrimaryUserIDJob *setPrimaryUserIDJob() const = 0;
+
+ virtual EncryptArchiveJob *encryptArchiveJob(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 915fef99..e6b2b8a8 100644
--- a/lang/qt/src/protocol_p.h
+++ b/lang/qt/src/protocol_p.h
@@ -46,6 +46,7 @@
#include "qgpgmedeletejob.h"
#include "qgpgmedownloadjob.h"
#include "qgpgmesignencryptjob.h"
+#include "qgpgmeencryptarchivejob.h"
#include "qgpgmeencryptjob.h"
#include "qgpgmesignjob.h"
#include "qgpgmesignkeyjob.h"
@@ -506,6 +507,18 @@ public:
}
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;
+ }
};
}
diff --git a/lang/qt/src/qgpgmeencryptarchivejob.cpp b/lang/qt/src/qgpgmeencryptarchivejob.cpp
new file mode 100644
index 00000000..63c55364
--- /dev/null
+++ b/lang/qt/src/qgpgmeencryptarchivejob.cpp
@@ -0,0 +1,152 @@
+/*
+ qgpgmeencryptarchivejob.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 "qgpgmeencryptarchivejob.h"
+
+#include "dataprovider.h"
+#include "encryptarchivejob_p.h"
+#include "filelistdataprovider.h"
+
+// #include <context.h>
+#include <data.h>
+// #include <encryptionresult.h>
+//
+// #include <QBuffer>
+// #include <QFileInfo>
+//
+// #include <cassert>
+
+using namespace QGpgME;
+using namespace GpgME;
+
+namespace
+{
+
+class QGpgMEEncryptArchiveJobPrivate : public EncryptArchiveJobPrivate
+{
+ QGpgMEEncryptArchiveJob *q = nullptr;
+
+public:
+ QGpgMEEncryptArchiveJobPrivate(QGpgMEEncryptArchiveJob *qq)
+ : q{qq}
+ {
+ }
+
+ ~QGpgMEEncryptArchiveJobPrivate() override = default;
+
+private:
+ void start() override
+ {
+ q->run();
+ }
+};
+
+}
+
+QGpgMEEncryptArchiveJob::QGpgMEEncryptArchiveJob(Context *context)
+ : mixin_type{context}
+{
+ setJobPrivate(this, std::unique_ptr<QGpgMEEncryptArchiveJobPrivate>{new QGpgMEEncryptArchiveJobPrivate{this}});
+ lateInitialization();
+}
+
+static QGpgMEEncryptArchiveJob::result_type encrypt(Context *ctx,
+ QThread *thread,
+ const std::vector<Key> &recipients,
+ const std::vector<QString> &paths,
+ const std::weak_ptr<QIODevice> &cipherText_,
+ Context::EncryptionFlags flags,
+ const QString &baseDirectory)
+{
+ const std::shared_ptr<QIODevice> cipherText = cipherText_.lock();
+ const _detail::ToThreadMover ctMover(cipherText, thread);
+
+ QGpgME::FileListDataProvider in{paths};
+ Data indata(&in);
+ if (!baseDirectory.isEmpty()) {
+ indata.setFileName(baseDirectory.toStdString());
+ }
+
+ QGpgME::QIODeviceDataProvider out{cipherText};
+ Data outdata(&out);
+
+ flags = static_cast<Context::EncryptionFlags>(flags | Context::EncryptArchive);
+ const EncryptionResult res = ctx->encrypt(recipients, indata, outdata, flags);
+ Error ae;
+ const QString log = _detail::audit_log_as_html(ctx, ae);
+ return std::make_tuple(res, log, ae);
+}
+
+GpgME::Error QGpgMEEncryptArchiveJob::start(const std::vector<GpgME::Key> &recipients,
+ const std::vector<QString> &paths,
+ const std::shared_ptr<QIODevice> &cipherText,
+ const GpgME::Context::EncryptionFlags flags)
+{
+ if (!cipherText) {
+ return Error::fromCode(GPG_ERR_INV_VALUE);
+ }
+
+ run(std::bind(&encrypt,
+ std::placeholders::_1,
+ std::placeholders::_2,
+ recipients,
+ paths,
+ std::placeholders::_3,
+ flags,
+ baseDirectory()),
+ cipherText);
+ return {};
+}
+
+// EncryptionResult QGpgMEEncryptArchiveJob::exec(const std::vector<Key> &recipients, const QByteArray &plainText,
+// const Context::EncryptionFlags eflags, QByteArray &cipherText)
+// {
+// const result_type r = encrypt_qba(context(), recipients, plainText, eflags, mOutputIsBase64Encoded, fileName());
+// cipherText = std::get<1>(r);
+// resultHook(r);
+// return mResult;
+// }
+
+void QGpgMEEncryptArchiveJob::resultHook(const result_type &tuple)
+{
+ mResult = std::get<0>(tuple);
+}
+
+#include "qgpgmeencryptarchivejob.moc"
diff --git a/lang/qt/src/qgpgmeencryptarchivejob.h b/lang/qt/src/qgpgmeencryptarchivejob.h
new file mode 100644
index 00000000..81398d07
--- /dev/null
+++ b/lang/qt/src/qgpgmeencryptarchivejob.h
@@ -0,0 +1,82 @@
+/*
+ qgpgmeencryptarchivejob.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_QGPGMEENCRYPTARCHIVEJOB_H__
+#define __QGPGME_QGPGMEENCRYPTARCHIVEJOB_H__
+
+#include "encryptarchivejob.h"
+
+#include "threadedjobmixin.h"
+
+#include <encryptionresult.h>
+#include <key.h>
+
+namespace QGpgME
+{
+
+class QGpgMEEncryptArchiveJob
+#ifdef Q_MOC_RUN
+ : public EncryptArchiveJob
+#else
+ : public _detail::ThreadedJobMixin<EncryptArchiveJob, std::tuple<GpgME::EncryptionResult, QString, GpgME::Error>>
+#endif
+{
+ Q_OBJECT
+#ifdef Q_MOC_RUN
+public Q_SLOTS:
+ void slotFinished();
+#endif
+public:
+ explicit QGpgMEEncryptArchiveJob(GpgME::Context *context);
+ ~QGpgMEEncryptArchiveJob() = default;
+
+ GpgME::Error start(const std::vector<GpgME::Key> &recipients,
+ const std::vector<QString> &paths,
+ const std::shared_ptr<QIODevice> &cipherText,
+ const GpgME::Context::EncryptionFlags flags) override;
+
+ // GpgME::EncryptionResult exec(const std::vector<GpgME::Key> &recipients,
+ // const std::vector<QString> &paths,
+ // const std::shared_ptr<QIODevice> &cipherText,
+ // const GpgME::Context::EncryptionFlags flags) override;
+
+ /* from ThreadedJobMixin */
+ void resultHook(const result_type &r) override;
+
+private:
+ GpgME::EncryptionResult mResult;
+};
+
+}
+
+#endif // __QGPGME_QGPGMEENCRYPTARCHIVEJOB_H__