diff options
author | Ruben Pollan <meskio@sindominio.net> | 2015-09-16 12:26:11 +0200 |
---|---|---|
committer | Ruben Pollan <meskio@sindominio.net> | 2015-09-16 12:26:11 +0200 |
commit | 61c9901bebf2e55c7bb43c7aa06b17187a5eaf43 (patch) | |
tree | 039f0917ae7175331ef17fb468e99b86e21bb825 /mail/src | |
parent | ecd6cdd674acdcbbaba13b844177cfd8160e5848 (diff) |
[bug] don't fail importing mismatched attached key
We can't import attached keys with different email address than the
sender. Now we don't fail in this case, just log it.
- Resolves: #7454
Diffstat (limited to 'mail/src')
-rw-r--r-- | mail/src/leap/mail/incoming/service.py | 5 | ||||
-rw-r--r-- | mail/src/leap/mail/incoming/tests/test_incoming_mail.py | 24 |
2 files changed, 26 insertions, 3 deletions
diff --git a/mail/src/leap/mail/incoming/service.py b/mail/src/leap/mail/incoming/service.py index 2a3a86a4..8d8f3c2a 100644 --- a/mail/src/leap/mail/incoming/service.py +++ b/mail/src/leap/mail/incoming/service.py @@ -686,6 +686,10 @@ class IncomingMail(Service): """ MIME_KEY = "application/pgp-keys" + def failed_put_key(failure): + logger.info("An error has ocurred adding attached key for %s: %s" + % (address, failure.getErrorMessage())) + deferreds = [] for attachment in attachments: if MIME_KEY == attachment.get_content_type(): @@ -694,6 +698,7 @@ class IncomingMail(Service): attachment.get_payload(), OpenPGPKey, address=address) + d.addErrback(failed_put_key) deferreds.append(d) return defer.gatherResults(deferreds) diff --git a/mail/src/leap/mail/incoming/tests/test_incoming_mail.py b/mail/src/leap/mail/incoming/tests/test_incoming_mail.py index 033799da..589ddadd 100644 --- a/mail/src/leap/mail/incoming/tests/test_incoming_mail.py +++ b/mail/src/leap/mail/incoming/tests/test_incoming_mail.py @@ -30,6 +30,7 @@ from email.parser import Parser from mock import Mock from twisted.internet import defer +from leap.keymanager.errors import KeyAddressMismatch from leap.keymanager.openpgp import OpenPGPKey from leap.mail.adaptors import soledad_indexes as fields from leap.mail.constants import INBOX_NAME @@ -154,9 +155,6 @@ subject: independence of cyberspace return d def testExtractAttachedKey(self): - """ - Test the OpenPGP header key extraction - """ KEY = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n..." message = MIMEMultipart() @@ -176,6 +174,26 @@ subject: independence of cyberspace d.addCallback(put_raw_key_called) return d + def testExtractInvalidAttachedKey(self): + KEY = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n..." + + message = MIMEMultipart() + message.add_header("from", ADDRESS_2) + key = MIMEApplication("", "pgp-keys") + key.set_payload(KEY) + message.attach(key) + self.fetcher._keymanager.put_raw_key = Mock( + return_value=defer.fail(KeyAddressMismatch())) + self.fetcher._keymanager.fetch_key = Mock() + + def put_raw_key_called(_): + self.fetcher._keymanager.put_raw_key.assert_called_once_with( + KEY, OpenPGPKey, address=ADDRESS_2) + + d = self._do_fetch(message.as_string()) + d.addCallback(put_raw_key_called) + return d + def testAddDecryptedHeader(self): class DummyMsg(): def __init__(self): |