work on forward secrecy

This commit is contained in:
Kevin Froman 2018-09-11 14:45:06 -05:00
parent ce2423e6d9
commit d151e0d302
5 changed files with 60 additions and 21 deletions

1
.gitignore vendored
View File

@ -13,3 +13,4 @@ onionr/data-encrypted.dat
onionr/.onionr-lock onionr/.onionr-lock
core core
.vscode/* .vscode/*
venv/*

View File

@ -472,18 +472,17 @@ class Core:
id text 0 id text 0
name text, 1 name text, 1
adders text, 2 adders text, 2
forwardKey text, 3 dateSeen not null, 3
dateSeen not null, 4 bytesStored int, 4
bytesStored int, 5 trust int 5
trust int 6 pubkeyExchanged int 6
pubkeyExchanged int 7 hashID text 7
hashID text 8 pow text 8
pow text 9
''' '''
conn = sqlite3.connect(self.peerDB) conn = sqlite3.connect(self.peerDB)
c = conn.cursor() c = conn.cursor()
command = (peer,) command = (peer,)
infoNumbers = {'id': 0, 'name': 1, 'adders': 2, 'forwardKey': 3, 'dateSeen': 4, 'bytesStored': 5, 'trust': 6, 'pubkeyExchanged': 7, 'hashID': 8} infoNumbers = {'id': 0, 'name': 1, 'adders': 2, 'dateSeen': 3, 'bytesStored': 4, 'trust': 5, 'pubkeyExchanged': 6, 'hashID': 7}
info = infoNumbers[info] info = infoNumbers[info]
iterCount = 0 iterCount = 0
retVal = '' retVal = ''

View File

@ -61,7 +61,6 @@ class DBCreator:
ID text not null, ID text not null,
name text, name text,
adders text, adders text,
forwardKey text,
dateSeen not null, dateSeen not null,
bytesStored int, bytesStored int,
trust int, trust int,
@ -69,6 +68,10 @@ class DBCreator:
hashID text, hashID text,
pow text not null); pow text not null);
''') ''')
c.execute('''CREATE TABLE forwardKeys(
peerKey text not null,
forwardKey text not null,
date int not null);''')
conn.commit() conn.commit()
conn.close() conn.close()
return return

View File

@ -17,7 +17,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. along with this program. If not, see <https://www.gnu.org/licenses/>.
''' '''
import onionrblockapi, logger, onionrexceptions, json import onionrblockapi, logger, onionrexceptions, json, sqlite3
class OnionrUser: class OnionrUser:
def __init__(self, coreInst, publicKey): def __init__(self, coreInst, publicKey):
self.trust = 0 self.trust = 0
@ -60,6 +60,20 @@ class OnionrUser:
def forwardDecrypt(self, encrypted): def forwardDecrypt(self, encrypted):
return return
def addForwardKey(self, newKey):
# Add a forward secrecy key for the peer
conn = sqlite3.connect(self._core.peerDB)
c = conn.cursor()
# Prepare the insert
time = self._core._utils.getEpoch()
command = (self.publicKey, newKey, time)
c.execute("INSERT INTO forwardKeys VALUES(?, ?, ?);", command)
conn.commit()
conn.close()
return
def findAndSetID(self): def findAndSetID(self):
'''Find any info about the user from existing blocks and cache it to their DB entry''' '''Find any info about the user from existing blocks and cache it to their DB entry'''
infoBlocks = [] infoBlocks = []

View File

@ -22,28 +22,50 @@
import logger, config import logger, config
import os, sys, json, time, random, shutil, base64, getpass, datetime, re import os, sys, json, time, random, shutil, base64, getpass, datetime, re
from onionrblockapi import Block from onionrblockapi import Block
import onionrusers
plugin_name = 'metadataprocessor' plugin_name = 'metadataprocessor'
# event listeners # event listeners
def _processUserInfo(api, newBlock):
'''
Set the username for a particular user, from a signed block by them
'''
myBlock = newBlock
peerName = myBlock.getMetadata('name')
try:
if len(peerName) > 20:
raise onionrexceptions.InvalidMetdata('Peer name specified is too large')
except TypeError:
pass
except onionrexceptions.InvalidMetadata:
pass
else:
api.get_core().setPeerInfo(signer, 'name', peerName)
logger.info('%s is now using the name %s.' % (signer, api.get_utils().escapeAnsi(peerName)))
def _processForwardKey(api, myBlock):
'''
Get the forward secrecy key specified by the user for us to use
'''
peer = onionrusers.OnionrUser(self.api.get_core(), myBlock.signer)
def on_processBlocks(api): def on_processBlocks(api):
myBlock = api.data['block'] myBlock = api.data['block']
blockType = api.data['type'] blockType = api.data['type']
print('blockType is ' + blockType) print('blockType is ' + blockType)
# Process specific block types
# userInfo blocks, such as for setting username
if blockType == 'userInfo': if blockType == 'userInfo':
if myBlock.verifySig(): if myBlock.verifySig():
peerName = myBlock.getMetadata('name') _processUserInfo(api, myBlock)
try: # forwardKey blocks
if len(peerName) > 20: elif blockType == 'forwardKey':
raise onionrexceptions.InvalidMetdata('Peer name specified is too large') if myBlock.verifySig():
except TypeError: _processForwardKey(api, myBlock)
pass
except onionrexceptions.InvalidMetadata:
pass
else:
api.get_core().setPeerInfo(signer, 'name', peerName)
logger.info('%s is now using the name %s.' % (signer, api.get_utils().escapeAnsi(peerName)))
def on_init(api, data = None): def on_init(api, data = None):