x/crypto/ssh: knownhosts does not handle multiple keys with same type #28870
Labels
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Open a SSH connection to a host that has multiple keys in my known_hosts file.
There is a load balancer is in front of two SSH servers that maintain different keys. Although I do not agree the setup is best practice, OpenSSH allows for multiple keys+types for the same hostname.
I used a simple test application to validate:
What did you expect to see?
I expected the host key to be validated in the same manner as OpenSSH.
What did you see instead?
In my test, I added a fake key of the same type and hostname. If the valid key was first, it worked fine. Anything else would fail.
I noticed this from crypto/ssh/knownhosts/knownhosts.go:
Which will only look at the first key of a given type. To work around this, I added another key type for the other server and it worked fine. However, I think this should handle multiple key/type combinations.
The text was updated successfully, but these errors were encountered: