xpra icon
Bug tracker and wiki

This bug tracker and wiki are being discontinued
please use https://github.com/Xpra-org/xpra instead.


Ticket #2303: ssh-agent.patch

File ssh-agent.patch, 5.6 KB (added by Antoine Martin, 2 years ago)

try to start the AgentRequestHandler?

  • xpra/net/ssh.py

     
    188188
    189189def ssh_paramiko_connect_to(display_desc):
    190190    #plain socket attributes:
     191    ssh = display_desc.get("ssh", "paramiko")
    191192    dtype = display_desc["type"]
    192193    host = display_desc["host"]
    193194    port = display_desc.get("ssh-port", 22)
     
    206207            "host"  : host,
    207208            "port"  : port,
    208209            }
     210    forward_agent = "-A" in ssh and "-a" not in ssh
     211    log("ssh_paramiko_connect_to(%s)", display_desc)
     212    def mayforwardagent(transport, chan):
     213        if forward_agent:
     214            log("forwarding agent on %s", chan)
     215            from paramiko.agent import AgentRequestHandler
     216            AgentRequestHandler(chan)
     217            #for p in arh.__clientProxys:
     218            #    pass
     219            paramiko_run_test_command(transport, "/usr/bin/env")
     220            #paramiko_run_test_command(transport, "/usr/bin/ls")
     221
    209222    with nogssapi_context():
    210223        from paramiko import SSHConfig, ProxyCommand
    211224        ssh_config = SSHConfig()
     
    222235                port = host_config.get("port", port)
    223236                proxycommand = host_config.get("proxycommand")
    224237                keyfiles = host_config.get("identityfile")
     238                forward_agent = host_config.get("forwardagent", forward_agent)
    225239                if proxycommand:
    226240                    sock = ProxyCommand(proxycommand)
    227241                    from xpra.child_reaper import getChildReaper
     
    238252                                               host_config or ssh_config.lookup("*"),
    239253                                               keyfiles)
    240254                    chan = paramiko_run_remote_xpra(transport, proxy_command, remote_xpra, socket_dir, display_as_args)
     255                    mayforwardagent(transport, chan)
    241256                    peername = (host, port)
    242257                    conn = SSHProxyCommandConnection(chan, peername, peername, socket_info)
    243258                    conn.target = host_target_string("ssh", username, host, port, display)
     
    271286                                       keyfiles)
    272287            log("Opening proxy channel")
    273288            chan_to_middle = middle_transport.open_channel("direct-tcpip", (host, port), ('localhost', 0))
     289            mayforwardagent(middle_transport, chan_to_middle)
    274290
    275291            transport = Transport(chan_to_middle)
    276292            transport.use_compression(False)
     
    284300                                       host_config or ssh_config.lookup("*"),
    285301                                       keyfiles)
    286302            chan = paramiko_run_remote_xpra(transport, proxy_command, remote_xpra, socket_dir, display_as_args)
     303            mayforwardagent(transport, chan)
    287304
    288305            peername = (host, port)
    289306            conn = SSHProxyCommandConnection(chan, peername, peername, socket_info)
     
    312329                                   host_config or ssh_config.lookup("*"),
    313330                                   keyfiles)
    314331        chan = paramiko_run_remote_xpra(transport, proxy_command, remote_xpra, socket_dir, display_as_args)
     332        mayforwardagent(transport, chan)
    315333        conn = SSHSocketConnection(chan, sock, sockname, peername, (host, port), socket_info)
    316334        conn.target = host_target_string("ssh", username, host, port, display)
    317335        conn.timeout = SOCKET_TIMEOUT
     
    612630        raise InitException("SSH Authentication on %s failed" % host)
    613631
    614632
     633def paramiko_run_test_command(transport, cmd):
     634    from paramiko import SSHException
     635    try:
     636        chan = transport.open_session(window_size=None, max_packet_size=0, timeout=60)
     637        chan.set_name("%s" % cmd)
     638    except SSHException as e:
     639        log("open_session", exc_info=True)
     640        raise InitException("failed to open SSH session: %s" % e)
     641    log("paramiko_run_test_command('%s')", cmd)
     642    chan.exec_command(cmd)
     643    #poll until the command terminates:
     644    start = monotonic_time()
     645    stdout = []
     646    stderr = []
     647    run = True
     648    while run:
     649        if monotonic_time()-start>10:
     650            chan.close()
     651            raise InitException("SSH test command '%s' timed out" % cmd)
     652        log("exit status is not ready yet, sleeping")
     653        while chan.recv_ready():
     654            stdout.append(chan.recv(1024))
     655        while chan.recv_stderr_ready():
     656            stderr.append(chan.recv_stderr(1024))
     657        run = not chan.exit_status_ready()
     658        time.sleep(0.01)
     659    r = chan.recv_exit_status()
     660    log("exec_command('%s')=%s", cmd, r)
     661    log("stdout=%s", stdout)
     662    log("stderr=%s", stderr)
     663    chan.close()
     664
    615665def paramiko_run_remote_xpra(transport, xpra_proxy_command=None, remote_xpra=None, socket_dir=None, display_as_args=None):
    616666    from paramiko import SSHException
    617667    assert remote_xpra
  • xpra/scripts/main.py

     
    806806        #maybe restrict to win32 only?
    807807        ssh_cmd = ssh[0].lower()
    808808        is_putty = ssh_cmd.endswith("plink") or ssh_cmd.endswith("plink.exe")
    809         is_paramiko = ssh_cmd=="paramiko"
     809        is_paramiko = ssh_cmd.startswith("paramiko")
    810810        if is_paramiko:
    811811            desc["is_paramiko"] = is_paramiko
    812812        if is_putty:
     
    834834        desc.update({
    835835            "host"          : host,
    836836            "full_ssh"      : full_ssh,
     837            "ssh"           : ssh,
    837838            "remote_xpra"   : opts.remote_xpra,
    838839            })
    839840        if opts.socket_dir: