1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
# Copyright (C) 2017 Jan Jancar
#
# This file is a part of the Mailman PGP plugin.
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along with
# this program. If not, see <http://www.gnu.org/licenses/>.
""""""
import copy
from mailman.email.message import UserNotification
from mailman.interfaces.pending import IPendings
from mailman.interfaces.subscriptions import TokenOwner
from public import public
from zope.component import getUtility
from mailman_pgp.pgp.mime import MIMEWrapper
from mailman_pgp.utils.email import overwrite_message
SUBSCRIPTION_MOD_REQUEST = """\
----------
TODO: this is a pgp enabled list.
A user with address {address} requested subscription.
The key is attached to this message.
Fingerprint: {fingerprint}
----------
"""
KEY_CHANGE_MOD_REQUEST = """\
----------
TODO: this is a pgp enabled list.
A subscriber with address {address} requested a change of his key.
The new key is attached to this message.
Old key fingerprint: {old_fpr}
New key fingerprint: {new_fpr}
----------
"""
KEY_REVOKE_MOD_REQUEST = """\
----------
TODO: this is a pgp enabled list.
A subscriber with address {address} revoked a part of his key,
which made it unusable and needs to be reset. The subscriber
supplied a new key. The new key is attached to this message.
Old key fingerprint: {old_fpr}
New key fingerprint: {new_fpr}
----------
"""
class ModeratorApprovalMixin:
def __init__(self, pre_approved=False):
self.approved = pre_approved
def _step_mod_approval(self):
if not self.approved:
self.push('get_approval')
def _step_get_approval(self):
self._pend(TokenOwner.moderator)
self.push('receive_mod_confirmation')
self.save()
name = self._request_name
body = self._request_body
if self.mlist.admin_immed_notify:
subject = 'New {} request from {}'.format(name,
self.pgp_address.email)
msg = UserNotification(
self.mlist.owner_address, self.mlist.owner_address,
subject, body, self.mlist.preferred_language)
out = copy.deepcopy(msg)
wrapped = MIMEWrapper(msg)
msg = wrapped.attach_keys(self.pubkey)
overwrite_message(msg, out)
out.send(self.mlist)
raise StopIteration
def _step_receive_mod_confirmation(self):
pendings = getUtility(IPendings)
if self.token is not None:
pendings.confirm(self.token)
self.token = None
self.token_owner = TokenOwner.no_one
@public
class ModeratorSubApprovalMixin(ModeratorApprovalMixin):
def __init__(self, pre_approved=False):
super().__init__(pre_approved)
@property
def _request_name(self):
return 'subscription'
@property
def _request_body(self):
params = {'mlist': self.mlist.fqdn_listname,
'address': self.pgp_address.email,
'fingerprint': self.pubkey.fingerprint}
return SUBSCRIPTION_MOD_REQUEST.format(**params)
@public
class ModeratorKeyChangeApprovalMixin(ModeratorApprovalMixin):
def __init__(self, pre_approved=False):
super().__init__(pre_approved)
@property
def _request_name(self):
return 'key change'
@property
def _request_body(self):
params = {'mlist': self.mlist.fqdn_listname,
'address': self.pgp_address.email,
'fingerprint': self.pubkey.fingerprint,
'old_fpr': self.pgp_address.key_fingerprint,
'new_fpr': self.pubkey.fingerprint}
return KEY_CHANGE_MOD_REQUEST.format(**params)
@public
class ModeratorKeyRevokeApprovalMixin(ModeratorApprovalMixin):
def __init__(self, pre_approved=False):
super().__init__(pre_approved)
@property
def _request_name(self):
return 'key reset'
@property
def _request_body(self):
params = {'mlist': self.mlist.fqdn_listname,
'address': self.pgp_address.email,
'fingerprint': self.pubkey.fingerprint,
'old_fpr': self.pgp_address.key_fingerprint,
'new_fpr': self.pubkey.fingerprint}
return KEY_REVOKE_MOD_REQUEST.format(**params)
|