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


Python credentials.ISSHPrivateKey方法代码示例

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


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

示例1: _sanityCheckKey

# 需要导入模块: from twisted.cred import credentials [as 别名]
# 或者: from twisted.cred.credentials import ISSHPrivateKey [as 别名]
def _sanityCheckKey(self, credentials):
        """
        Checks whether the provided credentials are a valid SSH key with a
        signature (does not actually verify the signature).

        @param credentials: the credentials offered by the user
        @type credentials: L{ISSHPrivateKey} provider

        @raise ValidPublicKey: the credentials do not include a signature. See
            L{error.ValidPublicKey} for more information.

        @raise BadKeyError: The key included with the credentials is not
            recognized as a key.

        @return: the key in the credentials
        @rtype: L{twisted.conch.ssh.keys.Key}
        """
        if not credentials.signature:
            raise error.ValidPublicKey()

        return keys.Key.fromString(credentials.blob) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:23,代码来源:checkers.py

示例2: _checkKey

# 需要导入模块: from twisted.cred import credentials [as 别名]
# 或者: from twisted.cred.credentials import ISSHPrivateKey [as 别名]
def _checkKey(self, pubKey, credentials):
        """
        Checks the public key against all authorized keys (if any) for the
        user.

        @param pubKey: the key in the credentials (just to prevent it from
            having to be calculated again)
        @type pubKey:

        @param credentials: the credentials offered by the user
        @type credentials: L{ISSHPrivateKey} provider

        @raise UnauthorizedLogin: If the key is not authorized, or if there
            was any error obtaining a list of authorized keys for the user.

        @return: C{pubKey} if the key is authorized
        @rtype: L{twisted.conch.ssh.keys.Key}
        """
        if any(key == pubKey for key in
               self._keydb.getAuthorizedKeys(credentials.username)):
            return pubKey

        raise UnauthorizedLogin("Key not authorized") 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:25,代码来源:checkers.py

示例3: test_checkersPamAuth

# 需要导入模块: from twisted.cred import credentials [as 别名]
# 或者: from twisted.cred.credentials import ISSHPrivateKey [as 别名]
def test_checkersPamAuth(self):
        """
        The L{OpenSSHFactory} built by L{tap.makeService} has a portal with
        L{IPluggableAuthenticationModules}, L{ISSHPrivateKey} and
        L{IUsernamePassword} interfaces registered as checkers if C{pamauth} is
        available.
        """
        # Fake the presence of pamauth, even if PyPAM is not installed
        self.patch(tap, "pamauth", object())
        config = tap.Options()
        service = tap.makeService(config)
        portal = service.factory.portal
        self.assertEquals(
            set(portal.checkers.keys()),
            set([IPluggableAuthenticationModules, ISSHPrivateKey,
                 IUsernamePassword])) 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:18,代码来源:test_tap.py

示例4: test_isChecker

# 需要导入模块: from twisted.cred import credentials [as 别名]
# 或者: from twisted.cred.credentials import ISSHPrivateKey [as 别名]
def test_isChecker(self):
        """
        Verifies that strcred.makeChecker('sshkey') returns an object
        that implements the L{ICredentialsChecker} interface.
        """
        sshChecker = strcred.makeChecker('sshkey')
        self.assertTrue(checkers.ICredentialsChecker.providedBy(sshChecker))
        self.assertIn(
            credentials.ISSHPrivateKey, sshChecker.credentialInterfaces) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:11,代码来源:test_strcred.py

示例5: _cbRequestAvatarId

# 需要导入模块: from twisted.cred import credentials [as 别名]
# 或者: from twisted.cred.credentials import ISSHPrivateKey [as 别名]
def _cbRequestAvatarId(self, validKey, credentials):
        """
        Check whether the credentials themselves are valid, now that we know
        if the key matches the user.

        @param validKey: A boolean indicating whether or not the public key
            matches a key in the user's authorized_keys file.

        @param credentials: The credentials offered by the user.
        @type credentials: L{ISSHPrivateKey} provider

        @raise UnauthorizedLogin: (as a failure) if the key does not match the
            user in C{credentials}. Also raised if the user provides an invalid
            signature.

        @raise ValidPublicKey: (as a failure) if the key matches the user but
            the credentials do not include a signature. See
            L{error.ValidPublicKey} for more information.

        @return: The user's username, if authentication was successful.
        """
        if not validKey:
            return failure.Failure(UnauthorizedLogin("invalid key"))
        if not credentials.signature:
            return failure.Failure(error.ValidPublicKey())
        else:
            try:
                pubKey = keys.Key.fromString(credentials.blob)
                if pubKey.verify(credentials.signature, credentials.sigData):
                    return credentials.username
            except: # any error should be treated as a failed login
                log.err()
                return failure.Failure(UnauthorizedLogin('error while verifying key'))
        return failure.Failure(UnauthorizedLogin("unable to verify key")) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:36,代码来源:checkers.py

示例6: _verifyKey

# 需要导入模块: from twisted.cred import credentials [as 别名]
# 或者: from twisted.cred.credentials import ISSHPrivateKey [as 别名]
def _verifyKey(self, pubKey, credentials):
        """
        Checks whether the credentials themselves are valid, now that we know
        if the key matches the user.

        @param pubKey: the key in the credentials (just to prevent it from
            having to be calculated again)
        @type pubKey: L{twisted.conch.ssh.keys.Key}

        @param credentials: the credentials offered by the user
        @type credentials: L{ISSHPrivateKey} provider

        @raise UnauthorizedLogin: If the key signature is invalid or there
            was any error verifying the signature.

        @return: The user's username, if authentication was successful
        @rtype: L{bytes}
        """
        try:
            if pubKey.verify(credentials.signature, credentials.sigData):
                return credentials.username
        except:  # Any error should be treated as a failed login
            log.err()
            raise UnauthorizedLogin('Error while verifying key')

        raise UnauthorizedLogin("Key signature invalid.") 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:28,代码来源:checkers.py

示例7: test_checkers

# 需要导入模块: from twisted.cred import credentials [as 别名]
# 或者: from twisted.cred.credentials import ISSHPrivateKey [as 别名]
def test_checkers(self):
        """
        The L{OpenSSHFactory} built by L{tap.makeService} has a portal with
        L{ISSHPrivateKey} and L{IUsernamePassword} interfaces registered as
        checkers.
        """
        config = tap.Options()
        service = tap.makeService(config)
        portal = service.factory.portal
        self.assertEqual(
            set(portal.checkers.keys()),
            set([ISSHPrivateKey, IUsernamePassword])) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:14,代码来源:test_tap.py

示例8: test_checkersWithoutPamAuth

# 需要导入模块: from twisted.cred import credentials [as 别名]
# 或者: from twisted.cred.credentials import ISSHPrivateKey [as 别名]
def test_checkersWithoutPamAuth(self):
        """
        The L{OpenSSHFactory} built by L{tap.makeService} has a portal with
        L{ISSHPrivateKey} and L{IUsernamePassword} interfaces registered as
        checkers if C{pamauth} is not available.
        """
        # Fake the absence of pamauth, even if PyPAM is installed
        self.patch(tap, "pamauth", None)
        config = tap.Options()
        service = tap.makeService(config)
        portal = service.factory.portal
        self.assertEquals(
            set(portal.checkers.keys()),
            set([ISSHPrivateKey, IUsernamePassword])) 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:16,代码来源:test_tap.py


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