Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Twisted ssh server authentication using keys

Here is a simple twisted application:

from twisted.cred import checkers, portal
from twisted.conch import manhole, manhole_ssh
from twisted.conch.insults import insults

from twisted.application import service, internet
from twisted.internet import endpoints, reactor


def makeManholeService(namespace):
    checker = checkers.InMemoryUsernamePasswordDatabaseDontUse(
        username="password")

    realm = manhole_ssh.TerminalRealm()
    realm.chainedProtocolFactory = lambda: insults.ServerProtocol(
                                        manhole.ColoredManhole, namespace)
    prt = portal.Portal(realm, [checker])
    factory = manhole_ssh.ConchFactory(prt)

    endp = endpoints.serverFromString(reactor, 'tcp:6022')

    manholeService = internet.StreamServerEndpointService(endp, factory)
    return manholeService


application = service.Application("my app")
manholeService = makeManholeService({'foo': 'bar'})
manholeService.setServiceParent(application)

We can connect to it with ssh:

$ ssh username@localhost -p 6022
username@localhost's password:

>>> foo
'bar'
>>>

Now I want to replace InMemoryUsernamePasswordDatabaseDontUse such that the server can authenticate users, who identify themselves using rsa/dsa keys.

Do I have to implement a checker?

For example, I have some public keys listed in ~/.ssh/authorized_keys. The SSH server should reject all connections, except those that can be verified using public keys in that file.

like image 891
Maxim Avatar asked Oct 21 '25 20:10

Maxim


1 Answers

Yes, you need to make a checker. But there are building blocks you can use within Conch that should make it pretty easy. Ying Li has an example project, "ess" ("SSH" without the "SH") that implements some checkers that you might be interested in checking out.

like image 107
Glyph Avatar answered Oct 23 '25 11:10

Glyph



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!