php / pecl-networking-ssh2

Bindings for the libssh2 library
http://pecl.php.net/package/ssh2
Other
51 stars 58 forks source link

Modern SSH hostkey methods compatibility #63

Closed Grundik closed 1 year ago

Grundik commented 1 year ago

According to documentation, ssh2_connect currently supports only ssh-rsa and ssh-dss hostkey methods, but both of them are deprecated:

So, its unable to connect to server, which uses modern OpenSSH versions.

Library should be updated to support more modern hostkey methods.

langemeijer commented 1 year ago

Did you verify that ssh2_connect() is not working with servers without dss or rsa?

glancing over the php_ssh2_session_connect() does not reveal anything specific to either ssh-rsa or ssh-dss.

At the time the documentation was written, both hostkey methods probably were the only two. As the ssh2 extension is only a thin wrapper over libssh2, the supported hostkey methods probably are defined by what your libssh2 capabilities. ed25519 and ECDH is support has been in libssh2 since 2018-ish, so any recent version could very well work.

Could you check? In that case this is a documentation issue.

Grundik commented 1 year ago

I've done some research, and obtained following data:

So it seems like issue is both the code and documentation, since ssh2_connect sometimes can use extra hostkey types, but its strangely unreliable. And it seems like there are no connection with libssh2 binary itself, since in any stated cases, it was able to support any mentioned hostkey types.

Maybe its a compilation options, like some #defines?..

Grundik commented 1 year ago

Oh, surprisingly for me, but libssh2.so is not part of openssh package, and its completely independent.

So it seems like libssh2 issue after all: version from in debian unstable (1.10) accepts ed25519, but version from debian stable (1.9) does not. And both of them does not accepts sha2.

rfay commented 1 year ago

I'd be interested to know whether you tracked this to a particular libssh2 problem? I'd also be interested in why it was "closed as completed".

Grundik commented 1 year ago

This PHP module just uses libssh2, not limiting hostkey method. But libssh2 is not the part of openssh, its completely different library, so its compatibility is not that good, especially in older versions.

Modern versions of libssh2 are supporting ECDSA and ED25519, but it depends on distro, which version are provided there. For example, debian bullseye has quite old version, and there be problems.

But all of that is not a problem of PHP ssh2 module, it all roots in libssh2. Which is rarely updated, leading to quite a lag of feature implementation for end user. For example they skipped rsa-sha2 method completely, which should have been implemented ~10 years ago.