コード例 #1
0
def main():
    # List all connected TREZORs on USB
    devices = HidTransport.enumerate()

    # Check whether we found any
    if len(devices) == 0:
        print('No TREZOR found')
        return

    # Use first connected device
    transport = HidTransport(devices[0])

    # Creates object for manipulating TREZOR
    client = TrezorClient(transport)

    # Print out TREZOR's features and settings
    print(client.features)

    # Get the first address of first BIP44 account
    # (should be the same address as shown in wallet.trezor.io)
    bip32_path = client.expand_path("44'/42'/0'/0/0")
    address = client.get_address('Decred', bip32_path)
    print('Decred address:', address)

    address_n = client.expand_path("0")
    xpub = client.get_public_node('Decred', address_n)
    print('xpub: ', xpub)

    client.close()
コード例 #2
0
def main():
    # List all connected TREZORs on USB
    devices = HidTransport.enumerate()

    # Check whether we found any
    if len(devices) == 0:
        print 'No TREZOR found'
        return

    # Use first connected device
    transport = HidTransport(devices[0])

    # Creates object for manipulating TREZOR
    client = TrezorClient(transport)

    # Print out TREZOR's features and settings
    print client.features

    # Get the first address of first BIP44 account
    # (should be the same address as shown in mytrezor.com)
    bip32_path = client.expand_path("44'/0'/0'/0/0")
    address = client.get_address('Bitcoin', bip32_path)
    print 'Bitcoin address:', address

    client.close()
コード例 #3
0
def get_client():
    devices = HidTransport.enumerate()  # list all connected TREZORs on USB
    if len(devices) == 0:  # check whether we found any
        return None
    transport = HidTransport(devices[0])  # use first connected device
    return TrezorClient(
        transport)  # creates object for communicating with TREZOR
コード例 #4
0
def Choose_device(devices):
    if not len(devices):
        raise Exception("No TREZOR connected!")

    if len(devices) == 1:
        try:
            return HidTransport(devices[0])
        except OSError:
            raise Exception("Device is currently in use, try reconnect the device")

    i = 0
    print("----------------------------\n")
    print("Available devices:\n")
    for d in devices:
        try:
            client = TrezorClient(d)
        except OSError:
            sys.stderr.write("[-] <device is currently in use>\n")
            continue

        if client.features.label:
            print("[%d] %s\n" % (i, client.features.label))
        else:
            print("[%d] <no label>\n" % i)
        client.close()
        i += 1
        

    print("----------------------------\n")

    try:
        device_id = int(input("Please choose device to use:"))
        return HidTransport(devices[device_id])
    except:
        raise Exception("Invalid choice, exiting...")
コード例 #5
0
def main():
    try:
        # List all connected TREZORs on USB
        devices = HidTransport.enumerate()

        # Check whether we found any
        if len(devices) == 0:
            input('No TREZOR found. Press any key...')
            return

        # Use first connected device
        transport = HidTransport(devices[0])

        # Creates object for manipulating TREZOR
        client = TrezorClient(transport)

        # Print out TREZOR's features and settings
        print(client.features)

        # # Get the first address of first BIP44 account
        # # (should be the same address as shown in wallet.trezor.io)
        # bip32_path = client.expand_path("44'/0'/0'/0/0")
        # address = client.get_address('Bitcoin', bip32_path)
        # print('Bitcoin address:', address)

        client.close()
        input('Press any key...')
    except Exception as e:
        print(str(e))
        traceback.print_exc(file=sys.stdout)
        input('Press any key...')
コード例 #6
0
    def get_client(self):
        if not TREZOR:
            give_error('please install github.com/trezor/python-trezor')

        if not self.client or self.client.bad:
            try:
                d = HidTransport.enumerate()[0]
                self.transport = HidTransport(d)
            except:
                give_error(
                    'Could not connect to your Trezor. Please verify the cable is connected and that no other app is using it.'
                )
            self.client = QtGuiTrezorClient(self.transport)
            if (self.client.features.major_version == 1
                    and self.client.features.minor_version < 2) or (
                        self.client.features.major_version == 1
                        and self.client.features.minor_version == 2
                        and self.client.features.patch_version < 1):
                give_error(
                    'Outdated Trezor firmware. Please update the firmware from https://www.mytrezor.com'
                )
            self.client.set_tx_api(self)
            #self.client.clear_session()# TODO Doesn't work with firmware 1.1, returns proto.Failure
            self.client.bad = False
            self.device_checked = False
            self.proper_device = False
        return self.client
