diff options
author | Jamis Buck <jamis@37signals.com> | 2008-03-22 16:18:35 -0600 |
---|---|---|
committer | Jamis Buck <jamis@37signals.com> | 2008-03-22 16:18:35 -0600 |
commit | dbc084691d1f64931f8659b2baa3bb1df6aba700 (patch) | |
tree | 0d220b25bc02756ecbe880e71da940059822bf96 /lib/net/ssh | |
parent | bccc80a7ef7bf824723bc748ddb53ffcea3bb76e (diff) | |
download | net-ssh-dbc084691d1f64931f8659b2baa3bb1df6aba700.tar.gz |
support for :host_key_alias
Diffstat (limited to 'lib/net/ssh')
-rw-r--r-- | lib/net/ssh/config.rb | 5 | ||||
-rw-r--r-- | lib/net/ssh/transport/algorithms.rb | 2 | ||||
-rw-r--r-- | lib/net/ssh/verifiers/strict.rb | 7 |
3 files changed, 9 insertions, 5 deletions
diff --git a/lib/net/ssh/config.rb b/lib/net/ssh/config.rb index 25f40bd..ef09a6c 100644 --- a/lib/net/ssh/config.rb +++ b/lib/net/ssh/config.rb @@ -16,6 +16,7 @@ module Net; module SSH # * GlobalKnownHostsFile => :global_known_hosts_file # * HostBasedAuthentication => maps to the :auth_methods option # * HostKeyAlgorithms => maps to :host_key option + # * HostKeyAlias => :host_key_alias # * IdentityFile => maps to the :keys option # * Macs => maps to the :hmac option # * PasswordAuthentication => maps to the :auth_methods option @@ -25,7 +26,7 @@ module Net; module SSH # * UserKnownHostsFile => :user_known_hosts_file # #-- - # FIXME: HostKeyAlias, HostName, LocalForward, SendEnv, User + # FIXME: HostName, LocalForward, SendEnv, User #++ # # Note that you will never need to use this class directly--you can control @@ -116,7 +117,7 @@ module Net; module SSH when 'hostkeyalgorithms' then hash[:host_key] = value.split(/,/) when 'hostkeyalias' then - # FIXME + hash[:host_key_alias] = value when 'hostname' then # FIXME when 'identityfile' then diff --git a/lib/net/ssh/transport/algorithms.rb b/lib/net/ssh/transport/algorithms.rb index 411317e..557648c 100644 --- a/lib/net/ssh/transport/algorithms.rb +++ b/lib/net/ssh/transport/algorithms.rb @@ -210,7 +210,7 @@ module Net; module SSH; module Transport # make sure the host keys are specified in preference order, where any # existing known key for the host has preference. - existing_keys = KnownHosts.search_for(session.host_as_string, options) + existing_keys = KnownHosts.search_for(options[:host_key_alias] || session.host_as_string, options) host_keys = existing_keys.map { |key| key.ssh_type }.uniq algorithms[:host_key].each do |name| host_keys << name unless host_keys.include?(name) diff --git a/lib/net/ssh/verifiers/strict.rb b/lib/net/ssh/verifiers/strict.rb index d42c32a..ef8edfd 100644 --- a/lib/net/ssh/verifiers/strict.rb +++ b/lib/net/ssh/verifiers/strict.rb @@ -11,7 +11,8 @@ module Net; module SSH; module Verifiers # Otherwise, this returns true. class Strict def verify(arguments) - host = arguments[:session].host_as_string + options = arguments[:session].options + host = options[:host_key_alias] || arguments[:session].host_as_string matches = Net::SSH::KnownHosts.search_for(host, arguments[:session].options) # we've never seen this host before, so just automatically add the key. @@ -42,7 +43,9 @@ module Net; module SSH; module Verifiers def process_cache_miss(host, args) exception = HostKeyMismatch.new("fingerprint #{args[:fingerprint]} does not match for #{host.inspect}") exception.data = args - exception.callback = Proc.new { Net::SSH::KnownHosts.add(host, args[:key], args[:session].options) } + exception.callback = Proc.new do + Net::SSH::KnownHosts.add(host, args[:key], args[:session].options) + end raise exception end end |