redo imports

This commit is contained in:
Michel Oosterhof 2014-12-09 13:50:22 +04:00
parent 2e9a3ac1d7
commit 8e8882c5c1
1 changed files with 13 additions and 10 deletions

View File

@ -6,7 +6,11 @@ import string
from zope.interface import implementer from zope.interface import implementer
import twisted import twisted
from twisted.cred import checkers, credentials, error
from twisted.cred.checkers import ICredentialsChecker
from twisted.cred.credentials import IUsernamePassword, ISSHPrivateKey, IPluggableAuthenticationModules
from twisted.cred.error import UnauthorizedLogin, UnhandledCredentials
from twisted.internet import defer from twisted.internet import defer
from twisted.python import log, failure from twisted.python import log, failure
from twisted.conch import error from twisted.conch import error
@ -103,40 +107,39 @@ class UserDB(object):
self.userdb.append((login, uid, passwd)) self.userdb.append((login, uid, passwd))
self.save() self.save()
@implementer(checkers.ICredentialsChecker) @implementer(ICredentialsChecker)
class HoneypotPublicKeyChecker: class HoneypotPublicKeyChecker:
""" """
Checker that accepts, logs and denies public key authentication attempts Checker that accepts, logs and denies public key authentication attempts
""" """
credentialInterfaces = (credentials.ISSHPrivateKey,) credentialInterfaces = (ISSHPrivateKey,)
def requestAvatarId(self, credentials): def requestAvatarId(self, credentials):
_pubKey = keys.Key.fromString(credentials.blob) _pubKey = keys.Key.fromString(credentials.blob)
log.msg( 'Public Key attempt for user %s with fingerprint %s' % ( credentials.username, _pubKey.fingerprint() ) ) log.msg( 'Public Key attempt for user %s with fingerprint %s' % ( credentials.username, _pubKey.fingerprint() ) )
return failure.Failure(error.ConchError("Incorrect signature")) return failure.Failure(error.ConchError("Incorrect signature"))
@implementer(checkers.ICredentialsChecker) @implementer(ICredentialsChecker)
class HoneypotPasswordChecker: class HoneypotPasswordChecker:
""" """
Checker that accepts keyboard-interactive Checker that accepts keyboard-interactive
""" """
# credentialInterfaces = (credentials.IUsernamePassword, # credentialInterfaces = (IUsernamePassword, IPluggableAuthenticationModules)
# credentials.IPluggableAuthenticationModules)
credentialInterfaces = (credentials.IPluggableAuthenticationModules,) credentialInterfaces = (IPluggableAuthenticationModules,)
def requestAvatarId(self, credentials): def requestAvatarId(self, credentials):
if hasattr(credentials, 'password'): if hasattr(credentials, 'password'):
if self.checkUserPass(credentials.username, credentials.password): if self.checkUserPass(credentials.username, credentials.password):
return defer.succeed(credentials.username) return defer.succeed(credentials.username)
else: else:
return defer.fail(error.UnauthorizedLogin()) return defer.fail(UnauthorizedLogin())
elif hasattr(credentials, 'pamConversion'): elif hasattr(credentials, 'pamConversion'):
return self.checkPamUser(credentials.username, return self.checkPamUser(credentials.username,
credentials.pamConversion) credentials.pamConversion)
return defer.fail(error.UnhandledCredentials()) return defer.fail(UnhandledCredentials())
def checkPamUser(self, username, pamConversion): def checkPamUser(self, username, pamConversion):
r = pamConversion((('Password:', 1),)) r = pamConversion((('Password:', 1),))
@ -146,7 +149,7 @@ class HoneypotPasswordChecker:
for response, zero in responses: for response, zero in responses:
if self.checkUserPass(username, response): if self.checkUserPass(username, response):
return defer.succeed(username) return defer.succeed(username)
return defer.fail(error.UnauthorizedLogin()) return defer.fail(UnauthorizedLogin())
def checkUserPass(self, username, password): def checkUserPass(self, username, password):
if UserDB().checklogin(username, password): if UserDB().checklogin(username, password):