From ff8595e8f40f6177a69b732c92d67c9df5a15d0d Mon Sep 17 00:00:00 2001 From: Nich Date: Mon, 28 Mar 2016 21:51:56 +0000 Subject: [PATCH] Minor changes, decrypt project within PappySession Changed to decrypting project to within the PappySession object, instead of in main. More maintainable, and makes more sense. --- pappyproxy/compress.py | 9 ++++----- pappyproxy/crypto.py | 4 +++- pappyproxy/pappy.py | 10 ++++++---- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/pappyproxy/compress.py b/pappyproxy/compress.py index 427497c..c19761b 100644 --- a/pappyproxy/compress.py +++ b/pappyproxy/compress.py @@ -45,9 +45,8 @@ class Compress(object): zf = zipfile.ZipFile(self.zip_archive, mode="a") zf.write(self.config.crypt_dir) zf.close() - except e: - raise PappyException("Error creating the zipfile. Error: ", e) - pass + except zipfile.LargeZipFile as e: + raise PappyException("Project zipfile too large. Error: ", e) def unzip_project(self): """ @@ -63,7 +62,7 @@ class Compress(object): try: zf.extract("config.json") - except e: + except zipfile.BadZipfile as e: raise PappyException("Project archive contents corrupted. Error: ", e) zf.extractall() @@ -80,5 +79,5 @@ class Compress(object): try: with tarfile.open(self.bz2_archive, "r:bz2") as archive: archive.extractall() - except tarfile.ExtractError, e: + except tarfile.ExtractError as e: raise PappyException("Project archive contents corrupted. Error: ", e) diff --git a/pappyproxy/crypto.py b/pappyproxy/crypto.py index 289de72..9912880 100644 --- a/pappyproxy/crypto.py +++ b/pappyproxy/crypto.py @@ -82,6 +82,8 @@ class Crypto(object): archive = fern.decrypt(archive_crypt) except InvalidToken: raise PappyException("Problem decrypting the file, restart pappy to try again") + reactor.stop() + defer.returnValue(None) archive_file.write(archive) archive_file.close() @@ -162,7 +164,7 @@ class Crypto(object): try: if not self.key: self.key = b64encode(scrypt.hash(self.password, self.salt, buflen=32)) - except TypeError, e: + except TypeError as e: raise PappyException("Scrypt failed with type error: ", e) except scrypt.error, e: raise PappyException("Scrypt failed with internal error: ", e) diff --git a/pappyproxy/pappy.py b/pappyproxy/pappy.py index 011f685..cedf407 100755 --- a/pappyproxy/pappy.py +++ b/pappyproxy/pappy.py @@ -70,6 +70,12 @@ class PappySession(object): @defer.inlineCallbacks def start(self): from . import proxy, plugin + + if self.config.crypt_session: + self.decrypt() + self.config.load_from_file('./config.json') + self.config.global_load_from_file() + self.delete_data_on_quit = False # If the data file doesn't exist, create it with restricted permissions if not os.path.isfile(self.config.datafile): @@ -216,10 +222,6 @@ def main(): if settings['crypt']: pappy_config.crypt_file = settings['crypt'] pappy_config.crypt_session = True - session.decrypt() - conf_settings = pappy_config.load_from_file('./config.json') - pappy_config.global_load_from_file() - session.delete_data_on_quit = False elif settings['lite']: conf_settings = pappy_config.get_default_config() conf_settings['debug_dir'] = None