Пример #1
0
    def get_client(self, noPin=False):
        if not BTCHIP:
            self.give_error('please install github.com/btchip/btchip-python')

        aborted = False
        if not self.client or self.client.bad:
            try:
                d = getDongle(BTCHIP_DEBUG)
                d.setWaitImpl(DongleWaitQT(d))
                self.client = btchip(d)
                ver = self.client.getFirmwareVersion()
                firmware = ver['version'].split(".")
                self.canAlternateCoinVersions = (
                    ver['specialVersion'] >= 0x20
                    and map(int, firmware) >= [1, 0, 1])
                if not checkFirmware(firmware):
                    d.close()
                    try:
                        updateFirmware()
                    except Exception, e:
                        aborted = True
                        raise e
                    d = getDongle(BTCHIP_DEBUG)
                    d.setWaitImpl(DongleWaitQT(d))
                    self.client = btchip(d)
                try:
                    self.client.getOperationMode()
                except BTChipException, e:
                    if (e.sw == 0x6985):
                        d.close()
                        dialog = StartBTChipPersoDialog()
                        dialog.exec_()
                        # Then fetch the reference again  as it was invalidated
                        d = getDongle(BTCHIP_DEBUG)
                        d.setWaitImpl(DongleWaitQT(d))
                        self.client = btchip(d)
                    else:
                        raise e
                if not noPin:
                    # Immediately prompts for the PIN
                    remaining_attempts = self.client.getVerifyPinRemainingAttempts(
                    )
                    if remaining_attempts <> 1:
                        msg = "Enter your BTChip PIN - remaining attempts : " + str(
                            remaining_attempts)
                    else:
                        msg = "Enter your BTChip 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:
                        aborted = True
                        raise Exception(
                            'Aborted by user - please unplug the dongle and plug it again before retrying'
                        )
                    pin = pin.encode()
                    self.client.verifyPin(pin)
                    if self.canAlternateCoinVersions:
                        self.client.setAlternateCoinVersions(48, 5)
Пример #2
0
    def get_client(self, noPin=False):
        if not BTCHIP:
            give_error('please install github.com/btchip/btchip-python')

        aborted = False
        if not self.client or self.client.bad:
            try:
                d = getDongle(BTCHIP_DEBUG)
                d.setWaitImpl(DongleWaitQT(d))
                self.client = btchip(d)
                firmware = self.client.getFirmwareVersion()['version'].split(".")
                if int(firmware[0]) <> 1 or int(firmware[1]) <> 4:
                    aborted = True
                    raise Exception("Unsupported firmware version")
                if int(firmware[2]) < 9:
                    aborted = True
                    raise Exception("Please update your firmware - 1.4.9 or higher is necessary")
                try:
                    self.client.getOperationMode()
                except BTChipException, e:
                    if (e.sw == 0x6985):
                        d.close()
                        dialog = StartBTChipPersoDialog()                        
                        dialog.exec_()
                        # Then fetch the reference again  as it was invalidated
                        d = getDongle(BTCHIP_DEBUG)
                        d.setWaitImpl(DongleWaitQT(d))
                        self.client = btchip(d)
                    else:
                        raise e
                if not noPin:                    
                    # Immediately prompts for the PIN
                    remaining_attempts = self.client.getVerifyPinRemainingAttempts()                    
                    if remaining_attempts <> 1:
                        msg = "Enter your BTChip PIN - remaining attempts : " + str(remaining_attempts)
                    else:
                        msg = "Enter your BTChip 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:
                        aborted = True
                        raise Exception('Aborted by user - please unplug the dongle and plug it again before retrying')
                    pin = pin.encode()                   
                    self.client.verifyPin(pin)

            except BTChipException, e:
                try:
                    self.client.dongle.close()
                except:
                    pass
                self.client = None                
                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")
                raise e
