EldoS | Feel safer!

Software components for data protection, secure storage and transfer

sending text commands

Also by EldoS: CallbackProcess
A component to control process creation and termination in Windows and .NET applications.
#5372
Posted: 03/12/2008 18:59:35
by aljaz (Standard support level)
Joined: 01/10/2008
Posts: 18

Hi.

I would like to send some text commands from client to server and in other way.

I already programmed SSH Server and SSH Client. SSH Client establishes the connection (it also opens remote port forwarding tunnel). Now I need some additional communication tunnel where some kind text messages/commands will be transfered from client to server and also from server to client.

In help files I found that the right solution would be a custom remote subsystem. I don't find the way how to establish this kind of tunnel. My try:

Code
SSHRemotePortForwardingTunnel.TunnelList = SSHTunnelList
SSHRemotePortForwardingTunnel.ToHost = "localhost"
SSHRemotePortForwardingTunnel.ToPort = remotePort
SSHRemotePortForwardingTunnel.Host = "localhost"
SSHRemotePortForwardingTunnel.Port = localPort

SSHComoSubsystemTunnel.TunnelList = SSHTunnelList
SSHComoSubsystemTunnel.Subsystem = "ComoSubsystem"
AddHandler SSHComoSubsystemTunnel.OnOpen, AddressOf sshComoSubsystemTunnel_OnOpen
AddHandler SSHComoSubsystemTunnel.OnError, AddressOf sshComoSubsystemTunnel_OnError


SSHClient.Versions = SBSSHCommon.Unit.sbSSH2
SSHClient.UserName = userName
SSHClient.Password = "some password"

SSHClient.CloseIfNoActiveTunnels = False
SSHClient.AuthenticationTypes = SBSSHConstants.Unit.SSH_AUTH_TYPE_PASSWORD
SSHClient.TunnelList = SSHTunnelList


After SSH client establish the connection no events regarding Subsystem is triggered on the server side and sshComoSubsystemTunnel_OnOpen on client side is never triggered as well.

I also tried to open the tunnel manually. I waited 60 sec and tried with the command:

Code
SSHComoSubsystemTunnel.Open(Nothing)


The server does not react.


I found a way that actually do suit my requirements, but I don't think that this is the most efficient solution. I used TElShellSSHTunnel:

Code
SSHTunnel = New TElShellSSHTunnel
AddHandler SSHTunnel.OnOpen, AddressOf sshTunnelC_OnOpen
AddHandler SSHTunnel.OnClose, AddressOf sshTunnelC_OnClose
AddHandler SSHTunnel.OnError, AddressOf sshTunnelC_OnError

SSHTunnel.TunnelList = SSHTunnelList


The Tunnel is still not opened when the ssh connection is established (although AutoOpen=true). I have to open it after a few seconds with:

Code
If SSHTunnelConnection Is Nothing Then
     SSHTunnel.Open(Nothing)
End If


After that SSH Server triggers following events: m_server_OnTerminalRequest, m_server_OnBeforeOpenShell and finally m_server_OnOpenShell.

This is why I get back to thinking that TElShellSSHTunnel is meant for executing commands in command line and not for what I need.

I don't find the way out.

Whats the right solution?
Is there a way to open a tunnel when I need it? But than it is not possible to send a text command from server to client because server is not able to open additional tunnel to client, right?
How to open a tunnel automatically when the ssh connection establishes?
(Just because I'm curious) One off topic question: How much traffic (maybe in KB per hour) is it send from server to client and from client to server when a tunnel is opened and no traffic is actually sent?


Thanks in advance.
Aljaz Delakorda
#5384
Posted: 03/13/2008 02:08:28
by Ken Ivanov (EldoS Corp.)

If both client and server implementations are under your control, then your own subsystem tunnel seems to be the best solution.

Why it did not work for you: you need to specify the name of your subsystem in the TElSSHServer.AllowedSubsystems list. Subsystem connection request will be automatically rejected otherwise.

Quote
The Tunnel is still not opened when the ssh connection is established (although AutoOpen=true). I have to open it after a few seconds with:

It is likely that you missed some assignment. Please compare your code to SSHDemo sample, it does open the tunnel automatically.

Quote
Is there a way to open a tunnel when I need it?

Yes. However, only client can initiate tunnel opening (except remote port forwarding tunnel case). Custom subsystem will allow server to send commands when it needs, as SSH protocol does not restrict subsystem protocols in any way.

Quote
How to open a tunnel automatically when the ssh connection establishes?

Setting AutoOpen to true will help -- please see SSHDemo and SFTP client samples.

Quote
How much traffic (maybe in KB per hour) is it send from server to client and from client to server when a tunnel is opened and no traffic is actually sent?

Some SSH packets are sent in both directions when the tunnel is being opened. When the tunnel is inactive, no bytes are sent.
#5388
Posted: 03/13/2008 02:24:31
by aljaz (Standard support level)
Joined: 01/10/2008
Posts: 18

Quote
Innokentiy Ivanov wrote:
Why it did not work for you: you need to specify the name of your subsystem in the TElSSHServer.AllowedSubsy­stems list. Subsystem connection request will be automatically rejected otherwise.


How to do that? This property is declared as ReadOnly.

Code
Public ReadOnly Property AllowedSubsystems() As SBStringList.TElStringList
#5389
Posted: 03/13/2008 02:34:54
by Ken Ivanov (EldoS Corp.)

Server.AllowedSubsystems.Add("ComoSubsystem")
#5393
Posted: 03/13/2008 03:21:49
by aljaz (Standard support level)
Joined: 01/10/2008
Posts: 18

Quote
Innokentiy Ivanov wrote:
Server.AllowedSubsystems.­Add("ComoSubsystem")


Thank you. I guess it was just too obvious to figured it out. I managed to bring this things to work.
Also by EldoS: Rethync
The cross-platform framework that simplifies synchronizing data between mobile and desktop applications and servers and cloud storages

Reply

Statistics

Topic viewed 1668 times

Number of guests: 1, registered members: 0, in total hidden: 0




|

Back to top

As of July 15, 2016 EldoS Corporation will operate as a division of /n software inc. For more information, please read the announcement.

Got it!