From d5c44099863d0968a0cbf8f10f04ecf3f4e8ff17 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Mon, 11 Dec 2017 20:38:09 +0100 Subject: Stop using useless abstractions (that are not even threadsafe) --- .../src/domain/mime/mimetreeparser/CMakeLists.txt | 6 - .../mimetreeparser/applicationpgpencrypted.cpp | 4 +- .../mime/mimetreeparser/applicationpkcs7mime.cpp | 13 +- .../mime/mimetreeparser/cryptobodypartmemento.cpp | 56 ------ .../mime/mimetreeparser/cryptobodypartmemento.h | 75 -------- .../decryptverifybodypartmemento.cpp | 86 --------- .../mimetreeparser/decryptverifybodypartmemento.h | 81 -------- .../src/domain/mime/mimetreeparser/messagepart.cpp | 207 +++++++++------------ .../src/domain/mime/mimetreeparser/messagepart.h | 22 +-- .../mime/mimetreeparser/multipartencrypted.cpp | 8 +- .../domain/mime/mimetreeparser/multipartsigned.cpp | 11 +- .../mime/mimetreeparser/qgpgmejobexecutor.cpp | 158 ---------------- .../domain/mime/mimetreeparser/qgpgmejobexecutor.h | 86 --------- .../verifydetachedbodypartmemento.cpp | 177 ------------------ .../mimetreeparser/verifydetachedbodypartmemento.h | 87 --------- .../mimetreeparser/verifyopaquebodypartmemento.cpp | 179 ------------------ .../mimetreeparser/verifyopaquebodypartmemento.h | 93 --------- 17 files changed, 110 insertions(+), 1239 deletions(-) delete mode 100644 framework/src/domain/mime/mimetreeparser/cryptobodypartmemento.cpp delete mode 100644 framework/src/domain/mime/mimetreeparser/cryptobodypartmemento.h delete mode 100644 framework/src/domain/mime/mimetreeparser/decryptverifybodypartmemento.cpp delete mode 100644 framework/src/domain/mime/mimetreeparser/decryptverifybodypartmemento.h delete mode 100644 framework/src/domain/mime/mimetreeparser/qgpgmejobexecutor.cpp delete mode 100644 framework/src/domain/mime/mimetreeparser/qgpgmejobexecutor.h delete mode 100644 framework/src/domain/mime/mimetreeparser/verifydetachedbodypartmemento.cpp delete mode 100644 framework/src/domain/mime/mimetreeparser/verifydetachedbodypartmemento.h delete mode 100644 framework/src/domain/mime/mimetreeparser/verifyopaquebodypartmemento.cpp delete mode 100644 framework/src/domain/mime/mimetreeparser/verifyopaquebodypartmemento.h diff --git a/framework/src/domain/mime/mimetreeparser/CMakeLists.txt b/framework/src/domain/mime/mimetreeparser/CMakeLists.txt index 6f8c1993..e0bfec51 100644 --- a/framework/src/domain/mime/mimetreeparser/CMakeLists.txt +++ b/framework/src/domain/mime/mimetreeparser/CMakeLists.txt @@ -34,14 +34,8 @@ set(libmimetreeparser_SRCS nodehelper.cpp messagepart.cpp partnodebodypart.cpp - #Mementos - cryptobodypartmemento.cpp - decryptverifybodypartmemento.cpp - verifydetachedbodypartmemento.cpp - verifyopaquebodypartmemento.cpp #Stuff mimetreeparser_debug.cpp - qgpgmejobexecutor.cpp util.cpp ) diff --git a/framework/src/domain/mime/mimetreeparser/applicationpgpencrypted.cpp b/framework/src/domain/mime/mimetreeparser/applicationpgpencrypted.cpp index 6d0089c2..122a7577 100644 --- a/framework/src/domain/mime/mimetreeparser/applicationpgpencrypted.cpp +++ b/framework/src/domain/mime/mimetreeparser/applicationpgpencrypted.cpp @@ -24,8 +24,6 @@ #include "objecttreeparser.h" #include "messagepart.h" -#include - #include #include "mimetreeparser_debug.h" @@ -61,7 +59,7 @@ MessagePart::Ptr ApplicationPGPEncryptedBodyPartFormatter::process(Interface::Bo } EncryptedMessagePart::Ptr mp(new EncryptedMessagePart(part.objectTreeParser(), - data->decodedText(), QGpgME::openpgp(), + data->decodedText(), GpgME::OpenPGP, part.nodeHelper()->fromAsString(data), node, data)); mp->setIsEncrypted(true); return mp; diff --git a/framework/src/domain/mime/mimetreeparser/applicationpkcs7mime.cpp b/framework/src/domain/mime/mimetreeparser/applicationpkcs7mime.cpp index fe744c38..f65aa938 100644 --- a/framework/src/domain/mime/mimetreeparser/applicationpkcs7mime.cpp +++ b/framework/src/domain/mime/mimetreeparser/applicationpkcs7mime.cpp @@ -52,15 +52,11 @@ MessagePart::Ptr ApplicationPkcs7MimeBodyPartFormatter::process(Interface::BodyP return MessagePart::Ptr(); } - const auto smimeCrypto = QGpgME::smime(); - if (!smimeCrypto) { - return MessagePart::Ptr(); - } const QString smimeType = node->contentType()->parameter(QStringLiteral("smime-type")).toLower(); if (smimeType == QLatin1String("certs-only")) { - return CertMessagePart::Ptr(new CertMessagePart(part.objectTreeParser(), node, smimeCrypto)); + return CertMessagePart::Ptr(new CertMessagePart(part.objectTreeParser(), node, GpgME::CMS)); } bool isSigned = (smimeType == QLatin1String("signed-data")); @@ -83,7 +79,7 @@ MessagePart::Ptr ApplicationPkcs7MimeBodyPartFormatter::process(Interface::BodyP } auto _mp = EncryptedMessagePart::Ptr(new EncryptedMessagePart(part.objectTreeParser(), - node->decodedText(), smimeCrypto, + node->decodedText(), GpgME::CMS, part.nodeHelper()->fromAsString(node), node)); mp = _mp; _mp->setIsEncrypted(true); @@ -129,11 +125,8 @@ MessagePart::Ptr ApplicationPkcs7MimeBodyPartFormatter::process(Interface::BodyP const QTextCodec *aCodec(part.objectTreeParser()->codecFor(signTestNode)); const QByteArray signaturetext = signTestNode->decodedContent(); auto mp = SignedMessagePart::Ptr(new SignedMessagePart(part.objectTreeParser(), - aCodec->toUnicode(signaturetext), smimeCrypto, + aCodec->toUnicode(signaturetext), GpgME::CMS, part.nodeHelper()->fromAsString(node), signTestNode, signTestNode)); - if (!smimeCrypto) { - mp->partMetaData()->auditLogError = GpgME::Error(GPG_ERR_NOT_IMPLEMENTED); - } } return mp; } diff --git a/framework/src/domain/mime/mimetreeparser/cryptobodypartmemento.cpp b/framework/src/domain/mime/mimetreeparser/cryptobodypartmemento.cpp deleted file mode 100644 index a884ec36..00000000 --- a/framework/src/domain/mime/mimetreeparser/cryptobodypartmemento.cpp +++ /dev/null @@ -1,56 +0,0 @@ -/* - Copyright (c) 2014-2017 Montel Laurent - - This program 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. - - This program 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 -*/ - -#include "cryptobodypartmemento.h" - -using namespace GpgME; -using namespace MimeTreeParser; - -CryptoBodyPartMemento::CryptoBodyPartMemento() - : QObject(nullptr), - Interface::BodyPartMemento(), - m_running(false) -{ - -} - -CryptoBodyPartMemento::~CryptoBodyPartMemento() -{ - -} - -bool CryptoBodyPartMemento::isRunning() const -{ - return m_running; -} - -void CryptoBodyPartMemento::setAuditLog(const Error &err, const QString &log) -{ - m_auditLogError = err; - m_auditLog = log; -} - -void CryptoBodyPartMemento::setRunning(bool running) -{ - m_running = running; -} - -void CryptoBodyPartMemento::detach() -{ - disconnect(this, SIGNAL(update(MimeTreeParser::UpdateMode)), nullptr, nullptr); -} - diff --git a/framework/src/domain/mime/mimetreeparser/cryptobodypartmemento.h b/framework/src/domain/mime/mimetreeparser/cryptobodypartmemento.h deleted file mode 100644 index 076ed890..00000000 --- a/framework/src/domain/mime/mimetreeparser/cryptobodypartmemento.h +++ /dev/null @@ -1,75 +0,0 @@ -/* - Copyright (c) 2014-2016 Montel Laurent - - This program 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. - - This program 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 -*/ - -#ifndef __MIMETREEPARSER_CRYPTOBODYPARTMEMENTO_H__ -#define __MIMETREEPARSER_CRYPTOBODYPARTMEMENTO_H__ - -#include - -#include -#include - -#include "bodypart.h" -#include "enums.h" - -namespace MimeTreeParser -{ - -class CryptoBodyPartMemento - : public QObject, - public Interface::BodyPartMemento -{ - Q_OBJECT -public: - CryptoBodyPartMemento(); - ~CryptoBodyPartMemento(); - - virtual bool start() = 0; - virtual void exec() = 0; - bool isRunning() const; - - const QString &auditLogAsHtml() const - { - return m_auditLog; - } - GpgME::Error auditLogError() const - { - return m_auditLogError; - } - - void detach() Q_DECL_OVERRIDE; - -Q_SIGNALS: - void update(MimeTreeParser::UpdateMode); - -protected Q_SLOTS: - void notify() - { - Q_EMIT update(MimeTreeParser::Force); - } - -protected: - void setAuditLog(const GpgME::Error &err, const QString &log); - void setRunning(bool running); - -private: - bool m_running; - QString m_auditLog; - GpgME::Error m_auditLogError; -}; -} -#endif // __MIMETREEPARSER_CRYPTOBODYPARTMEMENTO_H__ diff --git a/framework/src/domain/mime/mimetreeparser/decryptverifybodypartmemento.cpp b/framework/src/domain/mime/mimetreeparser/decryptverifybodypartmemento.cpp deleted file mode 100644 index 9810797a..00000000 --- a/framework/src/domain/mime/mimetreeparser/decryptverifybodypartmemento.cpp +++ /dev/null @@ -1,86 +0,0 @@ -/* - Copyright (c) 2014-2017 Montel Laurent - - This program 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. - - This program 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 -*/ - -#include "decryptverifybodypartmemento.h" - -#include - -#include - -using namespace QGpgME; -using namespace GpgME; -using namespace MimeTreeParser; - -DecryptVerifyBodyPartMemento::DecryptVerifyBodyPartMemento(DecryptVerifyJob *job, const QByteArray &cipherText) - : CryptoBodyPartMemento(), - m_cipherText(cipherText), - m_job(job) -{ - Q_ASSERT(m_job); -} - -DecryptVerifyBodyPartMemento::~DecryptVerifyBodyPartMemento() -{ - if (m_job) { - m_job->slotCancel(); - } -} - -bool DecryptVerifyBodyPartMemento::start() -{ - Q_ASSERT(m_job); - if (const Error err = m_job->start(m_cipherText)) { - m_dr = DecryptionResult(err); - return false; - } - connect(m_job.data(), &DecryptVerifyJob::result, - this, &DecryptVerifyBodyPartMemento::slotResult); - setRunning(true); - return true; -} - -void DecryptVerifyBodyPartMemento::exec() -{ - Q_ASSERT(m_job); - QByteArray plainText; - setRunning(true); - const std::pair p = m_job->exec(m_cipherText, plainText); - saveResult(p.first, p.second, plainText); - m_job->deleteLater(); // exec'ed jobs don't delete themselves - m_job = nullptr; -} - -void DecryptVerifyBodyPartMemento::saveResult(const DecryptionResult &dr, - const VerificationResult &vr, - const QByteArray &plainText) -{ - Q_ASSERT(m_job); - setRunning(false); - m_dr = dr; - m_vr = vr; - m_plainText = plainText; - setAuditLog(m_job->auditLogError(), m_job->auditLogAsHtml()); -} - -void DecryptVerifyBodyPartMemento::slotResult(const DecryptionResult &dr, - const VerificationResult &vr, - const QByteArray &plainText) -{ - saveResult(dr, vr, plainText); - m_job = nullptr; - notify(); -} diff --git a/framework/src/domain/mime/mimetreeparser/decryptverifybodypartmemento.h b/framework/src/domain/mime/mimetreeparser/decryptverifybodypartmemento.h deleted file mode 100644 index 4781abe2..00000000 --- a/framework/src/domain/mime/mimetreeparser/decryptverifybodypartmemento.h +++ /dev/null @@ -1,81 +0,0 @@ -/* - Copyright (c) 2014-2016 Montel Laurent - - This program 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. - - This program 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 -*/ - -#ifndef __MIMETREEPARSER_DECRYPTVERIFYBODYPARTMEMENTO_H__ -#define __MIMETREEPARSER_DECRYPTVERIFYBODYPARTMEMENTO_H__ - -#include "cryptobodypartmemento.h" - -#include -#include - -#include - -#include "bodypart.h" - -namespace QGpgME -{ -class DecryptVerifyJob; -} - -namespace MimeTreeParser -{ - -class DecryptVerifyBodyPartMemento - : public CryptoBodyPartMemento -{ - Q_OBJECT -public: - DecryptVerifyBodyPartMemento(QGpgME::DecryptVerifyJob *job, const QByteArray &cipherText); - ~DecryptVerifyBodyPartMemento(); - - bool start() Q_DECL_OVERRIDE; - void exec() Q_DECL_OVERRIDE; - - const QByteArray &plainText() const - { - return m_plainText; - } - const GpgME::DecryptionResult &decryptResult() const - { - return m_dr; - } - const GpgME::VerificationResult &verifyResult() const - { - return m_vr; - } - -private Q_SLOTS: - void slotResult(const GpgME::DecryptionResult &dr, - const GpgME::VerificationResult &vr, - const QByteArray &plainText); - -private: - void saveResult(const GpgME::DecryptionResult &, - const GpgME::VerificationResult &, - const QByteArray &); -private: - // input: - const QByteArray m_cipherText; - QPointer m_job; - // output: - GpgME::DecryptionResult m_dr; - GpgME::VerificationResult m_vr; - QByteArray m_plainText; -}; -} -#endif // __MIMETREEPARSER_DECRYPTVERIFYBODYPARTMEMENTO_H__ diff --git a/framework/src/domain/mime/mimetreeparser/messagepart.cpp b/framework/src/domain/mime/mimetreeparser/messagepart.cpp index fb61e015..3ba19567 100644 --- a/framework/src/domain/mime/mimetreeparser/messagepart.cpp +++ b/framework/src/domain/mime/mimetreeparser/messagepart.cpp @@ -1,5 +1,6 @@ /* Copyright (c) 2015 Sandro Knauß + Copyright (c) 2017 Christian Mollekopf This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by @@ -21,24 +22,17 @@ #include "mimetreeparser_debug.h" #include "cryptohelper.h" #include "objecttreeparser.h" -#include "qgpgmejobexecutor.h" - -#include "cryptobodypartmemento.h" -#include "decryptverifybodypartmemento.h" -#include "verifydetachedbodypartmemento.h" -#include "verifyopaquebodypartmemento.h" #include "utils.h" #include #include -#include -#include -#include -#include -#include +#include +#include +#include +#include #include #include #include @@ -48,6 +42,24 @@ using namespace MimeTreeParser; +static GpgME::Data fromBA(const QByteArray &ba) +{ + return {ba.data(), static_cast(ba.size()), false}; +} + +static QSharedPointer gpgContext(GpgME::Protocol protocol) +{ + GpgME::initializeLibrary(); + auto error = GpgME::checkEngine(protocol); + if (error) { + qWarning() << "Engine check failed: " << error.asString(); + } + auto ctx = QSharedPointer(GpgME::Context::createForProtocol(protocol)); + Q_ASSERT(ctx); + return ctx; +} + + //------MessagePart----------------------- MessagePart::MessagePart(ObjectTreeParser *otp, const QString &text, KMime::Content *node) : mText(text) @@ -382,7 +394,7 @@ void TextMessagePart::parseContent() mEncryptionState = KMMsgNotEncrypted; const auto blocks = prepareMessageForDecryption(mNode->decodedContent()); - const auto cryptProto = QGpgME::openpgp(); + const auto cryptProto = GpgME::OpenPGP; if (!blocks.isEmpty()) { @@ -639,7 +651,7 @@ QString AlternativeMessagePart::htmlContent() const //-----CertMessageBlock---------------------- -CertMessagePart::CertMessagePart(ObjectTreeParser *otp, KMime::Content *node, const QGpgME::Protocol *cryptoProto) +CertMessagePart::CertMessagePart(ObjectTreeParser *otp, KMime::Content *node, const GpgME::Protocol cryptoProto) : MessagePart(otp, QString(), node) , mCryptoProto(cryptoProto) { @@ -657,9 +669,8 @@ CertMessagePart::~CertMessagePart() void CertMessagePart::import() { const QByteArray certData = mNode->decodedContent(); - QGpgME::ImportJob *import = mCryptoProto->importJob(); - QGpgMEJobExecutor executor; - auto result = executor.exec(import, certData); + auto ctx = gpgContext(mCryptoProto); + const auto result = ctx->importKeys(fromBA(certData)); } QString CertMessagePart::text() const @@ -670,11 +681,11 @@ QString CertMessagePart::text() const //-----SignedMessageBlock--------------------- SignedMessagePart::SignedMessagePart(ObjectTreeParser *otp, const QString &text, - const QGpgME::Protocol *cryptoProto, + const GpgME::Protocol cryptoProto, const QString &fromAddress, KMime::Content *node, KMime::Content *signedData) : MessagePart(otp, text, node) - , mCryptoProto(cryptoProto) + , mProtocol(cryptoProto) , mFromAddress(fromAddress) , mSignedData(signedData) { @@ -700,20 +711,6 @@ bool SignedMessagePart::isSigned() const return mMetaData.isSigned; } -CryptoBodyPartMemento *SignedMessagePart::verifySignature(const QByteArray &data, const QByteArray &signature) -{ - if (!signature.isEmpty()) { - if (QGpgME::VerifyDetachedJob *job = mCryptoProto->verifyDetachedJob()) { - return new VerifyDetachedBodyPartMemento(job, mCryptoProto->keyListJob(), signature, data); - } - } else { - if (QGpgME::VerifyOpaqueJob *job = mCryptoProto->verifyOpaqueJob()) { - return new VerifyOpaqueBodyPartMemento(job, mCryptoProto->keyListJob(), data); - } - } - return nullptr; -} - static int signatureToStatus(const GpgME::Signature &sig) { switch (sig.status().code()) { @@ -739,6 +736,23 @@ QString prettifyDN(const char *uid) return QGpgME::DN(uid).prettyDN(); } +static GpgME::KeyListResult listKeys(GpgME::Context * ctx, const char *pattern, bool secretOnly, std::vector &keys) { + if (const GpgME::Error err = ctx->startKeyListing(pattern, secretOnly)) { + return GpgME::KeyListResult( 0, err ); + } + + GpgME::Error err; + do { + keys.push_back( ctx->nextKey(err)); + } while ( !err ); + + keys.pop_back(); + + const GpgME::KeyListResult result = ctx->endKeyListing(); + ctx->cancelPendingOperation(); + return result; +} + void SignedMessagePart::sigStatusToMetaData() { GpgME::Key key; @@ -749,29 +763,22 @@ void SignedMessagePart::sigStatusToMetaData() mMetaData.sigSummary = signature.summary(); if (mMetaData.isGoodSignature && !key.keyID()) { - // Search for the key by its fingerprint so that we can check for - // trust etc. - QGpgME::KeyListJob *job = mCryptoProto->keyListJob(false); // local, no sigs - if (!job) { - qCDebug(MIMETREEPARSER_LOG) << "The Crypto backend does not support listing keys. "; + auto ctx = gpgContext(mProtocol); + // Search for the key by its fingerprint so that we can check for trust etc. + std::vector found_keys; + auto res = listKeys(ctx.data(), signature.fingerprint(), false, found_keys); + if (res.error()) { + qCDebug(MIMETREEPARSER_LOG) << "Error while searching key for Fingerprint: " << signature.fingerprint(); + } + if (found_keys.size() > 1) { + // Should not happen + qCDebug(MIMETREEPARSER_LOG) << "Oops: Found more then one Key for Fingerprint: " << signature.fingerprint(); + } + if (found_keys.empty()) { + // Should not happen at this point + qCWarning(MIMETREEPARSER_LOG) << "Oops: Found no Key for Fingerprint: " << signature.fingerprint(); } else { - std::vector found_keys; - // As we are local it is ok to make this synchronous - GpgME::KeyListResult res = job->exec(QStringList(QLatin1String(signature.fingerprint())), false, found_keys); - if (res.error()) { - qCDebug(MIMETREEPARSER_LOG) << "Error while searching key for Fingerprint: " << signature.fingerprint(); - } - if (found_keys.size() > 1) { - // Should not happen - qCDebug(MIMETREEPARSER_LOG) << "Oops: Found more then one Key for Fingerprint: " << signature.fingerprint(); - } - if (found_keys.empty()) { - // Should not happen at this point - qCWarning(MIMETREEPARSER_LOG) << "Oops: Found no Key for Fingerprint: " << signature.fingerprint(); - } else { - key = found_keys[0]; - } - delete job; + key = found_keys[0]; } } @@ -857,25 +864,18 @@ void SignedMessagePart::startVerificationDetached(const QByteArray &text, KMime: mMetaData.status = tr("Wrong Crypto Plug-In."); mMetaData.status_code = GPGME_SIG_STAT_NONE; - if (auto *m = verifySignature(text, signature)) { - m->exec(); - if (!signature.isEmpty()) { - mVerifiedText = text; - } - setVerificationResult(m, textNode); - delete m; + auto ctx = gpgContext(mProtocol); + + if (!signature.isEmpty()) { + qWarning() << "We have a signature"; + auto result = ctx->verifyDetachedSignature(fromBA(signature), fromBA(text)); + setVerificationResult(result, textNode, text); } else { - QString errorMsg; - if (!mCryptoProto) { - errorMsg = tr("No appropriate crypto plug-in was found."); - } else { - errorMsg = tr("Crypto plug-in \"%1\" cannot verify signatures.").arg( - mCryptoProto->name()); - } - mMetaData.errorText = tr("The message is signed, but the " - "validity of the signature cannot be " - "verified.
" - "Reason: %1").arg(errorMsg); + qWarning() << "We have no signature"; + QGpgME::QByteArrayDataProvider out; + GpgME::Data outdata(&out); + auto result = ctx->verifyOpaqueSignature(fromBA(text), outdata); + setVerificationResult(result, textNode, out.data()); } if (!mMetaData.isSigned) { @@ -883,24 +883,13 @@ void SignedMessagePart::startVerificationDetached(const QByteArray &text, KMime: } } -void SignedMessagePart::setVerificationResult(const CryptoBodyPartMemento *m, KMime::Content *textNode) +void SignedMessagePart::setVerificationResult(const GpgME::VerificationResult &result, KMime::Content *textNode, const QByteArray &plainText) { - if (const auto vm = dynamic_cast(m)) { - mSignatures = vm->verifyResult().signatures(); - } - if (const auto vm = dynamic_cast(m)) { - mVerifiedText = vm->plainText(); - mSignatures = vm->verifyResult().signatures(); - } - if (const auto vm = dynamic_cast(m)) { - mVerifiedText = vm->plainText(); - mSignatures = vm->verifyResult().signatures(); - } - mMetaData.auditLogError = m->auditLogError(); - mMetaData.auditLog = m->auditLogAsHtml(); - mMetaData.isSigned = !mSignatures.empty(); - - if (mMetaData.isSigned) { + mSignatures = result.signatures(); + mVerifiedText = plainText; + mMetaData.auditLogError = result.error(); + if (!mSignatures.empty()) { + mMetaData.isSigned = true; sigStatusToMetaData(); if (mNode && !textNode) { mOtp->mNodeHelper->setPartMetaData(mNode, mMetaData); @@ -941,11 +930,11 @@ QString SignedMessagePart::htmlContent() const //-----CryptMessageBlock--------------------- EncryptedMessagePart::EncryptedMessagePart(ObjectTreeParser *otp, const QString &text, - const QGpgME::Protocol *cryptoProto, + const GpgME::Protocol cryptoProto, const QString &fromAddress, KMime::Content *node, KMime::Content *encryptedNode) : MessagePart(otp, text, node) - , mCryptoProto(cryptoProto) + , mProtocol(cryptoProto) , mFromAddress(fromAddress) , mEncryptedNode(encryptedNode) { @@ -1012,32 +1001,21 @@ bool EncryptedMessagePart::okDecryptMIME(KMime::Content &data) mMetaData.auditLogError = GpgME::Error(); mMetaData.auditLog.clear(); - if (!mCryptoProto) { - mError = UnknownError; - mMetaData.errorText = tr("No appropriate crypto plug-in was found."); - return false; - } - - QGpgME::DecryptVerifyJob *job = mCryptoProto->decryptVerifyJob(); - if (!job) { - mError = UnknownError; - mMetaData.errorText = tr("Crypto plug-in \"%1\" cannot decrypt messages.").arg(mCryptoProto->name()); - return false; - } - const QByteArray ciphertext = data.decodedContent(); - auto m = QSharedPointer::create(job, ciphertext); - m->exec(); - - const QByteArray &plainText = m->plainText(); - const GpgME::DecryptionResult &decryptResult = m->decryptResult(); - const GpgME::VerificationResult &verifyResult = m->verifyResult(); + qWarning() << "Protocol: " << mProtocol; + auto ctx = gpgContext(mProtocol); + QGpgME::QByteArrayDataProvider out; + GpgME::Data outdata(&out); + const std::pair res = ctx->decryptAndVerify(fromBA(ciphertext), outdata); + const QByteArray &plainText = out.data(); + const GpgME::DecryptionResult &decryptResult = res.first; + const GpgME::VerificationResult &verifyResult = res.second; mMetaData.isSigned = verifyResult.signatures().size() > 0; if (verifyResult.signatures().size() > 0) { //We simply attach a signed message part to indicate that this content is also signed - auto subPart = SignedMessagePart::Ptr(new SignedMessagePart(mOtp, QString::fromUtf8(plainText), mCryptoProto, mFromAddress, nullptr, nullptr)); - subPart->setVerificationResult(m.data(), nullptr); + auto subPart = SignedMessagePart::Ptr(new SignedMessagePart(mOtp, QString::fromUtf8(plainText), mProtocol, mFromAddress, nullptr, nullptr)); + subPart->setVerificationResult(verifyResult, nullptr, plainText); appendSubPart(subPart); } @@ -1075,13 +1053,12 @@ bool EncryptedMessagePart::okDecryptMIME(KMime::Content &data) if(noSecKey) { mError = NoKeyError; - mMetaData.errorText = tr("Crypto plug-in \"%1\" could not decrypt the data. ").arg(mCryptoProto->name()) - + tr("No key found for recepients."); + mMetaData.errorText = tr("Could not decrypt the data. ") + tr("No key found for recepients."); } else if (passphraseError) { mError = PassphraseError; } else { mError = UnknownError; - mMetaData.errorText = tr("Crypto plug-in \"%1\" could not decrypt the data. ").arg(mCryptoProto->name()) + mMetaData.errorText = tr("Could not decrypt the data. ") + tr("Error: %1").arg(mMetaData.errorText); } return false; diff --git a/framework/src/domain/mime/mimetreeparser/messagepart.h b/framework/src/domain/mime/mimetreeparser/messagepart.h index 2e0aac21..8f34c582 100644 --- a/framework/src/domain/mime/mimetreeparser/messagepart.h +++ b/framework/src/domain/mime/mimetreeparser/messagepart.h @@ -41,11 +41,6 @@ namespace GpgME class ImportResult; } -namespace QGpgME -{ -class Protocol; -} - namespace KMime { class Content; @@ -270,14 +265,14 @@ class CertMessagePart : public MessagePart Q_OBJECT public: typedef QSharedPointer Ptr; - CertMessagePart(MimeTreeParser::ObjectTreeParser *otp, KMime::Content *node, const QGpgME::Protocol *cryptoProto); + CertMessagePart(MimeTreeParser::ObjectTreeParser *otp, KMime::Content *node, const GpgME::Protocol cryptoProto); virtual ~CertMessagePart(); QString text() const Q_DECL_OVERRIDE; void import(); private: - const QGpgME::Protocol *mCryptoProto; + const GpgME::Protocol mCryptoProto; friend class DefaultRendererPrivate; }; @@ -306,7 +301,7 @@ public: typedef QSharedPointer Ptr; EncryptedMessagePart(ObjectTreeParser *otp, const QString &text, - const QGpgME::Protocol *cryptoProto, + const GpgME::Protocol protocol, const QString &fromAddress, KMime::Content *node, KMime::Content *encryptedNode = nullptr); @@ -335,7 +330,7 @@ private: bool okDecryptMIME(KMime::Content &data); protected: - const QGpgME::Protocol *mCryptoProto; + const GpgME::Protocol mProtocol; QString mFromAddress; QByteArray mVerifiedText; std::vector mDecryptRecipients; @@ -353,7 +348,7 @@ public: typedef QSharedPointer Ptr; SignedMessagePart(ObjectTreeParser *otp, const QString &text, - const QGpgME::Protocol *cryptoProto, + const GpgME::Protocol protocol, const QString &fromAddress, KMime::Content *node, KMime::Content *signedData); @@ -373,13 +368,10 @@ public: QString htmlContent() const Q_DECL_OVERRIDE; private: - CryptoBodyPartMemento *verifySignature(const QByteArray &data, const QByteArray &signature); - void sigStatusToMetaData(); - - void setVerificationResult(const CryptoBodyPartMemento *m, KMime::Content *textNode); + void setVerificationResult(const GpgME::VerificationResult &result, KMime::Content *textNode, const QByteArray &plainText); protected: - const QGpgME::Protocol *mCryptoProto; + GpgME::Protocol mProtocol; QString mFromAddress; QByteArray mVerifiedText; KMime::Content *mSignedData; diff --git a/framework/src/domain/mime/mimetreeparser/multipartencrypted.cpp b/framework/src/domain/mime/mimetreeparser/multipartencrypted.cpp index cac9853d..5316a6a7 100644 --- a/framework/src/domain/mime/mimetreeparser/multipartencrypted.cpp +++ b/framework/src/domain/mime/mimetreeparser/multipartencrypted.cpp @@ -26,8 +26,6 @@ #include -#include - #include "mimetreeparser_debug.h" using namespace MimeTreeParser; @@ -51,19 +49,19 @@ MessagePart::Ptr MultiPartEncryptedBodyPartFormatter::process(Interface::BodyPar return MessagePart::Ptr(); } - const QGpgME::Protocol *useThisCryptProto = nullptr; + GpgME::Protocol useThisCryptProto = GpgME::UnknownProtocol; /* ATTENTION: This code is to be replaced by the new 'auto-detect' feature. -------------------------------------- */ KMime::Content *data = findTypeInDirectChilds(node, "application/octet-stream"); if (data) { - useThisCryptProto = QGpgME::openpgp(); + useThisCryptProto = GpgME::OpenPGP; } if (!data) { data = findTypeInDirectChilds(node, "application/pkcs7-mime"); if (data) { - useThisCryptProto = QGpgME::smime(); + useThisCryptProto = GpgME::CMS; } } /* diff --git a/framework/src/domain/mime/mimetreeparser/multipartsigned.cpp b/framework/src/domain/mime/mimetreeparser/multipartsigned.cpp index 6ecb09af..5c00e7dc 100644 --- a/framework/src/domain/mime/mimetreeparser/multipartsigned.cpp +++ b/framework/src/domain/mime/mimetreeparser/multipartsigned.cpp @@ -67,16 +67,16 @@ MessagePart::Ptr MultiPartSignedBodyPartFormatter::process(Interface::BodyPart & protocolContentType = signatureContentType; } - const QGpgME::Protocol *protocol = nullptr; + GpgME::Protocol protocol = GpgME::UnknownProtocol; if (protocolContentType == QLatin1String("application/pkcs7-signature") || protocolContentType == QLatin1String("application/x-pkcs7-signature")) { - protocol = QGpgME::smime(); + protocol = GpgME::CMS; } else if (protocolContentType == QLatin1String("application/pgp-signature") || protocolContentType == QLatin1String("application/x-pgp-signature")) { - protocol = QGpgME::openpgp(); + protocol = GpgME::OpenPGP; } - if (!protocol) { + if (protocol == GpgME::UnknownProtocol) { return MessagePart::Ptr(new MimeMessagePart(part.objectTreeParser(), signedData, false)); } @@ -88,9 +88,6 @@ MessagePart::Ptr MultiPartSignedBodyPartFormatter::process(Interface::BodyPart & SignedMessagePart::Ptr mp(new SignedMessagePart(part.objectTreeParser(), aCodec->toUnicode(cleartext), protocol, part.nodeHelper()->fromAsString(node), signature, signedData)); - if (!protocol) { - mp->partMetaData()->auditLogError = GpgME::Error(GPG_ERR_NOT_IMPLEMENTED); - } return mp; } diff --git a/framework/src/domain/mime/mimetreeparser/qgpgmejobexecutor.cpp b/framework/src/domain/mime/mimetreeparser/qgpgmejobexecutor.cpp deleted file mode 100644 index 1f453342..00000000 --- a/framework/src/domain/mime/mimetreeparser/qgpgmejobexecutor.cpp +++ /dev/null @@ -1,158 +0,0 @@ -/* - Copyright (c) 2008 Volker Krause - - This program 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. - - This program 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. -*/ - -#include "qgpgmejobexecutor.h" -#include "mimetreeparser_debug.h" - -#include -#include -#include -#include - -#include - -#include - -using namespace GpgME; -using namespace MimeTreeParser; - -QGpgMEJobExecutor::QGpgMEJobExecutor(QObject *parent) : QObject(parent) -{ - setObjectName(QStringLiteral("KleoJobExecutor")); - mEventLoop = new QEventLoop(this); -} - -GpgME::VerificationResult QGpgMEJobExecutor::exec( - QGpgME::VerifyDetachedJob *job, - const QByteArray &signature, - const QByteArray &signedData) -{ - qCDebug(MIMETREEPARSER_LOG) << "Starting detached verification job"; - connect(job, SIGNAL(result(GpgME::VerificationResult)), SLOT(verificationResult(GpgME::VerificationResult))); - GpgME::Error err = job->start(signature, signedData); - if (err) { - return VerificationResult(err); - } - mEventLoop->exec(QEventLoop::ExcludeUserInputEvents); - return mVerificationResult; -} - -GpgME::VerificationResult QGpgMEJobExecutor::exec( - QGpgME::VerifyOpaqueJob *job, - const QByteArray &signedData, - QByteArray &plainText) -{ - qCDebug(MIMETREEPARSER_LOG) << "Starting opaque verification job"; - connect(job, SIGNAL(result(GpgME::VerificationResult,QByteArray)), SLOT(verificationResult(GpgME::VerificationResult,QByteArray))); - GpgME::Error err = job->start(signedData); - if (err) { - plainText.clear(); - return VerificationResult(err); - } - mEventLoop->exec(QEventLoop::ExcludeUserInputEvents); - plainText = mData; - return mVerificationResult; -} - -std::pair< GpgME::DecryptionResult, GpgME::VerificationResult > QGpgMEJobExecutor::exec( - QGpgME::DecryptVerifyJob *job, - const QByteArray &cipherText, - QByteArray &plainText) -{ - qCDebug(MIMETREEPARSER_LOG) << "Starting decryption job"; - connect(job, &QGpgME::DecryptVerifyJob::result, this, &QGpgMEJobExecutor::decryptResult); - GpgME::Error err = job->start(cipherText); - if (err) { - plainText.clear(); - return std::make_pair(DecryptionResult(err), VerificationResult(err)); - } - mEventLoop->exec(QEventLoop::ExcludeUserInputEvents); - plainText = mData; - return std::make_pair(mDecryptResult, mVerificationResult); -} - -GpgME::ImportResult QGpgMEJobExecutor::exec(QGpgME::ImportJob *job, const QByteArray &certData) -{ - connect(job, SIGNAL(result(GpgME::ImportResult)), SLOT(importResult(GpgME::ImportResult))); - GpgME::Error err = job->start(certData); - if (err) { - return ImportResult(err); - } - mEventLoop->exec(QEventLoop::ExcludeUserInputEvents); - return mImportResult; -} - -Error QGpgMEJobExecutor::auditLogError() const -{ - return mAuditLogError; -} - -void QGpgMEJobExecutor::verificationResult(const GpgME::VerificationResult &result) -{ - qCDebug(MIMETREEPARSER_LOG) << "Detached verification job finished"; - QGpgME::Job *job = qobject_cast(sender()); - assert(job); - mVerificationResult = result; - mAuditLogError = job->auditLogError(); - mAuditLog = job->auditLogAsHtml(); - mEventLoop->quit(); -} - -void QGpgMEJobExecutor::verificationResult(const GpgME::VerificationResult &result, const QByteArray &plainText) -{ - qCDebug(MIMETREEPARSER_LOG) << "Opaque verification job finished"; - QGpgME::Job *job = qobject_cast(sender()); - assert(job); - mVerificationResult = result; - mData = plainText; - mAuditLogError = job->auditLogError(); - mAuditLog = job->auditLogAsHtml(); - mEventLoop->quit(); -} - -void QGpgMEJobExecutor::decryptResult( - const GpgME::DecryptionResult &decryptionresult, - const GpgME::VerificationResult &verificationresult, - const QByteArray &plainText) -{ - qCDebug(MIMETREEPARSER_LOG) << "Decryption job finished"; - QGpgME::Job *job = qobject_cast(sender()); - assert(job); - mVerificationResult = verificationresult; - mDecryptResult = decryptionresult; - mData = plainText; - mAuditLogError = job->auditLogError(); - mAuditLog = job->auditLogAsHtml(); - mEventLoop->quit(); -} - -void QGpgMEJobExecutor::importResult(const GpgME::ImportResult &result) -{ - QGpgME::Job *job = qobject_cast(sender()); - assert(job); - mImportResult = result; - mAuditLogError = job->auditLogError(); - mAuditLog = job->auditLogAsHtml(); - mEventLoop->quit(); -} - -QString QGpgMEJobExecutor::auditLogAsHtml() const -{ - return mAuditLog; -} - diff --git a/framework/src/domain/mime/mimetreeparser/qgpgmejobexecutor.h b/framework/src/domain/mime/mimetreeparser/qgpgmejobexecutor.h deleted file mode 100644 index 8a81b078..00000000 --- a/framework/src/domain/mime/mimetreeparser/qgpgmejobexecutor.h +++ /dev/null @@ -1,86 +0,0 @@ -/* - Copyright (c) 2008 Volker Krause - - This program 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. - - This program 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. -*/ - -#ifndef __MIMETREEPARSER_KLEOJOBEXECUTOR_H__ -#define __MIMETREEPARSER_KLEOJOBEXECUTOR_H__ - -#include -#include -#include - -#include - -#include - -class QEventLoop; - -namespace QGpgME -{ -class DecryptVerifyJob; -class ImportJob; -class VerifyDetachedJob; -class VerifyOpaqueJob; -} - -namespace MimeTreeParser -{ - -/** - Helper class for synchronous execution of Kleo crypto jobs. -*/ -class QGpgMEJobExecutor : public QObject -{ - Q_OBJECT -public: - explicit QGpgMEJobExecutor(QObject *parent = nullptr); - - GpgME::VerificationResult exec(QGpgME::VerifyDetachedJob *job, - const QByteArray &signature, - const QByteArray &signedData); - GpgME::VerificationResult exec(QGpgME::VerifyOpaqueJob *job, - const QByteArray &signedData, - QByteArray &plainText); - std::pair exec(QGpgME::DecryptVerifyJob *job, - const QByteArray &cipherText, - QByteArray &plainText); - GpgME::ImportResult exec(QGpgME::ImportJob *job, const QByteArray &certData); - - GpgME::Error auditLogError() const; - QString auditLogAsHtml() const; - -private Q_SLOTS: - void verificationResult(const GpgME::VerificationResult &result); - void verificationResult(const GpgME::VerificationResult &result, const QByteArray &plainText); - void decryptResult(const GpgME::DecryptionResult &decryptionresult, - const GpgME::VerificationResult &verificationresult, - const QByteArray &plainText); - void importResult(const GpgME::ImportResult &result); - -private: - QEventLoop *mEventLoop; - GpgME::VerificationResult mVerificationResult; - GpgME::DecryptionResult mDecryptResult; - GpgME::ImportResult mImportResult; - QByteArray mData; - GpgME::Error mAuditLogError; - QString mAuditLog; -}; - -} - -#endif diff --git a/framework/src/domain/mime/mimetreeparser/verifydetachedbodypartmemento.cpp b/framework/src/domain/mime/mimetreeparser/verifydetachedbodypartmemento.cpp deleted file mode 100644 index 56c1d1a7..00000000 --- a/framework/src/domain/mime/mimetreeparser/verifydetachedbodypartmemento.cpp +++ /dev/null @@ -1,177 +0,0 @@ -/* - Copyright (c) 2014-2017 Montel Laurent - - This program 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. - - This program 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 -*/ - -#include "verifydetachedbodypartmemento.h" -#include "mimetreeparser_debug.h" - -#include -#include - -#include - -#include - -#include - -using namespace QGpgME; -using namespace GpgME; -using namespace MimeTreeParser; - -VerifyDetachedBodyPartMemento::VerifyDetachedBodyPartMemento(VerifyDetachedJob *job, - KeyListJob *klj, - const QByteArray &signature, - const QByteArray &plainText) - : CryptoBodyPartMemento(), - m_signature(signature), - m_plainText(plainText), - m_job(job), - m_keylistjob(klj) -{ - assert(m_job); -} - -VerifyDetachedBodyPartMemento::~VerifyDetachedBodyPartMemento() -{ - if (m_job) { - m_job->slotCancel(); - } - if (m_keylistjob) { - m_keylistjob->slotCancel(); - } -} - -bool VerifyDetachedBodyPartMemento::start() -{ - assert(m_job); -#ifdef DEBUG_SIGNATURE - qCDebug(MIMETREEPARSER_LOG) << "tokoe: VerifyDetachedBodyPartMemento started"; -#endif - connect(m_job, SIGNAL(result(GpgME::VerificationResult)), - this, SLOT(slotResult(GpgME::VerificationResult))); - if (const Error err = m_job->start(m_signature, m_plainText)) { - m_vr = VerificationResult(err); -#ifdef DEBUG_SIGNATURE - qCDebug(MIMETREEPARSER_LOG) << "tokoe: VerifyDetachedBodyPartMemento stopped with error"; -#endif - return false; - } - setRunning(true); - return true; -} - -void VerifyDetachedBodyPartMemento::exec() -{ - assert(m_job); - setRunning(true); -#ifdef DEBUG_SIGNATURE - qCDebug(MIMETREEPARSER_LOG) << "tokoe: VerifyDetachedBodyPartMemento execed"; -#endif - saveResult(m_job->exec(m_signature, m_plainText)); - m_job->deleteLater(); // exec'ed jobs don't delete themselves - m_job = nullptr; -#ifdef DEBUG_SIGNATURE - qCDebug(MIMETREEPARSER_LOG) << "tokoe: VerifyDetachedBodyPartMemento after execed"; -#endif - if (canStartKeyListJob()) { - std::vector keys; - m_keylistjob->exec(keyListPattern(), /*secretOnly=*/false, keys); - if (!keys.empty()) { - m_key = keys.back(); - } - } - if (m_keylistjob) { - m_keylistjob->deleteLater(); // exec'ed jobs don't delete themselves - } - m_keylistjob = nullptr; - setRunning(false); -} - -bool VerifyDetachedBodyPartMemento::canStartKeyListJob() const -{ - if (!m_keylistjob) { - return false; - } - const char *const fpr = m_vr.signature(0).fingerprint(); - return fpr && *fpr; -} - -QStringList VerifyDetachedBodyPartMemento::keyListPattern() const -{ - assert(canStartKeyListJob()); - return QStringList(QString::fromLatin1(m_vr.signature(0).fingerprint())); -} - -void VerifyDetachedBodyPartMemento::saveResult(const VerificationResult &vr) -{ - assert(m_job); -#ifdef DEBUG_SIGNATURE - qCDebug(MIMETREEPARSER_LOG) << "tokoe: VerifyDetachedBodyPartMemento::saveResult called"; -#endif - m_vr = vr; - setAuditLog(m_job->auditLogError(), m_job->auditLogAsHtml()); -} - -void VerifyDetachedBodyPartMemento::slotResult(const VerificationResult &vr) -{ -#ifdef DEBUG_SIGNATURE - qCDebug(MIMETREEPARSER_LOG) << "tokoe: VerifyDetachedBodyPartMemento::slotResult called"; -#endif - saveResult(vr); - m_job = nullptr; - if (canStartKeyListJob() && startKeyListJob()) { -#ifdef DEBUG_SIGNATURE - qCDebug(MIMETREEPARSER_LOG) << "tokoe: VerifyDetachedBodyPartMemento: canStartKeyListJob && startKeyListJob"; -#endif - return; - } - if (m_keylistjob) { - m_keylistjob->deleteLater(); - } - m_keylistjob = nullptr; - setRunning(false); - notify(); -} - -bool VerifyDetachedBodyPartMemento::startKeyListJob() -{ - assert(canStartKeyListJob()); - if (const GpgME::Error err = m_keylistjob->start(keyListPattern())) { - return false; - } - connect(m_keylistjob, SIGNAL(done()), this, SLOT(slotKeyListJobDone())); - connect(m_keylistjob, SIGNAL(nextKey(GpgME::Key)), - this, SLOT(slotNextKey(GpgME::Key))); - return true; -} - -void VerifyDetachedBodyPartMemento::slotNextKey(const GpgME::Key &key) -{ -#ifdef DEBUG_SIGNATURE - qCDebug(MIMETREEPARSER_LOG) << "tokoe: VerifyDetachedBodyPartMemento::slotNextKey called"; -#endif - m_key = key; -} - -void VerifyDetachedBodyPartMemento::slotKeyListJobDone() -{ -#ifdef DEBUG_SIGNATURE - qCDebug(MIMETREEPARSER_LOG) << "tokoe: VerifyDetachedBodyPartMemento::slotKeyListJobDone called"; -#endif - m_keylistjob = nullptr; - setRunning(false); - notify(); -} diff --git a/framework/src/domain/mime/mimetreeparser/verifydetachedbodypartmemento.h b/framework/src/domain/mime/mimetreeparser/verifydetachedbodypartmemento.h deleted file mode 100644 index f37dfe81..00000000 --- a/framework/src/domain/mime/mimetreeparser/verifydetachedbodypartmemento.h +++ /dev/null @@ -1,87 +0,0 @@ -/* - Copyright (c) 2014-2016 Montel Laurent - - This program 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. - - This program 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 -*/ - -#ifndef __MIMETREEPARSER_VERIFYDETACHEDBODYPARTMEMENTO_H__ -#define __MIMETREEPARSER_VERIFYDETACHEDBODYPARTMEMENTO_H__ - -#include "cryptobodypartmemento.h" -#include -#include - -#include -#include - -#include "bodypart.h" - -namespace QGpgME -{ -class VerifyDetachedJob; -class KeyListJob; -} - -class QStringList; - -namespace MimeTreeParser -{ - -class VerifyDetachedBodyPartMemento - : public CryptoBodyPartMemento -{ - Q_OBJECT -public: - VerifyDetachedBodyPartMemento(QGpgME::VerifyDetachedJob *job, - QGpgME::KeyListJob *klj, - const QByteArray &signature, - const QByteArray &plainText); - ~VerifyDetachedBodyPartMemento(); - - bool start() Q_DECL_OVERRIDE; - void exec() Q_DECL_OVERRIDE; - - const GpgME::VerificationResult &verifyResult() const - { - return m_vr; - } - const GpgME::Key &signingKey() const - { - return m_key; - } - -private Q_SLOTS: - void slotResult(const GpgME::VerificationResult &vr); - void slotKeyListJobDone(); - void slotNextKey(const GpgME::Key &); - -private: - void saveResult(const GpgME::VerificationResult &); - bool canStartKeyListJob() const; - QStringList keyListPattern() const; - bool startKeyListJob(); -private: - // input: - const QByteArray m_signature; - const QByteArray m_plainText; - QPointer m_job; - QPointer m_keylistjob; - // output: - GpgME::VerificationResult m_vr; - GpgME::Key m_key; -}; - -} - -#endif // __MIMETREEPARSER_VERIFYDETACHEDBODYPARTMEMENTO_H__ diff --git a/framework/src/domain/mime/mimetreeparser/verifyopaquebodypartmemento.cpp b/framework/src/domain/mime/mimetreeparser/verifyopaquebodypartmemento.cpp deleted file mode 100644 index 99eb8b8e..00000000 --- a/framework/src/domain/mime/mimetreeparser/verifyopaquebodypartmemento.cpp +++ /dev/null @@ -1,179 +0,0 @@ -/* - Copyright (c) 2014-2017 Montel Laurent - - This program 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. - - This program 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 -*/ - -#include "verifyopaquebodypartmemento.h" -#include "mimetreeparser_debug.h" - -#include -#include - -#include - -#include - -#include - -using namespace QGpgME; -using namespace GpgME; -using namespace MimeTreeParser; - -VerifyOpaqueBodyPartMemento::VerifyOpaqueBodyPartMemento(VerifyOpaqueJob *job, - KeyListJob *klj, - const QByteArray &signature) - : CryptoBodyPartMemento(), - m_signature(signature), - m_job(job), - m_keylistjob(klj) -{ - assert(m_job); -} - -VerifyOpaqueBodyPartMemento::~VerifyOpaqueBodyPartMemento() -{ - if (m_job) { - m_job->slotCancel(); - } - if (m_keylistjob) { - m_keylistjob->slotCancel(); - } -} - -bool VerifyOpaqueBodyPartMemento::start() -{ - assert(m_job); -#ifdef DEBUG_SIGNATURE - qCDebug(MIMETREEPARSER_LOG) << "tokoe: VerifyOpaqueBodyPartMemento started"; -#endif - if (const Error err = m_job->start(m_signature)) { - m_vr = VerificationResult(err); -#ifdef DEBUG_SIGNATURE - qCDebug(MIMETREEPARSER_LOG) << "tokoe: VerifyOpaqueBodyPartMemento stopped with error"; -#endif - return false; - } - connect(m_job, SIGNAL(result(GpgME::VerificationResult,QByteArray)), - this, SLOT(slotResult(GpgME::VerificationResult,QByteArray))); - setRunning(true); - return true; -} - -void VerifyOpaqueBodyPartMemento::exec() -{ - assert(m_job); - setRunning(true); - QByteArray plainText; -#ifdef DEBUG_SIGNATURE - qCDebug(MIMETREEPARSER_LOG) << "tokoe: VerifyOpaqueBodyPartMemento execed"; -#endif - saveResult(m_job->exec(m_signature, plainText), plainText); -#ifdef DEBUG_SIGNATURE - qCDebug(MIMETREEPARSER_LOG) << "tokoe: VerifyOpaqueBodyPartMemento after execed"; -#endif - m_job->deleteLater(); // exec'ed jobs don't delete themselves - m_job = nullptr; - if (canStartKeyListJob()) { - std::vector keys; - m_keylistjob->exec(keyListPattern(), /*secretOnly=*/false, keys); - if (!keys.empty()) { - m_key = keys.back(); - } - } - if (m_keylistjob) { - m_keylistjob->deleteLater(); // exec'ed jobs don't delete themselves - } - m_keylistjob = nullptr; - setRunning(false); -} - -bool VerifyOpaqueBodyPartMemento::canStartKeyListJob() const -{ - if (!m_keylistjob) { - return false; - } - const char *const fpr = m_vr.signature(0).fingerprint(); - return fpr && *fpr; -} - -QStringList VerifyOpaqueBodyPartMemento::keyListPattern() const -{ - assert(canStartKeyListJob()); - return QStringList(QString::fromLatin1(m_vr.signature(0).fingerprint())); -} - -void VerifyOpaqueBodyPartMemento::saveResult(const VerificationResult &vr, - const QByteArray &plainText) -{ - assert(m_job); -#ifdef DEBUG_SIGNATURE - qCDebug(MIMETREEPARSER_LOG) << "tokoe: VerifyOpaqueBodyPartMemento::saveResult called"; -#endif - m_vr = vr; - m_plainText = plainText; - setAuditLog(m_job->auditLogError(), m_job->auditLogAsHtml()); -} - -void VerifyOpaqueBodyPartMemento::slotResult(const VerificationResult &vr, - const QByteArray &plainText) -{ -#ifdef DEBUG_SIGNATURE - qCDebug(MIMETREEPARSER_LOG) << "tokoe: VerifyOpaqueBodyPartMemento::slotResult called"; -#endif - saveResult(vr, plainText); - m_job = nullptr; - if (canStartKeyListJob() && startKeyListJob()) { -#ifdef DEBUG_SIGNATURE - qCDebug(MIMETREEPARSER_LOG) << "tokoe: VerifyOpaqueBodyPartMemento: canStartKeyListJob && startKeyListJob"; -#endif - return; - } - if (m_keylistjob) { - m_keylistjob->deleteLater(); - } - m_keylistjob = nullptr; - setRunning(false); - notify(); -} - -bool VerifyOpaqueBodyPartMemento::startKeyListJob() -{ - assert(canStartKeyListJob()); - if (const GpgME::Error err = m_keylistjob->start(keyListPattern())) { - return false; - } - connect(m_keylistjob, SIGNAL(done()), this, SLOT(slotKeyListJobDone())); - connect(m_keylistjob, SIGNAL(nextKey(GpgME::Key)), - this, SLOT(slotNextKey(GpgME::Key))); - return true; -} - -void VerifyOpaqueBodyPartMemento::slotNextKey(const GpgME::Key &key) -{ -#ifdef DEBUG_SIGNATURE - qCDebug(MIMETREEPARSER_LOG) << "tokoe: VerifyOpaqueBodyPartMemento::slotNextKey called"; -#endif - m_key = key; -} - -void VerifyOpaqueBodyPartMemento::slotKeyListJobDone() -{ -#ifdef DEBUG_SIGNATURE - qCDebug(MIMETREEPARSER_LOG) << "tokoe: VerifyOpaqueBodyPartMemento::slotKeyListJobDone called"; -#endif - m_keylistjob = nullptr; - setRunning(false); - notify(); -} diff --git a/framework/src/domain/mime/mimetreeparser/verifyopaquebodypartmemento.h b/framework/src/domain/mime/mimetreeparser/verifyopaquebodypartmemento.h deleted file mode 100644 index 02d30a13..00000000 --- a/framework/src/domain/mime/mimetreeparser/verifyopaquebodypartmemento.h +++ /dev/null @@ -1,93 +0,0 @@ -/* - Copyright (c) 2014-2016 Montel Laurent - - This program 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. - - This program 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 -*/ - -#ifndef __MIMETREEPARSER_VERIFYOPAQUEBODYPARTMEMENTO_H__ -#define __MIMETREEPARSER_VERIFYOPAQUEBODYPARTMEMENTO_H__ - -#include "cryptobodypartmemento.h" -#include -#include -#include - -#include -#include - -#include "bodypart.h" - -namespace QGpgME -{ -class VerifyOpaqueJob; -class KeyListJob; -} - -class QStringList; - -namespace MimeTreeParser -{ - -class VerifyOpaqueBodyPartMemento - : public CryptoBodyPartMemento -{ - Q_OBJECT -public: - VerifyOpaqueBodyPartMemento(QGpgME::VerifyOpaqueJob *job, - QGpgME::KeyListJob *klj, - const QByteArray &signature); - ~VerifyOpaqueBodyPartMemento(); - - bool start() Q_DECL_OVERRIDE; - void exec() Q_DECL_OVERRIDE; - - const QByteArray &plainText() const - { - return m_plainText; - } - const GpgME::VerificationResult &verifyResult() const - { - return m_vr; - } - const GpgME::Key &signingKey() const - { - return m_key; - } - -private Q_SLOTS: - void slotResult(const GpgME::VerificationResult &vr, - const QByteArray &plainText); - void slotKeyListJobDone(); - void slotNextKey(const GpgME::Key &); - -private: - void saveResult(const GpgME::VerificationResult &, - const QByteArray &); - bool canStartKeyListJob() const; - QStringList keyListPattern() const; - bool startKeyListJob(); -private: - // input: - const QByteArray m_signature; - QPointer m_job; - QPointer m_keylistjob; - // output: - GpgME::VerificationResult m_vr; - QByteArray m_plainText; - GpgME::Key m_key; -}; - -} - -#endif // __MIMETREEPARSER_VERIFYOPAQUEBODYPARTMEMENTO_H__ -- cgit v1.2.3