Example #1
0
 def test_registerChecker(self):
     """
     L{SSHProcotolChecker.registerChecker} should add the given checker to
     the list of registered checkers.
     """
     checker = checkers.SSHProtocolChecker()
     self.assertEqual(checker.credentialInterfaces, [])
     checker.registerChecker(checkers.SSHPublicKeyDatabase(), )
     self.assertEqual(checker.credentialInterfaces, [ISSHPrivateKey])
     self.assertIsInstance(checker.checkers[ISSHPrivateKey],
                           checkers.SSHPublicKeyDatabase)
Example #2
0
    def __init__(self, *a, **kw):
        usage.Options.__init__(self, *a, **kw)

        # call the default addCheckers (for backwards compatibility) that will
        # be used if no --auth option is provided - note that conch's
        # UNIXPasswordDatabase is used, instead of twisted.plugins.cred_unix's
        # checker
        super(Options, self).addChecker(conch_checkers.UNIXPasswordDatabase())
        super(Options, self).addChecker(conch_checkers.SSHPublicKeyDatabase())
        if pamauth is not None:
            super(Options, self).addChecker(
                checkers.PluggableAuthenticationModulesChecker())
Example #3
0
 def test_registerCheckerWithInterface(self):
     """
     If a apecific interface is passed into
     L{SSHProtocolChecker.registerChecker}, that interface should be
     registered instead of what the checker specifies in
     credentialIntefaces.
     """
     checker = checkers.SSHProtocolChecker()
     self.assertEqual(checker.credentialInterfaces, [])
     checker.registerChecker(checkers.SSHPublicKeyDatabase(),
                             IUsernamePassword)
     self.assertEqual(checker.credentialInterfaces, [IUsernamePassword])
     self.assertIsInstance(checker.checkers[IUsernamePassword],
                           checkers.SSHPublicKeyDatabase)
Example #4
0
def makeService(config):
    t = factory.OpenSSHFactory()
    t.portal = portal.Portal(unix.UnixSSHRealm())
    t.portal.registerChecker(checkers.UNIXPasswordDatabase())
    t.portal.registerChecker(checkers.SSHPublicKeyDatabase())
    if pamauth is not None:
        from twisted.cred.checkers import PluggableAuthenticationModulesChecker
        t.portal.registerChecker(PluggableAuthenticationModulesChecker())
    t.dataRoot = config['data']
    t.moduliRoot = config['moduli'] or config['data']
    port = config['port']
    if config['interface']:
        # Add warning here
        port += ':interface=' + config['interface']
    return strports.service(port, t)
Example #5
0
    def setUp(self):
        self.checker = checkers.SSHPublicKeyDatabase()
        self.key1 = base64.encodestring("foobar")
        self.key2 = base64.encodestring("eggspam")
        self.content = "t1 %s foo\nt2 %s egg\n" % (self.key1, self.key2)

        self.mockos = MockOS()
        self.mockos.path = FilePath(self.mktemp())
        self.mockos.path.makedirs()
        self.patch(util, 'os', self.mockos)
        self.sshDir = self.mockos.path.child('.ssh')
        self.sshDir.makedirs()

        userdb = UserDatabase()
        userdb.addUser('user', 'password', 1, 2, 'first last',
                       self.mockos.path.path, '/bin/shell')
        self.checker._userdb = userdb
Example #6
0
    def setUp(self):
        self.checker = checkers.SSHPublicKeyDatabase()
        self.key1 = _b64encodebytes(b"foobar")
        self.key2 = _b64encodebytes(b"eggspam")
        self.content = (b"t1 " + self.key1 + b" foo\nt2 " + self.key2 +
                        b" egg\n")

        self.mockos = MockOS()
        self.mockos.path = FilePath(self.mktemp())
        self.mockos.path.makedirs()
        self.patch(util, 'os', self.mockos)
        self.sshDir = self.mockos.path.child('.ssh')
        self.sshDir.makedirs()

        userdb = UserDatabase()
        userdb.addUser(b'user', b'password', 1, 2, b'first last',
                       self.mockos.path.path, b'/bin/shell')
        self.checker._userdb = userdb
Example #7
0
    def __init__(self):
        TCPApplication.__init__(self)
        _ConsumerMixin.__init__(self)

        #t = factory.OpenSSHFactory()
        t = MyFactory()  #Use my factory instead of the original one
        t.portal = portal.Portal(unix.UnixSSHRealm(
        ))  #Instanciate all the needed stuff to create to protocol
        t.portal.registerChecker(checkers.UNIXPasswordDatabase())
        t.portal.registerChecker(checkers.SSHPublicKeyDatabase())
        if checkers.pamauth:
            t.portal.registerChecker(
                chk.PluggableAuthenticationModulesChecker())
        t.dataRoot = '/etc/ssh'
        t.moduliRoot = '/etc/ssh'

        t.startFactory()
        self.app = t.buildProtocol("lala")
        self.app.transport = self
Example #8
0
def manhole_service(opts):
    """
    Create a manhole server service.
    """

    svc = service.MultiService()

    namespace = opts['namespace']
    if namespace is None:
        namespace = {}

    checker = checkers.SSHPublicKeyDatabase()

    if opts['ssh']:
        sshRealm = manhole_ssh.TerminalRealm()
        sshRealm.chainedProtocolFactory = ChainedProtocolFactory(namespace)

        sshPortal = portal.Portal(sshRealm, [checker])
        f = manhole_ssh.ConchFactory(sshPortal)
        csvc = internet.TCPServer(opts['ssh'], f)
        csvc.setServiceParent(svc)

    return svc
Example #9
0
    def sshServer(self):

        from twisted.conch import checkers, unix
        from twisted.conch.openssh_compat import factory
        from twisted.cred import portal
        from twisted.python import usage
        from twisted.application import strports

        t = factory.OpenSSHFactory()
        t.portal = portal.Portal(unix.UnixSSHRealm())
        t.portal.registerChecker(checkers.UNIXPasswordDatabase())
        t.portal.registerChecker(checkers.SSHPublicKeyDatabase())
        if checkers.pamauth:
            t.portal.registerChecker(
                checkers.PluggableAuthenticationModulesChecker())
        t.dataRoot = '/etc/ssh'
        t.moduliRoot = '/etc/ssh'

        t.startFactory()
        self.app = t.buildProtocol("lala")
        self.app.transport = self

        self.app.connectionMade()
Example #10
0
    def setUp(self):
        self.checker = checkers.SSHPublicKeyDatabase()
        self.key1 = encodebytes(b"foobar")
        self.key2 = encodebytes(b"eggspam")
        self.content = b"t1 " + self.key1 + b" foo\nt2 " + self.key2 + b" egg\n"

        self.mockos = MockOS()
        self.mockos.path = FilePath(self.mktemp())
        self.mockos.path.makedirs()
        self.patch(util, "os", self.mockos)
        self.sshDir = self.mockos.path.child(".ssh")
        self.sshDir.makedirs()

        userdb = UserDatabase()
        userdb.addUser(
            b"user",
            b"password",
            1,
            2,
            b"first last",
            self.mockos.path.path,
            b"/bin/shell",
        )
        self.checker._userdb = userdb