def connect_keepkey(ask_for_pin_fun, ask_for_pass_fun):
    try:

        def get_transport():
            from keepkeylib.transport_hid import HidTransport
            count = len(HidTransport.enumerate())
            if not count:
                logging.warning('Number of Keepkey devices: 0')
            for d in HidTransport.enumerate():
                transport = HidTransport(d)
                return transport

        # HidTransport.enumerate() has to be called in the main thread - second call from bg thread
        # causes SIGSEGV
        transport = WndUtils.callFunInTheMainThread(get_transport)

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

    except Exception as e:
        logging.exception("Exception occurred")
        raise
Ejemplo n.º 2
0
def connect_keepkey(ask_for_pin_fun, ask_for_pass_fun):
    """
    Connect to a Keepkey device.
    :param ask_for_pin_fun: ref to a function displaying a dialog asking the user for a pin (Trezor and Keepkey)
    :param ask_for_pass_fun: ref to a function displaying a dialog asking the user for a passphrase (Trezor and Keepkey)
    :return: ref to a keepkey client if connection successfull or None if we are sure that no Keepkey device connected.
    """
    def get_transport():
        from keepkeylib.transport_hid import HidTransport
        count = len(HidTransport.enumerate())
        if not count:
            logging.warning('Number of Keepkey devices: 0')
        for d in HidTransport.enumerate():
            transport = HidTransport(d)
            return transport

    # HidTransport.enumerate() has to be called in the main thread - second call from bg thread
    # causes SIGSEGV
    transport = WndUtils.callFunInTheMainThread(get_transport)

    if transport:
        client = MyKeepkeyClient(transport, ask_for_pin_fun, ask_for_pass_fun)
        return client
    else:
        logging.warning('Transport is None')
def connect_trezor(ask_for_pin_fun, ask_for_pass_fun):
    try:
        logging.info('Started function')

        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

        # HidTransport.enumerate() has to be called in the main thread - second call from bg thread
        # causes SIGSEGV
        transport = WndUtils.callFunInTheMainThread(get_transport)
        logging.info('Read transport')
        if transport:
            logging.info('Transport is OK')
            client = MyTrezorClient(transport, ask_for_pin_fun,
                                    ask_for_pass_fun)
            logging.info('Returning client')
            return client
        else:
            logging.warning('Transport is None')
            return None

    except Exception as e:
        logging.exception("Exception occurred")
        raise
Ejemplo n.º 4
0
def connect_trezor(ask_for_pin_fun, ask_for_pass_fun):
    """
    Connect to a Trezor device.
    :param ask_for_pin_fun: ref to a function displaying a dialog asking the user for a pin (Trezor and Keepkey)
    :param ask_for_pass_fun: ref to a function displaying a dialog asking the user for a passphrase (Trezor and Keepkey)
    :return: ref to a trezor client if connection successfull or None if we are sure that no Trezor device connected.
    """

    logging.info('Started function')

    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

    # HidTransport.enumerate() has to be called in the main thread - second call from bg thread
    # causes SIGSEGV
    transport = WndUtils.callFunInTheMainThread(get_transport)
    logging.info('Read transport')
    if transport:
        logging.info('Transport is OK')
        client = MyTrezorClient(transport, ask_for_pin_fun, ask_for_pass_fun)
        logging.info(
            'Trezor connected. Firmware version: %s.%s.%s, vendor: %s, initialized: %s, '
            'pp_protection: %s, pp_cached: %s, bootloader_mode: %s ' %
            (str(client.features.major_version),
             str(client.features.minor_version),
             str(client.features.patch_version), str(
                 client.features.vendor), str(client.features.initialized),
             str(client.features.passphrase_protection),
             str(client.features.passphrase_cached),
             str(client.features.bootloader_mode)))
        return client
    else:
        logging.warning('Transport is None')
        return None
Ejemplo n.º 5
0
    def ask_for_password(username, host, message=None):
        if not SshPassCache.parent_window:
            raise Exception('SshPassCache not initialized')

        def query_psw(msg):
            password, ok = QInputDialog.getText(SshPassCache.parent_window,
                                                'Password Dialog',
                                                msg,
                                                echo=QLineEdit.Password)
            return password, ok

        if not message:
            message = 'Enter password for ' + username + '@' + host + ':'

        if threading.current_thread() != threading.main_thread():
            password, ok = WndUtils.callFunInTheMainThread(query_psw, message)
        else:
            password, ok = query_psw(message)

        if not ok:
            raise UserCancelledConnection
        return password