Class: SSHKit::Backend::Netssh::KnownHostsKeys
- Inherits:
-
Object
- Object
- SSHKit::Backend::Netssh::KnownHostsKeys
- Defined in:
- lib/sshkit/backends/netssh/known_hosts.rb
Instance Method Summary collapse
-
#initialize(path) ⇒ KnownHostsKeys
constructor
A new instance of KnownHostsKeys.
- #keys_for(hostlist) ⇒ Object
Constructor Details
#initialize(path) ⇒ KnownHostsKeys
Returns a new instance of KnownHostsKeys.
10 11 12 13 14 15 |
# File 'lib/sshkit/backends/netssh/known_hosts.rb', line 10 def initialize(path) super() @path = File.(path) @hosts_keys = nil @mutex = Mutex.new end |
Instance Method Details
#keys_for(hostlist) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/sshkit/backends/netssh/known_hosts.rb', line 17 def keys_for(hostlist) keys, hashes = hosts_keys, hosts_hashes parse_file unless keys && hashes keys, hashes = hosts_keys, hosts_hashes host_names = hostlist.split(',') keys_found = host_names.map { |h| keys[h] || [] }.compact.inject(:&) 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 end [] end |