Skip to content

Commit 5aad2aa

Browse files
committed
Add encrypted field to comment.
See ietf-tools#913 - Legacy-Id: 5155
1 parent e1a5187 commit 5aad2aa

2 files changed

Lines changed: 29 additions & 3 deletions

File tree

ietf/nomcom/fields.py

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,31 @@
1+
import tempfile
2+
from django.conf import settings
13
from django.db import models
24

5+
from ietf.utils.pipe import pipe
36

4-
class EncriptedTextField(models.TextField):
5-
""" TODO: do the logic to store encripted text"""
7+
8+
class EncriptedException(Exception):
69
pass
10+
11+
12+
class EncriptedTextField(models.TextField):
13+
def pre_save(self, instance, add):
14+
if add:
15+
comments = getattr(instance, 'comments')
16+
position = getattr(instance, 'position')
17+
cert_file = position.nomcom.public_key.path
18+
comments_file = tempfile.NamedTemporaryFile()
19+
comments_file.write(comments)
20+
21+
code, out, error = pipe("%s smime -encrypt -in %s %s" % (settings.OPENSSL_COMMAND,
22+
comments_file.name,
23+
cert_file))
24+
comments_file.close()
25+
if not error:
26+
instance.comments = out
27+
return out
28+
else:
29+
raise EncriptedException(error)
30+
else:
31+
return instance.comments

ietf/settings.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,9 +261,10 @@
261261

262262
# NomCom Tool settings
263263
ROLODEX_URL = ""
264-
PUBLIC_KEYS_URL = BASE_DIR + "/public_keys/"
264+
PUBLIC_KEYS_URL = BASE_DIR + '/public_keys/'
265265
NOMCOM_FROM_EMAIL = DEFAULT_FROM_EMAIL
266266
NOMCOM_ADMIN_EMAIL = DEFAULT_FROM_EMAIL
267+
OPENSSL_COMMAND = '/usr/bin/openssl'
267268

268269
# Days from meeting to cut off dates on submit
269270
FIRST_CUTOFF_DAYS = 19

0 commit comments

Comments
 (0)