From 0701106340a3230874af12b8cbb31a03ac6a40b0 Mon Sep 17 00:00:00 2001 From: 3rdIteration Date: Tue, 17 Dec 2024 13:22:18 -0500 Subject: [PATCH] Fix for AES-GCM wallets --- btcrecover/btcrpass.py | 24 ++++++++++--------- .../dogechain.wallet.aes.json.2022-01 | 7 ------ ...-12 => dogechain.wallet.aes.json.2024-cbc} | 0 .../dogechain.wallet.aes.json.2024-gcm | 1 + btcrecover/test/test_passwords.py | 7 ++++-- 5 files changed, 19 insertions(+), 20 deletions(-) delete mode 100644 btcrecover/test/test-wallets/dogechain.wallet.aes.json.2022-01 rename btcrecover/test/test-wallets/{dogechain.wallet.aes.json.2024-12 => dogechain.wallet.aes.json.2024-cbc} (100%) create mode 100644 btcrecover/test/test-wallets/dogechain.wallet.aes.json.2024-gcm diff --git a/btcrecover/btcrpass.py b/btcrecover/btcrpass.py index c6229a62..f8963f7e 100644 --- a/btcrecover/btcrpass.py +++ b/btcrecover/btcrpass.py @@ -3048,18 +3048,20 @@ def _return_verified_password_or_false_cpu(self, arg_passwords): # dogechain.in if self.aes_cipher == "AES-CBC": decrypted_block = AES.new(key, AES.MODE_CBC, self.iv).decrypt(self._encrypted_block) + + if self.check_decrypted_block(decrypted_block, password): + # Decrypt and dump the wallet if required + self.decrypt_wallet(password) + return password.decode("utf_8", "replace"), count else: try: - decrypted_block = AES.new(key, AES.MODE_GCM, self.iv).decrypt_and_verify(self._encrypted_block, self.aes_auth_tag) + # For AES-GCM we need to decrypt the whole wallet, not just a block, + # also don't need to manually check the file contents as verification is part of the decryption + decrypted_block = AES.new(key, AES.MODE_GCM, self.iv).decrypt_and_verify(self._encrypted_wallet, self.aes_auth_tag) return password.decode("utf_8", "replace"), count except ValueError: continue - if self.check_decrypted_block(decrypted_block, password): - # Decrypt and dump the wallet if required - self.decrypt_wallet(password) - return password.decode("utf_8", "replace"), count - return False, count def _return_verified_password_or_false_opencl(self, arg_passwords): # dogechain.info Main Password @@ -3077,17 +3079,17 @@ def _return_verified_password_or_false_opencl(self, arg_passwords): # dogechain for count, (password, key) in enumerate(results, 1): if self.aes_cipher == "AES-CBC": decrypted_block = AES.new(key, AES.MODE_CBC, self.iv).decrypt(self._encrypted_block) + if self.check_decrypted_block(decrypted_block, password): + # Decrypt and dump the wallet if required + self.decrypt_wallet(password) + return password.decode("utf_8", "replace"), count else: try: - decrypted_block = AES.new(key, AES.MODE_GCM, self.iv).decrypt_and_verify(self._encrypted_block, + decrypted_block = AES.new(key, AES.MODE_GCM, self.iv).decrypt_and_verify(self._encrypted_wallet, self.aes_auth_tag) return password.decode("utf_8", "replace"), count except ValueError: continue - if self.check_decrypted_block(decrypted_block, password): - # Decrypt and dump the wallet if required - self.decrypt_wallet(password) - return password.decode("utf_8", "replace"), count return False, count diff --git a/btcrecover/test/test-wallets/dogechain.wallet.aes.json.2022-01 b/btcrecover/test/test-wallets/dogechain.wallet.aes.json.2022-01 deleted file mode 100644 index 3387267e..00000000 --- a/btcrecover/test/test-wallets/dogechain.wallet.aes.json.2022-01 +++ /dev/null @@ -1,7 +0,0 @@ -{ - "guid": "52500558-b3fa-4318-b6a3-3c55835c6575", - "payload": "Dw5gN5A0eMzK0aFzkn+sIymgcy5ncpGt7wSyJLFbCJvTJnbA0rNRPWz6LQRZeaoqOFugYjXqlj/HMjOGTlAmUWjZSbOCkngzQBwZe1jKY0iVWIKI7SCHE7yI6YQN0bV9HoAo4zl+nDxYC/EN+ue11OqWOYZNhDxwyn/poyRd7bcigeuvcjam292+pglc2koAmOJeuOg0m+NvdvS7Mw07mAGCyLVrxLmj5efDtIHWrdrGWv5SgmTUUr1pUEOJG5Ps;LzZwl72onfBNml5KA22HBJMEJwyfSUWxOyXlA36kWJA6FAdVYadYX7Ln3+Xe9BG2662d6lLI+b3SAK9njFtGe0O0DOnS+HIyVCBvPAkMsj874dNB2J9bJfpm5/kuh58EFkZoJXpXywscBlPHu7TlbTieb8B1g/SPpkLrXvQL22XM6NVI927wB1s081KFjcT8IBdMmMZIp/qVtlkyoqKfQBwqtmGb1sOYsa0r2n8aBcI+RFP6O7Md6LCMfZeRYIlU;RHpIRAm+DoUA1oribmXhxJ44LiXL+BpOdanK/P3jFfs+FVPagu//ItCgfUMlmHgt5x7Qhlu7JZMWJU3WdQOeixdxbpI1EEseAdOtRG/sIwv2Vf4vo16effuZuQm/MO8xBngeKE56splt6A39FHQUG4v3YtlDb1w6yVphyDBrhIFxUsdJyCxjzWappyE00FDdG+OOnkRKtBGRtN/yF1UIaUvs699ssM88FnUNK4xGc0WmPpJpL8ToLKIKTmD9c6VJ;U63oZYYqy9EvT85dOAuIR0TaQmRACJvzETyH3laoUXLGv9ktjYd9WdXJX/7G9gQnmzwCd1J65/GsitvbI9Ch0OHeCW3iIZqjVGGg4sU91RWR3BVgl4d5XLNxmHrUVHkOrEXMmJRgrF9oWXeYSsmNMQiCk5StgJppBE9WMc6x//tDPMVWMOWICmM6E1Qn+zlIrjtizPIWjGdckTgaKw7a415Yi1yFyh211ueMczycIvshhEKFGJO6f0UuwLej11Rv;su0DZr+7yKjxsF0guCzmBUERevBP18gRrJQclCExf86CuM5KrBXZAijCy8J53g8eITNCiCFQORMD5gDRHcfbypJ/hGSh0VBdCcxJ8CQCc3K8Ok+BJ0le7XsxL23oC1XoU/ORNZjN7yg7O21Ez+RArDGItEfdHHjMpox9rNyRHyjOExDFyz55Zb3rAF8PrTUL2dnOmo0BF8uvW45sZzxJdFztFwg/FyeycFRbwhQ0i/TfzW679dVvQkdOpiG31c4X", - "salt": "Gc55/tevRG/ODxUN0ENiRg==", - "pbkdf2_iterations": 5000, - "cipher": "AES-CBC" -} \ No newline at end of file diff --git a/btcrecover/test/test-wallets/dogechain.wallet.aes.json.2024-12 b/btcrecover/test/test-wallets/dogechain.wallet.aes.json.2024-cbc similarity index 100% rename from btcrecover/test/test-wallets/dogechain.wallet.aes.json.2024-12 rename to btcrecover/test/test-wallets/dogechain.wallet.aes.json.2024-cbc diff --git a/btcrecover/test/test-wallets/dogechain.wallet.aes.json.2024-gcm b/btcrecover/test/test-wallets/dogechain.wallet.aes.json.2024-gcm new file mode 100644 index 00000000..8794232c --- /dev/null +++ b/btcrecover/test/test-wallets/dogechain.wallet.aes.json.2024-gcm @@ -0,0 +1 @@ +{"guid": "52500558-b3fa-4318-b6a3-3c55835c6575","salt": "uTE5zPjTEpb6S23GbUJgwA==","payload": "LYp4+q9Qc2ixp2c49mrCfzfE+gnJgxNBF0YMmSmvELES9aQPwqp02O5Lo7p3npTHtbkjQeub8iGIddvvEdpoXqYi4ZFHSJ5/qM7lQKTzIXqLgJ8+3l3o/kqpgecXsrQKqmJEzzhzNCDnBhUeBpPiJuz39B5m1laehynsIZekAimJrkuEJtUHLfO54Mzzb3v2s6qAXUBuB9wjOBNCXgFPl1qDg+PMJdVhomyQWYoLr7425/+peoJ7IQ7BgH3sIUVua41zFIlkcHqjkYlBOuXOpb5tlZNRbgNRGiYISrYSRwBhuGO+U2R67ePTGtNq62VZhzs=","cipher": "AES-GCM","pbkdf2_iterations": 5000} \ No newline at end of file diff --git a/btcrecover/test/test_passwords.py b/btcrecover/test/test_passwords.py index 5b8be326..4a6c8939 100644 --- a/btcrecover/test/test_passwords.py +++ b/btcrecover/test/test_passwords.py @@ -1401,8 +1401,11 @@ def test_blockchain_secondpass_unencrypted(self): # this wallet has no second-p def test_dogechain_info_cpu(self): self.wallet_tester("dogechain.wallet.aes.json") - def test_dogechain_info_cpu(self): - self.wallet_tester("dogechain.wallet.aes.json.2024-12") + def test_dogechain_info_cpu_2024_CBC(self): + self.wallet_tester("dogechain.wallet.aes.json.2024-cbc") + + def test_dogechain_info_cpu_2024_GCM(self): + self.wallet_tester("dogechain.wallet.aes.json.2024-gcm") @skipUnless(can_load_ecdsa, "requires ECDSA") @skipUnless(can_load_bitcoinutils, "requires Bitcoin-Utils")