[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Reverse port forwarding requests server implementation


On Sunday 13 October 2013 12:26:00 Marco Ganci wrote:
> Hi,

Hey,

> I'm trying to implement a ssh server, obiousvly using libssh, that accept
> reverse port forwarding requests coming from clients.

I suggest you take a look at the libssh 0.6.0rc1 example directory. Especially 
the samplesshd-cb.c example using the new callback system. You need to 
implement the callbacks for accepting forward connections and implement them.

> For the client implementation I'm using with success the example available
> in the tutorial ( http://api.libssh.org/master/libssh_tutor_forwarding.html
> ), but for server I'm able to find only example about authentication,
> channel open/close/write/read, and no references about how to accept
> incoming reverse port forwading requests.

There is none. But look also at the examples/proxy.c file.

> I see that in the source code there are some undocumented functions that
> talks about general request and so on, but also after several attempes I'm
> not able to find a solution.

Which functions are you talking about?


> 
> Below some code.
> 
> Client:
>                                         ...
> if ( rc == SSH_AUTH_SUCCESS )
> {
> DebugStream() << "Authentication completed with success";
>  //forward connection
> rc = ssh_forward_listen(ssh_session, NULL, 3863 , NULL);
>  if (rc != SSH_OK)
> {
> DebugStream() << "Error opening remote port:" << ssh_get_error(ssh_session);
> DebugStream() << "Error opening remote port:" <<
> ssh_get_error_code(ssh_session);
> }
> 
> DebugStream() << "Waiting forward connections";
> ssh_channel channel = ssh_forward_accept(ssh_session, 60000);
>  if (channel == NULL)
> {
> DebugStream() << "Error waiting for incoming connection:" <<
> ssh_get_error(ssh_session);
> }
>  DebugStream() << "Connection accepted";
> 
> }
> ...
> 
> Server:
>                   ...
> do { //waiting for open channel request message = ssh_message_get(session);
> log("Message received"); if(message){ switch(ssh_message_type(message)){
> case SSH_REQUEST_GLOBAL:
> if(ssh_message_subtype(message)==SSH_GLOBAL_REQUEST_TCPIP_FORWARD){
> ssh_message_global_request_reply_success(message,3863);
> ssh_message_free(message); break; } default:
> ssh_message_reply_default(message); ssh_message_free(message); } } }
> while(message); log("Forward request ok!");
>                ..

Use the new callback system which is much easier.


Sorry for the late reply.



	-- andreas

-- 
Andreas Schneider                   GPG-ID: CC014E3D
www.cryptomilk.org                asn@xxxxxxxxxxxxxx


References:
Reverse port forwarding requests server implementationMarco Ganci <mak82@xxxxxxxxx>
Archive administrator: postmaster@lists.cynapses.org