def sync_folders(folder): if not DataEncryptionHandler.encryption_enabled(): return project_name = os.path.basename(folder) encrypted_folder = DataEncryptionHandler.compute_encrypted_folder_path( folder) if os.path.exists(encrypted_folder) or os.path.exists(folder): crypto_pass = DataEncryptionHandler._project_key(project_name) crypto = Crypto(crypto_pass) syncro = Syncrypto(crypto, encrypted_folder, folder) syncro.sync_folder() trash_path = os.path.join(encrypted_folder, "_syncrypto", "trash") if os.path.exists(trash_path): shutil.rmtree(trash_path) else: LOGGER.info("Project {} was deleted".format(project_name))
def sync_folders(folder): if not DataEncryptionHandler.encryption_enabled(): return encrypted_folder = DataEncryptionHandler.compute_encrypted_folder_path( folder) crypto_pass = os.environ[ DataEncryptionHandler. CRYPTO_PASS] if DataEncryptionHandler.CRYPTO_PASS in os.environ else None if crypto_pass is None: raise TVBException( "Storage encryption/decryption is not possible because password is not provided." ) crypto = Crypto(crypto_pass) syncro = Syncrypto(crypto, encrypted_folder, folder) syncro.sync_folder() trash_path = os.path.join(encrypted_folder, "_syncrypto", "trash") if os.path.exists(trash_path): shutil.rmtree(trash_path)
def isPass(self): sync = Syncrypto(self.crypto, self.encrypted_folder, self.plain_folder, self.encrypted_tree, self.plain_tree) sync2 = Syncrypto(self.crypto, self.encrypted_folder, self.plain_folder_check, self.encrypted_tree, self.plain_tree_check) sync.sync_folder(False) sync2.sync_folder(False) directory_cmp = dircmp(self.plain_folder, self.plain_folder_check) self.assertEqual(len(directory_cmp.left_only), 0) self.assertEqual(len(directory_cmp.right_only), 0) self.assertEqual(len(directory_cmp.diff_files), 0)
def test_change_password(self): sync = Syncrypto(self.crypto, self.encrypted_folder, self.plain_folder, self.encrypted_tree, self.plain_tree, self.snapshot_tree) sync.sync_folder(False) oldpass = self.crypto.password newpass = "******" sync.change_password(newpass) self.crypto.password = oldpass self.assertRaises(DecryptError, sync._load_encrypted_tree) self.crypto.password = newpass.encode("ascii") sync.sync_folder(False)
def test_change_password(self): sync = Syncrypto(self.crypto, self.encrypted_folder, self.plain_folder, self.encrypted_tree, self.plain_tree, self.snapshot_tree) sync.sync_folder() oldpass = self.crypto.password newpass = "******" sync.change_password(newpass) self.crypto.password = oldpass self.assertRaises(DecryptError, sync._load_encrypted_tree) self.crypto.password = newpass.encode("ascii") sync.sync_folder()
def isPass(self): sync = Syncrypto(self.crypto, self.encrypted_folder, self.plain_folder, self.encrypted_tree, self.plain_tree) sync2 = Syncrypto( self.crypto, self.encrypted_folder, self.plain_folder_check, self.encrypted_tree, self.plain_tree_check ) sync.sync_folder(False) sync2.sync_folder(False) directory_cmp = dircmp(self.plain_folder, self.plain_folder_check) self.assertEqual(len(directory_cmp.left_only), 0) self.assertEqual(len(directory_cmp.right_only), 0) self.assertEqual(len(directory_cmp.diff_files), 0)
from time import time from syncrypto import Crypto, Syncrypto bufferSize = 64 * 1024 password = "******" folder = "/Users/bvalean/TVB/PROJECTS/Default_Project" folder_encrypted = "/Users/bvalean/WORK/test-encryption/Default_Project_encrypted" folder_decrypted = "/Users/bvalean/WORK/test-encryption/Default_Project_decrypted" if __name__ == '__main__': print("========== ENCRYPTION ==========") crypto = Crypto(password) syncro1 = Syncrypto(crypto,folder_encrypted,folder) t = time() syncro1.sync_folder() print("========== FINISH ENCRYPTION ==========") encryption = time()-t print("========== DECRYPTION ==========") syncro1 = Syncrypto(crypto,folder_encrypted,folder_decrypted) t = time() syncro1.sync_folder() print("========== FINISH DECRYPTION ==========") decryption = time() - t print("========== RESULTS ==========") print("Ecrypted: {} seconds".format(encryption)) print("Decrypted: {} seconds".format(decryption))
def pass_invalid_plaintext_folder(self): invalid_folder = self.plain_folder + os.path.sep + "invalid_folder" with open(invalid_folder, 'wb') as f: f.write(b'Test') Syncrypto(self.crypto, self.encrypted_folder, invalid_folder) os.remove(invalid_folder)