Skip to content

Commit

Permalink
Merge pull request #1252 from pazz/update-envelope-keys
Browse files Browse the repository at this point in the history
fix: automatically update envelope gpg keys only if requested. see #1228
  • Loading branch information
dcbaker committed Jul 24, 2018
2 parents fd7ff0d + 70010c0 commit 62b7781
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
8 changes: 4 additions & 4 deletions alot/commands/envelope.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,8 +427,8 @@ def apply(self, ui):
# Currently we don't handle bcc because it creates a side channel leak,
# as the key of the person BCC'd will be available to other recievers,
# defeating the purpose of BCCing them
if self.key.lower() in ['to', 'from', 'cc']:
yield utils.set_encrypt(ui, ui.current_buffer.envelope)
if self.key.lower() in ['to', 'from', 'cc'] and envelope.encrypt:
yield utils.update_keys(ui, envelope)
ui.current_buffer.rebuild()


Expand All @@ -452,7 +452,7 @@ def apply(self, ui):
# as the key of the person BCC'd will be available to other recievers,
# defeating the purpose of BCCing them
if self.key.lower() in ['to', 'from', 'cc']:
yield utils.set_encrypt(ui, ui.current_buffer.envelope)
yield utils.update_keys(ui, ui.current_buffer.envelope)
ui.current_buffer.rebuild()


Expand Down Expand Up @@ -603,7 +603,7 @@ def apply(self, ui):
tmp_key = crypto.get_key(keyid)
envelope.encrypt_keys[tmp_key.fpr] = tmp_key
else:
yield utils.set_encrypt(ui, envelope, signed_only=self.trusted)
yield utils.update_keys(ui, envelope, signed_only=self.trusted)
envelope.encrypt = encrypt
if not envelope.encrypt:
# This is an extra conditional as it can even happen if encrypt is
Expand Down
6 changes: 3 additions & 3 deletions alot/commands/globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

from . import Command, registerCommand
from . import CommandCanceled
from .utils import set_encrypt
from .utils import update_keys
from .. import commands

from .. import buffers
Expand Down Expand Up @@ -916,12 +916,12 @@ def apply(self, ui):
logging.debug("Trying to encrypt message because encrypt=%s and "
"encrypt_by_default=%s", self.encrypt,
account.encrypt_by_default)
yield set_encrypt(ui, self.envelope, block_error=self.encrypt)
yield update_keys(ui, self.envelope, block_error=self.encrypt)
elif account.encrypt_by_default == u"trusted":
logging.debug("Trying to encrypt message because "
"account.encrypt_by_default=%s",
account.encrypt_by_default)
yield set_encrypt(ui, self.envelope, block_error=self.encrypt,
yield update_keys(ui, self.envelope, block_error=self.encrypt,
signed_only=True)
else:
logging.debug("No encryption by default, encrypt_by_default=%s",
Expand Down
2 changes: 1 addition & 1 deletion alot/commands/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@


@inlineCallbacks
def set_encrypt(ui, envelope, block_error=False, signed_only=False):
def update_keys(ui, envelope, block_error=False, signed_only=False):
"""Find and set the encryption keys in an envolope.
:param ui: the main user interface object
Expand Down
12 changes: 6 additions & 6 deletions tests/commands/utils_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def test_get_keys_from_to(self):
ui = utilities.make_ui()
envelope = Envelope()
envelope['To'] = 'ambig@example.com, test@example.com'
yield utils.set_encrypt(ui, envelope)
yield utils.update_keys(ui, envelope)
self.assertTrue(envelope.encrypt)
self.assertCountEqual(
[f.fpr for f in envelope.encrypt_keys.values()],
Expand All @@ -151,7 +151,7 @@ def test_get_keys_from_cc(self):
ui = utilities.make_ui()
envelope = Envelope()
envelope['Cc'] = 'ambig@example.com, test@example.com'
yield utils.set_encrypt(ui, envelope)
yield utils.update_keys(ui, envelope)
self.assertTrue(envelope.encrypt)
self.assertCountEqual(
[f.fpr for f in envelope.encrypt_keys.values()],
Expand All @@ -162,7 +162,7 @@ def test_get_partial_keys(self):
ui = utilities.make_ui()
envelope = Envelope()
envelope['Cc'] = 'foo@example.com, test@example.com'
yield utils.set_encrypt(ui, envelope)
yield utils.update_keys(ui, envelope)
self.assertTrue(envelope.encrypt)
self.assertCountEqual(
[f.fpr for f in envelope.encrypt_keys.values()],
Expand All @@ -173,7 +173,7 @@ def test_get_no_keys(self):
ui = utilities.make_ui()
envelope = Envelope()
envelope['To'] = 'foo@example.com'
yield utils.set_encrypt(ui, envelope)
yield utils.update_keys(ui, envelope)
self.assertFalse(envelope.encrypt)
self.assertEqual(envelope.encrypt_keys, {})

Expand All @@ -187,7 +187,7 @@ def test_encrypt_to_self_true(self):
account = _Account(encrypt_to_self=True, gpg_key=gpg_key)
with mock.patch('alot.commands.thread.settings.get_account_by_address',
mock.Mock(return_value=account)):
yield utils.set_encrypt(ui, envelope)
yield utils.update_keys(ui, envelope)
self.assertTrue(envelope.encrypt)
self.assertIn(FPR, envelope.encrypt_keys)
self.assertEqual(gpg_key, envelope.encrypt_keys[FPR])
Expand All @@ -202,6 +202,6 @@ def test_encrypt_to_self_false(self):
account = _Account(encrypt_to_self=False, gpg_key=gpg_key)
with mock.patch('alot.commands.thread.settings.get_account_by_address',
mock.Mock(return_value=account)):
yield utils.set_encrypt(ui, envelope)
yield utils.update_keys(ui, envelope)
self.assertTrue(envelope.encrypt)
self.assertNotIn(FPR, envelope.encrypt_keys)

0 comments on commit 62b7781

Please sign in to comment.