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


Python Key.fromFile方法代码示例

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


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

示例1: addKeyFile

# 需要导入模块: from twisted.conch.ssh.keys import Key [as 别名]
# 或者: from twisted.conch.ssh.keys.Key import fromFile [as 别名]
    def addKeyFile(self, kfile, password=None):
        if not os.path.exists(kfile):
            raise Exception("Key file not found %s", kfile)

        try:
            self.keys.append(Key.fromFile(kfile))
        except EncryptedKeyError:
            self.keys.append(Key.fromFile(kfile, passphrase=password))
开发者ID:calston,项目名称:tensor,代码行数:10,代码来源:ssh.py

示例2: __init__

# 需要导入模块: from twisted.conch.ssh.keys import Key [as 别名]
# 或者: from twisted.conch.ssh.keys.Key import fromFile [as 别名]
 def __init__(self, settings):
     self.settings = settings
     self.portal = Portal(Realm(settings))
     self.portal.registerChecker(Checker(settings))
     self.privateKeys = {
         'ssh-rsa': Key.fromFile(settings['hadoukngit']['private_key']),
     }
     self.publicKeys = {
         'ssh-rsa': Key.fromFile(settings['hadoukngit']['public_key']),
     }
开发者ID:hadoukn,项目名称:hadoukn-git-server,代码行数:12,代码来源:server.py

示例3: __init__

# 需要导入模块: from twisted.conch.ssh.keys import Key [as 别名]
# 或者: from twisted.conch.ssh.keys.Key import fromFile [as 别名]
 def __init__(self, settings):
     self.settings = settings
     self.portal = Portal(OpenRukoRealm(settings))
     self.portal.registerChecker(OpenRukoCredentialChecker(settings))
     self.privateKeys = {
         'ssh-rsa': Key.fromFile(settings['gitmouth_private_key']),
     }
     self.publicKeys = {
         'ssh-rsa': Key.fromFile(settings['gitmouth_public_key']),
     }
开发者ID:boffbowsh,项目名称:gitmouth,代码行数:12,代码来源:server.py

示例4: makeFactory

# 需要导入模块: from twisted.conch.ssh.keys import Key [as 别名]
# 或者: from twisted.conch.ssh.keys.Key import fromFile [as 别名]
 def makeFactory(self):
     """Create and start the factory that our SSH server uses."""
     factory = Factory(
         get_portal(None, None),
         private_key=Key.fromFile(
             get_key_path(PRIVATE_KEY_FILE)),
         public_key=Key.fromFile(
             get_key_path(PUBLIC_KEY_FILE)))
     factory.startFactory()
     return factory
开发者ID:pombreda,项目名称:UnnaturalCodeFork,代码行数:12,代码来源:test_daemon.py

示例5: _testrun

# 需要导入模块: from twisted.conch.ssh.keys import Key [as 别名]
# 或者: from twisted.conch.ssh.keys.Key import fromFile [as 别名]
 def _testrun(self, keyType, keySize=None):
     filename = self.mktemp()
     if keySize is None:
         subprocess.call(['ckeygen', '-t', keyType, '-f', filename, '--no-passphrase'])
     else:
         subprocess.call(['ckeygen', '-t', keyType, '-f', filename, '--no-passphrase',
             '-b', keySize])
     privKey = Key.fromFile(filename)
     pubKey = Key.fromFile(filename + '.pub')
     if keyType == 'ecdsa':
         self.assertEqual(privKey.type(), 'EC')
     else:
         self.assertEqual(privKey.type(), keyType.upper())
     self.assertTrue(pubKey.isPublic())
开发者ID:esabelhaus,项目名称:secret-octo-dubstep,代码行数:16,代码来源:test_ckeygen.py

示例6: __init__

# 需要导入模块: from twisted.conch.ssh.keys import Key [as 别名]
# 或者: from twisted.conch.ssh.keys.Key import fromFile [as 别名]
 def __init__(self,
              private_key_path,
              public_key_path,
              moduli_path=None,
              banner=None):
     portal = self._makePortal()
     ssh_factory = ParsnipSSHFactory(
         portal,
         private_key=Key.fromFile(private_key_path),
         public_key=Key.fromFile(public_key_path),
         banner=banner,
         moduli_path=moduli_path
     )
     self.service = strports.service('tcp:22', ssh_factory)
开发者ID:avoid3d,项目名称:waverbase-old,代码行数:16,代码来源:ssh.py

示例7: _load_key

# 需要导入模块: from twisted.conch.ssh.keys import Key [as 别名]
# 或者: from twisted.conch.ssh.keys.Key import fromFile [as 别名]
def _load_key(filename):
    try:
        return Key.fromFile(filename)
    except EncryptedKeyError:
        for i in xrange(3):
            passphrase = getpass.getpass("passphrase for %s: " % (filename,))
            if not passphrase:
                continue

            try:
                return Key.fromFile(filename, passphrase=passphrase)
            except BadKeyError:
                pass

        raise BadKeyPassphraseError()
开发者ID:reddit,项目名称:rollingpin,代码行数:17,代码来源:ssh.py

示例8: connect

# 需要导入模块: from twisted.conch.ssh.keys import Key [as 别名]
# 或者: from twisted.conch.ssh.keys.Key import fromFile [as 别名]
def connect(sdata, command, username, host, port=22, key_file=None, password=None):
    """
    Connect to an SSH host (as it happens, persistently).
    """
    sdata.set_conn_state('connecting')

    try:
        keys = [Key.fromFile(key_file)] if key_file else None
    except exceptions.IOError as e:
        print('### key load error:', str(e))
        push_failure_message(str(e), sdata)
        return

    endpoint = SSHCommandClientEndpoint.newConnection(
                    reactor, command, username, host, port=int(port),
                    keys=keys, password=password, ui=None,
                    knownHosts=PermissiveKnownHosts())

    factory = Factory()
    factory.protocol = LineProtocol
    factory.sdata = sdata

    d = endpoint.connect(factory)

    # Very small race condition between here and the replacement
    # in connectionMade() above, but I've never managed to hit it.
    def disconnect():
        sdata.log('Disconnecting while still attempting to connect, by request')
        d.cancel()
    sdata.transport_drop_cb = disconnect

    d.addErrback(lambda reason: push_failure_message(reason, sdata))
    return d
开发者ID:cisco,项目名称:xr-telemetry-m2m-web,代码行数:35,代码来源:ssh.py

示例9: getPublicKey

# 需要导入模块: from twisted.conch.ssh.keys import Key [as 别名]
# 或者: from twisted.conch.ssh.keys.Key import fromFile [as 别名]
 def getPublicKey(self):
     # this works with rsa too
     # just change the name here and in getPrivateKey
     if not os.path.exists(key_path) or self.lastPublicKey:
         # the file doesn't exist, or we've tried a public key
         return
     return Key.fromFile(key_path + ".pub")
开发者ID:ekohl,项目名称:vncauthproxy,代码行数:9,代码来源:ssh.py

示例10: generated

# 需要导入模块: from twisted.conch.ssh.keys import Key [as 别名]
# 或者: from twisted.conch.ssh.keys.Key import fromFile [as 别名]
        def generated(ignored):
            key = Key.fromFile(id_rsa.path)

            configuring = deferToThread(
                self.configure_ssh, self.server.ip, self.server.port)
            configuring.addCallback(lambda ignored: key)
            return configuring
开发者ID:tombh,项目名称:flocker,代码行数:9,代码来源:test_sshconfig.py

示例11: getPublicKey

# 需要导入模块: from twisted.conch.ssh.keys import Key [as 别名]
# 或者: from twisted.conch.ssh.keys.Key import fromFile [as 别名]
 def getPublicKey(self):
     path = self.options['ssh-key']
     # this works with rsa too
     # just change the name here and in getPrivateKey
     if not os.path.exists(path) or self.lastPublicKey:
         # the file doesn't exist, or we've tried a public key
         return
     return Key.fromFile(filename=path+'.pub')
开发者ID:bollustrado,项目名称:twisted_conch_pytexas_12,代码行数:10,代码来源:slave.py

示例12: test_key_not_regenerated

# 需要导入模块: from twisted.conch.ssh.keys import Key [as 别名]
# 或者: from twisted.conch.ssh.keys.Key import fromFile [as 别名]
    def test_key_not_regenerated(self):
        """
        ``create_keypair`` does not generate a new key pair if one can
        already be found in ``id_rsa_flocker`` and ``id_rsa_flocker.pub``.
        """
        ssh_config = FilePath(self.mktemp())
        configurator = OpenSSHConfiguration(
            ssh_config_path=ssh_config, flocker_path=None)

        id_rsa = ssh_config.child(b"id_rsa_flocker")

        configurator.create_keypair()

        expected_key = Key.fromFile(id_rsa.path)

        configurator.create_keypair()

        self.assertEqual(expected_key, Key.fromFile(id_rsa.path))
