Sha256: 864e61b9b2bcc0ea0db80539331d3c833b4469ead4ba3c08445f12065cb0600e

Contents?: true

Size: 1.13 KB

Versions: 28

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

28 entries across 28 versions & 6 rubygems

Version Path
net-ssh-7.3.0 lib/net/ssh/verifiers/accept_new_or_local_tunnel.rb
net-ssh-7.3.0.rc1 lib/net/ssh/verifiers/accept_new_or_local_tunnel.rb
harbr-2.8.1 vendor/bundle/ruby/3.2.0/gems/net-ssh-7.2.1/lib/net/ssh/verifiers/accept_new_or_local_tunnel.rb
net-ssh-7.2.3 lib/net/ssh/verifiers/accept_new_or_local_tunnel.rb
net-ssh-backports-6.3.6.backports lib/net/ssh/verifiers/accept_new_or_local_tunnel.rb
net-ssh-backports-6.3.5.backports lib/net/ssh/verifiers/accept_new_or_local_tunnel.rb
net-ssh-backports-6.3.4.backports lib/net/ssh/verifiers/accept_new_or_local_tunnel.rb
net-ssh-backports-6.3.3.backports lib/net/ssh/verifiers/accept_new_or_local_tunnel.rb
net-ssh-backports-6.3.2.backports lib/net/ssh/verifiers/accept_new_or_local_tunnel.rb
net-ssh-backports-6.3.1.backports lib/net/ssh/verifiers/accept_new_or_local_tunnel.rb
net-ssh-backports-6.3.0.backports lib/net/ssh/verifiers/accept_new_or_local_tunnel.rb
net-ssh-7.2.2.rc1 lib/net/ssh/verifiers/accept_new_or_local_tunnel.rb
net-ssh-7.2.1 lib/net/ssh/verifiers/accept_new_or_local_tunnel.rb
net-ssh-7.2.1.rc1 lib/net/ssh/verifiers/accept_new_or_local_tunnel.rb
honeybadger-5.4.0 vendor/bundle/ruby/3.2.0/gems/net-ssh-7.2.0/lib/net/ssh/verifiers/accept_new_or_local_tunnel.rb
honeybadger-5.3.0 vendor/bundle/ruby/3.2.0/gems/net-ssh-7.2.0/lib/net/ssh/verifiers/accept_new_or_local_tunnel.rb
net-ssh-7.2.0 lib/net/ssh/verifiers/accept_new_or_local_tunnel.rb
net-ssh-7.2.0.rc1 lib/net/ssh/verifiers/accept_new_or_local_tunnel.rb
net-ssh-7.2.0.beta1 lib/net/ssh/verifiers/accept_new_or_local_tunnel.rb
net-ssh-7.1.0 lib/net/ssh/verifiers/accept_new_or_local_tunnel.rb