diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2018-04-26 21:20:46 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2018-04-26 21:20:46 +0200 |
commit | 5da025fb7d42e4c82d7f3c3a7460e2ac1b8698d0 (patch) | |
tree | f1a17aac193206f6d95baba73068de9348cf6ccd /framework/src/domain/mime/mimetreeparser/messagepart.cpp | |
parent | ae20f0a057f4740e3eedb1641d99c37601ad0b7f (diff) | |
download | kube-5da025fb7d42e4c82d7f3c3a7460e2ac1b8698d0.tar.gz kube-5da025fb7d42e4c82d7f3c3a7460e2ac1b8698d0.zip |
Less gpgme in the interfaces
Diffstat (limited to 'framework/src/domain/mime/mimetreeparser/messagepart.cpp')
-rw-r--r-- | framework/src/domain/mime/mimetreeparser/messagepart.cpp | 64 |
1 files changed, 45 insertions, 19 deletions
diff --git a/framework/src/domain/mime/mimetreeparser/messagepart.cpp b/framework/src/domain/mime/mimetreeparser/messagepart.cpp index f4a962f7..9750ea9e 100644 --- a/framework/src/domain/mime/mimetreeparser/messagepart.cpp +++ b/framework/src/domain/mime/mimetreeparser/messagepart.cpp | |||
@@ -47,24 +47,38 @@ static GpgME::Data fromBA(const QByteArray &ba) | |||
47 | return {ba.data(), static_cast<size_t>(ba.size()), false}; | 47 | return {ba.data(), static_cast<size_t>(ba.size()), false}; |
48 | } | 48 | } |
49 | 49 | ||
50 | static QSharedPointer<GpgME::Context> gpgContext(GpgME::Protocol protocol) | 50 | |
51 | static GpgME::Protocol toGpgMe(CryptoProtocol p) | ||
52 | { | ||
53 | switch (p) { | ||
54 | case UnknownProtocol: | ||
55 | return GpgME::UnknownProtocol; | ||
56 | case CMS: | ||
57 | return GpgME::CMS; | ||
58 | case OpenPGP: | ||
59 | return GpgME::OpenPGP; | ||
60 | } | ||
61 | return GpgME::UnknownProtocol; | ||
62 | } | ||
63 | |||
64 | static QSharedPointer<GpgME::Context> gpgContext(CryptoProtocol protocol) | ||
51 | { | 65 | { |
52 | GpgME::initializeLibrary(); | 66 | GpgME::initializeLibrary(); |
53 | auto error = GpgME::checkEngine(protocol); | 67 | auto error = GpgME::checkEngine(toGpgMe(protocol)); |
54 | if (error) { | 68 | if (error) { |
55 | qWarning() << "Engine check failed: " << error.asString(); | 69 | qWarning() << "Engine check failed: " << error.asString(); |
56 | } | 70 | } |
57 | auto ctx = QSharedPointer<GpgME::Context>(GpgME::Context::createForProtocol(protocol)); | 71 | auto ctx = QSharedPointer<GpgME::Context>(GpgME::Context::createForProtocol(toGpgMe(protocol))); |
58 | Q_ASSERT(ctx); | 72 | Q_ASSERT(ctx); |
59 | return ctx; | 73 | return ctx; |
60 | } | 74 | } |
61 | 75 | ||
62 | static GpgME::VerificationResult verifyDetachedSignature(GpgME::Protocol protocol, const QByteArray &signature, const QByteArray &text) | 76 | static GpgME::VerificationResult verifyDetachedSignature(CryptoProtocol protocol, const QByteArray &signature, const QByteArray &text) |
63 | { | 77 | { |
64 | return gpgContext(protocol)->verifyDetachedSignature(fromBA(signature), fromBA(text)); | 78 | return gpgContext(protocol)->verifyDetachedSignature(fromBA(signature), fromBA(text)); |
65 | } | 79 | } |
66 | 80 | ||
67 | static GpgME::VerificationResult verifyOpaqueSignature(GpgME::Protocol protocol, const QByteArray &signature, QByteArray &outdata) | 81 | static GpgME::VerificationResult verifyOpaqueSignature(CryptoProtocol protocol, const QByteArray &signature, QByteArray &outdata) |
68 | { | 82 | { |
69 | QGpgME::QByteArrayDataProvider out; | 83 | QGpgME::QByteArrayDataProvider out; |
70 | GpgME::Data wrapper(&out); | 84 | GpgME::Data wrapper(&out); |
@@ -74,7 +88,7 @@ static GpgME::VerificationResult verifyOpaqueSignature(GpgME::Protocol protocol, | |||
74 | } | 88 | } |
75 | 89 | ||
76 | 90 | ||
77 | static std::pair<GpgME::DecryptionResult,GpgME::VerificationResult> decryptAndVerify(GpgME::Protocol protocol, const QByteArray &ciphertext, QByteArray &outdata) | 91 | static std::pair<GpgME::DecryptionResult,GpgME::VerificationResult> decryptAndVerify(CryptoProtocol protocol, const QByteArray &ciphertext, QByteArray &outdata) |
78 | { | 92 | { |
79 | QGpgME::QByteArrayDataProvider out; | 93 | QGpgME::QByteArrayDataProvider out; |
80 | GpgME::Data wrapper(&out); | 94 | GpgME::Data wrapper(&out); |
@@ -83,12 +97,12 @@ static std::pair<GpgME::DecryptionResult,GpgME::VerificationResult> decryptAndVe | |||
83 | return res; | 97 | return res; |
84 | } | 98 | } |
85 | 99 | ||
86 | static void importKeys(GpgME::Protocol protocol, const QByteArray &certData) | 100 | static void importKeys(CryptoProtocol protocol, const QByteArray &certData) |
87 | { | 101 | { |
88 | gpgContext(protocol)->importKeys(fromBA(certData)); | 102 | gpgContext(protocol)->importKeys(fromBA(certData)); |
89 | } | 103 | } |
90 | 104 | ||
91 | static GpgME::KeyListResult listKeys(GpgME::Protocol protocol, const char *pattern, bool secretOnly, std::vector<GpgME::Key> &keys) { | 105 | static GpgME::KeyListResult listKeys(CryptoProtocol protocol, const char *pattern, bool secretOnly, std::vector<GpgME::Key> &keys) { |
92 | auto ctx = gpgContext(protocol); | 106 | auto ctx = gpgContext(protocol); |
93 | if (const GpgME::Error err = ctx->startKeyListing(pattern, secretOnly)) { | 107 | if (const GpgME::Error err = ctx->startKeyListing(pattern, secretOnly)) { |
94 | return GpgME::KeyListResult( 0, err ); | 108 | return GpgME::KeyListResult( 0, err ); |
@@ -464,7 +478,7 @@ void TextMessagePart::parseContent() | |||
464 | auto body = mNode->decodedContent(); | 478 | auto body = mNode->decodedContent(); |
465 | const auto blocks = prepareMessageForDecryption(body); | 479 | const auto blocks = prepareMessageForDecryption(body); |
466 | 480 | ||
467 | const auto cryptProto = GpgME::OpenPGP; | 481 | const auto cryptProto = OpenPGP; |
468 | 482 | ||
469 | if (!blocks.isEmpty()) { | 483 | if (!blocks.isEmpty()) { |
470 | 484 | ||
@@ -715,7 +729,7 @@ QString AlternativeMessagePart::htmlContent() const | |||
715 | 729 | ||
716 | //-----CertMessageBlock---------------------- | 730 | //-----CertMessageBlock---------------------- |
717 | 731 | ||
718 | CertMessagePart::CertMessagePart(ObjectTreeParser *otp, KMime::Content *node, const GpgME::Protocol cryptoProto) | 732 | CertMessagePart::CertMessagePart(ObjectTreeParser *otp, KMime::Content *node, const CryptoProtocol cryptoProto) |
719 | : MessagePart(otp, QString(), node) | 733 | : MessagePart(otp, QString(), node) |
720 | , mProtocol(cryptoProto) | 734 | , mProtocol(cryptoProto) |
721 | { | 735 | { |
@@ -744,7 +758,7 @@ QString CertMessagePart::text() const | |||
744 | //-----SignedMessageBlock--------------------- | 758 | //-----SignedMessageBlock--------------------- |
745 | SignedMessagePart::SignedMessagePart(ObjectTreeParser *otp, | 759 | SignedMessagePart::SignedMessagePart(ObjectTreeParser *otp, |
746 | const QString &text, | 760 | const QString &text, |
747 | const GpgME::Protocol cryptoProto, | 761 | const CryptoProtocol cryptoProto, |
748 | const QString &fromAddress, | 762 | const QString &fromAddress, |
749 | KMime::Content *node, KMime::Content *signedData) | 763 | KMime::Content *node, KMime::Content *signedData) |
750 | : MessagePart(otp, text, node) | 764 | : MessagePart(otp, text, node) |
@@ -754,7 +768,8 @@ SignedMessagePart::SignedMessagePart(ObjectTreeParser *otp, | |||
754 | { | 768 | { |
755 | mMetaData.isSigned = true; | 769 | mMetaData.isSigned = true; |
756 | mMetaData.isGoodSignature = false; | 770 | mMetaData.isGoodSignature = false; |
757 | mMetaData.keyTrust = GpgME::Signature::Unknown; | 771 | //FIXME |
772 | // mMetaData.keyTrust = GpgME::Signature::Unknown; | ||
758 | mMetaData.status = tr("Wrong Crypto Plug-In."); | 773 | mMetaData.status = tr("Wrong Crypto Plug-In."); |
759 | mMetaData.status_code = GPGME_SIG_STAT_NONE; | 774 | mMetaData.status_code = GPGME_SIG_STAT_NONE; |
760 | } | 775 | } |
@@ -805,7 +820,13 @@ void SignedMessagePart::sigStatusToMetaData(const GpgME::Signature &signature) | |||
805 | mMetaData.status_code = signatureToStatus(signature); | 820 | mMetaData.status_code = signatureToStatus(signature); |
806 | mMetaData.isGoodSignature = mMetaData.status_code & GPGME_SIG_STAT_GOOD; | 821 | mMetaData.isGoodSignature = mMetaData.status_code & GPGME_SIG_STAT_GOOD; |
807 | // save extended signature status flags | 822 | // save extended signature status flags |
808 | mMetaData.sigSummary = signature.summary(); | 823 | auto summary = signature.summary(); |
824 | mMetaData.keyMissing = summary & GpgME::Signature::KeyMissing; | ||
825 | mMetaData.keyExpired = summary & GpgME::Signature::KeyExpired; | ||
826 | mMetaData.keyRevoked = summary & GpgME::Signature::KeyRevoked; | ||
827 | mMetaData.sigExpired = summary & GpgME::Signature::SigExpired; | ||
828 | mMetaData.crlMissing = summary & GpgME::Signature::CrlMissing; | ||
829 | mMetaData.crlTooOld = summary & GpgME::Signature::CrlTooOld; | ||
809 | 830 | ||
810 | if (mMetaData.isGoodSignature && !key.keyID()) { | 831 | if (mMetaData.isGoodSignature && !key.keyID()) { |
811 | // Search for the key by its fingerprint so that we can check for trust etc. | 832 | // Search for the key by its fingerprint so that we can check for trust etc. |
@@ -832,7 +853,8 @@ void SignedMessagePart::sigStatusToMetaData(const GpgME::Signature &signature) | |||
832 | if (mMetaData.keyId.isEmpty()) { | 853 | if (mMetaData.keyId.isEmpty()) { |
833 | mMetaData.keyId = signature.fingerprint(); | 854 | mMetaData.keyId = signature.fingerprint(); |
834 | } | 855 | } |
835 | mMetaData.keyTrust = signature.validity(); | 856 | auto keyTrust = signature.validity(); |
857 | mMetaData.keyIsTrusted = keyTrust & GpgME::Signature::Full || keyTrust & GpgME::Signature::Ultimate; | ||
836 | if (key.numUserIDs() > 0 && key.userID(0).id()) { | 858 | if (key.numUserIDs() > 0 && key.userID(0).id()) { |
837 | mMetaData.signer = prettifyDN(key.userID(0).id()); | 859 | mMetaData.signer = prettifyDN(key.userID(0).id()); |
838 | } | 860 | } |
@@ -899,7 +921,8 @@ void SignedMessagePart::startVerificationDetached(const QByteArray &text, KMime: | |||
899 | } | 921 | } |
900 | 922 | ||
901 | mMetaData.isSigned = false; | 923 | mMetaData.isSigned = false; |
902 | mMetaData.keyTrust = GpgME::Signature::Unknown; | 924 | //FIXME |
925 | // mMetaData.keyTrust = GpgME::Signature::Unknown; | ||
903 | mMetaData.status = tr("Wrong Crypto Plug-In."); | 926 | mMetaData.status = tr("Wrong Crypto Plug-In."); |
904 | mMetaData.status_code = GPGME_SIG_STAT_NONE; | 927 | mMetaData.status_code = GPGME_SIG_STAT_NONE; |
905 | 928 | ||
@@ -920,7 +943,8 @@ void SignedMessagePart::startVerificationDetached(const QByteArray &text, KMime: | |||
920 | void SignedMessagePart::setVerificationResult(const GpgME::VerificationResult &result, bool parseText, const QByteArray &plainText) | 943 | void SignedMessagePart::setVerificationResult(const GpgME::VerificationResult &result, bool parseText, const QByteArray &plainText) |
921 | { | 944 | { |
922 | auto signatures = result.signatures(); | 945 | auto signatures = result.signatures(); |
923 | mMetaData.auditLogError = result.error(); | 946 | // FIXME |
947 | // mMetaData.auditLogError = result.error(); | ||
924 | if (!signatures.empty()) { | 948 | if (!signatures.empty()) { |
925 | mMetaData.isSigned = true; | 949 | mMetaData.isSigned = true; |
926 | sigStatusToMetaData(signatures.front()); | 950 | sigStatusToMetaData(signatures.front()); |
@@ -955,7 +979,7 @@ QString SignedMessagePart::htmlContent() const | |||
955 | //-----CryptMessageBlock--------------------- | 979 | //-----CryptMessageBlock--------------------- |
956 | EncryptedMessagePart::EncryptedMessagePart(ObjectTreeParser *otp, | 980 | EncryptedMessagePart::EncryptedMessagePart(ObjectTreeParser *otp, |
957 | const QString &text, | 981 | const QString &text, |
958 | const GpgME::Protocol cryptoProto, | 982 | const CryptoProtocol cryptoProto, |
959 | const QString &fromAddress, | 983 | const QString &fromAddress, |
960 | KMime::Content *node, KMime::Content *encryptedNode) | 984 | KMime::Content *node, KMime::Content *encryptedNode) |
961 | : MessagePart(otp, text, node) | 985 | : MessagePart(otp, text, node) |
@@ -967,7 +991,8 @@ EncryptedMessagePart::EncryptedMessagePart(ObjectTreeParser *otp, | |||
967 | mMetaData.isGoodSignature = false; | 991 | mMetaData.isGoodSignature = false; |
968 | mMetaData.isEncrypted = false; | 992 | mMetaData.isEncrypted = false; |
969 | mMetaData.isDecryptable = false; | 993 | mMetaData.isDecryptable = false; |
970 | mMetaData.keyTrust = GpgME::Signature::Unknown; | 994 | //FIXME |
995 | // mMetaData.keyTrust = GpgME::Signature::Unknown; | ||
971 | mMetaData.status = tr("Wrong Crypto Plug-In."); | 996 | mMetaData.status = tr("Wrong Crypto Plug-In."); |
972 | mMetaData.status_code = GPGME_SIG_STAT_NONE; | 997 | mMetaData.status_code = GPGME_SIG_STAT_NONE; |
973 | } | 998 | } |
@@ -1021,7 +1046,8 @@ bool EncryptedMessagePart::okDecryptMIME(KMime::Content &data) | |||
1021 | { | 1046 | { |
1022 | mError = NoError; | 1047 | mError = NoError; |
1023 | mMetaData.errorText.clear(); | 1048 | mMetaData.errorText.clear(); |
1024 | mMetaData.auditLogError = GpgME::Error(); | 1049 | //FIXME |
1050 | // mMetaData.auditLogError = GpgME::Error(); | ||
1025 | mMetaData.auditLog.clear(); | 1051 | mMetaData.auditLog.clear(); |
1026 | 1052 | ||
1027 | const QByteArray ciphertext = data.decodedContent(); | 1053 | const QByteArray ciphertext = data.decodedContent(); |