def main(): # List all connected KeepKeys on USB devices = HidTransport.enumerate() # Check whether we found any if len(devices) == 0: print('No KeepKey found') return # Use first connected device transport = HidTransport(devices[0]) # Creates object for manipulating KeepKey client = KeepKeyClient(transport) # Print out KeepKey's features and settings print(client.features) # Get the first address of first BIP44 account # (should be the same address as shown in KeepKey wallet Chrome extension) bip32_path = client.expand_path("44'/0'/0'/0/0") address = client.get_address('morningstar', bip32_path) print('morningstar address:', address) client.close()
def setUp(self): transport = config.TRANSPORT(*config.TRANSPORT_ARGS, **config.TRANSPORT_KWARGS) if hasattr(config, 'DEBUG_TRANSPORT'): debug_transport = config.DEBUG_TRANSPORT( *config.DEBUG_TRANSPORT_ARGS, **config.DEBUG_TRANSPORT_KWARGS) self.client = KeepKeyDebugClient(transport) self.client.set_debuglink(debug_transport) else: self.client = KeepKeyClient(transport) self.client.set_tx_api(tx_api.TxApiBitcoin) # self.client.set_buttonwait(3) # 1 2 3 4 5 6 7 8 9 10 11 12 self.mnemonic12 = 'alcohol woman abuse must during monitor noble actual mixed trade anger aisle' self.mnemonic18 = 'owner little vague addict embark decide pink prosper true fork panda embody mixture exchange choose canoe electric jewel' self.mnemonic24 = 'dignity pass list indicate nasty swamp pool script soccer toe leaf photo multiply desk host tomato cradle drill spread actor shine dismiss champion exotic' self.mnemonic_all = ' '.join(['all'] * 12) self.pin4 = '1234' self.pin6 = '789456' self.pin8 = '45678978' self.client.wipe_device() print("Setup finished") print("--------------")
def main(): args = parse_args(Commands) if args.cmd == 'list': devices = list_usb() if args.json: print(json.dumps(devices)) else: for dev in devices: if dev[1] != None: print("%s - debuglink enabled" % dev[0]) else: print(dev[0]) return transport = get_transport(args.transport, args.path) if args.verbose: client = KeepKeyClientDebug(transport) else: client = KeepKeyClient(transport) cmds = Commands(client) res = args.func(cmds, args) if args.json: print(json.dumps(res, sort_keys=True, indent=4)) else: print(res)
def main(): # List all connected KeepKeys on USB devices = HidTransport.enumerate() # Check whether we found any if len(devices) == 0: print('No KeepKey found') return # Use first connected device transport = HidTransport(devices[0]) # Creates object for manipulating KeepKey client = KeepKeyClient(transport) # Print out KeepKey's features and settings print(client.features) # Get the first address of first BIP44 account # (should be the same address as shown in KeepKey wallet Chrome extension) mpath = "44'/0'/0'/0" bip32_path = client.expand_path(mpath) print bip32.serialize(client.get_public_node(bip32_path).node, 0x043587CF) for i in range(11): child_path = '%s%s' % ("44'/0'/0'/0/", str(i)) address = client.get_address('tDash', client.expand_path(child_path)) print 'tDASH address:', child_path, address client.close()
def main(): devices = wait_for_devices() transport = choose_device(devices) client = KeepKeyClient(transport) rootdir = os.environ['encfs_root'] # Read "man encfs" for more passw_file = os.path.join(rootdir, 'password.dat') if not os.path.exists(passw_file): # New encfs drive, let's generate password sys.stderr.write('Please provide label for new drive: ') label = input() sys.stderr.write('Computer asked KeepKey for new strong password.\n') sys.stderr.write('Please confirm action on your device.\n') # 32 bytes, good for AES keepkey_entropy = client.get_entropy(32) urandom_entropy = os.urandom(32) passw = hashlib.sha256(keepkey_entropy + urandom_entropy).digest() if len(passw) != 32: raise Exception("32 bytes password expected") bip32_path = [10, 0] passw_encrypted = client.encrypt_keyvalue(bip32_path, label, passw, False, True) data = {'label': label, 'bip32_path': bip32_path, 'password_encrypted_hex': binascii.hexlify(passw_encrypted)} json.dump(data, open(passw_file, 'wb')) # Let's load password data = json.load(open(passw_file, 'r')) sys.stderr.write('Please confirm action on your device.\n') passw = client.decrypt_keyvalue(data['bip32_path'], data['label'], binascii.unhexlify(data['password_encrypted_hex']), False, True) print(passw)
def choose_device(devices): if not len(devices): raise Exception("No KeepKey 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 = KeepKeyClient(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(input()) return HidTransport(devices[device_id]) except: raise Exception("Invalid choice, exiting...")
time.sleep(0.5) if enumerateCount == 3: break enumerateCount += 1 continue if enumerateStatus is False: print("Enumerate hard failed, power cycling") continue print("Fetching path...") for d in HidTransport.enumerate(): if path in d: transport = HidTransport(d) break print("Transport locked, continuing...") phy.set_capture_size(1025) client = KeepKeyClient(transport) print("KeepKeyClient OK, arming glitcher...") scope.arm() phy.arm() print("Arm OK") if oneshot: input("Hit enter to fire glitch event...") try: signal.alarm(10) data = client.ping("HelloHelloHelloHelloHello") print(data) if data != "HelloHelloHelloHelloHello": sys.exit(0) data = base64.b64encode(data.encode("utf-8")) except: data = ""
def check_hw_wallet(): printdbg('checking hw wallet') #client = None client = None signing = False if TYPE_HW_WALLET.lower().startswith("keepkey"): from keepkeylib.client import KeepKeyClient from keepkeylib.transport_hid import HidTransport import keepkeylib.ckd_public as bip32 try: devices = HidTransport.enumerate() except Exception as e: err_msg = str(e.args) print_err_exit(get_caller_name(), get_function_name(), err_msg) if len(devices) == 0: print('===> No HW Wallet found') signing = False else: try: print('===> keepkey HW Wallet found') transport = HidTransport(devices[0]) client = KeepKeyClient(transport) signing = True except Exception as e: err_msg = str(e.args) print_err_exit(get_caller_name(), get_function_name(), err_msg) elif TYPE_HW_WALLET.lower().startswith("trezor"): from trezorlib.client import TrezorClient from trezorlib.transport_hid import HidTransport import trezorlib.ckd_public as bip32 try: devices = HidTransport.enumerate() except Exception as e: err_msg = str(e.args) print_err_exit(get_caller_name(), get_function_name(), err_msg) if len(devices) == 0: print('===> No HW Wallet found') signing = False else: try: print('===> trezor HW Wallet found') transport = HidTransport(devices[0]) client = TrezorClient(transport) signing = True except Exception as e: err_msg = str(e.args) print_err_exit(get_caller_name(), get_function_name(), err_msg) elif TYPE_HW_WALLET.lower().startswith("ledgernanos"): #from btchip.btchip import * #from btchip.btchipUtils import * try: devices = getDongle(False) except Exception as e: err_msg = str(e.args) print_err_exit(get_caller_name(), get_function_name(), err_msg) if not devices: print('===> No HW Wallet found') signing = False else: try: print('===> Ledger nano s HW Wallet found') client = btchip(devices) signing = True except Exception as e: err_msg = str(e.args) print_err_exit(get_caller_name(), get_function_name(), err_msg) if client is not None: if TYPE_HW_WALLET.lower().startswith("ledgernanos"): pass else: try: wallet_supported_coins = list_coins(client) except Exception as e: err_msg = str(e.args) print_err_exit(get_caller_name(), get_function_name(), err_msg) if coin_name not in wallet_supported_coins: err_msg = 'only following coins supported by wallet\n\t' + \ str(wallet_supported_coins) print_err_exit(get_caller_name(), get_function_name(), err_msg) else: err_msg = "Can't run florijncoinmnb without hw wallet" print_err_exit(get_caller_name(), get_function_name(), err_msg) if TYPE_HW_WALLET.lower().startswith("ledgernanos"): mpath = get_mpath() return client, signing, mpath else: try: mpath = get_mpath() bip32_path = client.expand_path(mpath) xpub = bip32.serialize( client.get_public_node(bip32_path).node, (0x0488B21E if MAINNET else 0x043587CF)) except AssertionError as e: err_msg = str(e.args) print_err_exit(get_caller_name(), get_function_name(), err_msg) except Exception as e: err_msg = str(e.args) print_err_exit(get_caller_name(), get_function_name(), err_msg) except KeyboardInterrupt: print_err_exit(get_caller_name(), get_function_name(), "KeyboardInterrupt") printdbg('check_hw_wallet : signing : %s' % signing) printdbg('check_hw_wallet : xpub[:7] : %s' % xpub[:7]) printdbg('check_hw_wallet : xpub[-7:] : %s' % xpub[-7:]) printdbg('check_hw_wallet : mpath : %s' % mpath) return client, signing, bip32, mpath, xpub