URI: 
       thw wallet encryption unlock: clear session on incorrect passphrase - electrum - Electrum Bitcoin wallet
  HTML git clone https://git.parazyd.org/electrum
   DIR Log
   DIR Files
   DIR Refs
   DIR Submodules
       ---
   DIR commit d994d27704934d7bad4fc483b31172a2e70e0bf9
   DIR parent f3d254ff1ebb6f36f12fd314d73e535ed2f7ecdc
  HTML Author: SomberNight <somber.night@protonmail.com>
       Date:   Sat, 10 Mar 2018 03:59:01 +0100
       
       hw wallet encryption unlock: clear session on incorrect passphrase
       
       Diffstat:
         M gui/qt/installwizard.py             |       2 --
         M lib/base_wizard.py                  |      12 ++++++++++--
       
       2 files changed, 10 insertions(+), 4 deletions(-)
       ---
   DIR diff --git a/gui/qt/installwizard.py b/gui/qt/installwizard.py
       t@@ -246,8 +246,6 @@ class InstallWizard(QDialog, MessageBoxMixin, BaseWizard):
                            try:
                                self.run('choose_hw_device', HWD_SETUP_DECRYPT_WALLET)
                            except InvalidPassword as e:
       -                        # FIXME if we get here because of mistyped passphrase
       -                        # then that passphrase gets "cached"
                                QMessageBox.information(
                                    None, _('Error'),
                                    _('Failed to decrypt using this hardware device.') + '\n' +
   DIR diff --git a/lib/base_wizard.py b/lib/base_wizard.py
       t@@ -33,7 +33,7 @@ from .keystore import bip44_derivation
        from .wallet import Imported_Wallet, Standard_Wallet, Multisig_Wallet, wallet_types
        from .storage import STO_EV_USER_PW, STO_EV_XPUB_PW, get_derivation_used_for_hw_device_encryption
        from .i18n import _
       -from .util import UserCancelled
       +from .util import UserCancelled, InvalidPassword
        
        # hardware device setup purpose
        HWD_SETUP_NEW_WALLET, HWD_SETUP_DECRYPT_WALLET = range(0, 2)
       t@@ -259,7 +259,15 @@ class BaseWizard(object):
                    derivation = get_derivation_used_for_hw_device_encryption()
                    xpub = self.plugin.get_xpub(device_info.device.id_, derivation, 'standard', self)
                    password = keystore.Xpub.get_pubkey_from_xpub(xpub, ())
       -            self.storage.decrypt(password)
       +            try:
       +                self.storage.decrypt(password)
       +            except InvalidPassword:
       +                # try to clear session so that user can type another passphrase
       +                devmgr = self.plugins.device_manager
       +                client = devmgr.client_by_id(device_info.device.id_)
       +                if hasattr(client, 'clear_session'):  # FIXME not all hw wallet plugins have this
       +                    client.clear_session()
       +                raise
                else:
                    raise Exception('unknown purpose: %s' % purpose)