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)
|
||||
return
|
||||
|
||||
def dataDirEncrypt(self):
|
||||
simplecrypt.encrypt()
|
||||
def dataDirEncrypt(self, password):
|
||||
# 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
|
||||
|
||||
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):
|
||||
# This function intended to be used by the client
|
||||
# Queue to exchange data between "client" and server.
|
||||
|
28
tests.py
28
tests.py
@ -14,7 +14,7 @@
|
||||
You should have received a copy of the GNU General Public License
|
||||
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):
|
||||
def testPython3(self):
|
||||
@ -32,14 +32,26 @@ class OnionrTests(unittest.TestCase):
|
||||
self.assertTrue(False)
|
||||
else:
|
||||
self.assertTrue(True)
|
||||
def testDataEncrypt(self):
|
||||
testFile = open('data/test.txt', 'w')
|
||||
testFile.write("test data")
|
||||
testFile.close()
|
||||
def testData_a_Encrypt(self):
|
||||
print('--------------------------')
|
||||
print('Running data dir encrypt test')
|
||||
import core
|
||||
myCore = Core.core()
|
||||
|
||||
self.assertTrue(True)
|
||||
myCore = core.Core()
|
||||
myCore.dataDirEncrypt('password')
|
||||
if os.path.exists('data-encrypted.dat'):
|
||||
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):
|
||||
print('--------------------------')
|
||||
print('Testing PGP key generation')
|
||||
|
Loading…
Reference in New Issue
Block a user