diff options
| author | J08nY | 2017-06-22 14:16:15 +0200 |
|---|---|---|
| committer | J08nY | 2017-06-22 14:16:15 +0200 |
| commit | 1683c0e288d65d2cb99c118a98f8b581ebd492dc (patch) | |
| tree | d94e5f3c515db42920c79aeff7f5b20049f4301c | |
| parent | 2da30c19dbb5b3bac05d7db759091dd16447aa01 (diff) | |
| download | mailman-pgp-1683c0e288d65d2cb99c118a98f8b581ebd492dc.tar.gz mailman-pgp-1683c0e288d65d2cb99c118a98f8b581ebd492dc.tar.zst mailman-pgp-1683c0e288d65d2cb99c118a98f8b581ebd492dc.zip | |
| -rw-r--r-- | src/mailman_pgp/chains/__init__.py | 0 | ||||
| -rw-r--r-- | src/mailman_pgp/chains/default.py | 48 | ||||
| -rw-r--r-- | src/mailman_pgp/model/list.py | 13 | ||||
| -rw-r--r-- | src/mailman_pgp/rules/__init__.py | 0 | ||||
| -rw-r--r-- | src/mailman_pgp/rules/signature.py | 70 | ||||
| -rw-r--r-- | src/mailman_pgp/styles/base.py | 1 | ||||
| -rw-r--r-- | tox.ini | 1 |
7 files changed, 131 insertions, 2 deletions
diff --git a/src/mailman_pgp/chains/__init__.py b/src/mailman_pgp/chains/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/mailman_pgp/chains/__init__.py diff --git a/src/mailman_pgp/chains/default.py b/src/mailman_pgp/chains/default.py new file mode 100644 index 0000000..27ee190 --- /dev/null +++ b/src/mailman_pgp/chains/default.py @@ -0,0 +1,48 @@ +# 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/>. + +"""""" +from mailman.chains.base import Link +from mailman.core.i18n import _ +from mailman.interfaces.chain import IChain, LinkAction +from public import public +from zope.interface import implementer + + +@public +@implementer(IChain) +class EncryptedChain: + """Default encrypted chain.""" + + name = 'encrypted-posting-chain' + description = _('The encrypted moderation chain.') + + _link_descriptions = ( + ('signature', LinkAction.jump, 'moderation'), + ('truth', LinkAction.jump, 'default-posting-chain') + ) + + def __init__(self): + self._cached_links = None + + def get_links(self, mlist, msg, msgdata): + """See `IChain`.""" + if self._cached_links is None: + self._cached_links = links = [] + for rule, action, chain in self._link_descriptions: + links.append(Link(rule, action, chain)) + return iter(self._cached_links) diff --git a/src/mailman_pgp/model/list.py b/src/mailman_pgp/model/list.py index 247d263..4a25f0a 100644 --- a/src/mailman_pgp/model/list.py +++ b/src/mailman_pgp/model/list.py @@ -39,11 +39,20 @@ class EncryptedMailingList(Base): id = Column(Integer, primary_key=True) list_id = Column(SAUnicode, index=True) + + # Signature related properties unsigned_msg_action = Column(Enum(Action)) - nonencrypted_msg_action = Column(Enum(Action)) - strip_original_signature = Column(Boolean) + inline_pgp_action = Column(Enum(Action)) + expired_sig_action = Column(Enum(Action)) + revoked_sig_action = Column(Enum(Action)) + # duplicate_sig_action = Column(Enum(Action)) + invalid_sig_action = Column(Enum(Action)) + strip_original_sig = Column(Boolean) sign_outgoing = Column(Boolean) + # Encryption related properties + nonencrypted_msg_action = Column(Enum(Action)) + def __init__(self, mlist): super().__init__() self.list_id = mlist.list_id diff --git a/src/mailman_pgp/rules/__init__.py b/src/mailman_pgp/rules/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/mailman_pgp/rules/__init__.py diff --git a/src/mailman_pgp/rules/signature.py b/src/mailman_pgp/rules/signature.py new file mode 100644 index 0000000..28d05e4 --- /dev/null +++ b/src/mailman_pgp/rules/signature.py @@ -0,0 +1,70 @@ +# 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/>. + +"""""" + +from mailman.core.i18n import _ +from mailman.interfaces.rules import IRule +from public import public +from zope.interface import implementer + +from mailman_pgp.database import query +from mailman_pgp.model.list import EncryptedMailingList +from mailman_pgp.pgp.wrapper import PGPWrapper + + +@public +@implementer(IRule) +class Signature: + """""" + + name = 'signature' + + description = _( + """ + """) + + record = True + + def _record_action(self, msgdata, action, sender, reason): + msgdata['moderation_action'] = action + msgdata['moderation_sender'] = sender + msgdata.setdefault('moderation_reasons', []).append(reason) + + def check(self, mlist, msg, msgdata): + """See `IRule`.""" + enc_list = query(EncryptedMailingList).filter_by( + list_id=mlist.list_id).first() + if enc_list is None: + raise ValueError('Encrypted mailing list not found.') + wrapped = PGPWrapper(msg) + + if not wrapped.is_signed(): + action = enc_list.unsigned_msg_action + if action is not None: + self._record_action(msgdata, action, msg.sender, + 'The message is unsigned.') + return True + + if wrapped.is_inline_signed(): + action = enc_list.inline_pgp_action + if action is not None: + self._record_action(msgdata, action, msg.sender, + 'Inline PGP is not allowed.') + return True + + # TODO finish this
\ No newline at end of file diff --git a/src/mailman_pgp/styles/base.py b/src/mailman_pgp/styles/base.py index 6637ef5..f08674c 100644 --- a/src/mailman_pgp/styles/base.py +++ b/src/mailman_pgp/styles/base.py @@ -38,3 +38,4 @@ class EncryptedStyle: enc_list = EncryptedMailingList(mailing_list) with transaction(): config.db.session.add(enc_list) + mailing_list.posting_chain = 'encrypted-posting-chain' @@ -23,6 +23,7 @@ commands = deps = flake8>3.0 flake8-import-order + # This is ugly, but necessary due to the requirement on dev version of Mailman git+https://gitlab.com/mailman/mailman.git git+https://github.com/SecurityInnovation/PGPy |
