electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit caefea19dd5ffb856b2d11b855e98a68ad517608
parent 5259fcb6fd0cbb2ae77c55dc4efa1ca37350baab
Author: SomberNight <somber.night@protonmail.com>
Date:   Tue,  7 Apr 2020 18:56:14 +0200

trezor pin dialog: only show PIN "strength" when creating/changing

fixes #4832

Diffstat:
Melectrum/plugins/coldcard/cmdline.py | 2+-
Melectrum/plugins/hw_wallet/cmdline.py | 2+-
Melectrum/plugins/hw_wallet/plugin.py | 3+++
Melectrum/plugins/keepkey/clientbase.py | 8++++++--
Melectrum/plugins/keepkey/qt.py | 10+++++-----
Melectrum/plugins/safe_t/clientbase.py | 8++++++--
Melectrum/plugins/safe_t/qt.py | 10+++++-----
Melectrum/plugins/trezor/clientbase.py | 4+++-
Melectrum/plugins/trezor/qt.py | 10+++++-----
9 files changed, 35 insertions(+), 22 deletions(-)

diff --git a/electrum/plugins/coldcard/cmdline.py b/electrum/plugins/coldcard/cmdline.py @@ -15,7 +15,7 @@ class ColdcardCmdLineHandler(CmdLineHandler): def get_passphrase(self, msg, confirm): raise NotImplementedError - def get_pin(self, msg): + def get_pin(self, msg, *, show_strength=True): raise NotImplementedError def prompt_auth(self, msg): diff --git a/electrum/plugins/hw_wallet/cmdline.py b/electrum/plugins/hw_wallet/cmdline.py @@ -14,7 +14,7 @@ class CmdLineHandler(HardwareHandlerBase): print_stderr(msg) return getpass.getpass('') - def get_pin(self, msg): + def get_pin(self, msg, *, show_strength=True): t = { 'a':'7', 'b':'8', 'c':'9', 'd':'4', 'e':'5', 'f':'6', 'g':'1', 'h':'2', 'i':'3'} print_stderr(msg) print_stderr("a b c\nd e f\ng h i\n-----") diff --git a/electrum/plugins/hw_wallet/plugin.py b/electrum/plugins/hw_wallet/plugin.py @@ -251,6 +251,9 @@ class HardwareHandlerBase: def get_passphrase(self, msg: str, confirm: bool) -> Optional[str]: raise NotImplementedError() + def get_pin(self, msg: str, *, show_strength: bool = True) -> str: + raise NotImplementedError() + def is_any_tx_output_on_change_branch(tx: PartialTransaction) -> bool: return any([txout.is_change for txout in tx.outputs()]) diff --git a/electrum/plugins/keepkey/clientbase.py b/electrum/plugins/keepkey/clientbase.py @@ -1,5 +1,6 @@ import time from struct import pack +from typing import Optional from electrum import ecc from electrum.i18n import _ @@ -7,11 +8,12 @@ from electrum.util import UserCancelled from electrum.keystore import bip39_normalize_passphrase from electrum.bip32 import BIP32Node, convert_bip32_path_to_list_of_uint32 from electrum.logging import Logger -from electrum.plugins.hw_wallet.plugin import HardwareClientBase +from electrum.plugins.hw_wallet.plugin import HardwareClientBase, HardwareHandlerBase class GuiMixin(object): # Requires: self.proto, self.device + handler: Optional[HardwareHandlerBase] messages = { 3: _("Confirm the transaction output on your {} device"), @@ -45,6 +47,7 @@ class GuiMixin(object): return self.proto.ButtonAck() def callback_PinMatrixRequest(self, msg): + show_strength = True if msg.type == 2: msg = _("Enter a new PIN for your {}:") elif msg.type == 3: @@ -52,7 +55,8 @@ class GuiMixin(object): "NOTE: the positions of the numbers have changed!")) else: msg = _("Enter your current {} PIN:") - pin = self.handler.get_pin(msg.format(self.device)) + show_strength = False + pin = self.handler.get_pin(msg.format(self.device), show_strength=show_strength) if len(pin) > 9: self.handler.show_error(_('The PIN cannot be longer than 9 characters.')) pin = '' # to cancel below diff --git a/electrum/plugins/keepkey/qt.py b/electrum/plugins/keepkey/qt.py @@ -137,7 +137,7 @@ class CharacterDialog(WindowModalDialog): class QtHandler(QtHandlerBase): char_signal = pyqtSignal(object) - pin_signal = pyqtSignal(object) + pin_signal = pyqtSignal(object, object) close_char_dialog_signal = pyqtSignal() def __init__(self, win, pin_matrix_widget_class, device): @@ -162,17 +162,17 @@ class QtHandler(QtHandlerBase): self.character_dialog.accept() self.character_dialog = None - def get_pin(self, msg): + def get_pin(self, msg, *, show_strength=True): self.done.clear() - self.pin_signal.emit(msg) + self.pin_signal.emit(msg, show_strength) self.done.wait() return self.response - def pin_dialog(self, msg): + def pin_dialog(self, msg, show_strength): # Needed e.g. when resetting a device self.clear_dialog() dialog = WindowModalDialog(self.top_level_window(), _("Enter PIN")) - matrix = self.pin_matrix_widget_class() + matrix = self.pin_matrix_widget_class(show_strength) vbox = QVBoxLayout() vbox.addWidget(QLabel(msg)) vbox.addWidget(matrix) diff --git a/electrum/plugins/safe_t/clientbase.py b/electrum/plugins/safe_t/clientbase.py @@ -1,5 +1,6 @@ import time from struct import pack +from typing import Optional from electrum import ecc from electrum.i18n import _ @@ -7,11 +8,12 @@ from electrum.util import UserCancelled from electrum.keystore import bip39_normalize_passphrase from electrum.bip32 import BIP32Node, convert_bip32_path_to_list_of_uint32 from electrum.logging import Logger -from electrum.plugins.hw_wallet.plugin import HardwareClientBase +from electrum.plugins.hw_wallet.plugin import HardwareClientBase, HardwareHandlerBase class GuiMixin(object): # Requires: self.proto, self.device + handler: Optional[HardwareHandlerBase] # ref: https://github.com/trezor/trezor-common/blob/44dfb07cfaafffada4b2ce0d15ba1d90d17cf35e/protob/types.proto#L89 messages = { @@ -47,6 +49,7 @@ class GuiMixin(object): return self.proto.ButtonAck() def callback_PinMatrixRequest(self, msg): + show_strength = True if msg.type == 2: msg = _("Enter a new PIN for your {}:") elif msg.type == 3: @@ -54,7 +57,8 @@ class GuiMixin(object): "NOTE: the positions of the numbers have changed!")) else: msg = _("Enter your current {} PIN:") - pin = self.handler.get_pin(msg.format(self.device)) + show_strength = False + pin = self.handler.get_pin(msg.format(self.device), show_strength=show_strength) if len(pin) > 9: self.handler.show_error(_('The PIN cannot be longer than 9 characters.')) pin = '' # to cancel below diff --git a/electrum/plugins/safe_t/qt.py b/electrum/plugins/safe_t/qt.py @@ -38,24 +38,24 @@ PASSPHRASE_NOT_PIN = _( class QtHandler(QtHandlerBase): - pin_signal = pyqtSignal(object) + pin_signal = pyqtSignal(object, object) def __init__(self, win, pin_matrix_widget_class, device): super(QtHandler, self).__init__(win, device) self.pin_signal.connect(self.pin_dialog) self.pin_matrix_widget_class = pin_matrix_widget_class - def get_pin(self, msg): + def get_pin(self, msg, *, show_strength=True): self.done.clear() - self.pin_signal.emit(msg) + self.pin_signal.emit(msg, show_strength) self.done.wait() return self.response - def pin_dialog(self, msg): + def pin_dialog(self, msg, show_strength): # Needed e.g. when resetting a device self.clear_dialog() dialog = WindowModalDialog(self.top_level_window(), _("Enter PIN")) - matrix = self.pin_matrix_widget_class() + matrix = self.pin_matrix_widget_class(show_strength) vbox = QVBoxLayout() vbox.addWidget(QLabel(msg)) vbox.addWidget(matrix) diff --git a/electrum/plugins/trezor/clientbase.py b/electrum/plugins/trezor/clientbase.py @@ -246,6 +246,7 @@ class TrezorClientBase(HardwareClientBase, Logger): self.handler.show_message(message.format(self.device), self.client.cancel) def get_pin(self, code=None): + show_strength = True if code == 2: msg = _("Enter a new PIN for your {}:") elif code == 3: @@ -253,7 +254,8 @@ class TrezorClientBase(HardwareClientBase, Logger): "NOTE: the positions of the numbers have changed!")) else: msg = _("Enter your current {} PIN:") - pin = self.handler.get_pin(msg.format(self.device)) + show_strength = False + pin = self.handler.get_pin(msg.format(self.device), show_strength=show_strength) if not pin: raise Cancelled if len(pin) > 9: diff --git a/electrum/plugins/trezor/qt.py b/electrum/plugins/trezor/qt.py @@ -108,7 +108,7 @@ class MatrixDialog(WindowModalDialog): class QtHandler(QtHandlerBase): - pin_signal = pyqtSignal(object) + pin_signal = pyqtSignal(object, object) matrix_signal = pyqtSignal(object) close_matrix_dialog_signal = pyqtSignal() @@ -121,9 +121,9 @@ class QtHandler(QtHandlerBase): self.matrix_dialog = None self.passphrase_on_device = False - def get_pin(self, msg): + def get_pin(self, msg, *, show_strength=True): self.done.clear() - self.pin_signal.emit(msg) + self.pin_signal.emit(msg, show_strength) self.done.wait() return self.response @@ -144,11 +144,11 @@ class QtHandler(QtHandlerBase): def close_matrix_dialog(self): self.close_matrix_dialog_signal.emit() - def pin_dialog(self, msg): + def pin_dialog(self, msg, show_strength): # Needed e.g. when resetting a device self.clear_dialog() dialog = WindowModalDialog(self.top_level_window(), _("Enter PIN")) - matrix = self.pin_matrix_widget_class() + matrix = self.pin_matrix_widget_class(show_strength) vbox = QVBoxLayout() vbox.addWidget(QLabel(msg)) vbox.addWidget(matrix)