Exemple #1
0
 async def communication_settings(self):
     buttons = [(None, "Communication channels")] + [
         (host, host.settings_button)
         for host in self.hosts if host.settings_button is not None
     ]
     while True:
         menuitem = await self.gui.menu(buttons,
                                        title="Communication settings",
                                        note="Firmware version %s" %
                                        get_version(),
                                        last=(255, None))
         if menuitem == 255:
             return
         elif isinstance(menuitem, Host):
             reboot_required = await menuitem.settings_menu(
                 self.gui.show_screen(), self.keystore)
             if reboot_required:
                 if await self.gui.prompt(
                         "Reboot required!",
                         "Settings have been updated and will become active after reboot.\n\n"
                         "Do you want to reboot now?",
                 ):
                     reboot()
         else:
             print(menuitem)
             raise SpecterError("Not implemented")
 async def main(self):
     buttons = [
         (1, "Wipe the device storage"),
         (2, "Configure QR code scanner"),
         (3, "Scan something"),
         (4, "Test smartcard"),
     ]
     while True:
         res = await self.gui.menu(buttons,
                     title="Factory test, version %s" % get_version(),
                     note="This firmware is used to test electrical connections between the discovery board and other components.\nIt can also erase the content of the internal storage\n(factory reset).")
         if res == 1:
             conf = await self.gui.prompt("Wipe the device?",
                     "This will delete everything from internal storage.")
             if conf:
                 await self.wipe()
         elif res == 2:
             if self.qr is None:
                 self.qr = QRHost(self.rampath+"/qr")
                 self.qr.init()
                 self.qr.start(self)
             if self.qr.is_configured:
                 await self.gui.alert("Success!", "QR code scanner is configured")
             else:
                 await self.gui.alert("Fail...", "Something went wrong. Maybe reboot and try again...")
         elif res == 3:
             if self.qr is None:
                 self.qr = QRHost(self.rampath+"/qr")
                 self.qr.init()
                 self.qr.start(self)
             await self.qr.enable()
             s = await self.qr.get_data()
             if s:
                 data = s.read().decode()
                 await self.gui.alert("Here's what we scanned:", data)
         else:
             conn = get_connection()
             if not conn.isCardInserted():
                 await self.gui.alert("Card is not present!",
                     "Smartcard is not inserted")
             else:
                 try:
                     conn.connect(conn.T1_protocol)
                 except:
                     pass
                 try:
                     app = MemoryCardApplet(conn)
                     app.open_secure_channel()
                     print(app.get_pin_status())
                     if app.is_pin_set:
                         await self.gui.alert("Smartcard works!", "Pin is set")
                     else:
                         await self.gui.alert("Smartcard works!", "Pin is not set")
                 except Exception as e:
                     await self.gui.alert("Something went wrong...",
                         "We got an exception: %r" % e)
         await asyncio.sleep_ms(30)
Exemple #3
0
 async def update_devsettings(self):
     buttons = [
         (None, "Communication settings")
     ] + [
         (host, host.settings_button)
         for host in self.hosts
         if host.settings_button is not None
     ] + [
         (None, "Global settings"),
     ]
     if hasattr(self.keystore, "lock"):
         buttons.extend([(3, "Change PIN code")])
     buttons += [
         (456, "Reboot"),
         (123, "Wipe the device", True, 0x951E2D),
     ]
     while True:
         menuitem = await self.gui.menu(buttons,
                                   title="Device settings",
                                   note="Firmware version %s" % get_version(),
                                   last=(255, None)
         )
         if menuitem == 255:
             return
         elif menuitem == 456:
             if await self.gui.prompt(
                 "Reboot the device?",
                 "\n\nAre you sure?",
             ):
                 reboot()
             return
         # WIPE
         elif menuitem == 123:
             if await self.gui.prompt(
                 "Wiping the device will erase everything in the internal storage!",
                 "This includes multisig wallet files, keys, apps data etc.\n\n"
                 "But it doesn't include files stored on SD card or smartcard.\n\n"
                 "Are you sure?",
             ):
                 self.wipe()
             return
         elif menuitem == 3:
             await self.keystore.change_pin()
             return
         elif isinstance(menuitem, Host):
             reboot_required = await menuitem.settings_menu(self.gui.show_screen(), self.keystore)
             if reboot_required:
                 if await self.gui.prompt(
                     "Reboot required!",
                     "Settings have been updated and will become active after reboot.\n\n"
                     "Do you want to reboot now?",
                 ):
                     reboot()
         else:
             print(menuitem)
             raise SpecterError("Not implemented")
