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

Re: Tunneling


Hello,
Now that i had some time to review the sample of proxy, and install the new
library, I am still not sure if i can do this the way i need.
Let me restate my problem
I need to connect into HostB's SSH Server but in order to do that i need to
connect into MiddleHost SSH Server first
HostA ===> MiddleHost ===> HostB

So i need a Hop through SSH Server

With proxy.c i would need to install an application in the MiddleHost in
order to be able to just through but that is not what i want.
Looking better to the pseudocode that i placed before in this thread i now
realise that this would work for other type of data, like HTTP or
something. But what i want is for libssh to handle the authentication of
the HostB as well.
So what i believe i need is something like:

localSocket = create_local_listenning_socket( portLocal )
middleHostCon = connect_to("MiddleHost")
authenticate_user( middleHostCon, "username", "pass" )
hostBCon = connect_to_using_connnection( "HostB", middleHostCon)
authenticate_user( hostBCon , "username", "pass" )
( application ready to send data from local port into HostB )
while(1)
   if has_data(localSocket)
      data = read_from_socket( localSocket )
      write_to_connection( hostBCon, data)
   if has_data(hostBCon)
      data = read_from_connection( hostBCon)
      write_to_socket( localSocket, data )
   sleep(0.1)
disconnect( hostBCon )
disconnect( middleHostCon )
disconnect( localSocket )

Is there a way to accomplish this with libssh? Or do i need to create a
proxy application to put in the MiddleHost?

BR


On 27 November 2013 20:36, Dustin Oprea <myselfasunder@xxxxxxxxx> wrote:

>
> On Wed, Nov 27, 2013 at 12:11 PM, Andreas Schneider <asn@xxxxxxxxxxxxxx>wrote:
>
>> On Wednesday 27 November 2013 15:59:07 Joao Pedro Almeida Pereira wrote:
>> > Hello,
>> > So basically i need to do
>> > rc = channel_open_forward(forwarding_channel,
>> > "HostB", 22,
>> > "localhost", 5555);
>> > sock = create_socket("localhost",5555)
>> > con_sock = wait_for_client( sock )
>> > while true:
>> > if have_things_to_read( con_sock ):
>> >
>> > size_data = read_from_socket( con_sock, data_from_socket )
>> >
>> > channel_write(forwarding_channel, data_from_socket, size_data )
>> >
>> > else if have_things_to_read( forwarding_channel):
>> >
>> > size_data = channel_read( forwarding_channel, data_from_server)
>> >
>> > size_data = write_to_socket( con_sock, data_from_server )
>> > else:
>> > sleep(0.1)
>> > Something similar to this with all the control logic in order to handle
>> the
>> > case of errors.
>> >
>>
>> http://git.libssh.org/projects/libssh.git/tree/examples/proxy.c
>>
>> :)
>>
>> --
>> Andreas Schneider                   GPG-ID: CC014E3D
>> www.cryptomilk.org                asn@xxxxxxxxxxxxxx
>>
>>
>>
> There's also a very similar example online at
> http://api.libssh.org/master/libssh_tutor_forwarding.html .
>
> It basically agrees with yours (except they just use a constant literal as
> the source data).
>
>
>
> Dustin
>
>


-- 
--
-----
--------
João Pereira

Email: joao.almeida@xxxxxxxxxxx
Web: http://www.bluetc.es

Follow-Ups:
Re: TunnelingJoao Pedro Almeida Pereira <joao.almeida@xxxxxxxxxxx>
Archive administrator: postmaster@lists.cynapses.org