signed blocks related crashes fixed hopefully
This commit is contained in:
parent
3cba6b30c7
commit
8a9d1326fb
@ -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')
|
||||||
|
@ -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)
|
||||||
|
try:
|
||||||
data = data.encode()
|
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
|
||||||
|
@ -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,6 +356,9 @@ 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())
|
||||||
|
if sigResult.startswith('Invalid'):
|
||||||
|
logger.warn(sigResult)
|
||||||
|
else:
|
||||||
logger.info(sigResult)
|
logger.info(sigResult)
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
pass
|
pass
|
||||||
@ -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]
|
||||||
|
Loading…
Reference in New Issue
Block a user