From 5aad2aadffbf4d15131dc4252c1e37e233acdf9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Jim=C3=A9nez?= Date: Wed, 26 Dec 2012 17:24:27 +0000 Subject: [PATCH] Add encrypted field to comment. See #913 - Legacy-Id: 5155 --- ietf/nomcom/fields.py | 29 +++++++++++++++++++++++++++-- ietf/settings.py | 3 ++- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/ietf/nomcom/fields.py b/ietf/nomcom/fields.py index dc4d3685c..471e60275 100644 --- a/ietf/nomcom/fields.py +++ b/ietf/nomcom/fields.py @@ -1,6 +1,31 @@ +import tempfile +from django.conf import settings from django.db import models +from ietf.utils.pipe import pipe + + +class EncriptedException(Exception): + pass + class EncriptedTextField(models.TextField): - """ TODO: do the logic to store encripted text""" - pass + def pre_save(self, instance, add): + if add: + comments = getattr(instance, 'comments') + position = getattr(instance, 'position') + cert_file = position.nomcom.public_key.path + comments_file = tempfile.NamedTemporaryFile() + comments_file.write(comments) + + code, out, error = pipe("%s smime -encrypt -in %s %s" % (settings.OPENSSL_COMMAND, + comments_file.name, + cert_file)) + comments_file.close() + if not error: + instance.comments = out + return out + else: + raise EncriptedException(error) + else: + return instance.comments diff --git a/ietf/settings.py b/ietf/settings.py index 416b17e16..8a6f18bfc 100644 --- a/ietf/settings.py +++ b/ietf/settings.py @@ -261,9 +261,10 @@ IDSUBMIT_ANNOUNCE_LIST_EMAIL = 'i-d-announce@ietf.org' # NomCom Tool settings ROLODEX_URL = "" -PUBLIC_KEYS_URL = BASE_DIR + "/public_keys/" +PUBLIC_KEYS_URL = BASE_DIR + '/public_keys/' NOMCOM_FROM_EMAIL = DEFAULT_FROM_EMAIL NOMCOM_ADMIN_EMAIL = DEFAULT_FROM_EMAIL +OPENSSL_COMMAND = '/usr/bin/openssl' # Days from meeting to cut off dates on submit FIRST_CUTOFF_DAYS = 19