开发者ID:alex-docker,项目名称:flocker,代码行数:20,代码来源:test_sshconfig.py

示例13: __init__

# 需要导入模块: from twisted.conch.ssh.keys import Key [as 别名]
# 或者: from twisted.conch.ssh.keys.Key import fromFile [as 别名]
    def __init__(self, base_path):
        """
        :param FilePath base_path: The path beneath which all of the temporary
            SSH server-related files will be created.  An ``ssh`` directory
            will be created as a child of this directory to hold the key pair
            that is generated.  An ``sshd`` directory will also be created here
            to hold the generated host key.  A ``home`` directory is also
            created here and used as the home directory for shell logins to the
            server.
        """
        self.home = base_path.child(b"home")
        self.home.makedirs()

        ssh_path = base_path.child(b"ssh")
        ssh_path.makedirs()
        self.key_path = ssh_path.child(b"key")
        check_call(
            [
                b"ssh-keygen",
                # Specify the path where the generated key is written.
                b"-f",
                self.key_path.path,
                # Specify an empty passphrase.
                b"-N",
                b"",
                # Generate as little output as possible.
                b"-q",
            ]
        )
        key = Key.fromFile(self.key_path.path)

        sshd_path = base_path.child(b"sshd")
        sshd_path.makedirs()
        self.host_key_path = sshd_path.child(b"ssh_host_key")
        check_call(
            [
                b"ssh-keygen",
                # See above for option explanations.
                b"-f",
                self.host_key_path.path,
                b"-N",
                b"",
                b"-q",
            ]
        )

        factory = OpenSSHFactory()
        realm = _UnixSSHRealm(self.home)
        checker = _InMemoryPublicKeyChecker(public_key=key.public())
        factory.portal = Portal(realm, [checker])
        factory.dataRoot = sshd_path.path
        factory.moduliRoot = b"/etc/ssh"

        self._port = reactor.listenTCP(0, factory, interface=b"127.0.0.1")
        self.ip = IPAddress(self._port.getHost().host)
        self.port = self._port.getHost().port
开发者ID:zyegfryed,项目名称:flocker,代码行数:58,代码来源:ssh.py

示例14: get_manhole_factory

# 需要导入模块: from twisted.conch.ssh.keys import Key [as 别名]
# 或者: from twisted.conch.ssh.keys.Key import fromFile [as 别名]
def get_manhole_factory(namespace):
    """ Build a twisted manhole factory """

    from twisted.conch import manhole, manhole_ssh
    from twisted.cred import portal, checkers

    # I really hate Twisted's default colors
    colors = {
        'identifier': '\x1b[1;36m',
        'keyword': '\x1b[33m',
        'parameter': '\x1b[33m',
        'variable': '\x1b[36m',
        'string': '\x1b[35m',
        'number': '\x1b[1;32m',
        'op': '\x1b[33m'
    }

    manhole.VT102Writer.typeToColor.update(colors)

    realm = manhole_ssh.TerminalRealm()

    def get_manhole(_):
        return manhole.ColoredManhole(namespace)

    realm.chainedProtocolFactory.protocolFactory = get_manhole
    p = portal.Portal(realm)
    checker = checkers.InMemoryUsernamePasswordDatabaseDontUse()
    checker.addUser(config.backdoor_user, config.backdoor_password)
    p.registerChecker(checker)

    factory = manhole_ssh.ConchFactory(p)
    # As of Twisted~v16.0.0 we now have to give host SSH keys to any subclass of SSHFactory
    key_path = os.path.expanduser(config.ssh_key_path)
    factory.publicKeys = {
        'ssh-rsa': Key.fromFile(key_path)
    }

    factory.privateKeys = {
        'ssh-rsa': Key.fromFile(key_path)
    }

    return factory
开发者ID:spicerack,项目名称:sage,代码行数:44,代码来源:server.py

示例15: postOptions

# 需要导入模块: from twisted.conch.ssh.keys import Key [as 别名]
# 或者: from twisted.conch.ssh.keys.Key import fromFile [as 别名]
 def postOptions(self):
     """
     Verify the configuration is usable.
     """
     for required in ["auth-host", "auth-port", "host-key", "client-key",
                      "client-cert"]:
         if self[required] is None:
             raise UsageError("--%s option is required" % (required,))
     try:
         self["host-key"] = Key.fromFile(self["host-key"].path)
     except (IOError, BadKeyError), e:
         raise UsageError("Cannot load host key: %s" % (e,))
开发者ID:exarkun,项目名称:Pantheon-SSH,代码行数:14,代码来源:tap.py


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