You need to sign in or sign up before continuing.

net-ssh 8.1.2 → 8.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 66339496243d9984d49aeebce869255bb936e533280674b6a7aaf9de33381cfa
4
- data.tar.gz: f2492cf09d1396dac5731fed8bd5b9def374d7900e30e5c03a7fcf00986bad05
3
+ metadata.gz: de5c9a44083a899c9f60bf1397e3f11e8c4836aebcb20021f995d2d4bd20cbc9
4
+ data.tar.gz: ef226479b6e106df08ac506351ff4d4f0f9328e1dbb8783f10c467dece7d40f8
5
5
  SHA512:
6
- metadata.gz: 54534ecfdc1ef2b0ae192fbdfee3255021100e182c8bec06d48b03d2ea7c669dfa8d626b724d2ccd1f99a3743956196242c13941c39e2363a33c24b2691dce22
7
- data.tar.gz: c0c8bbc852f0ebc46f223668592a5b78484aa816ade2923f56f59552653fa893f683b2fe408ba9f19fc3391bc8d200bfcf90f12384d3bec812cbd62a776f5c1d
6
+ metadata.gz: 2636227f8c7b07768a63fc4e58e5045c28635a569ba01623ddc4623a6a8e6ef6234529825b1d24a096fc72391a87972cfa1d9f437879ddf29a364db5c3d984a6
7
+ data.tar.gz: 8e0666d0a106a34a28fb221df7ace6f9e216199a66de89248af5518cf5d4a949fdb627b8cbaa86dbf1bf71a7c95edeb43a921f230f76b6c093f317f2144b2d83
checksums.yaml.gz.sig CHANGED
Binary file
data/CHANGES.txt CHANGED
@@ -1,3 +1,10 @@
1
+ === 8.2.0
2
+
3
+ * Continue publickey authentication with the next identity, or the same key's file, when the agent refuses or fails to sign, and stop using an agent that closed the connection [#1090]
4
+ * Limit the size of zlib-decompressed packets so a server can't exhaust client memory with a highly compressed packet (reported by the RubyCentral gem security team and the Stripe security team) [#1091]
5
+ * Net::SSH::Test stories that script an `env` channel request no longer raise NoMethodError [#1089]
6
+ * Added `Net::SSH.default_configuration`, a callable receiving the host and its ssh_config options and returning default options for every `Net::SSH.start`, including connections opened by net-sftp, net-scp or SSHKit. Its options override ssh_config and are overridden by options passed to `start`; an option passed as `nil` counts as not given. It can't set `:user` or `:config`, and the options it changes are validated like those passed to `start`. Thanks @fatkodima [#986]
7
+
1
8
  === 8.1.2
2
9
 
3
10
  * Security: verify the proxy's certificate and hostname in `Net::SSH::Proxy::HTTPS` by default, and the hostname with any verifying `:ssl_context`; any certificate was accepted, exposing the proxy credentials to a man-in-the-middle. A self-signed or private CA proxy now needs an `:ssl_context` that trusts it, or one with `verify_mode = OpenSSL::SSL::VERIFY_NONE` to skip verification. Thanks @fuzzyrichie [GHSA-qcf4-j55x-72hv]
@@ -132,7 +132,8 @@ module Net
132
132
  user_identities.reject! { |identity| identity.equal?(corresponding_user_identity) }
133
133
 
134
134
  if !options[:keys_only] || corresponding_user_identity
135
- known_identities[key] = { from: :agent, identity: key }
135
+ fallback = corresponding_user_identity unless corresponding_user_identity&.dig(:from) == :pubkey_file_only
136
+ known_identities[key] = { from: :agent, identity: key, fallback: fallback }.compact
136
137
  yield key
137
138
  end
138
139
  end
@@ -199,15 +200,25 @@ module Net
199
200
  end
200
201
 
201
202
  if info[:from] == :agent
202
- raise KeyManagerError, "the agent is no longer available" unless agent
203
+ begin
204
+ raise AgentNotAvailable, "the agent is no longer available" unless agent
203
205
 
204
- case sig_alg
205
- when "rsa-sha2-512"
206
- return agent.sign(info[:identity], data.to_s, Net::SSH::Authentication::Agent::SSH_AGENT_RSA_SHA2_512)
207
- when "rsa-sha2-256"
208
- return agent.sign(info[:identity], data.to_s, Net::SSH::Authentication::Agent::SSH_AGENT_RSA_SHA2_256)
209
- else
210
- return agent.sign(info[:identity], data.to_s)
206
+ case sig_alg
207
+ when "rsa-sha2-512"
208
+ return agent.sign(info[:identity], data.to_s, Net::SSH::Authentication::Agent::SSH_AGENT_RSA_SHA2_512)
209
+ when "rsa-sha2-256"
210
+ return agent.sign(info[:identity], data.to_s, Net::SSH::Authentication::Agent::SSH_AGENT_RSA_SHA2_256)
211
+ else
212
+ return agent.sign(info[:identity], data.to_s)
213
+ end
214
+ rescue AgentError => e
215
+ debug { "agent could not sign: #{e.class} (#{e.message})" }
216
+ # Like OpenSSH, drop an agent that closed the connection so it is not asked (or prompts) again.
217
+ self.use_agent = false if e.is_a?(AgentClosedConnection)
218
+ raise unless info[:fallback]
219
+
220
+ info.replace(info[:fallback])
221
+ return sign(identity, data, sig_alg)
211
222
  end
212
223
  end
213
224
 
@@ -1,6 +1,7 @@
1
1
  require 'net/ssh/buffer'
2
2
  require 'net/ssh/errors'
3
3
  require 'net/ssh/authentication/methods/abstract'
4
+ require 'net/ssh/authentication/agent'
4
5
 
5
6
  module Net
6
7
  module SSH
@@ -78,7 +79,12 @@ module Net
78
79
  sig_data.write_string(session_id)
79
80
  sig_data.append(buffer.to_s)
80
81
 
81
- sig_blob = key_manager.sign(identity, sig_data, sig_alg)
82
+ begin
83
+ sig_blob = key_manager.sign(identity, sig_data, sig_alg)
84
+ rescue Net::SSH::Authentication::AgentError => e
85
+ debug { "publickey skipped (#{fingerprint(identity)}): #{e.message}" }
86
+ return false
87
+ end
82
88
 
83
89
  send_request(identity, username, next_service, alg, sig_blob.to_s)
84
90
  message = session.next_message
@@ -85,7 +85,7 @@ module Net
85
85
  when "exec", "subsystem", "shell" then parts << :string
86
86
  when "exit-status" then parts << :long
87
87
  when "pty-req" then parts.concat(%i[string long long long long string])
88
- when "env" then parts.contact(%i[string string])
88
+ when "env" then parts.concat(%i[string string])
89
89
  else
90
90
  request = Packet.registered_channel_requests(@data[1])
91
91
  raise "don't know what to do about #{@data[1]} channel request" unless request
@@ -1,4 +1,5 @@
1
1
  require 'zlib'
2
+ require 'net/ssh/errors'
2
3
  require 'net/ssh/transport/cipher_factory'
3
4
  require 'net/ssh/transport/hmac'
4
5
 
@@ -11,6 +12,9 @@ module Net
11
12
  # forth. This class will never be instantiated directly, but is used as
12
13
  # part of the internal state of the PacketStream module.
13
14
  class State
15
+ # Mirrors PacketStream::PACKET_MAX_SIZE; legitimate packets never decompress beyond it.
16
+ MAX_DECOMPRESSED_SIZE = 256 * 1024
17
+
14
18
  # The socket object that owns this state object.
15
19
  attr_reader :socket
16
20
 
@@ -131,7 +135,9 @@ module Net
131
135
  data = data.to_s
132
136
  return data unless compression?
133
137
 
134
- decompressor.inflate(data)
138
+ result = String.new
139
+ decompressor.inflate(data) { |chunk| append_decompressed(result, chunk) }
140
+ append_decompressed(result, decompressor.flush_next_out)
135
141
  end
136
142
 
137
143
  # Resets the counters on the state object, but leaves the sequence_number
@@ -191,6 +197,13 @@ module Net
191
197
 
192
198
  private
193
199
 
200
+ def append_decompressed(result, chunk)
201
+ result << chunk
202
+ raise Net::SSH::Exception, "decompressed packet exceeds #{MAX_DECOMPRESSED_SIZE} bytes" if result.bytesize > MAX_DECOMPRESSED_SIZE
203
+
204
+ result
205
+ end
206
+
194
207
  def update_next_iv(data, reset = false)
195
208
  @next_iv << data
196
209
  @next_iv = @next_iv[@next_iv.size - cipher.iv_len..-1]
@@ -49,10 +49,10 @@ module Net
49
49
  MAJOR = 8
50
50
 
51
51
  # The minor component of this version of the Net::SSH library
52
- MINOR = 1
52
+ MINOR = 2
53
53
 
54
54
  # The tiny component of this version of the Net::SSH library
55
- TINY = 2
55
+ TINY = 0
56
56
 
57
57
  # The prerelease component of this version of the Net::SSH library
58
58
  # nil allowed
data/lib/net/ssh.rb CHANGED
@@ -74,6 +74,36 @@ module Net
74
74
  control_master control_path preopen_channels
75
75
  ]
76
76
 
77
+ class << self
78
+ # A callable that supplies default options for every connection made
79
+ # with Net::SSH.start, including those opened by libraries such as
80
+ # net-sftp, net-scp or SSHKit. It is called with the host as passed to
81
+ # +start+ and the options read from ssh_config for it, and returns a Hash
82
+ # of options. Set it to +nil+ to remove it.
83
+ #
84
+ # Options are applied in this order, later ones winning: ssh_config, the
85
+ # hook's Hash, then the options passed to +start+. An option passed to
86
+ # +start+ as +nil+ counts as not given, so the hook's value applies. The
87
+ # hook can't set :user or :config, as both are needed to read ssh_config.
88
+ #
89
+ # Net::SSH.default_configuration = ->(host, ssh_config) {
90
+ # { timeout: ssh_config.fetch(:timeout, 5), keepalive: true }
91
+ # }
92
+ # Net::SSH.start("host", "user") do |ssh|
93
+ # # will have a default 5 seconds connection timeout
94
+ # # will use keepalive
95
+ # end
96
+ attr_reader :default_configuration
97
+
98
+ def default_configuration=(callable)
99
+ unless callable.nil? || callable.respond_to?(:call)
100
+ raise ArgumentError, "Net::SSH.default_configuration must respond to call or be nil, got #{callable.class}"
101
+ end
102
+
103
+ @default_configuration = callable
104
+ end
105
+ end
106
+
77
107
  # The standard means of starting a new SSH connection. When used with a
78
108
  # block, the connection will be closed when the block terminates, otherwise
79
109
  # the connection will just be returned. The yielded (or returned) value
@@ -104,6 +134,8 @@ module Net
104
134
  # option to use its default or ssh_config value; passing +nil+ (or an array
105
135
  # containing +nil+) raises ArgumentError, except for :password,
106
136
  # :passphrase, :logger and :password_prompt, where +nil+ means the default.
137
+ # Options given here override Net::SSH.default_configuration, which
138
+ # overrides ssh_config.
107
139
  #
108
140
  # * :auth_methods => an array of authentication methods to try
109
141
  # * :bind_address => the IP address on the connecting machine to use in
@@ -295,25 +327,19 @@ module Net
295
327
  # If +user+ parameter is nil it defaults to USER from ssh_config, or
296
328
  # local username
297
329
  def self.start(host, user = nil, options = {}, &block)
298
- if options.key?(:paranoid)
299
- raise ArgumentError, ":paranoid has been removed, use :verify_host_key (same values)"
300
- end
301
-
302
- invalid_options = options.keys - VALID_OPTIONS
303
- if invalid_options.any?
304
- raise ArgumentError, "invalid option(s): #{invalid_options.join(', ')}"
305
- end
306
-
307
- reject_nil_options(options)
330
+ validate_options!(options)
308
331
  Multiplex.validate_options!(options)
