summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--framework/domain/mimetreeparser/interface.cpp53
-rw-r--r--framework/domain/mimetreeparser/interface.h20
-rw-r--r--framework/domain/mimetreeparser/tests/gpgerrortest.cpp16
3 files changed, 71 insertions, 18 deletions
diff --git a/framework/domain/mimetreeparser/interface.cpp b/framework/domain/mimetreeparser/interface.cpp
index 77ffa4fd..2380e624 100644
--- a/framework/domain/mimetreeparser/interface.cpp
+++ b/framework/domain/mimetreeparser/interface.cpp
@@ -172,6 +172,7 @@ class KeyPrivate
172public: 172public:
173 Key *q; 173 Key *q;
174 GpgME::Key mKey; 174 GpgME::Key mKey;
175 QByteArray mKeyID;
175}; 176};
176 177
177Key::Key() 178Key::Key()
@@ -194,23 +195,37 @@ Key::~Key()
194 195
195QString Key::keyid() const 196QString Key::keyid() const
196{ 197{
197 return d->mKey.keyID(); 198 if (!d->mKey.isNull()) {
199 return d->mKey.keyID();
200 }
201
202 return d->mKeyID;
198} 203}
199 204
200QString Key::name() const 205QString Key::name() const
201{ 206{
202 //FIXME: is this the correct way to get the primary UID? 207 //FIXME: is this the correct way to get the primary UID?
203 return d->mKey.userID(0).name(); 208 if (!d->mKey.isNull()) {
209 return d->mKey.userID(0).name();
210 }
211
212 return QString();
204} 213}
205 214
206QString Key::email() const 215QString Key::email() const
207{ 216{
208 return d->mKey.userID(0).email(); 217 if (!d->mKey.isNull()) {
218 return d->mKey.userID(0).email();
219 }
220 return QString();
209} 221}
210 222
211QString Key::comment() const 223QString Key::comment() const
212{ 224{
213 return d->mKey.userID(0).comment(); 225 if (!d->mKey.isNull()) {
226 return d->mKey.userID(0).comment();
227 }
228 return QString();
214} 229}
215 230
216class SignaturePrivate 231class SignaturePrivate
@@ -269,6 +284,8 @@ class EncryptionPrivate
269public: 284public:
270 Encryption *q; 285 Encryption *q;
271 std::vector<Key::Ptr> mRecipients; 286 std::vector<Key::Ptr> mRecipients;
287 Encryption::ErrorType mErrorType;
288 QString mErrorString;
272}; 289};
273 290
274Encryption::Encryption(EncryptionPrivate *d_ptr) 291Encryption::Encryption(EncryptionPrivate *d_ptr)
@@ -281,6 +298,7 @@ Encryption::Encryption()
281 :d(std::unique_ptr<EncryptionPrivate>(new EncryptionPrivate)) 298 :d(std::unique_ptr<EncryptionPrivate>(new EncryptionPrivate))
282{ 299{
283 d->q = this; 300 d->q = this;
301 d->mErrorType = Encryption::NoError;
284} 302}
285 303
286Encryption::~Encryption() 304Encryption::~Encryption()
@@ -293,6 +311,17 @@ std::vector<Key::Ptr> Encryption::recipients() const
293 return d->mRecipients; 311 return d->mRecipients;
294} 312}
295 313
314QString Encryption::errorString()
315{
316 return d->mErrorString;
317}
318
319Encryption::ErrorType Encryption::errorType()
320{
321 return d->mErrorType;
322}
323
324
296class PartPrivate 325class PartPrivate
297{ 326{
298public: 327public:
@@ -381,6 +410,19 @@ Encryption::Ptr PartPrivate::createEncryption(const MimeTreeParser::EncryptedMes
381 } 410 }
382 411
383 auto encpriv = new EncryptionPrivate(); 412 auto encpriv = new EncryptionPrivate();
413 if (part->passphraseError()) {
414 encpriv->mErrorType = Encryption::PassphraseError;
415 encpriv->mErrorString = part->mMetaData.errorText;
416 } else if (part->isEncrypted() && !part->isDecryptable()) {
417 encpriv->mErrorType = Encryption::KeyMissing;
418 encpriv->mErrorString = part->mMetaData.errorText;
419 } else if (!part->isEncrypted() && !part->isDecryptable()) {
420 encpriv->mErrorType = Encryption::UnknownError;
421 encpriv->mErrorString = part->mMetaData.errorText;
422 } else {
423 encpriv->mErrorType = Encryption::NoError;
424 }
425
384 foreach(const auto &recipient, part->mDecryptRecipients) { 426 foreach(const auto &recipient, part->mDecryptRecipients) {
385 std::vector<GpgME::Key> found_keys; 427 std::vector<GpgME::Key> found_keys;
386 const auto &keyid = recipient.keyID(); 428 const auto &keyid = recipient.keyID();
@@ -396,6 +438,9 @@ Encryption::Ptr PartPrivate::createEncryption(const MimeTreeParser::EncryptedMes
396 if (found_keys.size() != 1) { 438 if (found_keys.size() != 1) {
397 // Should not Happen at this point 439 // Should not Happen at this point
398 qWarning() << "Oops: Found no Key for Fingerprint: " << keyid; 440 qWarning() << "Oops: Found no Key for Fingerprint: " << keyid;
441 auto keypriv = new KeyPrivate;
442 keypriv->mKeyID = keyid;
443 encpriv->mRecipients.push_back(Key::Ptr(new Key(keypriv)));
399 } else { 444 } else {
400 auto key = found_keys[0]; 445 auto key = found_keys[0];
401 auto keypriv = new KeyPrivate; 446 auto keypriv = new KeyPrivate;
diff --git a/framework/domain/mimetreeparser/interface.h b/framework/domain/mimetreeparser/interface.h
index 1c6fd31d..7c3ea28b 100644
--- a/framework/domain/mimetreeparser/interface.h
+++ b/framework/domain/mimetreeparser/interface.h
@@ -255,18 +255,6 @@ private:
255 friend class SinglePartPrivate; 255 friend class SinglePartPrivate;
256}; 256};
257 257
258
259class EncryptionPart : public Part
260{
261public:
262 typedef std::shared_ptr<EncryptionPart> Ptr;
263 QByteArray type() const Q_DECL_OVERRIDE;
264
265 EncryptionError error() const;
266private:
267 std::unique_ptr<EncryptionPartPrivate> d;
268};
269
270/* 258/*
271 * we want to request complete headers like: 259 * we want to request complete headers like:
272 * from/to... 260 * from/to...
@@ -344,11 +332,19 @@ public:
344class Encryption 332class Encryption
345{ 333{
346public: 334public:
335 enum ErrorType {
336 NoError,
337 PassphraseError,
338 KeyMissing,
339 UnknownError
340 };
347 typedef std::shared_ptr<Encryption> Ptr; 341 typedef std::shared_ptr<Encryption> Ptr;
348 Encryption(); 342 Encryption();
349 Encryption(EncryptionPrivate *); 343 Encryption(EncryptionPrivate *);
350 ~Encryption(); 344 ~Encryption();
351 std::vector<Key::Ptr> recipients() const; 345 std::vector<Key::Ptr> recipients() const;
346 QString errorString();
347 ErrorType errorType();
352private: 348private:
353 std::unique_ptr<EncryptionPrivate> d; 349 std::unique_ptr<EncryptionPrivate> d;
354}; 350};
diff --git a/framework/domain/mimetreeparser/tests/gpgerrortest.cpp b/framework/domain/mimetreeparser/tests/gpgerrortest.cpp
index aca12280..4254d972 100644
--- a/framework/domain/mimetreeparser/tests/gpgerrortest.cpp
+++ b/framework/domain/mimetreeparser/tests/gpgerrortest.cpp
@@ -71,7 +71,10 @@ private slots:
71 auto contentList = contentPart->content("plaintext"); 71 auto contentList = contentPart->content("plaintext");
72 QVERIFY(contentList[0]->content().startsWith("asdasd")); 72 QVERIFY(contentList[0]->content().startsWith("asdasd"));
73 QCOMPARE(contentList[0]->encryptions().size(), 1); 73 QCOMPARE(contentList[0]->encryptions().size(), 1);
74 QCOMPARE(contentList[0]->signatures().size(), 1); 74 auto enc = contentList[0]->encryptions()[0];
75 QCOMPARE(enc->errorType(), Encryption::NoError);
76 QCOMPARE(enc->errorString(), QString());
77 QCOMPARE((int) enc->recipients().size(), 2);
75 } 78 }
76 79
77 void testNoGPGInstalled_data() 80 void testNoGPGInstalled_data()
@@ -98,8 +101,12 @@ private slots:
98 QCOMPARE(contentPart->availableContents(), QVector<QByteArray>() << "plaintext"); 101 QCOMPARE(contentPart->availableContents(), QVector<QByteArray>() << "plaintext");
99 auto contentList = contentPart->content("plaintext"); 102 auto contentList = contentPart->content("plaintext");
100 QCOMPARE(contentList[0]->encryptions().size(), 1); 103 QCOMPARE(contentList[0]->encryptions().size(), 1);
101 QCOMPARE(contentList[0]->signatures().size(), 0);
102 QVERIFY(contentList[0]->content().isEmpty()); 104 QVERIFY(contentList[0]->content().isEmpty());
105 auto enc = contentList[0]->encryptions()[0];
106 qDebug() << "HUHU"<< enc->errorType();
107 QCOMPARE(enc->errorType(), Encryption::UnknownError);
108 QCOMPARE(enc->errorString(), QString("Crypto plug-in \"OpenPGP\" could not decrypt the data.<br />Error: No data"));
109 QCOMPARE((int) enc->recipients().size(), 0);
103 } 110 }
104 111
105 void testGpgIncorrectGPGHOME_data() 112 void testGpgIncorrectGPGHOME_data()
@@ -126,6 +133,11 @@ private slots:
126 QCOMPARE(contentList[0]->encryptions().size(), 1); 133 QCOMPARE(contentList[0]->encryptions().size(), 1);
127 QCOMPARE(contentList[0]->signatures().size(), 0); 134 QCOMPARE(contentList[0]->signatures().size(), 0);
128 QVERIFY(contentList[0]->content().isEmpty()); 135 QVERIFY(contentList[0]->content().isEmpty());
136 auto enc = contentList[0]->encryptions()[0];
137 qDebug() << enc->errorType();
138 QCOMPARE(enc->errorType(), Encryption::KeyMissing);
139 QCOMPARE(enc->errorString(), QString("Crypto plug-in \"OpenPGP\" could not decrypt the data.<br />Error: Decryption failed"));
140 QCOMPARE((int) enc->recipients().size(), 2);
129 } 141 }
130 142
131public Q_SLOTS: 143public Q_SLOTS: