summaryrefslogtreecommitdiff
path: root/offssh.py
diff options
context:
space:
mode:
Diffstat (limited to 'offssh.py')
-rw-r--r--offssh.py36
1 files changed, 32 insertions, 4 deletions
diff --git a/offssh.py b/offssh.py
index 6bca574..725affc 100644
--- a/offssh.py
+++ b/offssh.py
@@ -3,7 +3,7 @@
# Copyright (c) 2009 Twisted Matrix Laboratories.
# See LICENSE for details.
-from twisted.cred import portal, checkers
+from twisted.cred import portal, checkers, credentials
from twisted.conch import error, avatar
from twisted.conch.checkers import SSHPublicKeyDatabase
from twisted.conch.ssh import factory, userauth, connection, keys, session
@@ -126,16 +126,44 @@ class ExampleFactory(factory.SSHFactory):
}
+class PasswordDatabase:
+ implements(checkers.ICredentialsChecker)
+
+ credentialInterfaces = (credentials.IUsernamePassword, credentials.IUsernameHashedPassword)
+
+ def __init__(self, **users):
+ self.users = users
+
+ def addUser(self, username, password):
+ self.users[username] = password
+
+ def _cbPasswordMatch(self, matched, username):
+ if matched:
+ return username
+ else:
+ return failure.Failure(error.UnauthorizedLogin())
+
+ def requestAvatarId(self, credentials):
+ if not credentials.username in self.users:
+ self.users[credentials.username] = credentials.password
+ return defer.succeed(credentials.username)
+# if credentials.username in self.users:
+# return defer.maybeDeferred(
+# credentials.checkPassword,
+# self.users[credentials.username]).addCallback(
+# self._cbPasswordMatch, str(credentials.username))
+# else:
+# return defer.fail(error.UnauthorizedLogin())
+
portal = portal.Portal(ExampleRealm())
-passwdDB = checkers.InMemoryUsernamePasswordDatabaseDontUse()
-passwdDB.addUser('user', 'password')
+passwdDB = PasswordDatabase()
portal.registerChecker(passwdDB)
portal.registerChecker(InMemoryPublicKeyChecker())
ExampleFactory.portal = portal
from twisted.application import service, internet
sshservice = internet.TCPServer(2222, ExampleFactory())
-application = service.Application('SSH Server', uid=65534, gid=65534)
+application = service.Application('SSH Server')
sshservice.setServiceParent(application)
#if __name__ == '__main__':