From 66ae1e6091890528cb3499840bdd935b1e39956e Mon Sep 17 00:00:00 2001 From: Ruben Pollan Date: Tue, 3 May 2016 11:49:38 -0300 Subject: [feat] Adapt to the new KeyManager API without key types. - Related: #8031 --- mail/src/leap/mail/incoming/service.py | 20 ++++++-------------- .../leap/mail/incoming/tests/test_incoming_mail.py | 19 ++++++++----------- mail/src/leap/mail/outgoing/service.py | 13 +++++-------- mail/src/leap/mail/outgoing/tests/test_outgoing.py | 13 ++++++------- mail/src/leap/mail/smtp/gateway.py | 3 +-- mail/src/leap/mail/smtp/tests/test_gateway.py | 4 ++-- mail/src/leap/mail/tests/__init__.py | 5 ++--- 7 files changed, 30 insertions(+), 47 deletions(-) (limited to 'mail/src') diff --git a/mail/src/leap/mail/incoming/service.py b/mail/src/leap/mail/incoming/service.py index c7d194d6..0d49a40f 100644 --- a/mail/src/leap/mail/incoming/service.py +++ b/mail/src/leap/mail/incoming/service.py @@ -40,7 +40,6 @@ from leap.common.events import emit_async, catalog from leap.common.check import leap_assert, leap_assert_type from leap.common.mail import get_email_charset from leap.keymanager import errors as keymanager_errors -from leap.keymanager.openpgp import OpenPGPKey from leap.mail.adaptors import soledad_indexes as fields from leap.mail.generator import Generator from leap.mail.utils import json_loads, empty @@ -340,9 +339,7 @@ class IncomingMail(Service): "1" if success else "0") return self._process_decrypted_doc(doc, decrdata) - d = self._keymanager.decrypt( - doc.content[ENC_JSON_KEY], - self._userid, OpenPGPKey) + d = self._keymanager.decrypt(doc.content[ENC_JSON_KEY], self._userid) d.addErrback(self._errback) d.addCallback(process_decrypted) d.addCallback(lambda data: (doc, data)) @@ -525,8 +522,7 @@ class IncomingMail(Service): return (msg, signkey) d = self._keymanager.decrypt( - encdata, self._userid, OpenPGPKey, - verify=senderAddress) + encdata, self._userid, verify=senderAddress) d.addCallbacks(build_msg, self._decryption_error, errbackArgs=(msg,)) return d @@ -569,8 +565,7 @@ class IncomingMail(Service): end = data.find(PGP_END) pgp_message = data[begin:end + len(PGP_END)] d = self._keymanager.decrypt( - pgp_message, self._userid, OpenPGPKey, - verify=senderAddress) + pgp_message, self._userid, verify=senderAddress) d.addCallbacks(decrypted_data, self._decryption_error, errbackArgs=(data,)) else: @@ -595,8 +590,7 @@ class IncomingMail(Service): msg = copy.deepcopy(origmsg) data = self._serialize_msg(msg.get_payload(0)) detached_sig = self._extract_signature(msg) - d = self._keymanager.verify(data, sender_address, OpenPGPKey, - detached_sig) + d = self._keymanager.verify(data, sender_address, detached_sig) d.addCallback(lambda sign_key: (msg, sign_key)) d.addErrback(lambda _: (msg, keymanager_errors.InvalidSignature())) @@ -708,7 +702,7 @@ class IncomingMail(Service): else: return failure - d = self._keymanager.fetch_key(address, url, OpenPGPKey) + d = self._keymanager.fetch_key(address, url) d.addCallback( lambda _: logger.info("Imported key from header %s" % (url,))) @@ -749,9 +743,7 @@ class IncomingMail(Service): for attachment in attachments: if MIME_KEY == attachment.get_content_type(): d = self._keymanager.put_raw_key( - attachment.get_payload(decode=True), - OpenPGPKey, - address=address) + attachment.get_payload(decode=True), address=address) d.addCallbacks(log_key_added, failed_put_key) deferreds.append(d) d = 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 754df9f0..6267c06f 100644 --- a/mail/src/leap/mail/incoming/tests/test_incoming_mail.py +++ b/mail/src/leap/mail/incoming/tests/test_incoming_mail.py @@ -31,7 +31,6 @@ 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 from leap.mail.imap.account import IMAPAccount @@ -122,7 +121,7 @@ subject: independence of cyberspace def fetch_key_called(ret): self.fetcher._keymanager.fetch_key.assert_called_once_with( - ADDRESS_2, KEYURL, OpenPGPKey) + ADDRESS_2, KEYURL) d = self._create_incoming_email(message.as_string()) d.addCallback( @@ -167,7 +166,7 @@ subject: independence of cyberspace def put_raw_key_called(_): self.fetcher._keymanager.put_raw_key.assert_called_once_with( - KEY, OpenPGPKey, address=ADDRESS_2) + KEY, address=ADDRESS_2) d = self._do_fetch(message.as_string()) d.addCallback(put_raw_key_called) @@ -186,7 +185,7 @@ subject: independence of cyberspace def put_raw_key_called(_): self.fetcher._keymanager.put_raw_key.assert_called_once_with( - KEY, OpenPGPKey, address=ADDRESS_2) + KEY, address=ADDRESS_2) d = self._do_fetch(message.as_string()) d.addCallback(put_raw_key_called) @@ -210,7 +209,7 @@ subject: independence of cyberspace def put_raw_key_called(_): self.fetcher._keymanager.put_raw_key.assert_called_once_with( - KEY, OpenPGPKey, address=ADDRESS_2) + KEY, address=ADDRESS_2) self.assertFalse(self.fetcher._keymanager.fetch_key.called) d = self._do_fetch(message.as_string()) @@ -235,9 +234,9 @@ subject: independence of cyberspace def put_raw_key_called(_): self.fetcher._keymanager.put_raw_key.assert_called_once_with( - KEY, OpenPGPKey, address=ADDRESS_2) + KEY, address=ADDRESS_2) self.fetcher._keymanager.fetch_key.assert_called_once_with( - ADDRESS_2, KEYURL, OpenPGPKey) + ADDRESS_2, KEYURL) d = self._do_fetch(message.as_string()) d.addCallback(put_raw_key_called) @@ -286,9 +285,7 @@ subject: independence of cyberspace 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) + d = self._km.encrypt(self.EMAIL, ADDRESS, sign=ADDRESS_2) d.addCallback(create_encrypted_message) d.addCallback( lambda message: @@ -331,7 +328,7 @@ subject: independence of cyberspace ENC_JSON_KEY: encr_data } return email - d = self._km.encrypt(data, ADDRESS, OpenPGPKey, fetch_remote=False) + d = self._km.encrypt(data, ADDRESS, fetch_remote=False) d.addCallback(set_email_content) return d diff --git a/mail/src/leap/mail/outgoing/service.py b/mail/src/leap/mail/outgoing/service.py index 95d3e79f..05c3bed2 100644 --- a/mail/src/leap/mail/outgoing/service.py +++ b/mail/src/leap/mail/outgoing/service.py @@ -40,7 +40,6 @@ from twisted.python import log from leap.common.check import leap_assert_type, leap_assert from leap.common.events import emit_async, catalog -from leap.keymanager.openpgp import OpenPGPKey from leap.keymanager.errors import KeyNotFound, KeyAddressMismatch from leap.mail import __version__ from leap.mail import errors @@ -328,8 +327,7 @@ class OutgoingMail(object): return get_key_and_attach(None) def get_key_and_attach(_): - d = self._keymanager.get_key(from_address, OpenPGPKey, - fetch_remote=False) + d = self._keymanager.get_key(from_address, fetch_remote=False) d.addCallback(attach_key) return d @@ -348,8 +346,7 @@ class OutgoingMail(object): msg.attach(keymsg) return msg - d = self._keymanager.get_key(to_address, OpenPGPKey, - fetch_remote=False) + d = self._keymanager.get_key(to_address, fetch_remote=False) d.addCallbacks(attach_if_address_hasnt_encrypted, get_key_and_attach) d.addErrback(lambda _: origmsg) return d @@ -375,7 +372,7 @@ class OutgoingMail(object): newmsg, origmsg = res d = self._keymanager.encrypt( origmsg.as_string(unixfrom=False), - encrypt_address, OpenPGPKey, sign=sign_address) + encrypt_address, sign=sign_address) d.addCallback(lambda encstr: (newmsg, encstr)) return d @@ -440,7 +437,7 @@ class OutgoingMail(object): MultipartSigned('application/pgp-signature', 'pgp-sha512'), sign_address) ds = self._keymanager.sign( - msgtext, sign_address, OpenPGPKey, digest_algo='SHA512', + msgtext, sign_address, digest_algo='SHA512', clearsign=False, detach=True, binary=False) d = defer.gatherResults([dh, ds]) d.addCallback(create_signed_message) @@ -512,6 +509,6 @@ class OutgoingMail(object): preference='signencrypt') return newmsg, origmsg - d = self._keymanager.get_key(sign_address, OpenPGPKey, private=True) + d = self._keymanager.get_key(sign_address, private=True) d.addCallback(add_openpgp_header) return d diff --git a/mail/src/leap/mail/outgoing/tests/test_outgoing.py b/mail/src/leap/mail/outgoing/tests/test_outgoing.py index ad7803d3..12a72a70 100644 --- a/mail/src/leap/mail/outgoing/tests/test_outgoing.py +++ b/mail/src/leap/mail/outgoing/tests/test_outgoing.py @@ -35,7 +35,7 @@ from leap.mail.tests import TestCaseWithKeyManager from leap.mail.tests import ADDRESS, ADDRESS_2, PUBLIC_KEY_2 from leap.mail.smtp.tests.test_gateway import getSMTPFactory -from leap.keymanager import openpgp, errors +from leap.keymanager import errors BEGIN_PUBLIC_KEY = "-----BEGIN PGP PUBLIC KEY BLOCK-----" @@ -101,7 +101,7 @@ class TestOutgoingMail(TestCaseWithKeyManager): self.outgoing_mail._maybe_encrypt_and_sign(self.raw, self.dest)) d.addCallback(self._assert_encrypted) d.addCallback(lambda message: self._km.decrypt( - message.get_payload(1).get_payload(), ADDRESS, openpgp.OpenPGPKey)) + message.get_payload(1).get_payload(), ADDRESS)) d.addCallback(check_decryption) return d @@ -125,8 +125,7 @@ class TestOutgoingMail(TestCaseWithKeyManager): self.outgoing_mail._maybe_encrypt_and_sign(self.raw, self.dest)) d.addCallback(self._assert_encrypted) d.addCallback(lambda message: self._km.decrypt( - message.get_payload(1).get_payload(), ADDRESS, openpgp.OpenPGPKey, - verify=ADDRESS_2)) + message.get_payload(1).get_payload(), ADDRESS, verify=ADDRESS_2)) d.addCallback(check_decryption_and_verify) return d @@ -181,7 +180,7 @@ class TestOutgoingMail(TestCaseWithKeyManager): 'Signature could not be verified.') d = self._km.verify( - signed_text, ADDRESS_2, openpgp.OpenPGPKey, + signed_text, ADDRESS_2, detached_sig=message.get_payload(1).get_payload()) d.addCallback(assert_verify) return d @@ -196,7 +195,7 @@ class TestOutgoingMail(TestCaseWithKeyManager): d.addCallback(self._assert_encrypted) d.addCallback(self._check_headers, self.lines[:4]) d.addCallback(lambda message: self._km.decrypt( - message.get_payload(1).get_payload(), ADDRESS, openpgp.OpenPGPKey)) + message.get_payload(1).get_payload(), ADDRESS)) d.addCallback(lambda (decrypted, _): self._check_key_attachment(Parser().parsestr(decrypted))) return d @@ -238,7 +237,7 @@ class TestOutgoingMail(TestCaseWithKeyManager): key.sign_used = True return self._km.put_key(key) - d = self._km.get_key(address, openpgp.OpenPGPKey, fetch_remote=False) + d = self._km.get_key(address, fetch_remote=False) d.addCallback(set_sign) return d diff --git a/mail/src/leap/mail/smtp/gateway.py b/mail/src/leap/mail/smtp/gateway.py index bd0be6fc..74676089 100644 --- a/mail/src/leap/mail/smtp/gateway.py +++ b/mail/src/leap/mail/smtp/gateway.py @@ -48,7 +48,6 @@ from leap.mail.utils import validate_address from leap.mail.rfc3156 import RFC3156CompliantGenerator from leap.mail.outgoing.service import outgoingFactory from leap.mail.smtp.bounces import bouncerFactory -from leap.keymanager.openpgp import OpenPGPKey from leap.keymanager.errors import KeyNotFound # replace email generator with a RFC 3156 compliant one. @@ -321,7 +320,7 @@ class SMTPDelivery(object): def encrypt_func(_): return lambda: EncryptedMessage(user, self._outgoing_mail) - d = self._km.get_key(address, OpenPGPKey) + d = self._km.get_key(address) d.addCallbacks(found, not_found) d.addCallback(encrypt_func) return d diff --git a/mail/src/leap/mail/smtp/tests/test_gateway.py b/mail/src/leap/mail/smtp/tests/test_gateway.py index df83cf04..de31e110 100644 --- a/mail/src/leap/mail/smtp/tests/test_gateway.py +++ b/mail/src/leap/mail/smtp/tests/test_gateway.py @@ -147,7 +147,7 @@ class TestSmtpGateway(TestCaseWithKeyManager): True. """ # remove key from key manager - pubkey = yield self._km.get_key(ADDRESS, openpgp.OpenPGPKey) + pubkey = yield self._km.get_key(ADDRESS) pgp = openpgp.OpenPGPScheme( self._soledad, gpgbinary=self.GPG_BINARY_PATH) yield pgp.delete_key(pubkey) @@ -178,7 +178,7 @@ class TestSmtpGateway(TestCaseWithKeyManager): False. """ # remove key from key manager - pubkey = yield self._km.get_key(ADDRESS, openpgp.OpenPGPKey) + pubkey = yield self._km.get_key(ADDRESS) pgp = openpgp.OpenPGPScheme( self._soledad, gpgbinary=self.GPG_BINARY_PATH) yield pgp.delete_key(pubkey) diff --git a/mail/src/leap/mail/tests/__init__.py b/mail/src/leap/mail/tests/__init__.py index 8094c116..5493d43c 100644 --- a/mail/src/leap/mail/tests/__init__.py +++ b/mail/src/leap/mail/tests/__init__.py @@ -26,7 +26,6 @@ from twisted.trial import unittest from leap.soledad.client import Soledad from leap.keymanager import KeyManager -from leap.keymanager.openpgp import OpenPGPKey from leap.common.testing.basetest import BaseLeapTest @@ -97,8 +96,8 @@ class TestCaseWithKeyManager(unittest.TestCase, BaseLeapTest): self._km._async_client.request = Mock(return_value="") self._km._async_client_pinned.request = Mock(return_value="") - d1 = self._km.put_raw_key(PRIVATE_KEY, OpenPGPKey, ADDRESS) - d2 = self._km.put_raw_key(PRIVATE_KEY_2, OpenPGPKey, ADDRESS_2) + d1 = self._km.put_raw_key(PRIVATE_KEY, ADDRESS) + d2 = self._km.put_raw_key(PRIVATE_KEY_2, ADDRESS_2) return gatherResults([d1, d2]) def tearDown(self): -- cgit v1.2.3