|
|
|
@ -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) |
|
|
|
|
|
|
|
|
@ -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) |
|
|
|
|