work on adding peers
This commit is contained in:
parent
94c1368f72
commit
52fb4b139b
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,4 @@
|
||||
__pycache__/
|
||||
data/config.ini
|
||||
data/*.db
|
||||
dev-enabled
|
11
api.py
11
api.py
@ -29,6 +29,11 @@ class API:
|
||||
return True
|
||||
|
||||
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.debug = debug
|
||||
self._privateDelayTime = 3
|
||||
@ -91,7 +96,8 @@ class API:
|
||||
# Public means it is publicly network accessible
|
||||
self.validateHost('public')
|
||||
action = request.args.get('action')
|
||||
|
||||
if action == 'firstConnect':
|
||||
pass
|
||||
|
||||
@app.errorhandler(404)
|
||||
def notfound(err):
|
||||
@ -122,10 +128,9 @@ class API:
|
||||
if not request.host.endswith('onion') and not request.hosst.endswith('i2p'):
|
||||
abort(403)
|
||||
# Validate x-requested-with, to protect against CSRF/metadata leaks
|
||||
'''
|
||||
if self._developmentMode:
|
||||
try:
|
||||
request.headers['x-requested-with']
|
||||
except:
|
||||
# we exit rather than abort to avoid fingerprinting
|
||||
sys.exit(1)
|
||||
'''
|
23
core.py
23
core.py
@ -21,6 +21,8 @@ from Crypto import Random
|
||||
class Core:
|
||||
def __init__(self):
|
||||
self.queueDB = 'data/queue.db'
|
||||
self.peerDB = 'data/peers.db'
|
||||
|
||||
#self.daemonQueue() # Call to create the DB if it doesn't exist
|
||||
return
|
||||
|
||||
@ -31,6 +33,27 @@ class Core:
|
||||
key = gpg.gen_key(input_data)
|
||||
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):
|
||||
# Encrypt data directory (don't delete it in this function)
|
||||
if os.path.exists('data.tar'):
|
||||
|
15
onionr.py
15
onionr.py
@ -21,6 +21,11 @@ from colors import Colors
|
||||
|
||||
class Onionr:
|
||||
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()
|
||||
|
||||
@ -42,7 +47,12 @@ class Onionr:
|
||||
else:
|
||||
print('Failed to decrypt: ' + result[1])
|
||||
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
|
||||
self.config = configparser.ConfigParser()
|
||||
@ -76,7 +86,8 @@ class Onionr:
|
||||
print('Do', sys.argv[0], ' --help for Onionr help.')
|
||||
else:
|
||||
print(colors.RED, 'Invalid Command', colors.RESET)
|
||||
return
|
||||
|
||||
if not self._developmentMode:
|
||||
encryptionPassword = onionrUtils.getPassword('Enter password to encrypt directory.')
|
||||
onionrCore.dataDirEncrypt(encryptionPassword)
|
||||
shutil.rmtree('data/')
|
||||
|
24
tests.py
24
tests.py
@ -32,7 +32,21 @@ class OnionrTests(unittest.TestCase):
|
||||
self.assertTrue(False)
|
||||
else:
|
||||
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('Running data dir encrypt test')
|
||||
import core
|
||||
@ -42,13 +56,15 @@ class OnionrTests(unittest.TestCase):
|
||||
self.assertTrue(True)
|
||||
else:
|
||||
self.assertTrue(False)
|
||||
def testData_b_Decrypt(self):
|
||||
def testData_a_Decrypt(self):
|
||||
self.assertTrue(True)
|
||||
return
|
||||
print('--------------------------')
|
||||
print('Running data dir decrypt test')
|
||||
import core
|
||||
myCore = core.Core()
|
||||
myCore.dataDirDecrypt('password')
|
||||
if os.path.exists('data.tar'):
|
||||
if os.path.exists('data/'):
|
||||
self.assertTrue(True)
|
||||
else:
|
||||
self.assertTrue(False)
|
||||
@ -69,6 +85,8 @@ class OnionrTests(unittest.TestCase):
|
||||
# test if the daemon queue can read/write data
|
||||
import core
|
||||
myCore = core.Core()
|
||||
if not os.path.exists('data/queue.db'):
|
||||
myCore.daemonQueue()
|
||||
while True:
|
||||
command = myCore.daemonQueue()
|
||||
if command == False:
|
||||
|
Loading…
Reference in New Issue
Block a user