Browse Source

Support adding/removing/changing PIN on Trezor

283
Neil Booth 9 years ago
parent
commit
b50ace4225
  1. 46
      plugins/trezor/client.py
  2. 24
      plugins/trezor/qt_generic.py

46
plugins/trezor/client.py

@ -7,20 +7,20 @@ from electrum.util import PrintError
class GuiMixin(object):
# Requires: self.proto, self.device
messages = {
3: _("Confirm transaction outputs on %s device to continue"),
8: _("Confirm transaction fee on %s device to continue"),
7: _("Confirm message to sign on %s device to continue"),
10: _("Confirm address on %s device to continue"),
'change pin': _("Confirm PIN change on %s device to continue"),
'default': _("Check %s device to continue"),
'label': _("Confirm label change on %s device to continue"),
'remove pin': _("Confirm removal of PIN on %s device to continue"),
}
def callback_ButtonRequest(self, msg):
if msg.code == 3:
message = _("Confirm transaction outputs on %s device to continue")
elif msg.code == 8:
message = _("Confirm transaction fee on %s device to continue")
elif msg.code == 7:
if self.changing_label:
message = _("Confirm label change on %s device to continue")
else:
message = _("Confirm message to sign on %s device to continue")
elif msg.code == 10:
message = _("Confirm address on %s device to continue")
else:
message = _("Check %s device to continue")
msg_code = self.msg_code_override or msg.code
message = self.messages.get(msg_code, self.messages['default'])
if msg.code in [3, 8] and hasattr(self, 'cancel'):
cancel_callback = self.cancel
@ -32,11 +32,12 @@ class GuiMixin(object):
def callback_PinMatrixRequest(self, msg):
if msg.type == 1:
msg = _("Please enter %s current PIN")
msg = _("Enter your current %s PIN:")
elif msg.type == 2:
msg = _("Please enter %s new PIN")
msg = _("Enter a new %s PIN:")
elif msg.type == 3:
msg = _("Please enter %s new PIN again")
msg = (_("Please re-enter your new %s PIN.\n"
"Note the numbers have been shuffled!"))
else:
msg = _("Please enter %s PIN")
pin = self.handler.get_pin(msg % self.device)
@ -72,14 +73,21 @@ def trezor_client_class(protocol_mixin, base_client, proto):
self.handler = plugin.handler
self.tx_api = plugin
self.bad = False
self.changing_label = False
self.msg_code_override = None
def change_label(self, label):
self.changing_label = True
self.msg_code_override = 'label'
try:
self.apply_settings(label=label)
finally:
self.changing_label = False
self.msg_code_override = None
def set_pin(self, remove):
self.msg_code_override = 'remove pin' if remove else 'change pin'
try:
self.change_pin(remove)
finally:
self.msg_code_override = None
def firmware_version(self):
f = self.features

24
plugins/trezor/qt_generic.py

@ -187,8 +187,23 @@ class QtPlugin(TrezorPlugin):
self.handler.stop()
device_label.setText(new_label)
def update_pin_info():
features = client.features
pin_label.setText(noyes[features.pin_protection])
pin_button.setText(_("Change") if features.pin_protection
else _("Set"))
clear_pin_button.setVisible(features.pin_protection)
def set_pin(remove):
try:
client.set_pin(remove=remove)
finally:
self.handler.stop()
update_pin_info()
client = self.get_client()
features = client.features
noyes = [_("No"), _("Yes")]
bl_hash = features.bootloader_hash.encode('hex').upper()
bl_hash = "%s...%s" % (bl_hash[:10], bl_hash[-10:])
info_tab = QWidget()
@ -196,8 +211,13 @@ class QtPlugin(TrezorPlugin):
device_label = QLabel(features.label)
rename_button = QPushButton(_("Rename"))
rename_button.clicked.connect(rename)
pin_label = QLabel()
pin_button = QPushButton()
pin_button.clicked.connect(partial(set_pin, False))
clear_pin_button = QPushButton(_("Clear"))
clear_pin_button.clicked.connect(partial(set_pin, True))
update_pin_info()
noyes = [_("No"), _("Yes")]
version = "%d.%d.%d" % (features.major_version,
features.minor_version,
features.patch_version)
@ -208,7 +228,7 @@ class QtPlugin(TrezorPlugin):
(_("Firmware Version"), version),
(_("Language"), features.language),
(_("Has Passphrase"), noyes[features.passphrase_protection]),
(_("Has PIN"), noyes[features.pin_protection])
(_("Has PIN"), pin_label, pin_button, clear_pin_button)
]
for row_num, items in enumerate(rows):

Loading…
Cancel
Save