Esempio n. 1
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
Esempio n. 2
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
Esempio n. 3
0
def openSFTP(user, host):
    conn = SFTPConnection()
    options = ConchOptions()
    options['host'], options['port'] = host
    conn._sftp = Deferred()
    auth = SimpleUserAuth(user, conn)
    connect(options['host'], options['port'], options, verifyHostKey, auth)
    return conn._sftp
Esempio n. 4
0
def sftp(user, host, port):
    options = ClientOptions()
    options['host'] = host
    options['port'] = port
    conn = SFTPConnection()
    conn._sftp = Deferred()
    auth = ClientUserAuth(user, options, conn)
    connect(host, port, options, verifyHostKey, auth)
    return conn._sftp
Esempio n. 5
0
 def acquireConnection(self, user, password, host, port):
     options = ClientOptions()
     options['user'] = user
     options['password'] = password
     options['host'] = host
     options['port'] = port
     conn = SFTPConnection()
     conn._sftp = Deferred()
     auth = SFTPUserAuthClient(user, options, conn)
     connect(host, port, options, verifyHostKey, auth)
     return conn._sftp
Esempio n. 6
0
 def acquireConnection(self, user, password, host, port):
     options = ClientOptions()
     options['user'] = user
     options['password'] = password
     options['host'] = host
     options['port'] = port
     conn = SFTPConnection()
     conn._sftp = Deferred()
     auth = SFTPUserAuthClient(user, options, conn)
     connect(host, port, options, verifyHostKey, auth)
     return conn._sftp
Esempio n. 7
0
def sftp(user, host, port):
    options = ClientOptions()
    options['host'] = host
    options['port'] = port
    options.identitys = ['~/.ssh/amazon.pem']

    conn = SFTPConnection()
    conn._sftp = Deferred()
    auth = SSHUserAuthClient(user, options, conn)
    connect(host, port, options, verifyHostKey, auth)
    return conn._sftp
Esempio n. 8
0
def sftp(user, host, port):
    options = ClientOptions()
    options['host'] = host
    options['port'] = port
    options.identitys = ['~/.ssh/amazon.pem']

    conn = SFTPConnection()
    conn._sftp = Deferred()
    auth = SSHUserAuthClient(user, options, conn)
    connect(host, port, options, verifyHostKey, auth)
    return conn._sftp
Esempio n. 9
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
Esempio n. 10
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)
Esempio n. 11
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)
Esempio n. 12
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
Esempio n. 13
0
    def connect_sftp(self):
        conn = SFTPConnection()
        self.conn = conn
        conn._sftp = Deferred()
        options = ClientOptions()
        options['host'] = self.host
        options['port'] = self.port

        log.msg("self.host", self.host, logLevel=logging.DEBUG)
        log.msg("self.port", self.port, logLevel=logging.DEBUG)
        log.msg("self.user", self.user, logLevel=logging.DEBUG)

        self.auth = SSHUserAuthClient(self.user, options, conn)
        connect(self.host, self.port, options, verifyHostKey, self.auth)
        self._sftp = conn._sftp
        return self._sftp
Esempio n. 14
0
def doConnect(options):
    if "@" in options["host"]:
        options["user"], options["host"] = options["host"].split("@", 1)
    host = options["host"]
    if not options["user"]:
        options["user"] = getpass.getuser()
    if not options["port"]:
        options["port"] = 22
    else:
        options["port"] = int(options["port"])
    host = options["host"]
    port = options["port"]
    conn = SSHConnection()
    conn.options = options
    vhk = default.verifyHostKey
    uao = default.SSHUserAuthClient(options["user"], options, conn)
    connect.connect(host, port, options, vhk, uao).addErrback(_ebExit)
Esempio n. 15
0
def doConnect(options):
    if '@' in options['host']:
        options['user'], options['host'] = options['host'].split('@', 1)
    host = options['host']
    if not options['user']:
        options['user'] = getpass.getuser()
    if not options['port']:
        options['port'] = 22
    else:
        options['port'] = int(options['port'])
    host = options['host']
    port = options['port']
    conn = SSHConnection()
    conn.options = options
    vhk = default.verifyHostKey
    uao = default.SSHUserAuthClient(options['user'], options, conn)
    connect.connect(host, port, options, vhk, uao).addErrback(_ebExit)
Esempio n. 16
0
def doConnect():
#    log.deferr = handleError # HACK
    if '@' in options['host']:
        options['user'], options['host'] = options['host'].split('@',1)
    if not options.identitys:
        options.identitys = ['~/.ssh/id_rsa', '~/.ssh/id_dsa']
    host = options['host']
    if not options['user']:
        options['user'] = getpass.getuser()
    if not options['port']:
        options['port'] = 22
    else:
        options['port'] = int(options['port'])
    host = options['host']
    port = options['port']
    vhk = default.verifyHostKey
    uao = default.SSHUserAuthClient(options['user'], options, SSHConnection())
    connect.connect(host, port, options, vhk, uao).addErrback(_ebExit)
Esempio n. 17
0
def doConnect(options):
#    log.deferr = handleError # HACK
    if '@' in options['host']:
        options['user'], options['host'] = options['host'].split('@',1)
    host = options['host']
    if not options['user']:
        options['user'] = getpass.getuser() 
    if not options['port']:
        options['port'] = 22
    else:
        options['port'] = int(options['port'])
    host = options['host']
    port = options['port']
    conn = SSHConnection()
    conn.options = options
    vhk = default.verifyHostKey
    uao = default.SSHUserAuthClient(options['user'], options, conn)
    connect.connect(host, port, options, vhk, uao).addErrback(_ebExit)
Esempio n. 18
0
def doConnect():
#    log.deferr = handleError # HACK
    if '@' in options['host']:
        options['user'], options['host'] = options['host'].split('@',1)
    if not options.identitys:
        options.identitys = ['~/.ssh/id_rsa', '~/.ssh/id_dsa']
    host = options['host']
    if not options['user']:
        options['user'] = getpass.getuser()
    if not options['port']:
        options['port'] = 22
    else:
        options['port'] = int(options['port'])
    host = options['host']
    port = options['port']
    vhk = default.verifyHostKey
    uao = default.SSHUserAuthClient(options['user'], options, SSHConnection())
    connect.connect(host, port, options, vhk, uao).addErrback(_ebExit)
Esempio n. 19
0
def doConnect():
    if "@" in options["host"]:
        options["user"], options["host"] = options["host"].split("@", 1)
    if not options.identitys:
        options.identitys = ["~/.ssh/id_rsa", "~/.ssh/id_dsa"]
    host = options["host"]
    if not options["user"]:
        options["user"] = getpass.getuser()
    if not options["port"]:
        options["port"] = 22
    else:
        options["port"] = int(options["port"])
    host = options["host"]
    port = options["port"]
    vhk = default.verifyHostKey
    if not options["host-key-algorithms"]:
        options["host-key-algorithms"] = default.getHostKeyAlgorithms(
            host, options)
    uao = default.SSHUserAuthClient(options["user"], options, SSHConnection())
    connect.connect(host, port, options, vhk, uao).addErrback(_ebExit)
Esempio n. 20
0
def doConnect():
    if '@' in options['host']:
        options['user'], options['host'] = options['host'].split('@', 1)
    if not options.identitys:
        options.identitys = ['~/.ssh/id_rsa', '~/.ssh/id_dsa']
    host = options['host']
    if not options['user']:
        options['user'] = getpass.getuser()
    if not options['port']:
        options['port'] = 22
    else:
        options['port'] = int(options['port'])
    host = options['host']
    port = options['port']
    vhk = default.verifyHostKey
    if not options['host-key-algorithms']:
        options['host-key-algorithms'] = default.getHostKeyAlgorithms(
            host, options)
    uao = default.SSHUserAuthClient(options['user'], options, SSHConnection())
    connect.connect(host, port, options, vhk, uao).addErrback(_ebExit)
Esempio n. 21
0
def doSFTPConnect(host, port=22, user="******", pubkey=None, privkey=None):
    options = ClientOptions()
    options["host"] = host
    options["port"] = port
    options["pubkey"] = pubkey
    options["privkey"] = privkey
    conn = SFTPConnection()
    conn._sftp = defer.Deferred()
    auth = SSHUserAuthClient(user, options, conn)
    yield connect(host, port, options, verifyHostKey, auth)
    server_conn, server_client = yield conn._sftp
    sftp_client = SftpClient(server_conn, server_client)
    defer.returnValue(sftp_client)
Esempio n. 22
0
 def execute(self, remoteCommand, process, sshArgs=''):
     """
     Connect to the forwarding process using the 'unix' client found in
     L{twisted.conch.client.unix.connect}.  See
     L{OpenSSHClientTestCase.execute}.
     """
     process.deferred = defer.Deferred()
     port = self.conchServer.getHost().port
     cmd = ('-p %i -l testuser '
            '-K unix '
            '-v ') % port + sshArgs + \
            ' 127.0.0.1 ' + remoteCommand
     cmds = _makeArgs(cmd.split())
     options = self.makeOptions()
     self.conn = SSHTestConnectionForUnix(process, sys.executable, cmds)
     authClient = self.makeAuthClient(port, options)
     d = connect.connect(options['host'], port, options,
                         default.verifyHostKey, authClient)
     return d.addCallback(lambda x : process.deferred)
Esempio n. 23
0
 def execute(self, remoteCommand, process, sshArgs=''):
     """
     Connect to the forwarding process using the 'unix' client found in
     L{twisted.conch.client.unix.connect}.  See
     L{OpenSSHClientTestCase.execute}.
     """
     process.deferred = defer.Deferred()
     port = self.conchServer.getHost().port
     cmd = ('-p %i -l testuser '
            '-K unix '
            '-v ') % port + sshArgs + \
            ' 127.0.0.1 ' + remoteCommand
     cmds = _makeArgs(cmd.split())
     options = self.makeOptions()
     self.conn = SSHTestConnectionForUnix(process, sys.executable, cmds)
     authClient = self.makeAuthClient(port, options)
     d = connect.connect(options['host'], port, options,
                         default.verifyHostKey, authClient)
     return d.addCallback(lambda x: process.deferred)