コード例 #1
0
 def dbb_load_backup(self, show_msg=True):
     backups = self.hid_send_encrypt(b'{"backup":"list"}')
     if 'error' in backups:
         raise UserFacingException(backups['error']['message'])
     try:
         f = self.handler.win.query_choice(_("Choose a backup file:"),
                                           backups['backup'])
     except Exception:
         return False  # Back button pushed
     key = self.backup_password_dialog()
     if key is None:
         raise Exception('Canceled by user')
     key = self.stretch_key(key)
     if show_msg:
         self.handler.show_message(
             _("Loading backup...") + "\n\n" +
             _("To continue, touch the Digital Bitbox's light for 3 seconds."
               ) + "\n\n" +
             _("To cancel, briefly touch the light or wait for the timeout."
               ))
     msg = ('{"seed":{"source": "backup", "key": "%s", "filename": "%s"}}' %
            (key, backups['backup'][f])).encode('utf8')
     hid_reply = self.hid_send_encrypt(msg)
     self.handler.finished()
     if 'error' in hid_reply:
         raise UserFacingException(hid_reply['error']['message'])
     return True
コード例 #2
0
 def dbb_erase(self):
     self.handler.show_message(
         _("Are you sure you want to erase the Digital Bitbox?") + "\n\n" +
         _("To continue, touch the Digital Bitbox's light for 3 seconds.") +
         "\n\n" +
         _("To cancel, briefly touch the light or wait for the timeout."))
     hid_reply = self.hid_send_encrypt(b'{"reset":"__ERASE__"}')
     self.handler.finished()
     if 'error' in hid_reply:
         raise UserFacingException(hid_reply['error']['message'])
     else:
         self.password = None
         raise UserFacingException('Device erased')
コード例 #3
0
    def create_client(self, device, handler):
        if device.product_key[1] == 2:
            transport = self._try_webusb(device)
        else:
            transport = self._try_hid(device)

        if not transport:
            self.logger.info("cannot connect to device")
            return

        self.logger.info(f"connected to device at {device.path}")

        client = self.client_class(transport, handler, self)

        # Try a ping for device sanity
        try:
            client.ping('t')
        except BaseException as e:
            self.logger.info(f"ping failed {e}")
            return None

        if not client.atleast_version(*self.minimum_firmware):
            msg = (_('Outdated {} firmware for device labelled {}. Please '
                     'download the updated firmware from {}').format(
                         self.device, client.label(), self.firmware_URL))
            self.logger.info(msg)
            if handler:
                handler.show_error(msg)
            else:
                raise UserFacingException(msg)
            return None

        return client
コード例 #4
0
 def dbb_has_password(self):
     reply = self.hid_send_plain(b'{"ping":""}')
     if 'ping' not in reply:
         raise UserFacingException(
             _('Device communication error. Please unplug and replug your Digital Bitbox.'
               ))
     if reply['ping'] == 'password':
         return True
     return False
コード例 #5
0
 def dbb_generate_wallet(self):
     key = self.stretch_key(self.password)
     filename = ("Terracoin-Electrum-" +
                 time.strftime("%Y-%m-%d-%H-%M-%S") + ".pdf")
     msg = (
         '{"seed":{"source": "create", "key": "%s", "filename": "%s", "entropy": "%s"}}'
         % (key, filename, to_hexstr(os.urandom(32)))).encode('utf8')
     reply = self.hid_send_encrypt(msg)
     if 'error' in reply:
         raise UserFacingException(reply['error']['message'])
コード例 #6
0
 def setup_device(self, device_info, wizard, purpose):
     devmgr = self.device_manager()
     device_id = device_info.device.id_
     client = devmgr.client_by_id(device_id)
     if client is None:
         raise UserFacingException(
             _('Failed to create a client '
               'for this device.') + '\n' + _('Make sure it is in the '
                                              'correct state.'))
     # fixme: we should use: client.handler = wizard
     client.handler = self.create_handler(wizard)
     client.init_device()
     if not client.is_initialized():
         msg = _("Hideez Wallet is not initialized.\n\n"
                 "To initialize your Hideez Wallet please switch to "
                 "Hideez Bridge window and do device initialization "
                 "and backup sequence.\n\n"
                 "When device initialization and backup is finished "
                 "press 'Next' to proceed.")
         raise UserFacingException(msg)
     client.get_xpub('m', 'standard')
     client.used()
