summaryrefslogtreecommitdiff
path: root/login.py
blob: 6c95e56518a0ccbafc24d2a24fce0d28a79f22ad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
from twisted.cred import portal, checkers
from twisted.conch import manhole, manhole_ssh
import hashlib

def hash(username, netpass, localpass):
	return hashlib.sha1(netpass).hexdigest()

def getManholeFactory(namespace, filename):
	def getManhole(_):
		return manhole.Manhole(namespace)

	realm = manhole_ssh.TerminalRealm()
	realm.chainedProtocolFactory.protocolFactory = getManhole

	p = portal.Portal(realm)
	p.registerChecker(checkers.FilePasswordDB(filename, hash = hash))

	return manhole_ssh.ConchFactory(p)

if __name__ == '__main__':
	from twisted.internet import reactor
	import os
	factory = getManholeFactory({'x': 'foo'}, os.path.expanduser('~/.fot.users'))
	reactor.listenTCP(5022, factory)
	reactor.run()