Libssh2 on Haiku

I’m currently writing an SFTP/SCP client for Haiku. Since I’m already a bit familiar with the Haiku API (Interface Kit etc.) I started playing around with libssh2, which I’ve never used before.

I have written a little commandline test program, which connects over ssh, authenticates with user and password, establishes an sftp session and gets the directory listing of the specified folder. The problem is that it fails at the SSH handshake (libssh2_session_handshake()) with error code -2 and the message “Failed getting banner”.
The error does not occur on Linux, OSX, and FreeBSD only on Haiku (64bit and 32bit with gcc7 and gcc2).

Is there anybody on the forum who has some experience with libssh2 under Haiku? Is it a bug in the Haiku version of libssh2 or am I doing something wrong?

My test program is available here: https://pastebin.com/4GCyHag0
I compile it with “g++ -Wall -o sshtest sshtest.cpp -lssh2 -lnetwork”, and it should be run with “./sshtest ssh_server username password directory”

1 Like

While I can’t help with your issue, I’d like to point you to FTPPositive. Maybe if you don’t want to start from scratch, it’d be nice to extend and improve.

2 Likes

As you dont specify it here, not can be seen in the pastebin (you used argv), are you testing this against an external ssh server or are you trying to connect to the localhost ssh server on Haiku?

A local test may throw some light on the topic. (Also faster configuration changes to see if it works).

I have tested it with an external linux server, with an external haiku machine and with localhost on the same haiku machine. Always the same results.

As an additional info, connecting with the commandline ssh client supplied with haiku always worked.

Although I intended to start from scratch as a learning experience, your suggestion definitely makes sense to me. I’ll take a look at the FTPPositive source code and see if I can work with it. Do you know if it is maintained by somebody?

As you can see from the commits, it’s been mostly janus and me lately. Janus is normally doing the heavy lifting and I’m only good for some minor changes and optics… :slight_smile:

As with all projects at HaikuArchives, more devs are welcome! It’s a good idea that after you took a good look at a project and decide to get involved, to open issues at its tracker describing what problem/feature you like to tackle and how before working on a pull-request. Most often than not you probably won’t get much feedback aside from encouragement, at least for projects that are not on the radar of many people…

1 Like

I have been digging around with this, and dissected the whole libssh2 from the source code.

Unfortunately, it seems like a nonexpected socket error when using the inner function banner_receive from the libssh2 source code (called by the session handshake function).

When it tries to read from the connected socket, it answers 2147483637 (INT_MAX) as total received bytes, and goes through the libssh2 checkins as it being a positive answer, which is not.

If you trick/cheat the banner_receive code to use normal socket recv functions instead of libssh2 wrappers, you can read the banner from the server, but you will have errors later:

DEBUG: [libssh2] 1.400432 Socket: Recved 1 bytes banner
DEBUG: [libssh2] 1.401920 Socket: Sent 856/856 bytes at 0x187454d8
DEBUG: [libssh2] 1.401974 Socket: Recved 976/16384 bytes to 0x187414b0+0
DEBUG: [libssh2] 1.404606 Socket: Sent 80/80 bytes at 0x187454d8
DEBUG: [libssh2] 1.404653 Socket: Recved 2147483637/16384 bytes to 0x187414b0+0
DEBUG: [libssh2] 1.404669 Failure Event: -12 - Timeout waiting for ECDH_REPLY reply
DEBUG: [libssh2] 1.404688 Failure Event: -8 - Unrecoverable error exchanging keys
DEBUG: [libssh2] 1.404697 Failure Event: -8 - Unable to exchange encryption keys
Failure establishing SSH session: -8

So, i think that we can call the ssh2 code =>haiku sockets connection as broken .
@humdinger May we have some more eyes on this? Dont want Haiku to explode on some unexpected socket behavior in other lib :thinking:

1 Like

I cannot say if this is a fail on Haiku’s side or the libssh2 library’s. I’d suggest creating a ticket for it at Haiku’s Trac, and move it to haikuports, if the ball is in the port’s court.

If it needs more disussion, you may want to subscribe and post to the haiku-development mailing list. Many more devs will see it there than here in the forums.

@korli or @PulkoMandy may have more specific advice…

I downloaded and compiled libssh2 from source, instead of using the port, to see if it was an error on the port side (seems like it wasnt). I think that patch for BeOS/ Haiku is needed in libssh2 source when using the system sockets.

Will try to test more and fix it locally, and go to the Trac / Mailing list if the bell doesnt ring. :+1:

1 Like

Tested several things, including manual RECV instead of existing code, setting several options for libssh2 that were stated for BeOS on the network sockets and finally setting what libssh2 calls non-block/unblock which works ok (passes all the examples on the libssh2 code and the pastebin) until it just blocks on read when the handshake, user login and session are done.

Resuming: libssh2 + Haiku looks like a minefield. And I’m guessing that the fault is in libssh2 code to handling the sockets and not on Haiku sockets itselves.

I would use openssh or libssh if it does better (don’t know, i think i never used them) for this topic.

@BlueSky I have succesfully compiled, haiku-ported current master branch of libssh for the x86 architecture and did a simple example on connection, showing “ps -a” output on the remote machine by the C++ stdoutput. To Haiku localhost and online server outside my computers with success.

If you’r interested in this (remember, gcc7 only), i can try to figure out how to turn this into a real/official/public Haiku package.

Or i can post the recipe & patches only :thinking:

Thanks very much for investigating this whole thing. I´ve already taken a look at libssh, will try it out and see if it works better.

That would be great and highly appreciated :smile:

I’ve just noticed that libssh is already in HaikuPorts and installable from HaikuDepot. I have already ported my test program from libssh2 to libssh and it works without problems. Thanks again for your help.

I have already coded a very primitive GUI for my SCP/SFTP client. I am going to use this to develop and test the code for the scp/sftp stuff. When it’s working I’ll see if I can integrate it into FTPPositive.

I swear it wasnt when i looked :smile: . Maybe i was after libssh2 coding test and i missed it haha.
You’r welcome anyway, glad to hear that now the test program works ok :wink:

1 Like

I did it after seeing your struggle.

2 Likes

Aham! So i wasnt crazy.

No struggle on libssh porting. I even had the recipes with working hpkgs, up in my personal github repo for sandbox recipe playing. (https://github.com/pahefu/phHaikuRecipes/blob/master/net-libs/libssh/libssh-0.8.3.recipe).

The struggling was on going from that to being shown in Haiku depot. And being shy because making not formal recipes and that stuff, … yak yak yak.

1 Like