Merge pull request #208 from YunoHost/better_debug_gpg

Better debug information related to gpg for storing session
This commit is contained in:
Bram 2019-07-28 06:02:50 +02:00 committed by GitHub
commit bce7aee510
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 13 deletions

View file

@ -31,7 +31,7 @@
"server_already_running": "A server is already running on that port",
"success": "Success!",
"unable_authenticate": "Unable to authenticate",
"unable_retrieve_session": "Unable to retrieve the session",
"unable_retrieve_session": "Unable to retrieve the session because '{exception}'",
"unknown_group": "Unknown '{group}' group",
"unknown_user": "Unknown '{user}' user",
"values_mismatch": "Values don't match",

View file

@ -93,8 +93,8 @@ class BaseAuthenticator(object):
try:
# Extract id and hash from token
s_id, s_hash = token
except TypeError:
logger.error("unable to extract token parts from '%s'", token)
except TypeError as e:
logger.error("unable to extract token parts from '%s' because '%s'", token, e)
if password is None:
raise MoulinetteError('error_see_log')
@ -110,17 +110,19 @@ class BaseAuthenticator(object):
self.authenticate(password)
except MoulinetteError:
raise
except:
logger.exception("authentication (name: '%s', vendor: '%s') fails",
self.name, self.vendor)
except Exception as e:
logger.exception("authentication (name: '%s', vendor: '%s') fails because '%s'",
self.name, self.vendor, e)
raise MoulinetteError('unable_authenticate')
# Store session
if store_session:
try:
self._store_session(s_id, s_hash, password)
except:
logger.exception("unable to store session")
except Exception as e:
import traceback
traceback.print_exc()
logger.exception("unable to store session because %s", e)
else:
logger.debug("session has been stored")
@ -150,16 +152,16 @@ class BaseAuthenticator(object):
try:
with self._open_sessionfile(session_id, 'r') as f:
enc_pwd = f.read()
except IOError:
except IOError as e:
logger.debug("unable to retrieve session", exc_info=1)
raise MoulinetteError('unable_retrieve_session')
raise MoulinetteError('unable_retrieve_session', exception=e)
else:
gpg = gnupg.GPG()
gpg.encoding = 'utf-8'
decrypted = gpg.decrypt(enc_pwd, passphrase=session_hash)
if decrypted.ok is not True:
logger.error("unable to decrypt password for the session: %s",
decrypted.status)
raise MoulinetteError('unable_retrieve_session')
error_message = "unable to decrypt password for the session: %s", decrypted.status
logger.error(error_message)
raise MoulinetteError('unable_retrieve_session', exception=error_message)
return decrypted.data