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.
This commit is contained in:
parent
bf914e6f86
commit
e7d1f75435
1 changed files with 5 additions and 2 deletions
|
@ -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()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue