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


Python KnownHostsFile.fromPath方法代码示例

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


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

示例1: test_savingsPreservesExisting

# 需要导入模块: from twisted.conch.client.knownhosts import KnownHostsFile [as 别名]
# 或者: from twisted.conch.client.knownhosts.KnownHostsFile import fromPath [as 别名]
    def test_savingsPreservesExisting(self):
        """
        L{KnownHostsFile.save} will not overwrite existing entries in its save
        path, even if they were only added after the L{KnownHostsFile} instance
        was initialized.
        """
        # Start off with one host/key pair in the file
        path = self.pathWithContent(sampleHashedLine)
        knownHosts = KnownHostsFile.fromPath(path)

        # After initializing the KnownHostsFile instance, add a second host/key
        # pair to the file directly - without the instance's help or knowledge.
        with path.open("a") as hostsFileObj:
            hostsFileObj.write(otherSamplePlaintextLine)

        # Add a third host/key pair using the KnownHostsFile instance
        key = Key.fromString(thirdSampleKey)
        knownHosts.addHostKey("brandnew.example.com", key)
        knownHosts.save()

        # Check that all three host/key pairs are present.
        knownHosts = KnownHostsFile.fromPath(path)
        self.assertEqual([True, True, True], [
                knownHosts.hasHostKey(
                    "www.twistedmatrix.com", Key.fromString(sampleKey)),
                knownHosts.hasHostKey(
                    "divmod.com", Key.fromString(otherSampleKey)),
                knownHosts.hasHostKey("brandnew.example.com", key)])
开发者ID:12019,项目名称:OpenWrt_Luci_Lua,代码行数:30,代码来源:test_knownhosts.py

示例2: __init__

# 需要导入模块: from twisted.conch.client.knownhosts import KnownHostsFile [as 别名]
# 或者: from twisted.conch.client.knownhosts.KnownHostsFile import fromPath [as 别名]
    def __init__(self, *args, **kw):
        channel.CowrieSSHChannel.__init__(self, *args, **kw)

        keyPath = CONFIG.get('proxy', 'private_key')
        self.keys.append(keys.Key.fromFile(keyPath))

        try:
            keyPath = CONFIG.get('proxy', 'private_key')
            self.keys.append(keys.Key.fromFile(keyPath))
        except NoOptionError:
            self.keys = None

        knownHostsPath = CONFIG.get('proxy', 'known_hosts')
        self.knownHosts = KnownHostsFile.fromPath(knownHostsPath)

        self.host = CONFIG.get('proxy', 'host')
        self.port = CONFIG.getint('proxy', 'port')
        self.user = CONFIG.get('proxy', 'user')
        try:
            self.password = CONFIG.get('proxy', 'password')
        except NoOptionError:
            self.password = None

        log.msg("knownHosts = {0}".format(repr(self.knownHosts)))
        log.msg("host = {0}".format(self.host))
        log.msg("port = {0}".format(self.port))
        log.msg("user = {0}".format(self.user))

        self.client = ProxyClient(self)
开发者ID:Mato-Z,项目名称:cowrie,代码行数:31,代码来源:session.py

示例3: _knownHosts

# 需要导入模块: from twisted.conch.client.knownhosts import KnownHostsFile [as 别名]
# 或者: from twisted.conch.client.knownhosts.KnownHostsFile import fromPath [as 别名]
 def _knownHosts(cls):
     """
     @return: A L{KnownHostsFile} instance pointed at the user's personal
         I{known hosts} file.
     @type: L{KnownHostsFile}
     """
     return KnownHostsFile.fromPath(FilePath(expanduser(cls._KNOWN_HOSTS)))
开发者ID:0004c,项目名称:VTK,代码行数:9,代码来源:endpoints.py

示例4: fromConfig

