Skip to content
This repository was archived by the owner on Apr 5, 2018. It is now read-only.

Conversation

@tlrobinson
Copy link

This adds support for remote port forwarding, e.x. ssh -R :REMOTE_PORT:localhost:LOCAL_PORT me@myserver

It mostly works, except for communicating the port back to the client with replyGlobalMessageSuccess doesn't work asynchronously, and in fact will often segfault. This is due to the message being deallocated by libssh before we get a chance to send the response. Also, I believe libssh sends a success reply if you don't send one right away.

I'd love suggestions on how to fix this. I've tried a few things with little success.

Here's an example server (CoffeeScript):

net = require "net"
libssh = require "ssh"

server = libssh.createServer
  hostRsaKeyFile: "keys/id_rsa"
  hostDsaKeyFile: "keys/id_dsa"
  debug: true

server.on "connection", (session) ->
  session.on "globalrequest", console.log
  session.on "tcpipforward", (message) ->
    console.log "tcpipforward", message

    proxy = net.createServer (con) ->
      chan = session.openReverseForward(message.requestAddress, message.requestPort, con.remoteAddress, con.remotePort)
      console.log "chan", chan
      con.pipe(chan).pipe(con)

    session.on "close", ->
      console.log "session ended!"
      proxy.close()

    proxy.listen message.requestPort, message.requestAddress, ->
      console.log "listening", proxy.address()
      # TODO: crashes!
      # message.replyGlobalMessageSuccess(proxy.address().port)

  session.on "auth", (message) ->
    console.log "auth", message
    return message.replyAuthSuccess()

server.listen 3333

Not particularly useful since calling asynchronously causes
it to crash due to the message being deallocated too soon.
@rvagg
Copy link
Owner

rvagg commented Jun 19, 2014

Lots of libssh is still magic to me so these kinds of problems still throw me, perhaps you could have a look at the current libssh, if upgrading our dep helps then great, or perhaps a bug report to the libssh developers to get something manageable would help. Happy to take this PR whenever you think it's ready. Will also add you as a collaborator if you're keen to keep contributing.

@rvagg
Copy link
Owner

rvagg commented Aug 20, 2014

I'd love to merge this if anybody has time to figure out how to make it more solid

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants