Sha256: 82559f4875873ae09281bde39597360b6543bfa4b33bd0b65c17d8b7348d8938

Contents?: true

Size: 1.92 KB

Versions: 53

Compression:

Stored size: 1.92 KB

Contents

require 'net/ssh/errors'
require 'net/ssh/known_hosts'

module Net; module SSH; module Verifiers

  # 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.
  class Secure
    def verify(arguments)
      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 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

    private

    def process_cache_miss(host, args, exc_class, message)
      exception = exc_class.new("fingerprint #{args[:fingerprint]} " +
                                "#{message} for #{host.inspect}")
      exception.data = args
      exception.callback = Proc.new do
        Net::SSH::KnownHosts.add(host, args[:key], args[:session].options)
      end
      raise exception
    end
  end

end; end; end

Version data entries

53 entries across 51 versions & 9 rubygems

Version Path
vagrant-unbundled-1.9.1.1 vendor/bundle/ruby/2.4.0/gems/net-ssh-3.0.2/lib/net/ssh/verifiers/secure.rb
vagrant-compose-yaml-0.1.3 vendor/bundle/ruby/2.2.0/gems/net-ssh-3.0.2/lib/net/ssh/verifiers/secure.rb
vagrant-compose-yaml-0.1.2 vendor/bundle/ruby/2.2.0/gems/net-ssh-3.0.2/lib/net/ssh/verifiers/secure.rb
vagrant-compose-yaml-0.1.1 vendor/bundle/ruby/2.2.0/gems/net-ssh-3.0.2/lib/net/ssh/verifiers/secure.rb
vagrant-compose-yaml-0.1.0 vendor/bundle/ruby/2.2.0/gems/net-ssh-3.0.2/lib/net/ssh/verifiers/secure.rb
vagrant-unbundled-1.8.5.2 vendor/bundle/ruby/2.3.0/gems/net-ssh-3.0.2/lib/net/ssh/verifiers/secure.rb
vagrant-unbundled-1.8.5.1 vendor/bundle/ruby/2.3.0/gems/net-ssh-3.0.2/lib/net/ssh/verifiers/secure.rb
vagrant-unbundled-1.8.4.2 vendor/bundle/ruby/2.3.0/gems/net-ssh-3.0.2/lib/net/ssh/verifiers/secure.rb
vagrant-unbundled-1.8.4.1 vendor/bundle/ruby/2.3.0/gems/net-ssh-3.0.2/lib/net/ssh/verifiers/secure.rb
honeybadger-2.4.0 vendor/gems/ruby/2.2.0/gems/net-ssh-2.9.1/lib/net/ssh/verifiers/secure.rb
honeybadger-2.4.0 vendor/gems/ruby/1.9.1/gems/net-ssh-2.9.1/lib/net/ssh/verifiers/secure.rb
honeybadger-2.4.0 vendor/gems/ruby/2.1.0/gems/net-ssh-2.9.1/lib/net/ssh/verifiers/secure.rb
net-ssh-2.9.4 lib/net/ssh/verifiers/secure.rb
vagrant-unbundled-1.8.1.1 vendor/bundle/ruby/2.3.0/gems/net-ssh-3.0.2/lib/net/ssh/verifiers/secure.rb
net-ssh-3.0.2 lib/net/ssh/verifiers/secure.rb
net-ssh-3.0.2.rc1 lib/net/ssh/verifiers/secure.rb
net-ssh-2.9.4.rc1 lib/net/ssh/verifiers/secure.rb
sc_core-0.0.7 test/dummy/vendor/bundle/ruby/2.2.0/gems/net-ssh-3.0.1/lib/net/ssh/verifiers/secure.rb
net-ssh-3.0.1 lib/net/ssh/verifiers/secure.rb
net-ssh-3.0.1.rc1 lib/net/ssh/verifiers/secure.rb