Skip to content

Commit 3848074

Browse files
committed
Add an example of the format in the private key form.
Check if the private key is valid. Fixes ietf-tools#1004 - Legacy-Id: 5697
1 parent f795684 commit 3848074

3 files changed

Lines changed: 37 additions & 3 deletions

File tree

ietf/nomcom/forms.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
INEXISTENT_PERSON_TEMPLATE, NOMINEE_EMAIL_TEMPLATE, \
2727
NOMINATION_RECEIPT_TEMPLATE, FEEDBACK_RECEIPT_TEMPLATE, \
2828
get_user_email, get_hash_nominee_position, get_year_by_nomcom, \
29-
HEADER_QUESTIONNAIRE_TEMPLATE
29+
HEADER_QUESTIONNAIRE_TEMPLATE, validate_private_key
3030
from ietf.nomcom.decorators import member_required
3131

3232
ROLODEX_URL = getattr(settings, 'ROLODEX_URL', None)
@@ -758,6 +758,15 @@ class PrivateKeyForm(BaseNomcomForm, forms.Form):
758758

759759
fieldsets = [('Private key', ('key',))]
760760

761+
def clean_key(self):
762+
key = self.cleaned_data.get('key', None)
763+
if not key:
764+
return
765+
(validation, error) = validate_private_key(key)
766+
if validation:
767+
return key
768+
raise forms.ValidationError('Invalid private key. Error was: %s' % error)
769+
761770

762771
class PendingFeedbackForm(BaseNomcomForm, forms.ModelForm):
763772

ietf/nomcom/utils.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
import email
12
import hashlib
3+
import os
24
import re
3-
import email
5+
import tempfile
46

57
from django.conf import settings
68
from django.core.exceptions import PermissionDenied
@@ -156,3 +158,16 @@ def parse_email(text):
156158
body = extract_body(msg.get_payload())
157159

158160
return msg['From'], msg['Subject'], body
161+
162+
163+
def validate_private_key(key):
164+
key_file = tempfile.NamedTemporaryFile(delete=False)
165+
key_file.write(key)
166+
key_file.close()
167+
168+
command = "%s rsa -in %s -check -noout"
169+
code, out, error = pipe(command % (settings.OPENSSL_COMMAND,
170+
key_file.name))
171+
172+
os.unlink(key_file.name)
173+
return (not error, error)

ietf/templates/nomcom/private_key.html

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,17 @@
55
{% block nomcom_content %}
66
<h2>Enter private key</h2>
77

8-
<p>In order to access the {{ nomcom.group }} data you have to enter your private key. Please paste it in the text area below.</p>
8+
<p>In order to access the {{ nomcom.group }} data you have to enter your private key. Please paste it in the text area below. The key must be in the following format:</p>
9+
10+
<pre>
11+
-----BEGIN PRIVATE KEY-----
12+
MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDC1WgGTQjX1BHC
13+
jecwXk05g/r3feSAcErTQwszpjg3tixqQ+tLXQ2HuQLFDgWT26jd4FR7UPMUC9lE
14+
...
15+
8JA+eKl1wgzm/y+TwEbdxnj950jch0nqZUm+kx3omy9GRAx9qWP5r7Ot4Fx8uBbo
16+
CKn79FUPkVdlG8miRUY2UIU=
17+
-----END PRIVATE KEY-----
18+
</pre>
919

1020
<p>If you don't have a private key, please contact the group chair. You can leave the key empty and continue navigation without access to the encrypted data.</p>
1121

0 commit comments

Comments
 (0)