blockapi decrypt fix

master
Kevin Froman 2020-10-27 15:58:06 +00:00
parent d0e6f6c4af
commit 2837210cf4
1 changed files with 6 additions and 7 deletions

View File

@ -79,10 +79,7 @@ class Block:
# decrypt data # decrypt data
if self.getHeader('encryptType') == 'asym': if self.getHeader('encryptType') == 'asym':
try: try:
try: self.bcontent = encryption.pub_key_decrypt(self.bcontent, encodedData=False)
self.bcontent = encryption.pub_key_decrypt(self.bcontent, encodedData=encodedData)
except (binascii.Error, ValueError) as e:
self.bcontent = encryption.pub_key_decrypt(self.bcontent, encodedData=False)
bmeta = encryption.pub_key_decrypt(self.bmetadata, encodedData=encodedData) bmeta = encryption.pub_key_decrypt(self.bmetadata, encodedData=encodedData)
@ -93,9 +90,11 @@ class Block:
pass pass
self.bmetadata = json.loads(bmeta) self.bmetadata = json.loads(bmeta)
self.signature = encryption.pub_key_decrypt(self.signature, encodedData=encodedData) self.signature = encryption.pub_key_decrypt(self.signature, encodedData=encodedData)
self.signer = encryption.pub_key_decrypt(self.signer, encodedData=encodedData) self.signer = encryption.pub_key_decrypt(self.signer, encodedData=encodedData)
self.bheader['signer'] = self.signer.decode() self.bheader['signer'] = self.signer.decode()
self.signedData = json.dumps(self.bmetadata).encode() + self.bcontent self.signedData = json.dumps(self.bmetadata).encode() + self.bcontent
if not self.signer is None: if not self.signer is None:
if not self.verifySig(): if not self.verifySig():
@ -124,8 +123,8 @@ class Block:
except (onionrexceptions.DecryptionError, nacl.exceptions.CryptoError) as e: except (onionrexceptions.DecryptionError, nacl.exceptions.CryptoError) as e:
logger.error(str(e)) logger.error(str(e))
pass pass
except nacl.exceptions.CryptoError: except (nacl.exceptions.CryptoError,) as e:
logger.debug('Could not decrypt block. Either invalid key or corrupted data') logger.debug(f'Could not decrypt block. encodedData: {encodedData}. Either invalid key or corrupted data ' + str(e))
except onionrexceptions.ReplayAttack: except onionrexceptions.ReplayAttack:
logger.warn('%s is possibly a replay attack' % (self.hash,)) logger.warn('%s is possibly a replay attack' % (self.hash,))
else: else: