aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/mailman_pgp/chains/default.py4
-rw-r--r--src/mailman_pgp/commands/eml_key.py18
-rw-r--r--src/mailman_pgp/rules/encryption.py2
-rw-r--r--src/mailman_pgp/rules/signature.py40
-rw-r--r--src/mailman_pgp/utils/email.py11
5 files changed, 48 insertions, 27 deletions
diff --git a/src/mailman_pgp/chains/default.py b/src/mailman_pgp/chains/default.py
index 0a833d3..314d8b8 100644
--- a/src/mailman_pgp/chains/default.py
+++ b/src/mailman_pgp/chains/default.py
@@ -33,8 +33,8 @@ class PGPChain:
description = _('The PGP enabled moderation chain.')
_link_descriptions = (
- ('encryption', LinkAction.jump, 'moderation'),
- ('signature', LinkAction.jump, 'moderation'),
+ ('pgp-encryption', LinkAction.jump, 'moderation'),
+ ('pgp-signature', LinkAction.jump, 'moderation'),
('truth', LinkAction.jump, 'default-posting-chain')
)
diff --git a/src/mailman_pgp/commands/eml_key.py b/src/mailman_pgp/commands/eml_key.py
index 9ea0384..0437430 100644
--- a/src/mailman_pgp/commands/eml_key.py
+++ b/src/mailman_pgp/commands/eml_key.py
@@ -17,7 +17,6 @@
"""The key email command."""
from email.mime.text import MIMEText
-from email.utils import parseaddr
from mailman.email.message import UserNotification
from mailman.interfaces.command import ContinueProcessing, IEmailCommand
@@ -33,19 +32,12 @@ from mailman_pgp.model.address import PGPAddress
from mailman_pgp.model.list import PGPMailingList
from mailman_pgp.pgp.mime import MIMEWrapper
from mailman_pgp.pgp.wrapper import PGPWrapper
+from mailman_pgp.utils.email import get_email
from mailman_pgp.workflows.key_change import (CHANGE_CONFIRM_REQUEST,
KeyChangeWorkflow)
from mailman_pgp.workflows.pubkey import CONFIRM_REQUEST
-def _get_email(msg):
- display_name, email = parseaddr(msg['from'])
- # Address could be None or the empty string.
- if not email:
- email = msg.sender
- return email
-
-
def _cmd_set(pgp_list, mlist, msg, msgdata, arguments, results):
"""
`key set "token"` command.
@@ -76,7 +68,7 @@ def _cmd_set(pgp_list, mlist, msg, msgdata, arguments, results):
print('More than one key! Send only one key.', file=results)
return ContinueProcessing.no
- email = _get_email(msg)
+ email = get_email(msg)
if not email:
print('No email to subscribe with.', file=results)
return ContinueProcessing.no
@@ -126,7 +118,7 @@ def _cmd_confirm(pgp_list, mlist, msg, msgdata, arguments, results):
print('Missing token.', file=results)
return ContinueProcessing.no
- email = _get_email(msg)
+ email = get_email(msg)
if not email:
print('No email to subscribe with.', file=results)
return ContinueProcessing.no
@@ -205,7 +197,7 @@ def _cmd_change(pgp_list, mlist, msg, msgdata, arguments, results):
print('More than one key! Send only one key.', file=results)
return ContinueProcessing.no
- email = _get_email(msg)
+ email = get_email(msg)
if not email:
print('No email to change key of.', file=results)
return ContinueProcessing.no
@@ -238,7 +230,7 @@ def _cmd_receive(pgp_list, mlist, msg, msgdata, arguments, results):
file=results)
return ContinueProcessing.no
- email = _get_email(msg)
+ email = get_email(msg)
if not email:
print('No email to send list public key.', file=results)
return ContinueProcessing.no
diff --git a/src/mailman_pgp/rules/encryption.py b/src/mailman_pgp/rules/encryption.py
index 8e4840d..1a14b97 100644
--- a/src/mailman_pgp/rules/encryption.py
+++ b/src/mailman_pgp/rules/encryption.py
@@ -28,7 +28,7 @@ from zope.interface import implementer
class Encryption:
"""The encryption moderation rule."""
- name = 'encryption'
+ name = 'pgp-encryption'
description = _(
"A rule which jumps to the moderation chain, "
"when the incoming runner instructs it to.")
diff --git a/src/mailman_pgp/rules/signature.py b/src/mailman_pgp/rules/signature.py
index 395dd7d..dd90a9b 100644
--- a/src/mailman_pgp/rules/signature.py
+++ b/src/mailman_pgp/rules/signature.py
@@ -16,21 +16,24 @@
# this program. If not, see <http://www.gnu.org/licenses/>.
"""Signature checking rule for the pgp-posting-chain."""
-from email.utils import parseaddr
from operator import attrgetter
from mailman.core.i18n import _
from mailman.interfaces.action import Action
+from mailman.interfaces.chain import AcceptEvent
from mailman.interfaces.rules import IRule
from mailman.interfaces.usermanager import IUserManager
from public import public
from zope.component import getUtility
+from zope.event import classhandler
from zope.interface import implementer
+from mailman_pgp.database import transaction
from mailman_pgp.model.address import PGPAddress
from mailman_pgp.model.list import PGPMailingList
from mailman_pgp.model.sighash import PGPSigHash
from mailman_pgp.pgp.wrapper import PGPWrapper
+from mailman_pgp.utils.email import get_email
from mailman_pgp.utils.moderation import record_action
from mailman_pgp.utils.pgp import hashes, verifies
@@ -40,9 +43,9 @@ from mailman_pgp.utils.pgp import hashes, verifies
class Signature:
"""The signature checking rule."""
- name = 'signature'
+ name = 'pgp-signature'
description = _(
- "A rule which enforces PGP enabled list signature configuration.")
+ 'A rule which enforces PGP enabled list signature configuration.')
record = True
def check(self, mlist, msg, msgdata):
@@ -52,12 +55,7 @@ class Signature:
if pgp_list is None:
return False
- # Find sender
- display_name, email = parseaddr(msg['from'])
- # Address could be None or the empty string.
- if not email:
- email = msg.sender
-
+ email = get_email(msg)
# Wrap the message to work with it.
wrapped = PGPWrapper(msg)
@@ -117,10 +115,30 @@ class Signature:
record_action(msg, msgdata, action, email,
'Signature duplicate.')
return True
-
- # TODO: add the sig hashes to the db.
+ msgdata['pgp_sig_hashes'] = sig_hashes
# XXX: we need to track key revocation separately to use it here
# TODO: check key revocation here
return False
+
+
+@classhandler.handler(AcceptEvent)
+def on_message_posting(event):
+ """
+ Add sig hashes to sighash table.
+
+ :param event:
+ :type event: AcceptEvent
+ """
+ pgp_list = PGPMailingList.for_list(event.mlist)
+ if pgp_list is None:
+ return
+ pgp_address = PGPAddress.for_email(get_email(event.msg))
+ if pgp_address is None or pgp_address.key_fingerprint is None:
+ return
+ for sig_hash in event.msgdata['pgp_sig_hashes']:
+ with transaction() as t:
+ pgp_hash = PGPSigHash(hash=sig_hash,
+ fingerprint=pgp_address.key_fingerprint)
+ t.add(pgp_hash)
diff --git a/src/mailman_pgp/utils/email.py b/src/mailman_pgp/utils/email.py
index 4541313..80cf83f 100644
--- a/src/mailman_pgp/utils/email.py
+++ b/src/mailman_pgp/utils/email.py
@@ -16,6 +16,8 @@
# this program. If not, see <http://www.gnu.org/licenses/>.
""""""
+from email.utils import parseaddr
+
from public import public
@@ -36,3 +38,12 @@ def copy_headers(from_msg, to_msg, overwrite=False):
to_msg[key] = value
if to_msg.get_unixfrom() is None:
to_msg.set_unixfrom(from_msg.get_unixfrom())
+
+
+@public
+def get_email(msg):
+ display_name, email = parseaddr(msg['from'])
+ # Address could be None or the empty string.
+ if not email:
+ email = msg.sender
+ return email