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
blockContent = self._core.getData(i)
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:
blockMetadata['sig']
blockMetadata['id']
@ -270,15 +271,18 @@ class OnionrCommunicate:
pass
else:
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')
else:
self._core.updateBlockInfo(i, 'sig', 'false')
try:
blockMetadata['type']
logger.info('Block type is ' + blockMetadata['type'])
self._core.updateBlockInfo(i, 'dataType', blockMetadata['type'])
except KeyError:
logger.warn('Block has no type')
pass
except json.decoder.JSONDecodeError:
logger.warn('Could not decode block metadata')
pass
return
@ -312,6 +316,7 @@ class OnionrCommunicate:
self._core.setData(data)
logger.info('Successfully obtained data for ' + hash, timestamp=True)
retVal = True
break
'''
if data.startswith(b'-txt-'):
self._core.setBlockType(hash, 'txt')

View File

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

View File

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