Django GPG: 3rd party app compatibility update

Update the django_gpg app to work with the latest version of the
python-gnupg package (0.4.3).

The python-gnupg now returns a more clear error message to
differentiate between a bad passphrase and a missing passphrase.
This improments allows the django_gpg to simplify its error
message parsing and remove the literals:
"ERROR_MSG_NEED_PASSPHRASE" and "ERROR_MSG_GOOD_PASSPHRASE".

Signed-off-by: Roberto Rosario <Roberto.Rosario@mayan-edms.com>
This commit is contained in:
Roberto Rosario
2018-12-06 02:58:40 -04:00
parent d1a4cb875b
commit d6435b7735
4 changed files with 15 additions and 17 deletions

View File

@@ -151,6 +151,9 @@
``DOCUMENT_SIGNATURES_STORAGE_BACKEND_ARGUMENTS``. This
change differentiates them from the setting from the
django_gpg app.
- Updated the django_gpg app to work with the latest
version of the python-gnupg package (0.4.3).
3.1.9 (2018-11-01)
==================

View File

@@ -5,6 +5,9 @@ from django.utils.translation import ugettext_lazy as _
DEFAULT_GPG_PATH = '/usr/bin/gpg1'
DEFAULT_SETTING_GPG_BACKEND = 'mayan.apps.django_gpg.classes.PythonGNUPGBackend'
ERROR_MSG_BAD_PASSPHRASE = 'BAD_PASSPHRASE'
ERROR_MSG_MISSING_PASSPHRASE = 'MISSING_PASSPHRASE'
KEY_TYPES = {
'pub': _('Public'),
'sec': _('Secret'),
@@ -34,13 +37,14 @@ KEY_SECONDARY_CLASSES = (
KEYSERVER_DEFAULT_PORT = 11371
OUTPUT_MESSAGE_CONTAINS_PRIVATE_KEY = 'Contains private key'
SIGNATURE_STATE_BAD = 'signature bad'
SIGNATURE_STATE_NONE = None
SIGNATURE_STATE_ERROR = 'signature error'
SIGNATURE_STATE_NO_PUBLIC_KEY = 'no public key'
SIGNATURE_STATE_GOOD = 'signature good'
SIGNATURE_STATE_VALID = 'signature valid'
SIGNATURE_STATES = {
SIGNATURE_STATE_BAD: {
'text': _('Bad signature.'),
@@ -64,8 +68,3 @@ SIGNATURE_STATES = {
'text': _('Document is signed with a valid signature.'),
},
}
ERROR_MSG_NEED_PASSPHRASE = 'NEED_PASSPHRASE'
ERROR_MSG_BAD_PASSPHRASE = 'BAD_PASSPHRASE'
ERROR_MSG_GOOD_PASSPHRASE = 'GOOD_PASSPHRASE'
OUTPUT_MESSAGE_CONTAINS_PRIVATE_KEY = 'Contains private key'

View File

@@ -11,9 +11,8 @@ from django.utils.translation import ugettext_lazy as _
from .exceptions import NeedPassphrase, PassphraseError
from .literals import (
ERROR_MSG_NEED_PASSPHRASE, ERROR_MSG_BAD_PASSPHRASE,
ERROR_MSG_GOOD_PASSPHRASE, KEY_TYPE_CHOICES, KEY_TYPE_SECRET,
OUTPUT_MESSAGE_CONTAINS_PRIVATE_KEY
ERROR_MSG_BAD_PASSPHRASE, ERROR_MSG_MISSING_PASSPHRASE,
KEY_TYPE_CHOICES, KEY_TYPE_SECRET, OUTPUT_MESSAGE_CONTAINS_PRIVATE_KEY
)
from .managers import KeyManager
from .runtime import gpg_backend
@@ -124,10 +123,10 @@ class Key(models.Model):
logger.debug('file_sign_results.stderr: %s', file_sign_results.stderr)
if ERROR_MSG_NEED_PASSPHRASE in file_sign_results.stderr:
if ERROR_MSG_BAD_PASSPHRASE in file_sign_results.stderr:
raise PassphraseError
elif ERROR_MSG_GOOD_PASSPHRASE not in file_sign_results.stderr:
raise NeedPassphrase
if ERROR_MSG_MISSING_PASSPHRASE in file_sign_results.stderr:
raise NeedPassphrase
if ERROR_MSG_BAD_PASSPHRASE in file_sign_results.stderr:
raise PassphraseError
return file_sign_results

View File

@@ -1,8 +1,5 @@
from __future__ import unicode_literals
import os
from django.conf import settings
from django.utils.translation import ugettext_lazy as _
from mayan.apps.smart_settings import Namespace