commit 9931df9f254e49eb929723be62af61971b3032c8
parent 9eb152ed98ca056d7de264dca81aa4719ba14945
Author: SomberNight <somber.night@protonmail.com>
Date: Fri, 11 Sep 2020 13:39:36 +0200
storage: fix update-password edge-case
fixes #6400
Diffstat:
2 files changed, 27 insertions(+), 5 deletions(-)
diff --git a/electrum/storage.py b/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:
diff --git a/electrum/tests/test_wallet.py b/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")