Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions lib/sshkit/backends/netssh/known_hosts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,8 @@ def keys_for(hostlist)
return keys_found unless keys_found.empty?

host_names.each do |host|
hashes.each do |(hmac, salt), hash_keys|
if OpenSSL::HMAC.digest(sha1, salt, host) == hmac
return hash_keys
end
end
hash_keys = hashes.select { |(hmac, salt), _key| OpenSSL::HMAC.digest(sha1, salt, host) == hmac }.map(&:last)
return hash_keys unless hash_keys.empty?
end

[]
Expand Down
3 changes: 3 additions & 0 deletions test/known_hosts/github_hash_multiple_keys
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
|1|0FiqBFoMULRtWBgKU8KTL6frD3U=|ueXeaGg0qrUX4zu56MvbuWVtZ9g= ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQCj7ndNxQowgcQnjshcLrqPEiiphnt+VTTvDP6mHBL9j1aNUkY4Ue1gvwnGLVlOhGeYrnZaMgRK6+PKCUXaDbC7qtbW8gIkhL7aGCsOr/C56SJMy/BCZfxd1nWzAOxSDPgVsmerOBYfNqltV9/hWCqBywINIR+5dIg6JTJ72pcEpEjcYgXkE2YEFXV1JHnsKgbLWNlhScqb2UmyRkQyytRLtL+38TGxkxCflmO+5Z8CSSNY7GidjMIZ7Q4zMjA2n1nGrlTDkzwDCsw+wqFPGQA179cnfGWOWRVruj16z6XyvxvjJwbz0wQZ75XK5tKSb7FNyeIEs4TT4jk+S4dhPeAUC5y+bDYirYgM4GC7uEnztnZyaVWQ7B381AK4Qdrwt51ZqExKbQpTUNn+EjqoTwvqNj4kqx5QUCI0ThS/YkOxJCXmPUWZbhjpCg56i+2aB6CmK2JGhn57K5mj0MNdBXA4/WnwH6XoPWJzK5Nyu2zB3nAZp+S5hpQs+p1vN1/wsjk=
|1|6ogAl769sRmpOj/900YiFBetsSI=|Zs/ZvQZgOOz1zuP0LI8kNyhBF6w= ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOMqqnkVzrm0SdG6UOoqKLsabgH5C9okWi0dh2l9GKJl
|1|y3arMhNvGwdwUh0bg0F/eCZiDqg=|flAPgsDbEX+zvqECZIoMri52V7k= ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBEmKSENjQEezOmxkZMy7opKgwFB9nkt5YRrYMjNuG5N87uRgg6CLrbo5wAdT/y6v0mKV0U2w0WZ2YB/++Tpockg=
8 changes: 8 additions & 0 deletions test/unit/backends/test_netssh.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,14 @@ def test_known_hosts_for_when_an_host_hash_is_recognized
perform_known_hosts_test('github_hash', 'github.com')
end

def test_known_hosts_for_when_host_hashes_are_recognized_for_multiple_keys
source = File.join(File.dirname(__FILE__), '../../known_hosts', 'github_hash_multiple_keys')
kh = Netssh::KnownHosts.new
keys = kh.search_for('github.com', user_known_hosts_file: source, global_known_hosts_file: Tempfile.new('sshkit-test').path)

assert_equal(%w(ecdsa-sha2-nistp256 ssh-ed25519 ssh-rsa), keys.map(&:ssh_type).sort)
end

def test_known_hosts_for_with_multiple_hosts
perform_known_hosts_test('github', '192.30.252.123,github.com', 0)
perform_known_hosts_test('github_ip', '192.30.252.123,github.com', 1)
Expand Down