Fixed bugs with crypto.py, need to work on cleanup
Project is now properly encrypting the archive, and now I just need to ensure proper decryption is happening. Also need to work on cleaning up clear text versions of the crypt project files. Need to write tests for flushing out edge cases.
这个提交存在于:
父节点
c32201fd05
当前提交
a3cb5f13ed
共有 3 个文件被更改,包括 27 次插入 和 26 次删除
|
@ -23,19 +23,19 @@ class Compress(object):
|
|||
self.zip_archive = sessconfig.archive
|
||||
self.bz2_archive = sessconfig.archive
|
||||
|
||||
def compress_project():
|
||||
def compress_project(self):
|
||||
if bz2:
|
||||
tar_project()
|
||||
self.tar_project()
|
||||
else:
|
||||
zip_project()
|
||||
self.zip_project()
|
||||
|
||||
def decompress_project():
|
||||
def decompress_project(self):
|
||||
if bz2:
|
||||
untar_project()
|
||||
self.untar_project()
|
||||
else:
|
||||
unzip_project()
|
||||
self.unzip_project()
|
||||
|
||||
def zip_project():
|
||||
def zip_project(self):
|
||||
"""
|
||||
Zip project files
|
||||
|
||||
|
@ -52,7 +52,7 @@ class Compress(object):
|
|||
raise PappyException("Error creating the zipfile", e)
|
||||
pass
|
||||
|
||||
def unzip_project():
|
||||
def unzip_project(self):
|
||||
"""
|
||||
Extract project files from decrypted zip archive.
|
||||
Initially checks the zip archive's magic number and
|
||||
|
@ -71,24 +71,20 @@ class Compress(object):
|
|||
|
||||
zf.extractall()
|
||||
|
||||
def tar_project():
|
||||
if tarfile.is_tarfile(self.bz2_archive):
|
||||
archive = tarfile.open(self.bz2_archive, 'w:bz2')
|
||||
project_files = self.config.get_project_files()
|
||||
|
||||
# Read files line by line to accomodate larger files, e.g. the project database
|
||||
for pf in project_files:
|
||||
archive.add(pf)
|
||||
def tar_project(self):
|
||||
archive = tarfile.open(self.bz2_archive, 'w:bz2')
|
||||
project_files = self.config.get_project_files()
|
||||
|
||||
# Read files line by line to accomodate larger files, e.g. the project database
|
||||
for pf in project_files:
|
||||
archive.add(pf)
|
||||
archive.close()
|
||||
|
||||
def untar_project():
|
||||
def untar_project(self):
|
||||
if tarfile.is_tarfile(self.bz2_archive):
|
||||
# Attempt to read the first 16 bytes of the archive
|
||||
# Raise exception if there is a failure
|
||||
project_files = self.config.get_project_files()
|
||||
try:
|
||||
with tarfile.open(self.bz2_archive, "r:bz2") as archive:
|
||||
for pf in project_files:
|
||||
archive.add(pf)
|
||||
archive.extractall()
|
||||
except e:
|
||||
raise PappyException("Project archive contents corrupted. Error: ", e)
|
||||
|
|
|
@ -36,7 +36,7 @@ class Crypto(object):
|
|||
|
||||
# Create project archive and crypto archive
|
||||
self.compressor.compress_project()
|
||||
archive_file = open(self.archive, 'rb')
|
||||
archive_file = open(self.archive, 'rb').read()
|
||||
archive_crypt = open(self.config.crypt_file, 'wb')
|
||||
|
||||
# Encrypt the archive read as a bytestring
|
||||
|
@ -57,7 +57,7 @@ class Crypto(object):
|
|||
# Get the password and salt, then derive the key
|
||||
self.crypto_ramp_up()
|
||||
|
||||
crypto_path = os.path.join(os.getcwd(), self.config.crypt_dir)
|
||||
crypto_path = self.config.crypt_dir
|
||||
|
||||
if not os.path.isdir(crypto_path):
|
||||
os.mkdir(crypto_path)
|
||||
|
@ -168,7 +168,7 @@ class Crypto(object):
|
|||
|
||||
try:
|
||||
if not self.key:
|
||||
self.key = scrypt.hash(self.password, self.salt, buflen=32)
|
||||
self.key = b64encode(scrypt.hash(self.password, self.salt, buflen=32))
|
||||
except TypeError, e:
|
||||
raise PappyException("Scrypt failed with type error: ", e)
|
||||
except scrypt.error, e:
|
||||
|
|
|
@ -145,11 +145,11 @@ class PappySession(object):
|
|||
|
||||
@defer.inlineCallbacks
|
||||
def encrypt(self):
|
||||
self.crypto.encrypt_project(self.password)
|
||||
yield self.crypto.encrypt_project()
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def decrypt(self):
|
||||
self.crypto.decrypt_project()
|
||||
yield self.crypto.decrypt_project()
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def cleanup(self, ignored=None):
|
||||
|
@ -159,6 +159,11 @@ class PappySession(object):
|
|||
if self.delete_data_on_quit:
|
||||
print 'Deleting temporary datafile'
|
||||
os.remove(self.config.datafile)
|
||||
|
||||
# If currently in the crypt directory,
|
||||
# encrypt the project, delete clear files
|
||||
if os.getcwd() == self.config.crypt_dir:
|
||||
self.encrypt()
|
||||
|
||||
def parse_args():
|
||||
# parses sys.argv and returns a settings dictionary
|
||||
|
|
正在加载…
添加表格
添加链接
在新工单中引用