more work on data encryption
This commit is contained in:
parent
bcd9535bd5
commit
bfe16ee2b0
27
core.py
27
core.py
@ -31,10 +31,31 @@ class Core:
|
|||||||
key = gpg.gen_key(input_data)
|
key = gpg.gen_key(input_data)
|
||||||
return
|
return
|
||||||
|
|
||||||
def dataDirEncrypt(self):
|
def dataDirEncrypt(self, password):
|
||||||
simplecrypt.encrypt()
|
# Encrypt data directory (don't delete it in this function)
|
||||||
|
if os.path.exists('data.tar'):
|
||||||
|
os.remove('data.tar')
|
||||||
|
tar = tarfile.open("data.tar", "w")
|
||||||
|
for name in ['data']:
|
||||||
|
tar.add(name)
|
||||||
|
tar.close()
|
||||||
|
tarData = open('data.tar', 'r', encoding = "ISO-8859-1").read()
|
||||||
|
encrypted = simplecrypt.encrypt(password, tarData)
|
||||||
|
open('data-encrypted.dat', 'wb').write(encrypted)
|
||||||
|
os.remove('data.tar')
|
||||||
return
|
return
|
||||||
|
def dataDirDecrypt(self, password):
|
||||||
|
# Decrypt data directory
|
||||||
|
if not os.path.exists('data-encrypted.dat'):
|
||||||
|
return (False, 'encrypted archive does not exist')
|
||||||
|
data = open('data-encrypted.dat', 'rb').read()
|
||||||
|
try:
|
||||||
|
decrypted = simplecrypt.decrypt(password, data)
|
||||||
|
except simplecrypt.DecryptionException:
|
||||||
|
return (False, 'wrong password')
|
||||||
|
else:
|
||||||
|
open('data.tar', 'wb').write(decrypted)
|
||||||
|
return (True, '')
|
||||||
def daemonQueue(self):
|
def daemonQueue(self):
|
||||||
# This function intended to be used by the client
|
# This function intended to be used by the client
|
||||||
# Queue to exchange data between "client" and server.
|
# Queue to exchange data between "client" and server.
|
||||||
|
26
tests.py
26
tests.py
@ -14,7 +14,7 @@
|
|||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
'''
|
'''
|
||||||
import unittest, sys, os, base64, tarfile, shutil
|
import unittest, sys, os, base64, tarfile, shutil, simplecrypt
|
||||||
|
|
||||||
class OnionrTests(unittest.TestCase):
|
class OnionrTests(unittest.TestCase):
|
||||||
def testPython3(self):
|
def testPython3(self):
|
||||||
@ -32,14 +32,26 @@ class OnionrTests(unittest.TestCase):
|
|||||||
self.assertTrue(False)
|
self.assertTrue(False)
|
||||||
else:
|
else:
|
||||||
self.assertTrue(True)
|
self.assertTrue(True)
|
||||||
def testDataEncrypt(self):
|
def testData_a_Encrypt(self):
|
||||||
testFile = open('data/test.txt', 'w')
|
print('--------------------------')
|
||||||
testFile.write("test data")
|
print('Running data dir encrypt test')
|
||||||
testFile.close()
|
|
||||||
import core
|
import core
|
||||||
myCore = Core.core()
|
myCore = core.Core()
|
||||||
|
myCore.dataDirEncrypt('password')
|
||||||
|
if os.path.exists('data-encrypted.dat'):
|
||||||
self.assertTrue(True)
|
self.assertTrue(True)
|
||||||
|
else:
|
||||||
|
self.assertTrue(False)
|
||||||
|
def testData_b_Decrypt(self):
|
||||||
|
print('--------------------------')
|
||||||
|
print('Running data dir decrypt test')
|
||||||
|
import core
|
||||||
|
myCore = core.Core()
|
||||||
|
myCore.dataDirDecrypt('password')
|
||||||
|
if os.path.exists('data.tar'):
|
||||||
|
self.assertTrue(True)
|
||||||
|
else:
|
||||||
|
self.assertTrue(False)
|
||||||
def testPGPGen(self):
|
def testPGPGen(self):
|
||||||
print('--------------------------')
|
print('--------------------------')
|
||||||
print('Testing PGP key generation')
|
print('Testing PGP key generation')
|
||||||
|
Loading…
Reference in New Issue
Block a user