Skip to content

Return all keys for hashed known_hosts entries - #587

Open
ssaunier wants to merge 2 commits into
capistrano:masterfrom
ssaunier:hashed-known-hosts-all-keys
Open

ssaunier wants to merge 2 commits into
capistrano:masterfrom
ssaunier:hashed-known-hosts-all-keys

Conversation

@ssaunier

Copy link
Copy Markdown

ssh-keyscan -H (and OpenSSH with HashKnownHosts yes) writes one hashed line per key type, each with its own salt:

|1|saltA|hashA ssh-rsa AAAA...
|1|saltB|hashB ssh-ed25519 AAAA...
|1|saltC|hashC ecdsa-sha2-nistp256 AAAA...

KnownHostsKeys#keys_for returned the key from the first hashed line that matched the host, and ignored the others. If the server then negotiated a different key type (e.g. ssh-ed25519 while the first line is ssh-rsa), verification failed with Net::SSH::HostKeyMismatch, even though the key is in known_hosts. Unhashed lines don't have this problem, because their keys are collected per host.

This change collects the keys from every matching hashed line instead. The added test uses a hashed fixture with GitHub's three published host keys. Before the change, only the ssh-rsa key was returned.

Reported downstream in basecamp/kamal#1814.

Not changed here: a file mixing unhashed and hashed lines for the same host still returns only the unhashed keys, and hashed lines for the name and the IP aren't combined. Both differ from Net::SSH::KnownHosts, as does the unhashed case in #585. They could be handled separately if wanted.

The functional suite's test_ssh_option_merge failure on CI with net-ssh ≥ 8.1 is unrelated, and is fixed in #586.

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.

1 participant