# 需要导入模块: from twisted.conch.client.knownhosts import KnownHostsFile [as 别名]
# 或者: from twisted.conch.client.knownhosts.KnownHostsFile import fromPath [as 别名]
    def fromConfig(cls, reactor):
        keys = []
        if "identity" in _CONFIG:
            keyPath = os.path.expanduser(_CONFIG["identity"])
            if os.path.exists(keyPath):
                keys.append(readKey(keyPath))

        knownHostsPath = FilePath(os.path.expanduser(_CONFIG["knownhosts"]))
        if knownHostsPath.exists():
            knownHosts = KnownHostsFile.fromPath(knownHostsPath)
        else:
            knownHosts = None

        if "no-agent" in _CONFIG or "SSH_AUTH_SOCK" not in os.environ:
            agentEndpoint = None
        else:
            agentEndpoint = UNIXClientEndpoint(
                reactor, os.environ["SSH_AUTH_SOCK"])

        if "password" in _CONFIG:
            password = _CONFIG["password"]
        else:
            password = None

        return cls(
            reactor, _CONFIG["host"], _CONFIG["port"],
            _CONFIG["username"], password, keys,
            knownHosts, agentEndpoint)
开发者ID:fredericlepied,项目名称:zgerrit,代码行数:30,代码来源:zgerrit.py

示例5: fromCommandLine

# 需要导入模块: from twisted.conch.client.knownhosts import KnownHostsFile [as 别名]
# 或者: from twisted.conch.client.knownhosts.KnownHostsFile import fromPath [as 别名]
    def fromCommandLine(cls, reactor, argv):
        config = EchoOptions()
        config.parseOptions(argv)

        keys = []
        if config["identity"]:
            keyPath = os.path.expanduser(config["identity"])
            if os.path.exists(keyPath):
                keys.append(readKey(keyPath))

        knownHostsPath = FilePath(os.path.expanduser(config["knownhosts"]))
        if knownHostsPath.exists():
            knownHosts = KnownHostsFile.fromPath(knownHostsPath)
        else:
            knownHosts = None

        if config["no-agent"] or "SSH_AUTH_SOCK" not in os.environ:
            agentEndpoint = None
        else:
            agentEndpoint = UNIXClientEndpoint(
                reactor, os.environ["SSH_AUTH_SOCK"])

        return cls(
            reactor, config["host"], config["port"],
            config["username"], config["password"], keys,
            knownHosts, agentEndpoint)
开发者ID:wellbehavedsoftware,项目名称:wbs-graphite,代码行数:28,代码来源:echoclient_ssh.py

示例6: get_connection_helper

# 需要导入模块: from twisted.conch.client.knownhosts import KnownHostsFile [as 别名]
# 或者: from twisted.conch.client.knownhosts.KnownHostsFile import fromPath [as 别名]
def get_connection_helper(reactor, address, username, port):
    """
    Get a :class:`twisted.conch.endpoints._ISSHConnectionCreator` to connect to
    the given remote.

    :param reactor: Reactor to connect with.
    :param bytes address: The address of the remote host to connect to.
    :param bytes username: The user to connect as.
    :param int port: The port of the ssh server to connect to.

    :return _ISSHConnectionCreator:
    """
    try:
        agentEndpoint = UNIXClientEndpoint(
            reactor, os.environ["SSH_AUTH_SOCK"])
    except KeyError:
        agentEndpoint = None

    return _NewConnectionHelper(
        reactor, address, port, None, username,
        keys=None,
        password=None,
        agentEndpoint=agentEndpoint,
        knownHosts=KnownHostsFile.fromPath(FilePath("/dev/null")),
        ui=ConsoleUI(lambda: _ReadFile(b"yes")))
开发者ID:wangbinxiang,项目名称:flocker,代码行数:27,代码来源:_conch.py

示例7: verifyHostKey

# 需要导入模块: from twisted.conch.client.knownhosts import KnownHostsFile [as 别名]
# 或者: from twisted.conch.client.knownhosts.KnownHostsFile import fromPath [as 别名]
 def verifyHostKey(transport, host, pubKey, fingerprint):
     log.msg("verifying host key")
     actualHost = transport.factory.options["host"]
     actualKey = keys.Key.fromString(pubKey)
     kh = KnownHostsFile.fromPath(
         FilePath(transport.factory.options["known-hosts"] or os.path.expanduser("~/.ssh/known_hosts"))
     )
     return kh.verifyHostKey(console, actualHost, host, actualKey).addErrback(log.err)
开发者ID:pdh,项目名称:beatlounge,代码行数:10,代码来源:console.py

示例8: __init__