309
332
  explicit_options = options.keys
310
333
  host_arg = host
311
334
 
312
- options = options.dup
335
+ config_options = configuration_for(host, options.fetch(:config, true), user: user || options[:user])
336
+ default_options = default_options_for(host, config_options)
337
+
338
+ options = config_options.merge(default_options, options.compact)
313
339
  assign_defaults(options)
314
340
 
315
341
  options[:user] = user if user
316
- options = configuration_for(host, options.fetch(:config, true), user: options[:user]).merge(options)
342
+
317
343
  host = options.fetch(:host_name, host)
318
344
 
319
345
  options[:check_host_ip] = true unless options.key?(:check_host_ip)
@@ -418,13 +444,45 @@ module Net
418
444
  }.freeze
419
445
  private_constant :NIL_ALLOWED_OPTIONS, :NIL_OPTION_HINTS
420
446
 
421
- def self.reject_nil_options(options)
447
+ def self.default_options_for(host, config_options)
448
+ return {} unless default_configuration
449
+
450
+ source = "Net::SSH.default_configuration: "
451
+ default_options = default_configuration.call(host, config_options.dup)
452
+ raise ArgumentError, "#{source}must return a Hash, got #{default_options.class}" unless default_options.is_a?(Hash)
453
+
454
+ fixed = default_options.keys & %i[user config]
455
+ raise ArgumentError, "#{source}can't set #{fixed.map(&:inspect).join(', ')}" if fixed.any?
456
+
457
+ # A hook may pass ssh_config's values through (e.g. nil for StrictHostKeyChecking ask), so only what it changes is checked.
458
+ changed = default_options.reject { |key, value| config_options.key?(key) && config_options[key] == value }
459
+ validate_options!(changed, source)
460
+ Multiplex.validate_options!(changed)
461
+ default_options
462
+ end
463
+ private_class_method :default_options_for
464
+
465
+ def self.validate_options!(options, source = "")
466
+ if options.key?(:paranoid)
467
+ raise ArgumentError, "#{source}:paranoid has been removed, use :verify_host_key (same values)"
468
+ end
469
+
470
+ invalid_options = options.keys - VALID_OPTIONS
471
+ if invalid_options.any?
472
+ raise ArgumentError, "#{source}invalid option(s): #{invalid_options.join(', ')}"
473
+ end
474
+
475
+ reject_nil_options(options, source)
476
+ end
477
+ private_class_method :validate_options!
478
+
479
+ def self.reject_nil_options(options, source)
422
480
  nil_keys = options.select do |key, value|
423
481
  !NIL_ALLOWED_OPTIONS.include?(key) && (value.nil? || (value.is_a?(Array) && value.include?(nil)))
424
482
  end.keys
425
483
  return if nil_keys.empty?
426
484
 
427
- message = "nil is not allowed for #{nil_keys.map(&:inspect).join(', ')}; " \
485
+ message = "#{source}nil is not allowed for #{nil_keys.map(&:inspect).join(', ')}; " \
428
486
  "omit #{nil_keys.one? ? 'it' : 'them'} to use the default or ssh_config value"
429
487
  hints = NIL_OPTION_HINTS.values_at(*nil_keys).compact
430
488
  message += ", or pass #{hints.join(', or ')}" if hints.any?
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: net-ssh
3
3
  version: !ruby/object:Gem::Version
4
- version: 8.1.2
4
+ version: 8.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jamis Buck
@@ -32,7 +32,7 @@ cert_chain:
32
32
  ufHf4AX2UIkJbh7zCPkiNCqIr7MSWLNFG/9lOlHYsEJM8XujT1ofPobYx6YSFx/C
33
33
  7HBrI7UX7awt6UvBZebhcHzyMHxg/B5PVQllPA==
34
34
  -----END CERTIFICATE-----
35
- date: 2026-11-08 00:00:00.000000000 Z
35
+ date: 2026-11-25 00:00:00.000000000 Z
36
36
  dependencies:
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: logger
metadata.gz.sig CHANGED
Binary file