Skip to content

Commit

Permalink
qml: always ask for the password on wallet-open, even for ks-enc-only…
Browse files Browse the repository at this point in the history
… wallets

This is a hugely hackish -- it uses the kivy approach, which uses this same hack...
I am not really content with it but it should be relatively easy to review,
and if ok, should hotfix the linked issue.

fixes spesmilo#8374
related spesmilo#8382
  • Loading branch information
SomberNight committed May 4, 2023
1 parent 2732a82 commit 9765039
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
2 changes: 1 addition & 1 deletion electrum/gui/qml/qewallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ def deleteInvoice(self, key: str):
@pyqtSlot(str, result=bool)
def verifyPassword(self, password):
try:
self.wallet.storage.check_password(password)
self.wallet.check_password(password)
return True
except InvalidPassword as e:
return False
Expand Down
26 changes: 24 additions & 2 deletions electrum/gui/qml/qewalletdb.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
import os
from typing import TYPE_CHECKING

from PyQt5.QtCore import pyqtProperty, pyqtSignal, pyqtSlot, QObject

from electrum.logging import get_logger
from electrum.storage import WalletStorage, StorageEncryptionVersion
from electrum.wallet_db import WalletDB
from electrum.wallet import Wallet
from electrum.bip32 import normalize_bip32_derivation, xpub_type
from electrum.util import InvalidPassword, WalletFileException
from electrum import keystore

if TYPE_CHECKING:
from electrum.simple_config import SimpleConfig


class QEWalletDB(QObject):
_logger = get_logger(__name__)

Expand All @@ -29,6 +35,7 @@ def __init__(self, parent=None):

from .qeapp import ElectrumQmlApplication
self.daemon = ElectrumQmlApplication._daemon
self._config = self.daemon.config # type: SimpleConfig

self.reset()

Expand Down Expand Up @@ -144,9 +151,24 @@ def load_storage(self):
except InvalidPassword as e:
self.validPassword = False
self.invalidPassword.emit()
else: # storage not encrypted; but it might still have a keystore pw
# FIXME hack... load both db and full wallet, just to tell if it has keystore pw.
# this also completely ignores db.requires_split(), db.get_action(), etc
db = WalletDB(self._storage.read(), manual_upgrades=False)
wallet = Wallet(db, self._storage, config=self._config)
self.needsPassword = wallet.has_password()
if self.needsPassword:
try:
wallet.check_password('' if not self._password else self._password)
self.validPassword = True
except InvalidPassword as e:
self.validPassword = False
self._storage = None
self.invalidPassword.emit()

if not self._storage.is_past_initial_decryption():
self._storage = None
if self._storage:
if not self._storage.is_past_initial_decryption():
self._storage = None

def load_db(self):
# needs storage accessible
Expand Down

0 comments on commit 9765039

Please sign in to comment.