PMs now disguise sender (needs testing)

This commit is contained in:
Kevin Froman 2018-04-30 02:38:53 -05:00
parent a376e583e6
commit c6c819bd28
No known key found for this signature in database
GPG Key ID: 0D414D0FE405B63B

View File

@ -54,9 +54,20 @@ class OnionrUtils:
''' '''
try: try:
encrypted = self._core._crypto.pubKeyEncrypt(message, pubkey, anonymous=True, encodedData=True).decode() # We sign PMs here rather than in core.insertBlock in order to mask the sender's pubkey
block = self._core.insertBlock(encrypted, header='pm', sign=True) payload = {'sig': '', 'msg': '', 'id': self._core._crypto.pubKey}
sign = self._core._crypto.edSign(message, self._core._crypto.privKey, encodeResult=True)
#encrypted = self._core._crypto.pubKeyEncrypt(message, pubkey, anonymous=True, encodedData=True).decode()
payload['sig'] = sign
payload['msg'] = message
payload = json.dumps(payload)
message = payload
encrypted = self._core._crypto.pubKeyEncrypt(message, pubkey, anonymous=True, encodedData=True).decode()
block = self._core.insertBlock(encrypted, header='pm', sign=False)
if block == '': if block == '':
logger.error('Could not send PM') logger.error('Could not send PM')
else: else:
@ -334,33 +345,39 @@ class OnionrUtils:
metadata = json.loads(data[0] + '}') metadata = json.loads(data[0] + '}')
except json.decoder.JSONDecodeError: except json.decoder.JSONDecodeError:
metadata = {} metadata = {}
try: '''
sig = json.loads(data[0].strip() + '}')['sig'] sigResult = self._core._crypto.edVerify(message, signer, sig, encodedData=True)
sigID = json.loads(data[0].strip() + '}')['id'] #sigResult = False
signer = self._core._utils.getPeerByHashId(sigID) if sigResult != False:
logger.debug('signer ' + signer) sigResult = 'Valid signature by ' + signer
logger.debug('signature ' + metadata['sig'])
except KeyError:
pass
else: else:
# TODO: Possible refactor to use verification on proccessblocks sigResult = 'Invalid signature by ' + signer
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)
except nacl.exceptions.CryptoError as e: except nacl.exceptions.CryptoError as e:
logger.error('Unable to decrypt ' + i, error=e) logger.error('Unable to decrypt ' + i, error=e)
else: else:
logger.info('Recieved message: ' + message.decode()) try:
if sigResult.startswith('Invalid'): message = json.loads(message.decode())
logger.warn(sigResult) message['msg']
message['id']
message['sig']
except json.decoder.JSONDecodeError:
logger.error('Could not decode PM JSON')
except KeyError:
logger.error('PM is missing JSON keys')
else: else:
logger.info(sigResult) if self.validatePubKey(message['id']):
sigResult = self._core._crypto.edVerify(message['msg'], message['id'], message['sig'], encodedData=True)
logger.info('-----------------------------------')
logger.info('Recieved message: ' + message['msg'])
if sigResult:
logger.info('Valid signature by ' + message['id'])
else:
logger.warn('Invalid signature by ' + message['id'])
except FileNotFoundError: except FileNotFoundError:
pass pass
except Exception as error: except Exception as error: