|
Packit |
d7e8d0 |
/*
|
|
Packit |
d7e8d0 |
qgpgmedecryptverifyjob.cpp
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
This file is part of qgpgme, the Qt API binding for gpgme
|
|
Packit |
d7e8d0 |
Copyright (c) 2004,2008 Klarälvdalens Datakonsult AB
|
|
Packit |
d7e8d0 |
Copyright (c) 2016 by Bundesamt für Sicherheit in der Informationstechnik
|
|
Packit |
d7e8d0 |
Software engineering by Intevation GmbH
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
QGpgME is free software; you can redistribute it and/or
|
|
Packit |
d7e8d0 |
modify it under the terms of the GNU General Public License as
|
|
Packit |
d7e8d0 |
published by the Free Software Foundation; either version 2 of the
|
|
Packit |
d7e8d0 |
License, or (at your option) any later version.
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
QGpgME is distributed in the hope that it will be useful,
|
|
Packit |
d7e8d0 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
d7e8d0 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
d7e8d0 |
General Public License for more details.
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
You should have received a copy of the GNU General Public License along
|
|
Packit |
d7e8d0 |
with this program; if not, write to the Free Software Foundation, Inc.,
|
|
Packit |
d7e8d0 |
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
In addition, as a special exception, the copyright holders give
|
|
Packit |
d7e8d0 |
permission to link the code of this program with any edition of
|
|
Packit |
d7e8d0 |
the Qt library by Trolltech AS, Norway (or with modified versions
|
|
Packit |
d7e8d0 |
of Qt that use the same license as Qt), and distribute linked
|
|
Packit |
d7e8d0 |
combinations including the two. You must obey the GNU General
|
|
Packit |
d7e8d0 |
Public License in all respects for all of the code used other than
|
|
Packit |
d7e8d0 |
Qt. If you modify this file, you may extend this exception to
|
|
Packit |
d7e8d0 |
your version of the file, but you are not obligated to do so. If
|
|
Packit |
d7e8d0 |
you do not wish to do so, delete this exception statement from
|
|
Packit |
d7e8d0 |
your version.
|
|
Packit |
d7e8d0 |
*/
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
#ifdef HAVE_CONFIG_H
|
|
Packit |
d7e8d0 |
#include "config.h"
|
|
Packit |
d7e8d0 |
#endif
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
#include "qgpgmedecryptverifyjob.h"
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
#include "dataprovider.h"
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
#include "context.h"
|
|
Packit |
d7e8d0 |
#include "decryptionresult.h"
|
|
Packit |
d7e8d0 |
#include "verificationresult.h"
|
|
Packit |
d7e8d0 |
#include "data.h"
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
#include <QDebug>
|
|
Packit |
d7e8d0 |
#include "gpgme_backend_debug.h"
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
#include <QBuffer>
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
#include <cassert>
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
using namespace QGpgME;
|
|
Packit |
d7e8d0 |
using namespace GpgME;
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
QGpgMEDecryptVerifyJob::QGpgMEDecryptVerifyJob(Context *context)
|
|
Packit |
d7e8d0 |
: mixin_type(context)
|
|
Packit |
d7e8d0 |
{
|
|
Packit |
d7e8d0 |
lateInitialization();
|
|
Packit |
d7e8d0 |
}
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
QGpgMEDecryptVerifyJob::~QGpgMEDecryptVerifyJob() {}
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
static QGpgMEDecryptVerifyJob::result_type decrypt_verify(Context *ctx, QThread *thread,
|
|
Packit |
d7e8d0 |
const std::weak_ptr<QIODevice> &cipherText_,
|
|
Packit |
d7e8d0 |
const std::weak_ptr<QIODevice> &plainText_)
|
|
Packit |
d7e8d0 |
{
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
qCDebug(GPGPME_BACKEND_LOG);
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
const std::shared_ptr<QIODevice> cipherText = cipherText_.lock();
|
|
Packit |
d7e8d0 |
const std::shared_ptr<QIODevice> plainText = plainText_.lock();
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
const _detail::ToThreadMover ctMover(cipherText, thread);
|
|
Packit |
d7e8d0 |
const _detail::ToThreadMover ptMover(plainText, thread);
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
QGpgME::QIODeviceDataProvider in(cipherText);
|
|
Packit |
d7e8d0 |
const Data indata(&in);
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
if (!plainText) {
|
|
Packit |
d7e8d0 |
QGpgME::QByteArrayDataProvider out;
|
|
Packit |
d7e8d0 |
Data outdata(&out;;
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
const std::pair<DecryptionResult, VerificationResult> res = ctx->decryptAndVerify(indata, outdata);
|
|
Packit |
d7e8d0 |
Error ae;
|
|
Packit |
d7e8d0 |
const QString log = _detail::audit_log_as_html(ctx, ae);
|
|
Packit |
d7e8d0 |
qCDebug(GPGPME_BACKEND_LOG) << "End no plainText. Error: " << ae;
|
|
Packit |
d7e8d0 |
return std::make_tuple(res.first, res.second, out.data(), log, ae);
|
|
Packit |
d7e8d0 |
} else {
|
|
Packit |
d7e8d0 |
QGpgME::QIODeviceDataProvider out(plainText);
|
|
Packit |
d7e8d0 |
Data outdata(&out;;
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
const std::pair<DecryptionResult, VerificationResult> res = ctx->decryptAndVerify(indata, outdata);
|
|
Packit |
d7e8d0 |
Error ae;
|
|
Packit |
d7e8d0 |
const QString log = _detail::audit_log_as_html(ctx, ae);
|
|
Packit |
d7e8d0 |
qCDebug(GPGPME_BACKEND_LOG) << "End plainText. Error: " << ae;
|
|
Packit |
d7e8d0 |
return std::make_tuple(res.first, res.second, QByteArray(), log, ae);
|
|
Packit |
d7e8d0 |
}
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
}
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
static QGpgMEDecryptVerifyJob::result_type decrypt_verify_qba(Context *ctx, const QByteArray &cipherText)
|
|
Packit |
d7e8d0 |
{
|
|
Packit |
d7e8d0 |
const std::shared_ptr<QBuffer> buffer(new QBuffer);
|
|
Packit |
d7e8d0 |
buffer->setData(cipherText);
|
|
Packit |
d7e8d0 |
if (!buffer->open(QIODevice::ReadOnly)) {
|
|
Packit |
d7e8d0 |
assert(!"This should never happen: QBuffer::open() failed");
|
|
Packit |
d7e8d0 |
}
|
|
Packit Service |
30b792 |
return decrypt_verify(ctx, nullptr, buffer, std::shared_ptr<QIODevice>());
|
|
Packit |
d7e8d0 |
}
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
Error QGpgMEDecryptVerifyJob::start(const QByteArray &cipherText)
|
|
Packit |
d7e8d0 |
{
|
|
Packit |
d7e8d0 |
run(std::bind(&decrypt_verify_qba, std::placeholders::_1, cipherText));
|
|
Packit |
d7e8d0 |
return Error();
|
|
Packit |
d7e8d0 |
}
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
void QGpgMEDecryptVerifyJob::start(const std::shared_ptr<QIODevice> &cipherText, const std::shared_ptr<QIODevice> &plainText)
|
|
Packit |
d7e8d0 |
{
|
|
Packit |
d7e8d0 |
run(std::bind(&decrypt_verify, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4), cipherText, plainText);
|
|
Packit |
d7e8d0 |
}
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
std::pair<GpgME::DecryptionResult, GpgME::VerificationResult>
|
|
Packit |
d7e8d0 |
QGpgME::QGpgMEDecryptVerifyJob::exec(const QByteArray &cipherText, QByteArray &plainText)
|
|
Packit |
d7e8d0 |
{
|
|
Packit |
d7e8d0 |
const result_type r = decrypt_verify_qba(context(), cipherText);
|
|
Packit |
d7e8d0 |
plainText = std::get<2>(r);
|
|
Packit |
d7e8d0 |
resultHook(r);
|
|
Packit |
d7e8d0 |
return mResult;
|
|
Packit |
d7e8d0 |
}
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
//PENDING(marc) implement showErrorDialog()
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
void QGpgMEDecryptVerifyJob::resultHook(const result_type &tuple)
|
|
Packit |
d7e8d0 |
{
|
|
Packit |
d7e8d0 |
mResult = std::make_pair(std::get<0>(tuple), std::get<1>(tuple));
|
|
Packit |
d7e8d0 |
}
|
|
Packit |
d7e8d0 |
#include "qgpgmedecryptverifyjob.moc"
|