Skip to content

Take known_hosts into account when sending the preferrerd key order. - #473

Open
mbr wants to merge 3 commits into
paramiko:mainfrom
mbr:master
Open

mbr wants to merge 3 commits into
paramiko:mainfrom
mbr:master

Conversation

@mbr

@mbr mbr commented Jan 8, 2015

Copy link
Copy Markdown

A common problem when using parameter on systems like Ubuntu or Debian
is that the default host key request by the regular SSH client is
ecdsa-sha2-nistp256, while Paramiko will ask for ssh-rsa first. This will
cause a miss upon the first key lookup and will trigger a "host is not
in known_hosts" warning, even though it's present.

This patch will check if the host is known first and alter the list of
preferred host key types based upon that information before connecting.

I'm not 100% sure everything is in the right place, since I spent most of my time actually tracking down thte issue. However I believe that the current state is a catatrophe! While in theory this should cause affected people to cautiously file bug reports, this is what reality looks like: https://stackoverflow.com/questions/10670217/paramiko-unknown-server - cannot get it working? oh well, better disable host key checking (which is conveniently named "auto add" instead).

mbr added 3 commits January 8, 2015 13:53
A common problem when using parameter on systems like Ubuntu or Debian
is that the default host key request by the regular SSH client is
ecdsa-sha2-nistp256, while Paramiko will ask for ssh-rsa first. This will
cause a miss upon the first key lookup and will trigger an "host is not
in known_hosts" warning, even though it's present.

This patch will check if the host is known first and alter the list of
preferred host key types based upon that information before connecting.
@bitprophet

Copy link
Copy Markdown
Member

This sounds very familiar, I don't have time to dig deeply into the rest of the stuff flagged as key-related ( Keys ) but suspect it's probably closely related. Adding to the label so I come back and look when I tackle that area (see mostly #387)

@mbr

mbr commented Jan 27, 2015

Copy link
Copy Markdown
Author

Thanks. I actually missed that it was somewhat of a known problem. I do hope it's a priority, because as I said above, it seriously compromises the actual security of many systems out there.

If I can do more to help, let me know.

@j9ac9k

j9ac9k commented Jun 28, 2015

Copy link
Copy Markdown

Can confirm this is the same issue as #529 ...applying mbr@d516837 mbr@b7f10c7 and mbr@b7fbb8d fixed the issue for me.

@finjulhich

Copy link
Copy Markdown

Also confirm what j9ac9k commented on 28 Jun.
Although I only applied the first 2 commits in his comment, as the 3rd one is identical to the 2nd one.

@mc3

mc3 commented May 27, 2016

Copy link
Copy Markdown

Being not compatible with command line ssh tools is a big issue for me:

  File "/usr/local/py_venv/p35ca/lib/python3.5/site-packages/paramiko/client.py", line 361, in connect
    server_key)
  File "/usr/local/py_venv/p35ca/lib/python3.5/site-packages/paramiko/client.py", line 648, in missing_host_key
    raise SSHException('Server %r not found in known_hosts' % hostname)
paramiko.ssh_exception.SSHException: Server 'bh3' not found in known_hosts
(p35ca)[root@hermes /usr/local/py_app/CA]# host bh3
bh3.lrau.net has address 91.216.35.170
bh3.lrau.net has IPv6 address 2a02:d40:2:18::70
(p34ca)[root@hermes /usr/local/py_app/CA]# grep bh3 ~/.ssh/known_hosts 
bh3 ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBHy/V8HrE1oMGmZdCSo+6TXFcVuDY6Vx8bCsm2Y8jshNvgE+oOGHb+9ZqltmZrsq7qoG4CMYbB9cNKvRAw6/ufE=
bh3.lrau.net ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBHy/V8HrE1oMGmZdCSo+6TXFcVuDY6Vx8bCsm2Y8jshNvgE+oOGHb+9ZqltmZrsq7qoG4CMYbB9cNKvRAw6/ufE=
(p34ca)[root@hermes /usr/local/py_app/CA]# ssh -V
OpenSSH_6.6.1p1, OpenSSL 1.0.1p-freebsd 9 Jul 2015

That missing functionality prevents me from migrating from mbr/paramiko to paramiko/paramiko.

@Caligatio

Copy link
Copy Markdown

I just ran into this problem today and it set me back an hour or two. The proposed patch by @mbr looks like it's going down the right path but doesn't appear to take into account non-system known_hosts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants