hopefully fixed everything for new sig format
This commit is contained in:
parent
ff5bdd62f2
commit
908ccbe664
@ -550,37 +550,36 @@ class OnionrCommunicate:
|
||||
blockContent = self._core.getData(i)
|
||||
try:
|
||||
#blockMetadata = json.loads(self._core.getData(i)).split('}')[0] + '}'
|
||||
blockMetadata = self._core.getData(i)
|
||||
blockMetadata = json.loads(blockMetadata[:blockMetadata.rfind(b'}') + 1])
|
||||
blockMetadata = json.loads(blockContent[:blockContent.rfind(b'}') + 1])
|
||||
try:
|
||||
blockMetadata = blockMetadata.decode()
|
||||
except AttributeError:
|
||||
blockMeta2 = json.loads(blockMetadata['meta'])
|
||||
except KeyError:
|
||||
blockMeta2 = {'type': ''}
|
||||
pass
|
||||
|
||||
#blockMetadata = json.loads(blockMetadata + '}')
|
||||
|
||||
blockContent = blockContent[blockContent.rfind(b'}') + 1:]
|
||||
try:
|
||||
blockMetadata['sig']
|
||||
blockMetadata['meta']['id']
|
||||
blockMeta2['id']
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
else:
|
||||
blockData = json.dumps(blockMetadata['meta']) + blockMetadata[blockMetadata.rfind(b'}') + 1:]
|
||||
#blockData = json.dumps(blockMetadata['meta']) + blockMetadata[blockMetadata.rfind(b'}') + 1:]
|
||||
|
||||
creator = self._utils.getPeerByHashId(blockMetadata['meta']['id'])
|
||||
creator = self._utils.getPeerByHashId(blockMeta2['id'])
|
||||
try:
|
||||
creator = creator.decode()
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
if self._core._crypto.edVerify(blockContent.split(b'}')[1], creator, blockMetadata['sig'], encodedData=True):
|
||||
if self._core._crypto.edVerify(blockMetaData['meta'] + blockContent, creator, blockMetadata['sig'], encodedData=True):
|
||||
logger.info(i + ' was signed')
|
||||
self._core.updateBlockInfo(i, 'sig', 'true')
|
||||
else:
|
||||
logger.warn(i + ' has an invalid signature')
|
||||
self._core.updateBlockInfo(i, 'sig', 'false')
|
||||
try:
|
||||
logger.info('Block type is ' + blockMetadata['type'])
|
||||
self._core.updateBlockInfo(i, 'dataType', blockMetadata['type'])
|
||||
logger.info('Block type is ' + blockMeta2['type'])
|
||||
self._core.updateBlockInfo(i, 'dataType', blockMeta2['type'])
|
||||
self.removeBlockFromProcessingList(i)
|
||||
self.removeBlockFromProcessingList(i)
|
||||
except KeyError:
|
||||
|
@ -641,6 +641,7 @@ class Core:
|
||||
|
||||
metadata = json.dumps(metadata)
|
||||
metadata = metadata.encode()
|
||||
signature = ''
|
||||
|
||||
if sign:
|
||||
signature = self._crypto.edSign(metadata + data, self._crypto.privKey, encodeResult=True)
|
||||
@ -650,9 +651,9 @@ class Core:
|
||||
ourID = ourID.decode()
|
||||
except AttributeError:
|
||||
pass
|
||||
metadata = {'sig': signature, 'meta': metadata.decode()}
|
||||
metadata = json.dumps(metadata)
|
||||
metadata = metadata.encode()
|
||||
metadata = {'sig': signature, 'meta': metadata.decode()}
|
||||
metadata = json.dumps(metadata)
|
||||
metadata = metadata.encode()
|
||||
|
||||
if len(data) == 0:
|
||||
logger.error('Will not insert empty block')
|
||||
|
@ -336,6 +336,41 @@ class OnionrUtils:
|
||||
continue
|
||||
try:
|
||||
with open('data/blocks/' + i + '.dat', 'r') as potentialMessage:
|
||||
potentialMessage = potentialMessage.read()
|
||||
blockMetadata = json.loads(potentialMessage[:potentialMessage.rfind('}') + 1])
|
||||
blockContent = potentialMessage[potentialMessage.rfind('}') + 1:]
|
||||
|
||||
try:
|
||||
message = self._core._crypto.pubKeyDecrypt(blockContent, encodedData=True, anonymous=True)
|
||||
except nacl.exceptions.CryptoError as e:
|
||||
pass
|
||||
else:
|
||||
try:
|
||||
message = message.decode()
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
try:
|
||||
message = json.loads(message)
|
||||
except json.decoder.JSONDecodeError:
|
||||
pass
|
||||
else:
|
||||
print('--------------------')
|
||||
logger.info('Decrypted ' + i + ':')
|
||||
logger.info(message["msg"])
|
||||
|
||||
signer = message["id"]
|
||||
sig = message["sig"]
|
||||
|
||||
if self.validatePubKey(signer):
|
||||
if self._core._crypto.edVerify(message["msg"], signer, sig, encodedData=True):
|
||||
logger.info("Good signature by " + signer)
|
||||
else:
|
||||
logger.warn("Bad signature by " + signer)
|
||||
else:
|
||||
logger.warn("Bad sender id: " + signer)
|
||||
|
||||
'''
|
||||
data = potentialMessage.read().split('}')
|
||||
message = data[1]
|
||||
sigResult = ''
|
||||
@ -345,14 +380,6 @@ class OnionrUtils:
|
||||
metadata = json.loads(data[0] + '}')
|
||||
except json.decoder.JSONDecodeError:
|
||||
metadata = {}
|
||||
'''
|
||||
sigResult = self._core._crypto.edVerify(message, signer, sig, encodedData=True)
|
||||
#sigResult = False
|
||||
if sigResult != False:
|
||||
sigResult = 'Valid signature by ' + signer
|
||||
else:
|
||||
sigResult = 'Invalid signature by ' + signer
|
||||
'''
|
||||
|
||||
try:
|
||||
message = self._core._crypto.pubKeyDecrypt(message, encodedData=True, anonymous=True)
|
||||
@ -378,6 +405,7 @@ class OnionrUtils:
|
||||
logger.info('Valid signature by ' + message['id'])
|
||||
else:
|
||||
logger.warn('Invalid signature by ' + message['id'])
|
||||
'''
|
||||
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
|
Loading…
Reference in New Issue
Block a user