diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2018-02-26 18:07:51 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2018-02-26 18:07:51 +0100 |
commit | 97a1daaa7dfdffbcce18f87fcc666c9896e31e38 (patch) | |
tree | 04736d949f8bcf12f3abc6bdba90fe145392f2d2 | |
parent | 5e8a56bc47937efcfc49fc0e2bf7e0be4cddb350 (diff) | |
download | kube-97a1daaa7dfdffbcce18f87fcc666c9896e31e38.tar.gz kube-97a1daaa7dfdffbcce18f87fcc666c9896e31e38.zip |
gpg error handling cleanup
-rw-r--r-- | framework/src/domain/mime/mimetreeparser/messagepart.cpp | 25 | ||||
-rw-r--r-- | framework/src/domain/mime/mimetreeparser/tests/gpgerrortest.cpp | 18 |
2 files changed, 17 insertions, 26 deletions
diff --git a/framework/src/domain/mime/mimetreeparser/messagepart.cpp b/framework/src/domain/mime/mimetreeparser/messagepart.cpp index 995ea811..541efd7f 100644 --- a/framework/src/domain/mime/mimetreeparser/messagepart.cpp +++ b/framework/src/domain/mime/mimetreeparser/messagepart.cpp | |||
@@ -979,8 +979,6 @@ void EncryptedMessagePart::startDecryption(const QByteArray &text, const QTextCo | |||
979 | bool EncryptedMessagePart::okDecryptMIME(KMime::Content &data) | 979 | bool EncryptedMessagePart::okDecryptMIME(KMime::Content &data) |
980 | { | 980 | { |
981 | mError = NoError; | 981 | mError = NoError; |
982 | auto passphraseError = false; | ||
983 | auto noSecKey = false; | ||
984 | mMetaData.errorText.clear(); | 982 | mMetaData.errorText.clear(); |
985 | mMetaData.auditLogError = GpgME::Error(); | 983 | mMetaData.auditLogError = GpgME::Error(); |
986 | mMetaData.auditLog.clear(); | 984 | mMetaData.auditLog.clear(); |
@@ -1003,36 +1001,37 @@ bool EncryptedMessagePart::okDecryptMIME(KMime::Content &data) | |||
1003 | } | 1001 | } |
1004 | 1002 | ||
1005 | mDecryptRecipients = decryptResult.recipients(); | 1003 | mDecryptRecipients = decryptResult.recipients(); |
1006 | auto decryptionOk = !decryptResult.error(); | 1004 | if (decryptResult.error() && mMetaData.isSigned) { |
1007 | |||
1008 | if (!decryptionOk && mMetaData.isSigned) { | ||
1009 | //Only a signed part | 1005 | //Only a signed part |
1010 | mMetaData.isEncrypted = false; | 1006 | mMetaData.isEncrypted = false; |
1011 | mDecryptedData = plainText; | 1007 | mDecryptedData = plainText; |
1012 | return true; | 1008 | return true; |
1013 | } | 1009 | } |
1014 | 1010 | ||
1015 | passphraseError = decryptResult.error().isCanceled() || decryptResult.error().code() == GPG_ERR_NO_SECKEY; | ||
1016 | mMetaData.isEncrypted = decryptResult.error().code() != GPG_ERR_NO_DATA; | ||
1017 | mMetaData.errorText = QString::fromLocal8Bit(decryptResult.error().asString()); | ||
1018 | if (mMetaData.isEncrypted && decryptResult.numRecipients() > 0) { | 1011 | if (mMetaData.isEncrypted && decryptResult.numRecipients() > 0) { |
1019 | mMetaData.keyId = decryptResult.recipient(0).keyID(); | 1012 | mMetaData.keyId = decryptResult.recipient(0).keyID(); |
1020 | } | 1013 | } |
1021 | 1014 | ||
1022 | if (decryptionOk) { | 1015 | if (!decryptResult.error()) { |
1023 | mDecryptedData = plainText; | 1016 | mDecryptedData = plainText; |
1024 | setText(QString::fromUtf8(mDecryptedData.constData())); | 1017 | setText(QString::fromUtf8(mDecryptedData.constData())); |
1025 | } else { | 1018 | } else { |
1026 | noSecKey = true; | 1019 | mMetaData.isEncrypted = decryptResult.error().code() != GPG_ERR_NO_DATA; |
1020 | mMetaData.errorText = QString::fromLocal8Bit(decryptResult.error().asString()); | ||
1021 | |||
1022 | std::stringstream ss; | ||
1023 | ss << decryptResult << '\n' << verifyResult; | ||
1024 | qWarning() << "Decryption failed: " << ss.str().c_str(); | ||
1025 | |||
1026 | bool passphraseError = decryptResult.error().isCanceled() || decryptResult.error().code() == GPG_ERR_NO_SECKEY; | ||
1027 | |||
1028 | auto noSecKey = true; | ||
1027 | foreach (const GpgME::DecryptionResult::Recipient &recipient, decryptResult.recipients()) { | 1029 | foreach (const GpgME::DecryptionResult::Recipient &recipient, decryptResult.recipients()) { |
1028 | noSecKey &= (recipient.status().code() == GPG_ERR_NO_SECKEY); | 1030 | noSecKey &= (recipient.status().code() == GPG_ERR_NO_SECKEY); |
1029 | } | 1031 | } |
1030 | if (!passphraseError && !noSecKey) { // GpgME do not detect passphrase error correctly | 1032 | if (!passphraseError && !noSecKey) { // GpgME do not detect passphrase error correctly |
1031 | passphraseError = true; | 1033 | passphraseError = true; |
1032 | } | 1034 | } |
1033 | std::stringstream ss; | ||
1034 | ss << decryptResult << '\n' << verifyResult; | ||
1035 | qWarning() << "Decryption failed: " << ss.str().c_str(); | ||
1036 | 1035 | ||
1037 | if(noSecKey) { | 1036 | if(noSecKey) { |
1038 | mError = NoKeyError; | 1037 | mError = NoKeyError; |
diff --git a/framework/src/domain/mime/mimetreeparser/tests/gpgerrortest.cpp b/framework/src/domain/mime/mimetreeparser/tests/gpgerrortest.cpp index 32bffeb5..7e0e0d04 100644 --- a/framework/src/domain/mime/mimetreeparser/tests/gpgerrortest.cpp +++ b/framework/src/domain/mime/mimetreeparser/tests/gpgerrortest.cpp | |||
@@ -71,13 +71,10 @@ private slots: | |||
71 | auto part = partList[0]; | 71 | auto part = partList[0]; |
72 | QVERIFY(bool(part)); | 72 | QVERIFY(bool(part)); |
73 | 73 | ||
74 | qWarning() << part->metaObject()->className() << part->text() << part->partMetaData()->status; | ||
75 | QVERIFY(part->text().startsWith("asdasd")); | 74 | QVERIFY(part->text().startsWith("asdasd")); |
76 | QCOMPARE(part->encryptions().size(), 1); | 75 | QCOMPARE(part->encryptions().size(), 1); |
77 | auto enc = part->encryptions()[0]; | 76 | auto enc = part->encryptions()[0]; |
78 | QCOMPARE(enc->error(), MimeTreeParser::MessagePart::NoError); | 77 | QCOMPARE(enc->error(), MimeTreeParser::MessagePart::NoError); |
79 | // QCOMPARE(enc->errorType(), Encryption::NoError); | ||
80 | // QCOMPARE(enc->errorString(), QString()); | ||
81 | // QCOMPARE((int) enc->recipients().size(), 2); | 78 | // QCOMPARE((int) enc->recipients().size(), 2); |
82 | } | 79 | } |
83 | 80 | ||
@@ -109,11 +106,8 @@ private slots: | |||
109 | 106 | ||
110 | QCOMPARE(part->encryptions().size(), 1); | 107 | QCOMPARE(part->encryptions().size(), 1); |
111 | QVERIFY(part->text().isEmpty()); | 108 | QVERIFY(part->text().isEmpty()); |
112 | // auto enc = part->encryptions()[0]; | 109 | auto enc = part->encryptions()[0]; |
113 | // qDebug() << "HUHU"<< enc->errorType(); | 110 | QCOMPARE(enc->error(), MimeTreeParser::MessagePart::NoKeyError); |
114 | // QCOMPARE(enc->errorType(), Encryption::UnknownError); | ||
115 | // QCOMPARE(enc->errorString(), QString("Crypto plug-in \"OpenPGP\" could not decrypt the data.<br />Error: No data")); | ||
116 | // QCOMPARE((int) enc->recipients().size(), 0); | ||
117 | } | 111 | } |
118 | 112 | ||
119 | void testGpgIncorrectGPGHOME_data() | 113 | void testGpgIncorrectGPGHOME_data() |
@@ -143,10 +137,8 @@ private slots: | |||
143 | QCOMPARE(part->encryptions().size(), 1); | 137 | QCOMPARE(part->encryptions().size(), 1); |
144 | QCOMPARE(part->signatures().size(), 0); | 138 | QCOMPARE(part->signatures().size(), 0); |
145 | QVERIFY(part->text().isEmpty()); | 139 | QVERIFY(part->text().isEmpty()); |
146 | // auto enc = part->encryptions()[0]; | 140 | auto enc = part->encryptions()[0]; |
147 | // qDebug() << enc->errorType(); | 141 | QCOMPARE(enc->error(), MimeTreeParser::MessagePart::NoKeyError); |
148 | // QCOMPARE(enc->errorType(), Encryption::KeyMissing); | ||
149 | // QCOMPARE(enc->errorString(), QString("Crypto plug-in \"OpenPGP\" could not decrypt the data.<br />Error: Decryption failed")); | ||
150 | // QCOMPARE((int) enc->recipients().size(), 2); | 142 | // QCOMPARE((int) enc->recipients().size(), 2); |
151 | } | 143 | } |
152 | 144 | ||
@@ -178,7 +170,7 @@ public Q_SLOTS: | |||
178 | resetEnv(); | 170 | resetEnv(); |
179 | } | 171 | } |
180 | private: | 172 | private: |
181 | void unsetEnv(const QByteArray &name) | 173 | void unsetEnv(const QByteArray &name) |
182 | { | 174 | { |
183 | mModifiedEnv << name; | 175 | mModifiedEnv << name; |
184 | unsetenv(name); | 176 | unsetenv(name); |