コード例 #7
0
def main():
    # List all connected TREZORs on USB
    devices = HidTransport.enumerate()

    # Check whether we found any
    if len(devices) == 0:
        print('No TREZOR found')
        return

    # Use first connected device
    transport = HidTransport(devices[0])

    # Creates object for manipulating TREZOR
    debug_transport = HidTransport(devices[0], **{'debug_link': True})
    client = TrezorClient(transport)
    debug = DebugLink(debug_transport)

    arg1 = int(sys.argv[1], 16)
    arg2 = int(sys.argv[2], 16)
    step = 0x400 if arg2 >= 0x400 else arg2

    f = open('memory.dat', 'w')

    for addr in range(arg1, arg1 + arg2, step):
        mem = debug.memory_read(addr, step)
        f.write(mem)

    f.close()

    client.close()
コード例 #8
0
def wait_for_devices():
    devices = HidTransport.enumerate()
    while not len(devices):
        sys.stderr.write("Please connect Trezor to computer and press Enter...")
        raw_input()
        devices = HidTransport.enumerate()

    return devices
コード例 #9
0
 def get_transport():
     from trezorlib.transport_hid import HidTransport
     count = len(HidTransport.enumerate())
     if not count:
         logging.warning('Number of Trezor devices: 0')
     for d in HidTransport.enumerate():
         transport = HidTransport(d)
         return transport
コード例 #10
0
def Wait_for_devices():
    devices = HidTransport.enumerate()
    while not len(devices):
        print("Please connect TREZOR to computer and press Enter...")
        input()
        devices = HidTransport.enumerate()

    return devices
コード例 #11
0
def wait_for_devices():
    devices = HidTransport.enumerate()
    while not len(devices):
        sys.stderr.write("Please connect TREZOR to computer and press Enter...")
        raw_input()
        devices = HidTransport.enumerate()

    return devices
コード例 #12
0
ファイル: snippet.py プロジェクト: someburner/GistsHub
def get_trezor_client():
    devices = HidTransport.enumerate()
    if len(devices) == 0:
        worklog.error('could not find any trezor device connected')
        return None

    transport = HidTransport(devices[0])
    client = TrezorClient(transport)
    return client
コード例 #13
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
コード例 #14
0
ファイル: trezori.py プロジェクト: instagibbs/HWI
    def __init__(self, device, path):
        super(TrezorClient, self).__init__(device)
        device.close()
        devices = HidTransport.enumerate()
        self.client = None
        for d in devices:
            if d[0] == path:
                transport = HidTransport(d)
                self.client = Trezor(transport)
                break

        # if it wasn't able to find a client, throw an error
        if not self.client:
            raise IOError("no Device")
コード例 #15
0
ファイル: _factory.py プロジェクト: jperryman23/trezor-agent
def client():
    # pylint: disable=import-error
    from trezorlib.client import TrezorClient
    from trezorlib.transport_hid import HidTransport
    from trezorlib.messages_pb2 import PassphraseAck

    devices = list(HidTransport.enumerate())
    if len(devices) != 1:
        msg = '{:d} Trezor devices found'.format(len(devices))
        raise IOError(msg)

    t = TrezorClient(HidTransport(devices[0]))
    t.callback_PassphraseRequest = lambda msg: PassphraseAck(passphrase='')
    return t
コード例 #16
0
def get_transport():
    if HID_ENABLED and HidTransport.enumerate():
        devices = HidTransport.enumerate()
        wirelink = devices[0]
        debuglink = devices[0].find_debug()

    elif PIPE_ENABLED and pipe_exists('/tmp/pipe.trezor.to'):
        wirelink = PipeTransport('/tmp/pipe.trezor', False)
        debuglink = PipeTransport('/tmp/pipe.trezor_debug', False)

    elif UDP_ENABLED:
        wirelink = UdpTransport()
        debuglink = UdpTransport()

    return wirelink, debuglink
コード例 #17
0
def main():
    # List all connected TREZORs on USB
    devices = HidTransport.enumerate()

    # Check whether we found any
    if len(devices) == 0:
        print('No TREZOR found')
        return

    # Use first connected device
    transport = devices[0]
    debug_transport = devices[0].find_debug()

    # Creates object for manipulating TREZOR
    client = TrezorClient(transport)
    debug = DebugLink(debug_transport)

    sector = int(sys.argv[1])
    f = open(sys.argv[2], "rb")
    content = f.read(sectorlens[sector])
    if (len(content) != sectorlens[sector]):
        print("Not enough bytes in file")
        return

    debug.flash_erase(sector)
    step = 0x400
    for offset in range(0, sectorlens[sector], step):
        debug.memory_write(sectoraddrs[sector] + offset,
                           content[offset:offset + step],
                           flash=True)
    client.close()
