Tested and fixed file copying from Crypto.decrypt_project

In the function for grabbing project files (`Config.get_project_files`)
I was overcomplicating getting the current working directory.
Simplified the process and removed the bug!
This commit is contained in:
onizenso 2016-03-25 20:28:22 +00:00
parent b56bb83558
commit c32201fd05
3 changed files with 28 additions and 25 deletions

View file

@ -9,6 +9,7 @@ import shutil
import twisted
from . import compress
from .util import PappyException
from base64 import b64encode, b64decode
from cryptography.fernet import Fernet
from twisted.internet import reactor, defer
@ -56,9 +57,10 @@ class Crypto(object):
# Get the password and salt, then derive the key
self.crypto_ramp_up()
# Create crypto working directory
crypto_path = os.path.join(os.getcwd(), self.config.crypt_dir)
os.mkdir(crypto_path)
if not os.path.isdir(crypto_path):
os.mkdir(crypto_path)
if os.path.isfile(self.config.crypt_file):
# Derive the key
@ -113,7 +115,7 @@ class Crypto(object):
def set_salt_from_file(self):
try:
salt_file = open(self.config.salt_file, 'rb')
self.config.salt = salt_file.readline().strip()
self.salt = salt_file.readline().strip()
except:
raise PappyException("Unable to read project.salt")
@ -121,7 +123,7 @@ class Crypto(object):
if os.path.isfile(self.config.salt_file):
self.set_salt_from_file()
else:
self.config.salt = os.urandom(16)
self.salt = os.urandom(16)
def get_password(self):
"""
@ -166,6 +168,8 @@ class Crypto(object):
try:
if not self.key:
self.key = scrypt.hash(self.password, self.salt, bufflen=32)
except e:
raise PappyException("Error deriving the key: ", e)
self.key = scrypt.hash(self.password, self.salt, buflen=32)
except TypeError, e:
raise PappyException("Scrypt failed with type error: ", e)
except scrypt.error, e:
raise PappyException("Scrypt failed with internal error: ", e)