aboutsummaryrefslogtreecommitdiff
path: root/src/django_pgpmailman/forms.py
diff options
context:
space:
mode:
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.')
+ )