From 8559565dca16d27f6d45c871b7e1fcdd043fe495 Mon Sep 17 00:00:00 2001 From: Roberto Rosario Date: Sat, 15 Dec 2018 15:27:26 -0400 Subject: [PATCH] Signatures: No terminal raises NeedPassphrase Update the Key model's sign_file method to raise the NeedPassphrase exception when GPG has no terminal available and not just when the GPG backend specifically asks for a passphrase. Signed-off-by: Roberto Rosario --- HISTORY.rst | 2 ++ mayan/apps/django_gpg/literals.py | 1 + mayan/apps/django_gpg/models.py | 5 +++-- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index cc8d55c862..1925bded30 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -187,6 +187,8 @@ "methods.py". - The PropertyHelper class has been removed as the accessors no longer need it. +- Raise the NeedPassphrase exception when GPG has no terminal + available. 3.1.9 (2018-11-01) ================== diff --git a/mayan/apps/django_gpg/literals.py b/mayan/apps/django_gpg/literals.py index 9567ea6987..ea85b945ab 100644 --- a/mayan/apps/django_gpg/literals.py +++ b/mayan/apps/django_gpg/literals.py @@ -13,6 +13,7 @@ DEFAULT_SETTING_GPG_BACKEND = 'mayan.apps.django_gpg.classes.PythonGNUPGBackend' ERROR_MSG_BAD_PASSPHRASE = 'BAD_PASSPHRASE' ERROR_MSG_MISSING_PASSPHRASE = 'MISSING_PASSPHRASE' +ERROR_MSG_NO_TERMINAL = 'Sorry, no terminal at all requested - can\'t get input' KEY_TYPES = { 'pub': _('Public'), diff --git a/mayan/apps/django_gpg/models.py b/mayan/apps/django_gpg/models.py index 129d197168..0716f94c91 100644 --- a/mayan/apps/django_gpg/models.py +++ b/mayan/apps/django_gpg/models.py @@ -12,7 +12,8 @@ from django.utils.translation import ugettext_lazy as _ from .exceptions import NeedPassphrase, PassphraseError from .literals import ( ERROR_MSG_BAD_PASSPHRASE, ERROR_MSG_MISSING_PASSPHRASE, - KEY_TYPE_CHOICES, KEY_TYPE_SECRET, OUTPUT_MESSAGE_CONTAINS_PRIVATE_KEY + ERROR_MSG_NO_TERMINAL, KEY_TYPE_CHOICES, KEY_TYPE_SECRET, + OUTPUT_MESSAGE_CONTAINS_PRIVATE_KEY ) from .managers import KeyManager from .runtime import gpg_backend @@ -123,7 +124,7 @@ class Key(models.Model): logger.debug('file_sign_results.stderr: %s', file_sign_results.stderr) - if ERROR_MSG_MISSING_PASSPHRASE in file_sign_results.stderr: + if ERROR_MSG_MISSING_PASSPHRASE in file_sign_results.stderr or ERROR_MSG_NO_TERMINAL in file_sign_results.stderr: raise NeedPassphrase if ERROR_MSG_BAD_PASSPHRASE in file_sign_results.stderr: