Marco Ganci
2013-10-13 10:26:00 UTC
Hi,
I'm trying to implement a ssh server, obiousvly using libssh, that accept
reverse port forwarding requests coming from clients.
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.
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.
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!");
...
Is this code correct?
Any suggestion?
Thank you in advance
Best Regards
I'm trying to implement a ssh server, obiousvly using libssh, that accept
reverse port forwarding requests coming from clients.
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.
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.
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!");
...
Is this code correct?
Any suggestion?
Thank you in advance
Best Regards
--
-- Marco Ganci
-- mak82-VGgt2q2+T+***@public.gmane.org
-- marco.ganci-***@public.gmane.org
-- Marco Ganci
-- mak82-VGgt2q2+T+***@public.gmane.org
-- marco.ganci-***@public.gmane.org