edited spec, added hmac generation function + test
This commit is contained in:
parent
45eb94d759
commit
19bab6a3c6
4 changed files with 30 additions and 15 deletions
|
@ -1,7 +1,7 @@
|
|||
#!/usr/bin/env python3
|
||||
'''
|
||||
Onionr - P2P Microblogging Platform & Social network.
|
||||
|
||||
Onionr - P2P Microblogging Platform & Social network.
|
||||
|
||||
This file contains both the OnionrCommunicate class for communcating with peers
|
||||
and code to operate as a daemon, getting commands from the command queue database (see core.Core.daemonQueue)
|
||||
'''
|
||||
|
@ -39,7 +39,7 @@ class OnionrCommunicate:
|
|||
return
|
||||
def getRemotePeerKey(self, peerID):
|
||||
'''This function contacts a peer and gets their main PGP key.
|
||||
|
||||
|
||||
This is safe because Tor or I2P is used, but it does not ensure that the person is who they say they are
|
||||
'''
|
||||
url = 'http://' + peerID + '/public/?action=getPGP'
|
||||
|
@ -70,4 +70,4 @@ if shouldRun:
|
|||
try:
|
||||
OnionrCommunicate(debug, developmentMode)
|
||||
except KeyboardInterrupt:
|
||||
pass
|
||||
pass
|
||||
|
|
|
@ -34,7 +34,7 @@ class Core:
|
|||
return
|
||||
|
||||
def generateMainPGP(self):
|
||||
''' Generate the main PGP key for our client. Should not be done often.
|
||||
''' Generate the main PGP key for our client. Should not be done often.
|
||||
Uses own PGP home folder in the data/ directory. '''
|
||||
# Generate main pgp key
|
||||
gpg = gnupg.GPG(homedir='data/pgp/')
|
||||
|
@ -49,7 +49,7 @@ class Core:
|
|||
conn = sqlite3.connect(self.peerDB)
|
||||
c = conn.cursor()
|
||||
t = (peerID, name, 'unknown')
|
||||
c.execute('Insert into users (id, name, dateSeen) values(?, ?, ?);', t)
|
||||
c.execute('Insert into peers (id, name, dateSeen) values(?, ?, ?);', t)
|
||||
conn.commit()
|
||||
conn.close()
|
||||
return True
|
||||
|
@ -62,7 +62,7 @@ class Core:
|
|||
conn = sqlite3.connect(self.peerDB)
|
||||
c = conn.cursor()
|
||||
c.execute('''
|
||||
create table users(
|
||||
create table peers(
|
||||
ID text not null,
|
||||
name text,
|
||||
pgpKey text,
|
||||
|
@ -74,7 +74,7 @@ class Core:
|
|||
''')
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
|
||||
def dataDirEncrypt(self, password):
|
||||
'''
|
||||
Encrypt the data directory on Onionr shutdown
|
||||
|
@ -149,9 +149,10 @@ class Core:
|
|||
conn.commit()
|
||||
conn.close()
|
||||
return
|
||||
|
||||
|
||||
def generateHMAC(self):
|
||||
'''
|
||||
generate and return an HMAC key
|
||||
'''
|
||||
return
|
||||
key = base64.b64encode(os.urandom(32))
|
||||
return key
|
||||
|
|
|
@ -90,6 +90,17 @@ class OnionrTests(unittest.TestCase):
|
|||
myCore.generateMainPGP()
|
||||
if os.path.exists('data/pgp/'):
|
||||
self.assertTrue(True)
|
||||
def testHMACGen(self):
|
||||
print('--------------------------')
|
||||
print('running daemon queue test')
|
||||
# Test if hmac key generation is working
|
||||
import core
|
||||
myCore = core.Core()
|
||||
key = myCore.generateHMAC()
|
||||
if len(key) > 10:
|
||||
self.assertTrue(True)
|
||||
else:
|
||||
self.assertTrue(False)
|
||||
def testQueue(self):
|
||||
print('--------------------------')
|
||||
print('running daemon queue test')
|
||||
|
@ -110,4 +121,4 @@ class OnionrTests(unittest.TestCase):
|
|||
if command[0] == 'testCommand':
|
||||
if myCore.daemonQueue() == False:
|
||||
print('Succesfully added and read command')
|
||||
unittest.main()
|
||||
unittest.main()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue