summaryrefslogtreecommitdiff
path: root/login.py
blob: a39ffd30736d09fe4873c06e361afb10d5ee4aad (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
26
27
28
29
30
31
from twisted.cred import portal, checkers
from twisted.conch import manhole, manhole_ssh
from twisted.conch.ssh import keys
from twisted.python import filepath
import hashlib
import os

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))

	factory = manhole_ssh.ConchFactory(p)
	ssh_key = keys._getPersistentRSAKey(filepath.FilePath(os.path.expanduser('~/.fot.ssh')).child('id_rsa'), 2048)
	factory.publicKeys[b'ssh-rsa'] = ssh_key
	factory.privateKeys[b'ssh-rsa'] = ssh_key
	return factory

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