Skip to content

SSHClient: request host key type from known_hosts - #910

Merged
bitprophet merged 4 commits into
paramiko:2.1from
ploxiln:client_hostkey_req_backport
Jun 9, 2017
Merged

bitprophet merged 4 commits into
paramiko:2.1from
ploxiln:client_hostkey_req_backport

Conversation

@ploxiln

@ploxiln ploxiln commented Feb 23, 2017

Copy link
Copy Markdown
Contributor

fixes #865

one part of an alternative set of PRs to #899

I only backported this to 2.1 because there were some changes around t.start_client() in 2.0 and 2.1 which make forward-merging have possibly tricky conflicts there. I can backport further if you would like, and won't mind the conflict resolution when forward-merging :)

@ploxiln
ploxiln force-pushed the client_hostkey_req_backport branch from 59285b8 to c4519ec Compare February 23, 2017 20:48
@coveralls

coveralls commented Feb 23, 2017 •

Copy link
Copy Markdown

Coverage Status

Coverage decreased (-0.08%) to 74.203% when pulling c4519ec on ploxiln:client_hostkey_req_backport into 5061ee6 on paramiko:master.

@bitprophet

bitprophet commented Feb 23, 2017 •

Copy link
Copy Markdown
Member

Nah, at this point anything that makes backporting to 1.x hard is a good argument for "don't bother".

If someone who's stuck on 1.x (despite the security concerns, which was one reason we even did the backend switch in 2.0) is super upset they don't have such a change, they can submit their own PR :D

@ploxiln

ploxiln commented Jun 1, 2017

Copy link
Copy Markdown
Contributor Author

I can rebase this and resolve conflicts if you like (... #974 causes conflicts for pretty much all pull requests against 2.0+ ...)

@bitprophet

bitprophet commented Jun 1, 2017 •

Copy link
Copy Markdown
Member

That'd be great, thanks! (And, yes, it does, but I'd rather not let compatibility with PRs prevent necessary change. For example all of Fabric 1's PRs will get broked good once 2.0 becomes the new master... 🙃 )

@ploxiln
ploxiln force-pushed the client_hostkey_req_backport branch 2 times, most recently from 281d248 to 5fc547b Compare June 2, 2017 03:49
@ploxiln

ploxiln commented Jun 2, 2017

Copy link
Copy Markdown
Contributor Author

Rebased, resolved conflicts, and also removed a commit which tweaked a log message which I realized is not related to host keys (it's related to user auth keys).

Manually tested and verified, but I'm working on a proper automated test...

@ploxiln

ploxiln commented Jun 2, 2017

Copy link
Copy Markdown
Contributor Author

Added proper tests for this. If I run them against the 2.1 branch (without this PR), the ones which I expect to fail do so:

test_host_key_negotiation_1 (test_client.SSHClientTest) ... /Users/pierce/scratch/fabwork/paramiko/paramiko/client.py:708: UserWarning: Unknown ssh-rsa host key for [127.0.0.1]:50456: 60733844cb5186657fdedaa22b5a57d5
  key.get_fingerprint())))
FAIL
test_host_key_negotiation_2 (test_client.SSHClientTest) ... ok
test_host_key_negotiation_3 (test_client.SSHClientTest) ... ERROR
test_host_key_negotiation_4 (test_client.SSHClientTest) ... ok

@ploxiln

ploxiln commented Jun 6, 2017

Copy link
Copy Markdown
Contributor Author

Now that #981 is merged, I can revise this to use the SecurityOptions api to change the order of the preferred host key types (to put the available key first). I may do very soon that if it's not too late...

@ploxiln
ploxiln force-pushed the client_hostkey_req_backport branch from 10306da to 4fd1af0 Compare June 6, 2017 05:37
ploxiln added a commit to ploxiln/paramiko-ng that referenced this pull request Jun 6, 2017
@ploxiln

ploxiln commented Jun 6, 2017

Copy link
Copy Markdown
Contributor Author

changed to use SecurityOptions, will squash down a bit if that looks good

ploxiln added 4 commits June 7, 2017 01:58
If we have a host keys that will be checked, we need to
negotiate for the type we have. Commonly, openssh could
have saved an ecdsa key in known_hosts, 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.

Before this change, a man-in-the-middle attack on the paramiko ssh
client was possible by having only a host key type which differs from
what the client has in known_hosts (and then giving any key of that type).
@ploxiln
ploxiln force-pushed the client_hostkey_req_backport branch from 7cc1f22 to 4526052 Compare June 7, 2017 06:03
@bitprophet

Copy link
Copy Markdown
Member

Hrm, this appears to conflict with the ResourceManager removal due to the same chunk moving around, but I think it's just re-applying 2 line nukes after merging your changes, so I've done that.

@bitprophet
bitprophet merged commit 4526052 into paramiko:2.1 Jun 9, 2017
@ploxiln

ploxiln commented Jun 10, 2017

Copy link
Copy Markdown
Contributor Author

Your merge conflict resolution looks correct - thanks!

@ploxiln
ploxiln deleted the client_hostkey_req_backport branch September 13, 2017 18:42
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.

3 participants