trezor pin dialog: only show PIN "strength" when creating/changing
fixes #4832
This commit is contained in:
@@ -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):
|
||||
|
||||
@@ -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-----")
|
||||
|
||||
@@ -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()])
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user