xpra icon
Bug tracker and wiki

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


Ticket #2041: ssh-2hop-splitconnect.patch

File ssh-2hop-splitconnect.patch, 4.4 KB (added by Antoine Martin, 3 years ago)

splits the connect function and the channel opening

  • xpra/net/ssh.py

     
    240240                    ssh_client = SSHClient()
    241241                    ssh_client.load_system_host_keys()
    242242                    ssh_client.connect(host, port, sock=sock)
    243                     chan = do_ssh_paramiko_connect_to(ssh_client.get_transport(),
    244                                                       host, username, password,
    245                                                       proxy_command, remote_xpra, socket_dir, display_as_args)
     243                    transport = ssh_client.get_transport()
     244                    do_ssh_paramiko_connect_to(transport, host, username, password)
     245                    chan = paramiko_run_remote_xpra(transport, proxy_command, remote_xpra, socket_dir, display_as_args)
    246246                    peername = (host, port)
    247247                    conn = SSHProxyCommandConnection(chan, peername, target, socket_info)
    248248                    conn.timeout = SOCKET_TIMEOUT
     
    269269            except SSHException as e:
    270270                log("start_client()", exc_info=True)
    271271                raise InitException("SSH negotiation failed: %s" % e)
    272             chan_to_middle = do_ssh_paramiko_connect_to(middle_transport, proxy_host, proxy_username, proxy_password, dest_host=host, dest_port=port)
     272            do_ssh_paramiko_connect_to(middle_transport, proxy_host, proxy_username, proxy_password)
     273            log("Opening proxy channel")
     274            chan_to_middle = middle_transport.open_channel("direct-tcpip", (host, port), ('localhost', 0))
     275
    273276            transport = Transport(chan_to_middle)
    274277            transport.use_compression(False)
    275278            try:
     
    277280            except SSHException as e:
    278281                log("start_client()", exc_info=True)
    279282                raise InitException("SSH negotiation failed: %s" % e)
    280             chan = do_ssh_paramiko_connect_to(transport, host, username, password, proxy_command, remote_xpra, socket_dir, display_as_args)
     283            do_ssh_paramiko_connect_to(transport, host, username, password)
     284            chan = paramiko_run_remote_xpra(transport, proxy_command, remote_xpra, socket_dir, display_as_args)
     285
    281286            peername = (host, port)
    282287            conn = SSHProxyCommandConnection(chan, peername, target, socket_info)
    283288            conn.timeout = SOCKET_TIMEOUT
     
    297302        except SSHException as e:
    298303            log("start_client()", exc_info=True)
    299304            raise InitException("SSH negotiation failed: %s" % e)
    300         chan = do_ssh_paramiko_connect_to(transport,
    301                                           host, username, password,
    302                                           proxy_command, remote_xpra, socket_dir, display_as_args)
     305        do_ssh_paramiko_connect_to(transport, host, username, password)
     306        chan = paramiko_run_remote_xpra(transport, proxy_command, remote_xpra, socket_dir, display_as_args)
    303307        conn = SSHSocketConnection(chan, sock, sockname, peername, target, socket_info)
    304308        conn.timeout = SOCKET_TIMEOUT
    305309        conn.start_stderr_reader()
     
    312316    def __init__(self):
    313317        nomodule_context.__init__(self, "gssapi")
    314318
    315 # (1) If the arguments after "proxy_command" are "None", then we're opening a port-forward
    316 # (2) If "parachan" is set, that means we're using a port-forward
    317 def do_ssh_paramiko_connect_to(transport, host, username, password,
    318                                xpra_proxy_command=None, remote_xpra=None, socket_dir=None, display_as_args=None,
    319                                dest_host=None, dest_port=None):
     319
     320def do_ssh_paramiko_connect_to(transport, host, username, password):
    320321    from paramiko import SSHException, RSAKey, PasswordRequiredException
    321322    from paramiko.agent import Agent
    322323    from paramiko.hostkeys import HostKeys
     
    544545        transport.close()
    545546        raise InitException("SSH Authentication on %s failed" % host)
    546547
    547     if remote_xpra is None:
    548         log("Opening proxy channel")
    549         return transport.open_channel("direct-tcpip", (dest_host, dest_port), ('localhost', 0))
    550548
     549def paramiko_run_remote_xpra(transport, xpra_proxy_command=None, remote_xpra=None, socket_dir=None, display_as_args=None):
     550    from paramiko import SSHException
    551551    assert len(remote_xpra)>0
    552552    log("will try to run xpra from: %s", remote_xpra)
    553553    for xpra_cmd in remote_xpra: