work on adding peers

This commit is contained in:
Kevin Froman 2018-01-09 21:50:38 -06:00
parent 94c1368f72
commit 52fb4b139b
No known key found for this signature in database
GPG Key ID: 0D414D0FE405B63B
5 changed files with 74 additions and 16 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
__pycache__/ __pycache__/
data/config.ini data/config.ini
data/*.db data/*.db
dev-enabled

21
api.py
View File

@ -29,6 +29,11 @@ class API:
return True return True
def __init__(self, config, debug): def __init__(self, config, debug):
if os.path.exists('dev-enabled'):
print('DEVELOPMENT MODE ENABLED (THIS IS LESS SECURE!)')
self._developmentMode = True
else:
self._developmentMode = False
self.config = config self.config = config
self.debug = debug self.debug = debug
self._privateDelayTime = 3 self._privateDelayTime = 3
@ -91,7 +96,8 @@ class API:
# Public means it is publicly network accessible # Public means it is publicly network accessible
self.validateHost('public') self.validateHost('public')
action = request.args.get('action') action = request.args.get('action')
if action == 'firstConnect':
pass
@app.errorhandler(404) @app.errorhandler(404)
def notfound(err): def notfound(err):
@ -122,10 +128,9 @@ class API:
if not request.host.endswith('onion') and not request.hosst.endswith('i2p'): if not request.host.endswith('onion') and not request.hosst.endswith('i2p'):
abort(403) abort(403)
# Validate x-requested-with, to protect against CSRF/metadata leaks # Validate x-requested-with, to protect against CSRF/metadata leaks
''' if self._developmentMode:
try: try:
request.headers['x-requested-with'] request.headers['x-requested-with']
except: except:
# we exit rather than abort to avoid fingerprinting # we exit rather than abort to avoid fingerprinting
sys.exit(1) sys.exit(1)
'''

23
core.py
View File

@ -21,6 +21,8 @@ from Crypto import Random
class Core: class Core:
def __init__(self): def __init__(self):
self.queueDB = 'data/queue.db' self.queueDB = 'data/queue.db'
self.peerDB = 'data/peers.db'
#self.daemonQueue() # Call to create the DB if it doesn't exist #self.daemonQueue() # Call to create the DB if it doesn't exist
return return
@ -30,6 +32,27 @@ class Core:
input_data = gpg.gen_key_input(key_type="RSA", key_length=2048, name_real='anon', name_comment='Onionr key', name_email='anon@onionr') input_data = gpg.gen_key_input(key_type="RSA", key_length=2048, name_real='anon', name_comment='Onionr key', name_email='anon@onionr')
key = gpg.gen_key(input_data) key = gpg.gen_key(input_data)
return return
def addPeer(self, id, name=''):
# This function simply adds a peer to the DB
return
def createPeerDB(self):
# generate the peer database
conn = sqlite3.connect(self.peerDB)
c = conn.cursor()
c.execute('''
create table users(
ID text not null,
name text,
pgpKey text,
hmacKey text,
forwardKey text,
dateSeen not null,
trust int);
''')
conn.commit()
conn.close()
def dataDirEncrypt(self, password): def dataDirEncrypt(self, password):
# Encrypt data directory (don't delete it in this function) # Encrypt data directory (don't delete it in this function)

View File

@ -21,6 +21,11 @@ from colors import Colors
class Onionr: class Onionr:
def __init__(self): def __init__(self):
if os.path.exists('dev-enabled'):
print('DEVELOPMENT MODE ENABLED (THIS IS LESS SECURE!)')
self._developmentMode = True
else:
self._developmentMode = False
colors = Colors() colors = Colors()
@ -42,7 +47,12 @@ class Onionr:
else: else:
print('Failed to decrypt: ' + result[1]) print('Failed to decrypt: ' + result[1])
else: else:
os.mkdir('data') if not os.path.exists('data/'):
os.mkdir('data/')
if os.path.exists('data/peers.db'):
onionrCore.createPeerDB()
pass
# Get configuration # Get configuration
self.config = configparser.ConfigParser() self.config = configparser.ConfigParser()
@ -76,10 +86,11 @@ class Onionr:
print('Do', sys.argv[0], ' --help for Onionr help.') print('Do', sys.argv[0], ' --help for Onionr help.')
else: else:
print(colors.RED, 'Invalid Command', colors.RESET) print(colors.RED, 'Invalid Command', colors.RESET)
return
encryptionPassword = onionrUtils.getPassword('Enter password to encrypt directory.') if not self._developmentMode:
onionrCore.dataDirEncrypt(encryptionPassword) encryptionPassword = onionrUtils.getPassword('Enter password to encrypt directory.')
shutil.rmtree('data/') onionrCore.dataDirEncrypt(encryptionPassword)
shutil.rmtree('data/')
return return
def daemon(self): def daemon(self):
os.system('./communicator.py') os.system('./communicator.py')

View File

@ -32,7 +32,21 @@ class OnionrTests(unittest.TestCase):
self.assertTrue(False) self.assertTrue(False)
else: else:
self.assertTrue(True) self.assertTrue(True)
def testData_a_Encrypt(self): def testPeerDBCreation(self):
print('--------------------------')
print('Running peer db creation test')
if os.path.exists('data/peers.db'):
os.remove('data/peers.db')
import core
myCore = core.Core()
myCore.createPeerDB()
if os.path.exists('data/peers.db'):
self.assertTrue(True)
else:
self.assertTrue(False)
def testData_b_Encrypt(self):
self.assertTrue(True)
return
print('--------------------------') print('--------------------------')
print('Running data dir encrypt test') print('Running data dir encrypt test')
import core import core
@ -42,13 +56,15 @@ class OnionrTests(unittest.TestCase):
self.assertTrue(True) self.assertTrue(True)
else: else:
self.assertTrue(False) self.assertTrue(False)
def testData_b_Decrypt(self): def testData_a_Decrypt(self):
self.assertTrue(True)
return
print('--------------------------') print('--------------------------')
print('Running data dir decrypt test') print('Running data dir decrypt test')
import core import core
myCore = core.Core() myCore = core.Core()
myCore.dataDirDecrypt('password') myCore.dataDirDecrypt('password')
if os.path.exists('data.tar'): if os.path.exists('data/'):
self.assertTrue(True) self.assertTrue(True)
else: else:
self.assertTrue(False) self.assertTrue(False)
@ -69,6 +85,8 @@ class OnionrTests(unittest.TestCase):
# test if the daemon queue can read/write data # test if the daemon queue can read/write data
import core import core
myCore = core.Core() myCore = core.Core()
if not os.path.exists('data/queue.db'):
myCore.daemonQueue()
while True: while True:
command = myCore.daemonQueue() command = myCore.daemonQueue()
if command == False: if command == False: