def enumerate(password: str = "") -> List[Dict[str, object]]: """ Enumerate all BitBox02 devices. Bootloaders excluded. """ result = [] for device_info in devices.get_any_bitbox02s(): path = device_info["path"].decode() client = Bitbox02Client(path) client.set_noise_config(SilentNoiseConfig()) d_data: Dict[str, object] = {} bb02 = None with handle_errors(common_err_msgs["enumerate"], d_data): bb02 = client.init(expect_initialized=None) version, platform, edition, unlocked = bitbox02.BitBox02.get_info( client.transport ) if platform != Platform.BITBOX02: client.close() continue if edition not in (BitBox02Edition.MULTI, BitBox02Edition.BTCONLY): client.close() continue assert isinstance(edition, BitBox02Edition) d_data.update( { "type": "bitbox02", "path": path, "model": { BitBox02Edition.MULTI: "bitbox02_multi", BitBox02Edition.BTCONLY: "bitbox02_btconly", }[edition], "needs_pin_sent": False, "needs_passphrase_sent": False, } ) if bb02 is not None: with handle_errors(common_err_msgs["enumerate"], d_data): if not bb02.device_info()["initialized"]: raise DeviceNotReadyError( "BitBox02 is not initialized. Please initialize it using the BitBoxApp." ) elif not unlocked: raise DeviceNotReadyError( "Please load wallet to unlock." if _using_external_gui else "Please use any subcommand to unlock" ) d_data["fingerprint"] = client.get_master_fingerprint_hex() result.append(d_data) client.close() return result
def enumerate(password=""): results = [] # Jade is not really an HID device, it shows as a serial/com port device. # Scan com ports looking for the relevant vid and pid, and use 'path' to # hold the path to the serial port device, eg. /dev/ttyUSB0 for devinfo in list_ports.comports(): if devinfo.vid == JADE_VENDOR_ID and devinfo.pid == JADE_DEVICE_ID: d_data = {} d_data["type"] = "jade" d_data["path"] = devinfo.device d_data["needs_pin_sent"] = False d_data["needs_passphrase_sent"] = False client = None with handle_errors(common_err_msgs["enumerate"], d_data): client = JadeClient(devinfo.device, password) d_data["fingerprint"] = client.get_master_fingerprint().hex() if client: client.close() results.append(d_data) return results
def enumerate(password: str = "") -> List[Dict[str, Any]]: results = [] devs = hid.HidTransport.enumerate() devs.extend(webusb.WebUsbTransport.enumerate()) devs.extend(udp.UdpTransport.enumerate()) for dev in devs: d_data: Dict[str, Any] = {} d_data["type"] = "trezor" d_data["path"] = dev.get_path() client = None with handle_errors(common_err_msgs["enumerate"], d_data): client = TrezorClient(d_data["path"], password) try: client._prepare_device() except TypeError: continue if "trezor" not in client.client.features.vendor: continue d_data["model"] = "trezor_" + client.client.features.model.lower() if d_data["path"] == "udp:127.0.0.1:21324": d_data["model"] += "_simulator" d_data["needs_pin_sent"] = ( client.client.features.pin_protection and not client.client.features.unlocked ) if client.client.features.model == "1": d_data[ "needs_passphrase_sent" ] = ( client.client.features.passphrase_protection ) # always need the passphrase sent for Trezor One if it has passphrase protection enabled else: d_data["needs_passphrase_sent"] = False if d_data["needs_pin_sent"]: raise DeviceNotReadyError( "Trezor is locked. Unlock by using 'promptpin' and then 'sendpin'." ) if d_data["needs_passphrase_sent"] and not password: raise DeviceNotReadyError( "Passphrase needs to be specified before the fingerprint information can be retrieved" ) if client.client.features.initialized: d_data["fingerprint"] = client.get_master_fingerprint().hex() d_data[ "needs_passphrase_sent" ] = False # Passphrase is always needed for the above to have worked, so it's already sent else: d_data["error"] = "Not initialized" d_data["code"] = DEVICE_NOT_INITIALIZED if client: client.close() results.append(d_data) return results
def enumerate(password=""): results = [] for dev in enumerate_devices(): # enumerate_devices filters to Trezors and Keepkeys. # Only allow Trezors and unknowns. Unknown devices will reach the check for vendor later if dev.get_usb_vendor_id() not in TREZOR_VENDOR_IDS | {-1}: continue d_data = {} d_data["type"] = "trezor" d_data["path"] = dev.get_path() client = None with handle_errors(common_err_msgs["enumerate"], d_data): client = TrezorClient(d_data["path"], password) client.client.init_device() if "trezor" not in client.client.features.vendor: continue d_data["model"] = "trezor_" + client.client.features.model.lower() if d_data["path"] == "udp:127.0.0.1:21324": d_data["model"] += "_simulator" d_data["needs_pin_sent"] = (client.client.features.pin_protection and not client.client.features.pin_cached) if client.client.features.model == "1": d_data["needs_passphrase_sent"] = ( client.client.features.passphrase_protection ) # always need the passphrase sent for Trezor One if it has passphrase protection enabled else: d_data["needs_passphrase_sent"] = False if d_data["needs_pin_sent"]: raise DeviceNotReadyError( "Trezor is locked. Unlock by using 'promptpin' and then 'sendpin'." ) if d_data["needs_passphrase_sent"] and not password: raise DeviceNotReadyError( "Passphrase needs to be specified before the fingerprint information can be retrieved" ) if client.client.features.initialized: d_data["fingerprint"] = client.get_master_fingerprint_hex() # Passphrase is always needed for the above to have worked, # so it's already sent d_data["needs_passphrase_sent"] = False else: d_data["error"] = "Not initialized" d_data["code"] = DEVICE_NOT_INITIALIZED if client: client.close() results.append(d_data) return results
def enumerate(password=''): results = [] for dev in enumerate_devices(): # enumerate_devices filters to Trezors and Keepkeys. # Only allow Trezors and unknowns. Unknown devices will reach the check for vendor later if dev.get_usb_vendor_id() not in TREZOR_VENDOR_IDS | {-1}: continue d_data = {} d_data['type'] = 'trezor' d_data['path'] = dev.get_path() client = None with handle_errors(common_err_msgs["enumerate"], d_data): client = TrezorClient(d_data['path'], password) client.client.init_device() if 'trezor' not in client.client.features.vendor: continue d_data['model'] = 'trezor_' + client.client.features.model.lower() if d_data['path'] == 'udp:127.0.0.1:21324': d_data['model'] += '_simulator' d_data[ 'needs_pin_sent'] = client.client.features.pin_protection and not client.client.features.pin_cached if client.client.features.model == '1': d_data[ 'needs_passphrase_sent'] = client.client.features.passphrase_protection # always need the passphrase sent for Trezor One if it has passphrase protection enabled else: d_data['needs_passphrase_sent'] = False if d_data['needs_pin_sent']: raise DeviceNotReadyError( 'Trezor is locked. Unlock by using \'promptpin\' and then \'sendpin\'.' ) if d_data['needs_passphrase_sent'] and not password: raise DeviceNotReadyError( "Passphrase needs to be specified before the fingerprint information can be retrieved" ) if client.client.features.initialized: d_data['fingerprint'] = client.get_master_fingerprint_hex() d_data[ 'needs_passphrase_sent'] = False # Passphrase is always needed for the above to have worked, so it's already sent else: d_data['error'] = 'Not initialized' d_data['code'] = DEVICE_NOT_INITIALIZED if client: client.close() results.append(d_data) return results
def enumerate(password=""): results = [] devices = [] devices.extend(hid.enumerate(LEDGER_VENDOR_ID, 0)) devices.append({ "path": SIMULATOR_PATH.encode(), "interface_number": 0, "product_id": 0x1000 }) for d in devices: if ("interface_number" in d and d["interface_number"] == 0 or ("usage_page" in d and d["usage_page"] == 0xFFA0)): d_data = {} path = d["path"].decode() d_data["type"] = "ledger" model = d["product_id"] >> 8 if model in LEDGER_MODEL_IDS.keys(): d_data["model"] = LEDGER_MODEL_IDS[model] elif d["product_id"] in LEDGER_LEGACY_PRODUCT_IDS.keys(): d_data["model"] = LEDGER_LEGACY_PRODUCT_IDS[d["product_id"]] else: continue d_data["path"] = path if path == SIMULATOR_PATH: d_data["model"] += "_simulator" client = None with handle_errors(common_err_msgs["enumerate"], d_data): try: client = LedgerClient(path, password) d_data["fingerprint"] = client.get_master_fingerprint_hex() d_data["needs_pin_sent"] = False d_data["needs_passphrase_sent"] = False except BTChipException: # Ignore simulator if there's an exception, means it isn't there if path == SIMULATOR_PATH: continue else: raise if client: client.close() results.append(d_data) return results
def _get_device_entry(device_model: str, device_path: str) -> Dict[str, Any]: d_data: Dict[str, Any] = {} d_data["type"] = "jade" d_data["model"] = device_model d_data["path"] = device_path d_data["needs_pin_sent"] = False d_data["needs_passphrase_sent"] = False client = None with handle_errors(common_err_msgs["enumerate"], d_data): client = JadeClient(device_path, password, timeout=1) d_data["fingerprint"] = client.get_master_fingerprint().hex() if client: client.close() return d_data