File: accept_new_or_local_tunnel.rb

package info (click to toggle)
ruby-net-ssh 1%3A7.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,804 kB
  • sloc: ruby: 16,999; makefile: 5
file content (33 lines) | stat: -rw-r--r-- 1,155 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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