aboutsummaryrefslogtreecommitdiff
path: root/src/django_pgpmailman/forms.py
diff options
context:
space:
mode:
authorJ08nY2017-08-18 18:59:54 +0200
committerJ08nY2017-08-18 18:59:54 +0200
commit9d23d95ca530f5eabcd0f1c50d18dea2dc29b506 (patch)
tree850df69361e0a71bbd6596ec1b213db2a0ab1b2a /src/django_pgpmailman/forms.py
parent4207a3f3ee3288b02c91808935976f0b8006eb14 (diff)
downloaddjango-pgpmailman-9d23d95ca530f5eabcd0f1c50d18dea2dc29b506.tar.gz
django-pgpmailman-9d23d95ca530f5eabcd0f1c50d18dea2dc29b506.tar.zst
django-pgpmailman-9d23d95ca530f5eabcd0f1c50d18dea2dc29b506.zip
Diffstat (limited to 'src/django_pgpmailman/forms.py')
-rw-r--r--src/django_pgpmailman/forms.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/django_pgpmailman/forms.py b/src/django_pgpmailman/forms.py
index 07761df..493d3d8 100644
--- a/src/django_pgpmailman/forms.py
+++ b/src/django_pgpmailman/forms.py
@@ -16,8 +16,11 @@
# 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 django import forms
+from django.core.exceptions import ValidationError
from django.utils.translation import ugettext_lazy as _
+from pgpy import PGPKey
+from pgpy.errors import PGPError
class NullBooleanRadioSelect(forms.RadioSelect):
@@ -163,3 +166,33 @@ class ListMiscSettingsForm(forms.Form):
help_text=_('A set of member roles that are allowed to sign the '
'lists public key via the `key sign` command.')
)
+
+
+class KeyFileField(forms.FileField):
+ def to_python(self, data):
+ try:
+ return PGPKey.from_blob(data.read())[0]
+ except PGPError as e:
+ raise ValidationError(str(e), code='invalid')
+
+
+class ListKeyManagementForm(forms.Form):
+ key = KeyFileField(
+ widget=forms.ClearableFileInput(),
+ required=False,
+ label=_('Upload a new private key'),
+ help_text=_('Useful for uploading a complately different list key '
+ 'than the one generated by mailman-pgp, when setting '
+ 'up a new mailing list. The uploaded key must be a '
+ 'private PGP key, not expired and must be usable for '
+ 'encryption and signatures.')
+ )
+ pubkey = KeyFileField(
+ widget=forms.ClearableFileInput(),
+ required=False,
+ label=_('Upload a public key'),
+ help_text=_('New signatures from the uploaded key are merged with '
+ 'the current list key, provided the uploaded key '
+ 'has the same key material and contains the UID that '
+ 'was signed.')
+ )