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


Python common.getNS函数代码示例

本文整理汇总了Python中twisted.conch.ssh.common.getNS函数的典型用法代码示例。如果您正苦于以下问题:Python getNS函数的具体用法?Python getNS怎么用?Python getNS使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: request_env

 def request_env(self, data):
     name, rest = getNS(data)
     value, rest = getNS(rest)
     if rest:
         raise ValueError("Bad data given in env request")
     log.msg(eventid='KIPP0013', format='request_env: %(name)s=%(value)s', name=name, value=value)
     return 0
开发者ID:andrew-morris,项目名称:cowrie,代码行数:7,代码来源:ssh.py

示例2: _parseAttributes

 def _parseAttributes(self, data):
     flags ,= struct.unpack('!L', data[:4])
     attrs = {}
     data = data[4:]
     if flags & FILEXFER_ATTR_SIZE == FILEXFER_ATTR_SIZE:
         size ,= struct.unpack('!Q', data[:8])
         attrs['size'] = size
         data = data[8:]
     if flags & FILEXFER_ATTR_OWNERGROUP == FILEXFER_ATTR_OWNERGROUP:
         uid, gid = struct.unpack('!2L', data[:8])
         attrs['uid'] = uid
         attrs['gid'] = gid
         data = data[8:]
     if flags & FILEXFER_ATTR_PERMISSIONS == FILEXFER_ATTR_PERMISSIONS:
         perms ,= struct.unpack('!L', data[:4])
         attrs['permissions'] = perms
         data = data[4:]
     if flags & FILEXFER_ATTR_ACMODTIME == FILEXFER_ATTR_ACMODTIME:
         atime, mtime = struct.unpack('!2L', data[:8])
         attrs['atime'] = atime
         attrs['mtime'] = mtime
         data = data[8:]
     if flags & FILEXFER_ATTR_EXTENDED == FILEXFER_ATTR_EXTENDED:
         extended_count ,= struct.unpack('!L', data[:4])
         data = data[4:]
         for i in xrange(extended_count):
             extended_type, data = getNS(data)
             extended_data, data = getNS(data)
             attrs['ext_%s' % extended_type] = extended_data
     return attrs, data
开发者ID:12019,项目名称:OpenWrt_Luci_Lua,代码行数:30,代码来源:filetransfer.py

示例3: request_env

    def request_env(self, data):
	name, rest = getNS(data)
	value, rest = getNS(rest)
	if rest:
	    raise ValueError("Bad data given in env request")
	log.msg('request_env: %s=%s' % (name, value) )
	return 0
开发者ID:localh0rzd,项目名称:kippo,代码行数:7,代码来源:ssh.py

示例4: auth_publickey

 def auth_publickey(self, packet):
     # This is copied and pasted from twisted/conch/ssh/userauth.py in
     # Twisted 8.0.1. We do this so we can customize how the credentials
     # are built and pass a mind to self.portal.login.
     hasSig = ord(packet[0])
     algName, blob, rest = getNS(packet[1:], 2)
     pubKey = keys.Key.fromString(blob).keyObject
     signature = hasSig and getNS(rest)[0] or None
     if hasSig:
         b = (
             NS(self.transport.sessionID)
             + chr(userauth.MSG_USERAUTH_REQUEST)
             + NS(self.user)
             + NS(self.nextService)
             + NS("publickey")
             + chr(hasSig)
             + NS(keys.objectType(pubKey))
             + NS(blob)
         )
         # The next three lines are different from the original.
         c = self.makePublicKeyCredentials(self.user, algName, blob, b, signature)
         return self.portal.login(c, self.getMind(), IConchUser)
     else:
         # The next four lines are different from the original.
         c = self.makePublicKeyCredentials(self.user, algName, blob, None, None)
         return self.portal.login(c, self.getMind(), IConchUser).addErrback(self._ebCheckKey, packet[1:])
开发者ID:vitaminmoo,项目名称:unnaturalcode,代码行数:26,代码来源:auth.py

示例5: auth_publickey

    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:JohnDoes95,项目名称:project_parser,代码行数:34,代码来源:userauth.py

示例6: verify

    def verify(self, signature, data):
        """
        Returns true if the signature for data is valid for this Key.

        @type signature: C{str}
        @type data: C{str}
        @rtype: C{bool}
        """
        if len(signature) == 40:
            # DSA key with no padding
            signatureType, signature = 'ssh-dss', common.NS(signature)
        else:
            signatureType, signature = common.getNS(signature)
        if signatureType != self.sshType():
            return False
        if self.type() == 'RSA':
            numbers = common.getMP(signature)
            digest = pkcs1Digest(data, self.keyObject.size() / 8)
        elif self.type() == 'DSA':
            signature = common.getNS(signature)[0]
            numbers = [
                Util.number.bytes_to_long(n) for n in
                    (signature[:20], signature[20:])
                ]
            digest = sha1(data).digest()
        return self.keyObject.verify(digest, numbers)
开发者ID:ssilverek,项目名称:kodb,代码行数:26,代码来源:keys.py

示例7: auth_publickey

    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:timkrentz,项目名称:SunTracker,代码行数:26,代码来源:userauth.py

示例8: ssh_USERAUTH_PK_OK

 def ssh_USERAUTH_PK_OK(self, packet):
     if self.lastAuth == 'publickey':
         # this is ok
         publicKey = self.lastPublicKey
         keyType =  getNS(publicKey)[0]
         b = NS(self.transport.sessionID) + chr(MSG_USERAUTH_REQUEST) + \
         NS(self.user) + NS(self.instance.name) + NS('publickey') + '\xff' +\
         NS(keyType) + NS(publicKey)
         d  = self.signData(publicKey, b)
         if not d:
             self.askForAuth('none', '')
             # this will fail, we'll move on
             return
         d.addCallback(self._cbSignedData)
         d.addErrback(self._ebAuth)
     elif self.lastAuth == 'password':
         prompt, language, rest = getNS(packet, 2)
         self._oldPass = self._newPass = None
         self.getPassword('Old Password: ').addCallbacks(self._setOldPass, self._ebAuth)
         self.getPassword(prompt).addCallbacks(self._setNewPass, self._ebAuth)
     elif self.lastAuth == 'keyboard-interactive':
         name, instruction, lang, data = getNS(packet, 3)
         numPrompts = struct.unpack('!L', data[:4])[0]
         data = data[4:]
         prompts = []
         for i in range(numPrompts):
             prompt, data = getNS(data)
             echo = bool(ord(data[0]))
             data = data[1:]
             prompts.append((prompt, echo))
         d = self.getGenericAnswers(name, instruction, prompts)
         d.addCallback(self._cbGenericAnswers)
         d.addErrback(self._ebAuth)
开发者ID:clayball,项目名称:hector,代码行数:33,代码来源:userauth.py

示例9: auth_publickey

    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:beelives,项目名称:opencanary,代码行数:27,代码来源:ssh.py

示例10: packet_SYMLINK

 def packet_SYMLINK(self, data):
     requestId = data[:4]
     data = data[4:]
     linkPath, data = getNS(data)
     targetPath, data = getNS(data)
     d = defer.maybeDeferred(self.client.makeLink, linkPath, targetPath)
     d.addCallback(self._cbStatus, requestId, 'symlink succeeded')
     d.addErrback(self._ebStatus, requestId, 'symlink failed')
开发者ID:12019,项目名称:OpenWrt_Luci_Lua,代码行数:8,代码来源:filetransfer.py

示例11: unpackOpen_direct_tcpip

def unpackOpen_direct_tcpip(data):
    """Unpack the data to a usable format.
    """
    connHost, rest = common.getNS(data)
    connPort = int(struct.unpack('>L', rest[:4])[0])
    origHost, rest = common.getNS(rest[4:])
    origPort = int(struct.unpack('>L', rest[:4])[0])
    return (connHost, connPort), (origHost, origPort)
开发者ID:alfonsjose,项目名称:international-orders-app,代码行数:8,代码来源:forwarding.py

示例12: packet_RENAME

 def packet_RENAME(self, data):
     requestId = data[:4]
     data = data[4:]
     oldPath, data = getNS(data)
     newPath, data = getNS(data)
     assert data == '', 'still have data in RENAME: %s' % repr(data)
     d = defer.maybeDeferred(self.client.renameFile, oldPath, newPath)
     d.addCallback(self._cbStatus, requestId, "rename succeeded")
     d.addErrback(self._ebStatus, requestId, "rename failed")
开发者ID:12019,项目名称:OpenWrt_Luci_Lua,代码行数:9,代码来源:filetransfer.py

示例13: packet_HANDLE

 def packet_HANDLE(self, data):
     d, data = self._parseRequest(data)
     isFile, name = self.wasAFile.pop(d)
     if isFile:
         cb = ClientFile(self, getNS(data)[0])
     else:
         cb = ClientDirectory(self, getNS(data)[0])
     cb.name = name
     d.callback(cb)
开发者ID:12019,项目名称:OpenWrt_Luci_Lua,代码行数:9,代码来源:filetransfer.py

示例14: packet_VERSION

 def packet_VERSION(self, data):
     version, = struct.unpack('!L', data[:4])
     data = data[4:]
     d = {}
     while data:
         k, data = getNS(data)
         v, data = getNS(data)
         d[k]=v
     self.version = version
     self.gotServerVersion(version, d)
开发者ID:12019,项目名称:OpenWrt_Luci_Lua,代码行数:10,代码来源:filetransfer.py

示例15: parseRequest_pty_req

def parseRequest_pty_req(data):
    """Parse the data from a pty-req request into usable data.

    @returns: a tuple of (terminal type, (rows, cols, xpixel, ypixel), modes)
    """
    term, rest = common.getNS(data)
    cols, rows, xpixel, ypixel = struct.unpack('>4L', rest[: 16])
    modes, ignored= common.getNS(rest[16:])
    winSize = (rows, cols, xpixel, ypixel)
    modes = [(ord(modes[i]), struct.unpack('>L', modes[i+1: i+5])[0]) for i in range(0, len(modes)-1, 5)]
    return term, winSize, modes
开发者ID:AnthonyNystrom,项目名称:YoGoMee,代码行数:11,代码来源:session.py


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