summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2017-06-11 21:36:25 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2017-06-11 22:49:59 +0200
commit37a2512e3cc58722d637471fae950593ccf4ef1d (patch)
treea9a75ce68913d35e253f5a2c4cc13b4b4e522147
parent96f080e433029790a628913e2e6c5179f78ee925 (diff)
downloadkube-37a2512e3cc58722d637471fae950593ccf4ef1d.tar.gz
kube-37a2512e3cc58722d637471fae950593ccf4ef1d.zip
Simplified code a bit
-rw-r--r--framework/src/domain/mime/mimetreeparser/messagepart.cpp125
1 files changed, 48 insertions, 77 deletions
diff --git a/framework/src/domain/mime/mimetreeparser/messagepart.cpp b/framework/src/domain/mime/mimetreeparser/messagepart.cpp
index 303268e5..10dee9cf 100644
--- a/framework/src/domain/mime/mimetreeparser/messagepart.cpp
+++ b/framework/src/domain/mime/mimetreeparser/messagepart.cpp
@@ -1089,98 +1089,73 @@ bool EncryptedMessagePart::okDecryptMIME(KMime::Content &data)
1089 mMetaData.auditLogError = GpgME::Error(); 1089 mMetaData.auditLogError = GpgME::Error();
1090 mMetaData.auditLog.clear(); 1090 mMetaData.auditLog.clear();
1091 bool bDecryptionOk = false; 1091 bool bDecryptionOk = false;
1092 bool cannotDecrypt = false;
1093 NodeHelper *nodeHelper = mOtp->nodeHelper(); 1092 NodeHelper *nodeHelper = mOtp->nodeHelper();
1094 1093
1095 // TODO in the async case remember the memento: 1094 if (!mCryptoProto) {
1096 const DecryptVerifyBodyPartMemento *m = nullptr; 1095 mMetaData.errorText = i18n("No appropriate crypto plug-in was found.");
1097 1096 return false;
1098 Q_ASSERT(!m || mCryptoProto); //No CryptoPlugin and having a bodyPartMemento -> there is something completely wrong 1097 }
1099 1098
1100 if (!m && mCryptoProto) { 1099 QGpgME::DecryptVerifyJob *job = mCryptoProto->decryptVerifyJob();
1101 QGpgME::DecryptVerifyJob *job = mCryptoProto->decryptVerifyJob(); 1100 if (!job) {
1102 if (!job) { 1101 mMetaData.errorText = i18n("Crypto plug-in \"%1\" cannot decrypt messages.", mCryptoProto->name());
1103 cannotDecrypt = true; 1102 return false;
1104 } else {
1105 const QByteArray ciphertext = data.decodedContent();
1106 DecryptVerifyBodyPartMemento *newM = new DecryptVerifyBodyPartMemento(job, ciphertext);
1107 if (mOtp->allowAsync()) {
1108 QObject::connect(newM, &CryptoBodyPartMemento::update,
1109 nodeHelper, &NodeHelper::update);
1110 // QObject::connect(newM, SIGNAL(update(MimeTreeParser::UpdateMode)), _source->sourceObject(),
1111 // SLOT(update(MimeTreeParser::UpdateMode)));
1112 if (newM->start()) {
1113 mMetaData.inProgress = true;
1114 mOtp->mHasPendingAsyncJobs = true;
1115 } else {
1116 m = newM;
1117 }
1118 } else {
1119 newM->exec();
1120 m = newM;
1121 }
1122 }
1123 //Only relevant in the async case
1124 // } else if (m->isRunning()) {
1125 // mMetaData.inProgress = true;
1126 // mOtp->mHasPendingAsyncJobs = true;
1127 // m = nullptr;
1128 } 1103 }
1129 1104
1130 if (m) { 1105 const QByteArray ciphertext = data.decodedContent();
1131 const QByteArray &plainText = m->plainText(); 1106 auto m = QSharedPointer<DecryptVerifyBodyPartMemento>::create(job, ciphertext);
1132 const GpgME::DecryptionResult &decryptResult = m->decryptResult(); 1107 m->exec();
1133 const GpgME::VerificationResult &verifyResult = m->verifyResult(); 1108
1134 mMetaData.isSigned = verifyResult.signatures().size() > 0; 1109 const QByteArray &plainText = m->plainText();
1135 1110 const GpgME::DecryptionResult &decryptResult = m->decryptResult();
1136 if (verifyResult.signatures().size() > 0) { 1111 const GpgME::VerificationResult &verifyResult = m->verifyResult();
1137 //We simply attach a signed message part to indicate that this content is also signed 1112 mMetaData.isSigned = verifyResult.signatures().size() > 0;
1138 auto subPart = SignedMessagePart::Ptr(new SignedMessagePart(mOtp, QString::fromUtf8(plainText), mCryptoProto, mFromAddress, nullptr, nullptr)); 1113
1139 subPart->setVerificationResult(m, nullptr); 1114 if (verifyResult.signatures().size() > 0) {
1140 appendSubPart(subPart); 1115 //We simply attach a signed message part to indicate that this content is also signed
1141 } 1116 auto subPart = SignedMessagePart::Ptr(new SignedMessagePart(mOtp, QString::fromUtf8(plainText), mCryptoProto, mFromAddress, nullptr, nullptr));
1117 subPart->setVerificationResult(m.data(), nullptr);
1118 appendSubPart(subPart);
1119 }
1142 1120
1143 mDecryptRecipients = decryptResult.recipients(); 1121 mDecryptRecipients = decryptResult.recipients();
1144 bDecryptionOk = !decryptResult.error(); 1122 bDecryptionOk = !decryptResult.error();
1145 1123
1124 if (!bDecryptionOk) {
1146 std::stringstream ss; 1125 std::stringstream ss;
1147 ss << decryptResult << '\n' << verifyResult; 1126 ss << decryptResult << '\n' << verifyResult;
1148 qWarning() << ss.str().c_str(); 1127 qWarning() << ss.str().c_str();
1128 }
1129
1130 if (!bDecryptionOk && mMetaData.isSigned) {
1131 //Only a signed part
1132 mMetaData.isEncrypted = false;
1133 bDecryptionOk = true;
1134 mDecryptedData = plainText;
1135 } else {
1136 mPassphraseError = decryptResult.error().isCanceled() || decryptResult.error().code() == GPG_ERR_NO_SECKEY;
1137 mMetaData.isEncrypted = decryptResult.error().code() != GPG_ERR_NO_DATA;
1138 mMetaData.errorText = QString::fromLocal8Bit(decryptResult.error().asString());
1139 if (mMetaData.isEncrypted && decryptResult.numRecipients() > 0) {
1140 mMetaData.keyId = decryptResult.recipient(0).keyID();
1141 }
1149 1142
1150 if (!bDecryptionOk && mMetaData.isSigned) { 1143 if (bDecryptionOk) {
1151 //Only a signed part
1152 mMetaData.isEncrypted = false;
1153 bDecryptionOk = true;
1154 mDecryptedData = plainText; 1144 mDecryptedData = plainText;
1145 setText(QString::fromUtf8(mDecryptedData.constData()));
1155 } else { 1146 } else {
1156 mPassphraseError = decryptResult.error().isCanceled() || decryptResult.error().code() == GPG_ERR_NO_SECKEY; 1147 mNoSecKey = true;
1157 mMetaData.isEncrypted = decryptResult.error().code() != GPG_ERR_NO_DATA; 1148 foreach (const GpgME::DecryptionResult::Recipient &recipient, decryptResult.recipients()) {
1158 mMetaData.errorText = QString::fromLocal8Bit(decryptResult.error().asString()); 1149 mNoSecKey &= (recipient.status().code() == GPG_ERR_NO_SECKEY);
1159 if (mMetaData.isEncrypted && decryptResult.numRecipients() > 0) {
1160 mMetaData.keyId = decryptResult.recipient(0).keyID();
1161 } 1150 }
1162 1151 if (!mPassphraseError && !mNoSecKey) { // GpgME do not detect passphrase error correctly
1163 if (bDecryptionOk) { 1152 mPassphraseError = true;
1164 mDecryptedData = plainText;
1165 setText(QString::fromUtf8(mDecryptedData.constData()));
1166 } else {
1167 mNoSecKey = true;
1168 foreach (const GpgME::DecryptionResult::Recipient &recipient, decryptResult.recipients()) {
1169 mNoSecKey &= (recipient.status().code() == GPG_ERR_NO_SECKEY);
1170 }
1171 if (!mPassphraseError && !mNoSecKey) { // GpgME do not detect passphrase error correctly
1172 mPassphraseError = true;
1173 }
1174 } 1153 }
1175 } 1154 }
1176 } 1155 }
1177 1156
1178 if (!bDecryptionOk) { 1157 if (!bDecryptionOk) {
1179 if (!mCryptoProto) { 1158 if(mNoSecKey) {
1180 mMetaData.errorText = i18n("No appropriate crypto plug-in was found.");
1181 } else if (cannotDecrypt) {
1182 mMetaData.errorText = i18n("Crypto plug-in \"%1\" cannot decrypt messages.", mCryptoProto->name());
1183 } else if(mNoSecKey) {
1184 mMetaData.errorText = i18n("Crypto plug-in \"%1\" could not decrypt the data. ", mCryptoProto->name()) 1159 mMetaData.errorText = i18n("Crypto plug-in \"%1\" could not decrypt the data. ", mCryptoProto->name())
1185 + i18n("No key found for recepients."); 1160 + i18n("No key found for recepients.");
1186 } else if (!passphraseError()) { 1161 } else if (!passphraseError()) {
@@ -1188,10 +1163,6 @@ bool EncryptedMessagePart::okDecryptMIME(KMime::Content &data)
1188 + i18n("Error: %1", mMetaData.errorText); 1163 + i18n("Error: %1", mMetaData.errorText);
1189 } 1164 }
1190 } 1165 }
1191 //TODO don't delete in async case
1192 if (m) {
1193 delete m;
1194 }
1195 return bDecryptionOk; 1166 return bDecryptionOk;
1196} 1167}
1197 1168