Пример #3
0
    def get_client(self, noPin=False):
        if not BTCHIP:
            self.give_error('please install github.com/btchip/btchip-python')

        aborted = False
        if not self.client or self.client.bad:
            try:
                d = getDongle(BTCHIP_DEBUG)
                d.setWaitImpl(DongleWaitQT(d))
                self.client = btchip(d)
                ver = self.client.getFirmwareVersion()
                firmware = ver['version'].split(".")
                self.canAlternateCoinVersions = (ver['specialVersion'] >= 0x20 and
                                                 map(int, firmware) >= [1, 0, 1])
                if not checkFirmware(firmware):                    
                    d.close()
                    try:
                        updateFirmware()
                    except Exception, e:
                        aborted = True
                        raise e
                    d = getDongle(BTCHIP_DEBUG)
                    d.setWaitImpl(DongleWaitQT(d))
                    self.client = btchip(d)                    
                try:
                    self.client.getOperationMode()
                except BTChipException, e:
                    if (e.sw == 0x6985):
                        d.close()
                        dialog = StartBTChipPersoDialog()                        
                        dialog.exec_()
                        # Then fetch the reference again  as it was invalidated
                        d = getDongle(BTCHIP_DEBUG)
                        d.setWaitImpl(DongleWaitQT(d))
                        self.client = btchip(d)
                    else:
                        raise e
                if not noPin:                    
                    # Immediately prompts for the PIN
                    remaining_attempts = self.client.getVerifyPinRemainingAttempts()                    
                    if remaining_attempts <> 1:
                        msg = "Enter your BTChip PIN - remaining attempts : " + str(remaining_attempts)
                    else:
                        msg = "Enter your BTChip 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:
                        aborted = True
                        raise Exception('Aborted by user - please unplug the dongle and plug it again before retrying')
                    pin = pin.encode()                   
                    self.client.verifyPin(pin)
                    if self.canAlternateCoinVersions:
                        self.client.setAlternateCoinVersions(48, 5)
Пример #4
0
 def get_client(self, wallet, force_pair=True, noPin=False):
     aborted = False
     client = self.client
     if not client or client.bad:
         try:
             d = getDongle(BTCHIP_DEBUG)
             client = btchip(d)
             ver = client.getFirmwareVersion()
             firmware = ver['version'].split(".")
             wallet.canAlternateCoinVersions = (
                 ver['specialVersion'] >= 0x20
                 and map(int, firmware) >= [1, 0, 1])
             if not checkFirmware(firmware):
                 d.close()
                 try:
                     updateFirmware()
                 except Exception, e:
                     aborted = True
                     raise e
                 d = getDongle(BTCHIP_DEBUG)
                 client = btchip(d)
             try:
                 client.getOperationMode()
             except BTChipException, e:
                 if (e.sw == 0x6985):
                     d.close()
                     dialog = StartBTChipPersoDialog()
                     dialog.exec_()
                     # Then fetch the reference again  as it was invalidated
                     d = getDongle(BTCHIP_DEBUG)
                     client = btchip(d)
                 else:
                     raise e
             if not noPin:
                 # Immediately prompts for the PIN
                 remaining_attempts = client.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 = wallet.password_dialog(msg)
                 if not confirmed:
                     aborted = True
                     raise Exception(
                         'Aborted by user - please unplug the dongle and plug it again before retrying'
                     )
                 pin = pin.encode()
                 client.verifyPin(pin)
                 if wallet.canAlternateCoinVersions:
                     client.setAlternateCoinVersions(
                         PUBKEY_ADDR, SCRIPT_ADDR)
Пример #5
0
    def get_client(self, noPin=False):
        if not BTCHIP:
            self.give_error("please install github.com/btchip/btchip-python")

        aborted = False
        if not self.client or self.client.bad:
            try:
                d = getDongle(BTCHIP_DEBUG)
                self.client = btchip(d)
                self.client.handler = self.plugin.handler
                firmware = self.client.getFirmwareVersion()["version"].split(".")
                if not checkFirmware(firmware):
                    d.close()
                    try:
                        updateFirmware()
                    except Exception, e:
                        aborted = True
                        raise e
                    d = getDongle(BTCHIP_DEBUG)
                    self.client = btchip(d)
                try:
                    self.client.getOperationMode()
                except BTChipException, e:
                    if e.sw == 0x6985:
                        d.close()
                        dialog = StartBTChipPersoDialog()
                        dialog.exec_()
                        # Then fetch the reference again  as it was invalidated
                        d = getDongle(BTCHIP_DEBUG)
                        self.client = btchip(d)
                    else:
                        raise e
                if not noPin:
                    # Immediately prompts for the PIN
                    remaining_attempts = self.client.getVerifyPinRemainingAttempts()
                    if remaining_attempts <> 1:
                        msg = "Enter your BTChip PIN - remaining attempts : " + str(remaining_attempts)
                    else:
                        msg = "Enter your BTChip 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:
                        aborted = True
                        raise Exception("Aborted by user - please unplug the dongle and plug it again before retrying")
                    pin = pin.encode()
                    self.client.verifyPin(pin)
Пример #6
0
    def process(ctrl, mnemonic_words, pin, passphrase, secondary_pin):
        ctrl.dlg_config_fun(dlg_title="Please confirm", show_progress_bar=False)
        ctrl.display_msg_fun('<b>Please wait while initializing device...</b>')

        dongle = getDongle()

        # stage 1: initialize the hardware wallet with mnemonic words
        apdudata = bytearray()
        if pin:
            apdudata += bytearray([len(pin)]) + bytearray(pin, 'utf8')
        else:
            apdudata += bytearray([0])

        # empty prefix
        apdudata += bytearray([0])

        # empty passphrase in this phase
        apdudata += bytearray([0])

        if mnemonic_words:
            apdudata += bytearray([len(mnemonic_words)]) + bytearray(mnemonic_words, 'utf8')
        else:
            apdudata += bytearray([0])

        apdu = bytearray([0xE0, 0xD0, 0x00, 0x00, len(apdudata)]) + apdudata
        dongle.exchange(apdu, timeout=3000)

        # stage 2: setup the secondary pin and the passphrase if provided
        if passphrase and secondary_pin:
            ctrl.display_msg_fun('<b>Configuring the passphrase, enter the primary PIN on your <br>'
                                 'hardware wallet when asked...</b>')

            apdudata = bytearray()
            if pin:
                apdudata += bytearray([len(pin)]) + bytearray(secondary_pin, 'utf8')
            else:
                apdudata += bytearray([0])

            # empty prefix
            apdudata += bytearray([0])

            if passphrase:
                passphrase = unicodedata.normalize('NFKD', passphrase)
                apdudata += bytearray([len(passphrase)]) + bytearray(passphrase, 'utf8')
            else:
                apdudata += bytearray([0])

            # empty mnemonic words in this phase
            apdudata += bytearray([0])

            apdu = bytearray([0xE0, 0xD0, 0x01, 0x00, len(apdudata)]) + apdudata
            dongle.exchange(apdu, timeout=3000)

        dongle.close()
        del dongle
Пример #7
0
 def get_client(self, wallet, noPin=False):
     aborted = False
     client = self.client
     if not client or client.bad:
         try:
             d = getDongle(BTCHIP_DEBUG)
             client = btchip(d)
             firmware = client.getFirmwareVersion()['version'].split(".")
             if not checkFirmware(firmware):
                 d.close()
                 try:
                     updateFirmware()
                 except Exception, e:
                     aborted = True
                     raise e
                 d = getDongle(BTCHIP_DEBUG)
                 client = btchip(d)
             try:
                 client.getOperationMode()
             except BTChipException, e:
                 if (e.sw == 0x6985):
                     d.close()
                     dialog = StartBTChipPersoDialog()
                     dialog.exec_()
                     # Then fetch the reference again  as it was invalidated
                     d = getDongle(BTCHIP_DEBUG)
                     client = btchip(d)
                 else:
                     raise e
             if not noPin:
                 # Immediately prompts for the PIN
                 remaining_attempts = client.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 = wallet.password_dialog(msg)
                 if not confirmed:
                     aborted = True
                     raise Exception('Aborted by user - please unplug the dongle and plug it again before retrying')
                 pin = pin.encode()
                 client.verifyPin(pin)
