当前位置: 首页>>代码示例>>Python>>正文


Python Agent.get_keys方法代码示例

本文整理汇总了Python中paramiko.agent.Agent.get_keys方法的典型用法代码示例。如果您正苦于以下问题:Python Agent.get_keys方法的具体用法?Python Agent.get_keys怎么用?Python Agent.get_keys使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在paramiko.agent.Agent的用法示例。


在下文中一共展示了Agent.get_keys方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _prepare_ssh_pkey

# 需要导入模块: from paramiko.agent import Agent [as 别名]
# 或者: from paramiko.agent.Agent import get_keys [as 别名]
  def _prepare_ssh_pkey(self):
    """Tries to load config.ssh_key from file, for later use. Doesn't do that, it there are keys in the agent."""
    from paramiko.agent import Agent
    from paramiko import RSAKey, DSSKey
    import getpass
    if config.ssh_key is None:
      # user didn't configure a specific ssh_key, so nothing to do for us
      return None

    agent = Agent()
    if len(agent.get_keys()) > 0 and config.ssh_key_ignore_if_agent:
      print "I: Running ssh-agent found, not loading ssh-key %s" % config.ssh_key
      return None

    # try to load the key from file
    password = None
    need_password = False
    saved_exception = None
    for pkey_class in (DSSKey, RSAKey):
      try:
        return pkey_class.from_private_key_file(config.ssh_key, password=password)
      except paramiko.PasswordRequiredException:
        need_password = True
        break
      except paramiko.SSHException, e:
        saved_exception = e
开发者ID:zeha,项目名称:multiapt,代码行数:28,代码来源:multiapt.py

示例2: SSHClient

# 需要导入模块: from paramiko.agent import Agent [as 别名]
# 或者: from paramiko.agent.Agent import get_keys [as 别名]

#.........这里部分代码省略.........
        if pkey is not None:
            try:
                self._log(
                    DEBUG,
                    'Trying SSH key %s' % hexlify(pkey.get_fingerprint()))
                allowed_types = set(
                    self._transport.auth_publickey(username, pkey))
                two_factor = (allowed_types & two_factor_types)
                if not two_factor:
                    return
            except SSHException as e:
                saved_exception = e

        if not two_factor:
            for key_filename in key_filenames:
                for pkey_class in (RSAKey, DSSKey, ECDSAKey, Ed25519Key):
                    try:
                        key = self._key_from_filepath(
                            key_filename, pkey_class, password,
                        )
                        allowed_types = set(
                            self._transport.auth_publickey(username, key))
                        two_factor = (allowed_types & two_factor_types)
                        if not two_factor:
                            return
                        break
                    except SSHException as e:
                        saved_exception = e

        if not two_factor and allow_agent:
            if self._agent is None:
                self._agent = Agent()

            for key in self._agent.get_keys():
                try:
                    self._log(
                        DEBUG,
                        'Trying SSH agent key %s' % hexlify(
                            key.get_fingerprint()))
                    # for 2-factor auth a successfully auth'd key password
                    # will return an allowed 2fac auth method
                    allowed_types = set(
                        self._transport.auth_publickey(username, key))
                    two_factor = (allowed_types & two_factor_types)
                    if not two_factor:
                        return
                    break
                except SSHException as e:
                    saved_exception = e

        if not two_factor:
            keyfiles = []

            for keytype, name in [
                (RSAKey, "rsa"),
                (DSSKey, "dsa"),
                (ECDSAKey, "ecdsa"),
                (Ed25519Key, "ed25519"),
            ]:
                # ~/ssh/ is for windows
                for directory in [".ssh", "ssh"]:
                    full_path = os.path.expanduser(
                        "~/%s/id_%s" % (directory, name)
                    )
                    if os.path.isfile(full_path):
                        # TODO: only do this append if below did not run
开发者ID:starboarder2001,项目名称:paramiko,代码行数:70,代码来源:client.py

示例3: SSHClient

# 需要导入模块: from paramiko.agent import Agent [as 别名]
# 或者: from paramiko.agent.Agent import get_keys [as 别名]

#.........这里部分代码省略.........
                    except:
                        self._log(EXCEPTION, 'non-ssh exception')
                        raise
                    else:
                        self._log(DEBUG,
                                  '%s is the right Public Key Algorithm for file %s' % (
                                      algo, key_filename))

                    self._log(DEBUG, 'Trying key %s from %s' %
                              (hexlify(key.get_fingerprint()), key_filename))

                    try:
                        allowed_types = set(
                            self._transport.auth_publickey(username, key))
                        two_factor = (allowed_types & two_factor_types)
                        if not two_factor:
                            return
                    except AuthenticationException as e:
                        self._log(EXCEPTION, 'Authentication failure')
                        raise
                    except SSHException as e:
                        self._log(EXCEPTION, 'ssh exception')
                        raise
                    except:
                        self._log(EXCEPTION, 'non-ssh exception')
                        raise
                    else:
                        break

        if not two_factor and allow_agent:
            if self._agent is None:
                self._agent = Agent()

            for key in self._agent.get_keys():
                try:
                    self._log(DEBUG, 'Trying SSH agent key %s' %
                              hexlify(key.get_fingerprint()))
                    # for 2-factor auth a successfully auth'd key password will
                    # return an allowed 2fac auth method
                    allowed_types = set(
                        self._transport.auth_publickey(username, key))
                    two_factor = (allowed_types & two_factor_types)
                    if not two_factor:
                        return
                    break
                except AuthenticationException as e:
                    self._log(EXCEPTION, 'Authentication failure')
                    raise
                except SSHException as e:
                    self._log(DEBUG,
                              '%s is not the right Public Key' % key)
                except:
                    self._log(EXCEPTION, 'non-ssh exception')
                    raise
                else:
                    self._log(DEBUG,
                              '%s is the right Public Key' % key)
                    break

        if not two_factor:
            keyfiles = []
            if look_for_keys:
                for pfx in ('~/.ssh', '~/ssh'):
                    for algo, adict in algo_map:
                        keyfile = os.path.join(os.path.expanduser(pfx),
                                               adict['filename'])