# 需要导入模块: from twisted.conch.client.knownhosts import KnownHostsFile [as 别名]
# 或者: from twisted.conch.client.knownhosts.KnownHostsFile import fromPath [as 别名]
 def __init__(self, factory):
     self.factory = factory
     self._state = b'STARTING'
     self.knownHosts = KnownHostsFile.fromPath(
         FilePath(os.path.expanduser('~/.ssh/known_hosts'))
     )
     self._hostKeyFailure = None
     self._user_auth = None
     self._connection_lost_reason = None
开发者ID:eddking,项目名称:metis,代码行数:11,代码来源:client.py

示例9: connectionMade

# 需要导入模块: from twisted.conch.client.knownhosts import KnownHostsFile [as 别名]
# 或者: from twisted.conch.client.knownhosts.KnownHostsFile import fromPath [as 别名]
 def connectionMade(self):
     script_dir = os.getcwd()
     rel_path = "hostkeys"
     abs_file_path = os.path.join(script_dir, rel_path)
     knownHosts = KnownHostsFile.fromPath(abs_file_path)
     self.point = SSHCommandClientEndpoint.newConnection(reactor, 'cmd', 'user', '127.0.0.1', port=5122,
                                                         password='password', knownHosts=PermissiveKnownHosts())
     self.sshSide = FzSSHClient()
     self.sshSide.tcpSide = self
     connectProtocol(self.point, self.sshSide)
开发者ID:matanmaz,项目名称:SshTelnetProxy,代码行数:12,代码来源:TcpSshConverter.py

示例10: loadSampleHostsFile

# 需要导入模块: from twisted.conch.client.knownhosts import KnownHostsFile [as 别名]
# 或者: from twisted.conch.client.knownhosts.KnownHostsFile import fromPath [as 别名]
 def loadSampleHostsFile(self, content=(
         sampleHashedLine + otherSamplePlaintextLine +
         "\n# That was a blank line.\n"
         "This is just unparseable.\n"
         "|1|This also unparseable.\n")):
     """
     Return a sample hosts file, with keys for www.twistedmatrix.com and
     divmod.com present.
     """
     return KnownHostsFile.fromPath(self.pathWithContent(content))
开发者ID:12019,项目名称:OpenWrt_Luci_Lua,代码行数:12,代码来源:test_knownhosts.py

示例11: test_loadNonExistent

# 需要导入模块: from twisted.conch.client.knownhosts import KnownHostsFile [as 别名]
# 或者: from twisted.conch.client.knownhosts.KnownHostsFile import fromPath [as 别名]
 def test_loadNonExistent(self):
     """
     Loading a L{KnownHostsFile} from a path that does not exist should
     result in an empty L{KnownHostsFile} that will save back to that path.
     """
     pn = self.mktemp()
     knownHostsFile = KnownHostsFile.fromPath(FilePath(pn))
     self.assertEqual([], list(knownHostsFile._entries))
     self.assertEqual(False, FilePath(pn).exists())
     knownHostsFile.save()
     self.assertEqual(True, FilePath(pn).exists())
开发者ID:AmirKhooj,项目名称:VTK,代码行数:13,代码来源:test_knownhosts.py

示例12: test_loadNonExistentParent

# 需要导入模块: from twisted.conch.client.knownhosts import KnownHostsFile [as 别名]
# 或者: from twisted.conch.client.knownhosts.KnownHostsFile import fromPath [as 别名]
 def test_loadNonExistentParent(self):
     """
     Loading a L{KnownHostsFile} from a path whose parent directory does not
     exist should result in an empty L{KnownHostsFile} that will save back
     to that path, creating its parent directory(ies) in the process.
     """
     thePath = FilePath(self.mktemp())
     knownHostsPath = thePath.child("foo").child("known_hosts")
     knownHostsFile = KnownHostsFile.fromPath(knownHostsPath)
     knownHostsFile.save()
     knownHostsPath.restat(False)
     self.assertEqual(True, knownHostsPath.exists())
开发者ID:12019,项目名称:OpenWrt_Luci_Lua,代码行数:14,代码来源:test_knownhosts.py

示例13: test_savingAvoidsDuplication

