Class: Net::SSH::Multiplex::ProxyTransport

Inherits:
Object
  • Object
show all
Includes:
Connection::Constants, Loggable
Defined in:
lib/net/ssh/multiplex/proxy_transport.rb

Overview

Stands in for Net::SSH::Transport::Session underneath a Net::SSH::Connection::Session when connected through an OpenSSH ControlMaster in proxy mode. Key exchange, rekeying, host key verification and authentication all belong to the master, so the matching transport methods are no-ops or raise NotSupportedOverControlMaster.

Constant Summary collapse

DEFAULT_PORT =
22
UNSUPPORTED_CHANNEL_REQUESTS =

Channel requests whose follow-up channel the server opens towards the master, which serves it from its own agent or X display only if it has ForwardAgent or ForwardX11 enabled itself, and rejects it otherwise (clientloop.c, client_input_channel_open).

%w[[email protected] auth-agent-req x11-req].freeze

Constants included from Connection::Constants

Connection::Constants::CHANNEL_CLOSE, Connection::Constants::CHANNEL_DATA, Connection::Constants::CHANNEL_EOF, Connection::Constants::CHANNEL_EXTENDED_DATA, Connection::Constants::CHANNEL_FAILURE, Connection::Constants::CHANNEL_OPEN, Connection::Constants::CHANNEL_OPEN_CONFIRMATION, Connection::Constants::CHANNEL_OPEN_FAILURE, Connection::Constants::CHANNEL_REQUEST, Connection::Constants::CHANNEL_SUCCESS, Connection::Constants::CHANNEL_WINDOW_ADJUST, Connection::Constants::GLOBAL_REQUEST, Connection::Constants::REQUEST_FAILURE, Connection::Constants::REQUEST_SUCCESS

Instance Attribute Summary collapse

Attributes included from Loggable

#logger

Instance Method Summary collapse

Methods included from Loggable

#debug, #error, #fatal, #info, #lwarn

Constructor Details

#initialize(socket, host:, control_path:, options: {}) ⇒ ProxyTransport

Returns a new instance of ProxyTransport.



115
116
117
118
119
120
121
122
123
124
# File 'lib/net/ssh/multiplex/proxy_transport.rb', line 115

def initialize(socket, host:, control_path:, options: {})
  self.logger = options[:logger]
  @host = host
  @port = options[:port] || DEFAULT_PORT
  @options = options
  @control_path = control_path
  @socket = socket
  @socket.extend(PacketSocket)
  @socket.logger = logger
end

Instance Attribute Details

#control_path ⇒ Object (readonly)

The ControlMaster socket path this transport is connected through.



113
114
115
# File 'lib/net/ssh/multiplex/proxy_transport.rb', line 113

def control_path
  @control_path
end

#host ⇒ Object (readonly)

Returns the value of attribute host.



110
111
112
# File 'lib/net/ssh/multiplex/proxy_transport.rb', line 110

def host
  @host
end

#options ⇒ Object (readonly)

Returns the value of attribute options.



110
111
112
# File 'lib/net/ssh/multiplex/proxy_transport.rb', line 110

def options
  @options
end

#port ⇒ Object (readonly)

Returns the value of attribute port.



110
111
112
# File 'lib/net/ssh/multiplex/proxy_transport.rb', line 110

def port
  @port
end

#socket ⇒ Object (readonly)

Returns the value of attribute socket.



110
111
112
# File 'lib/net/ssh/multiplex/proxy_transport.rb', line 110

def socket
  @socket
end

Instance Method Details

#algorithms ⇒ Object



174
175
176
# File 'lib/net/ssh/multiplex/proxy_transport.rb', line 174

def algorithms
  not_supported("the negotiated algorithms")
end

#close ⇒ Object



138
139
140
# File 'lib/net/ssh/multiplex/proxy_transport.rb', line 138

def close
  socket.close unless closed?
end

#closed? ⇒ Boolean

Returns:

  • (Boolean)


134
135
136
# File 'lib/net/ssh/multiplex/proxy_transport.rb', line 134

def closed?
  socket.closed?
end

#enqueue_message(message) ⇒ Object



159
160
161
# File 'lib/net/ssh/multiplex/proxy_transport.rb', line 159

def enqueue_message(message)
  socket.enqueue_packet(check_supported(message.to_s))
end

#hint ⇒ Object



168
# File 'lib/net/ssh/multiplex/proxy_transport.rb', line 168

def hint(*); end

#host_as_string ⇒ Object



126
127
128
# File 'lib/net/ssh/multiplex/proxy_transport.rb', line 126

def host_as_string
  @host_as_string ||= port == DEFAULT_PORT ? host.to_s : "[#{host}]:#{port}"
end

#host_key_verifier ⇒ Object



182
183
184
# File 'lib/net/ssh/multiplex/proxy_transport.rb', line 182

def host_key_verifier
  not_supported("host key verification")
end

#host_keys ⇒ Object



178
179
180
# File 'lib/net/ssh/multiplex/proxy_transport.rb', line 178

def host_keys
  not_supported("the host keys")
end

#next_message ⇒ Object



147
148
149
# File 'lib/net/ssh/multiplex/proxy_transport.rb', line 147

def next_message
  poll_message(:block)
end

#peer ⇒ Object



130
131
132
# File 'lib/net/ssh/multiplex/proxy_transport.rb', line 130

def peer
  @peer ||= { ip: nil, port: port.to_i, host: host, canonized: host_as_string }
end

#poll_message(mode = :nonblock) ⇒ Object



151
152
153
# File 'lib/net/ssh/multiplex/proxy_transport.rb', line 151

def poll_message(mode = :nonblock, *)
  socket.next_packet(mode, options[:timeout])
end

#rekey! ⇒ Object

The master rekeys its own connection.



164
# File 'lib/net/ssh/multiplex/proxy_transport.rb', line 164

def rekey!; end

#rekey_as_needed ⇒ Object



166
# File 'lib/net/ssh/multiplex/proxy_transport.rb', line 166

def rekey_as_needed; end

#send_message(message) ⇒ Object



155
156
157
# File 'lib/net/ssh/multiplex/proxy_transport.rb', line 155

def send_message(message)
  socket.send_packet(check_supported(message.to_s))
end

#server_version ⇒ Object



170
171
172
# File 'lib/net/ssh/multiplex/proxy_transport.rb', line 170

def server_version
  not_supported("the server version")
end

#shutdown! ⇒ Object



142
143
144
145
# File 'lib/net/ssh/multiplex/proxy_transport.rb', line 142

def shutdown!
  error { "forcing connection closed" }
  close
end