コード例 #18
0
def main():
    # List all connected TREZORs on USB
    devices = HidTransport.enumerate()

    # Check whether we found any
    if len(devices) == 0:
        print 'No TREZOR found'
        return

    # Use first connected device
    transport = HidTransport(devices[0])

    # Creates object for manipulating TREZOR
    client = TrezorClient(transport)

    # Print out TREZOR's features and settings
    print client.features

    # Get the first address of first BIP44 account
    # (should be the same address as shown in mytrezor.com)
    bip32_path = client.expand_path("44'/0'/0'/0/0")
    address = client.get_address('Bitcoin', bip32_path)
    print 'Bitcoin address:', address

    client.close()
コード例 #19
0
ファイル: cmd.py プロジェクト: cyberaa/python-trezor
def get_transport(transport_string, path, **kwargs):
    if transport_string == 'usb':
        from trezorlib.transport_hid import HidTransport

        if path == '':
            try:
                path = list_usb()[0][0]
            except IndexError:
                raise Exception("No Trezor found on USB")

        for d in HidTransport.enumerate():
            # Two-tuple of (normal_interface, debug_interface)
            if path in d:
                return HidTransport(d, **kwargs)

        raise Exception("Device not found")
 
    if transport_string == 'serial':
        from trezorlib.transport_serial import SerialTransport
        return SerialTransport(path, **kwargs)

    if transport_string == 'pipe':
        from trezorlib.transport_pipe import PipeTransport
        return PipeTransport(path, is_device=False, **kwargs)
    
    if transport_string == 'socket':
        from trezorlib.transport_socket import SocketTransportClient
        return SocketTransportClient(path, **kwargs)
    
    if transport_string == 'fake':
        from trezorlib.transport_fake import FakeTransport
        return FakeTransport(path, **kwargs)
    
    raise NotImplemented("Unknown transport")
コード例 #20
0
    def get_client() -> Optional[MyTrezorClient]:
        from trezorlib.transport_hid import HidTransport
        count = len(HidTransport.enumerate())
        if not count:
            logging.warning('Number of Trezor devices: 0')

        for d in HidTransport.enumerate():
            transport = HidTransport(d)
            client = MyTrezorClient(transport, ask_for_pin_callback,
                                    ask_for_pass_callback)
            if not device_id or client.features.device_id == device_id:
                return client
            else:
                client.clear_session()
                client.close()
        return None
コード例 #21
0
ファイル: trezor.py プロジェクト: azhar3339/electrum
    def get_client(self):
        if not TREZOR:
            give_error("please install github.com/trezor/python-trezor")

        if not self.client or self.client.bad:
            try:
                d = HidTransport.enumerate()[0]
                self.transport = HidTransport(d)
            except:
                give_error(
                    "Could not connect to your Trezor. Please verify the cable is connected and that no other app is using it."
                )
            self.client = QtGuiTrezorClient(self.transport)
            if (self.client.features.major_version == 1 and self.client.features.minor_version < 2) or (
                self.client.features.major_version == 1
                and self.client.features.minor_version == 2
                and self.client.features.patch_version < 1
            ):
                give_error("Outdated Trezor firmware. Please update the firmware from https://www.mytrezor.com")
            self.client.set_tx_api(self)
            # self.client.clear_session()# TODO Doesn't work with firmware 1.1, returns proto.Failure
            self.client.bad = False
            self.device_checked = False
            self.proper_device = False
        return self.client
コード例 #22
0
def connect_trezor(ask_for_pin_fun, ask_for_pass_fun):
    try:
        from trezorlib.transport_hid import HidTransport
        transport = None
        for d in HidTransport.enumerate():
            transport = HidTransport(d)
            break

        if transport:
            client = MyTrezorClient(transport, ask_for_pin_fun,
                                    ask_for_pass_fun)
            return client
        else:
            return None

    except Exception as e:
        raise
コード例 #23
0
ファイル: identity.py プロジェクト: rajeevbbqq/snet-cli
 def __init__(self, w3, index):
     self.w3 = w3
     self.client = TrezorClient(HidTransport.enumerate()[0])
     self.index = index
     self.address = self.w3.toChecksumAddress("0x" + bytes(
         self.client.ethereum_get_address(
             [44 + BIP32_HARDEN, 60 +
              BIP32_HARDEN, BIP32_HARDEN, 0, index])).hex())
