Example #1
0
    def setUpClass(self):
        if hasattr(self, 'skip'):
            return
        test_process.SignalMixin.setUpClass(self)
        CFTPClientTestBase.setUpClass(self)
        self.startServer()
        cmd1 = ('-p %i -l testuser '
                '--known-hosts kh_test '
                '--host-key-algorithms ssh-rsa '
                '-a '
                '-K direct '
                '-i dsa_test '
                '127.0.0.1')
        port = self.server.getHost().port
        cmds1 = (cmd1 % port).split()
        o = options.ConchOptions()

        def _(host, *args):
            o['host'] = host

        o.parseArgs = _
        o.parseOptions(cmds1)
        vhk = default.verifyHostKey
        self.conn = conn = test_conch.SSHTestConnectionForUnix(None)
        uao = default.SSHUserAuthClient(o['user'], o, conn)
        return connect.connect(o['host'], int(o['port']), o, vhk, uao)
Example #2
0
    def execute(self, args, p, preargs=''):
        if runtime.platformType == 'win32':
            raise unittest.SkipTest, "can't run cmdline client on win32"
        port = self.server.getHost().port
        cmd1 = ('-p %i -l testuser '
                '--known-hosts kh_test '
                '--user-authentications publickey '
                '--host-key-algorithms ssh-rsa '
                '-a '
                '-K direct '
                '-i dsa_test '
                '127.0.0.1') % port
        cmd2 = ('-p %i -l testuser '
                '-K unix '
                '-v ') % port + preargs + \
                ' 127.0.0.1 ' + args
        cmds1 = cmd1.split()
        cmds2 = _makeArgs(cmd2.split())
        o = options.ConchOptions()

        def _(host, *args):
            o['host'] = host

        o.parseArgs = _
        o.parseOptions(cmds1)
        vhk = default.verifyHostKey
        conn = SSHTestConnectionForUnix(p, sys.executable, cmds2)
        uao = default.SSHUserAuthClient(o['user'], o, conn)
        d = connect.connect(o['host'], int(o['port']), o, vhk, uao)
        d.addErrback(lambda f: unittest.fail(
            'Failure connecting to test server: %s' % f))
        d.addCallback(lambda x: p.deferred)
        d.addCallback(lambda x: defer.maybeDeferred(conn.transport.transport.
                                                    loseConnection))
        return d
Example #3
0
    def connectConsole(console, user=None, host='127.0.0.1', port=9000):
        opts = options.ConchOptions()
        opts.parseOptions([])
        opts['host'] = host
        opts['port'] = port
        if user is None:
            user = getpass.getuser()
        conn = SSHConnection(console)
        userauth = default.SSHUserAuthClient(user, opts, conn)

        def eb(reason):
            log.err(reason)
            console.writeHelp('failed connecting to remote: %s' % reason)

        log.msg('connecting')

        def verifyHostKey(transport, host, pubKey, fingerprint):
            log.msg('verifying host key')
            actualHost = transport.factory.options['host']
            actualKey = keys.Key.fromString(pubKey)
            kh = KnownHostsFile.fromPath(
                FilePath(transport.factory.options['known-hosts']
                         or os.path.expanduser('~/.ssh/known_hosts')))
            return kh.verifyHostKey(console, actualHost, host,
                                    actualKey).addErrback(log.err)

        connect.connect(host, port, opts, verifyHostKey,
                        userauth).addErrback(eb)
        return conn
Example #4
0
    def _build_conch_options(self):
        """Verify and construct the ssh (conch) option object
        
        This is just a dictionary like object that options the twisted ssh implementation uses.
        """
        ssh_options = options.ConchOptions()
        if not hasattr(self, 'agent'):
            ssh_options['noagent'] = True
        else:
            if 'SSH_AUTH_SOCK' in os.environ:
                ssh_options['agent'] = True
            else:
                raise Error("No SSH Agent available ($SSH_AUTH_SOCK)")

        if hasattr(self, "identities"):
            for file_name in self.identities:
                file_path = os.path.expanduser(file_name)
                if not os.path.exists(file_path):
                    raise Error("Private key file %s doesn't exist" % file_name)
                if not os.path.exists(file_path + ".pub"):
                    raise Error("Public key %s doesn't exist" % (file_name + ".pub"))
            
                ssh_options.opt_identity(file_name)
        
        return ssh_options
Example #5
0
    def makeOptions(self):
        o = options.ConchOptions()

        def parseArgs(host, *args):
            o['host'] = host

        o.parseArgs = parseArgs
        return o
Example #6
0
 def connectionSecure(self):
     opts = options.ConchOptions()
     self.conn = SimpleSSHConnection(self.suite)
     self.requestService(ClientUserAuth(self.user, opts, self.conn))