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.
This commit is contained in:
Sergi Delgado Segura
2019-10-07 16:34:28 +01:00
parent 76f0b1934a
commit 88532f7345
2 changed files with 4 additions and 3 deletions

View File

@@ -64,8 +64,7 @@ class BlockProcessor:
for uuid in locator_uuid_map[locator]: for uuid in locator_uuid_map[locator]:
try: try:
# ToDo: #20-test-tx-decrypting-edge-cases # ToDo: #20-test-tx-decrypting-edge-cases
justice_rawtx = appointments[uuid].encrypted_blob.decrypt(binascii.unhexlify(dispute_txid)) justice_rawtx = appointments[uuid].encrypted_blob.decrypt(dispute_txid)
justice_rawtx = binascii.hexlify(justice_rawtx).decode()
justice_txid = bitcoin_cli.decoderawtransaction(justice_rawtx).get('txid') justice_txid = bitcoin_cli.decoderawtransaction(justice_rawtx).get('txid')
matches.append((locator, uuid, dispute_txid, justice_txid, justice_rawtx)) matches.append((locator, uuid, dispute_txid, justice_txid, justice_rawtx))

View File

@@ -11,6 +11,7 @@ class EncryptedBlob:
def decrypt(self, key): def decrypt(self, key):
# master_key = H(tx_id | tx_id) # master_key = H(tx_id | tx_id)
key = unhexlify(key)
master_key = sha256(key + key).digest() 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. # 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) aesgcm = AESGCM(sk)
data = unhexlify(self.data.encode()) data = unhexlify(self.data.encode())
raw_tx = aesgcm.decrypt(nonce=nonce, data=data, associated_data=None) 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