Пример #8
0
    def load_hw_devices(self):
        """
        Load all instances of the selected hardware wallet type. If there is more than one, user has to select which
        one he is going to use.
        """

        control_trezor_keepkey_libs(self.hw_type)
        self.main_ui.disconnectHardwareWallet(
        )  # disconnect hw if it's open in the main window
        self.hw_device_instances.clear()
        self.cboDeviceInstance.clear()

        if self.hw_type == HWType.trezor:
            import trezorlib.client as client
            from trezorlib.transport_hid import HidTransport

            for d in HidTransport.enumerate():
                transport = HidTransport(d)
                cl = client.TrezorClient(transport)
                lbl = cl.features.label + ' (' + cl.features.device_id + ')'
                self.hw_device_instances.append([lbl, cl.features.device_id])
                self.cboDeviceInstance.addItem(lbl)
                cl.clear_session()
                cl.close()

        elif self.hw_type == HWType.keepkey:
            import keepkeylib.client as client
            from keepkeylib.transport_hid import HidTransport

            for d in HidTransport.enumerate():
                transport = HidTransport(d)
                cl = client.KeepKeyClient(transport)
                lbl = cl.features.label + ' (' + cl.features.device_id + ')'
                self.hw_device_instances.append([lbl, cl.features.device_id])
                self.cboDeviceInstance.addItem(lbl)
                cl.clear_session()
                cl.close()

        elif self.hw_type == HWType.ledger_nano_s:
            from btchip.btchipComm import getDongle
            from btchip.btchipException import BTChipException
            try:
                dongle = getDongle()
                if dongle:
                    lbl = HWType.get_desc(self.hw_type)
                    self.hw_device_instances.append([lbl, None])
                    self.cboDeviceInstance.addItem(lbl)
                    dongle.close()
                    del dongle
            except BTChipException as e:
                if e.message != 'No dongle found':
                    raise
Пример #9
0
def connect_ledgernano():
    dongle = getDongle()
    app = btchip(dongle)
    try:
        ver = app.getFirmwareVersion()
        logging.info('Ledger Nano S connected. Firmware version: %s, specialVersion: %s, compressedKeys: %s' %
                     (str(ver.get('version')), str(ver.get('specialVersion')), ver.get('compressedKeys')))

        client = btchip_dmt(dongle)
        return client
    except:
        dongle.close()
        raise
from btchip.btchip import btchip
from btchip.btchipComm import getDongle


def sha256(text):
    import hashlib
    m = hashlib.sha256()
    m.update(bytearray.fromhex(text))

    return m.digest()


dongle = getDongle(True)
app = btchip(dongle)

# Set passwords
# empty password
app.setBTCVPassword("1", btchip.BTCV_PASSWORD_INSTANT)

instantPassword = "******"
recoveryPassword = "******"

app.setBTCVPassword(instantPassword, btchip.BTCV_PASSWORD_INSTANT)
app.setBTCVPassword(recoveryPassword, btchip.BTCV_PASSWORD_RECOVERY)

# Set password use
instantPasswordHash = sha256(bytearray(instantPassword.encode('utf-8')).hex().ljust(64, '0'))
recoveryPasswordHash = sha256(bytearray(recoveryPassword.encode('utf-8')).hex().ljust(64, '0'))

app.setBTCVPasswordUse(bytearray(32), btchip.BTCV_TX_ALERT)
Пример #11
0
    def get_client(self, noPin=False):
        if not BTCHIP:
            give_error('please install github.com/btchip/btchip-python')

        aborted = False
        if not self.client or self.client.bad:
            try:
                d = getDongle(BTCHIP_DEBUG)
                d.setWaitImpl(DongleWaitQT(d))
                self.client = btchip(d)
                firmware = self.client.getFirmwareVersion()['version'].split(
                    ".")
                if int(firmware[0]) <> 1 or int(firmware[1]) <> 4:
                    aborted = True
                    raise Exception("Unsupported firmware version")
                if int(firmware[2]) < 9:
                    aborted = True
                    raise Exception(
                        "Please update your firmware - 1.4.9 or higher is necessary"
                    )
                try:
                    self.client.getOperationMode()
                except BTChipException, e:
                    if (e.sw == 0x6985):
                        d.close()
                        dialog = StartBTChipPersoDialog()
                        dialog.exec_()
                        # Then fetch the reference again  as it was invalidated
                        d = getDongle(BTCHIP_DEBUG)
                        d.setWaitImpl(DongleWaitQT(d))
                        self.client = btchip(d)
                    else:
                        raise e
                if not noPin:
                    # Immediately prompts for the PIN
                    remaining_attempts = self.client.getVerifyPinRemainingAttempts(
                    )
                    if remaining_attempts <> 1:
                        msg = "Enter your BTChip PIN - remaining attempts : " + str(
                            remaining_attempts)
                    else:
                        msg = "Enter your BTChip 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:
                        aborted = True
                        raise Exception(
                            'Aborted by user - please unplug the dongle and plug it again before retrying'
                        )
                    pin = pin.encode()
                    self.client.verifyPin(pin)

            except BTChipException, e:
                try:
                    self.client.dongle.close()
                except:
                    pass
                self.client = None
                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"
                    )
                raise e