diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-12-11 20:38:09 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-12-11 23:55:32 +0100 |
commit | d5c44099863d0968a0cbf8f10f04ecf3f4e8ff17 (patch) | |
tree | 7f481f96abd47a3a04c40b4fe0d09d9cdf14f00d /framework/src | |
parent | 9f2b3626cc3399c47736faa1b9954f7dbdbe8bd6 (diff) | |
download | kube-d5c44099863d0968a0cbf8f10f04ecf3f4e8ff17.tar.gz kube-d5c44099863d0968a0cbf8f10f04ecf3f4e8ff17.zip |
Stop using useless abstractions (that are not even threadsafe)
Diffstat (limited to 'framework/src')
17 files changed, 110 insertions, 1239 deletions
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 | |||
34 | nodehelper.cpp | 34 | nodehelper.cpp |
35 | messagepart.cpp | 35 | messagepart.cpp |
36 | partnodebodypart.cpp | 36 | partnodebodypart.cpp |
37 | #Mementos | ||
38 | cryptobodypartmemento.cpp | ||
39 | decryptverifybodypartmemento.cpp | ||
40 | verifydetachedbodypartmemento.cpp | ||
41 | verifyopaquebodypartmemento.cpp | ||
42 | #Stuff | 37 | #Stuff |
43 | mimetreeparser_debug.cpp | 38 | mimetreeparser_debug.cpp |
44 | qgpgmejobexecutor.cpp | ||
45 | util.cpp | 39 | util.cpp |
46 | ) | 40 | ) |
47 | 41 | ||
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 @@ | |||
24 | #include "objecttreeparser.h" | 24 | #include "objecttreeparser.h" |
25 | #include "messagepart.h" | 25 | #include "messagepart.h" |
26 | 26 | ||
27 | #include <QGpgME/Protocol> | ||
28 | |||
29 | #include <KMime/Content> | 27 | #include <KMime/Content> |
30 | 28 | ||
31 | #include "mimetreeparser_debug.h" | 29 | #include "mimetreeparser_debug.h" |
@@ -61,7 +59,7 @@ MessagePart::Ptr ApplicationPGPEncryptedBodyPartFormatter::process(Interface::Bo | |||
61 | } | 59 | } |
62 | 60 | ||
63 | EncryptedMessagePart::Ptr mp(new EncryptedMessagePart(part.objectTreeParser(), | 61 | EncryptedMessagePart::Ptr mp(new EncryptedMessagePart(part.objectTreeParser(), |
64 | data->decodedText(), QGpgME::openpgp(), | 62 | data->decodedText(), GpgME::OpenPGP, |
65 | part.nodeHelper()->fromAsString(data), node, data)); | 63 | part.nodeHelper()->fromAsString(data), node, data)); |
66 | mp->setIsEncrypted(true); | 64 | mp->setIsEncrypted(true); |
67 | return mp; | 65 | 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 | |||
52 | return MessagePart::Ptr(); | 52 | return MessagePart::Ptr(); |
53 | } | 53 | } |
54 | 54 | ||
55 | const auto smimeCrypto = QGpgME::smime(); | ||
56 | if (!smimeCrypto) { | ||
57 | return MessagePart::Ptr(); | ||
58 | } | ||
59 | 55 | ||
60 | const QString smimeType = node->contentType()->parameter(QStringLiteral("smime-type")).toLower(); | 56 | const QString smimeType = node->contentType()->parameter(QStringLiteral("smime-type")).toLower(); |
61 | 57 | ||
62 | if (smimeType == QLatin1String("certs-only")) { | 58 | if (smimeType == QLatin1String("certs-only")) { |
63 | return CertMessagePart::Ptr(new CertMessagePart(part.objectTreeParser(), node, smimeCrypto)); | 59 | return CertMessagePart::Ptr(new CertMessagePart(part.objectTreeParser(), node, GpgME::CMS)); |
64 | } | 60 | } |
65 | 61 | ||
66 | bool isSigned = (smimeType == QLatin1String("signed-data")); | 62 | bool isSigned = (smimeType == QLatin1String("signed-data")); |
@@ -83,7 +79,7 @@ MessagePart::Ptr ApplicationPkcs7MimeBodyPartFormatter::process(Interface::BodyP | |||
83 | } | 79 | } |
84 | 80 | ||
85 | auto _mp = EncryptedMessagePart::Ptr(new EncryptedMessagePart(part.objectTreeParser(), | 81 | auto _mp = EncryptedMessagePart::Ptr(new EncryptedMessagePart(part.objectTreeParser(), |
86 | node->decodedText(), smimeCrypto, | 82 | node->decodedText(), GpgME::CMS, |
87 | part.nodeHelper()->fromAsString(node), node)); | 83 | part.nodeHelper()->fromAsString(node), node)); |
88 | mp = _mp; | 84 | mp = _mp; |
89 | _mp->setIsEncrypted(true); | 85 | _mp->setIsEncrypted(true); |
@@ -129,11 +125,8 @@ MessagePart::Ptr ApplicationPkcs7MimeBodyPartFormatter::process(Interface::BodyP | |||
129 | const QTextCodec *aCodec(part.objectTreeParser()->codecFor(signTestNode)); | 125 | const QTextCodec *aCodec(part.objectTreeParser()->codecFor(signTestNode)); |
130 | const QByteArray signaturetext = signTestNode->decodedContent(); | 126 | const QByteArray signaturetext = signTestNode->decodedContent(); |
131 | auto mp = SignedMessagePart::Ptr(new SignedMessagePart(part.objectTreeParser(), | 127 | auto mp = SignedMessagePart::Ptr(new SignedMessagePart(part.objectTreeParser(), |
132 | aCodec->toUnicode(signaturetext), smimeCrypto, | 128 | aCodec->toUnicode(signaturetext), GpgME::CMS, |
133 | part.nodeHelper()->fromAsString(node), signTestNode, signTestNode)); | 129 | part.nodeHelper()->fromAsString(node), signTestNode, signTestNode)); |
134 | if (!smimeCrypto) { | ||
135 | mp->partMetaData()->auditLogError = GpgME::Error(GPG_ERR_NOT_IMPLEMENTED); | ||
136 | } | ||
137 | } | 130 | } |
138 | return mp; | 131 | return mp; |
139 | } | 132 | } |
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 @@ | |||
1 | /* | ||
2 | Copyright (c) 2014-2017 Montel Laurent <montel@kde.org> | ||
3 | |||
4 | This program is free software; you can redistribute it and/or modify it | ||
5 | under the terms of the GNU General Public License, version 2, as | ||
6 | published by the Free Software Foundation. | ||
7 | |||
8 | This program is distributed in the hope that it will be useful, but | ||
9 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
11 | General Public License for more details. | ||
12 | |||
13 | You should have received a copy of the GNU General Public License along | ||
14 | with this program; if not, write to the Free Software Foundation, Inc., | ||
15 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
16 | */ | ||
17 | |||
18 | #include "cryptobodypartmemento.h" | ||
19 | |||
20 | using namespace GpgME; | ||
21 | using namespace MimeTreeParser; | ||
22 | |||
23 | CryptoBodyPartMemento::CryptoBodyPartMemento() | ||
24 | : QObject(nullptr), | ||
25 | Interface::BodyPartMemento(), | ||
26 | m_running(false) | ||
27 | { | ||
28 | |||
29 | } | ||
30 | |||
31 | CryptoBodyPartMemento::~CryptoBodyPartMemento() | ||
32 | { | ||
33 | |||
34 | } | ||
35 | |||
36 | bool CryptoBodyPartMemento::isRunning() const | ||
37 | { | ||
38 | return m_running; | ||
39 | } | ||
40 | |||
41 | void CryptoBodyPartMemento::setAuditLog(const Error &err, const QString &log) | ||
42 | { | ||
43 | m_auditLogError = err; | ||
44 | m_auditLog = log; | ||
45 | } | ||
46 | |||
47 | void CryptoBodyPartMemento::setRunning(bool running) | ||
48 | { | ||
49 | m_running = running; | ||
50 | } | ||
51 | |||
52 | void CryptoBodyPartMemento::detach() | ||
53 | { | ||
54 | disconnect(this, SIGNAL(update(MimeTreeParser::UpdateMode)), nullptr, nullptr); | ||
55 | } | ||
56 | |||
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 @@ | |||
1 | /* | ||
2 | Copyright (c) 2014-2016 Montel Laurent <montel@kde.org> | ||
3 | |||
4 | This program is free software; you can redistribute it and/or modify it | ||
5 | under the terms of the GNU General Public License, version 2, as | ||
6 | published by the Free Software Foundation. | ||
7 | |||
8 | This program is distributed in the hope that it will be useful, but | ||
9 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
11 | General Public License for more details. | ||
12 | |||
13 | You should have received a copy of the GNU General Public License along | ||
14 | with this program; if not, write to the Free Software Foundation, Inc., | ||
15 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
16 | */ | ||
17 | |||
18 | #ifndef __MIMETREEPARSER_CRYPTOBODYPARTMEMENTO_H__ | ||
19 | #define __MIMETREEPARSER_CRYPTOBODYPARTMEMENTO_H__ | ||
20 | |||
21 | #include <gpgme++/error.h> | ||
22 | |||
23 | #include <QObject> | ||
24 | #include <QString> | ||
25 | |||
26 | #include "bodypart.h" | ||
27 | #include "enums.h" | ||
28 | |||
29 | namespace MimeTreeParser | ||
30 | { | ||
31 | |||
32 | class CryptoBodyPartMemento | ||
33 | : public QObject, | ||
34 | public Interface::BodyPartMemento | ||
35 | { | ||
36 | Q_OBJECT | ||
37 | public: | ||
38 | CryptoBodyPartMemento(); | ||
39 | ~CryptoBodyPartMemento(); | ||
40 | |||
41 | virtual bool start() = 0; | ||
42 | virtual void exec() = 0; | ||
43 | bool isRunning() const; | ||
44 | |||
45 | const QString &auditLogAsHtml() const | ||
46 | { | ||
47 | return m_auditLog; | ||
48 | } | ||
49 | GpgME::Error auditLogError() const | ||
50 | { | ||
51 | return m_auditLogError; | ||
52 | } | ||
53 | |||
54 | void detach() Q_DECL_OVERRIDE; | ||
55 | |||
56 | Q_SIGNALS: | ||
57 | void update(MimeTreeParser::UpdateMode); | ||
58 | |||
59 | protected Q_SLOTS: | ||
60 | void notify() | ||
61 | { | ||
62 | Q_EMIT update(MimeTreeParser::Force); | ||
63 | } | ||
64 | |||
65 | protected: | ||
66 | void setAuditLog(const GpgME::Error &err, const QString &log); | ||
67 | void setRunning(bool running); | ||
68 | |||
69 | private: | ||
70 | bool m_running; | ||
71 | QString m_auditLog; | ||
72 | GpgME::Error m_auditLogError; | ||
73 | }; | ||
74 | } | ||
75 | #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 @@ | |||
1 | /* | ||
2 | Copyright (c) 2014-2017 Montel Laurent <montel@kde.org> | ||
3 | |||
4 | This program is free software; you can redistribute it and/or modify it | ||
5 | under the terms of the GNU General Public License, version 2, as | ||
6 | published by the Free Software Foundation. | ||
7 | |||
8 | This program is distributed in the hope that it will be useful, but | ||
9 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
11 | General Public License for more details. | ||
12 | |||
13 | You should have received a copy of the GNU General Public License along | ||
14 | with this program; if not, write to the Free Software Foundation, Inc., | ||
15 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
16 | */ | ||
17 | |||
18 | #include "decryptverifybodypartmemento.h" | ||
19 | |||
20 | #include <QGpgME/DecryptVerifyJob> | ||
21 | |||
22 | #include <qstringlist.h> | ||
23 | |||
24 | using namespace QGpgME; | ||
25 | using namespace GpgME; | ||
26 | using namespace MimeTreeParser; | ||
27 | |||
28 | DecryptVerifyBodyPartMemento::DecryptVerifyBodyPartMemento(DecryptVerifyJob *job, const QByteArray &cipherText) | ||
29 | : CryptoBodyPartMemento(), | ||
30 | m_cipherText(cipherText), | ||
31 | m_job(job) | ||
32 | { | ||
33 | Q_ASSERT(m_job); | ||
34 | } | ||
35 | |||
36 | DecryptVerifyBodyPartMemento::~DecryptVerifyBodyPartMemento() | ||
37 | { | ||
38 | if (m_job) { | ||
39 | m_job->slotCancel(); | ||
40 | } | ||
41 | } | ||
42 | |||
43 | bool DecryptVerifyBodyPartMemento::start() | ||
44 | { | ||
45 | Q_ASSERT(m_job); | ||
46 | if (const Error err = m_job->start(m_cipherText)) { | ||
47 | m_dr = DecryptionResult(err); | ||
48 | return false; | ||
49 | } | ||
50 | connect(m_job.data(), &DecryptVerifyJob::result, | ||
51 | this, &DecryptVerifyBodyPartMemento::slotResult); | ||
52 | setRunning(true); | ||
53 | return true; | ||
54 | } | ||
55 | |||
56 | void DecryptVerifyBodyPartMemento::exec() | ||
57 | { | ||
58 | Q_ASSERT(m_job); | ||
59 | QByteArray plainText; | ||
60 | setRunning(true); | ||
61 | const std::pair<DecryptionResult, VerificationResult> p = m_job->exec(m_cipherText, plainText); | ||
62 | saveResult(p.first, p.second, plainText); | ||
63 | m_job->deleteLater(); // exec'ed jobs don't delete themselves | ||
64 | m_job = nullptr; | ||
65 | } | ||
66 | |||
67 | void DecryptVerifyBodyPartMemento::saveResult(const DecryptionResult &dr, | ||
68 | const VerificationResult &vr, | ||
69 | const QByteArray &plainText) | ||
70 | { | ||
71 | Q_ASSERT(m_job); | ||
72 | setRunning(false); | ||
73 | m_dr = dr; | ||
74 | m_vr = vr; | ||
75 | m_plainText = plainText; | ||
76 | setAuditLog(m_job->auditLogError(), m_job->auditLogAsHtml()); | ||
77 | } | ||
78 | |||
79 | void DecryptVerifyBodyPartMemento::slotResult(const DecryptionResult &dr, | ||
80 | const VerificationResult &vr, | ||
81 | const QByteArray &plainText) | ||
82 | { | ||
83 | saveResult(dr, vr, plainText); | ||
84 | m_job = nullptr; | ||
85 | notify(); | ||
86 | } | ||
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 @@ | |||
1 | /* | ||
2 | Copyright (c) 2014-2016 Montel Laurent <montel@kde.org> | ||
3 | |||
4 | This program is free software; you can redistribute it and/or modify it | ||
5 | under the terms of the GNU General Public License, version 2, as | ||
6 | published by the Free Software Foundation. | ||
7 | |||
8 | This program is distributed in the hope that it will be useful, but | ||
9 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
11 | General Public License for more details. | ||
12 | |||
13 | You should have received a copy of the GNU General Public License along | ||
14 | with this program; if not, write to the Free Software Foundation, Inc., | ||
15 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
16 | */ | ||
17 | |||
18 | #ifndef __MIMETREEPARSER_DECRYPTVERIFYBODYPARTMEMENTO_H__ | ||
19 | #define __MIMETREEPARSER_DECRYPTVERIFYBODYPARTMEMENTO_H__ | ||
20 | |||
21 | #include "cryptobodypartmemento.h" | ||
22 | |||
23 | #include <gpgme++/verificationresult.h> | ||
24 | #include <gpgme++/decryptionresult.h> | ||
25 | |||
26 | #include <QPointer> | ||
27 | |||
28 | #include "bodypart.h" | ||
29 | |||
30 | namespace QGpgME | ||
31 | { | ||
32 | class DecryptVerifyJob; | ||
33 | } | ||
34 | |||
35 | namespace MimeTreeParser | ||
36 | { | ||
37 | |||
38 | class DecryptVerifyBodyPartMemento | ||
39 | : public CryptoBodyPartMemento | ||
40 | { | ||
41 | Q_OBJECT | ||
42 | public: | ||
43 | DecryptVerifyBodyPartMemento(QGpgME::DecryptVerifyJob *job, const QByteArray &cipherText); | ||
44 | ~DecryptVerifyBodyPartMemento(); | ||
45 | |||
46 | bool start() Q_DECL_OVERRIDE; | ||
47 | void exec() Q_DECL_OVERRIDE; | ||
48 | |||
49 | const QByteArray &plainText() const | ||
50 | { | ||
51 | return m_plainText; | ||
52 | } | ||
53 | const GpgME::DecryptionResult &decryptResult() const | ||
54 | { | ||
55 | return m_dr; | ||
56 | } | ||
57 | const GpgME::VerificationResult &verifyResult() const | ||
58 | { | ||
59 | return m_vr; | ||
60 | } | ||
61 | |||
62 | private Q_SLOTS: | ||
63 | void slotResult(const GpgME::DecryptionResult &dr, | ||
64 | const GpgME::VerificationResult &vr, | ||
65 | const QByteArray &plainText); | ||
66 | |||
67 | private: | ||
68 | void saveResult(const GpgME::DecryptionResult &, | ||
69 | const GpgME::VerificationResult &, | ||
70 | const QByteArray &); | ||
71 | private: | ||
72 | // input: | ||
73 | const QByteArray m_cipherText; | ||
74 | QPointer<QGpgME::DecryptVerifyJob> m_job; | ||
75 | // output: | ||
76 | GpgME::DecryptionResult m_dr; | ||
77 | GpgME::VerificationResult m_vr; | ||
78 | QByteArray m_plainText; | ||
79 | }; | ||
80 | } | ||
81 | #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 @@ | |||
1 | /* | 1 | /* |
2 | Copyright (c) 2015 Sandro Knauß <sknauss@kde.org> | 2 | Copyright (c) 2015 Sandro Knauß <sknauss@kde.org> |
3 | Copyright (c) 2017 Christian Mollekopf <mollekopf@kolabsys.com> | ||
3 | 4 | ||
4 | This library is free software; you can redistribute it and/or modify it | 5 | This library is free software; you can redistribute it and/or modify it |
5 | under the terms of the GNU Library General Public License as published by | 6 | under the terms of the GNU Library General Public License as published by |
@@ -21,24 +22,17 @@ | |||
21 | #include "mimetreeparser_debug.h" | 22 | #include "mimetreeparser_debug.h" |
22 | #include "cryptohelper.h" | 23 | #include "cryptohelper.h" |
23 | #include "objecttreeparser.h" | 24 | #include "objecttreeparser.h" |
24 | #include "qgpgmejobexecutor.h" | ||
25 | |||
26 | #include "cryptobodypartmemento.h" | ||
27 | #include "decryptverifybodypartmemento.h" | ||
28 | #include "verifydetachedbodypartmemento.h" | ||
29 | #include "verifyopaquebodypartmemento.h" | ||
30 | 25 | ||
31 | #include "utils.h" | 26 | #include "utils.h" |
32 | 27 | ||
33 | #include <KMime/Content> | 28 | #include <KMime/Content> |
34 | 29 | ||
35 | #include <QGpgME/DN> | 30 | #include <QGpgME/DN> |
36 | #include <QGpgME/Protocol> | 31 | #include <QGpgME/DataProvider> |
37 | #include <QGpgME/ImportJob> | ||
38 | #include <QGpgME/KeyListJob> | ||
39 | #include <QGpgME/VerifyDetachedJob> | ||
40 | #include <QGpgME/VerifyOpaqueJob> | ||
41 | 32 | ||
33 | #include <gpgme++/context.h> | ||
34 | #include <gpgme++/data.h> | ||
35 | #include <gpgme++/verificationresult.h> | ||
42 | #include <gpgme++/key.h> | 36 | #include <gpgme++/key.h> |
43 | #include <gpgme++/keylistresult.h> | 37 | #include <gpgme++/keylistresult.h> |
44 | #include <gpgme.h> | 38 | #include <gpgme.h> |
@@ -48,6 +42,24 @@ | |||
48 | 42 | ||
49 | using namespace MimeTreeParser; | 43 | using namespace MimeTreeParser; |
50 | 44 | ||
45 | static GpgME::Data fromBA(const QByteArray &ba) | ||
46 | { | ||
47 | return {ba.data(), static_cast<size_t>(ba.size()), false}; | ||
48 | } | ||
49 | |||
50 | static QSharedPointer<GpgME::Context> gpgContext(GpgME::Protocol protocol) | ||
51 | { | ||
52 | GpgME::initializeLibrary(); | ||
53 | auto error = GpgME::checkEngine(protocol); | ||
54 | if (error) { | ||
55 | qWarning() << "Engine check failed: " << error.asString(); | ||
56 | } | ||
57 | auto ctx = QSharedPointer<GpgME::Context>(GpgME::Context::createForProtocol(protocol)); | ||
58 | Q_ASSERT(ctx); | ||
59 | return ctx; | ||
60 | } | ||
61 | |||
62 | |||
51 | //------MessagePart----------------------- | 63 | //------MessagePart----------------------- |
52 | MessagePart::MessagePart(ObjectTreeParser *otp, const QString &text, KMime::Content *node) | 64 | MessagePart::MessagePart(ObjectTreeParser *otp, const QString &text, KMime::Content *node) |
53 | : mText(text) | 65 | : mText(text) |
@@ -382,7 +394,7 @@ void TextMessagePart::parseContent() | |||
382 | mEncryptionState = KMMsgNotEncrypted; | 394 | mEncryptionState = KMMsgNotEncrypted; |
383 | const auto blocks = prepareMessageForDecryption(mNode->decodedContent()); | 395 | const auto blocks = prepareMessageForDecryption(mNode->decodedContent()); |
384 | 396 | ||
385 | const auto cryptProto = QGpgME::openpgp(); | 397 | const auto cryptProto = GpgME::OpenPGP; |
386 | 398 | ||
387 | if (!blocks.isEmpty()) { | 399 | if (!blocks.isEmpty()) { |
388 | 400 | ||
@@ -639,7 +651,7 @@ QString AlternativeMessagePart::htmlContent() const | |||
639 | 651 | ||
640 | //-----CertMessageBlock---------------------- | 652 | //-----CertMessageBlock---------------------- |
641 | 653 | ||
642 | CertMessagePart::CertMessagePart(ObjectTreeParser *otp, KMime::Content *node, const QGpgME::Protocol *cryptoProto) | 654 | CertMessagePart::CertMessagePart(ObjectTreeParser *otp, KMime::Content *node, const GpgME::Protocol cryptoProto) |
643 | : MessagePart(otp, QString(), node) | 655 | : MessagePart(otp, QString(), node) |
644 | , mCryptoProto(cryptoProto) | 656 | , mCryptoProto(cryptoProto) |
645 | { | 657 | { |
@@ -657,9 +669,8 @@ CertMessagePart::~CertMessagePart() | |||
657 | void CertMessagePart::import() | 669 | void CertMessagePart::import() |
658 | { | 670 | { |
659 | const QByteArray certData = mNode->decodedContent(); | 671 | const QByteArray certData = mNode->decodedContent(); |
660 | QGpgME::ImportJob *import = mCryptoProto->importJob(); | 672 | auto ctx = gpgContext(mCryptoProto); |
661 | QGpgMEJobExecutor executor; | 673 | const auto result = ctx->importKeys(fromBA(certData)); |
662 | auto result = executor.exec(import, certData); | ||
663 | } | 674 | } |
664 | 675 | ||
665 | QString CertMessagePart::text() const | 676 | QString CertMessagePart::text() const |
@@ -670,11 +681,11 @@ QString CertMessagePart::text() const | |||
670 | //-----SignedMessageBlock--------------------- | 681 | //-----SignedMessageBlock--------------------- |
671 | SignedMessagePart::SignedMessagePart(ObjectTreeParser *otp, | 682 | SignedMessagePart::SignedMessagePart(ObjectTreeParser *otp, |
672 | const QString &text, | 683 | const QString &text, |
673 | const QGpgME::Protocol *cryptoProto, | 684 | const GpgME::Protocol cryptoProto, |
674 | const QString &fromAddress, | 685 | const QString &fromAddress, |
675 | KMime::Content *node, KMime::Content *signedData) | 686 | KMime::Content *node, KMime::Content *signedData) |
676 | : MessagePart(otp, text, node) | 687 | : MessagePart(otp, text, node) |
677 | , mCryptoProto(cryptoProto) | 688 | , mProtocol(cryptoProto) |
678 | , mFromAddress(fromAddress) | 689 | , mFromAddress(fromAddress) |
679 | , mSignedData(signedData) | 690 | , mSignedData(signedData) |
680 | { | 691 | { |
@@ -700,20 +711,6 @@ bool SignedMessagePart::isSigned() const | |||
700 | return mMetaData.isSigned; | 711 | return mMetaData.isSigned; |
701 | } | 712 | } |
702 | 713 | ||
703 | CryptoBodyPartMemento *SignedMessagePart::verifySignature(const QByteArray &data, const QByteArray &signature) | ||
704 | { | ||
705 | if (!signature.isEmpty()) { | ||
706 | if (QGpgME::VerifyDetachedJob *job = mCryptoProto->verifyDetachedJob()) { | ||
707 | return new VerifyDetachedBodyPartMemento(job, mCryptoProto->keyListJob(), signature, data); | ||
708 | } | ||
709 | } else { | ||
710 | if (QGpgME::VerifyOpaqueJob *job = mCryptoProto->verifyOpaqueJob()) { | ||
711 | return new VerifyOpaqueBodyPartMemento(job, mCryptoProto->keyListJob(), data); | ||
712 | } | ||
713 | } | ||
714 | return nullptr; | ||
715 | } | ||
716 | |||
717 | static int signatureToStatus(const GpgME::Signature &sig) | 714 | static int signatureToStatus(const GpgME::Signature &sig) |
718 | { | 715 | { |
719 | switch (sig.status().code()) { | 716 | switch (sig.status().code()) { |
@@ -739,6 +736,23 @@ QString prettifyDN(const char *uid) | |||
739 | return QGpgME::DN(uid).prettyDN(); | 736 | return QGpgME::DN(uid).prettyDN(); |
740 | } | 737 | } |
741 | 738 | ||
739 | static GpgME::KeyListResult listKeys(GpgME::Context * ctx, const char *pattern, bool secretOnly, std::vector<GpgME::Key> &keys) { | ||
740 | if (const GpgME::Error err = ctx->startKeyListing(pattern, secretOnly)) { | ||
741 | return GpgME::KeyListResult( 0, err ); | ||
742 | } | ||
743 | |||
744 | GpgME::Error err; | ||
745 | do { | ||
746 | keys.push_back( ctx->nextKey(err)); | ||
747 | } while ( !err ); | ||
748 | |||
749 | keys.pop_back(); | ||
750 | |||
751 | const GpgME::KeyListResult result = ctx->endKeyListing(); | ||
752 | ctx->cancelPendingOperation(); | ||
753 | return result; | ||
754 | } | ||
755 | |||
742 | void SignedMessagePart::sigStatusToMetaData() | 756 | void SignedMessagePart::sigStatusToMetaData() |
743 | { | 757 | { |
744 | GpgME::Key key; | 758 | GpgME::Key key; |
@@ -749,29 +763,22 @@ void SignedMessagePart::sigStatusToMetaData() | |||
749 | mMetaData.sigSummary = signature.summary(); | 763 | mMetaData.sigSummary = signature.summary(); |
750 | 764 | ||
751 | if (mMetaData.isGoodSignature && !key.keyID()) { | 765 | if (mMetaData.isGoodSignature && !key.keyID()) { |
752 | // Search for the key by its fingerprint so that we can check for | 766 | auto ctx = gpgContext(mProtocol); |
753 | // trust etc. | 767 | // Search for the key by its fingerprint so that we can check for trust etc. |
754 | QGpgME::KeyListJob *job = mCryptoProto->keyListJob(false); // local, no sigs | 768 | std::vector<GpgME::Key> found_keys; |
755 | if (!job) { | 769 | auto res = listKeys(ctx.data(), signature.fingerprint(), false, found_keys); |
756 | qCDebug(MIMETREEPARSER_LOG) << "The Crypto backend does not support listing keys. "; | 770 | if (res.error()) { |
771 | qCDebug(MIMETREEPARSER_LOG) << "Error while searching key for Fingerprint: " << signature.fingerprint(); | ||
772 | } | ||
773 | if (found_keys.size() > 1) { | ||
774 | // Should not happen | ||
775 | qCDebug(MIMETREEPARSER_LOG) << "Oops: Found more then one Key for Fingerprint: " << signature.fingerprint(); | ||
776 | } | ||
777 | if (found_keys.empty()) { | ||
778 | // Should not happen at this point | ||
779 | qCWarning(MIMETREEPARSER_LOG) << "Oops: Found no Key for Fingerprint: " << signature.fingerprint(); | ||
757 | } else { | 780 | } else { |
758 | std::vector<GpgME::Key> found_keys; | 781 | key = found_keys[0]; |
759 | // As we are local it is ok to make this synchronous | ||
760 | GpgME::KeyListResult res = job->exec(QStringList(QLatin1String(signature.fingerprint())), false, found_keys); | ||
761 | if (res.error()) { | ||
762 | qCDebug(MIMETREEPARSER_LOG) << "Error while searching key for Fingerprint: " << signature.fingerprint(); | ||
763 | } | ||
764 | if (found_keys.size() > 1) { | ||
765 | // Should not happen | ||
766 | qCDebug(MIMETREEPARSER_LOG) << "Oops: Found more then one Key for Fingerprint: " << signature.fingerprint(); | ||
767 | } | ||
768 | if (found_keys.empty()) { | ||
769 | // Should not happen at this point | ||
770 | qCWarning(MIMETREEPARSER_LOG) << "Oops: Found no Key for Fingerprint: " << signature.fingerprint(); | ||
771 | } else { | ||
772 | key = found_keys[0]; | ||
773 | } | ||
774 | delete job; | ||
775 | } | 782 | } |
776 | } | 783 | } |
777 | 784 | ||
@@ -857,25 +864,18 @@ void SignedMessagePart::startVerificationDetached(const QByteArray &text, KMime: | |||
857 | mMetaData.status = tr("Wrong Crypto Plug-In."); | 864 | mMetaData.status = tr("Wrong Crypto Plug-In."); |
858 | mMetaData.status_code = GPGME_SIG_STAT_NONE; | 865 | mMetaData.status_code = GPGME_SIG_STAT_NONE; |
859 | 866 | ||
860 | if (auto *m = verifySignature(text, signature)) { | 867 | auto ctx = gpgContext(mProtocol); |
861 | m->exec(); | 868 | |
862 | if (!signature.isEmpty()) { | 869 | if (!signature.isEmpty()) { |
863 | mVerifiedText = text; | 870 | qWarning() << "We have a signature"; |
864 | } | 871 | auto result = ctx->verifyDetachedSignature(fromBA(signature), fromBA(text)); |
865 | setVerificationResult(m, textNode); | 872 | setVerificationResult(result, textNode, text); |
866 | delete m; | ||
867 | } else { | 873 | } else { |
868 | QString errorMsg; | 874 | qWarning() << "We have no signature"; |
869 | if (!mCryptoProto) { | 875 | QGpgME::QByteArrayDataProvider out; |
870 | errorMsg = tr("No appropriate crypto plug-in was found."); | 876 | GpgME::Data outdata(&out); |
871 | } else { | 877 | auto result = ctx->verifyOpaqueSignature(fromBA(text), outdata); |
872 | errorMsg = tr("Crypto plug-in \"%1\" cannot verify signatures.").arg( | 878 | setVerificationResult(result, textNode, out.data()); |
873 | mCryptoProto->name()); | ||
874 | } | ||
875 | mMetaData.errorText = tr("The message is signed, but the " | ||
876 | "validity of the signature cannot be " | ||
877 | "verified.<br />" | ||
878 | "Reason: %1").arg(errorMsg); | ||
879 | } | 879 | } |
880 | 880 | ||
881 | if (!mMetaData.isSigned) { | 881 | if (!mMetaData.isSigned) { |
@@ -883,24 +883,13 @@ void SignedMessagePart::startVerificationDetached(const QByteArray &text, KMime: | |||
883 | } | 883 | } |
884 | } | 884 | } |
885 | 885 | ||
886 | void SignedMessagePart::setVerificationResult(const CryptoBodyPartMemento *m, KMime::Content *textNode) | 886 | void SignedMessagePart::setVerificationResult(const GpgME::VerificationResult &result, KMime::Content *textNode, const QByteArray &plainText) |
887 | { | 887 | { |
888 | if (const auto vm = dynamic_cast<const VerifyDetachedBodyPartMemento *>(m)) { | 888 | mSignatures = result.signatures(); |
889 | mSignatures = vm->verifyResult().signatures(); | 889 | mVerifiedText = plainText; |
890 | } | 890 | mMetaData.auditLogError = result.error(); |
891 | if (const auto vm = dynamic_cast<const VerifyOpaqueBodyPartMemento *>(m)) { | 891 | if (!mSignatures.empty()) { |
892 | mVerifiedText = vm->plainText(); | 892 | mMetaData.isSigned = true; |
893 | mSignatures = vm->verifyResult().signatures(); | ||
894 | } | ||
895 | if (const auto vm = dynamic_cast<const DecryptVerifyBodyPartMemento *>(m)) { | ||
896 | mVerifiedText = vm->plainText(); | ||
897 | mSignatures = vm->verifyResult().signatures(); | ||
898 | } | ||
899 | mMetaData.auditLogError = m->auditLogError(); | ||
900 | mMetaData.auditLog = m->auditLogAsHtml(); | ||
901 | mMetaData.isSigned = !mSignatures.empty(); | ||
902 | |||
903 | if (mMetaData.isSigned) { | ||
904 | sigStatusToMetaData(); | 893 | sigStatusToMetaData(); |
905 | if (mNode && !textNode) { | 894 | if (mNode && !textNode) { |
906 | mOtp->mNodeHelper->setPartMetaData(mNode, mMetaData); | 895 | mOtp->mNodeHelper->setPartMetaData(mNode, mMetaData); |
@@ -941,11 +930,11 @@ QString SignedMessagePart::htmlContent() const | |||
941 | //-----CryptMessageBlock--------------------- | 930 | //-----CryptMessageBlock--------------------- |
942 | EncryptedMessagePart::EncryptedMessagePart(ObjectTreeParser *otp, | 931 | EncryptedMessagePart::EncryptedMessagePart(ObjectTreeParser *otp, |
943 | const QString &text, | 932 | const QString &text, |
944 | const QGpgME::Protocol *cryptoProto, | 933 | const GpgME::Protocol cryptoProto, |
945 | const QString &fromAddress, | 934 | const QString &fromAddress, |
946 | KMime::Content *node, KMime::Content *encryptedNode) | 935 | KMime::Content *node, KMime::Content *encryptedNode) |
947 | : MessagePart(otp, text, node) | 936 | : MessagePart(otp, text, node) |
948 | , mCryptoProto(cryptoProto) | 937 | , mProtocol(cryptoProto) |
949 | , mFromAddress(fromAddress) | 938 | , mFromAddress(fromAddress) |
950 | , mEncryptedNode(encryptedNode) | 939 | , mEncryptedNode(encryptedNode) |
951 | { | 940 | { |
@@ -1012,32 +1001,21 @@ bool EncryptedMessagePart::okDecryptMIME(KMime::Content &data) | |||
1012 | mMetaData.auditLogError = GpgME::Error(); | 1001 | mMetaData.auditLogError = GpgME::Error(); |
1013 | mMetaData.auditLog.clear(); | 1002 | mMetaData.auditLog.clear(); |
1014 | 1003 | ||
1015 | if (!mCryptoProto) { | ||
1016 | mError = UnknownError; | ||
1017 | mMetaData.errorText = tr("No appropriate crypto plug-in was found."); | ||
1018 | return false; | ||
1019 | } | ||
1020 | |||
1021 | QGpgME::DecryptVerifyJob *job = mCryptoProto->decryptVerifyJob(); | ||
1022 | if (!job) { | ||
1023 | mError = UnknownError; | ||
1024 | mMetaData.errorText = tr("Crypto plug-in \"%1\" cannot decrypt messages.").arg(mCryptoProto->name()); | ||
1025 | return false; | ||
1026 | } | ||
1027 | |||
1028 | const QByteArray ciphertext = data.decodedContent(); | 1004 | const QByteArray ciphertext = data.decodedContent(); |
1029 | auto m = QSharedPointer<DecryptVerifyBodyPartMemento>::create(job, ciphertext); | 1005 | qWarning() << "Protocol: " << mProtocol; |
1030 | m->exec(); | 1006 | auto ctx = gpgContext(mProtocol); |
1031 | 1007 | QGpgME::QByteArrayDataProvider out; | |
1032 | const QByteArray &plainText = m->plainText(); | 1008 | GpgME::Data outdata(&out); |
1033 | const GpgME::DecryptionResult &decryptResult = m->decryptResult(); | 1009 | const std::pair<GpgME::DecryptionResult,GpgME::VerificationResult> res = ctx->decryptAndVerify(fromBA(ciphertext), outdata); |
1034 | const GpgME::VerificationResult &verifyResult = m->verifyResult(); | 1010 | const QByteArray &plainText = out.data(); |
1011 | const GpgME::DecryptionResult &decryptResult = res.first; | ||
1012 | const GpgME::VerificationResult &verifyResult = res.second; | ||
1035 | mMetaData.isSigned = verifyResult.signatures().size() > 0; | 1013 | mMetaData.isSigned = verifyResult.signatures().size() > 0; |
1036 | 1014 | ||
1037 | if (verifyResult.signatures().size() > 0) { | 1015 | if (verifyResult.signatures().size() > 0) { |
1038 | //We simply attach a signed message part to indicate that this content is also signed | 1016 | //We simply attach a signed message part to indicate that this content is also signed |
1039 | auto subPart = SignedMessagePart::Ptr(new SignedMessagePart(mOtp, QString::fromUtf8(plainText), mCryptoProto, mFromAddress, nullptr, nullptr)); | 1017 | auto subPart = SignedMessagePart::Ptr(new SignedMessagePart(mOtp, QString::fromUtf8(plainText), mProtocol, mFromAddress, nullptr, nullptr)); |
1040 | subPart->setVerificationResult(m.data(), nullptr); | 1018 | subPart->setVerificationResult(verifyResult, nullptr, plainText); |
1041 | appendSubPart(subPart); | 1019 | appendSubPart(subPart); |
1042 | } | 1020 | } |
1043 | 1021 | ||
@@ -1075,13 +1053,12 @@ bool EncryptedMessagePart::okDecryptMIME(KMime::Content &data) | |||
1075 | 1053 | ||
1076 | if(noSecKey) { | 1054 | if(noSecKey) { |
1077 | mError = NoKeyError; | 1055 | mError = NoKeyError; |
1078 | mMetaData.errorText = tr("Crypto plug-in \"%1\" could not decrypt the data. ").arg(mCryptoProto->name()) | 1056 | mMetaData.errorText = tr("Could not decrypt the data. ") + tr("No key found for recepients."); |
1079 | + tr("No key found for recepients."); | ||
1080 | } else if (passphraseError) { | 1057 | } else if (passphraseError) { |
1081 | mError = PassphraseError; | 1058 | mError = PassphraseError; |
1082 | } else { | 1059 | } else { |
1083 | mError = UnknownError; | 1060 | mError = UnknownError; |
1084 | mMetaData.errorText = tr("Crypto plug-in \"%1\" could not decrypt the data. ").arg(mCryptoProto->name()) | 1061 | mMetaData.errorText = tr("Could not decrypt the data. ") |
1085 | + tr("Error: %1").arg(mMetaData.errorText); | 1062 | + tr("Error: %1").arg(mMetaData.errorText); |
1086 | } | 1063 | } |
1087 | return false; | 1064 | 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 | |||
41 | class ImportResult; | 41 | class ImportResult; |
42 | } | 42 | } |
43 | 43 | ||
44 | namespace QGpgME | ||
45 | { | ||
46 | class Protocol; | ||
47 | } | ||
48 | |||
49 | namespace KMime | 44 | namespace KMime |
50 | { | 45 | { |
51 | class Content; | 46 | class Content; |
@@ -270,14 +265,14 @@ class CertMessagePart : public MessagePart | |||
270 | Q_OBJECT | 265 | Q_OBJECT |
271 | public: | 266 | public: |
272 | typedef QSharedPointer<CertMessagePart> Ptr; | 267 | typedef QSharedPointer<CertMessagePart> Ptr; |
273 | CertMessagePart(MimeTreeParser::ObjectTreeParser *otp, KMime::Content *node, const QGpgME::Protocol *cryptoProto); | 268 | CertMessagePart(MimeTreeParser::ObjectTreeParser *otp, KMime::Content *node, const GpgME::Protocol cryptoProto); |
274 | virtual ~CertMessagePart(); | 269 | virtual ~CertMessagePart(); |
275 | 270 | ||
276 | QString text() const Q_DECL_OVERRIDE; | 271 | QString text() const Q_DECL_OVERRIDE; |
277 | void import(); | 272 | void import(); |
278 | 273 | ||
279 | private: | 274 | private: |
280 | const QGpgME::Protocol *mCryptoProto; | 275 | const GpgME::Protocol mCryptoProto; |
281 | friend class DefaultRendererPrivate; | 276 | friend class DefaultRendererPrivate; |
282 | }; | 277 | }; |
283 | 278 | ||
@@ -306,7 +301,7 @@ public: | |||
306 | typedef QSharedPointer<EncryptedMessagePart> Ptr; | 301 | typedef QSharedPointer<EncryptedMessagePart> Ptr; |
307 | EncryptedMessagePart(ObjectTreeParser *otp, | 302 | EncryptedMessagePart(ObjectTreeParser *otp, |
308 | const QString &text, | 303 | const QString &text, |
309 | const QGpgME::Protocol *cryptoProto, | 304 | const GpgME::Protocol protocol, |
310 | const QString &fromAddress, | 305 | const QString &fromAddress, |
311 | KMime::Content *node, KMime::Content *encryptedNode = nullptr); | 306 | KMime::Content *node, KMime::Content *encryptedNode = nullptr); |
312 | 307 | ||
@@ -335,7 +330,7 @@ private: | |||
335 | bool okDecryptMIME(KMime::Content &data); | 330 | bool okDecryptMIME(KMime::Content &data); |
336 | 331 | ||
337 | protected: | 332 | protected: |
338 | const QGpgME::Protocol *mCryptoProto; | 333 | const GpgME::Protocol mProtocol; |
339 | QString mFromAddress; | 334 | QString mFromAddress; |
340 | QByteArray mVerifiedText; | 335 | QByteArray mVerifiedText; |
341 | std::vector<GpgME::DecryptionResult::Recipient> mDecryptRecipients; | 336 | std::vector<GpgME::DecryptionResult::Recipient> mDecryptRecipients; |
@@ -353,7 +348,7 @@ public: | |||
353 | typedef QSharedPointer<SignedMessagePart> Ptr; | 348 | typedef QSharedPointer<SignedMessagePart> Ptr; |
354 | SignedMessagePart(ObjectTreeParser *otp, | 349 | SignedMessagePart(ObjectTreeParser *otp, |
355 | const QString &text, | 350 | const QString &text, |
356 | const QGpgME::Protocol *cryptoProto, | 351 | const GpgME::Protocol protocol, |
357 | const QString &fromAddress, | 352 | const QString &fromAddress, |
358 | KMime::Content *node, KMime::Content *signedData); | 353 | KMime::Content *node, KMime::Content *signedData); |
359 | 354 | ||
@@ -373,13 +368,10 @@ public: | |||
373 | QString htmlContent() const Q_DECL_OVERRIDE; | 368 | QString htmlContent() const Q_DECL_OVERRIDE; |
374 | 369 | ||
375 | private: | 370 | private: |
376 | CryptoBodyPartMemento *verifySignature(const QByteArray &data, const QByteArray &signature); | ||
377 | |||
378 | void sigStatusToMetaData(); | 371 | void sigStatusToMetaData(); |
379 | 372 | void setVerificationResult(const GpgME::VerificationResult &result, KMime::Content *textNode, const QByteArray &plainText); | |
380 | void setVerificationResult(const CryptoBodyPartMemento *m, KMime::Content *textNode); | ||
381 | protected: | 373 | protected: |
382 | const QGpgME::Protocol *mCryptoProto; | 374 | GpgME::Protocol mProtocol; |
383 | QString mFromAddress; | 375 | QString mFromAddress; |
384 | QByteArray mVerifiedText; | 376 | QByteArray mVerifiedText; |
385 | KMime::Content *mSignedData; | 377 | 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 @@ | |||
26 | 26 | ||
27 | #include <KMime/Content> | 27 | #include <KMime/Content> |
28 | 28 | ||
29 | #include <QGpgME/Protocol> | ||
30 | |||
31 | #include "mimetreeparser_debug.h" | 29 | #include "mimetreeparser_debug.h" |
32 | 30 | ||
33 | using namespace MimeTreeParser; | 31 | using namespace MimeTreeParser; |
@@ -51,19 +49,19 @@ MessagePart::Ptr MultiPartEncryptedBodyPartFormatter::process(Interface::BodyPar | |||
51 | return MessagePart::Ptr(); | 49 | return MessagePart::Ptr(); |
52 | } | 50 | } |
53 | 51 | ||
54 | const QGpgME::Protocol *useThisCryptProto = nullptr; | 52 | GpgME::Protocol useThisCryptProto = GpgME::UnknownProtocol; |
55 | 53 | ||
56 | /* | 54 | /* |
57 | ATTENTION: This code is to be replaced by the new 'auto-detect' feature. -------------------------------------- | 55 | ATTENTION: This code is to be replaced by the new 'auto-detect' feature. -------------------------------------- |
58 | */ | 56 | */ |
59 | KMime::Content *data = findTypeInDirectChilds(node, "application/octet-stream"); | 57 | KMime::Content *data = findTypeInDirectChilds(node, "application/octet-stream"); |
60 | if (data) { | 58 | if (data) { |
61 | useThisCryptProto = QGpgME::openpgp(); | 59 | useThisCryptProto = GpgME::OpenPGP; |
62 | } | 60 | } |
63 | if (!data) { | 61 | if (!data) { |
64 | data = findTypeInDirectChilds(node, "application/pkcs7-mime"); | 62 | data = findTypeInDirectChilds(node, "application/pkcs7-mime"); |
65 | if (data) { | 63 | if (data) { |
66 | useThisCryptProto = QGpgME::smime(); | 64 | useThisCryptProto = GpgME::CMS; |
67 | } | 65 | } |
68 | } | 66 | } |
69 | /* | 67 | /* |
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 & | |||
67 | protocolContentType = signatureContentType; | 67 | protocolContentType = signatureContentType; |
68 | } | 68 | } |
69 | 69 | ||
70 | const QGpgME::Protocol *protocol = nullptr; | 70 | GpgME::Protocol protocol = GpgME::UnknownProtocol; |
71 | if (protocolContentType == QLatin1String("application/pkcs7-signature") || | 71 | if (protocolContentType == QLatin1String("application/pkcs7-signature") || |
72 | protocolContentType == QLatin1String("application/x-pkcs7-signature")) { | 72 | protocolContentType == QLatin1String("application/x-pkcs7-signature")) { |
73 | protocol = QGpgME::smime(); | 73 | protocol = GpgME::CMS; |
74 | } else if (protocolContentType == QLatin1String("application/pgp-signature") || | 74 | } else if (protocolContentType == QLatin1String("application/pgp-signature") || |
75 | protocolContentType == QLatin1String("application/x-pgp-signature")) { | 75 | protocolContentType == QLatin1String("application/x-pgp-signature")) { |
76 | protocol = QGpgME::openpgp(); | 76 | protocol = GpgME::OpenPGP; |
77 | } | 77 | } |
78 | 78 | ||
79 | if (!protocol) { | 79 | if (protocol == GpgME::UnknownProtocol) { |
80 | return MessagePart::Ptr(new MimeMessagePart(part.objectTreeParser(), signedData, false)); | 80 | return MessagePart::Ptr(new MimeMessagePart(part.objectTreeParser(), signedData, false)); |
81 | } | 81 | } |
82 | 82 | ||
@@ -88,9 +88,6 @@ MessagePart::Ptr MultiPartSignedBodyPartFormatter::process(Interface::BodyPart & | |||
88 | SignedMessagePart::Ptr mp(new SignedMessagePart(part.objectTreeParser(), | 88 | SignedMessagePart::Ptr mp(new SignedMessagePart(part.objectTreeParser(), |
89 | aCodec->toUnicode(cleartext), protocol, | 89 | aCodec->toUnicode(cleartext), protocol, |
90 | part.nodeHelper()->fromAsString(node), signature, signedData)); | 90 | part.nodeHelper()->fromAsString(node), signature, signedData)); |
91 | if (!protocol) { | ||
92 | mp->partMetaData()->auditLogError = GpgME::Error(GPG_ERR_NOT_IMPLEMENTED); | ||
93 | } | ||
94 | 91 | ||
95 | return mp; | 92 | return mp; |
96 | } | 93 | } |
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 @@ | |||
1 | /* | ||
2 | Copyright (c) 2008 Volker Krause <vkrause@kde.org> | ||
3 | |||
4 | This program is free software; you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Public License as published by | ||
6 | the Free Software Foundation; either version 2 of the License, or | ||
7 | (at your option) any later version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU General Public License | ||
15 | along with this program; if not, write to the Free Software | ||
16 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
17 | */ | ||
18 | |||
19 | #include "qgpgmejobexecutor.h" | ||
20 | #include "mimetreeparser_debug.h" | ||
21 | |||
22 | #include <QGpgME/DecryptVerifyJob> | ||
23 | #include <QGpgME/ImportJob> | ||
24 | #include <QGpgME/VerifyDetachedJob> | ||
25 | #include <QGpgME/VerifyOpaqueJob> | ||
26 | |||
27 | #include <QEventLoop> | ||
28 | |||
29 | #include <cassert> | ||
30 | |||
31 | using namespace GpgME; | ||
32 | using namespace MimeTreeParser; | ||
33 | |||
34 | QGpgMEJobExecutor::QGpgMEJobExecutor(QObject *parent) : QObject(parent) | ||
35 | { | ||
36 | setObjectName(QStringLiteral("KleoJobExecutor")); | ||
37 | mEventLoop = new QEventLoop(this); | ||
38 | } | ||
39 | |||
40 | GpgME::VerificationResult QGpgMEJobExecutor::exec( | ||
41 | QGpgME::VerifyDetachedJob *job, | ||
42 | const QByteArray &signature, | ||
43 | const QByteArray &signedData) | ||
44 | { | ||
45 | qCDebug(MIMETREEPARSER_LOG) << "Starting detached verification job"; | ||
46 | connect(job, SIGNAL(result(GpgME::VerificationResult)), SLOT(verificationResult(GpgME::VerificationResult))); | ||
47 | GpgME::Error err = job->start(signature, signedData); | ||
48 | if (err) { | ||
49 | return VerificationResult(err); | ||
50 | } | ||
51 | mEventLoop->exec(QEventLoop::ExcludeUserInputEvents); | ||
52 | return mVerificationResult; | ||
53 | } | ||
54 | |||
55 | GpgME::VerificationResult QGpgMEJobExecutor::exec( | ||
56 | QGpgME::VerifyOpaqueJob *job, | ||
57 | const QByteArray &signedData, | ||
58 | QByteArray &plainText) | ||
59 | { | ||
60 | qCDebug(MIMETREEPARSER_LOG) << "Starting opaque verification job"; | ||
61 | connect(job, SIGNAL(result(GpgME::VerificationResult,QByteArray)), SLOT(verificationResult(GpgME::VerificationResult,QByteArray))); | ||
62 | GpgME::Error err = job->start(signedData); | ||
63 | if (err) { | ||
64 | plainText.clear(); | ||
65 | return VerificationResult(err); | ||
66 | } | ||
67 | mEventLoop->exec(QEventLoop::ExcludeUserInputEvents); | ||
68 | plainText = mData; | ||
69 | return mVerificationResult; | ||
70 | } | ||
71 | |||
72 | std::pair< GpgME::DecryptionResult, GpgME::VerificationResult > QGpgMEJobExecutor::exec( | ||
73 | QGpgME::DecryptVerifyJob *job, | ||
74 | const QByteArray &cipherText, | ||
75 | QByteArray &plainText) | ||
76 | { | ||
77 | qCDebug(MIMETREEPARSER_LOG) << "Starting decryption job"; | ||
78 | connect(job, &QGpgME::DecryptVerifyJob::result, this, &QGpgMEJobExecutor::decryptResult); | ||
79 | GpgME::Error err = job->start(cipherText); | ||
80 | if (err) { | ||
81 | plainText.clear(); | ||
82 | return std::make_pair(DecryptionResult(err), VerificationResult(err)); | ||
83 | } | ||
84 | mEventLoop->exec(QEventLoop::ExcludeUserInputEvents); | ||
85 | plainText = mData; | ||
86 | return std::make_pair(mDecryptResult, mVerificationResult); | ||
87 | } | ||
88 | |||
89 | GpgME::ImportResult QGpgMEJobExecutor::exec(QGpgME::ImportJob *job, const QByteArray &certData) | ||
90 | { | ||
91 | connect(job, SIGNAL(result(GpgME::ImportResult)), SLOT(importResult(GpgME::ImportResult))); | ||
92 | GpgME::Error err = job->start(certData); | ||
93 | if (err) { | ||
94 | return ImportResult(err); | ||
95 | } | ||
96 | mEventLoop->exec(QEventLoop::ExcludeUserInputEvents); | ||
97 | return mImportResult; | ||
98 | } | ||
99 | |||
100 | Error QGpgMEJobExecutor::auditLogError() const | ||
101 | { | ||
102 | return mAuditLogError; | ||
103 | } | ||
104 | |||
105 | void QGpgMEJobExecutor::verificationResult(const GpgME::VerificationResult &result) | ||
106 | { | ||
107 | qCDebug(MIMETREEPARSER_LOG) << "Detached verification job finished"; | ||
108 | QGpgME::Job *job = qobject_cast<QGpgME::Job *>(sender()); | ||
109 | assert(job); | ||
110 | mVerificationResult = result; | ||
111 | mAuditLogError = job->auditLogError(); | ||
112 | mAuditLog = job->auditLogAsHtml(); | ||
113 | mEventLoop->quit(); | ||
114 | } | ||
115 | |||
116 | void QGpgMEJobExecutor::verificationResult(const GpgME::VerificationResult &result, const QByteArray &plainText) | ||
117 | { | ||
118 | qCDebug(MIMETREEPARSER_LOG) << "Opaque verification job finished"; | ||
119 | QGpgME::Job *job = qobject_cast<QGpgME::Job *>(sender()); | ||
120 | assert(job); | ||
121 | mVerificationResult = result; | ||
122 | mData = plainText; | ||
123 | mAuditLogError = job->auditLogError(); | ||
124 | mAuditLog = job->auditLogAsHtml(); | ||
125 | mEventLoop->quit(); | ||
126 | } | ||
127 | |||
128 | void QGpgMEJobExecutor::decryptResult( | ||
129 | const GpgME::DecryptionResult &decryptionresult, | ||
130 | const GpgME::VerificationResult &verificationresult, | ||
131 | const QByteArray &plainText) | ||
132 | { | ||
133 | qCDebug(MIMETREEPARSER_LOG) << "Decryption job finished"; | ||
134 | QGpgME::Job *job = qobject_cast<QGpgME::Job *>(sender()); | ||
135 | assert(job); | ||
136 | mVerificationResult = verificationresult; | ||
137 | mDecryptResult = decryptionresult; | ||
138 | mData = plainText; | ||
139 | mAuditLogError = job->auditLogError(); | ||
140 | mAuditLog = job->auditLogAsHtml(); | ||
141 | mEventLoop->quit(); | ||
142 | } | ||
143 | |||
144 | void QGpgMEJobExecutor::importResult(const GpgME::ImportResult &result) | ||
145 | { | ||
146 | QGpgME::Job *job = qobject_cast<QGpgME::Job *>(sender()); | ||
147 | assert(job); | ||
148 | mImportResult = result; | ||
149 | mAuditLogError = job->auditLogError(); | ||
150 | mAuditLog = job->auditLogAsHtml(); | ||
151 | mEventLoop->quit(); | ||
152 | } | ||
153 | |||
154 | QString QGpgMEJobExecutor::auditLogAsHtml() const | ||
155 | { | ||
156 | return mAuditLog; | ||
157 | } | ||
158 | |||
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 @@ | |||
1 | /* | ||
2 | Copyright (c) 2008 Volker Krause <vkrause@kde.org> | ||
3 | |||
4 | This program is free software; you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Public License as published by | ||
6 | the Free Software Foundation; either version 2 of the License, or | ||
7 | (at your option) any later version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU General Public License | ||
15 | along with this program; if not, write to the Free Software | ||
16 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
17 | */ | ||
18 | |||
19 | #ifndef __MIMETREEPARSER_KLEOJOBEXECUTOR_H__ | ||
20 | #define __MIMETREEPARSER_KLEOJOBEXECUTOR_H__ | ||
21 | |||
22 | #include <gpgme++/decryptionresult.h> | ||
23 | #include <gpgme++/importresult.h> | ||
24 | #include <gpgme++/verificationresult.h> | ||
25 | |||
26 | #include <QObject> | ||
27 | |||
28 | #include <utility> | ||
29 | |||
30 | class QEventLoop; | ||
31 | |||
32 | namespace QGpgME | ||
33 | { | ||
34 | class DecryptVerifyJob; | ||
35 | class ImportJob; | ||
36 | class VerifyDetachedJob; | ||
37 | class VerifyOpaqueJob; | ||
38 | } | ||
39 | |||
40 | namespace MimeTreeParser | ||
41 | { | ||
42 | |||
43 | /** | ||
44 | Helper class for synchronous execution of Kleo crypto jobs. | ||
45 | */ | ||
46 | class QGpgMEJobExecutor : public QObject | ||
47 | { | ||
48 | Q_OBJECT | ||
49 | public: | ||
50 | explicit QGpgMEJobExecutor(QObject *parent = nullptr); | ||
51 | |||
52 | GpgME::VerificationResult exec(QGpgME::VerifyDetachedJob *job, | ||
53 | const QByteArray &signature, | ||
54 | const QByteArray &signedData); | ||
55 | GpgME::VerificationResult exec(QGpgME::VerifyOpaqueJob *job, | ||
56 | const QByteArray &signedData, | ||
57 | QByteArray &plainText); | ||
58 | std::pair<GpgME::DecryptionResult, GpgME::VerificationResult> exec(QGpgME::DecryptVerifyJob *job, | ||
59 | const QByteArray &cipherText, | ||
60 | QByteArray &plainText); | ||
61 | GpgME::ImportResult exec(QGpgME::ImportJob *job, const QByteArray &certData); | ||
62 | |||
63 | GpgME::Error auditLogError() const; | ||
64 | QString auditLogAsHtml() const; | ||
65 | |||
66 | private Q_SLOTS: | ||
67 | void verificationResult(const GpgME::VerificationResult &result); | ||
68 | void verificationResult(const GpgME::VerificationResult &result, const QByteArray &plainText); | ||
69 | void decryptResult(const GpgME::DecryptionResult &decryptionresult, | ||
70 | const GpgME::VerificationResult &verificationresult, | ||
71 | const QByteArray &plainText); | ||
72 | void importResult(const GpgME::ImportResult &result); | ||
73 | |||
74 | private: | ||
75 | QEventLoop *mEventLoop; | ||
76 | GpgME::VerificationResult mVerificationResult; | ||
77 | GpgME::DecryptionResult mDecryptResult; | ||
78 | GpgME::ImportResult mImportResult; | ||
79 | QByteArray mData; | ||
80 | GpgME::Error mAuditLogError; | ||
81 | QString mAuditLog; | ||
82 | }; | ||
83 | |||
84 | } | ||
85 | |||
86 | #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 @@ | |||
1 | /* | ||
2 | Copyright (c) 2014-2017 Montel Laurent <montel@kde.org> | ||
3 | |||
4 | This program is free software; you can redistribute it and/or modify it | ||
5 | under the terms of the GNU General Public License, version 2, as | ||
6 | published by the Free Software Foundation. | ||
7 | |||
8 | This program is distributed in the hope that it will be useful, but | ||
9 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
11 | General Public License for more details. | ||
12 | |||
13 | You should have received a copy of the GNU General Public License along | ||
14 | with this program; if not, write to the Free Software Foundation, Inc., | ||
15 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
16 | */ | ||
17 | |||
18 | #include "verifydetachedbodypartmemento.h" | ||
19 | #include "mimetreeparser_debug.h" | ||
20 | |||
21 | #include <QGpgME/VerifyDetachedJob> | ||
22 | #include <QGpgME/KeyListJob> | ||
23 | |||
24 | #include <gpgme++/keylistresult.h> | ||
25 | |||
26 | #include <qstringlist.h> | ||
27 | |||
28 | #include <cassert> | ||
29 | |||
30 | using namespace QGpgME; | ||
31 | using namespace GpgME; | ||
32 | using namespace MimeTreeParser; | ||
33 | |||
34 | VerifyDetachedBodyPartMemento::VerifyDetachedBodyPartMemento(VerifyDetachedJob *job, | ||
35 | KeyListJob *klj, | ||
36 | const QByteArray &signature, | ||
37 | const QByteArray &plainText) | ||
38 | : CryptoBodyPartMemento(), | ||
39 | m_signature(signature), | ||
40 | m_plainText(plainText), | ||
41 | m_job(job), | ||
42 | m_keylistjob(klj) | ||
43 | { | ||
44 | assert(m_job); | ||
45 | } | ||
46 | |||
47 | VerifyDetachedBodyPartMemento::~VerifyDetachedBodyPartMemento() | ||
48 | { | ||
49 | if (m_job) { | ||
50 | m_job->slotCancel(); | ||
51 | } | ||
52 | if (m_keylistjob) { | ||
53 | m_keylistjob->slotCancel(); | ||
54 | } | ||
55 | } | ||
56 | |||
57 | bool VerifyDetachedBodyPartMemento::start() | ||
58 | { | ||
59 | assert(m_job); | ||
60 | #ifdef DEBUG_SIGNATURE | ||
61 | qCDebug(MIMETREEPARSER_LOG) << "tokoe: VerifyDetachedBodyPartMemento started"; | ||
62 | #endif | ||
63 | connect(m_job, SIGNAL(result(GpgME::VerificationResult)), | ||
64 | this, SLOT(slotResult(GpgME::VerificationResult))); | ||
65 | if (const Error err = m_job->start(m_signature, m_plainText)) { | ||
66 | m_vr = VerificationResult(err); | ||
67 | #ifdef DEBUG_SIGNATURE | ||
68 | qCDebug(MIMETREEPARSER_LOG) << "tokoe: VerifyDetachedBodyPartMemento stopped with error"; | ||
69 | #endif | ||
70 | return false; | ||
71 | } | ||
72 | setRunning(true); | ||
73 | return true; | ||
74 | } | ||
75 | |||
76 | void VerifyDetachedBodyPartMemento::exec() | ||
77 | { | ||
78 | assert(m_job); | ||
79 | setRunning(true); | ||
80 | #ifdef DEBUG_SIGNATURE | ||
81 | qCDebug(MIMETREEPARSER_LOG) << "tokoe: VerifyDetachedBodyPartMemento execed"; | ||
82 | #endif | ||
83 | saveResult(m_job->exec(m_signature, m_plainText)); | ||
84 | m_job->deleteLater(); // exec'ed jobs don't delete themselves | ||
85 | m_job = nullptr; | ||
86 | #ifdef DEBUG_SIGNATURE | ||
87 | qCDebug(MIMETREEPARSER_LOG) << "tokoe: VerifyDetachedBodyPartMemento after execed"; | ||
88 | #endif | ||
89 | if (canStartKeyListJob()) { | ||
90 | std::vector<GpgME::Key> keys; | ||
91 | m_keylistjob->exec(keyListPattern(), /*secretOnly=*/false, keys); | ||
92 | if (!keys.empty()) { | ||
93 | m_key = keys.back(); | ||
94 | } | ||
95 | } | ||
96 | if (m_keylistjob) { | ||
97 | m_keylistjob->deleteLater(); // exec'ed jobs don't delete themselves | ||
98 | } | ||
99 | m_keylistjob = nullptr; | ||
100 | setRunning(false); | ||
101 | } | ||
102 | |||
103 | bool VerifyDetachedBodyPartMemento::canStartKeyListJob() const | ||
104 | { | ||
105 | if (!m_keylistjob) { | ||
106 | return false; | ||
107 | } | ||
108 | const char *const fpr = m_vr.signature(0).fingerprint(); | ||
109 | return fpr && *fpr; | ||
110 | } | ||
111 | |||
112 | QStringList VerifyDetachedBodyPartMemento::keyListPattern() const | ||
113 | { | ||
114 | assert(canStartKeyListJob()); | ||
115 | return QStringList(QString::fromLatin1(m_vr.signature(0).fingerprint())); | ||
116 | } | ||
117 | |||
118 | void VerifyDetachedBodyPartMemento::saveResult(const VerificationResult &vr) | ||
119 | { | ||
120 | assert(m_job); | ||
121 | #ifdef DEBUG_SIGNATURE | ||
122 | qCDebug(MIMETREEPARSER_LOG) << "tokoe: VerifyDetachedBodyPartMemento::saveResult called"; | ||
123 | #endif | ||
124 | m_vr = vr; | ||
125 | setAuditLog(m_job->auditLogError(), m_job->auditLogAsHtml()); | ||
126 | } | ||
127 | |||
128 | void VerifyDetachedBodyPartMemento::slotResult(const VerificationResult &vr) | ||
129 | { | ||
130 | #ifdef DEBUG_SIGNATURE | ||
131 | qCDebug(MIMETREEPARSER_LOG) << "tokoe: VerifyDetachedBodyPartMemento::slotResult called"; | ||
132 | #endif | ||
133 | saveResult(vr); | ||
134 | m_job = nullptr; | ||
135 | if (canStartKeyListJob() && startKeyListJob()) { | ||
136 | #ifdef DEBUG_SIGNATURE | ||
137 | qCDebug(MIMETREEPARSER_LOG) << "tokoe: VerifyDetachedBodyPartMemento: canStartKeyListJob && startKeyListJob"; | ||
138 | #endif | ||
139 | return; | ||
140 | } | ||
141 | if (m_keylistjob) { | ||
142 | m_keylistjob->deleteLater(); | ||
143 | } | ||
144 | m_keylistjob = nullptr; | ||
145 | setRunning(false); | ||
146 | notify(); | ||
147 | } | ||
148 | |||
149 | bool VerifyDetachedBodyPartMemento::startKeyListJob() | ||
150 | { | ||
151 | assert(canStartKeyListJob()); | ||
152 | if (const GpgME::Error err = m_keylistjob->start(keyListPattern())) { | ||
153 | return false; | ||
154 | } | ||
155 | connect(m_keylistjob, SIGNAL(done()), this, SLOT(slotKeyListJobDone())); | ||
156 | connect(m_keylistjob, SIGNAL(nextKey(GpgME::Key)), | ||
157 | this, SLOT(slotNextKey(GpgME::Key))); | ||
158 | return true; | ||
159 | } | ||
160 | |||
161 | void VerifyDetachedBodyPartMemento::slotNextKey(const GpgME::Key &key) | ||
162 | { | ||
163 | #ifdef DEBUG_SIGNATURE | ||
164 | qCDebug(MIMETREEPARSER_LOG) << "tokoe: VerifyDetachedBodyPartMemento::slotNextKey called"; | ||
165 | #endif | ||
166 | m_key = key; | ||
167 | } | ||
168 | |||
169 | void VerifyDetachedBodyPartMemento::slotKeyListJobDone() | ||
170 | { | ||
171 | #ifdef DEBUG_SIGNATURE | ||
172 | qCDebug(MIMETREEPARSER_LOG) << "tokoe: VerifyDetachedBodyPartMemento::slotKeyListJobDone called"; | ||
173 | #endif | ||
174 | m_keylistjob = nullptr; | ||
175 | setRunning(false); | ||
176 | notify(); | ||
177 | } | ||
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 @@ | |||
1 | /* | ||
2 | Copyright (c) 2014-2016 Montel Laurent <montel@kde.org> | ||
3 | |||
4 | This program is free software; you can redistribute it and/or modify it | ||
5 | under the terms of the GNU General Public License, version 2, as | ||
6 | published by the Free Software Foundation. | ||
7 | |||
8 | This program is distributed in the hope that it will be useful, but | ||
9 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
11 | General Public License for more details. | ||
12 | |||
13 | You should have received a copy of the GNU General Public License along | ||
14 | with this program; if not, write to the Free Software Foundation, Inc., | ||
15 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
16 | */ | ||
17 | |||
18 | #ifndef __MIMETREEPARSER_VERIFYDETACHEDBODYPARTMEMENTO_H__ | ||
19 | #define __MIMETREEPARSER_VERIFYDETACHEDBODYPARTMEMENTO_H__ | ||
20 | |||
21 | #include "cryptobodypartmemento.h" | ||
22 | #include <gpgme++/verificationresult.h> | ||
23 | #include <gpgme++/key.h> | ||
24 | |||
25 | #include <QString> | ||
26 | #include <QPointer> | ||
27 | |||
28 | #include "bodypart.h" | ||
29 | |||
30 | namespace QGpgME | ||
31 | { | ||
32 | class VerifyDetachedJob; | ||
33 | class KeyListJob; | ||
34 | } | ||
35 | |||
36 | class QStringList; | ||
37 | |||
38 | namespace MimeTreeParser | ||
39 | { | ||
40 | |||
41 | class VerifyDetachedBodyPartMemento | ||
42 | : public CryptoBodyPartMemento | ||
43 | { | ||
44 | Q_OBJECT | ||
45 | public: | ||
46 | VerifyDetachedBodyPartMemento(QGpgME::VerifyDetachedJob *job, | ||
47 | QGpgME::KeyListJob *klj, | ||
48 | const QByteArray &signature, | ||
49 | const QByteArray &plainText); | ||
50 | ~VerifyDetachedBodyPartMemento(); | ||
51 | |||
52 | bool start() Q_DECL_OVERRIDE; | ||
53 | void exec() Q_DECL_OVERRIDE; | ||
54 | |||
55 | const GpgME::VerificationResult &verifyResult() const | ||
56 | { | ||
57 | return m_vr; | ||
58 | } | ||
59 | const GpgME::Key &signingKey() const | ||
60 | { | ||
61 | return m_key; | ||
62 | } | ||
63 | |||
64 | private Q_SLOTS: | ||
65 | void slotResult(const GpgME::VerificationResult &vr); | ||
66 | void slotKeyListJobDone(); | ||
67 | void slotNextKey(const GpgME::Key &); | ||
68 | |||
69 | private: | ||
70 | void saveResult(const GpgME::VerificationResult &); | ||
71 | bool canStartKeyListJob() const; | ||
72 | QStringList keyListPattern() const; | ||
73 | bool startKeyListJob(); | ||
74 | private: | ||
75 | // input: | ||
76 | const QByteArray m_signature; | ||
77 | const QByteArray m_plainText; | ||
78 | QPointer<QGpgME::VerifyDetachedJob> m_job; | ||
79 | QPointer<QGpgME::KeyListJob> m_keylistjob; | ||
80 | // output: | ||
81 | GpgME::VerificationResult m_vr; | ||
82 | GpgME::Key m_key; | ||
83 | }; | ||
84 | |||
85 | } | ||
86 | |||
87 | #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 @@ | |||
1 | /* | ||
2 | Copyright (c) 2014-2017 Montel Laurent <montel@kde.org> | ||
3 | |||
4 | This program is free software; you can redistribute it and/or modify it | ||
5 | under the terms of the GNU General Public License, version 2, as | ||
6 | published by the Free Software Foundation. | ||
7 | |||
8 | This program is distributed in the hope that it will be useful, but | ||
9 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
11 | General Public License for more details. | ||
12 | |||
13 | You should have received a copy of the GNU General Public License along | ||
14 | with this program; if not, write to the Free Software Foundation, Inc., | ||
15 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
16 | */ | ||
17 | |||
18 | #include "verifyopaquebodypartmemento.h" | ||
19 | #include "mimetreeparser_debug.h" | ||
20 | |||
21 | #include <QGpgME/VerifyOpaqueJob> | ||
22 | #include <QGpgME/KeyListJob> | ||
23 | |||
24 | #include <gpgme++/keylistresult.h> | ||
25 | |||
26 | #include <qstringlist.h> | ||
27 | |||
28 | #include <cassert> | ||
29 | |||
30 | using namespace QGpgME; | ||
31 | using namespace GpgME; | ||
32 | using namespace MimeTreeParser; | ||
33 | |||
34 | VerifyOpaqueBodyPartMemento::VerifyOpaqueBodyPartMemento(VerifyOpaqueJob *job, | ||
35 | KeyListJob *klj, | ||
36 | const QByteArray &signature) | ||
37 | : CryptoBodyPartMemento(), | ||
38 | m_signature(signature), | ||
39 | m_job(job), | ||
40 | m_keylistjob(klj) | ||
41 | { | ||
42 | assert(m_job); | ||
43 | } | ||
44 | |||
45 | VerifyOpaqueBodyPartMemento::~VerifyOpaqueBodyPartMemento() | ||
46 | { | ||
47 | if (m_job) { | ||
48 | m_job->slotCancel(); | ||
49 | } | ||
50 | if (m_keylistjob) { | ||
51 | m_keylistjob->slotCancel(); | ||
52 | } | ||
53 | } | ||
54 | |||
55 | bool VerifyOpaqueBodyPartMemento::start() | ||
56 | { | ||
57 | assert(m_job); | ||
58 | #ifdef DEBUG_SIGNATURE | ||
59 | qCDebug(MIMETREEPARSER_LOG) << "tokoe: VerifyOpaqueBodyPartMemento started"; | ||
60 | #endif | ||
61 | if (const Error err = m_job->start(m_signature)) { | ||
62 | m_vr = VerificationResult(err); | ||
63 | #ifdef DEBUG_SIGNATURE | ||
64 | qCDebug(MIMETREEPARSER_LOG) << "tokoe: VerifyOpaqueBodyPartMemento stopped with error"; | ||
65 | #endif | ||
66 | return false; | ||
67 | } | ||
68 | connect(m_job, SIGNAL(result(GpgME::VerificationResult,QByteArray)), | ||
69 | this, SLOT(slotResult(GpgME::VerificationResult,QByteArray))); | ||
70 | setRunning(true); | ||
71 | return true; | ||
72 | } | ||
73 | |||
74 | void VerifyOpaqueBodyPartMemento::exec() | ||
75 | { | ||
76 | assert(m_job); | ||
77 | setRunning(true); | ||
78 | QByteArray plainText; | ||
79 | #ifdef DEBUG_SIGNATURE | ||
80 | qCDebug(MIMETREEPARSER_LOG) << "tokoe: VerifyOpaqueBodyPartMemento execed"; | ||
81 | #endif | ||
82 | saveResult(m_job->exec(m_signature, plainText), plainText); | ||
83 | #ifdef DEBUG_SIGNATURE | ||
84 | qCDebug(MIMETREEPARSER_LOG) << "tokoe: VerifyOpaqueBodyPartMemento after execed"; | ||
85 | #endif | ||
86 | m_job->deleteLater(); // exec'ed jobs don't delete themselves | ||
87 | m_job = nullptr; | ||
88 | if (canStartKeyListJob()) { | ||
89 | std::vector<GpgME::Key> keys; | ||
90 | m_keylistjob->exec(keyListPattern(), /*secretOnly=*/false, keys); | ||
91 | if (!keys.empty()) { | ||
92 | m_key = keys.back(); | ||
93 | } | ||
94 | } | ||
95 | if (m_keylistjob) { | ||
96 | m_keylistjob->deleteLater(); // exec'ed jobs don't delete themselves | ||
97 | } | ||
98 | m_keylistjob = nullptr; | ||
99 | setRunning(false); | ||
100 | } | ||
101 | |||
102 | bool VerifyOpaqueBodyPartMemento::canStartKeyListJob() const | ||
103 | { | ||
104 | if (!m_keylistjob) { | ||
105 | return false; | ||
106 | } | ||
107 | const char *const fpr = m_vr.signature(0).fingerprint(); | ||
108 | return fpr && *fpr; | ||
109 | } | ||
110 | |||
111 | QStringList VerifyOpaqueBodyPartMemento::keyListPattern() const | ||
112 | { | ||
113 | assert(canStartKeyListJob()); | ||
114 | return QStringList(QString::fromLatin1(m_vr.signature(0).fingerprint())); | ||
115 | } | ||
116 | |||
117 | void VerifyOpaqueBodyPartMemento::saveResult(const VerificationResult &vr, | ||
118 | const QByteArray &plainText) | ||
119 | { | ||
120 | assert(m_job); | ||
121 | #ifdef DEBUG_SIGNATURE | ||
122 | qCDebug(MIMETREEPARSER_LOG) << "tokoe: VerifyOpaqueBodyPartMemento::saveResult called"; | ||
123 | #endif | ||
124 | m_vr = vr; | ||
125 | m_plainText = plainText; | ||
126 | setAuditLog(m_job->auditLogError(), m_job->auditLogAsHtml()); | ||
127 | } | ||
128 | |||
129 | void VerifyOpaqueBodyPartMemento::slotResult(const VerificationResult &vr, | ||
130 | const QByteArray &plainText) | ||
131 | { | ||
132 | #ifdef DEBUG_SIGNATURE | ||
133 | qCDebug(MIMETREEPARSER_LOG) << "tokoe: VerifyOpaqueBodyPartMemento::slotResult called"; | ||
134 | #endif | ||
135 | saveResult(vr, plainText); | ||
136 | m_job = nullptr; | ||
137 | if (canStartKeyListJob() && startKeyListJob()) { | ||
138 | #ifdef DEBUG_SIGNATURE | ||
139 | qCDebug(MIMETREEPARSER_LOG) << "tokoe: VerifyOpaqueBodyPartMemento: canStartKeyListJob && startKeyListJob"; | ||
140 | #endif | ||
141 | return; | ||
142 | } | ||
143 | if (m_keylistjob) { | ||
144 | m_keylistjob->deleteLater(); | ||
145 | } | ||
146 | m_keylistjob = nullptr; | ||
147 | setRunning(false); | ||
148 | notify(); | ||
149 | } | ||
150 | |||
151 | bool VerifyOpaqueBodyPartMemento::startKeyListJob() | ||
152 | { | ||
153 | assert(canStartKeyListJob()); | ||
154 | if (const GpgME::Error err = m_keylistjob->start(keyListPattern())) { | ||
155 | return false; | ||
156 | } | ||
157 | connect(m_keylistjob, SIGNAL(done()), this, SLOT(slotKeyListJobDone())); | ||
158 | connect(m_keylistjob, SIGNAL(nextKey(GpgME::Key)), | ||
159 | this, SLOT(slotNextKey(GpgME::Key))); | ||
160 | return true; | ||
161 | } | ||
162 | |||
163 | void VerifyOpaqueBodyPartMemento::slotNextKey(const GpgME::Key &key) | ||
164 | { | ||
165 | #ifdef DEBUG_SIGNATURE | ||
166 | qCDebug(MIMETREEPARSER_LOG) << "tokoe: VerifyOpaqueBodyPartMemento::slotNextKey called"; | ||
167 | #endif | ||
168 | m_key = key; | ||
169 | } | ||
170 | |||
171 | void VerifyOpaqueBodyPartMemento::slotKeyListJobDone() | ||
172 | { | ||
173 | #ifdef DEBUG_SIGNATURE | ||
174 | qCDebug(MIMETREEPARSER_LOG) << "tokoe: VerifyOpaqueBodyPartMemento::slotKeyListJobDone called"; | ||
175 | #endif | ||
176 | m_keylistjob = nullptr; | ||
177 | setRunning(false); | ||
178 | notify(); | ||
179 | } | ||
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 @@ | |||
1 | /* | ||
2 | Copyright (c) 2014-2016 Montel Laurent <montel@kde.org> | ||
3 | |||
4 | This program is free software; you can redistribute it and/or modify it | ||
5 | under the terms of the GNU General Public License, version 2, as | ||
6 | published by the Free Software Foundation. | ||
7 | |||
8 | This program is distributed in the hope that it will be useful, but | ||
9 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
11 | General Public License for more details. | ||
12 | |||
13 | You should have received a copy of the GNU General Public License along | ||
14 | with this program; if not, write to the Free Software Foundation, Inc., | ||
15 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
16 | */ | ||
17 | |||
18 | #ifndef __MIMETREEPARSER_VERIFYOPAQUEBODYPARTMEMENTO_H__ | ||
19 | #define __MIMETREEPARSER_VERIFYOPAQUEBODYPARTMEMENTO_H__ | ||
20 | |||
21 | #include "cryptobodypartmemento.h" | ||
22 | #include <gpgme++/verificationresult.h> | ||
23 | #include <gpgme++/decryptionresult.h> | ||
24 | #include <gpgme++/key.h> | ||
25 | |||
26 | #include <QString> | ||
27 | #include <QPointer> | ||
28 | |||
29 | #include "bodypart.h" | ||
30 | |||
31 | namespace QGpgME | ||
32 | { | ||
33 | class VerifyOpaqueJob; | ||
34 | class KeyListJob; | ||
35 | } | ||
36 | |||
37 | class QStringList; | ||
38 | |||
39 | namespace MimeTreeParser | ||
40 | { | ||
41 | |||
42 | class VerifyOpaqueBodyPartMemento | ||
43 | : public CryptoBodyPartMemento | ||
44 | { | ||
45 | Q_OBJECT | ||
46 | public: | ||
47 | VerifyOpaqueBodyPartMemento(QGpgME::VerifyOpaqueJob *job, | ||
48 | QGpgME::KeyListJob *klj, | ||
49 | const QByteArray &signature); | ||
50 | ~VerifyOpaqueBodyPartMemento(); | ||
51 | |||
52 | bool start() Q_DECL_OVERRIDE; | ||
53 | void exec() Q_DECL_OVERRIDE; | ||
54 | |||
55 | const QByteArray &plainText() const | ||
56 | { | ||
57 | return m_plainText; | ||
58 | } | ||
59 | const GpgME::VerificationResult &verifyResult() const | ||
60 | { | ||
61 | return m_vr; | ||
62 | } | ||
63 | const GpgME::Key &signingKey() const | ||
64 | { | ||
65 | return m_key; | ||
66 | } | ||
67 | |||
68 | private Q_SLOTS: | ||
69 | void slotResult(const GpgME::VerificationResult &vr, | ||
70 | const QByteArray &plainText); | ||
71 | void slotKeyListJobDone(); | ||
72 | void slotNextKey(const GpgME::Key &); | ||
73 | |||
74 | private: | ||
75 | void saveResult(const GpgME::VerificationResult &, | ||
76 | const QByteArray &); | ||
77 | bool canStartKeyListJob() const; | ||
78 | QStringList keyListPattern() const; | ||
79 | bool startKeyListJob(); | ||
80 | private: | ||
81 | // input: | ||
82 | const QByteArray m_signature; | ||
83 | QPointer<QGpgME::VerifyOpaqueJob> m_job; | ||
84 | QPointer<QGpgME::KeyListJob> m_keylistjob; | ||
85 | // output: | ||
86 | GpgME::VerificationResult m_vr; | ||
87 | QByteArray m_plainText; | ||
88 | GpgME::Key m_key; | ||
89 | }; | ||
90 | |||
91 | } | ||
92 | |||
93 | #endif // __MIMETREEPARSER_VERIFYOPAQUEBODYPARTMEMENTO_H__ | ||