work on metadata, forward secrecy, and starting on sockets

master
Kevin Froman 2018-09-13 12:26:22 -05:00
parent 1c2a8a2f40
commit ee2a74380b
No known key found for this signature in database
GPG Key ID: 0D414D0FE405B63B
5 changed files with 61 additions and 6 deletions

View File

@ -48,6 +48,7 @@ class Core:
self.torPort = torPort self.torPort = torPort
self.dataNonceFile = 'data/block-nonces.dat' self.dataNonceFile = 'data/block-nonces.dat'
self.dbCreate = dbcreator.DBCreator(self) self.dbCreate = dbcreator.DBCreator(self)
self.forwardKeysFile = 'data/forward-keys.db'
self.usageFile = 'data/disk-usage.txt' self.usageFile = 'data/disk-usage.txt'
self.config = config self.config = config

View File

@ -71,7 +71,9 @@ class DBCreator:
c.execute('''CREATE TABLE forwardKeys( c.execute('''CREATE TABLE forwardKeys(
peerKey text not null, peerKey text not null,
forwardKey text not null, forwardKey text not null,
date int not null);''') date int not null,
expire int not null
);''')
conn.commit() conn.commit()
conn.close() conn.close()
return return
@ -109,3 +111,23 @@ class DBCreator:
conn.commit() conn.commit()
conn.close() conn.close()
return return
def createForwardKeyDB(self):
'''
Create the forward secrecy key db (*for *OUR* keys*)
'''
if os.path.exists(self.core.forwardKeysFile):
raise Exception("Block database already exists")
conn = sqlite3.connect(self.core.forwardKeysFile)
c = conn.cursor()
c.execute('''CREATE TABLE myForwardKeys(
peer text not null,
public key text not null,
private key text not null,
date int not null,
expire int not null
);
''')
conn.commit()
conn.close()
return

View File

@ -93,6 +93,26 @@ class OnionrUser:
return list(keyList) return list(keyList)
def generateForwardKey(self, expire=432000):
# Generate a forward secrecy key for the peer
conn = sqlite3.connect(self._core.forwardKeysFile)
c = conn.cursor()
# Prepare the insert
time = self._core._utils.getEpoch()
newKeys = self._core._crypto.generatePubKey()
newPub = newKeys[0]
newPriv = newKeys[1]
time = self._core._utils.getEpoch()
command = (self.publicKey, newPub, newPriv, time, expire)
c.execute("INSERT INTO myForwardKeys VALUES(?, ?, ?, ?);", command)
conn.commit()
conn.close()
def addForwardKey(self, newKey): def addForwardKey(self, newKey):
if not self._core._utils.validatePubKey(newKey): if not self._core._utils.validatePubKey(newKey):
raise onionrexceptions.InvalidPubkey raise onionrexceptions.InvalidPubkey

View File

@ -265,11 +265,12 @@ class OnionrUtils:
myBlock.decrypt() myBlock.decrypt()
blockType = myBlock.getMetadata('type') # we would use myBlock.getType() here, but it is bugged with encrypted blocks blockType = myBlock.getMetadata('type') # we would use myBlock.getType() here, but it is bugged with encrypted blocks
signer = self.bytesToStr(myBlock.signer) signer = self.bytesToStr(myBlock.signer)
valid = myBlock.verifySig()
try: try:
if len(blockType) <= 10: if len(blockType) <= 10:
self._core.updateBlockInfo(blockHash, 'dataType', blockType) self._core.updateBlockInfo(blockHash, 'dataType', blockType)
onionrevents.event('processBlocks', data = {'block': myBlock, 'type': blockType}, onionr = None) onionrevents.event('processBlocks', data = {'block': myBlock, 'type': blockType, 'signer': signer, 'validSig': valid}, onionr = None)
except TypeError: except TypeError:
pass pass

View File

@ -22,7 +22,7 @@
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 import onionrusers, onionrexceptions
plugin_name = 'metadataprocessor' plugin_name = 'metadataprocessor'
@ -50,6 +50,13 @@ def _processForwardKey(api, myBlock):
Get the forward secrecy key specified by the user for us to use Get the forward secrecy key specified by the user for us to use
''' '''
peer = onionrusers.OnionrUser(self.api.get_core(), myBlock.signer) peer = onionrusers.OnionrUser(self.api.get_core(), myBlock.signer)
key = myBlock.getMetadata('newFSKey')
# We don't need to validate here probably, but it helps
if api.get_utils().validatePubKey(key):
peer.addForwardKey(key)
else:
raise onionrexceptions.InvalidPubkey("%s is nota valid pubkey key" % (key,))
def on_processBlocks(api): def on_processBlocks(api):
myBlock = api.data['block'] myBlock = api.data['block']
@ -60,12 +67,16 @@ def on_processBlocks(api):
# userInfo blocks, such as for setting username # userInfo blocks, such as for setting username
if blockType == 'userInfo': if blockType == 'userInfo':
if myBlock.verifySig(): if api.data['validSig']:
_processUserInfo(api, myBlock) _processUserInfo(api, myBlock)
# forwardKey blocks # forwardKey blocks, add a new forward secrecy key for a peer
elif blockType == 'forwardKey': elif blockType == 'forwardKey':
if myBlock.verifySig(): if api.data['validSig']:
_processForwardKey(api, myBlock) _processForwardKey(api, myBlock)
# socket blocks
elif blockType == 'openSocket':
if api.data['validSig']:
pass
def on_init(api, data = None): def on_init(api, data = None):