From e7d1f754358b29d9bb71791a3472b173a24d0f86 Mon Sep 17 00:00:00 2001 From: Nich Date: Mon, 28 Mar 2016 21:24:59 +0000 Subject: [PATCH] Added exception handling for failure to decrypt When entering the wrong password, fernet throws an 'InvalidToken' exception. This is now handled, but does not fully shutdown pappy. Working on asking for password multiple times, then shutting down completely after reasonable amount of total tries, e.g. 3. --- pappyproxy/crypto.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pappyproxy/crypto.py b/pappyproxy/crypto.py index 14a96f1..289de72 100644 --- a/pappyproxy/crypto.py +++ b/pappyproxy/crypto.py @@ -11,7 +11,7 @@ import twisted from . import compress from .util import PappyException from base64 import b64encode, b64decode -from cryptography.fernet import Fernet +from cryptography.fernet import Fernet, InvalidToken from twisted.internet import reactor, defer class Crypto(object): @@ -78,7 +78,10 @@ class Crypto(object): # Decrypt the project archive archive_crypt = open(self.config.crypt_file, 'rb').read() archive_file = open(self.config.archive, 'wb') - archive = fern.decrypt(archive_crypt) + try: + archive = fern.decrypt(archive_crypt) + except InvalidToken: + raise PappyException("Problem decrypting the file, restart pappy to try again") archive_file.write(archive) archive_file.close()