Pep8 corrections
This commit is contained in:
parent
f5c53add9c
commit
f7d8df69cc
3 changed files with 75 additions and 69 deletions
|
@ -16,6 +16,7 @@ except ImportError:
|
|||
from base64 import b64encode, b64decode
|
||||
from os import getcwd, sep, path, urandom
|
||||
|
||||
|
||||
class Compress(object):
|
||||
def __init__(self, sessconfig):
|
||||
self.config = sessconfig
|
||||
|
@ -63,7 +64,7 @@ class Compress(object):
|
|||
try:
|
||||
zf.extract("config.json")
|
||||
except zipfile.BadZipfile as e:
|
||||
raise PappyException("Project archive contents corrupted. Error: ", e)
|
||||
raise PappyException("Zip archive corrupted. Error: ", e)
|
||||
|
||||
zf.extractall()
|
||||
|
||||
|
@ -71,7 +72,7 @@ class Compress(object):
|
|||
archive = tarfile.open(self.bz2_archive, 'w:bz2')
|
||||
|
||||
archive.add(self.config.crypt_dir)
|
||||
archive.close()
|
||||
archive.close()
|
||||
|
||||
def untar_project(self):
|
||||
if tarfile.is_tarfile(self.bz2_archive):
|
||||
|
@ -80,4 +81,4 @@ class Compress(object):
|
|||
with tarfile.open(self.bz2_archive, "r:bz2") as archive:
|
||||
archive.extractall()
|
||||
except tarfile.ExtractError as e:
|
||||
raise PappyException("Project archive contents corrupted. Error: ", e)
|
||||
raise PappyException("Tar archive corrupted. Error: ", e)
|
||||
|
|
|
@ -14,6 +14,7 @@ from base64 import b64encode, b64decode
|
|||
from cryptography.fernet import Fernet, InvalidToken
|
||||
from twisted.internet import reactor, defer
|
||||
|
||||
|
||||
class Crypto(object):
|
||||
def __init__(self, sessconfig):
|
||||
self.config = sessconfig
|
||||
|
@ -25,7 +26,8 @@ class Crypto(object):
|
|||
|
||||
def encrypt_project(self):
|
||||
"""
|
||||
Compress and encrypt the project files, deleting clear-text files afterwards
|
||||
Compress and encrypt the project files,
|
||||
deleting clear-text files afterwards
|
||||
"""
|
||||
|
||||
# Leave the crypto working directory
|
||||
|
@ -54,13 +56,13 @@ class Crypto(object):
|
|||
# Delete clear-text files
|
||||
self.delete_clear_files()
|
||||
|
||||
|
||||
def decrypt_project(self):
|
||||
"""
|
||||
Decrypt and decompress the project files
|
||||
"""
|
||||
|
||||
# If project hasn't been encrypted before, setup crypt working directory
|
||||
# If project hasn't been encrypted before,
|
||||
# setup crypt working directory
|
||||
if not os.path.isfile(self.config.crypt_file):
|
||||
os.mkdir(self.config.crypt_dir)
|
||||
|
||||
|
@ -78,8 +80,8 @@ class Crypto(object):
|
|||
retries = 3
|
||||
while True:
|
||||
try:
|
||||
self.crypto_ramp_up()
|
||||
fern = Fernet(self.key)
|
||||
self.crypto_ramp_up()
|
||||
fern = Fernet(self.key)
|
||||
archive = fern.decrypt(archive_crypt)
|
||||
break
|
||||
except InvalidToken:
|
||||
|
@ -107,7 +109,7 @@ class Crypto(object):
|
|||
return True
|
||||
|
||||
def confirm_password_retry(self):
|
||||
answer = raw_input("Would you like to re-enter your password? (y/n)").strip()
|
||||
answer = raw_input("Re-enter your password? (y/n)").strip()
|
||||
if answer[0] == "y" or answer[0] == "Y":
|
||||
return True
|
||||
else:
|
||||
|
@ -181,7 +183,8 @@ class Crypto(object):
|
|||
|
||||
try:
|
||||
if not self.key:
|
||||
self.key = b64encode(scrypt.hash(self.password, self.salt, buflen=32))
|
||||
shash = scrypt.hash(self.password, self.salt, buflen=32)
|
||||
self.key = b64encode(shash)
|
||||
except TypeError as e:
|
||||
raise PappyException("Scrypt failed with type error: ", e)
|
||||
except scrypt.error, e:
|
||||
|
@ -200,5 +203,4 @@ class Crypto(object):
|
|||
Forces generation of new salt after opening and closing the project.
|
||||
Adds security in the case of a one-time compromise of the system.
|
||||
"""
|
||||
#os.remove(self.config.salt_file)
|
||||
os.remove(self.config.crypt_file)
|
||||
|
|
|
@ -181,7 +181,10 @@ def parse_args():
|
|||
parser = argparse.ArgumentParser(description='An intercepting proxy for testing web applications.')
|
||||
parser.add_argument('-l', '--lite', help='Run the proxy in "lite" mode', action='store_true')
|
||||
try:
|
||||
parser.add_argument('-c', '--crypt', type=str, nargs=1, help='Start pappy in "crypto" mode, must supply a name for the encrypted project archive [CRYPT]')
|
||||
hlpmsg = 'Start pappy in "crypto" mode,'+
|
||||
'must supply a name for the encrypted'+
|
||||
'project archive [CRYPT]'
|
||||
parser.add_argument('-c', '--crypt', type=str, nargs=1, help=hlpmsg)
|
||||
except:
|
||||
print 'Must supply a project name: pappy -c <project_name>'
|
||||
reactor.stop()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue