diff options
author | Ruben Pollan <meskio@sindominio.net> | 2015-09-10 12:19:08 +0200 |
---|---|---|
committer | Ruben Pollan <meskio@sindominio.net> | 2015-09-10 12:19:08 +0200 |
commit | cf7906eda74ad73d026f1a2a29b3581d72abb473 (patch) | |
tree | e00cbd59bd30c3820de46b2f9fa5cdaccd7c47bc | |
parent | 862ed843611bbb10664e06460faee48adce9e5aa (diff) | |
parent | d4c61d7680a726227541daa13e6f72efbbd0fa2e (diff) |
Merge pixelated's X-Leap-Encryption into develop
-rw-r--r-- | src/leap/mail/incoming/service.py | 12 | ||||
-rw-r--r-- | src/leap/mail/incoming/tests/test_incoming_mail.py | 20 |
2 files changed, 30 insertions, 2 deletions
diff --git a/src/leap/mail/incoming/service.py b/src/leap/mail/incoming/service.py index 2bc6751..2e953a7 100644 --- a/src/leap/mail/incoming/service.py +++ b/src/leap/mail/incoming/service.py @@ -90,6 +90,7 @@ class IncomingMail(Service): CONTENT_KEY = "content" LEAP_SIGNATURE_HEADER = 'X-Leap-Signature' + LEAP_ENCRYPTION_HEADER = 'X-Leap-Encryption' """ Header added to messages when they are decrypted by the fetcher, which states the validity of an eventual signature that might be included @@ -99,6 +100,8 @@ class IncomingMail(Service): LEAP_SIGNATURE_INVALID = 'invalid' LEAP_SIGNATURE_COULD_NOT_VERIFY = 'could not verify' + LEAP_ENCRYPTION_DECRYPTED = 'decrypted' + def __init__(self, keymanager, soledad, inbox, userid, check_period=INCOMING_CHECK_PERIOD): @@ -461,6 +464,10 @@ class IncomingMail(Service): d.addCallback(add_leap_header) return d + def _add_decrypted_header(self, msg): + msg.add_header(self.LEAP_ENCRYPTION_HEADER, + self.LEAP_ENCRYPTION_DECRYPTED) + def _decrypt_multipart_encrypted_msg(self, msg, encoding, senderAddress): """ Decrypt a message with content-type 'multipart/encrypted'. @@ -503,6 +510,7 @@ class IncomingMail(Service): # all ok, replace payload by unencrypted payload msg.set_payload(decrmsg.get_payload()) + self._add_decrypted_header(msg) return (msg, signkey) d = self._keymanager.decrypt( @@ -537,7 +545,9 @@ class IncomingMail(Service): def decrypted_data(res): decrdata, signkey = res - return data.replace(pgp_message, decrdata), signkey + replaced_data = data.replace(pgp_message, decrdata) + self._add_decrypted_header(origmsg) + return replaced_data, signkey def encode_and_return(res): data, signkey = res diff --git a/src/leap/mail/incoming/tests/test_incoming_mail.py b/src/leap/mail/incoming/tests/test_incoming_mail.py index f43f746..033799d 100644 --- a/src/leap/mail/incoming/tests/test_incoming_mail.py +++ b/src/leap/mail/incoming/tests/test_incoming_mail.py @@ -176,8 +176,22 @@ subject: independence of cyberspace d.addCallback(put_raw_key_called) return d + def testAddDecryptedHeader(self): + class DummyMsg(): + def __init__(self): + self.headers = {} + + def add_header(self, k, v): + self.headers[k] = v + + msg = DummyMsg() + self.fetcher._add_decrypted_header(msg) + + self.assertEquals(msg.headers['X-Leap-Encryption'], 'decrypted') + def testDecryptEmail(self): self.fetcher._decryption_error = Mock() + self.fetcher._add_decrypted_header = Mock() def create_encrypted_message(encstr): message = Parser().parsestr(self.EMAIL) @@ -198,9 +212,13 @@ subject: independence of cyberspace return newmsg def decryption_error_not_called(_): - self.assertFalse(self.fetcher._decyption_error.called, + self.assertFalse(self.fetcher._decryption_error.called, "There was some errors with decryption") + def add_decrypted_header_called(_): + self.assertTrue(self.fetcher._add_decrypted_header.called, + "There was some errors with decryption") + d = self._km.encrypt( self.EMAIL, ADDRESS, OpenPGPKey, sign=ADDRESS_2) |