From 70cf44ccece2598fc1122e7961bc6cf9eec61170 Mon Sep 17 00:00:00 2001 From: Sander van Grieken Date: Tue, 12 Jul 2022 16:49:07 +0200 Subject: [PATCH] qml: wip single password --- electrum/gui/qml/components/OpenWallet.qml | 2 ++ .../qml/components/wizard/WCWalletPassword.qml | 2 +- electrum/gui/qml/qeconfig.py | 8 +++++--- electrum/gui/qml/qedaemon.py | 12 ++++++++++-- electrum/gui/qml/qewallet.py | 14 +++++++------- electrum/gui/qml/qewalletdb.py | 17 +++++------------ 6 files changed, 30 insertions(+), 25 deletions(-) diff --git a/electrum/gui/qml/components/OpenWallet.qml b/electrum/gui/qml/components/OpenWallet.qml index 715ae2685..e72a172dc 100644 --- a/electrum/gui/qml/components/OpenWallet.qml +++ b/electrum/gui/qml/components/OpenWallet.qml @@ -108,6 +108,7 @@ Pane { unlockButton.enabled = false _unlockClicked = true wallet_db.password = password.text + wallet_db.verify() openwalletdialog.forceActiveFocus() } @@ -132,6 +133,7 @@ Pane { } Component.onCompleted: { + wallet_db.verify() password.forceActiveFocus() } } diff --git a/electrum/gui/qml/components/wizard/WCWalletPassword.qml b/electrum/gui/qml/components/wizard/WCWalletPassword.qml index 51c5cc468..b9f8651b9 100644 --- a/electrum/gui/qml/components/wizard/WCWalletPassword.qml +++ b/electrum/gui/qml/components/wizard/WCWalletPassword.qml @@ -3,7 +3,7 @@ import QtQuick.Layouts 1.0 import QtQuick.Controls 2.1 WizardComponent { - valid: password1.text === password2.text + valid: password1.text === password2.text && password1.text.length > 4 onAccept: { wizard_data['password'] = password1.text diff --git a/electrum/gui/qml/qeconfig.py b/electrum/gui/qml/qeconfig.py index cf1f28de6..0e2333e82 100644 --- a/electrum/gui/qml/qeconfig.py +++ b/electrum/gui/qml/qeconfig.py @@ -90,12 +90,14 @@ class QEConfig(AuthMixin, QObject): def pinCode(self, pin_code): if pin_code == '': self.pinCodeRemoveAuth() - self.config.set_key('pin_code', pin_code, True) - self.pinCodeChanged.emit() + else: + self.config.set_key('pin_code', pin_code, True) + self.pinCodeChanged.emit() @auth_protect(method='wallet') def pinCodeRemoveAuth(self): - pass # no-op + self.config.set_key('pin_code', '', True) + self.pinCodeChanged.emit() useGossipChanged = pyqtSignal() @pyqtProperty(bool, notify=useGossipChanged) diff --git a/electrum/gui/qml/qedaemon.py b/electrum/gui/qml/qedaemon.py index 4cf24b6b0..f61317598 100644 --- a/electrum/gui/qml/qedaemon.py +++ b/electrum/gui/qml/qedaemon.py @@ -4,7 +4,7 @@ from decimal import Decimal from PyQt5.QtCore import pyqtProperty, pyqtSignal, pyqtSlot, QObject, QUrl from PyQt5.QtCore import Qt, QAbstractListModel, QModelIndex -from electrum.util import register_callback, get_new_wallet_name, WalletFileException +from electrum.util import register_callback, get_new_wallet_name, WalletFileException, standardize_path from electrum.logging import get_logger from electrum.wallet import Wallet, Abstract_Wallet from electrum.storage import WalletStorage, StorageReadWriteError @@ -130,12 +130,17 @@ class QEDaemon(AuthMixin, QObject): if self._path is None: return + self._path = standardize_path(self._path) self._logger.debug('load wallet ' + str(self._path)) - if path not in self.daemon._wallets: + if not password: + password = self._password + + if self._path not in self.daemon._wallets: # pre-checks, let walletdb trigger any necessary user interactions self._walletdb.path = self._path self._walletdb.password = password + self._walletdb.verify() if not self._walletdb.ready: return @@ -144,6 +149,7 @@ class QEDaemon(AuthMixin, QObject): if wallet != None: self._loaded_wallets.add_wallet(wallet=wallet) self._current_wallet = QEWallet.getInstanceFor(wallet) + self._current_wallet.password = password self.walletLoaded.emit() if self.daemon.config.get('single_password'): @@ -218,3 +224,5 @@ class QEDaemon(AuthMixin, QObject): assert self._use_single_password self._logger.debug('about to set password to %s for ALL wallets' % password) self.daemon.update_password_for_directory(old_password=self._password, new_password=password) + self._password = password + diff --git a/electrum/gui/qml/qewallet.py b/electrum/gui/qml/qewallet.py index 039205279..3e244459f 100644 --- a/electrum/gui/qml/qewallet.py +++ b/electrum/gui/qml/qewallet.py @@ -545,10 +545,10 @@ class QEWallet(AuthMixin, QObject, QtEventListener): if storage.is_encrypted_with_hw_device(): return - self._logger.debug('Ok to set password for wallet with path %s' % storage.path) - if password: - enc_version = StorageEncryptionVersion.USER_PASSWORD - else: - enc_version = StorageEncryptionVersion.PLAINTEXT - storage.set_password(password, enc_version=enc_version) - self.wallet.save_db() + self._logger.debug(f'Ok to set password from {self.password} to {password} for wallet with path {storage.path}') + + try: + self.wallet.update_password(self.password, password, encrypt_storage=True) + self.password = password + except InvalidPassword as e: + self._logger.exception(repr(e)) diff --git a/electrum/gui/qml/qewalletdb.py b/electrum/gui/qml/qewalletdb.py index ee6f647a5..4a3c986cd 100644 --- a/electrum/gui/qml/qewalletdb.py +++ b/electrum/gui/qml/qewalletdb.py @@ -59,10 +59,6 @@ class QEWalletDB(QObject): self.reset() self._path = wallet_path - self.load_storage() - if self._storage: - self.load_db() - self.pathChanged.emit(self._ready) @pyqtProperty(bool, notify=needsPasswordChanged) @@ -101,12 +97,6 @@ class QEWalletDB(QObject): self._password = wallet_password self.passwordChanged.emit() - self.load_storage() - - if self._storage: - self.needsPassword = False - self.load_db() - @pyqtProperty(bool, notify=requiresSplitChanged) def requiresSplit(self): return self._requiresSplit @@ -125,6 +115,11 @@ class QEWalletDB(QObject): def ready(self): return self._ready + @pyqtSlot() + def verify(self): + self.load_storage() + if self._storage: + self.load_db() @pyqtSlot() def doSplit(self): @@ -226,5 +221,3 @@ class QEWalletDB(QObject): except Exception as e: self._logger.error(str(e)) self.createError.emit(str(e)) - -