clue / reactphp-ssh-proxy

Async SSH proxy connector and forwarder, tunnel any TCP/IP-based protocol through an SSH server, built on top of ReactPHP.
https://clue.engineering/2018/introducing-reactphp-ssh-proxy
MIT License
21 stars 7 forks source link

Support local SSH SOCKS proxy server #5

Closed clue closed 5 years ago

clue commented 5 years ago

Currently, the SshProcessConnector allows creating plaintext TCP/IP connections which can be used by higher-level protocol implementations. It is implemented by spawning an SSH client like ssh -W google.com:80 user@example.com and will access the standard I/O process streams and represent this as a single connection. Accordingly, it will spawn one process per connection.

As an alternative, we should also support running the local SSH client as a SOCKS proxy server like ssh -D 1080 user@example.com. This will start a local SOCKS proxy server listening on 127.0.0.1:1080 and will accept any number of TCP/IP connections over a single SSH client process.

Technically, this is already supported by manually launching the SSH client using the above command and then simply using https://github.com/clue/reactphp-socks to connect to this local SOCKS proxy server.

Accordingly, we should provide a new class that will automatically spawn this local SOCKS proxy server on demand only and will then use the above SOCKS client library to connect to this server. This means that the process will automatically be spawned on demand only and also that it should be closed when it is not used for some time (idle period similar to https://github.com/friends-of-reactphp/mysql/pull/88).

Additionally, by leveraging the existing SOCKS client implementation we can also provide secure TLS support (#4). I've started looking into this and will keep this ticket updated as I make progress.