コード例 #24
0
ファイル: trezor.py プロジェクト: XertroV/electrum3-lib
    def get_client(self):
        if not TREZOR:
            raise Exception('please install github.com/trezor/python-trezor')

        if not self.client or self.client.bad:
            try:
                d = HidTransport.enumerate()[0]
                self.transport = HidTransport(d)
            except:
                raise Exception("Trezor not found")
            self.client = QtGuiTrezorClient(self.transport)
            self.client.set_tx_api(self)
            #self.client.clear_session()# TODO Doesn't work with firmware 1.1, returns proto.Failure
            self.client.bad = False
            self.device_checked = False
            self.proper_device = False
        return self.client
コード例 #25
0
ファイル: identity.py プロジェクト: arturgontijo/snet-cli
 def __init__(self, w3, index):
     self.w3 = w3
     self.client = TrezorClient(HidTransport.enumerate()[0])
     self.index = index
     self.address = self.w3.toChecksumAddress(
         "0x" + bytes(self.client.ethereum_get_address([44 + BIP32_HARDEN,
                                                        60 + BIP32_HARDEN,
                                                        BIP32_HARDEN, 0,
                                                        index])).hex())
コード例 #26
0
ファイル: mem_write.py プロジェクト: tmsrjs/python-trezor
def main():
    # List all connected TREZORs on USB
    devices = HidTransport.enumerate()

    # Check whether we found any
    if len(devices) == 0:
        print('No TREZOR found')
        return

    # Use first connected device
    transport = HidTransport(devices[0])

    # Creates object for manipulating TREZOR
    debug_transport = HidTransport(devices[0], **{'debug_link': True})
    client = TrezorClient(transport)
    debug = DebugLink(debug_transport)

    mem = debug.memory_write(int(sys.argv[1],16), binascii.unhexlify(sys.argv[2]), flash=True)
    client.close()
コード例 #27
0
    def get_client(self):
        if not TREZOR:
            give_error('please install github.com/trezor/python-trezor')

        if not self.client or self.client.bad:
            d = HidTransport.enumerate()
            if not d:
                give_error(
                    'Could not connect to your Trezor. Please verify the cable is connected and that no other app is using it.'
                )
            self.transport = HidTransport(d[0])
            self.client = QtGuiTrezorClient(self.transport)
            self.client.handler = self.handler
            self.client.set_tx_api(self)
            self.client.bad = False
            if not self.atleast_version(1, 2, 1):
                self.client = None
                give_error(
                    'Outdated Trezor firmware. Please update the firmware from https://www.mytrezor.com'
                )
        return self.client
コード例 #28
0
ファイル: cmdtr.py プロジェクト: wizardofozzie/python-trezor
def get_transport(transport_string, path, **kwargs):
    if transport_string == 'usb':
        from trezorlib.transport_hid import HidTransport

        if path == '':
            try:
                path = list_usb()[0][0]
            except IndexError:
                raise Exception("No Trezor found on USB")

        for d in HidTransport.enumerate():
            # Two-tuple of (normal_interface, debug_interface)
            if path in d:
                return HidTransport(d, **kwargs)

        raise Exception("Device not found")

    if transport_string == 'serial':
        from trezorlib.transport_serial import SerialTransport
        return SerialTransport(path, **kwargs)

    if transport_string == 'pipe':
        from trezorlib.transport_pipe import PipeTransport
        return PipeTransport(path, is_device=False, **kwargs)

    if transport_string == 'socket':
        from trezorlib.transport_socket import SocketTransportClient
        return SocketTransportClient(path, **kwargs)

    if transport_string == 'bridge':
        from trezorlib.transport_bridge import BridgeTransport
        return BridgeTransport(path, **kwargs)

    if transport_string == 'fake':
        from trezorlib.transport_fake import FakeTransport
        return FakeTransport(path, **kwargs)

    raise NotImplemented("Unknown transport")
コード例 #29
0
    def _try_hid(self, device):
        self.print_error("Trying to connect over USB...")
        if device.interface_number == 1:
            pair = [None, device.path]
        else:
            pair = [device.path, None]

        try:
            from trezorlib.transport_hid import HidTransport
            return HidTransport(pair)
        except BaseException as e:
            raise
            self.print_error("cannot connect at", device.path, str(e))
            return None
コード例 #30
0
    def chooseDevice(self, devices):
        """
        Choose device from enumerated list. If there's only one Trezor,
        that will be chosen.

        If there are multiple Trezors, diplays a widget with list
        of Trezor devices to choose from.

        @returns HidTransport object of selected device
        """
        if not len(devices):
            raise RuntimeError("No Trezor connected!")
        if len(devices) == 1:
            try:
                return HidTransport(devices[0])
            except IOError:
                raise RuntimeError("Trezor is currently in use")
        # maps deviceId string to device label
        deviceMap = {}
        for device in devices:
            try:
                transport = HidTransport(device)
                client = DeOS_TrezorClient(transport)
                label = client.features.label and client.features.label or "<no label>"
                client.close()

                deviceMap[device[0]] = label
            except IOError:
                # device in use, do not offer as choice
                continue
        if not deviceMap:
            raise RuntimeError("All connected Trezors are in use!")
        dialog = TrezorChooserDialog(deviceMap)
        if not dialog.exec_():
            sys.exit(9)
        deviceStr = dialog.chosenDeviceStr()
        return HidTransport([deviceStr, None])
コード例 #31
0
def choose_device(devices):
    if not len(devices):
        raise Exception("No Trezor connected!")

    if len(devices) == 1:
        try:
            return HidTransport(devices[0])
        except IOError:
            raise Exception("Device is currently in use")

    i = 0
    sys.stderr.write("----------------------------\n")
    sys.stderr.write("Available devices:\n")
    for d in devices:
        try:
            t = HidTransport(d)
        except IOError:
            sys.stderr.write("[-] <device is currently in use>\n")
            continue

        client = TrezorClient(t)

        if client.features.label:
            sys.stderr.write("[%d] %s\n" % (i, client.features.label))
        else:
            sys.stderr.write("[%d] <no label>\n" % i)
        t.close()
        i += 1

    sys.stderr.write("----------------------------\n")
    sys.stderr.write("Please choose device to use: ")

    try:
        device_id = int(raw_input())
        return HidTransport(devices[device_id])
    except:
        raise Exception("Invalid choice, exiting...")
コード例 #32
0
ファイル: trezor.py プロジェクト: paulmadore/electrum-ltc
    def get_client(self):
        if not TREZOR:
            give_error('please install github.com/trezor/python-trezor')

        if not self.client or self.client.bad:
            d = HidTransport.enumerate()
            if not d:
                give_error('Could not connect to your Trezor. Please verify the cable is connected and that no other app is using it.')
            self.transport = HidTransport(d[0])
            self.client = QtGuiTrezorClient(self.transport)
            self.client.handler = self.handler
            self.client.set_tx_api(self)
            self.client.bad = False
            if not self.atleast_version(1, 2, 1):
                self.client = None
                give_error('Outdated Trezor firmware. Please update the firmware from https://www.mytrezor.com')
        return self.client
コード例 #33
0
ファイル: trezor.py プロジェクト: XertroV/electrum3-lib
    def get_client(self):
        if not TREZOR:
            raise Exception('please install github.com/trezor/python-trezor')

        if not self.client or self.client.bad:
            try:
                d = HidTransport.enumerate()[0]
                self.transport = HidTransport(d)
            except:
                raise Exception("Trezor not found")
            self.client = QtGuiTrezorClient(self.transport)
            self.client.set_tx_api(self)
            #self.client.clear_session()# TODO Doesn't work with firmware 1.1, returns proto.Failure
            self.client.bad = False
            self.device_checked = False
            self.proper_device = False
        return self.client
コード例 #34
0
ファイル: trezor.py プロジェクト: Tyronethedev/electrum
    def get_client(self):
        if not TREZOR:
            give_error('please install github.com/trezor/python-trezor')

        if not self.client or self.client.bad:
            try:
                d = HidTransport.enumerate()[0]
                self.transport = HidTransport(d)
            except:
                give_error('Could not connect to your Trezor. Please verify the cable is connected and that no other app is using it.')
            self.client = QtGuiTrezorClient(self.transport)
            self.client.set_tx_api(self)
            #self.client.clear_session()# TODO Doesn't work with firmware 1.1, returns proto.Failure
            self.client.bad = False
            self.device_checked = False
            self.proper_device = False
        return self.client
