thebaselab / codeapp

Building a full-fledged code editor for iPad
https://code.thebaselab.com
MIT License
2.95k stars 202 forks source link

Implement ssh port forwarding #764

Closed pedromzadeh closed 1 year ago

pedromzadeh commented 1 year ago

Would it be possible to implement SSH port forwarding? The Blink app has this feature, so I think it should be achievable on iOS.

For instance, ssh -L 8888:localhost:8888 username@server_address.

Would be pretty useful for spinning up and accessing remote Jupyter servers.

thekeith commented 1 year ago

@pedromzadeh I’d go a step further and add ssh config to enable forwarding of multiple ports and agent forwarding as well. I raised this in #928 before I saw your issue

bummoblizard commented 1 year ago

This is doable but it's going to involve some work. We need to add the relevant features in our Objective-C libssh2 wrapper https://github.com/thebaselab/NMSSH to support this.

bummoblizard commented 1 year ago

https://libssh2.org/examples/tcpip-forward.html

thekeith commented 1 year ago

This is doable but it's going to involve some work. We need to add the relevant features in our Objective-C libssh2 wrapper https://github.com/thebaselab/NMSSH to support this.

I’ll go dig up my Objective-C skills…

bummoblizard commented 1 year ago

I’ll go dig up my Objective-C skills…

@thekeith I am working on it.

bummoblizard commented 1 year ago

Proposed NMSSH API:

class NMSSHChannel {
  // ...

  /* 
  Start listening on a local port and forward any TCP connection to the host, non-blocking
  queue: The queue where libssh2 calls are executed in (libssh2 and NMSSH are not thread-safe by design)
  */
  func bindLocalPortToRemoteHost(localListenIP: String, localPort: Int32, hostTargetIP: Int32, hostTargetPort: Int32, in queue: DispatchQueue) throws -> NMSSHSocket
}

class NMSSHSocket {
  // Underlying libssh2 socket
  private var sock: libssh2_socket_t 

  // To stop listening on a port
  func close()

  // TODO: Delegate / methods for status updates
}

bindLocalPortToRemoteHost():

bummoblizard commented 1 year ago

Simulator Screenshot - iPad (10th generation) - 2023-08-30 at 16 40 21

thekeith commented 1 year ago

Great to see progress here. How would it be configured?

One caveat is making sure that it doesn’t require a separate action to connect forwarded ports. In Termius for example you have to make a completely separate connection and initiate it for port forwarding which makes it a pain to set up, especially when you’re already in a session or want to forward multiple ports.

Ideally it would be great to allow users to do so via a UX which simply writes to a ~/.ssh/config file.

bummoblizard commented 1 year ago

Great to see progress here. How would it be configured?

One caveat is making sure that it doesn’t require a separate action to connect forwarded ports. In Termius for example you have to make a completely separate connection and initiate it for port forwarding which makes it a pain to set up, especially when you’re already in a session or want to forward multiple ports.

Ideally it would be great to allow users to do so via a UX which simply writes to a ~/.ssh/config file.

It would be configured through both GUI and config file. Let's support GUI first and deal with parsing .ssh/config in https://github.com/thebaselab/codeapp/issues/928.

bummoblizard commented 1 year ago

It will be available for testing in TestFlight after 1.5.0 is approved for public testing: Simulator Screenshot - iPad Pro (12 9-inch) (6th generation) - 2023-09-01 at 13 14 28