Skip to content

Commit

Permalink
Fix for AES-GCM wallets
Browse files Browse the repository at this point in the history
  • Loading branch information
3rdIteration committed Dec 17, 2024
1 parent db11341 commit 0701106
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 20 deletions.
24 changes: 13 additions & 11 deletions btcrecover/btcrpass.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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}
7 changes: 5 additions & 2 deletions btcrecover/test/test_passwords.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 0701106

Please sign in to comment.