Browse Source

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

fixes #4832
hard-fail-on-bad-server-string
SomberNight 5 years ago
parent
commit
caefea19dd
No known key found for this signature in database GPG Key ID: B33B5F232C6271E9
  1. 2
      electrum/plugins/coldcard/cmdline.py
  2. 2
      electrum/plugins/hw_wallet/cmdline.py
  3. 3
      electrum/plugins/hw_wallet/plugin.py
  4. 8
      electrum/plugins/keepkey/clientbase.py
  5. 10
      electrum/plugins/keepkey/qt.py
  6. 8
      electrum/plugins/safe_t/clientbase.py
  7. 10
      electrum/plugins/safe_t/qt.py
  8. 4
      electrum/plugins/trezor/clientbase.py
  9. 10
      electrum/plugins/trezor/qt.py

2
electrum/plugins/coldcard/cmdline.py

@ -15,7 +15,7 @@ class ColdcardCmdLineHandler(CmdLineHandler):
def get_passphrase(self, msg, confirm): def get_passphrase(self, msg, confirm):
raise NotImplementedError raise NotImplementedError
def get_pin(self, msg): def get_pin(self, msg, *, show_strength=True):
raise NotImplementedError raise NotImplementedError
def prompt_auth(self, msg): def prompt_auth(self, msg):

2
electrum/plugins/hw_wallet/cmdline.py

@ -14,7 +14,7 @@ class CmdLineHandler(HardwareHandlerBase):
print_stderr(msg) print_stderr(msg)
return getpass.getpass('') 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'} t = { 'a':'7', 'b':'8', 'c':'9', 'd':'4', 'e':'5', 'f':'6', 'g':'1', 'h':'2', 'i':'3'}
print_stderr(msg) print_stderr(msg)
print_stderr("a b c\nd e f\ng h i\n-----") print_stderr("a b c\nd e f\ng h i\n-----")

3
electrum/plugins/hw_wallet/plugin.py

@ -251,6 +251,9 @@ class HardwareHandlerBase:
def get_passphrase(self, msg: str, confirm: bool) -> Optional[str]: def get_passphrase(self, msg: str, confirm: bool) -> Optional[str]:
raise NotImplementedError() 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: def is_any_tx_output_on_change_branch(tx: PartialTransaction) -> bool:
return any([txout.is_change for txout in tx.outputs()]) return any([txout.is_change for txout in tx.outputs()])

8
electrum/plugins/keepkey/clientbase.py

@ -1,5 +1,6 @@
import time import time
from struct import pack from struct import pack
from typing import Optional
from electrum import ecc from electrum import ecc
from electrum.i18n import _ from electrum.i18n import _
@ -7,11 +8,12 @@ from electrum.util import UserCancelled
from electrum.keystore import bip39_normalize_passphrase from electrum.keystore import bip39_normalize_passphrase
from electrum.bip32 import BIP32Node, convert_bip32_path_to_list_of_uint32 from electrum.bip32 import BIP32Node, convert_bip32_path_to_list_of_uint32
from electrum.logging import Logger 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): class GuiMixin(object):
# Requires: self.proto, self.device # Requires: self.proto, self.device
handler: Optional[HardwareHandlerBase]
messages = { messages = {
3: _("Confirm the transaction output on your {} device"), 3: _("Confirm the transaction output on your {} device"),
@ -45,6 +47,7 @@ class GuiMixin(object):
return self.proto.ButtonAck() return self.proto.ButtonAck()
def callback_PinMatrixRequest(self, msg): def callback_PinMatrixRequest(self, msg):
show_strength = True
if msg.type == 2: if msg.type == 2:
msg = _("Enter a new PIN for your {}:") msg = _("Enter a new PIN for your {}:")
elif msg.type == 3: elif msg.type == 3:
@ -52,7 +55,8 @@ class GuiMixin(object):
"NOTE: the positions of the numbers have changed!")) "NOTE: the positions of the numbers have changed!"))
else: else:
msg = _("Enter your current {} PIN:") 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: if len(pin) > 9:
self.handler.show_error(_('The PIN cannot be longer than 9 characters.')) self.handler.show_error(_('The PIN cannot be longer than 9 characters.'))
pin = '' # to cancel below pin = '' # to cancel below

