diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2018-04-25 21:20:40 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2018-04-25 21:20:40 +0200 |
commit | a29eae612c79d23c9916345d76b6753aab8f7e16 (patch) | |
tree | 64ae45e6c830c560e41c6d89103448882148c796 | |
parent | 7aff8815c471035f8d73d4c769358dc0b2f5cf6a (diff) | |
download | kube-a29eae612c79d23c9916345d76b6753aab8f7e16.tar.gz kube-a29eae612c79d23c9916345d76b6753aab8f7e16.zip |
Starting to isolate our gpgme++ usage.
So we can destroy it.
4 files changed, 57 insertions, 37 deletions
diff --git a/framework/src/domain/mime/mimetreeparser/messagepart.cpp b/framework/src/domain/mime/mimetreeparser/messagepart.cpp index 9b677d86..f4a962f7 100644 --- a/framework/src/domain/mime/mimetreeparser/messagepart.cpp +++ b/framework/src/domain/mime/mimetreeparser/messagepart.cpp | |||
@@ -59,6 +59,53 @@ static QSharedPointer<GpgME::Context> gpgContext(GpgME::Protocol protocol) | |||
59 | return ctx; | 59 | return ctx; |
60 | } | 60 | } |
61 | 61 | ||
62 | static GpgME::VerificationResult verifyDetachedSignature(GpgME::Protocol protocol, const QByteArray &signature, const QByteArray &text) | ||
63 | { | ||
64 | return gpgContext(protocol)->verifyDetachedSignature(fromBA(signature), fromBA(text)); | ||
65 | } | ||
66 | |||
67 | static GpgME::VerificationResult verifyOpaqueSignature(GpgME::Protocol protocol, const QByteArray &signature, QByteArray &outdata) | ||
68 | { | ||
69 | QGpgME::QByteArrayDataProvider out; | ||
70 | GpgME::Data wrapper(&out); | ||
71 | const auto result = gpgContext(protocol)->verifyOpaqueSignature(fromBA(signature), wrapper); | ||
72 | outdata = out.data(); | ||
73 | return result; | ||
74 | } | ||
75 | |||
76 | |||
77 | static std::pair<GpgME::DecryptionResult,GpgME::VerificationResult> decryptAndVerify(GpgME::Protocol protocol, const QByteArray &ciphertext, QByteArray &outdata) | ||
78 | { | ||
79 | QGpgME::QByteArrayDataProvider out; | ||
80 | GpgME::Data wrapper(&out); | ||
81 | const std::pair<GpgME::DecryptionResult,GpgME::VerificationResult> res = gpgContext(protocol)->decryptAndVerify(fromBA(ciphertext), wrapper); | ||
82 | outdata = out.data(); | ||
83 | return res; | ||
84 | } | ||
85 | |||
86 | static void importKeys(GpgME::Protocol protocol, const QByteArray &certData) | ||
87 | { | ||
88 | gpgContext(protocol)->importKeys(fromBA(certData)); | ||
89 | } | ||
90 | |||
91 | static GpgME::KeyListResult listKeys(GpgME::Protocol protocol, const char *pattern, bool secretOnly, std::vector<GpgME::Key> &keys) { | ||
92 | auto ctx = gpgContext(protocol); | ||
93 | if (const GpgME::Error err = ctx->startKeyListing(pattern, secretOnly)) { | ||
94 | return GpgME::KeyListResult( 0, err ); | ||
95 | } | ||
96 | |||
97 | GpgME::Error err; | ||
98 | do { | ||
99 | keys.push_back( ctx->nextKey(err)); | ||
100 | } while ( !err ); | ||
101 | |||
102 | keys.pop_back(); | ||
103 | |||
104 | const GpgME::KeyListResult result = ctx->endKeyListing(); | ||
105 | ctx->cancelPendingOperation(); | ||
106 | return result; | ||
107 | } | ||
108 | |||
62 | 109 | ||
63 | //------MessagePart----------------------- | 110 | //------MessagePart----------------------- |
64 | MessagePart::MessagePart(ObjectTreeParser *otp, const QString &text, KMime::Content *node) | 111 | MessagePart::MessagePart(ObjectTreeParser *otp, const QString &text, KMime::Content *node) |
@@ -670,7 +717,7 @@ QString AlternativeMessagePart::htmlContent() const | |||
670 | 717 | ||
671 | CertMessagePart::CertMessagePart(ObjectTreeParser *otp, KMime::Content *node, const GpgME::Protocol cryptoProto) | 718 | CertMessagePart::CertMessagePart(ObjectTreeParser *otp, KMime::Content *node, const GpgME::Protocol cryptoProto) |
672 | : MessagePart(otp, QString(), node) | 719 | : MessagePart(otp, QString(), node) |
673 | , mCryptoProto(cryptoProto) | 720 | , mProtocol(cryptoProto) |
674 | { | 721 | { |
675 | if (!mNode) { | 722 | if (!mNode) { |
676 | qCWarning(MIMETREEPARSER_LOG) << "not a valid node"; | 723 | qCWarning(MIMETREEPARSER_LOG) << "not a valid node"; |
@@ -686,8 +733,7 @@ CertMessagePart::~CertMessagePart() | |||
686 | void CertMessagePart::import() | 733 | void CertMessagePart::import() |
687 | { | 734 | { |
688 | const QByteArray certData = mNode->decodedContent(); | 735 | const QByteArray certData = mNode->decodedContent(); |
689 | auto ctx = gpgContext(mCryptoProto); | 736 | importKeys(mProtocol, certData); |
690 | const auto result = ctx->importKeys(fromBA(certData)); | ||
691 | } | 737 | } |
692 | 738 | ||
693 | QString CertMessagePart::text() const | 739 | QString CertMessagePart::text() const |
@@ -753,23 +799,6 @@ QString prettifyDN(const char *uid) | |||
753 | return QGpgME::DN(uid).prettyDN(); | 799 | return QGpgME::DN(uid).prettyDN(); |
754 | } | 800 | } |
755 | 801 | ||
756 | static GpgME::KeyListResult listKeys(GpgME::Context * ctx, const char *pattern, bool secretOnly, std::vector<GpgME::Key> &keys) { | ||
757 | if (const GpgME::Error err = ctx->startKeyListing(pattern, secretOnly)) { | ||
758 | return GpgME::KeyListResult( 0, err ); | ||
759 | } | ||
760 | |||
761 | GpgME::Error err; | ||
762 | do { | ||
763 | keys.push_back( ctx->nextKey(err)); | ||
764 | } while ( !err ); | ||
765 | |||
766 | keys.pop_back(); | ||
767 | |||
768 | const GpgME::KeyListResult result = ctx->endKeyListing(); | ||
769 | ctx->cancelPendingOperation(); | ||
770 | return result; | ||
771 | } | ||
772 | |||
773 | void SignedMessagePart::sigStatusToMetaData(const GpgME::Signature &signature) | 802 | void SignedMessagePart::sigStatusToMetaData(const GpgME::Signature &signature) |
774 | { | 803 | { |
775 | GpgME::Key key; | 804 | GpgME::Key key; |
@@ -779,10 +808,9 @@ void SignedMessagePart::sigStatusToMetaData(const GpgME::Signature &signature) | |||
779 | mMetaData.sigSummary = signature.summary(); | 808 | mMetaData.sigSummary = signature.summary(); |
780 | 809 | ||
781 | if (mMetaData.isGoodSignature && !key.keyID()) { | 810 | if (mMetaData.isGoodSignature && !key.keyID()) { |
782 | auto ctx = gpgContext(mProtocol); | ||
783 | // Search for the key by its fingerprint so that we can check for trust etc. | 811 | // Search for the key by its fingerprint so that we can check for trust etc. |
784 | std::vector<GpgME::Key> found_keys; | 812 | std::vector<GpgME::Key> found_keys; |
785 | auto res = listKeys(ctx.data(), signature.fingerprint(), false, found_keys); | 813 | auto res = listKeys(mProtocol, signature.fingerprint(), false, found_keys); |
786 | if (res.error()) { | 814 | if (res.error()) { |
787 | qCDebug(MIMETREEPARSER_LOG) << "Error while searching key for Fingerprint: " << signature.fingerprint(); | 815 | qCDebug(MIMETREEPARSER_LOG) << "Error while searching key for Fingerprint: " << signature.fingerprint(); |
788 | } | 816 | } |
@@ -875,16 +903,13 @@ void SignedMessagePart::startVerificationDetached(const QByteArray &text, KMime: | |||
875 | mMetaData.status = tr("Wrong Crypto Plug-In."); | 903 | mMetaData.status = tr("Wrong Crypto Plug-In."); |
876 | mMetaData.status_code = GPGME_SIG_STAT_NONE; | 904 | mMetaData.status_code = GPGME_SIG_STAT_NONE; |
877 | 905 | ||
878 | auto ctx = gpgContext(mProtocol); | ||
879 | |||
880 | if (!signature.isEmpty()) { | 906 | if (!signature.isEmpty()) { |
881 | auto result = ctx->verifyDetachedSignature(fromBA(signature), fromBA(text)); | 907 | auto result = verifyDetachedSignature(mProtocol, signature, text); |
882 | setVerificationResult(result, false, text); | 908 | setVerificationResult(result, false, text); |
883 | } else { | 909 | } else { |
884 | QGpgME::QByteArrayDataProvider out; | 910 | QByteArray outdata; |
885 | GpgME::Data outdata(&out); | 911 | auto result = verifyOpaqueSignature(mProtocol, text, outdata); |
886 | auto result = ctx->verifyOpaqueSignature(fromBA(text), outdata); | 912 | setVerificationResult(result, false, outdata); |
887 | setVerificationResult(result, false, out.data()); | ||
888 | } | 913 | } |
889 | 914 | ||
890 | if (!mMetaData.isSigned) { | 915 | if (!mMetaData.isSigned) { |
@@ -1000,11 +1025,8 @@ bool EncryptedMessagePart::okDecryptMIME(KMime::Content &data) | |||
1000 | mMetaData.auditLog.clear(); | 1025 | mMetaData.auditLog.clear(); |
1001 | 1026 | ||
1002 | const QByteArray ciphertext = data.decodedContent(); | 1027 | const QByteArray ciphertext = data.decodedContent(); |
1003 | auto ctx = gpgContext(mProtocol); | 1028 | QByteArray plainText; |
1004 | QGpgME::QByteArrayDataProvider out; | 1029 | const auto res = decryptAndVerify(mProtocol, ciphertext, plainText); |
1005 | GpgME::Data outdata(&out); | ||
1006 | const std::pair<GpgME::DecryptionResult,GpgME::VerificationResult> res = ctx->decryptAndVerify(fromBA(ciphertext), outdata); | ||
1007 | const QByteArray &plainText = out.data(); | ||
1008 | const GpgME::DecryptionResult &decryptResult = res.first; | 1030 | const GpgME::DecryptionResult &decryptResult = res.first; |
1009 | const GpgME::VerificationResult &verifyResult = res.second; | 1031 | const GpgME::VerificationResult &verifyResult = res.second; |
1010 | mMetaData.isSigned = verifyResult.signatures().size() > 0; | 1032 | mMetaData.isSigned = verifyResult.signatures().size() > 0; |
diff --git a/framework/src/domain/mime/mimetreeparser/messagepart.h b/framework/src/domain/mime/mimetreeparser/messagepart.h index 8cd74717..b2714f09 100644 --- a/framework/src/domain/mime/mimetreeparser/messagepart.h +++ b/framework/src/domain/mime/mimetreeparser/messagepart.h | |||
@@ -269,7 +269,7 @@ public: | |||
269 | void import(); | 269 | void import(); |
270 | 270 | ||
271 | private: | 271 | private: |
272 | const GpgME::Protocol mCryptoProto; | 272 | const GpgME::Protocol mProtocol; |
273 | friend class DefaultRendererPrivate; | 273 | friend class DefaultRendererPrivate; |
274 | }; | 274 | }; |
275 | 275 | ||
diff --git a/framework/src/domain/mime/mimetreeparser/objecttreeparser.h b/framework/src/domain/mime/mimetreeparser/objecttreeparser.h index 695d5356..ad67205b 100644 --- a/framework/src/domain/mime/mimetreeparser/objecttreeparser.h +++ b/framework/src/domain/mime/mimetreeparser/objecttreeparser.h | |||
@@ -37,7 +37,6 @@ | |||
37 | #include "nodehelper.h" | 37 | #include "nodehelper.h" |
38 | #include "messagepart.h" | 38 | #include "messagepart.h" |
39 | 39 | ||
40 | #include <gpgme++/verificationresult.h> | ||
41 | #include <functional> | 40 | #include <functional> |
42 | 41 | ||
43 | class QString; | 42 | class QString; |
diff --git a/framework/src/domain/mime/partmodel.cpp b/framework/src/domain/mime/partmodel.cpp index 4583e2a6..7b90ca8b 100644 --- a/framework/src/domain/mime/partmodel.cpp +++ b/framework/src/domain/mime/partmodel.cpp | |||
@@ -25,7 +25,6 @@ | |||
25 | #include <QDebug> | 25 | #include <QDebug> |
26 | #include <QTextDocument> | 26 | #include <QTextDocument> |
27 | 27 | ||
28 | #include <gpgme++/key.h> | ||
29 | #include <gpgme.h> | 28 | #include <gpgme.h> |
30 | 29 | ||
31 | class PartModelPrivate | 30 | class PartModelPrivate |