diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/leap/mail/imap/fetch.py | 3 | ||||
-rw-r--r-- | src/leap/mail/smtp/smtprelay.py | 13 | ||||
-rw-r--r-- | src/leap/mail/smtp/tests/__init__.py | 12 | ||||
-rw-r--r-- | src/leap/mail/smtp/tests/test_smtprelay.py | 18 |
4 files changed, 24 insertions, 22 deletions
diff --git a/src/leap/mail/imap/fetch.py b/src/leap/mail/imap/fetch.py index 44b3124..f20c996 100644 --- a/src/leap/mail/imap/fetch.py +++ b/src/leap/mail/imap/fetch.py @@ -8,7 +8,6 @@ from twisted.internet.task import LoopingCall from twisted.internet.threads import deferToThread from leap.common.check import leap_assert, leap_assert_type -from leap.keymanager import openpgp from leap.soledad import Soledad logger = logging.getLogger(__name__) @@ -134,7 +133,7 @@ class LeapIncomingMail(object): def _decrypt_msg(self, doc, encdata): log.msg('decrypting msg') key = self._pkey - decrdata = (openpgp.decrypt_asym( + decrdata = (self._keymanager.decrypt( encdata, key, # XXX get from public method instead passphrase=self._soledad._passphrase)) diff --git a/src/leap/mail/smtp/smtprelay.py b/src/leap/mail/smtp/smtprelay.py index e5a5614..5211d8e 100644 --- a/src/leap/mail/smtp/smtprelay.py +++ b/src/leap/mail/smtp/smtprelay.py @@ -34,11 +34,7 @@ from email.parser import Parser from leap.common.check import leap_assert, leap_assert_type from leap.keymanager import KeyManager -from leap.keymanager.openpgp import ( - OpenPGPKey, - encrypt_asym, - sign, -) +from leap.keymanager.openpgp import OpenPGPKey from leap.keymanager.errors import KeyNotFound @@ -296,12 +292,13 @@ class CtxFactory(ssl.ClientContextFactory): self.key = key def getContext(self): - self.method = SSL.TLSv1_METHOD #SSLv23_METHOD + self.method = SSL.TLSv1_METHOD # SSLv23_METHOD ctx = ssl.ClientContextFactory.getContext(self) ctx.use_certificate_file(self.cert) ctx.use_privatekey_file(self.key) return ctx + class EncryptedMessage(object): """ Receive plaintext from client, encrypt it and send message to a @@ -453,7 +450,7 @@ class EncryptedMessage(object): """ if message.is_multipart() is False: message.set_payload( - encrypt_asym( + self._km.encrypt( message.get_payload(), pubkey, sign=signkey)) else: for msg in message.get_payload(): @@ -472,7 +469,7 @@ class EncryptedMessage(object): """ if message.is_multipart() is False: message.set_payload( - sign( + self._km.sign( message.get_payload(), signkey)) else: for msg in message.get_payload(): diff --git a/src/leap/mail/smtp/tests/__init__.py b/src/leap/mail/smtp/tests/__init__.py index 73c9421..d952405 100644 --- a/src/leap/mail/smtp/tests/__init__.py +++ b/src/leap/mail/smtp/tests/__init__.py @@ -41,6 +41,8 @@ from leap.common.testing.basetest import BaseLeapTest class TestCaseWithKeyManager(BaseLeapTest): + GPG_BINARY_PATH = '/usr/bin/gpg' + def setUp(self): # mimic BaseLeapTest.setUpClass behaviour, because this is deprecated # in Twisted: http://twistedmatrix.com/trac/ticket/1870 @@ -110,7 +112,9 @@ class TestCaseWithKeyManager(BaseLeapTest): 'port': 25, 'username': address, 'password': '<password>', - 'encrypted_only': True + 'encrypted_only': True, + 'cert': 'blah', + 'key': 'bleh', } class Response(object): @@ -125,12 +129,13 @@ class TestCaseWithKeyManager(BaseLeapTest): nickserver_url = '' # the url of the nickserver km = KeyManager(address, nickserver_url, self._soledad, - ca_cert_path='') + ca_cert_path='', gpgbinary=self.GPG_BINARY_PATH) km._fetcher.put = Mock() km._fetcher.get = Mock(return_value=Response()) # insert test keys in key manager. - pgp = openpgp.OpenPGPScheme(self._soledad) + pgp = openpgp.OpenPGPScheme( + self._soledad, gpgbinary=self.GPG_BINARY_PATH) pgp.put_ascii_key(PRIVATE_KEY) pgp.put_ascii_key(PRIVATE_KEY_2) @@ -371,4 +376,3 @@ THx7N776fcYHGumbqUMYrxrcZSbNveE6SaK8fphRam1dewM0 =a5gs -----END PGP PRIVATE KEY BLOCK----- """ - diff --git a/src/leap/mail/smtp/tests/test_smtprelay.py b/src/leap/mail/smtp/tests/test_smtprelay.py index 65c4558..a529c93 100644 --- a/src/leap/mail/smtp/tests/test_smtprelay.py +++ b/src/leap/mail/smtp/tests/test_smtprelay.py @@ -83,14 +83,14 @@ class TestSmtpRelay(TestCaseWithKeyManager): text = "simple raw text" pubkey = self._km.get_key( ADDRESS, openpgp.OpenPGPKey, private=False) - encrypted = openpgp.encrypt_asym(text, pubkey) + encrypted = self._km.encrypt(text, pubkey) self.assertNotEqual( text, encrypted, "Ciphertext is equal to plaintext.") privkey = self._km.get_key( ADDRESS, openpgp.OpenPGPKey, private=True) - decrypted = openpgp.decrypt_asym(encrypted, privkey) + decrypted = self._km.decrypt(encrypted, privkey) self.assertEqual(text, decrypted, - "Decrypted text differs from plaintext.") + "Decrypted text differs from plaintext.") def test_relay_accepts_valid_email(self): """ @@ -129,7 +129,7 @@ class TestSmtpRelay(TestCaseWithKeyManager): m.eomReceived() privkey = self._km.get_key( ADDRESS, openpgp.OpenPGPKey, private=True) - decrypted = openpgp.decrypt_asym(m._message.get_payload(), privkey) + decrypted = self._km.decrypt(m._message.get_payload(), privkey) self.assertEqual( '\r\n'.join(self.EMAIL_DATA[9:12]) + '\r\n', decrypted, @@ -153,7 +153,7 @@ class TestSmtpRelay(TestCaseWithKeyManager): privkey = self._km.get_key( ADDRESS, openpgp.OpenPGPKey, private=True) pubkey = self._km.get_key(ADDRESS_2, openpgp.OpenPGPKey) - decrypted = openpgp.decrypt_asym( + decrypted = self._km.decrypt( m._message.get_payload(), privkey, verify=pubkey) self.assertEqual( '\r\n'.join(self.EMAIL_DATA[9:12]) + '\r\n', @@ -190,7 +190,7 @@ class TestSmtpRelay(TestCaseWithKeyManager): # assert signature is valid pubkey = self._km.get_key(ADDRESS_2, openpgp.OpenPGPKey) self.assertTrue( - openpgp.verify(m._message.get_payload(), pubkey), + self._km.verify(m._message.get_payload(), pubkey), 'Signature could not be verified.') def test_missing_key_rejects_address(self): @@ -200,7 +200,8 @@ class TestSmtpRelay(TestCaseWithKeyManager): """ # remove key from key manager pubkey = self._km.get_key(ADDRESS, openpgp.OpenPGPKey) - pgp = openpgp.OpenPGPScheme(self._soledad) + pgp = openpgp.OpenPGPScheme( + self._soledad, gpgbinary=self.GPG_BINARY_PATH) pgp.delete_key(pubkey) # mock the key fetching self._km.fetch_keys_from_server = Mock(return_value=[]) @@ -226,7 +227,8 @@ class TestSmtpRelay(TestCaseWithKeyManager): """ # remove key from key manager pubkey = self._km.get_key(ADDRESS, openpgp.OpenPGPKey) - pgp = openpgp.OpenPGPScheme(self._soledad) + pgp = openpgp.OpenPGPScheme( + self._soledad, gpgbinary=self.GPG_BINARY_PATH) pgp.delete_key(pubkey) # mock the key fetching self._km.fetch_keys_from_server = Mock(return_value=[]) |