finished encrypt/decryption of data

master
Kevin Froman 2018-01-09 16:58:12 -06:00
parent bfe16ee2b0
commit 94c1368f72
No known key found for this signature in database
GPG Key ID: 0D414D0FE405B63B
3 changed files with 56 additions and 5 deletions

View File

@ -52,9 +52,12 @@ class Core:
try:
decrypted = simplecrypt.decrypt(password, data)
except simplecrypt.DecryptionException:
return (False, 'wrong password')
return (False, 'wrong password (or corrupted archive)')
else:
open('data.tar', 'wb').write(decrypted)
tar = tarfile.open('data.tar')
tar.extractall()
tar.close()
return (True, '')
def daemonQueue(self):
# This function intended to be used by the client

View File

@ -14,8 +14,9 @@
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 sys, os, threading, configparser, base64, random
import gui, api, colors
import sys, os, threading, configparser, base64, random, getpass, shutil
import gui, api, colors, core
from onionrutils import OnionrUtils
from colors import Colors
class Onionr:
@ -23,13 +24,24 @@ class Onionr:
colors = Colors()
onionrCore = core.Core()
onionrUtils = OnionrUtils()
# Get configuration and Handle commands
self.debug = False # Whole application debugging
os.chdir(sys.path[0])
if not os.path.exists('data'):
if os.path.exists('data-encrypted.dat'):
while True:
print('Enter password to decrypt:')
password = getpass.getpass()
result = onionrCore.dataDirDecrypt(password)
if os.path.exists('data/'):
break
else:
print('Failed to decrypt: ' + result[1])
else:
os.mkdir('data')
# Get configuration
@ -65,6 +77,9 @@ class Onionr:
else:
print(colors.RED, 'Invalid Command', colors.RESET)
return
encryptionPassword = onionrUtils.getPassword('Enter password to encrypt directory.')
onionrCore.dataDirEncrypt(encryptionPassword)
shutil.rmtree('data/')
return
def daemon(self):
os.system('./communicator.py')

33
onionrutils.py Normal file
View File

@ -0,0 +1,33 @@
'''
Onionr - P2P Microblogging Platform & Social network
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
'''
# Misc functions that do not fit in the main api, but are useful
import getpass
class OnionrUtils():
def __init__(self):
return
def getPassword(self, message='Enter password: '):
# Get a password safely with confirmation and return it
while True:
print(message)
pass1 = getpass.getpass()
print('Confirm password: ')
pass2 = getpass.getpass()
if pass1 != pass2:
print("Passwords do not match.")
input()
else:
break
return pass1