UPDATED Please read: SSH/SFTP client issue

Discussion of open issues, suggestions and bugs regarding network security and data protection solution - SecureBridge
tcaduto12068
Posts: 132
Joined: Wed 17 Aug 2016 05:57

UPDATED Please read: SSH/SFTP client issue

Post by tcaduto12068 » Tue 21 May 2019 19:30

This is on Linux with FPC 3.0.4
see sample code below, this is connecting to a python Paramiko sftp server (latest version)
I have to have a sleep(100) before the ssh client disconnect and if I do the SFTP disconnect it raises a error:
Image



00000000004F0BAC 4889d8 mov %rbx,%rax
00000000004F0BAF 488b00 mov (%rax),%rax
00000000004F0BB2 ff9040010000 callq *0x140(%rax)
00000000004F0BB8 4189c4 mov %eax,%r12d
00000000004F0BBB 4183fc00 cmp $0x0,%r12d
00000000004F0BBF 7f45 jg 0x4f0c06 <SCVIO$_$TCRVIO_$__$$_ENDRECEIVE$ISCASYNCRESULT$$LONGINT+278>
00000000004F0BC1 488b7b28 mov 0x28(%rbx),%rdi
00000000004F0BC5 e8467ef7ff callq 0x468a10 <CLASSES$_$TTHREAD_$__$$_TERMINATE>
00000000004F0BCA 48837b5000 cmpq $0x0,0x50(%rbx)
00000000004F0BCF 7435 je 0x4f0c06 <SCVIO$_$TCRVIO_$__$$_ENDRECEIVE$ISCASYNCRESULT$$LONGINT+278>
00000000004F0BD1 807b0800 cmpb $0x0,0x8(%rbx)
00000000004F0BD5 752f jne 0x4f0c06 <SCVIO$_$TCRVIO_$__$$_ENDRECEIVE$ISCASYNCRESULT$$LONGINT+278>
00000000004F0BD7 8b4b58 mov 0x58(%rbx),%ecx
00000000004F0BDA 488b5350 mov 0x50(%rbx),%rdx
00000000004F0BDE 488d3deb881a00 lea 0x1a88eb(%rip),%rdi # 0x6994d0 <VMT_$SCVIO_$$_SOCKETEXCEPTION>
00000000004F0BE5 48be0100000000000000 movabs $0x1,%rsi
00000000004F0BEF e85ceeffff callq 0x4efa50 <SCVIO$_$SOCKETEXCEPTION_$__$$_CREATE$ANSISTRING$LONGINT$$SOCKETEXCEPTION>

(I am also getting host key not verified errors randomly as well)
Image

Code: Select all

program sftp_send_file;
{$mode objfpc} {$H+}
uses cthreads,datamodU, sbridge10,sysutils;
var
  sftp_client:tsftmod;
  fullfilename:string;
  basename:string;
  remotename:string;
begin
      if ParamCount >= 1 then
      begin
           fullfilename:= ParamStr(1);
           basename:= extractfilename(fullfilename);
      end;
      sftp_client:=Tsftmod.create(nil);
      try
        sftp_client.ssh.HostName:='xxxxxxx.xxxxxxx.com';
        sftp_client.ssh.Port:=10022;
        sftp_client.ssh.User:='xxxxxxx';
        sftp_client.ssh.Password:='xxxxx';
        //connect ssh client
        sftp_client.ssh.Connect;
        if sftp_client.ssh.Connected then
        try
          sftp_client.sftp.Initialize;
          if sftp_client.sftp.Active then
          try
             remotename:=  format('/TO/%s',[basename]);
             sftp_client.sftp.UploadFile(fullfilename,remotename,true);
          finally
               //sftp_client.sftp.Disconnect;
          end;
        finally
          sleep(100);
          sftp_client.ssh.Disconnect;
        end;
      finally
        freeandnil(sftp_client);
      end;
end. 
Last edited by tcaduto12068 on Mon 17 Jun 2019 21:12, edited 1 time in total.

ViktorV
Devart Team
Posts: 3168
Joined: Wed 30 Jul 2014 07:16

Re: SSH/SFTP client issue

Post by ViktorV » Wed 22 May 2019 11:54

Please try to use night build of SecureBridge which we sent you and inform us about the results.

tcaduto12068
Posts: 132
Joined: Wed 17 Aug 2016 05:57

Re: SSH/SFTP client issue

Post by tcaduto12068 » Wed 22 May 2019 14:05

Hi Viktor,
I installed the nightly build and the host key random error did not seem to pop up,
but it hangs on the SSH disconnect even with no SFTP used.
On the prior build it would disconnect ok if I put a 100ms sleep before the ssh discnnect.

It works fine in the Lazarus for windows, I am trying to build this small console app on Linux (manjaro)

ViktorV
Devart Team
Posts: 3168
Joined: Wed 30 Jul 2014 07:16

Re: SSH/SFTP client issue

Post by ViktorV » Wed 22 May 2019 14:13

Unfortunately, we can't reproduce the issue.
Please compose a small test sample that would demonstrate the described behavior and send it to us via the contact form https://devart.com/company/contactform.html so that we could research the issue further.
For us to quickly investigate this behavior of SecureBridge, please allow test access to your server and, if possible, send us the necessary connection data.

tcaduto12068
Posts: 132
Joined: Wed 17 Aug 2016 05:57

Re: SSH/SFTP client issue

Post by tcaduto12068 » Wed 22 May 2019 14:40

Some more info.
I tested it against two SSH servers
1. A python Paramiko based server
2. A open SSH server on Ubuntu 16.04.1 LTS

Both hang when the ssh client disconnect method is called.
same error in the screen shot I posted in the other posts above this one.

ViktorV
Devart Team
Posts: 3168
Joined: Wed 30 Jul 2014 07:16

Re: SSH/SFTP client issue

Post by ViktorV » Wed 22 May 2019 14:46

We will investigate this SecureBridge behavior using your data and let you know the result.

tcaduto12068
Posts: 132
Joined: Wed 17 Aug 2016 05:57

Re: SSH/SFTP client issue

Post by tcaduto12068 » Wed 22 May 2019 14:56

Ok, well it appears to be an issue with the debugger in Lazarus, when I don't put a break point or run it from the command line it works perfectly.

tcaduto12068
Posts: 132
Joined: Wed 17 Aug 2016 05:57

Re: SSH/SFTP client issue

Post by tcaduto12068 » Wed 22 May 2019 15:05

I can work around the debugger issue, but there is one more thing.
When I click on the ssh client component to set properties etc, it pops up a empty dialog box and appears to be hanging on the property editor on the second line which is the ciphersclient line.

ViktorV
Devart Team
Posts: 3168
Joined: Wed 30 Jul 2014 07:16

Re: SSH/SFTP client issue

Post by ViktorV » Fri 24 May 2019 10:18

Thank you for the information. We have reproduced and fixed the issue. This fix will be included in the next build of SecureBridge.

ViktorV
Devart Team
Posts: 3168
Joined: Wed 30 Jul 2014 07:16

Re: SSH/SFTP client issue

Post by ViktorV » Fri 24 May 2019 11:12

We have answered you via e-mail.

tcaduto12068
Posts: 132
Joined: Wed 17 Aug 2016 05:57

Re: SSH/SFTP client issue

Post by tcaduto12068 » Fri 24 May 2019 15:29

The property editor issue is fixed.

Still seeing a very long disconnect time when I call:
sftp_client.ssh.Disconnect after sftp_client.sftp.Disconnect;

sftp_client is a datamodule that has the two components on it.

tcaduto12068
Posts: 132
Joined: Wed 17 Aug 2016 05:57

Re: SSH/SFTP client issue

Post by tcaduto12068 » Fri 24 May 2019 15:39

sometimes it disconnects normally but on the times it takes a long time this error pops up in the dubugger:
(On FPC on Manjaro Linux)

[Debugger Exception Notification]

Project sftp_send_file raised exception class 'SocketException' with message:
Error on data reading from the connection:
Try again.
Socket Error Code: 11($B)

At address 50F547


[Ignore this exception type]

[Break] [Continue]

I tested against a paramiko python SSH server and a OpenSSH on Ubuntu.

When I hit break it goes into the assembler in what looks likes some asyncresult function.

Stops on this line in assembler:

000000000050F547 8b4b58 mov 0x58(%rbx),%ecx


When I turn the debugger off my try except does not catch it, it just takes a long time to disconnect.

ViktorV
Devart Team
Posts: 3168
Joined: Wed 30 Jul 2014 07:16

Re: SSH/SFTP client issue

Post by ViktorV » Mon 27 May 2019 10:07

Unfortunately, we can't reproduce the issue.
To understand the issue cause, we need a test sample where the issue is stably reproduced.
Therefore, please compose and send us a small sample of stably reproducing the error with test access to your server and send it to us via the contact form https://devart.com/company/contactform.html . As soon as we get such an example and the problem will be reproduced in our environment and we will try to give you an answer right away. If the cause of the error is in our code, we will fix it as soon as possible.

tcaduto12068
Posts: 132
Joined: Wed 17 Aug 2016 05:57

Re: SSH/SFTP client issue

Post by tcaduto12068 » Mon 17 Jun 2019 21:12

here is some python client code that shows this issue connecting to sbridge sftp server:
Note the sleep after the sftp.disconnect, without the sleep the server throws this error:

Code: Select all

06/17/2019 04:11:04 PM:[Error] SSH Client(10.201.8.250:56192) ERROR for user:testuser:Error on data reading from the connection:
An existing connection was forcibly closed by the remote host..
Same thing happens when I write a client with the SBridge client component.

This is on that last nightly build I downloaed a few weeks ago, but does it on the released production verison of sbridge also.


NOTE this was with Paramiko version 2.5 (latest)

Code: Select all

import paramiko
import glob
import os
import time
from threading import Thread

def sendfile(filename):
    try:
        host = 'your.host.name'
        port = 10022
        username = "testuser"
        password = "12345678"
        #print('starting thread to send file')
        transport = None
        sftp = None
        transport = paramiko.Transport((host, port))
        transport.connect(username=username, password=password)
        print('connected to host')
        sftp = paramiko.SFTPClient.from_transport(transport)
        basename = os.path.basename(filename)
        remotefilename = os.path.join('/', basename)
        sftp.put(filename, remotefilename)
        print('Uploaded file '+ filename)
    finally:
        if sftp is not None:
            sftp.close()
            time.sleep(.2)
        if transport is not None:
            transport.close()

#Upload files 1 per connection
count = 0
files = glob.glob(r'C:\Users\20659a\Desktop\test_files\*')
for file in files:

    t = Thread(target=sendfile, args=(file,))
    t.start()

tcaduto12068
Posts: 132
Joined: Wed 17 Aug 2016 05:57

Re: UPDATED Please read: SSH/SFTP client issue

Post by tcaduto12068 » Tue 18 Jun 2019 13:39

bump

Post Reply