aboutsummaryrefslogtreecommitdiff
path: root/src/mailman_pgp/rules/signature.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/mailman_pgp/rules/signature.py')
-rw-r--r--src/mailman_pgp/rules/signature.py26
1 files changed, 18 insertions, 8 deletions
diff --git a/src/mailman_pgp/rules/signature.py b/src/mailman_pgp/rules/signature.py
index c40de32..c8ef62d 100644
--- a/src/mailman_pgp/rules/signature.py
+++ b/src/mailman_pgp/rules/signature.py
@@ -17,6 +17,7 @@
"""Signature checking rule for the pgp-posting-chain."""
import logging
+from email.utils import parseaddr
from mailman.core.i18n import _
from mailman.interfaces.action import Action
@@ -29,6 +30,7 @@ from zope.interface import implementer
from mailman_pgp.database import query
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
log = logging.getLogger('mailman.plugin.pgp')
@@ -57,7 +59,13 @@ class Signature:
# Find the `PGPMailingList` this is for.
pgp_list = PGPMailingList.for_list(mlist)
if pgp_list is None:
- raise ValueError('PGP enabled mailing list not found.')
+ return False
+
+ # Find sender
+ display_name, email = parseaddr(msg['from'])
+ # Address could be None or the empty string.
+ if not email:
+ email = msg.sender
# Wrap the message to work with it.
wrapped = PGPWrapper(msg)
@@ -66,7 +74,7 @@ class Signature:
if not wrapped.is_signed():
action = pgp_list.unsigned_msg_action
if action != Action.defer:
- record_action(msg, msgdata, action, msg.sender,
+ record_action(msg, msgdata, action, email,
'The message is unsigned.')
return True
@@ -74,28 +82,30 @@ class Signature:
if wrapped.inline.is_signed():
action = pgp_list.inline_pgp_action
if action != Action.defer:
- record_action(msg, msgdata, action, msg.sender,
+ record_action(msg, msgdata, action, email,
'Inline PGP is not allowed.')
return True
# Lookup the address by sender, and its corresponding `PGPAddress`.
user_manager = getUtility(IUserManager)
- sender = msg.sender
- address = user_manager.get_address(sender)
+ address = user_manager.get_address(email)
pgp_address = PGPAddress.for_address(address)
if pgp_address is None:
- raise ValueError('PGP enabled address not found.')
+ # Just let it continue.
+ return False
# See if we have a key.
key = pgp_address.key
if key is None:
- raise ValueError('No key?')
+ record_action(msg, msgdata, Action.reject, email,
+ 'No key set for address {}.'.format(email))
+ return True
# Take the `invalid_sig_action` if the verification failed.
if not wrapped.verifies(key):
action = pgp_list.invalid_sig_action
if action != Action.defer:
- record_action(msg, msgdata, action, msg.sender,
+ record_action(msg, msgdata, action, email,
'Signature did not verify.')
return True