Browse Source

storage: fix update-password edge-case

fixes #6400
patch-4
SomberNight 4 years ago
parent
commit
9931df9f25
No known key found for this signature in database GPG Key ID: B33B5F232C6271E9
  1. 10
      electrum/storage.py
  2. 22
      electrum/tests/test_wallet.py

10
electrum/storage.py

@ -106,10 +106,7 @@ class WalletStorage(Logger):
if encryption is disabled completely (self.is_encrypted() == False),
or if encryption is enabled but the contents have already been decrypted.
"""
try:
return not self.is_encrypted() or bool(self.decrypted)
except AttributeError:
return False
return not self.is_encrypted() or bool(self.pubkey)
def is_encrypted(self):
"""Return if storage encryption is currently enabled."""
@ -189,11 +186,14 @@ class WalletStorage(Logger):
return
if not self.is_past_initial_decryption():
self.decrypt(password) # this sets self.pubkey
if self.pubkey and self.pubkey != self.get_eckey_from_password(password).get_public_key_hex():
assert self.pubkey is not None
if self.pubkey != self.get_eckey_from_password(password).get_public_key_hex():
raise InvalidPassword()
def set_password(self, password, enc_version=None):
"""Set a password to be used for encrypting this storage."""
if not self.is_past_initial_decryption():
raise Exception("storage needs to be decrypted before changing password")
if enc_version is None:
enc_version = self._encryption_version
if password and enc_version != StorageEncryptionVersion.PLAINTEXT:

22
electrum/tests/test_wallet.py

@ -263,3 +263,25 @@ class TestWalletPassword(WalletTestCase):
with self.assertRaises(InvalidPassword):
wallet.check_password("wrong password")
wallet.check_password("1234")
def test_update_password_with_app_restarts(self):
wallet_str = '{"addr_history":{"1364Js2VG66BwRdkaoxAaFtdPb1eQgn8Dr":[],"15CyDgLffJsJgQrhcyooFH4gnVDG82pUrA":[],"1Exet2BhHsFxKTwhnfdsBMkPYLGvobxuW6":[]},"addresses":{"change":[],"receiving":["1364Js2VG66BwRdkaoxAaFtdPb1eQgn8Dr","1Exet2BhHsFxKTwhnfdsBMkPYLGvobxuW6","15CyDgLffJsJgQrhcyooFH4gnVDG82pUrA"]},"keystore":{"keypairs":{"0344b1588589958b0bcab03435061539e9bcf54677c104904044e4f8901f4ebdf5":"L2sED74axVXC4H8szBJ4rQJrkfem7UMc6usLCPUoEWxDCFGUaGUM","0389508c13999d08ffae0f434a085f4185922d64765c0bff2f66e36ad7f745cc5f":"L3Gi6EQLvYw8gEEUckmqawkevfj9s8hxoQDFveQJGZHTfyWnbk1U","04575f52b82f159fa649d2a4c353eb7435f30206f0a6cb9674fbd659f45082c37d559ffd19bea9c0d3b7dcc07a7b79f4cffb76026d5d4dff35341efe99056e22d2":"5JyVyXU1LiRXATvRTQvR9Kp8Rx1X84j2x49iGkjSsXipydtByUq"},"type":"imported"},"pruned_txo":{},"seed_version":13,"stored_height":-1,"transactions":{},"tx_fees":{},"txi":{},"txo":{},"use_encryption":false,"verified_tx3":{},"wallet_type":"standard","winpos-qt":[100,100,840,405]}'
db = WalletDB(wallet_str, manual_upgrades=False)
storage = WalletStorage(self.wallet_path)
wallet = Wallet(db, storage, config=self.config)
wallet.stop()
storage = WalletStorage(self.wallet_path)
# if storage.is_encrypted():
# storage.decrypt(password)
db = WalletDB(storage.read(), manual_upgrades=False)
wallet = Wallet(db, storage, config=self.config)
wallet.check_password(None)
wallet.update_password(None, "1234")
with self.assertRaises(InvalidPassword):
wallet.check_password(None)
with self.assertRaises(InvalidPassword):
wallet.check_password("wrong password")
wallet.check_password("1234")

Loading…
Cancel
Save