From 37d090c621006cc4caa7e0fb9d080b3e6a9da05c Mon Sep 17 00:00:00 2001 From: SomberNight Date: Tue, 8 Oct 2024 15:15:42 +0000 Subject: [PATCH] commands: check password already in decorator Previously it was only the actual commands that directly or indirectly verified the password. This adds a check that runs for any command requiring a password. related https://github.com/spesmilo/electrum/pull/9238 --- electrum/commands.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/electrum/commands.py b/electrum/commands.py index 68c1c7fdb..9533f955e 100644 --- a/electrum/commands.py +++ b/electrum/commands.py @@ -43,7 +43,7 @@ import os from .import util, ecc from .util import (bfh, format_satoshis, json_decode, json_normalize, is_hash256_str, is_hex_str, to_bytes, parse_max_spend, to_decimal, - UserFacingException) + UserFacingException, InvalidPassword) from . import bitcoin from .bitcoin import is_address, hash_160, COIN from .bip32 import BIP32Node @@ -156,8 +156,13 @@ def command(s): wallet = kwargs.get('wallet') # type: Optional[Abstract_Wallet] if cmd.requires_wallet and not wallet: raise UserFacingException('wallet not loaded') - if cmd.requires_password and password is None and wallet.has_password(): - raise UserFacingException('Password required') + if cmd.requires_password and wallet.has_password(): + if password is None: + raise UserFacingException('Password required') + try: + wallet.check_password(password) + except InvalidPassword as e: + raise UserFacingException(str(e)) from None if cmd.requires_lightning and (not wallet or not wallet.has_lightning()): raise UserFacingException('Lightning not enabled in this wallet') return await func(*args, **kwargs)