10
electrum/plugins/keepkey/qt.py

@ -137,7 +137,7 @@ class CharacterDialog(WindowModalDialog):
class QtHandler(QtHandlerBase): class QtHandler(QtHandlerBase):
char_signal = pyqtSignal(object) char_signal = pyqtSignal(object)
pin_signal = pyqtSignal(object) pin_signal = pyqtSignal(object, object)
close_char_dialog_signal = pyqtSignal() close_char_dialog_signal = pyqtSignal()
def __init__(self, win, pin_matrix_widget_class, device): def __init__(self, win, pin_matrix_widget_class, device):
@ -162,17 +162,17 @@ class QtHandler(QtHandlerBase):
self.character_dialog.accept() self.character_dialog.accept()
self.character_dialog = None self.character_dialog = None
def get_pin(self, msg): def get_pin(self, msg, *, show_strength=True):
self.done.clear() self.done.clear()
self.pin_signal.emit(msg) self.pin_signal.emit(msg, show_strength)
self.done.wait() self.done.wait()
return self.response return self.response
def pin_dialog(self, msg): def pin_dialog(self, msg, show_strength):
# Needed e.g. when resetting a device # Needed e.g. when resetting a device
self.clear_dialog() self.clear_dialog()
dialog = WindowModalDialog(self.top_level_window(), _("Enter PIN")) 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 = QVBoxLayout()
vbox.addWidget(QLabel(msg)) vbox.addWidget(QLabel(msg))
vbox.addWidget(matrix) vbox.addWidget(matrix)

8
electrum/plugins/safe_t/clientbase.py

@ -1,5 +1,6 @@
import time import time
from struct import pack from struct import pack
from typing import Optional
from electrum import ecc from electrum import ecc
from electrum.i18n import _ from electrum.i18n import _
@ -7,11 +8,12 @@ from electrum.util import UserCancelled
from electrum.keystore import bip39_normalize_passphrase from electrum.keystore import bip39_normalize_passphrase
from electrum.bip32 import BIP32Node, convert_bip32_path_to_list_of_uint32 from electrum.bip32 import BIP32Node, convert_bip32_path_to_list_of_uint32
from electrum.logging import Logger 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): class GuiMixin(object):
# Requires: self.proto, self.device # Requires: self.proto, self.device
handler: Optional[HardwareHandlerBase]
# ref: https://github.com/trezor/trezor-common/blob/44dfb07cfaafffada4b2ce0d15ba1d90d17cf35e/protob/types.proto#L89 # ref: https://github.com/trezor/trezor-common/blob/44dfb07cfaafffada4b2ce0d15ba1d90d17cf35e/protob/types.proto#L89
messages = { messages = {
@ -47,6 +49,7 @@ class GuiMixin(object):
return self.proto.ButtonAck() return self.proto.ButtonAck()
def callback_PinMatrixRequest(self, msg): def callback_PinMatrixRequest(self, msg):
show_strength = True
if msg.type == 2: if msg.type == 2:
msg = _("Enter a new PIN for your {}:") msg = _("Enter a new PIN for your {}:")
elif msg.type == 3: elif msg.type == 3:
@ -54,7 +57,8 @@ class GuiMixin(object):
"NOTE: the positions of the numbers have changed!")) "NOTE: the positions of the numbers have changed!"))
else: else:
msg = _("Enter your current {} PIN:") 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: if len(pin) > 9:
self.handler.show_error(_('The PIN cannot be longer than 9 characters.')) self.handler.show_error(_('The PIN cannot be longer than 9 characters.'))
pin = '' # to cancel below pin = '' # to cancel below

