aboutsummaryrefslogtreecommitdiffstats
path: root/lang/qt/src/qgpgmeverifydetachedjob.cpp
diff options
context:
space:
mode:
authorIngo Klöcker <[email protected]>2024-01-05 11:10:22 +0000
committerIngo Klöcker <[email protected]>2024-01-05 11:10:22 +0000
commitc631622484dc9c00a05e3c25c53ef263db83b381 (patch)
tree84d9986d50ea50d3ff66d175ea36da47e21761b0 /lang/qt/src/qgpgmeverifydetachedjob.cpp
parentcore: Tell gpg that we want to verify signed data (diff)
downloadgpgme-c631622484dc9c00a05e3c25c53ef263db83b381.tar.gz
gpgme-c631622484dc9c00a05e3c25c53ef263db83b381.zip
qt: Support verification of detached signatures directly from files
* lang/qt/src/Makefile.am: Add new files. * lang/qt/src/job.cpp (VerifyDetachedJob): Move definition of constructor and destructor and inclusion of the moc file to the corresponding .cpp file. * lang/qt/src/verifydetachedjob.cpp: New. * lang/qt/src/verifydetachedjob.h (VerifyDetachedJob): Add member functions setSignatureFile, signatureFile, setSignedFile, signedFile. * lang/qt/src/verifydetachedjob_p.h: New. * lang/qt/src/qgpgmeverifydetachedjob.cpp (class QGpgMEVerifyDetachedJobPrivate): New. (QGpgMEVerifyDetachedJob::QGpgMEVerifyDetachedJob): Instantiate private job class. (verify_from_filename): New. * lang/qt/tests/Makefile.am: Add new test program. * lang/qt/tests/run-verifydetachedjob.cpp: New. -- This makes it possible to tell gpg to read the input directly from the specified files bypassing GpgME's Data IO when verifying a detached signature. GnuPG-bug-id: 6550
Diffstat (limited to 'lang/qt/src/qgpgmeverifydetachedjob.cpp')
-rw-r--r--lang/qt/src/qgpgmeverifydetachedjob.cpp78
1 files changed, 73 insertions, 5 deletions
diff --git a/lang/qt/src/qgpgmeverifydetachedjob.cpp b/lang/qt/src/qgpgmeverifydetachedjob.cpp
index 52d4329b..57b3c368 100644
--- a/lang/qt/src/qgpgmeverifydetachedjob.cpp
+++ b/lang/qt/src/qgpgmeverifydetachedjob.cpp
@@ -39,10 +39,14 @@
#include "qgpgmeverifydetachedjob.h"
#include "dataprovider.h"
+#include "util.h"
+#include "verifydetachedjob_p.h"
-#include "context.h"
-#include "verificationresult.h"
-#include "data.h"
+#include <QFile>
+
+#include <context.h>
+#include <data.h>
+#include <verificationresult.h>
#include <cassert>
@@ -50,9 +54,36 @@
using namespace QGpgME;
using namespace GpgME;
+namespace
+{
+
+class QGpgMEVerifyDetachedJobPrivate : public VerifyDetachedJobPrivate
+{
+ QGpgMEVerifyDetachedJob *q = nullptr;
+
+public:
+ QGpgMEVerifyDetachedJobPrivate(QGpgMEVerifyDetachedJob *qq)
+ : q{qq}
+ {
+ }
+
+ ~QGpgMEVerifyDetachedJobPrivate() override = default;
+
+private:
+ GpgME::Error startIt() override;
+
+ void startNow() override
+ {
+ q->run();
+ }
+};
+
+}
+
QGpgMEVerifyDetachedJob::QGpgMEVerifyDetachedJob(Context *context)
: mixin_type(context)
{
+ setJobPrivate(this, std::unique_ptr<QGpgMEVerifyDetachedJobPrivate>{new QGpgMEVerifyDetachedJobPrivate{this}});
lateInitialization();
}
@@ -98,6 +129,31 @@ static QGpgMEVerifyDetachedJob::result_type verify_detached_qba(Context *ctx, co
}
+static QGpgMEVerifyDetachedJob::result_type verify_from_filename(Context *ctx,
+ const QString &signatureFilePath,
+ const QString &signedFilePath)
+{
+ Data signatureData;
+#ifdef Q_OS_WIN
+ signatureData.setFileName(signatureFilePath().toUtf8().constData());
+#else
+ signatureData.setFileName(QFile::encodeName(signatureFilePath).constData());
+#endif
+
+ Data signedData;
+#ifdef Q_OS_WIN
+ signedData.setFileName(signedFilePath().toUtf8().constData());
+#else
+ signedData.setFileName(QFile::encodeName(signedFilePath).constData());
+#endif
+
+ const auto verificationResult = ctx->verifyDetachedSignature(signatureData, signedData);
+
+ Error ae;
+ const QString log = _detail::audit_log_as_html(ctx, ae);
+ return std::make_tuple(verificationResult, log, ae);
+}
+
Error QGpgMEVerifyDetachedJob::start(const QByteArray &signature, const QByteArray &signedData)
{
run(std::bind(&verify_detached_qba, std::placeholders::_1, signature, signedData));
@@ -117,10 +173,22 @@ GpgME::VerificationResult QGpgME::QGpgMEVerifyDetachedJob::exec(const QByteArray
return mResult;
}
-//PENDING(marc) implement showErrorDialog()
-
void QGpgME::QGpgMEVerifyDetachedJob::resultHook(const result_type &tuple)
{
mResult = std::get<0>(tuple);
}
+
+GpgME::Error QGpgMEVerifyDetachedJobPrivate::startIt()
+{
+ if (m_signatureFilePath.isEmpty() || m_signedFilePath.isEmpty()) {
+ return Error::fromCode(GPG_ERR_INV_VALUE);
+ }
+
+ q->run([=](Context *ctx) {
+ return verify_from_filename(ctx, m_signatureFilePath, m_signedFilePath);
+ });
+
+ return {};
+}
+
#include "qgpgmeverifydetachedjob.moc"