Exemple #4
0
 async def update_devsettings(self):
     buttons = [(None, "Categories")] + [
         (1, "Communication"),
         # (2, "Applications"),
         (3, "Experimental"),
     ] + [
         (None, "Global settings"),
     ]
     if hasattr(self.keystore, "lock"):
         buttons.extend([(777, "Change PIN code")])
     buttons += [
         (456, "Reboot"),
         (123, "Wipe the device", True, 0x951E2D),
     ]
     while True:
         menuitem = await self.gui.menu(buttons,
                                        title="Device settings",
                                        note="Firmware version %s" %
                                        get_version(),
                                        last=(255, None))
         if menuitem == 255:
             return
         elif menuitem == 3:
             await self.experimental_settings()
         elif menuitem == 456:
             if await self.gui.prompt(
                     "Reboot the device?",
                     "\n\nAre you sure?",
             ):
                 reboot()
             return
         # WIPE
         elif menuitem == 123:
             if await self.gui.prompt(
                     "Wiping the device will erase everything in the internal storage!",
                     "This includes multisig wallet files, keys, apps data etc.\n\n"
                     "But it doesn't include files stored on SD card or smartcard.\n\n"
                     "Are you sure?",
             ):
                 self.wipe()
             return
         elif menuitem == 777:
             await self.keystore.change_pin()
             return
         elif menuitem == 1:
             await self.communication_settings()
         else:
             print(menuitem)
             raise SpecterError("Not implemented")
    async def settingsmenu(self):
        net = NETWORKS[self.network]["name"]
        buttons = [
            # id, text
            (None, "Network"),
            (5, "Switch network (%s)" % net),
            (None, "Key management"),
        ]
        if self.keystore.storage_button is not None:
            buttons.append((0, self.keystore.storage_button))
        buttons.extend([(2, "Enter BIP-39 password"),
                        (None, "Security")])  # delimiter
        if hasattr(self.keystore, "lock"):
            buttons.extend([(3, "Change PIN code")])
        buttons.extend([(4, "Device settings")])
        # wait for menu selection
        menuitem = await self.gui.menu(buttons,
                                       last=(255, None),
                                       note="Firmware version %s" %
                                       get_version())

        # process the menu button:
        # back button
        if menuitem == 255:
            return self.mainmenu
        elif menuitem == 0:
            await self.keystore.storage_menu()
        elif menuitem == 2:
            pwd = await self.gui.get_input()
            if pwd is None:
                return self.settingsmenu
            self.keystore.set_mnemonic(password=pwd)
            for app in self.apps:
                app.init(self.keystore, self.network, self.gui.show_loader)
        elif menuitem == 3:
            await self.keystore.change_pin()
            return self.mainmenu
        elif menuitem == 4:
            await self.update_devsettings()
        elif menuitem == 5:
            await self.select_network()
        else:
            print(menuitem)
            raise SpecterError("Not implemented")
        return self.settingsmenu
 async def update_devsettings(self):
     res = await self.gui.devscreen(dev=self.dev,
                                    usb=self.usb,
                                    note="Firmware version %s" %
                                    get_version())
     if res is not None:
         if res["wipe"]:
             if await self.gui.prompt(
                     "Wiping the device will erase everything in the internal storage!",
                     "This includes multisig wallet files, keys, apps data etc.\n\n"
                     "But it doesn't include files stored on SD card or smartcard.\n\n"
                     "Are you sure?",
             ):
                 self.wipe()
             return
         self.update_config(**res)
         if await self.gui.prompt(
                 "Reboot required!",
                 "Changing USB mode requires to "
                 "reboot the device. Proceed?",
         ):
             reboot()