# 需要导入模块: from twisted.conch.client.knownhosts import KnownHostsFile [as 别名]
# 或者: from twisted.conch.client.knownhosts.KnownHostsFile import fromPath [as 别名]
    def test_savingAvoidsDuplication(self):
        """
        L{KnownHostsFile.save} only writes new entries to the save path, not
        entries which were added and already written by a previous call to
        C{save}.
        """
        path = FilePath(self.mktemp())
        knownHosts = KnownHostsFile(path)
        entry = knownHosts.addHostKey(
            "some.example.com", Key.fromString(sampleKey))
        knownHosts.save()
        knownHosts.save()

        knownHosts = KnownHostsFile.fromPath(path)
        self.assertEqual([entry], list(knownHosts.iterentries()))
开发者ID:12019,项目名称:OpenWrt_Luci_Lua,代码行数:17,代码来源:test_knownhosts.py

示例14: verifyHostKey

# 需要导入模块: from twisted.conch.client.knownhosts import KnownHostsFile [as 别名]
# 或者: from twisted.conch.client.knownhosts.KnownHostsFile import fromPath [as 别名]
def verifyHostKey(transport, host, pubKey, fingerprint):
    """
    Verify a host's key.

    This function is a gross vestige of some bad factoring in the client
    internals.  The actual implementation, and a better signature of this logic
    is in L{KnownHostsFile.verifyHostKey}.  This function is not deprecated yet
    because the callers have not yet been rehabilitated, but they should
    eventually be changed to call that method instead.

    However, this function does perform two functions not implemented by
    L{KnownHostsFile.verifyHostKey}.  It determines the path to the user's
    known_hosts file based on the options (which should really be the options
    object's job), and it provides an opener to L{ConsoleUI} which opens
    '/dev/tty' so that the user will be prompted on the tty of the process even
    if the input and output of the process has been redirected.  This latter
    part is, somewhat obviously, not portable, but I don't know of a portable
    equivalent that could be used.

    @param host: Due to a bug in L{SSHClientTransport.verifyHostKey}, this is
    always the dotted-quad IP address of the host being connected to.
    @type host: L{str}

    @param transport: the client transport which is attempting to connect to
    the given host.
    @type transport: L{SSHClientTransport}

    @param fingerprint: the fingerprint of the given public key, in
    xx:xx:xx:... format.  This is ignored in favor of getting the fingerprint
    from the key itself.
    @type fingerprint: L{str}

    @param pubKey: The public key of the server being connected to.
    @type pubKey: L{str}

    @return: a L{Deferred} which fires with C{1} if the key was successfully
    verified, or fails if the key could not be successfully verified.  Failure
    types may include L{HostKeyChanged}, L{UserRejectedKey}, L{IOError} or
    L{KeyboardInterrupt}.
    """
    actualHost = transport.factory.options['host']
    actualKey = keys.Key.fromString(pubKey)
    kh = KnownHostsFile.fromPath(FilePath(
            transport.factory.options['known-hosts']
            or os.path.expanduser(_KNOWN_HOSTS)
            ))
    ui = ConsoleUI(lambda : _open("/dev/tty", "r+b"))
    return kh.verifyHostKey(ui, actualHost, host, actualKey)
开发者ID:dansgithubuser,项目名称:constructicon,代码行数:50,代码来源:default.py

示例15: test_verifyNonPresentKey_Yes

# 需要导入模块: from twisted.conch.client.knownhosts import KnownHostsFile [as 别名]
# 或者: from twisted.conch.client.knownhosts.KnownHostsFile import fromPath [as 别名]
 def test_verifyNonPresentKey_Yes(self):
     """
     Verifying a key where neither the hostname nor the IP are present
     should result in the UI being prompted with a message explaining as
     much.  If the UI says yes, the Deferred should fire with True.
     """
     ui, l, knownHostsFile = self.verifyNonPresentKey()
     ui.promptDeferred.callback(True)
     self.assertEqual([True], l)
     reloaded = KnownHostsFile.fromPath(knownHostsFile.savePath)
     self.assertEqual(
         True,
         reloaded.hasHostKey("4.3.2.1", Key.fromString(thirdSampleKey)))
     self.assertEqual(
         True,
         reloaded.hasHostKey("sample-host.example.com",
                             Key.fromString(thirdSampleKey)))
开发者ID:12019,项目名称:OpenWrt_Luci_Lua,代码行数:19,代码来源:test_knownhosts.py


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