Browse Source

password unification: bugfix, now passes test cases

fixes https://github.com/spesmilo/electrum/issues/8259

note that technically this is an API change for
- wallet.check_password
- wallet.update_password
- storage.check_password
master
SomberNight 3 years ago
parent
commit
9df5f55a1f
No known key found for this signature in database
GPG Key ID: B33B5F232C6271E9
  1. 9
      electrum/daemon.py
  2. 5
      electrum/storage.py
  3. 7
      electrum/wallet.py

9
electrum/daemon.py

@ -623,13 +623,18 @@ class Daemon(Logger):
if not wallet.storage.is_encrypted():
is_unified = False
try:
wallet.check_password(old_password)
try:
wallet.check_password(old_password)
old_password_real = old_password
except util.InvalidPassword:
wallet.check_password(None)
old_password_real = None
except Exception:
failed.append(path)
continue
if new_password:
self.logger.info(f'updating password for wallet: {path!r}')
wallet.update_password(old_password, new_password, encrypt_storage=True)
wallet.update_password(old_password_real, new_password, encrypt_storage=True)
can_be_unified = failed == []
is_unified = can_be_unified and is_unified
return can_be_unified, is_unified

5
electrum/storage.py

@ -29,6 +29,7 @@ import hashlib
import base64
import zlib
from enum import IntEnum
from typing import Optional
from . import ecc
from .util import (profiler, InvalidPassword, WalletFileException, bfh, standardize_path,
@ -186,9 +187,11 @@ class WalletStorage(Logger):
s = s.decode('utf8')
return s
def check_password(self, password) -> None:
def check_password(self, password: Optional[str]) -> None:
"""Raises an InvalidPassword exception on invalid password"""
if not self.is_encrypted():
if password is not None:
raise InvalidPassword("password given but wallet has no password")
return
if not self.is_past_initial_decryption():
self.decrypt(password) # this sets self.pubkey

7
electrum/wallet.py

@ -2682,7 +2682,12 @@ class Abstract_Wallet(ABC, Logger, EventListener):
def may_have_password(cls):
return True
def check_password(self, password):
def check_password(self, password: Optional[str]) -> None:
"""Raises an InvalidPassword exception on invalid password"""
if not self.has_password():
if password is not None:
raise InvalidPassword("password given but wallet has no password")
return
if self.has_keystore_encryption():
self.keystore.check_password(password)
if self.has_storage_encryption():

Loading…
Cancel
Save