Sha256: 780e75e9a9500dfb7acce100c78ff5d1846a57a56899dc3360ded1c632e58ec8

Contents?: true

Size: 1.13 KB

Versions: 47

Compression:

Stored size: 1.13 KB

Contents

require 'net/ssh/verifiers/accept_new'

module Net
  module SSH
    module Verifiers

      # Basically the same as the AcceptNew verifier, but does not try to actually
      # verify a connection if the server is the localhost and the port is a
      # nonstandard port number. Those two conditions will typically mean the
      # connection is being tunnelled through a forwarded port, so the known-hosts
      # file will not be helpful (in general).
      class AcceptNewOrLocalTunnel < AcceptNew
        # Tries to determine if the connection is being tunnelled, and if so,
        # returns true. Otherwise, performs the standard strict verification.
        def verify(arguments)
          return true if tunnelled?(arguments)
          super
        end

        private

        # A connection is potentially being tunnelled if the port is not 22,
        # and the ip refers to the localhost.
        def tunnelled?(args)
          return false if args[:session].port == Net::SSH::Transport::Session::DEFAULT_PORT

          ip = args[:session].peer[:ip]
          return ip == "127.0.0.1" || ip == "::1"
        end
      end

    end
  end
end

Version data entries

47 entries across 40 versions & 3 rubygems

Version Path
vagrant-unbundled-2.2.19.0 vendor/bundle/ruby/3.0.0/gems/net-ssh-6.1.0/lib/net/ssh/verifiers/accept_new_or_local_tunnel.rb
vagrant-unbundled-2.2.18.0 vendor/bundle/ruby/3.0.0/gems/net-ssh-6.1.0/lib/net/ssh/verifiers/accept_new_or_local_tunnel.rb
vagrant-unbundled-2.2.16.0 vendor/bundle/ruby/2.7.0/gems/net-ssh-6.2.0.rc1/lib/net/ssh/verifiers/accept_new_or_local_tunnel.rb
vagrant-unbundled-2.2.16.0 vendor/bundle/ruby/3.0.0/gems/net-ssh-6.1.0/lib/net/ssh/verifiers/accept_new_or_local_tunnel.rb
net-ssh-6.2.0.rc2 lib/net/ssh/verifiers/accept_new_or_local_tunnel.rb
vagrant-unbundled-2.2.14.0 vendor/bundle/ruby/2.7.0/gems/net-ssh-6.2.0.rc1/lib/net/ssh/verifiers/accept_new_or_local_tunnel.rb
vagrant-unbundled-2.2.10.0 vendor/bundle/ruby/2.7.0/gems/net-ssh-6.1.0/lib/net/ssh/verifiers/accept_new_or_local_tunnel.rb
net-ssh-6.2.0.rc1 lib/net/ssh/verifiers/accept_new_or_local_tunnel.rb
net-ssh-6.2.0.beta1 lib/net/ssh/verifiers/accept_new_or_local_tunnel.rb
net-ssh-6.1.0 lib/net/ssh/verifiers/accept_new_or_local_tunnel.rb
vagrant-unbundled-2.2.9.0 vendor/bundle/ruby/2.7.0/gems/net-ssh-5.2.0/lib/net/ssh/verifiers/accept_new_or_local_tunnel.rb
vagrant-unbundled-2.2.8.0 vendor/bundle/ruby/2.7.0/gems/net-ssh-5.2.0/lib/net/ssh/verifiers/accept_new_or_local_tunnel.rb
net-ssh-6.1.0.rc1 lib/net/ssh/verifiers/accept_new_or_local_tunnel.rb
net-ssh-6.0.2 lib/net/ssh/verifiers/accept_new_or_local_tunnel.rb
net-ssh-6.0.1 lib/net/ssh/verifiers/accept_new_or_local_tunnel.rb
net-ssh-6.0.0 lib/net/ssh/verifiers/accept_new_or_local_tunnel.rb
net-ssh-6.0.0.rc1 lib/net/ssh/verifiers/accept_new_or_local_tunnel.rb
vagrant-unbundled-2.2.7.0 vendor/bundle/ruby/2.7.0/gems/net-ssh-5.1.0/lib/net/ssh/verifiers/accept_new_or_local_tunnel.rb
vagrant-unbundled-2.2.7.0 vendor/bundle/ruby/2.6.0/gems/net-ssh-5.1.0/lib/net/ssh/verifiers/accept_new_or_local_tunnel.rb
net-ssh-6.0.0.beta2 lib/net/ssh/verifiers/accept_new_or_local_tunnel.rb