10
electrum/plugins/safe_t/qt.py

@ -38,24 +38,24 @@ PASSPHRASE_NOT_PIN = _(
class QtHandler(QtHandlerBase): class QtHandler(QtHandlerBase):
pin_signal = pyqtSignal(object) pin_signal = pyqtSignal(object, object)
def __init__(self, win, pin_matrix_widget_class, device): def __init__(self, win, pin_matrix_widget_class, device):
super(QtHandler, self).__init__(win, device) super(QtHandler, self).__init__(win, device)
self.pin_signal.connect(self.pin_dialog) self.pin_signal.connect(self.pin_dialog)
self.pin_matrix_widget_class = pin_matrix_widget_class 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.done.clear()
self.pin_signal.emit(msg) self.pin_signal.emit(msg, show_strength)
self.done.wait() self.done.wait()
return self.response return self.response
def pin_dialog(self, msg): def pin_dialog(self, msg, show_strength):
# Needed e.g. when resetting a device # Needed e.g. when resetting a device
self.clear_dialog() self.clear_dialog()
dialog = WindowModalDialog(self.top_level_window(), _("Enter PIN")) 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 = QVBoxLayout()
vbox.addWidget(QLabel(msg)) vbox.addWidget(QLabel(msg))
vbox.addWidget(matrix) vbox.addWidget(matrix)

4
electrum/plugins/trezor/clientbase.py

@ -246,6 +246,7 @@ class TrezorClientBase(HardwareClientBase, Logger):
self.handler.show_message(message.format(self.device), self.client.cancel) self.handler.show_message(message.format(self.device), self.client.cancel)
def get_pin(self, code=None): def get_pin(self, code=None):
show_strength = True
if code == 2: if code == 2:
msg = _("Enter a new PIN for your {}:") msg = _("Enter a new PIN for your {}:")
elif code == 3: elif code == 3:
@ -253,7 +254,8 @@ class TrezorClientBase(HardwareClientBase, Logger):
"NOTE: the positions of the numbers have changed!")) "NOTE: the positions of the numbers have changed!"))
else: else:
msg = _("Enter your current {} PIN:") 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: if not pin:
raise Cancelled raise Cancelled
if len(pin) > 9: if len(pin) > 9:

10
electrum/plugins/trezor/qt.py

@ -108,7 +108,7 @@ class MatrixDialog(WindowModalDialog):
class QtHandler(QtHandlerBase): class QtHandler(QtHandlerBase):
pin_signal = pyqtSignal(object) pin_signal = pyqtSignal(object, object)
matrix_signal = pyqtSignal(object) matrix_signal = pyqtSignal(object)
close_matrix_dialog_signal = pyqtSignal() close_matrix_dialog_signal = pyqtSignal()
@ -121,9 +121,9 @@ class QtHandler(QtHandlerBase):
self.matrix_dialog = None self.matrix_dialog = None
self.passphrase_on_device = False self.passphrase_on_device = False
def get_pin(self, msg): def get_pin(self, msg, *, show_strength=True):
self.done.clear() self.done.clear()
self.pin_signal.emit(msg) self.pin_signal.emit(msg, show_strength)
self.done.wait() self.done.wait()
return self.response return self.response
@ -144,11 +144,11 @@ class QtHandler(QtHandlerBase):
def close_matrix_dialog(self): def close_matrix_dialog(self):
self.close_matrix_dialog_signal.emit() 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 # Needed e.g. when resetting a device
self.clear_dialog() self.clear_dialog()
dialog = WindowModalDialog(self.top_level_window(), _("Enter PIN")) 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 = QVBoxLayout()
vbox.addWidget(QLabel(msg)) vbox.addWidget(QLabel(msg))
vbox.addWidget(matrix) vbox.addWidget(matrix)

Loading…
Cancel
Save