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


Python credentials.SSHPrivateKey方法代码示例

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


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

示例1: auth_publickey

# 需要导入模块: from twisted.cred import credentials [as 别名]
# 或者: from twisted.cred.credentials import SSHPrivateKey [as 别名]
def auth_publickey(self, packet):
        hasSig = ord(packet[0])
        algName, blob, rest = getNS(packet[1:], 2)
        pubKey = keys.getPublicKeyObject(data = blob)
        signature = hasSig and getNS(rest)[0] or None
        if hasSig:
            b = NS(self.transport.sessionID) + chr(MSG_USERAUTH_REQUEST) + \
                NS(self.user) + NS(self.nextService) + NS('publickey') + \
                chr(hasSig) +  NS(keys.objectType(pubKey)) + NS(blob)
            c = credentials.SSHPrivateKey(self.user, algName, blob, b, signature)
            return self.portal.login(c, None, interfaces.IConchUser)
        else:
            c = credentials.SSHPrivateKey(self.user, algName, blob, None, None)
            return self.portal.login(c, None, interfaces.IConchUser).addErrback(
                                                        self._ebCheckKey,
                                                        packet[1:]) 
开发者ID:kenorb-contrib,项目名称:BitTorrent,代码行数:18,代码来源:userauth.py

示例2: auth_publickey

# 需要导入模块: from twisted.cred import credentials [as 别名]
# 或者: from twisted.cred.credentials import SSHPrivateKey [as 别名]
def auth_publickey(self, packet):
        """
        Public key authentication.  Payload::
            byte has signature
            string algorithm name
            string key blob
            [string signature] (if has signature is True)

        Create a SSHPublicKey credential and verify it using our portal.
        """
        hasSig = ord(packet[0:1])
        algName, blob, rest = getNS(packet[1:], 2)
        pubKey = keys.Key.fromString(blob)
        signature = hasSig and getNS(rest)[0] or None
        if hasSig:
            b = (NS(self.transport.sessionID) + chr(MSG_USERAUTH_REQUEST) +
                NS(self.user) + NS(self.nextService) + NS(b'publickey') +
                chr(hasSig) +  NS(pubKey.sshType()) + NS(blob))
            c = credentials.SSHPrivateKey(self.user, algName, blob, b,
                    signature)
            return self.portal.login(c, None, interfaces.IConchUser)
        else:
            c = credentials.SSHPrivateKey(self.user, algName, blob, None, None)
            return self.portal.login(c, None,
                    interfaces.IConchUser).addErrback(self._ebCheckKey,
                            packet[1:]) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:28,代码来源:userauth.py

示例3: auth_publickey

# 需要导入模块: from twisted.cred import credentials [as 别名]
# 或者: from twisted.cred.credentials import SSHPrivateKey [as 别名]
def auth_publickey(self, packet):
        """
        Public key authentication.  Payload::
            byte has signature
            string algorithm name
            string key blob
            [string signature] (if has signature is True)

        Create a SSHPublicKey credential and verify it using our portal.
        """
        hasSig = ord(packet[0:1])
        algName, blob, rest = getNS(packet[1:], 2)

        try:
            pubKey = keys.Key.fromString(blob)
        except keys.BadKeyError:
            error = "Unsupported key type %s or bad key" % (
                algName.decode('ascii'),)
            log.msg(error)
            return defer.fail(UnauthorizedLogin(error))

        signature = hasSig and getNS(rest)[0] or None
        if hasSig:
            b = (NS(self.transport.sessionID) + chr(MSG_USERAUTH_REQUEST) +
                NS(self.user) + NS(self.nextService) + NS(b'publickey') +
                chr(hasSig) +  NS(pubKey.sshType()) + NS(blob))
            c = credentials.SSHPrivateKey(self.user, algName, blob, b,
                    signature)
            return self.portal.login(c, None, interfaces.IConchUser)
        else:
            c = credentials.SSHPrivateKey(self.user, algName, blob, None, None)
            return self.portal.login(c, None,
                    interfaces.IConchUser).addErrback(self._ebCheckKey,
                            packet[1:]) 
开发者ID:wistbean,项目名称:learn_python3_spider,代码行数:36,代码来源:userauth.py

示例4: auth_publickey

# 需要导入模块: from twisted.cred import credentials [as 别名]
# 或者: from twisted.cred.credentials import SSHPrivateKey [as 别名]
def auth_publickey(self, packet):

        try:
            #extract the public key blob from the SSH packet
            key_blob = getNS(getNS(packet[1:])[1])[0]
        except:
            key_blob = "No public key found."

        try:
            #convert blob into openssh key format
            key = keys.Key.fromString(key_blob).toString('openssh')
        except:
            key = "Invalid SSH Public Key Submitted: {key_blob}".format(key_blob=key_blob.encode('hex'))
            for keytype in ['ecdsa-sha2-nistp256','ecdsa-sha2-nistp384','ecdsa-sha2-nistp521','ssh-ed25519']:
                if keytype in key_blob:
                    key = '{keytype} {keydata}'.format(
                            keytype=keytype,
                            keydata=base64.b64encode(key_blob))

            print('Key was {key}'.format(key=key))

        c = credentials.SSHPrivateKey(None,None,None,None,None)

        #self.log(key=key)

        return self.portal.login(c, None, conchinterfaces.IConchUser).addErrback(
                                                        self._ebPassword) 
开发者ID:thinkst,项目名称:opencanary,代码行数:29,代码来源:ssh.py

示例5: auth_publickey

# 需要导入模块: from twisted.cred import credentials [as 别名]
# 或者: from twisted.cred.credentials import SSHPrivateKey [as 别名]
def auth_publickey(self, packet):
        """
        Public key authentication.  Payload::
            byte has signature
            string algorithm name
            string key blob
            [string signature] (if has signature is True)

        Create a SSHPublicKey credential and verify it using our portal.
        """
        hasSig = ord(packet[0])
        algName, blob, rest = getNS(packet[1:], 2)
        pubKey = keys.Key.fromString(blob)
        signature = hasSig and getNS(rest)[0] or None
        if hasSig:
            b = (NS(self.transport.sessionID) + chr(MSG_USERAUTH_REQUEST) +
                NS(self.user) + NS(self.nextService) + NS('publickey') +
                chr(hasSig) +  NS(pubKey.sshType()) + NS(blob))
            c = credentials.SSHPrivateKey(self.user, algName, blob, b,
                    signature)
            return self.portal.login(c, None, interfaces.IConchUser)
        else:
            c = credentials.SSHPrivateKey(self.user, algName, blob, None, None)
            return self.portal.login(c, None,
                    interfaces.IConchUser).addErrback(self._ebCheckKey,
                            packet[1:]) 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:28,代码来源:userauth.py


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