From e314bb4723fe0f65f3b43873b56c6e63d35c4313 Mon Sep 17 00:00:00 2001 From: Henrik Levkowetz Date: Thu, 4 Jul 2019 22:04:42 +0000 Subject: [PATCH] Undid delete of ietf/nomcom/fields; it's currently needed by ietf/nomcom/migrations/0001_initial.py - Legacy-Id: 16403 --- ietf/nomcom/fields.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 ietf/nomcom/fields.py diff --git a/ietf/nomcom/fields.py b/ietf/nomcom/fields.py new file mode 100644 index 000000000..f418bb382 --- /dev/null +++ b/ietf/nomcom/fields.py @@ -0,0 +1,32 @@ +# Copyright The IETF Trust 2012-2019, All Rights Reserved +from django.conf import settings +from django.db import models +from django.utils.encoding import smart_str + +from ietf.utils.pipe import pipe +from ietf.utils.log import log + +class EncryptedException(Exception): + pass + +class EncryptedTextField(models.TextField): + def pre_save(self, instance, add): + if add: + comments = smart_str(getattr(instance, 'comments')) + nomcom = getattr(instance, 'nomcom') + try: + cert_file = nomcom.public_key.path + except ValueError as e: + raise ValueError("Trying to read the NomCom public key: " + str(e)) + + command = "%s smime -encrypt -in /dev/stdin %s" % (settings.OPENSSL_COMMAND, cert_file) + code, out, error = pipe(command, comments.encode()) + if code != 0: + log("openssl error: %s:\n Error %s: %s" %(command, code, error)) + if not error: + instance.comments = out + return out + else: + raise EncryptedException(error) + else: + return instance.comments