Code Monkey home page Code Monkey logo

Comments (5)

JoelStienlet avatar JoelStienlet commented on May 18, 2024

Hello,
I've had some problems with the demos too, but I got this one working with:
host.encode('utf-8')

from ssh2-python.

RobCoops avatar RobCoops commented on May 18, 2024

@JoelStienlet Thanks for the info, I tried but I am getting the same result regardless of the encoding of the hostname:

Read 3 hosts from known hosts file at /root/.ssh/known_hosts
Traceback (most recent call last):
  File "test.py", line 34, in <module>
    kh.checkp(host.encode('utf-8'), 22, host_key, type_mask)
  File "ssh2/knownhost.pyx", line 252, in ssh2.knownhost.KnownHost.checkp
ssh2.exceptions.KnownHostCheckNotFoundError: ('Host %s not found in known hosts collection', b'localhost')

I of course made sure that the host is in the known_hosts file so it should find it no problem.

>grep localhost ~/.ssh/known_hosts
localhost ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBAVsEAljGvdqAwiyTaUPJZTHu0XVRby+M/2HttiaagThlLmgA8asBMzHNkXnOJO6hJXS2VZZDgwGv1XFr2yH+CA=

Sure it does not complain but the code still does not quite work... going to spend quite some more time on this trying to work out what is wrong as I am not very familiar with the underlying library its hard to debug this one

from ssh2-python.

JoelStienlet avatar JoelStienlet commented on May 18, 2024

Can you check the value of type_mask? I've used LIBSSH2_KNOWNHOST_TYPE_PLAIN:
from ssh2.knownhost import LIBSSH2_KNOWNHOST_TYPE_PLAIN
kh.checkp(args.host.encode('utf-8'), args.port, host_key, LIBSSH2_KNOWNHOST_TYPE_PLAIN )

from ssh2-python.

pkittenis avatar pkittenis commented on May 18, 2024

Hi there,

Thanks for the interest and report.

The example script is correct.

The reason it does not work for the above is because the key type in the hosts file is ecdsa-sha2-nistp256 while the example script tries to verify RSA or DSS keys. The underlying library is low level and requires explicit key type checks.

Python version does not matter, though the host parameter must be in bytes - b'localhost' - currently. It could take unicode as well for ease of use, though unicode characters in known host files are not valid.

The exception is because a matching host and key type cannot be found - there can be multiple keys per host of different types. On type check errors where a host does match the error returned is KnownHostCheckNotFoundError regardless.

There is now ECDSA and ED25519 key type support in libssh2, neither of which have flags exposed in ssh2.knownhost. The example script might also check for all possible key types.

PRs welcome for both of these.

from ssh2-python.

pkittenis avatar pkittenis commented on May 18, 2024

Flags updated for latest libssh2. Examples welcome.

from ssh2-python.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.