コード例 #35
0
def main():
    devices = HidTransport.enumerate()
    if not devices:
        print('TREZOR is not plugged in. Please, connect TREZOR and retry.')
        return

    client = TrezorClient(devices[0])

    print()
    print('Confirm operation on TREZOR')
    print()

    masterKey = getMasterKey(client)
    # print('master key:', masterKey)

    fileName = getFileEncKey(masterKey)[0]
    # print('file name:', fileName)

    path = os.path.expanduser('~/Dropbox/Apps/TREZOR Password Manager/')
    # print('path to file:', path)

    encKey = getFileEncKey(masterKey)[2]
    # print('enckey:', encKey)

    full_path = path + fileName
    parsed_json = decryptStorage(full_path, encKey)

    # list entries
    entries = parsed_json['entries']
    printEntries(entries)

    entry_id = input('Select entry number to decrypt: ')
    entry_id = str(entry_id)

    plain_nonce = getDecryptedNonce(client, entries[entry_id])

    pwdArr = entries[entry_id]['password']['data']
    pwdHex = ''.join([hex(x)[2:].zfill(2) for x in pwdArr])
    print('password: '******'safe_note']['data']
    safeNoteHex = ''.join([hex(x)[2:].zfill(2) for x in safeNoteArr])
    print('safe_note:', decryptEntryValue(plain_nonce, unhexlify(safeNoteHex)))

    return
コード例 #36
0
ファイル: pwdreader.py プロジェクト: admxjx/slips
def main():
    devices = HidTransport.enumerate()
    if not devices:
        print('TREZOR is not plugged in. Please, connect TREZOR and retry.')
        return

    client = TrezorClient(devices[0])

    print()
    print('Confirm operation on TREZOR')
    print()

    masterKey = getMasterKey(client)
    # print('master key:', masterKey)

    fileName = getFileEncKey(masterKey)[0]
    # print('file name:', fileName)

    path = os.path.expanduser('~/Dropbox/Apps/TREZOR Password Manager/')
    # print('path to file:', path)

    encKey = getFileEncKey(masterKey)[2]
    # print('enckey:', encKey)

    full_path = path + fileName
    parsed_json = decryptStorage(full_path, encKey)

    # list entries
    entries = parsed_json['entries']
    printEntries(entries)

    entry_id = input('Select entry number to decrypt: ')
    entry_id = str(entry_id)

    plain_nonce = getDecryptedNonce(client, entries[entry_id])

    pwdArr = entries[entry_id]['password']['data']
    pwdHex = ''.join([ hex(x)[2:].zfill(2) for x in pwdArr ])
    print('password: '******'safe_note']['data']
    safeNoteHex = ''.join([ hex(x)[2:].zfill(2) for x in safeNoteArr ])
    print('safe_note:', decryptEntryValue(plain_nonce, unhexlify(safeNoteHex)))

    return
コード例 #37
0
ファイル: mem_read.py プロジェクト: schinzelh/python-trezor
def main():
    # List all connected TREZORs on USB
    devices = HidTransport.enumerate()

    # Check whether we found any
    if len(devices) == 0:
        print('No TREZOR found')
        return

    # Use first connected device
    transport = HidTransport(devices[0])

    # Creates object for manipulating TREZOR
    debug_transport = HidTransport(devices[0], **{'debug_link': True})
    client = TrezorClient(transport)
    debug = DebugLink(debug_transport)

    mem = debug.memory_read(int(sys.argv[1],16), int(sys.argv[2],16))
    f = open('memory.dat', 'w')
    f.write(mem)
    f.close()

    client.close()
コード例 #38
0
def choose_device(devices):
    if not len(devices):
        raise Exception("No Trezor connected!")

    if len(devices) == 1:
        try:
            return HidTransport(devices[0])
        except IOError:
            raise Exception("Device is currently in use")

    i = 0
    sys.stderr.write("----------------------------\n")
    sys.stderr.write("Available devices:\n")
    for d in devices:
        try:
            t = HidTransport(d)
        except IOError:
            sys.stderr.write("[-] <device is currently in use>\n")
            continue

        client = TrezorClient(t)

        if client.features.label:
            sys.stderr.write("[%d] %s\n" % (i, client.features.label))
        else:
            sys.stderr.write("[%d] <no label>\n" % i)
        t.close()
        i += 1

    sys.stderr.write("----------------------------\n")
    sys.stderr.write("Please choose device to use: ")

    try:
        device_id = int(raw_input())
        return HidTransport(devices[device_id])
    except:
        raise Exception("Invalid choice, exiting...")
コード例 #39
0
ファイル: trezor.py プロジェクト: vivekteega/flo-electrum
 def hid_transport(self, device):
     from trezorlib.transport_hid import HidTransport
     return HidTransport.find_by_path(device.path)
コード例 #40
0
ファイル: pwdreader.py プロジェクト: BTA-BATA/slips
    full_path = ''.join((path, fileName))
    parsed_json = decryptStorage(full_path, encKey)

    #list entries
    entries = parsed_json['entries']
    printEntries(entries)

    entry_id = raw_input('Select entry number to decrypt: ')
    entry_id = str(entry_id)

    plain_nonce = getDecryptedNonce(entries[entry_id])

    pwdArr = entries[entry_id]['password']['data']
    pwdHex = ''.join([ hex(x)[2:].zfill(2) for x in pwdArr ])
    print 'password: '******'safe_note']['data']
    safeNoteHex = ''.join([ hex(x)[2:].zfill(2) for x in safeNoteArr ])
    print 'safe_note:', decryptEntryValue(plain_nonce, unhexlify(safeNoteHex))

    return

if __name__ == '__main__':
    try:
        # init TREZOR transport
        client = TrezorClient(HidTransport(HidTransport.enumerate()[0]))
    except:
        print 'TREZOR is not plugged in. Please, connect TREZOR and retry.'
    else:
        main()
コード例 #41
0
ファイル: TrezorPass.py プロジェクト: hiviah/TrezorPass
	def enumerateHIDDevices(self):
		"""Returns Trezor HID devices"""
		devices = HidTransport.enumerate()

		return devices
コード例 #42
0
ファイル: cmd.py プロジェクト: cyberaa/python-trezor
def list_usb():
    from trezorlib.transport_hid import HidTransport
    return HidTransport.enumerate()
コード例 #43
0
    def enumerateHIDDevices(self):
        """Returns Trezor HID devices"""
        devices = HidTransport.enumerate()

        return devices
コード例 #44
0
ファイル: toolkit.py プロジェクト: EricSchles/TrezorToolkit
import time

from PyQt4 import QtCore, QtGui
from PyQt4.QtCore import QThread, SIGNAL

from pycoin.key.bip32 import Wallet

from trezorlib.client import TrezorClient
from trezorlib.transport_hid import HidTransport
import trezorlib

import mnemonic

from gui import Ui_MainWindow

devices = HidTransport.enumerate()
transport = HidTransport(devices[0])

client = TrezorClient(transport)

#netcode = "BTC"
#xpub = Wallet(False, netcode, node.chain_code, node.depth, unhexlify("%08x" % node.fingerprint), node.child_num)

#
# Wrap trezor functions in a with statement (using this) to show on the UI that
# interaction is required on the trezor
#

class TrezorWarning:

    def __init__(self):
コード例 #45
0
def main():
    numinputs = 600
    sizeinputtx = 10

    # List all connected TREZORs on USB
    devices = HidTransport.enumerate()

    # Check whether we found any
    if len(devices) == 0:
        print('No TREZOR found')
        return

    # Use first connected device
    print(devices[0][0])
#    transport = BridgeTransport(devices[0][0])
    transport = HidTransport(devices[0])

    txstore = MyTXAPIBitcoin()

    # Creates object for manipulating TREZOR
    client = TrezorClient(transport)
#    client.set_tx_api(TXAPITestnet())
    txstore.set_client(client)
    txstore.set_publickey(client.get_public_node(client.expand_path("44'/0'/0'")))
    print("creating input txs")
    txstore.create_inputs(numinputs, sizeinputtx)
    print("go")
    client.set_tx_api(txstore)
