EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Blocking SSH call?

Also by EldoS: CallbackDisk
Create virtual disks backed by memory or custom location, expose disk images as disks and more.
#2333
Posted: 02/19/2007 09:33:10
by Eugene Mayevski (EldoS Corp.)

You can get what you want fast, effectively and inexpensive. Choose any two of three.

The most effective approach would be to use ElSSHClient and it's tunnels. ElSSHClient is asynchronous and lets you create an SFTP tunnel only if needed and on the fly, i.e. within the same SSH connection. But use of ElSSHClient is not a 5-minute job. It requires certain understanding of the components and of SSH nature.

If you can live with 2 connections, use ElSimpleSSHClient and it's Command property. Call ReceiveData as follows (this is a piece of the test application that I used now to verify the behaviour):

Code
procedure TForm1.Timer1Timer(Sender: TObject);
var
  S, ES : string;
  BufSize : integer;
  StdErrSize : integer;
  TC         : integer;
begin
  if (not Client.Active) or (Client.Active and Client.CanReceive(0)) then
  begin
    SetLength(S, 65536);
    SetLength(ES, 65536);
    BufSize := 65536;
    StdErrSize := 65536;
    Client.ReceiveData(@S[1], BufSize, @ES[1], StdErrSize, true);
    SetLength(S, BufSize);
    SetLength(ES, StdErrSize);

    if Bufsize > 0 then
      Memo1.Lines.Text := Memo1.Lines.Text + S;

    if StdErrSize > 0 then
      Memo2.Text := Memo2.Text + ES;
  end;
end;


The command(s) will be executed and the connection will be closed after that. This way you don't need to wait for any timeout. However, if something goes wrong, SocketTimeout property won't let your routing wait forever.

The third option is to create a technical specification for what you need exactly and use our custom services. The task will take 5-6 hours depending on specification (the estimation includes the time necessary for communication). But I think that the above code piece will be enough.


Sincerely yours
Eugene Mayevski
#2334
Posted: 02/19/2007 14:39:31
by Martin Berube (Basic support level)
Joined: 02/16/2007
Posts: 9

Thanks for you suggestions, I'll check this out. One last thing (I hope ...) : I got an Exception using the SimpleSSHClient. It's some test code and it couldn't be more simple :

ssh = New TElSimpleSSHClient
ssh.Address = test.SERVER
ssh.Port = test.PORT
ssh.Username = test.USER
ssh.Password = test.PASSWORD
ssh.UseInternalSocket = True
ssh.Versions = 0
ssh.SocketTimeout = DEFAULT_TIMEOUT
ssh.EncryptionAlgorithms(5) = True
ssh.EncryptionAlgorithms(6) = True
ssh.EncryptionAlgorithms(7) = True
ssh.EncryptionAlgorithms(1) = True
ssh.EncryptionAlgorithms(0) = True
ssh.Versions = SBSSHCommon.Unit.sbSSH2
ssh.AuthenticationTypes = SBSSHConstants.Unit.SSH_AUTH_TYPE_PASSWORD
ssh.Open()
ssh.Close()


Connection works well. But the ssh.Close() statement give me some troubles. With the previous version of SBB we used (4.4.094) it works well but with the new release 5.0.0.106, I got the follow Exception:

System.NullReferenceException

There's the call stack :
SBSSHCommon.TElSSHTunnelConnection.remove_OnData(TSSHDataEvent Parameter)
SBSimpleSSH.TElSimpleSSHClient.OnTunnelClose(Object Sender, TElSSHTunnelConnection Conn)
SBSSHCommon.TElCustomSSHTunnel.DoClose(TElSSHTunnelConnection Connection)
SBSSHCommon.TElSSHTunnelConnection.DoClose(TSSHCloseType CloseType)
SBSSHClient.TElSSHClientTunnelConnection.DoClose(TSSHCloseType CloseType)
SBSSHCommon.TElSSHTunnelConnection.Close(Boolean FlushCachedData)
SBSSHClient.TElSSHClient.PerformClose(Boolean Forced, String CloseReason)
SBSSHClient.TElSSHClient.Close(Boolean Forced)
SBSimpleSSH.TElSimpleSSHClient.Close()

Can you help me with that ?

Thanks again for your help, this is really good support !
#2335
Posted: 02/19/2007 14:47:41
by Eugene Mayevski (EldoS Corp.)

This looks like some rare bug. I will pass this to HelpDesk for evaluation.


Sincerely yours
Eugene Mayevski
#2336
Posted: 02/19/2007 15:40:12
by Eugene Mayevski (EldoS Corp.)

We've identified and fixed the problem.


Sincerely yours
Eugene Mayevski
#2337
Posted: 02/20/2007 07:57:59
by Martin Berube (Basic support level)
Joined: 02/16/2007
Posts: 9

Thanks. That's quick !

When do you think a fixed release will be available ?
#2338
Posted: 02/20/2007 15:14:01
by Martin Berube (Basic support level)
Joined: 02/16/2007
Posts: 9

Another question : when you use the command property, calling receiveData returns only the result (stdout) of the command. If I call it manually by using sendText and receiveText, my result also contains the echo of what I put in sendText. Is there a way to get the same result as open with the command property set give, using TEISimpleSSHClient ?

Thanks again.
#2339
Posted: 02/20/2007 15:34:21
by Eugene Mayevski (EldoS Corp.)

I don't understand your question, but you can change RequestTerminal property and see the resulting behaviour. Remember, that SecureBlackbox doesn't interpret the results, - it only transfers binary data. The rest is done by the server. I.e. it's not our job to convert the output of the command or show the echo.


Sincerely yours
Eugene Mayevski
#2340
Posted: 02/20/2007 15:41:41
by Martin Berube (Basic support level)
Joined: 02/16/2007
Posts: 9

That what I thought. So it's probably something to set. Where should I change the requestTerminal property? TELSimpleSSHClinet doesn't have that property.
#2341
Posted: 02/21/2007 00:55:28
by Eugene Mayevski (EldoS Corp.)

It does. Maybe it's not documented yet. You can always use Object Browser to check syntax of the methods and properties.


Sincerely yours
Eugene Mayevski
#2342
Posted: 02/21/2007 08:28:51
by Martin Berube (Basic support level)
Joined: 02/16/2007
Posts: 9

Hi

You're right but it doesn't help me. I still get the same result. By looking the source code (i just learn we have it...), I understand better what's happening : a TELCommandSSHTunnel is created when command parameter is set and a TELShellSSHTunnel when not. So there's my questions/requests:
- Do you think it could be possible to add a new method to simpleSSHClient to execute a command Sync (ex: response = SSHSimpleClient.executeCommand("ls")) with a way to keep client active. It will really help when you have logic that depends on the result of the last command(something like:
sshSimpleClient.open()
if sshSimpleClient.executeCommand("ls").contains("myFile")
sshSimpleClient.executeCommand("pgm1")
else
sshSimpleClient.executeCommand("pgm1")

- Do you think of a way I can do it with the current version (5.0)

- When I send multiple commands (with the commands property), only the 1st one is executed. It seems to be related with the useInternalSocket property. When I set it to true, it works well but when I use my socket, only the first one is executed on server.

I still have a lot of questions for you because the more I test, the less I understand how I can use SBB to do what I want. I don't know if continuing that kind of "chat" on the forum is the better way to do it. Is there a way we can communicate together in a more "interactive" way. I would be able to explain exactly what I need ?

Thanks again
Also by EldoS: Callback File System
Create virtual file systems and disks, expose and manage remote data as if they were files on the local disk.

Reply

Statistics

Topic viewed 24256 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!