Class: Net::SSH::Verifiers::Secure
- Inherits:
-
Object
- Object
- Net::SSH::Verifiers::Secure
- Defined in:
- lib/net/ssh/verifiers/secure.rb
Overview
Does a strict host verification, looking the server up in the known host files to see if a key has already been seen for this server. If this server does not appear in any host file, an exception will be raised (HostKeyUnknown). This is in contrast to the “Strict” class, which will silently add the key to your known_hosts file. If the server does appear at least once, but the key given does not match any known for the server, an exception will be raised (HostKeyMismatch). Otherwise, this returns true.
Direct Known Subclasses
Instance Method Summary collapse
Instance Method Details
#verify(arguments) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/net/ssh/verifiers/secure.rb', line 15 def verify(arguments) = arguments[:session]. host = [:host_key_alias] || arguments[:session].host_as_string matches = Net::SSH::KnownHosts.search_for(host, arguments[:session].) # We've never seen this host before, so raise an exception. if matches.empty? process_cache_miss(host, arguments, HostKeyUnknown, "is unknown") end # If we found any matches, check to see that the key type and # blob also match. found = matches.any? do |key| key.ssh_type == arguments[:key].ssh_type && key.to_blob == arguments[:key].to_blob end # If a match was found, return true. Otherwise, raise an exception # indicating that the key was not recognized. unless found process_cache_miss(host, arguments, HostKeyMismatch, "does not match") end found end |