#    client.set_tx_api(MyTXAPIBitcoin())

    # Print out TREZOR's features and settings
    print(client.features)

    # Get the first address of first BIP44 account
    # (should be the same address as shown in mytrezor.com)

    outputs = [
        proto_types.TxOutputType(
            amount=0,
            script_type=proto_types.PAYTOADDRESS,
            address='p2xtZoXeX5X8BP8JfFhQK2nD3emtjch7UeFm'
#            op_return_data=binascii.unhexlify('2890770995194662774cd192ee383b805e9a066e6a456be037727649228fb7f6')
#            address_n=client.expand_path("44'/0'/0'/0/35"),
#            address='3PUxV6Cc4udQZQsJhArVUzvvVoKC8ohkAj',
        ),
#        proto_types.TxOutputType(
#            amount=0,
#            script_type=proto_types.PAYTOOPRETURN,
#            op_return_data=binascii.unhexlify('2890770995194662774cd192ee383b805e9a066e6a456be037727649228fb7f6')
#        ),
#        proto_types.TxOutputType(
#            amount= 8120,
#            script_type=proto_types.PAYTOADDRESS,
#            address_n=client.expand_path("44'/1'/0'/1/0"),
#            address='1PtCkQgyN6xHmXWzLmFFrDNA5vYhYLeNFZ',
#            address='14KRxYgFc7Se8j7MDdrK5PTNv8meq4GivK',
#        ),
#         proto_types.TxOutputType(
#             amount= 18684 - 2000,
#             script_type=proto_types.PAYTOADDRESS,
#             address_n=client.expand_path("44'/0'/0'/0/7"),
# #            address='1PtCkQgyN6xHmXWzLmFFrDNA5vYhYLeNFZ',
# #            address='1s9TSqr3PHZdXGrYws59Uaf5SPqavH43z',
#         ),
#         proto_types.TxOutputType(
#             amount= 1000,
#             script_type=proto_types.PAYTOADDRESS,
# #            address_n=client.expand_path("44'/0'/0'/0/18"),
# #            address='1PtCkQgyN6xHmXWzLmFFrDNA5vYhYLeNFZ',
#             address='1NcMqUvyWv1K3Zxwmx5sqfj7ZEmPCSdJFM',
#         ),
    ]

#    (signatures, serialized_tx) = client.sign_tx('Testnet', inputs, outputs)
    (signatures, serialized_tx) = client.sign_tx('Bitcoin', txstore.get_inputs(), txstore.get_outputs())
    print('Transaction:', binascii.hexlify(serialized_tx))

    client.close()
コード例 #46
0
    def chooseDevice(self, devices):
        """
		Choose device from enumerated list. If there's only one Trezor,
		that will be chosen.

		If there are multiple Trezors, diplays a widget with list
		of Trezor devices to choose from.

		devices is a list of device
		A device is something like:
		in Py2:  ['0001:0008:00', '0001:0008:01']
		In Py3:  [b'0001:0008:00', b'0001:0008:01']

		@returns HidTransport object of selected device
		"""
        if not len(devices):
            raise RuntimeError(u"No Trezor connected!")

        if len(devices) == 1:
            try:
                return HidTransport(devices[0])
            except IOError:
                raise RuntimeError(u"Trezor is currently in use")

        # maps deviceId string to device label
        deviceMap = {}
        for device in devices:
            try:
                transport = HidTransport(device)
                client = QtTrezorClient(transport)
                label = client.features.label and client.features.label or "<no label>"
                client.close()

                deviceMap[device[0]] = label
            except IOError:
                # device in use, do not offer as choice
                continue

        if not deviceMap:
            raise RuntimeError(u"All connected Trezors are in use!")

        if self.readdevicestringfromstdin:
            print(u'Chose your Trezor device please. '
                  'Devices currently in use are not listed:')
            ii = 0
            for device in deviceMap:
                print('%d  %s' % (ii, deviceMap[device]))
                ii += 1
            ii -= 1
            while True:
                inputstr = input(u"Please provide the number of the device "
                                 "chosen: (%d-%d, Carriage return to quit) " %
                                 (0, ii))

                if inputstr == '':
                    raise RuntimeError(u"No Trezors device chosen! Quitting.")
                try:
                    inputint = int(inputstr)
                except Exception:
                    print(u'Wrong input. You must enter a number '
                          'between %d and %d. Try again.' % (0, ii))
                    continue
                if inputint < 0 or inputint > ii:
                    print(u'Wrong input. You must enter a number '
                          'between %d and %d. Try again.' % (0, ii))
                    continue
                break
            # Py2-vs-Py3: dictionaries are different in Py2 and Py3
            if sys.version_info[0] > 2:  # Py2-vs-Py3:
                deviceStr = list(deviceMap.keys())[ii]
            else:
                deviceStr = deviceMap.keys()[ii]
        else:
            dialog = TrezorChooserDialog(deviceMap)
            if not dialog.exec_():
                raise RuntimeError(u"No Trezors device chosen! Quitting.")
            deviceStr = dialog.chosenDeviceStr()
        return HidTransport([deviceStr, None])
コード例 #47
0
ファイル: vault.py プロジェクト: Harikrishnan-github/deosorg
 def _get_devices(self):
     """
     Returns Trezor HID devices
     """
     return HidTransport.enumerate()