hopefully fixed everything for new sig format
parent
ff5bdd62f2
commit
908ccbe664
|
@ -550,37 +550,36 @@ class OnionrCommunicate:
|
||||||
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 = self._core.getData(i)
|
blockMetadata = json.loads(blockContent[:blockContent.rfind(b'}') + 1])
|
||||||
blockMetadata = json.loads(blockMetadata[:blockMetadata.rfind(b'}') + 1])
|
|
||||||
try:
|
try:
|
||||||
blockMetadata = blockMetadata.decode()
|
blockMeta2 = json.loads(blockMetadata['meta'])
|
||||||
except AttributeError:
|
except KeyError:
|
||||||
|
blockMeta2 = {'type': ''}
|
||||||
pass
|
pass
|
||||||
|
blockContent = blockContent[blockContent.rfind(b'}') + 1:]
|
||||||
#blockMetadata = json.loads(blockMetadata + '}')
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
blockMetadata['sig']
|
blockMetadata['sig']
|
||||||
blockMetadata['meta']['id']
|
blockMeta2['id']
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
else:
|
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:
|
try:
|
||||||
creator = creator.decode()
|
creator = creator.decode()
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
pass
|
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')
|
self._core.updateBlockInfo(i, 'sig', 'true')
|
||||||
else:
|
else:
|
||||||
|
logger.warn(i + ' has an invalid signature')
|
||||||
self._core.updateBlockInfo(i, 'sig', 'false')
|
self._core.updateBlockInfo(i, 'sig', 'false')
|
||||||
try:
|
try:
|
||||||
logger.info('Block type is ' + blockMetadata['type'])
|
logger.info('Block type is ' + blockMeta2['type'])
|
||||||
self._core.updateBlockInfo(i, 'dataType', blockMetadata['type'])
|
self._core.updateBlockInfo(i, 'dataType', blockMeta2['type'])
|
||||||
self.removeBlockFromProcessingList(i)
|
self.removeBlockFromProcessingList(i)
|
||||||
self.removeBlockFromProcessingList(i)
|
self.removeBlockFromProcessingList(i)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
|
|
|
@ -641,6 +641,7 @@ class Core:
|
||||||
|
|
||||||
metadata = json.dumps(metadata)
|
metadata = json.dumps(metadata)
|
||||||
metadata = metadata.encode()
|
metadata = metadata.encode()
|
||||||
|
signature = ''
|
||||||
|
|
||||||
if sign:
|
if sign:
|
||||||
signature = self._crypto.edSign(metadata + data, self._crypto.privKey, encodeResult=True)
|
signature = self._crypto.edSign(metadata + data, self._crypto.privKey, encodeResult=True)
|
||||||
|
|
|
@ -336,6 +336,41 @@ class OnionrUtils:
|
||||||
continue
|
continue
|
||||||
try:
|
try:
|
||||||
with open('data/blocks/' + i + '.dat', 'r') as potentialMessage:
|
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('}')
|
data = potentialMessage.read().split('}')
|
||||||
message = data[1]
|
message = data[1]
|
||||||
sigResult = ''
|
sigResult = ''
|
||||||
|
@ -345,14 +380,6 @@ class OnionrUtils:
|
||||||
metadata = json.loads(data[0] + '}')
|
metadata = json.loads(data[0] + '}')
|
||||||
except json.decoder.JSONDecodeError:
|
except json.decoder.JSONDecodeError:
|
||||||
metadata = {}
|
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:
|
try:
|
||||||
message = self._core._crypto.pubKeyDecrypt(message, encodedData=True, anonymous=True)
|
message = self._core._crypto.pubKeyDecrypt(message, encodedData=True, anonymous=True)
|
||||||
|
@ -378,6 +405,7 @@ class OnionrUtils:
|
||||||
logger.info('Valid signature by ' + message['id'])
|
logger.info('Valid signature by ' + message['id'])
|
||||||
else:
|
else:
|
||||||
logger.warn('Invalid signature by ' + message['id'])
|
logger.warn('Invalid signature by ' + message['id'])
|
||||||
|
'''
|
||||||
|
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
pass
|
pass
|
||||||
|
|
Loading…
Reference in New Issue