aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJ08nY2017-07-10 23:43:44 +0200
committerJ08nY2017-07-10 23:43:44 +0200
commit4d98c0bcc1ee4eb7d2de38a7ae21f97f1b0c9943 (patch)
tree169225d3e034fcf733dfcc46f59839520c670a92
parent7b136683c76afae000c07f5dc54f3785b038695f (diff)
downloadmailman-pgp-4d98c0bcc1ee4eb7d2de38a7ae21f97f1b0c9943.tar.gz
mailman-pgp-4d98c0bcc1ee4eb7d2de38a7ae21f97f1b0c9943.tar.zst
mailman-pgp-4d98c0bcc1ee4eb7d2de38a7ae21f97f1b0c9943.zip
-rw-r--r--src/mailman_pgp/workflows/base.py32
-rw-r--r--src/mailman_pgp/workflows/subscription.py30
2 files changed, 46 insertions, 16 deletions
diff --git a/src/mailman_pgp/workflows/base.py b/src/mailman_pgp/workflows/base.py
index 40ff4d7..3f4ba8d 100644
--- a/src/mailman_pgp/workflows/base.py
+++ b/src/mailman_pgp/workflows/base.py
@@ -18,9 +18,11 @@
""""""
from mailman.email.message import UserNotification
from mailman.interfaces.subscriptions import TokenOwner
+from pgpy import PGPKey
from mailman_pgp.model.address import PGPAddress
from mailman_pgp.model.list import PGPMailingList
+from mailman_pgp.pgp.utils import copy_headers
from mailman_pgp.pgp.wrapper import PGPWrapper
KEY_REQUEST = """\
@@ -43,12 +45,29 @@ Token: {}
class PubkeyMixin:
- def __init__(self, pubkey=None):
+ def __init__(self, pubkey=None, pre_confirmed=False):
self.pubkey = pubkey
+ self.pubkey_confirmed = pre_confirmed
+
+ @property
+ def pubkey_key(self):
+ if self.pubkey is None:
+ return None
+ return str(self.pubkey)
+
+ @pubkey_key.setter
+ def pubkey_key(self, value):
+ if value is not None:
+ self.pubkey, _ = PGPKey.from_blob(value)
+ else:
+ self.pubkey = None
def _step_pubkey_checks(self):
if not self.pubkey:
self.push('send_key_request')
+ else:
+ if not self.pubkey_confirmed:
+ self.push('send_confirm_request')
def _step_send_key_request(self):
self._set_token(TokenOwner.subscriber)
@@ -65,14 +84,15 @@ class PubkeyMixin:
def _step_receive_key(self):
pgp_address = PGPAddress.for_address(self.address)
- if pgp_address is None or pgp_address.key:
+ if pgp_address is None or pgp_address.key is None:
# The workflow was confirmed but we still dont have an address
# or the pubkey. So resend request and wait.
self.push('send_key_request')
return
else:
self.pubkey = pgp_address.key
- self.push('send_confirm_request')
+ if not self.pubkey_confirmed:
+ self.push('send_confirm_request')
def _step_send_confirm_request(self):
self._set_token(TokenOwner.subscriber)
@@ -86,10 +106,12 @@ class PubkeyMixin:
self.token))
pgp_list = PGPMailingList.for_list(self.mlist)
wrapped = PGPWrapper(msg)
- encrypted = wrapped.encrypt(self.pubkey, pgp_list.pubkey)
+ encrypted = wrapped.sign_encrypt(pgp_list.key, self.pubkey,
+ pgp_list.pubkey)
# XXX: This is not good:
- msg.set_payload(encrypted)
+ msg.set_payload(encrypted.get_payload())
+ copy_headers(encrypted, msg, True)
msg.send(self.mlist)
raise StopIteration
diff --git a/src/mailman_pgp/workflows/subscription.py b/src/mailman_pgp/workflows/subscription.py
index a571b44..6b8240c 100644
--- a/src/mailman_pgp/workflows/subscription.py
+++ b/src/mailman_pgp/workflows/subscription.py
@@ -29,8 +29,8 @@ from mailman_pgp.workflows.base import PubkeyMixin
@public
@implementer(ISubscriptionWorkflow)
-class ConfimSubscriptionPolicy(SubscriptionBase, VerificationMixin,
- ConfirmationMixin, PubkeyMixin):
+class ConfirmSubscriptionPolicy(SubscriptionBase, VerificationMixin,
+ ConfirmationMixin, PubkeyMixin):
""""""
name = 'pgp-policy-confirm'
@@ -40,7 +40,8 @@ class ConfimSubscriptionPolicy(SubscriptionBase, VerificationMixin,
save_attributes = (
'verified',
'confirmed',
- 'pubkey',
+ 'pubkey_key',
+ 'pubkey_confirmed',
'address_key',
'subscriber_key',
'user_key',
@@ -48,11 +49,13 @@ class ConfimSubscriptionPolicy(SubscriptionBase, VerificationMixin,
)
def __init__(self, mlist, subscriber=None, *,
- pre_verified=False, pre_confirmed=False, pubkey=None):
+ pre_verified=False, pre_confirmed=False, pubkey=None,
+ pubkey_pre_confirmed=False):
SubscriptionBase.__init__(self, mlist, subscriber)
VerificationMixin.__init__(self, pre_verified=pre_verified)
ConfirmationMixin.__init__(self, pre_confirmed=pre_confirmed)
- PubkeyMixin.__init__(self, pubkey=pubkey)
+ PubkeyMixin.__init__(self, pubkey=pubkey,
+ pre_confirmed=pubkey_pre_confirmed)
def _step_prepare(self):
self.push('do_subscription')
@@ -75,7 +78,8 @@ class ModerationSubscriptionPolicy(SubscriptionBase, VerificationMixin,
save_attributes = (
'verified',
'approved',
- 'pubkey',
+ 'pubkey_key',
+ 'pubkey_confirmed',
'address_key',
'subscriber_key',
'user_key',
@@ -83,11 +87,13 @@ class ModerationSubscriptionPolicy(SubscriptionBase, VerificationMixin,
)
def __init__(self, mlist, subscriber=None, *,
- pre_verified=False, pre_approved=False, pubkey=None):
+ pre_verified=False, pre_approved=False, pubkey=None,
+ pubkey_pre_confirmed=False):
SubscriptionBase.__init__(self, mlist, subscriber)
VerificationMixin.__init__(self, pre_verified=pre_verified)
ModerationMixin.__init__(self, pre_approved=pre_approved)
- PubkeyMixin.__init__(self, pubkey=pubkey)
+ PubkeyMixin.__init__(self, pubkey=pubkey,
+ pre_confirmed=pubkey_pre_confirmed)
def _step_prepare(self):
self.push('do_subscription')
@@ -112,7 +118,8 @@ class ConfirmModerationSubscriptionPolicy(SubscriptionBase, VerificationMixin,
'verified',
'confirmed',
'approved',
- 'pubkey',
+ 'pubkey_key',
+ 'pubkey_confirmed',
'address_key',
'subscriber_key',
'user_key',
@@ -121,12 +128,13 @@ class ConfirmModerationSubscriptionPolicy(SubscriptionBase, VerificationMixin,
def __init__(self, mlist, subscriber=None, *,
pre_verified=False, pre_confirmed=False, pre_approved=False,
- pubkey=None):
+ pubkey=None, pubkey_pre_confirmed=False):
SubscriptionBase.__init__(self, mlist, subscriber)
VerificationMixin.__init__(self, pre_verified=pre_verified)
ConfirmationMixin.__init__(self, pre_confirmed=pre_confirmed)
ModerationMixin.__init__(self, pre_approved=pre_approved)
- PubkeyMixin.__init__(self, pubkey=pubkey)
+ PubkeyMixin.__init__(self, pubkey=pubkey,
+ pre_confirmed=pubkey_pre_confirmed)
def _step_prepare(self):
self.push('do_subscription')