aboutsummaryrefslogtreecommitdiff
path: root/src/mailman_pgp/commands
diff options
context:
space:
mode:
Diffstat (limited to 'src/mailman_pgp/commands')
-rw-r--r--src/mailman_pgp/commands/eml_key.py38
-rw-r--r--src/mailman_pgp/commands/tests/test_key.py154
2 files changed, 73 insertions, 119 deletions
diff --git a/src/mailman_pgp/commands/eml_key.py b/src/mailman_pgp/commands/eml_key.py
index c42415d..6b3dbd6 100644
--- a/src/mailman_pgp/commands/eml_key.py
+++ b/src/mailman_pgp/commands/eml_key.py
@@ -65,10 +65,9 @@ def _cmd_set(pgp_list, mlist, msg, msgdata, arguments, results):
print('Missing token.', file=results)
return ContinueProcessing.no
- wrapped = PGPWrapper(msg)
+ wrapped = PGPWrapper(msg, True)
if wrapped.is_encrypted():
- decrypted = wrapped.try_decrypt(pgp_list.key)
- wrapped = PGPWrapper(decrypted)
+ wrapped.try_decrypt(pgp_list.key)
if not wrapped.has_keys():
print('No keys attached? Send a key.', file=results)
@@ -154,10 +153,9 @@ def _cmd_confirm(pgp_list, mlist, msg, msgdata, arguments, results):
print('No key set.', file=results)
return ContinueProcessing.no
- wrapped = PGPWrapper(msg)
+ wrapped = PGPWrapper(msg, True)
if wrapped.is_encrypted():
- decrypted = wrapped.try_decrypt(pgp_list.key)
- wrapped = PGPWrapper(decrypted)
+ wrapped.try_decrypt(pgp_list.key)
if not wrapped.is_signed():
print('Message not signed, ignoring.', file=results)
@@ -226,10 +224,9 @@ def _cmd_change(pgp_list, mlist, msg, msgdata, arguments, results):
print('Your key is currently not confirmed.', file=results)
return ContinueProcessing.no
- wrapped = PGPWrapper(msg)
+ wrapped = PGPWrapper(msg, True)
if wrapped.is_encrypted():
- decrypted = wrapped.try_decrypt(pgp_list.key)
- wrapped = PGPWrapper(decrypted)
+ wrapped.try_decrypt(pgp_list.key)
if not wrapped.has_keys():
print('No keys attached? Send a key.', file=results)
@@ -294,10 +291,9 @@ def _cmd_revoke(pgp_list, mlist, msg, msgdata, arguments, results):
print('Your key is currently not confirmed.', file=results)
return ContinueProcessing.no
- wrapped = PGPWrapper(msg)
+ wrapped = PGPWrapper(msg, True)
if wrapped.is_encrypted():
- decrypted = wrapped.try_decrypt(pgp_list.key)
- wrapped = PGPWrapper(decrypted)
+ wrapped.try_decrypt(pgp_list.key)
if not wrapped.has_revocs():
print('No key revocations attached? Send a key revocation.',
@@ -378,10 +374,9 @@ def _cmd_sign(pgp_list, mlist, msg, msgdata, arguments, results):
print('Your key is currently not confirmed.', file=results)
return ContinueProcessing.no
- wrapped = PGPWrapper(msg)
+ wrapped = PGPWrapper(msg, True)
if wrapped.is_encrypted():
- decrypted = wrapped.try_decrypt(pgp_list.key)
- wrapped = PGPWrapper(decrypted)
+ wrapped.try_decrypt(pgp_list.key)
if not wrapped.has_keys():
print('No keys attached? Send a key.', file=results)
@@ -434,15 +429,14 @@ def _cmd_receive(pgp_list, mlist, msg, msgdata, arguments, results):
print('No email to send list public key.', file=results)
return ContinueProcessing.no
- msg = UserNotification(email, mlist.request_address,
+ out = UserNotification(email, mlist.request_address,
'{} public key'.format(mlist.fqdn_listname))
- msg.set_type('multipart/mixed')
- msg['MIME-Version'] = '1.0'
- msg.attach(MIMEText('Here is the public key you requested.'))
- wrapped = MIMEWrapper(msg)
- msg = wrapped.attach_keys(pgp_list.pubkey)
+ out.set_type('multipart/mixed')
+ out['MIME-Version'] = '1.0'
+ out.attach(MIMEText('Here is the public key you requested.'))
+ MIMEWrapper(out).attach_keys(pgp_list.pubkey)
- msg.send(mlist)
+ out.send(mlist)
print('Key sent.', file=results)
return ContinueProcessing.yes
diff --git a/src/mailman_pgp/commands/tests/test_key.py b/src/mailman_pgp/commands/tests/test_key.py
index 8dd6fcc..ad45373 100644
--- a/src/mailman_pgp/commands/tests/test_key.py
+++ b/src/mailman_pgp/commands/tests/test_key.py
@@ -20,7 +20,7 @@ import copy
import unittest
from mailman.app.lifecycle import create_list
-from mailman.email.message import Message
+from mailman.email.message import Message, MultipartDigestMessage
from mailman.interfaces.member import MemberRole
from mailman.interfaces.subscriptions import ISubscriptionManager
from mailman.interfaces.usermanager import IUserManager
@@ -56,11 +56,11 @@ def _create_plain(from_hdr, to_hdr, subject_hdr, payload):
def _create_mixed(from_hdr, to_hdr, subject_hdr):
- message = Message()
+ message = MultipartDigestMessage()
message['From'] = from_hdr
message['To'] = to_hdr
message['Subject'] = subject_hdr
- message.set_type('multipart/mixed')
+ message.set_payload([])
return message
@@ -141,8 +141,7 @@ class TestPreSubscription(unittest.TestCase):
set_message = _create_mixed('bart@example.com', 'test@example.com',
'Re: key set {}'.format(token))
- wrapped_set_message = MIMEWrapper(set_message)
- set_message = wrapped_set_message.attach_keys(self.bart_key.pubkey)
+ MIMEWrapper(set_message).attach_keys(self.bart_key.pubkey)
items = _run_message(set_message, 2)
@@ -179,11 +178,9 @@ class TestPreSubscription(unittest.TestCase):
set_message = _create_mixed('bart@example.com', 'test@example.com',
'Re: key set {}'.format(token))
- wrapped_set_message = MIMEWrapper(set_message)
- set_message = wrapped_set_message.attach_keys(self.bart_key.pubkey)
- wrapped_set_message = MIMEWrapper(set_message)
- set_message = wrapped_set_message.encrypt(self.pgp_list.pubkey,
- self.bart_key.pubkey)
+ MIMEWrapper(set_message).attach_keys(self.bart_key.pubkey).encrypt(
+ self.pgp_list.pubkey,
+ self.bart_key.pubkey)
items = _run_message(set_message, 2)
@@ -230,10 +227,8 @@ class TestPreSubscription(unittest.TestCase):
def test_set_multiple_keys(self):
set_message = _create_mixed('bart@example.com', 'test@example.com',
'Re: key set token')
- wrapped_set_message = MIMEWrapper(set_message)
- set_message = wrapped_set_message.attach_keys(self.bart_key.pubkey)
- wrapped_set_message = MIMEWrapper(set_message)
- set_message = wrapped_set_message.attach_keys(self.anne_key.pubkey)
+ MIMEWrapper(set_message).attach_keys(self.bart_key.pubkey).attach_keys(
+ self.anne_key.pubkey)
items = _run_message(set_message, 1)
results_msg = items[0].msg
@@ -244,8 +239,7 @@ class TestPreSubscription(unittest.TestCase):
def test_set_private_key(self):
set_message = _create_mixed('bart@example.com', 'test@example.com',
'Re: key set token')
- wrapped_set_message = MIMEWrapper(set_message)
- set_message = wrapped_set_message.attach_keys(self.bart_key)
+ MIMEWrapper(set_message).attach_keys(self.bart_key)
items = _run_message(set_message, 1)
results_msg = items[0].msg
@@ -256,8 +250,7 @@ class TestPreSubscription(unittest.TestCase):
def test_set_no_encrypt_key(self):
set_message = _create_mixed('bart@example.com', 'test@example.com',
'Re: key set token')
- wrapped_set_message = MIMEWrapper(set_message)
- set_message = wrapped_set_message.attach_keys(self.unusable_key.pubkey)
+ MIMEWrapper(set_message).attach_keys(self.unusable_key.pubkey)
items = _run_message(set_message, 1)
results_msg = items[0].msg
@@ -268,8 +261,7 @@ class TestPreSubscription(unittest.TestCase):
def test_set_no_email(self):
message = _create_mixed('', 'test@example.com', 'key set token')
- wrapped_message = MIMEWrapper(message)
- message = wrapped_message.attach_keys(self.bart_key.pubkey)
+ MIMEWrapper(message).attach_keys(self.bart_key.pubkey)
items = _run_message(message, 1)
results_msg = items[0].msg
@@ -279,8 +271,7 @@ class TestPreSubscription(unittest.TestCase):
def test_set_no_address(self):
set_message = _create_mixed('bart@example.com', 'test@example.com',
'key set token')
- wrapped_set_message = MIMEWrapper(set_message)
- set_message = wrapped_set_message.attach_keys(self.bart_key.pubkey)
+ MIMEWrapper(set_message).attach_keys(self.bart_key.pubkey)
items = _run_message(set_message, 1)
results_msg = items[0].msg
@@ -295,8 +286,7 @@ class TestPreSubscription(unittest.TestCase):
set_message = _create_mixed('bart@example.com', 'test@example.com',
'key set token')
- wrapped_set_message = MIMEWrapper(set_message)
- set_message = wrapped_set_message.attach_keys(self.bart_key.pubkey)
+ MIMEWrapper(set_message).attach_keys(self.bart_key.pubkey)
items = _run_message(set_message, 1)
results_msg = items[0].msg
@@ -315,8 +305,7 @@ class TestPreSubscription(unittest.TestCase):
set_message = _create_mixed('bart@example.com', 'test@example.com',
'key set token')
- wrapped_set_message = MIMEWrapper(set_message)
- set_message = wrapped_set_message.attach_keys(self.bart_key.pubkey)
+ MIMEWrapper(set_message).attach_keys(self.bart_key.pubkey)
items = _run_message(set_message, 1)
results_msg = items[0].msg
@@ -339,8 +328,7 @@ class TestPreSubscription(unittest.TestCase):
CONFIRM_REQUEST.format(
self.bart_key.fingerprint,
token))
- wrapped_message = MIMEWrapper(message)
- message = wrapped_message.sign(self.bart_key)
+ MIMEWrapper(message).sign(self.bart_key)
_run_message(message)
@@ -364,10 +352,9 @@ class TestPreSubscription(unittest.TestCase):
CONFIRM_REQUEST.format(
self.bart_key.fingerprint,
token))
- wrapped_message = MIMEWrapper(message)
- message = wrapped_message.sign_encrypt(self.bart_key,
- self.pgp_list.pubkey,
- self.bart_key.pubkey)
+ MIMEWrapper(message).sign_encrypt(self.bart_key,
+ self.pgp_list.pubkey,
+ self.bart_key.pubkey)
_run_message(message)
@@ -415,8 +402,7 @@ class TestPreSubscription(unittest.TestCase):
CONFIRM_REQUEST.format(
self.bart_key.fingerprint,
'token'))
- wrapped_message = MIMEWrapper(message)
- message = wrapped_message.sign(self.bart_key)
+ MIMEWrapper(message).sign(self.bart_key)
items = _run_message(message, 1)
results_msg = items[0].msg
@@ -462,8 +448,7 @@ class TestPreSubscription(unittest.TestCase):
CONFIRM_REQUEST.format(
self.bart_key.fingerprint,
token))
- wrapped_message = MIMEWrapper(message)
- message = wrapped_message.sign(self.bart_key)
+ MIMEWrapper(message).sign(self.bart_key)
message.get_payload(0).set_payload(
'Something that was definitely not signed.')
@@ -488,8 +473,7 @@ class TestPreSubscription(unittest.TestCase):
CONFIRM_REQUEST.format(
self.bart_key.fingerprint,
'token'))
- wrapped_message = MIMEWrapper(message)
- message = wrapped_message.sign(self.bart_key)
+ MIMEWrapper(message).sign(self.bart_key)
items = _run_message(message, 1)
results_msg = items[0].msg
@@ -511,8 +495,7 @@ class TestPreSubscription(unittest.TestCase):
'Re: key confirm {}'.format(token),
'Some text, that definitely does not'
'contain the required/expected statement.')
- wrapped_message = MIMEWrapper(message)
- message = wrapped_message.sign(self.bart_key)
+ MIMEWrapper(message).sign(self.bart_key)
items = _run_message(message, 1)
results_msg = items[0].msg
@@ -561,8 +544,7 @@ class TestAfterSubscription(unittest.TestCase):
message = _create_mixed('bart@example.com', 'test@example.com',
'key change')
- wrapped_message = MIMEWrapper(message)
- message = wrapped_message.attach_keys(self.bart_new_key.pubkey)
+ MIMEWrapper(message).attach_keys(self.bart_new_key.pubkey)
items = _run_message(message, 2)
if (items[0].msg['Subject'] ==
@@ -577,8 +559,8 @@ class TestAfterSubscription(unittest.TestCase):
confirm_wrapped = PGPWrapper(confirm_request)
self.assertTrue(confirm_wrapped.is_encrypted())
- decrypted = confirm_wrapped.decrypt(self.bart_new_key)
- self.assertIn('key confirm', decrypted['subject'])
+ decrypted = confirm_wrapped.decrypt(self.bart_new_key).msg
+ self.assertIn('key confirm', str(decrypted['subject']))
def test_change_encrypted(self):
bart = getUtility(IUserManager).create_address('bart@example.com',
@@ -592,10 +574,8 @@ class TestAfterSubscription(unittest.TestCase):
message = _create_mixed('bart@example.com', 'test@example.com',
'key change')
- wrapped_message = MIMEWrapper(message)
- message = wrapped_message.attach_keys(self.bart_new_key.pubkey)
- wrapped_message = MIMEWrapper(message)
- message = wrapped_message.encrypt(self.pgp_list.pubkey)
+ MIMEWrapper(message).attach_keys(self.bart_new_key.pubkey).encrypt(
+ self.pgp_list.pubkey)
items = _run_message(message, 2)
if (items[0].msg['Subject'] ==
@@ -610,8 +590,8 @@ class TestAfterSubscription(unittest.TestCase):
confirm_wrapped = PGPWrapper(confirm_request)
self.assertTrue(confirm_wrapped.is_encrypted())
- decrypted = confirm_wrapped.decrypt(self.bart_new_key)
- self.assertIn('key confirm', decrypted['subject'])
+ decrypted = confirm_wrapped.decrypt(self.bart_new_key).msg
+ self.assertIn('key confirm', str(decrypted['subject']))
def test_change_confirm(self):
bart = getUtility(IUserManager).create_address('bart@example.com',
@@ -625,8 +605,7 @@ class TestAfterSubscription(unittest.TestCase):
message = _create_mixed('bart@example.com', 'test@example.com',
'key change')
- wrapped_message = MIMEWrapper(message)
- message = wrapped_message.attach_keys(self.bart_new_key.pubkey)
+ MIMEWrapper(message).attach_keys(self.bart_new_key.pubkey)
items = _run_message(message, 2)
if (items[0].msg['Subject'] ==
@@ -635,20 +614,19 @@ class TestAfterSubscription(unittest.TestCase):
else:
confirm_request = items[0].msg
request_wrapped = PGPWrapper(confirm_request)
- decrypted = request_wrapped.decrypt(self.bart_new_key)
+ decrypted = request_wrapped.decrypt(self.bart_new_key).msg
subj = decrypted['subject']
- token = subj.split(' ')[-1]
+ token = str(subj).split(' ')[-1]
confirm_message = _create_plain('bart@example.com', 'test@example.com',
decrypted['subject'],
CHANGE_CONFIRM_REQUEST.format(
self.bart_new_key.fingerprint,
token))
- wrapped_confirm = MIMEWrapper(confirm_message)
- confirm = wrapped_confirm.sign(self.bart_key)
+ MIMEWrapper(confirm_message).sign(self.bart_key)
- _run_message(confirm)
+ _run_message(confirm_message)
pgp_address = PGPAddress.for_address(bart)
self.assertEqual(pgp_address.key_fingerprint,
@@ -666,8 +644,7 @@ class TestAfterSubscription(unittest.TestCase):
def test_change_no_email(self):
message = _create_mixed('', 'test@example.com', 'key change')
- wrapped_message = MIMEWrapper(message)
- message = wrapped_message.attach_keys(self.bart_key.pubkey)
+ MIMEWrapper(message).attach_keys(self.bart_key.pubkey)
items = _run_message(message, 1)
results_msg = items[0].msg
@@ -677,8 +654,7 @@ class TestAfterSubscription(unittest.TestCase):
def test_change_no_pgp_address(self):
message = _create_mixed('bart@example.com', 'test@example.com',
'key change')
- wrapped_message = MIMEWrapper(message)
- message = wrapped_message.attach_keys(self.bart_key.pubkey)
+ MIMEWrapper(message).attach_keys(self.bart_key.pubkey)
items = _run_message(message, 1)
results_msg = items[0].msg
@@ -749,10 +725,8 @@ class TestAfterSubscription(unittest.TestCase):
set_message = _create_mixed('bart@example.com', 'test@example.com',
'key change')
- wrapped_set_message = MIMEWrapper(set_message)
- set_message = wrapped_set_message.attach_keys(self.bart_key.pubkey)
- wrapped_set_message = MIMEWrapper(set_message)
- set_message = wrapped_set_message.attach_keys(self.bart_new_key.pubkey)
+ MIMEWrapper(set_message).attach_keys(self.bart_key.pubkey).attach_keys(
+ self.bart_new_key.pubkey)
items = _run_message(set_message, 1)
results_msg = items[0].msg
@@ -771,8 +745,7 @@ class TestAfterSubscription(unittest.TestCase):
message = _create_mixed('bart@example.com', 'test@example.com',
'key change')
- wrapped_message = MIMEWrapper(message)
- message = wrapped_message.attach_keys(self.bart_key)
+ MIMEWrapper(message).attach_keys(self.bart_key)
items = _run_message(message, 1)
results_msg = items[0].msg
@@ -791,8 +764,7 @@ class TestAfterSubscription(unittest.TestCase):
message = _create_mixed('bart@example.com', 'test@example.com',
'key change')
- wrapped_message = MIMEWrapper(message)
- message = wrapped_message.attach_keys(self.unusable_key.pubkey)
+ MIMEWrapper(message).attach_keys(self.unusable_key.pubkey)
items = _run_message(message, 1)
results_msg = items[0].msg
@@ -814,8 +786,7 @@ class TestAfterSubscription(unittest.TestCase):
message = _create_mixed('bart@example.com', 'test@example.com',
'key revoke')
- wrapped_message = MIMEWrapper(message)
- message = wrapped_message.attach_revocs(revoc)
+ MIMEWrapper(message).attach_revocs(revoc)
items = _run_message(message, 2)
if (items[0].msg['Subject'] ==
@@ -856,8 +827,7 @@ class TestAfterSubscription(unittest.TestCase):
message = _create_mixed('bart@example.com', 'test@example.com',
'key revoke')
- wrapped_message = MIMEWrapper(message)
- message = wrapped_message.attach_revocs(revoc)
+ MIMEWrapper(message).attach_revocs(revoc)
items = _run_message(message, 1)
results_msg = items[0].msg
@@ -881,10 +851,7 @@ class TestAfterSubscription(unittest.TestCase):
message = _create_mixed('bart@example.com', 'test@example.com',
'key revoke')
- wrapped_message = MIMEWrapper(message)
- message = wrapped_message.attach_revocs(revoc)
- wrapped_message = MIMEWrapper(message)
- message = wrapped_message.encrypt(self.pgp_list.pubkey)
+ MIMEWrapper(message).attach_revocs(revoc).encrypt(self.pgp_list.pubkey)
items = _run_message(message, 2)
if (items[0].msg['Subject'] ==
@@ -991,12 +958,12 @@ class TestAfterSubscription(unittest.TestCase):
message = _create_mixed('bart@example.com', 'test@example.com',
'key sign')
- wrapped_message = MIMEWrapper(message)
+
new_key = copy.copy(self.pgp_list.pubkey)
uid = next(iter(new_key.userids))
sig = self.bart_key.certify(uid)
uid |= sig
- message = wrapped_message.attach_keys(new_key)
+ MIMEWrapper(message).attach_keys(new_key)
items = _run_message(message, 1)
results_msg = items[0].msg
@@ -1020,14 +987,12 @@ class TestAfterSubscription(unittest.TestCase):
message = _create_mixed('bart@example.com', 'test@example.com',
'key sign')
- wrapped_message = MIMEWrapper(message)
+
new_key = copy.copy(self.pgp_list.pubkey)
uid = next(iter(new_key.userids))
sig = self.bart_key.certify(uid)
uid |= sig
- message = wrapped_message.attach_keys(new_key)
- wrapped_message = MIMEWrapper(message)
- message = wrapped_message.encrypt(self.pgp_list.pubkey)
+ MIMEWrapper(message).attach_keys(new_key).encrypt(self.pgp_list.pubkey)
items = _run_message(message, 1)
results_msg = items[0].msg
@@ -1125,10 +1090,8 @@ class TestAfterSubscription(unittest.TestCase):
message = _create_mixed('bart@example.com', 'test@example.com',
'key sign')
- wrapped_message = MIMEWrapper(message)
- message = wrapped_message.attach_keys(self.bart_key.pubkey)
- wrapped_message = MIMEWrapper(message)
- message = wrapped_message.attach_keys(self.bart_new_key.pubkey)
+ MIMEWrapper(message).attach_keys(self.bart_key.pubkey).attach_keys(
+ self.bart_new_key.pubkey)
items = _run_message(message, 1)
results_msg = items[0].msg
@@ -1149,8 +1112,7 @@ class TestAfterSubscription(unittest.TestCase):
message = _create_mixed('bart@example.com', 'test@example.com',
'key sign')
- wrapped_message = MIMEWrapper(message)
- message = wrapped_message.attach_keys(self.pgp_list.pubkey)
+ MIMEWrapper(message).attach_keys(self.pgp_list.pubkey)
items = _run_message(message, 1)
results_msg = items[0].msg
@@ -1174,8 +1136,7 @@ class TestAfterSubscription(unittest.TestCase):
message = _create_mixed('bart@example.com', 'test@example.com',
'key sign')
- wrapped_message = MIMEWrapper(message)
- message = wrapped_message.attach_keys(self.bart_key.pubkey)
+ MIMEWrapper(message).attach_keys(self.bart_key.pubkey)
items = _run_message(message, 1)
results_msg = items[0].msg
@@ -1199,11 +1160,11 @@ class TestAfterSubscription(unittest.TestCase):
message = _create_mixed('bart@example.com', 'test@example.com',
'key sign')
- wrapped_message = MIMEWrapper(message)
new_key = copy.copy(self.pgp_list.pubkey)
for uid in new_key.userids:
new_key.del_uid(uid.email)
- message = wrapped_message.attach_keys(new_key)
+
+ MIMEWrapper(message).attach_keys(new_key)
items = _run_message(message, 1)
results_msg = items[0].msg
@@ -1227,8 +1188,7 @@ class TestAfterSubscription(unittest.TestCase):
message = _create_mixed('bart@example.com', 'test@example.com',
'key sign')
- wrapped_message = MIMEWrapper(message)
- message = wrapped_message.attach_keys(self.pgp_list.pubkey)
+ MIMEWrapper(message).attach_keys(self.pgp_list.pubkey)
items = _run_message(message, 1)
results_msg = items[0].msg
@@ -1252,12 +1212,12 @@ class TestAfterSubscription(unittest.TestCase):
message = _create_mixed('bart@example.com', 'test@example.com',
'key sign')
- wrapped_message = MIMEWrapper(message)
+
new_key = copy.copy(self.pgp_list.pubkey)
uid = next(iter(new_key.userids))
sig = self.bart_new_key.certify(uid)
uid |= sig
- message = wrapped_message.attach_keys(new_key)
+ MIMEWrapper(message).attach_keys(new_key)
items = _run_message(message, 1)
results_msg = items[0].msg