diff options
Diffstat (limited to 'mail')
-rw-r--r-- | mail/changes/VERSION_COMPAT | 1 | ||||
-rw-r--r-- | mail/changes/next-changelog.rst | 2 | ||||
-rw-r--r-- | mail/setup.py | 30 | ||||
-rw-r--r-- | mail/src/leap/mail/incoming/service.py | 20 | ||||
-rw-r--r-- | mail/src/leap/mail/incoming/tests/test_incoming_mail.py | 21 | ||||
-rw-r--r-- | mail/src/leap/mail/outgoing/service.py | 13 | ||||
-rw-r--r-- | mail/src/leap/mail/outgoing/tests/test_outgoing.py | 13 | ||||
-rw-r--r-- | mail/src/leap/mail/smtp/gateway.py | 3 | ||||
-rw-r--r-- | mail/src/leap/mail/smtp/tests/test_gateway.py | 4 | ||||
-rw-r--r-- | mail/src/leap/mail/tests/__init__.py | 5 |
10 files changed, 54 insertions, 58 deletions
diff --git a/mail/changes/VERSION_COMPAT b/mail/changes/VERSION_COMPAT index cc00ecf7..77a394f9 100644 --- a/mail/changes/VERSION_COMPAT +++ b/mail/changes/VERSION_COMPAT @@ -8,3 +8,4 @@ # # BEGIN DEPENDENCY LIST ------------------------- # leap.foo.bar>=x.y.z +leap.keymanager >= 0.5.2 diff --git a/mail/changes/next-changelog.rst b/mail/changes/next-changelog.rst index e04e4238..21b10103 100644 --- a/mail/changes/next-changelog.rst +++ b/mail/changes/next-changelog.rst @@ -10,6 +10,8 @@ I've added a new category `Misc` so we can track doc/style/packaging stuff. Features ~~~~~~~~ +- `#8031 <https://leap.se/code/issues/8031>`_: Adapt to the new KeyManager API without key types. + - `#1234 <https://leap.se/code/issues/1234>`_: Description of the new feature corresponding with issue #1234. - New feature without related issue number. diff --git a/mail/setup.py b/mail/setup.py index 960cea14..ede620da 100644 --- a/mail/setup.py +++ b/mail/setup.py @@ -62,6 +62,7 @@ cmdclass = versioneer.get_cmdclass() class freeze_debianver(Command): + """ Freezes the version in a debian branch. To be used after merging the development branch onto the debian one. @@ -74,14 +75,20 @@ class freeze_debianver(Command): # unpacked source archive. Distribution tarballs contain a pre-generated copy # of this file. -version_version = '{version}' -full_revisionid = '{full_revisionid}' -""" - templatefun = r""" +import json +import sys + +version_json = ''' +{ + "dirty": false, + "error": null, + "full-revisionid": "FULL_REVISIONID", + "version": "VERSION_STRING" +} +''' # END VERSION_JSON -def get_versions(default={}, verbose=False): - return {'version': version_version, - 'full-revisionid': full_revisionid} +def get_versions(): + return json.loads(version_json) """ def initialize_options(self): @@ -96,10 +103,11 @@ def get_versions(default={}, verbose=False): if proceed != "y": print("He. You scared. Aborting.") return - subst_template = self.template.format( - version=VERSION_SHORT, - version_full=VERSION_REVISION) + self.templatefun - with open(versioneer.versionfile_source, 'w') as f: + subst_template = self.template.replace( + 'VERSION_STRING', VERSION_SHORT).replace( + 'FULL_REVISIONID', VERSION_REVISION) + versioneer_cfg = versioneer.get_config_from_root('.') + with open(versioneer_cfg.versionfile_source, 'w') as f: f.write(subst_template) diff --git a/mail/src/leap/mail/incoming/service.py b/mail/src/leap/mail/incoming/service.py index 58a19c81..fea3ecb4 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)) @@ -536,8 +533,7 @@ class IncomingMail(Service): return res d = self._keymanager.decrypt( - encdata, self._userid, OpenPGPKey, - verify=senderAddress) + encdata, self._userid, verify=senderAddress) d.addCallbacks(build_msg, self._decryption_error, errbackArgs=(msg,)) d.addCallbacks(verify_signature_after_decrypt_an_email) return d @@ -581,8 +577,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: @@ -607,8 +602,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())) @@ -720,7 +714,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,))) @@ -761,9 +755,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 91f25566..0f19a6fe 100644 --- a/mail/src/leap/mail/incoming/tests/test_incoming_mail.py +++ b/mail/src/leap/mail/incoming/tests/test_incoming_mail.py @@ -32,7 +32,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 @@ -123,7 +122,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( @@ -168,7 +167,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) @@ -187,7 +186,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) @@ -211,7 +210,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()) @@ -236,9 +235,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) @@ -287,13 +286,13 @@ 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: self._do_fetch(message.as_string())) + d.addCallback(decryption_error_not_called) + d.addCallback(add_decrypted_header_called) return d def testValidateSignatureFromEncryptedEmailFromAppleMail(self): @@ -349,7 +348,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): |