Browse Source

Implement passphrase protection toggling.

Along with chicken box.
283
Neil Booth 9 years ago
parent
commit
6fb7dbd30d
  1. 2
      gui/qt/installwizard.py
  2. 14
      lib/plugins.py
  3. 9
      plugins/trezor/client.py
  4. 20
      plugins/trezor/qt_generic.py

2
gui/qt/installwizard.py

@ -439,7 +439,6 @@ class InstallWizard(WindowModalDialog, WizardBase):
else: else:
text = QTextEdit() text = QTextEdit()
text.setMaximumHeight(60) text.setMaximumHeight(60)
vbox.addWidget(text)
if method == self.TIM_MNEMONIC: if method == self.TIM_MNEMONIC:
msg = _("Enter your BIP39 mnemonic:") msg = _("Enter your BIP39 mnemonic:")
else: else:
@ -451,6 +450,7 @@ class InstallWizard(WindowModalDialog, WizardBase):
OK_button.setEnabled(False) OK_button.setEnabled(False)
vbox.addWidget(QLabel(msg)) vbox.addWidget(QLabel(msg))
vbox.addWidget(text)
pin = QLineEdit() pin = QLineEdit()
pin.setValidator(QRegExpValidator(QRegExp('[1-9]{0,10}'))) pin.setValidator(QRegExpValidator(QRegExp('[1-9]{0,10}')))
pin.setMaximumWidth(100) pin.setMaximumWidth(100)

14
lib/plugins.py

@ -238,14 +238,12 @@ class DeviceMgr(PrintError):
a device is plugged into a different port the wallet is a device is plugged into a different port the wallet is
automatically re-paired. automatically re-paired.
Wallets are informed on connect / disconnect / unpairing events. Wallets are informed on connect / disconnect events. It must
It must implement connected(), disconnected() and unpaired() implement connected(), disconnected() callbacks. Being connected
callbacks. Being connected implies a pairing. Being disconnected implies a pairing. Callbacks can happen in any thread context,
doesn't. Callbacks can happen in any thread context, and we do and we do them without holding the lock.
them without holding the lock.
This plugin is thread-safe. Currently only USB is implemented.'''
This plugin is thread-safe. Currently only USB is implemented.
'''
# Client lookup types. CACHED will look up in our client cache # Client lookup types. CACHED will look up in our client cache
# only. PRESENT will do a scan if there is no client in the cache. # only. PRESENT will do a scan if there is no client in the cache.

9
plugins/trezor/client.py

@ -16,6 +16,7 @@ class GuiMixin(object):
'default': _("Check %s device to continue"), 'default': _("Check %s device to continue"),
'label': _("Confirm label change on %s device to continue"), 'label': _("Confirm label change on %s device to continue"),
'remove pin': _("Confirm removal of PIN on %s device to continue"), 'remove pin': _("Confirm removal of PIN on %s device to continue"),
'passphrase': _("Confirm on %s device to continue"),
} }
def callback_ButtonRequest(self, msg): def callback_ButtonRequest(self, msg):
@ -126,6 +127,14 @@ def trezor_client_class(protocol_mixin, base_client, proto):
def address_from_derivation(self, derivation): def address_from_derivation(self, derivation):
return self.get_address('Bitcoin', self.expand_path(derivation)) return self.get_address('Bitcoin', self.expand_path(derivation))
def toggle_passphrase(self):
self.msg_code_override = 'passphrase'
try:
enabled = not self.features.passphrase_protection
self.apply_settings(use_passphrase=enabled)
finally:
self.msg_code_override = None
def change_label(self, label): def change_label(self, label):
self.msg_code_override = 'label' self.msg_code_override = 'label'
try: try:

20
plugins/trezor/qt_generic.py

@ -208,6 +208,22 @@ def qt_plugin_class(base_plugin_class):
get_client().change_label(str(response[0])) get_client().change_label(str(response[0]))
refresh() refresh()
def toggle_passphrase():
title = _("Confirm Toggle Passphrase Protection")
msg = _("This will cause your Electrum wallet to be unpaired "
"unless your passphrase was or will be empty.\n\n"
"This is because addresses will no "
"longer correspond to those used by your %s.\n\n"
"If your passphrase is not or was not empty you will "
"need to create a new Electrum wallet with the install "
"wizard so that they match.\n\n"
"Are you sure you want to proceed?") % device
if not dialog.question(msg, title=title):
return
get_client().toggle_passphrase()
self.device_manager().close_wallet(wallet) # Unpair
refresh()
def set_pin(): def set_pin():
get_client().set_pin(remove=False) get_client().set_pin(remove=False)
refresh() refresh()
@ -266,6 +282,8 @@ def qt_plugin_class(base_plugin_class):
language_label = QLabel() language_label = QLabel()
rename_button = QPushButton(_("Rename")) rename_button = QPushButton(_("Rename"))
rename_button.clicked.connect(rename) rename_button.clicked.connect(rename)
toggle_passphrase_button = QPushButton(_("Toggle"))
toggle_passphrase_button.clicked.connect(toggle_passphrase)
pin_button = QPushButton() pin_button = QPushButton()
pin_button.clicked.connect(set_pin) pin_button.clicked.connect(set_pin)
clear_pin_button = QPushButton(_("Clear")) clear_pin_button = QPushButton(_("Clear"))
@ -273,7 +291,7 @@ def qt_plugin_class(base_plugin_class):
add_rows_to_layout(info_layout, [ add_rows_to_layout(info_layout, [
(_("Device Label"), device_label, rename_button), (_("Device Label"), device_label, rename_button),
(_("Has Passphrase"), passphrase_label), (_("Has Passphrase"), passphrase_label, toggle_passphrase_button),
(_("Has PIN"), pin_label, pin_button, clear_pin_button), (_("Has PIN"), pin_label, pin_button, clear_pin_button),
(_("Initialized"), initialized_label), (_("Initialized"), initialized_label),
(_("Device ID"), device_id_label), (_("Device ID"), device_id_label),

Loading…
Cancel
Save