示例#1
0
    def check_libraries_available(self) -> bool:
        def version_str(t):
            return ".".join(str(i) for i in t)

        try:
            # this might raise ImportError or LibraryFoundButUnusable
            library_version = self.get_library_version()
            # if no exception so far, we might still raise LibraryFoundButUnusable
            if (library_version == 'unknown'
                    or versiontuple(library_version) < self.minimum_library
                    or hasattr(self, "maximum_library")
                    and versiontuple(library_version) >= self.maximum_library):
                raise LibraryFoundButUnusable(library_version=library_version)
        except ImportError:
            return False
        except LibraryFoundButUnusable as e:
            library_version = e.library_version
            max_version_str = (version_str(self.maximum_library) if hasattr(
                self, "maximum_library") else "inf")
            self.libraries_available_message = (
                _("Library version for '{}' is incompatible.").format(
                    self.name) +
                '\nInstalled: {}, Needed: {} <= x < {}'.format(
                    library_version, version_str(self.minimum_library),
                    max_version_str))
            self.logger.warning(self.libraries_available_message)
            return False

        return True
示例#2
0
    def perform_hw1_preflight(self):
        try:
            firmwareInfo = self.dongleObject.getFirmwareVersion()
            firmware = firmwareInfo['version']
            self.bitcoinCashSupported = versiontuple(
                firmware) >= BITCOIN_CASH_SUPPORT

            if not checkFirmware(
                    firmwareInfo) or not self.supports_bitcoin_cash():
                self.dongleObject.dongle.close()
                raise Exception(
                    "HW1 firmware version too old. Please update at "
                    "https://www.ledgerwallet.com")
            try:
                self.dongleObject.getOperationMode()
            except BTChipException as e:
                if e.sw == 0x6985:
                    self.dongleObject.dongle.close()
                    self.handler.get_setup()
                    # Acquire the new client on the next run
                else:
                    raise e
            if (self.has_detached_pin_support(self.dongleObject)
                    and not self.is_pin_validated(self.dongleObject)
                    and (self.handler is not None)):
                remaining_attempts = self.dongleObject.getVerifyPinRemainingAttempts(
                )
                if remaining_attempts != 1:
                    msg = "Enter your Ledger PIN - remaining attempts : " + str(
                        remaining_attempts)
                else:
                    msg = (
                        "Enter your Ledger PIN - WARNING : LAST ATTEMPT. "
                        "If the PIN is not correct, the dongle will be wiped.")
                confirmed, p, pin = self.password_dialog(msg)
                if not confirmed:
                    raise Exception(
                        'Aborted by user - please unplug the dongle '
                        'and plug it again before retrying')
                pin = pin.encode()
                self.dongleObject.verifyPin(pin)

        except BTChipException as e:
            if e.sw == 0x6faa:
                raise Exception(
                    "Dongle is temporarily locked - please unplug it and "
                    "replug it again")
            if (e.sw & 0xFFF0) == 0x63c0:
                raise Exception(
                    "Invalid PIN - please unplug the dongle and plug "
                    "it again before retrying")
            if e.sw == 0x6f00 and e.message == 'Invalid channel':
                # based on docs 0x6f00 might be a more general error, hence we also
                # compare message to be sure
                raise Exception(
                    "Invalid channel.\nPlease make sure that "
                    "'Browser support' is disabled on your device.")
            raise e