Skip to content

client: prefer keytype from known_hosts, more ecdsa server hostkey support - #899

Closed
ploxiln wants to merge 6 commits into
paramiko:masterfrom
ploxiln:client_hostkey_req
Closed

ploxiln wants to merge 6 commits into
paramiko:masterfrom
ploxiln:client_hostkey_req

Conversation

@ploxiln

@ploxiln ploxiln commented Feb 20, 2017

Copy link
Copy Markdown
Contributor

fixes #865

Note that Transport.connect() already does something similar: if a hostkey is passed, it sets _preferred_keys to the type of that hostkey. (But SSHClient does not use Transport.connect(), it uses the alternative start_client() for more control.)

See commit messages for more details. Also, I'll be doing a bit more testing with different sets of key types available on the server, just to be sure...

@ploxiln

ploxiln commented Feb 20, 2017 •

Copy link
Copy Markdown
Contributor Author

looks like I re-discovered #794 (I had forgotten the details of that), I'll remove that change from this PR if/when that (linked diff) gets in

@ploxiln ploxiln changed the title client: prefer keytype in known_hosts, more ecdsa server hostkey support client: prefer keytype from known_hosts, more ecdsa server hostkey support Feb 20, 2017
@coveralls

coveralls commented Feb 20, 2017 •

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.07%) to 74.268% when pulling 814ba00 on ploxiln:client_hostkey_req into cc0a225 on paramiko:master.

@ploxiln ploxiln mentioned this pull request Feb 20, 2017
@coveralls

coveralls commented Feb 21, 2017 •

Copy link
Copy Markdown

Coverage Status

Coverage decreased (-0.05%) to 74.189% when pulling 718088c on ploxiln:client_hostkey_req into 281e1f1 on paramiko:master.

@coveralls

coveralls commented Feb 21, 2017 •

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.004%) to 74.244% when pulling 82a6432 on ploxiln:client_hostkey_req into 281e1f1 on paramiko:master.

_verify_key() only supported ecdsa-sha2-nistp256, ssh-rsa, ssh-dsa
If we have server host keys that will be checked, need need to
negotiate for one of the types we have. Commonly, openssh could
have saved an ecdsa key but SSHClient will let the Transport
negotiate for an rsa key.

Then it would consider a key of a non-corresponding type to be "missing".
That situation is also now a BadHostKeyException.
openssh client seems to prefer ecdsa server host keys
@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.008%) to 74.217% when pulling b53915d on ploxiln:client_hostkey_req into 421f03b on paramiko:master.

3 similar comments
@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.008%) to 74.217% when pulling b53915d on ploxiln:client_hostkey_req into 421f03b on paramiko:master.

@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.008%) to 74.217% when pulling b53915d on ploxiln:client_hostkey_req into 421f03b on paramiko:master.

@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.008%) to 74.217% when pulling b53915d on ploxiln:client_hostkey_req into 421f03b on paramiko:master.

@coveralls

coveralls commented Feb 22, 2017 •

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.05%) to 74.258% when pulling b53915d on ploxiln:client_hostkey_req into 421f03b on paramiko:master.

@coveralls

coveralls commented Feb 22, 2017 •

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.05%) to 74.262% when pulling 4cd4f51 on ploxiln:client_hostkey_req into 421f03b on paramiko:master.

@ploxiln

ploxiln commented Feb 22, 2017

Copy link
Copy Markdown
Contributor Author

Made some updates:

Regarding supported_key_format_identifiers(), I kinda prefer just writing the key type strings out literally, both in _key_info and _preferred_keys. They're short, there's just 3 of them, they won't be changing for years, and the order in _preferred_keys matters. The next type to be implemented will be a new class for curve25519. Currently in this PR I don't write them literally, I call supported_key_format_identifiers() to cater to the existing style, but I'd be glad to change to literals if you like that.

Tested with known_hosts containing just:

  • valid ecdsa-sha2-nistp256
  • wrong ecdsa-sha2-nistp256
  • valid ssh-rsa
  • wrong ssh-rsa
  • valid ecdsa-sha2-nistp521

with the server configured with:

  • just ssh-rsa
  • just ecdsa-sha2-nistp256
  • just ecdsa-sha2-nistp521
  • all three enabled

And succeeds / fails where I expect 😁

I think this approach is more correct than #900.

In this approach, the client prefers the key type(s) that it has in known_hosts. This enhances Fabric behavior with no changes to Fabric. This is also what the openssh client seems to do. Also, by coincidence, this is also what putty now does as of the 0.68 release yesterday (since it only now supports ecdsa keys):

Host key preference policy change: PuTTY prefers host key formats for which it already knows the key.

In #900, the user of the SSHClient must specify the correct key type. That would require changes to Fabric to be useful with it.

Further, note that currently, and in #900, if a different key type is negotiated from the server than is present in known_hosts, it is considered that they host key is missing when really it is a host key mismatch.

With this PR, if the server is not configured with a key type that is in known_hosts, it will fail at host key negotiation. But also, if that did succeed for some reason, it will be a host key mismatch.

@djmattyg007

Copy link
Copy Markdown

This issue is hitting me quite hard. I'd really appreciate it if this could be merged and a new release created ASAP.

@bitprophet bitprophet added this to the 2.2 milestone Feb 22, 2017
@ploxiln

ploxiln commented Feb 22, 2017

Copy link
Copy Markdown
Contributor Author

If any parts of this could be considered "fixes" for existing functionality, I would be willing to open a branch with the desired parts backported to the desired older version, then rebase this on top of master after that whole process goes through. Or just having all this in the 2.2 release is also fine with me :)

@ploxiln

ploxiln commented Feb 23, 2017

Copy link
Copy Markdown
Contributor Author

I'm going to open two new pull requests, as an alternative to this one. You should see the references to them show up below this comment later today :)

  • one will be for master, and include the ecdsa key specific stuff (support for nistp384 and nistp521, and prefer ecdsa keys by default)
  • the other will be for an older branch, with the SSHClient host key type selection fix

@ploxiln

ploxiln commented Feb 23, 2017

Copy link
Copy Markdown
Contributor Author

alternative PRs opened ^^

@bitprophet

Copy link
Copy Markdown
Member

Closing in favor of the newer PRs, thanks!

@bitprophet bitprophet closed this Feb 23, 2017
@ploxiln
ploxiln deleted the client_hostkey_req branch September 13, 2017 18:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

only rsa host key checked

4 participants