コード例 #7
0
 def setup_device(self, device_info, wizard, purpose):
     devmgr = self.device_manager()
     device_id = device_info.device.id_
     client = devmgr.client_by_id(device_id)
     if client is None:
         raise UserFacingException(
             _('Failed to create a client for this device.') + '\n' +
             _('Make sure it is in the correct state.'))
     # fixme: we should use: client.handler = wizard
     client.handler = self.create_handler(wizard)
     if not device_info.initialized:
         self.initialize_device(device_id, wizard, client.handler)
     client.get_xpub('m', 'standard')
     client.used()
コード例 #8
0
ファイル: trezor.py プロジェクト: terracoin/electrum-trc
    def setup_device(self, device_info, wizard, purpose):
        devmgr = self.device_manager()
        device_id = device_info.device.id_
        client = devmgr.client_by_id(device_id)
        if client is None:
            raise UserFacingException(
                _('Failed to create a client for this device.') + '\n' +
                _('Make sure it is in the correct state.'))

        if not client.is_uptodate():
            msg = (_('Outdated {} firmware for device labelled {}. Please '
                     'download the updated firmware from {}').format(
                         self.device, client.label(), self.firmware_URL))
            raise OutdatedHwFirmwareException(msg)

        # fixme: we should use: client.handler = wizard
        client.handler = self.create_handler(wizard)
        if not device_info.initialized:
            self.initialize_device(device_id, wizard, client.handler)
        is_creating_wallet = purpose == HWD_SETUP_NEW_WALLET
        client.get_xpub('m', 'standard', creating=is_creating_wallet)
        client.used()
コード例 #9
0
    def sign_transaction(self, tx, password):
        if tx.is_complete():
            return
        # previous transactions used as inputs
        prev_tx = {}
        # path of the xpubs that are involved
        xpub_path = {}
        for txin in tx.inputs():
            pubkeys, x_pubkeys = tx.get_sorted_pubkeys(txin)
            tx_hash = txin['prevout_hash']
            if txin.get('prev_tx') is None:
                raise UserFacingException(
                    _('Offline signing with {} is not supported for legacy inputs.'
                      ).format(self.device))
            prev_tx[tx_hash] = txin['prev_tx']
            for x_pubkey in x_pubkeys:
                if not is_xpubkey(x_pubkey):
                    continue
                xpub, s = parse_xpubkey(x_pubkey)
                if xpub == self.get_master_public_key():
                    xpub_path[xpub] = self.get_derivation()

        self.plugin.sign_transaction(self, tx, prev_tx, xpub_path)
コード例 #10
0
 def recover_or_erase_dialog(self):
     msg = _(
         "The Digital Bitbox is already seeded. Choose an option:") + "\n"
     choices = [
         (_("Create a wallet using the current seed")),
         (_("Load a wallet from the micro SD card (the current seed is overwritten)"
            )), (_("Erase the Digital Bitbox"))
     ]
     try:
         reply = self.handler.win.query_choice(msg, choices)
     except Exception:
         return  # Back button pushed
     if reply == 2:
         self.dbb_erase()
     elif reply == 1:
         if not self.dbb_load_backup():
             return
     else:
         if self.hid_send_encrypt(b'{"device":"info"}')['device']['lock']:
             raise UserFacingException(
                 _("Full 2FA enabled. This is not supported yet."))
         # Use existing seed
     self.isInitialized = True
コード例 #11
0
 def decrypt_message(self, sequence, message, password):
     raise UserFacingException(
         _('Encryption and decryption are not implemented by {}').format(
             self.device))