From 88532f7345e8ca402f7990f1f2c6d4dbc8be2e5d Mon Sep 17 00:00:00 2001 From: Sergi Delgado Segura Date: Mon, 7 Oct 2019 16:34:28 +0100 Subject: [PATCH] Changes derypt key input type and return The input types for Blob.encrypt and EncryptedBlob.decrypt were not consistent. The former was in hex whereas the later was in bytes. Format the later in hex for consistency. --- pisa/block_processor.py | 3 +-- pisa/encrypted_blob.py | 4 +++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/pisa/block_processor.py b/pisa/block_processor.py index 062d938..419e26f 100644 --- a/pisa/block_processor.py +++ b/pisa/block_processor.py @@ -64,8 +64,7 @@ class BlockProcessor: for uuid in locator_uuid_map[locator]: try: # ToDo: #20-test-tx-decrypting-edge-cases - justice_rawtx = appointments[uuid].encrypted_blob.decrypt(binascii.unhexlify(dispute_txid)) - justice_rawtx = binascii.hexlify(justice_rawtx).decode() + justice_rawtx = appointments[uuid].encrypted_blob.decrypt(dispute_txid) justice_txid = bitcoin_cli.decoderawtransaction(justice_rawtx).get('txid') matches.append((locator, uuid, dispute_txid, justice_txid, justice_rawtx)) diff --git a/pisa/encrypted_blob.py b/pisa/encrypted_blob.py index 7e7d2bb..63f6e64 100644 --- a/pisa/encrypted_blob.py +++ b/pisa/encrypted_blob.py @@ -11,6 +11,7 @@ class EncryptedBlob: def decrypt(self, key): # master_key = H(tx_id | tx_id) + key = unhexlify(key) master_key = sha256(key + key).digest() # The 16 MSB of the master key will serve as the AES GCM 128 secret key. The 16 LSB will serve as the IV. @@ -27,5 +28,6 @@ class EncryptedBlob: aesgcm = AESGCM(sk) data = unhexlify(self.data.encode()) raw_tx = aesgcm.decrypt(nonce=nonce, data=data, associated_data=None) + hex_raw_tx = hexlify(raw_tx).decode('utf8') - return raw_tx + return hex_raw_tx