signed blocks related crashes fixed hopefully

master
Kevin Froman 2018-04-26 20:15:30 -05:00
parent 3cba6b30c7
commit 8a9d1326fb
No known key found for this signature in database
GPG Key ID: 0D414D0FE405B63B
3 changed files with 19 additions and 8 deletions

View File

@ -262,7 +262,8 @@ class OnionrCommunicate:
# deal with block metadata # deal with block metadata
blockContent = self._core.getData(i) blockContent = self._core.getData(i)
try: try:
blockMetadata = json.loads(self._core.getData(i)).split('}')[0] + '}' #blockMetadata = json.loads(self._core.getData(i)).split('}')[0] + '}'
blockMetadata = json.loads(self._core.getData(i).split(b'}')[0] + b'}')
try: try:
blockMetadata['sig'] blockMetadata['sig']
blockMetadata['id'] blockMetadata['id']
@ -270,15 +271,18 @@ class OnionrCommunicate:
pass pass
else: else:
creator = self._utils.getPeerByHashId(blockMetadata['id']) creator = self._utils.getPeerByHashId(blockMetadata['id'])
if self._crypto.edVerify(blockContent, creator): if self._crypto.edVerify(blockContent.split(b'}')[1], creator, blockMetadata['sig'], encodedData=True):
self._core.updateBlockInfo(i, 'sig', 'true') self._core.updateBlockInfo(i, 'sig', 'true')
else: else:
self._core.updateBlockInfo(i, 'sig', 'false') self._core.updateBlockInfo(i, 'sig', 'false')
try: try:
blockMetadata['type'] logger.info('Block type is ' + blockMetadata['type'])
self._core.updateBlockInfo(i, 'dataType', blockMetadata['type'])
except KeyError: except KeyError:
logger.warn('Block has no type')
pass pass
except json.decoder.JSONDecodeError: except json.decoder.JSONDecodeError:
logger.warn('Could not decode block metadata')
pass pass
return return
@ -312,6 +316,7 @@ class OnionrCommunicate:
self._core.setData(data) self._core.setData(data)
logger.info('Successfully obtained data for ' + hash, timestamp=True) logger.info('Successfully obtained data for ' + hash, timestamp=True)
retVal = True retVal = True
break
''' '''
if data.startswith(b'-txt-'): if data.startswith(b'-txt-'):
self._core.setBlockType(hash, 'txt') self._core.setBlockType(hash, 'txt')

View File

@ -47,7 +47,10 @@ class OnionrCrypto:
key = nacl.signing.VerifyKey(key=key, encoder=nacl.encoding.Base32Encoder) key = nacl.signing.VerifyKey(key=key, encoder=nacl.encoding.Base32Encoder)
retData = False retData = False
sig = base64.b64decode(sig) sig = base64.b64decode(sig)
data = data.encode() try:
data = data.encode()
except AttributeError:
pass
if encodedData: if encodedData:
try: try:
retData = key.verify(data, sig) # .encode() is not the same as nacl.encoding retData = key.verify(data, sig) # .encode() is not the same as nacl.encoding

View File

@ -337,11 +337,12 @@ class OnionrUtils:
try: try:
sig = json.loads(data[0].strip() + '}')['sig'] sig = json.loads(data[0].strip() + '}')['sig']
signer = self._core._utils.getPeerByHashId(metadata['id']) signer = self._core._utils.getPeerByHashId(metadata['id'])
print('signer',signer) logger.debug('signer ' + signer)
print('signature', metadata['sig']) logger.debug('signature ' + metadata['sig'])
except KeyError: except KeyError:
pass pass
else: else:
# TODO: Possible refactor to use verification on proccessblocks
sigResult = self._core._crypto.edVerify(message, signer, sig, encodedData=True) sigResult = self._core._crypto.edVerify(message, signer, sig, encodedData=True)
#sigResult = False #sigResult = False
if sigResult != False: if sigResult != False:
@ -355,7 +356,10 @@ class OnionrUtils:
logger.error('Unable to decrypt ' + i, error=e) logger.error('Unable to decrypt ' + i, error=e)
else: else:
logger.info('Recieved message: ' + message.decode()) logger.info('Recieved message: ' + message.decode())
logger.info(sigResult) if sigResult.startswith('Invalid'):
logger.warn(sigResult)
else:
logger.info(sigResult)
except FileNotFoundError: except FileNotFoundError:
pass pass
except Exception as error: except Exception as error:
@ -373,7 +377,6 @@ class OnionrUtils:
c = conn.cursor() c = conn.cursor()
command = (hash,) command = (hash,)
retData = '' retData = ''
print('finding', hash)
for row in c.execute('SELECT ID FROM peers where hashID=?', command): for row in c.execute('SELECT ID FROM peers where hashID=?', command):
if row[0] != '': if row[0] != '':
retData = row[0] retData = row[0]