开发者ID:LLC-Technologies-Collier,项目名称:paramiko,代码行数:70,代码来源:client.py

示例4: SSHClient

# 需要导入模块: from paramiko.agent import Agent [as 别名]
# 或者: from paramiko.agent.Agent import get_keys [as 别名]

#.........这里部分代码省略.........
            - The key passed in, if one was passed in.
            - Any key we can find through an SSH agent (if allowed).
            - Any "id_rsa" or "id_dsa" key discoverable in ~/.ssh/ (if allowed).
            - Plain username/password auth, if a password was given.

        (The password might be needed to unlock a private key, or for
        two-factor authentication [for which it is required].)
        """
        saved_exception = None
        two_factor = False
        allowed_types = []

        if pkey is not None:
            try:
                self._log(DEBUG, 'Trying SSH key %s' % hexlify(pkey.get_fingerprint()))
                allowed_types = self._transport.auth_publickey(username, pkey)
                two_factor = (allowed_types == ['password'])
                if not two_factor:
                    return
            except SSHException:
                saved_exception = sys.exc_info()[1]

        if not two_factor:
            for key_filename in key_filenames:
                for pkey_class in (RSAKey, DSSKey):
                    try:
                        key = pkey_class.from_private_key_file(key_filename, password)
                        self._log(DEBUG, 'Trying key %s from %s' % (hexlify(key.get_fingerprint()), key_filename))
                        self._transport.auth_publickey(username, key)
                        two_factor = (allowed_types == ['password'])
                        if not two_factor:
                            return
                        break
                    except SSHException:
                        saved_exception = sys.exc_info()[1]

        if not two_factor and allow_agent:
            if self._agent == None:
                self._agent = Agent()

            for key in self._agent.get_keys():
                try:
                    self._log(DEBUG, 'Trying SSH agent key %s' % hexlify(key.get_fingerprint()))
                    # for 2-factor auth a successfully auth'd key will result in ['password']
                    allowed_types = self._transport.auth_publickey(username, key)
                    two_factor = (allowed_types == ['password'])
                    if not two_factor:
                        return
                    break
                except SSHException:
                    saved_exception = sys.exc_info()[1]

        if not two_factor:
            keyfiles = []
            rsa_key = os.path.expanduser('~/.ssh/id_rsa')
            dsa_key = os.path.expanduser('~/.ssh/id_dsa')
            if os.path.isfile(rsa_key):
                keyfiles.append((RSAKey, rsa_key))
            if os.path.isfile(dsa_key):
                keyfiles.append((DSSKey, dsa_key))
            # look in ~/ssh/ for windows users:
            rsa_key = os.path.expanduser('~/ssh/id_rsa')
            dsa_key = os.path.expanduser('~/ssh/id_dsa')
            if os.path.isfile(rsa_key):
                keyfiles.append((RSAKey, rsa_key))
            if os.path.isfile(dsa_key):
                keyfiles.append((DSSKey, dsa_key))

            if not look_for_keys:
                keyfiles = []

            for pkey_class, filename in keyfiles:
                try:
                    key = pkey_class.from_private_key_file(filename, password)
                    self._log(DEBUG, 'Trying discovered key %s in %s' % (hexlify(key.get_fingerprint()), filename))
                    # for 2-factor auth a successfully auth'd key will result in ['password']
                    allowed_types = self._transport.auth_publickey(username, key)
                    two_factor = (allowed_types == ['password'])
                    if not two_factor:
                        return
                    break
                except (SSHException, IOError):
                    saved_exception = sys.exc_info()[1]

        if password is not None:
            try:
                self._transport.auth_password(username, password)
                return
            except SSHException:
                saved_exception = sys.exc_info()[1]
        elif two_factor:
            raise SSHException('Two-factor authentication requires a password')

        # if we got an auth-failed exception earlier, re-raise it
        if saved_exception is not None:
            raise saved_exception
        raise SSHException('No authentication methods available')

    def _log(self, level, msg):
        self._transport._log(level, msg)
开发者ID:molddu,项目名称:tiramola,代码行数:104,代码来源:client.py

示例5: get_agent_keys

# 需要导入模块: from paramiko.agent import Agent [as 别名]
# 或者: from paramiko.agent.Agent import get_keys [as 别名]
def get_agent_keys():
    agent = Agent()
    keys = [KeyPair(_key=key) for key in agent.get_keys()]
    agent.close()
    return keys
开发者ID:jdotpy,项目名称:pycloud,代码行数:7,代码来源:security.py


注:本文中的paramiko.agent.Agent.get_keys方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。