net-ssh 5.2.0 → 7.0.1

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.
Files changed (122) hide show
  1. checksums.yaml +5 -5
  2. checksums.yaml.gz.sig +0 -0
  3. data/.dockerignore +6 -0
  4. data/.github/config/rubocop_linter_action.yml +4 -0
  5. data/.github/workflows/ci-with-docker.yml +44 -0
  6. data/.github/workflows/ci.yml +87 -0
  7. data/.github/workflows/rubocop.yml +13 -0
  8. data/.gitignore +3 -0
  9. data/.rubocop.yml +16 -2
  10. data/.rubocop_todo.yml +623 -511
  11. data/CHANGES.txt +50 -2
  12. data/Dockerfile +27 -0
  13. data/Dockerfile.openssl3 +17 -0
  14. data/Gemfile +2 -0
  15. data/Gemfile.noed25519 +2 -0
  16. data/Manifest +0 -1
  17. data/README.md +293 -0
  18. data/Rakefile +6 -2
  19. data/appveyor.yml +4 -2
  20. data/docker-compose.yml +23 -0
  21. data/lib/net/ssh/authentication/agent.rb +29 -13
  22. data/lib/net/ssh/authentication/certificate.rb +19 -7
  23. data/lib/net/ssh/authentication/constants.rb +0 -1
  24. data/lib/net/ssh/authentication/ed25519.rb +13 -8
  25. data/lib/net/ssh/authentication/ed25519_loader.rb +5 -8
  26. data/lib/net/ssh/authentication/key_manager.rb +73 -32
  27. data/lib/net/ssh/authentication/methods/abstract.rb +12 -3
  28. data/lib/net/ssh/authentication/methods/hostbased.rb +3 -5
  29. data/lib/net/ssh/authentication/methods/keyboard_interactive.rb +5 -3
  30. data/lib/net/ssh/authentication/methods/none.rb +6 -9
  31. data/lib/net/ssh/authentication/methods/password.rb +2 -3
  32. data/lib/net/ssh/authentication/methods/publickey.rb +56 -16
  33. data/lib/net/ssh/authentication/pageant.rb +97 -97
  34. data/lib/net/ssh/authentication/pub_key_fingerprint.rb +2 -3
  35. data/lib/net/ssh/authentication/session.rb +27 -23
  36. data/lib/net/ssh/buffer.rb +51 -40
  37. data/lib/net/ssh/buffered_io.rb +24 -26
  38. data/lib/net/ssh/config.rb +82 -50
  39. data/lib/net/ssh/connection/channel.rb +101 -87
  40. data/lib/net/ssh/connection/constants.rb +0 -4
  41. data/lib/net/ssh/connection/event_loop.rb +30 -25
  42. data/lib/net/ssh/connection/keepalive.rb +12 -12
  43. data/lib/net/ssh/connection/session.rb +115 -111
  44. data/lib/net/ssh/connection/term.rb +56 -58
  45. data/lib/net/ssh/errors.rb +12 -12
  46. data/lib/net/ssh/key_factory.rb +10 -13
  47. data/lib/net/ssh/known_hosts.rb +106 -39
  48. data/lib/net/ssh/loggable.rb +10 -11
  49. data/lib/net/ssh/packet.rb +1 -1
  50. data/lib/net/ssh/prompt.rb +9 -11
  51. data/lib/net/ssh/proxy/command.rb +1 -2
  52. data/lib/net/ssh/proxy/errors.rb +2 -4
  53. data/lib/net/ssh/proxy/http.rb +18 -20
  54. data/lib/net/ssh/proxy/https.rb +8 -10
  55. data/lib/net/ssh/proxy/jump.rb +8 -10
  56. data/lib/net/ssh/proxy/socks4.rb +2 -4
  57. data/lib/net/ssh/proxy/socks5.rb +3 -6
  58. data/lib/net/ssh/service/forward.rb +9 -8
  59. data/lib/net/ssh/test/channel.rb +24 -26
  60. data/lib/net/ssh/test/extensions.rb +35 -35
  61. data/lib/net/ssh/test/kex.rb +6 -8
  62. data/lib/net/ssh/test/local_packet.rb +0 -2
  63. data/lib/net/ssh/test/packet.rb +3 -3
  64. data/lib/net/ssh/test/remote_packet.rb +6 -8
  65. data/lib/net/ssh/test/script.rb +25 -27
  66. data/lib/net/ssh/test/socket.rb +12 -15
  67. data/lib/net/ssh/test.rb +7 -7
  68. data/lib/net/ssh/transport/algorithms.rb +100 -58
  69. data/lib/net/ssh/transport/cipher_factory.rb +34 -50
  70. data/lib/net/ssh/transport/constants.rb +13 -9
  71. data/lib/net/ssh/transport/ctr.rb +8 -14
  72. data/lib/net/ssh/transport/hmac/abstract.rb +20 -5
  73. data/lib/net/ssh/transport/hmac/md5.rb +0 -2
  74. data/lib/net/ssh/transport/hmac/md5_96.rb +0 -2
  75. data/lib/net/ssh/transport/hmac/none.rb +0 -2
  76. data/lib/net/ssh/transport/hmac/ripemd160.rb +0 -2
  77. data/lib/net/ssh/transport/hmac/sha1.rb +0 -2
  78. data/lib/net/ssh/transport/hmac/sha1_96.rb +0 -2
  79. data/lib/net/ssh/transport/hmac/sha2_256.rb +7 -11
  80. data/lib/net/ssh/transport/hmac/sha2_256_96.rb +4 -8
  81. data/lib/net/ssh/transport/hmac/sha2_256_etm.rb +12 -0
  82. data/lib/net/ssh/transport/hmac/sha2_512.rb +6 -9
  83. data/lib/net/ssh/transport/hmac/sha2_512_96.rb +4 -8
  84. data/lib/net/ssh/transport/hmac/sha2_512_etm.rb +12 -0
  85. data/lib/net/ssh/transport/hmac.rb +13 -11
  86. data/lib/net/ssh/transport/identity_cipher.rb +11 -13
  87. data/lib/net/ssh/transport/kex/abstract.rb +130 -0
  88. data/lib/net/ssh/transport/kex/abstract5656.rb +72 -0
  89. data/lib/net/ssh/transport/kex/curve25519_sha256.rb +39 -0
  90. data/lib/net/ssh/transport/kex/curve25519_sha256_loader.rb +30 -0
  91. data/lib/net/ssh/transport/kex/diffie_hellman_group14_sha1.rb +5 -19
  92. data/lib/net/ssh/transport/kex/diffie_hellman_group14_sha256.rb +11 -0
  93. data/lib/net/ssh/transport/kex/diffie_hellman_group1_sha1.rb +30 -139
  94. data/lib/net/ssh/transport/kex/diffie_hellman_group_exchange_sha1.rb +1 -8
  95. data/lib/net/ssh/transport/kex/diffie_hellman_group_exchange_sha256.rb +5 -9
  96. data/lib/net/ssh/transport/kex/ecdh_sha2_nistp256.rb +20 -81
  97. data/lib/net/ssh/transport/kex/ecdh_sha2_nistp384.rb +5 -4
  98. data/lib/net/ssh/transport/kex/ecdh_sha2_nistp521.rb +5 -4
  99. data/lib/net/ssh/transport/kex.rb +15 -10
  100. data/lib/net/ssh/transport/key_expander.rb +7 -8
  101. data/lib/net/ssh/transport/openssl.rb +149 -127
  102. data/lib/net/ssh/transport/packet_stream.rb +50 -16
  103. data/lib/net/ssh/transport/server_version.rb +17 -16
  104. data/lib/net/ssh/transport/session.rb +9 -7
  105. data/lib/net/ssh/transport/state.rb +44 -44
  106. data/lib/net/ssh/verifiers/accept_new.rb +0 -2
  107. data/lib/net/ssh/verifiers/accept_new_or_local_tunnel.rb +1 -2
  108. data/lib/net/ssh/verifiers/always.rb +6 -4
  109. data/lib/net/ssh/verifiers/never.rb +0 -2
  110. data/lib/net/ssh/version.rb +3 -3
  111. data/lib/net/ssh.rb +12 -8
  112. data/net-ssh-public_cert.pem +8 -8
  113. data/net-ssh.gemspec +9 -7
  114. data/support/ssh_tunnel_bug.rb +3 -3
  115. data.tar.gz.sig +0 -0
  116. metadata +55 -30
  117. metadata.gz.sig +0 -0
  118. data/.travis.yml +0 -53
  119. data/Gemfile.noed25519.lock +0 -41
  120. data/README.rdoc +0 -194
  121. data/lib/net/ssh/ruby_compat.rb +0 -13
  122. data/support/arcfour_check.rb +0 -20
@@ -1,8 +1,7 @@
1
1
  require 'net/ssh/loggable'
2
- require 'net/ssh/ruby_compat'
3
2
 
4
- module Net
5
- module SSH
3
+ module Net
4
+ module SSH
6
5
  module Connection
7
6
  # EventLoop can be shared across multiple sessions
8
7
  #
@@ -12,81 +11,84 @@ module Net
12
11
  # and we don't pass session.
13
12
  class EventLoop
14
13
  include Loggable
15
-
16
- def initialize(logger=nil)
14
+
15
+ def initialize(logger = nil)
17
16
  self.logger = logger
18
17
  @sessions = []
19
18
  end
20
-
19
+
21
20
  def register(session)
22
21
  @sessions << session
23
22
  end
24
-
23
+
25
24
  # process until timeout
26
25
  # if a block is given a session will be removed from loop
27
26
  # if block returns false for that session
28
27
  def process(wait = nil, &block)
29
28
  return false unless ev_preprocess(&block)
30
-
29
+
31
30
  ev_select_and_postprocess(wait)
32
31
  end
33
-
32
+
34
33
  # process the event loop but only for the sepcified session
35
34
  def process_only(session, wait = nil)
36
35
  orig_sessions = @sessions
37
36
  begin
38
37
  @sessions = [session]
39
38
  return false unless ev_preprocess
39
+
40
40
  ev_select_and_postprocess(wait)
41
41
  ensure
42
42
  @sessions = orig_sessions
43
43
  end
44
44
  end
45
-
45
+
46
46
  # Call preprocess on each session. If block given and that
47
47
  # block retuns false then we exit the processing
48
48
  def ev_preprocess(&block)
49
49
  return false if block_given? && !yield(self)
50
+
50
51
  @sessions.each(&:ev_preprocess)
51
52
  return false if block_given? && !yield(self)
53
+
52
54
  return true
53
55
  end
54
-
56
+
55
57
  def ev_select_and_postprocess(wait)
56
58
  owners = {}
57
59
  r = []
58
60
  w = []
59
61
  minwait = nil
60
62
  @sessions.each do |session|
61
- sr,sw,actwait = session.ev_do_calculate_rw_wait(wait)
63
+ sr, sw, actwait = session.ev_do_calculate_rw_wait(wait)
62
64
  minwait = actwait if actwait && (minwait.nil? || actwait < minwait)
63
65
  r.push(*sr)
64
66
  w.push(*sw)
65
67
  sr.each { |ri| owners[ri] = session }
66
68
  sw.each { |wi| owners[wi] = session }
67
69
  end
68
-
70
+
69
71
  readers, writers, = IO.select(r, w, nil, minwait)
70
-
72
+
71
73
  fired_sessions = {}
72
-
74
+
73
75
  if readers
74
76
  readers.each do |reader|
75
77
  session = owners[reader]
76
- (fired_sessions[session] ||= { r: [],w: [] })[:r] << reader
78
+ (fired_sessions[session] ||= { r: [], w: [] })[:r] << reader
77
79
  end
78
80
  end
79
81
  if writers
80
82
  writers.each do |writer|
81
83
  session = owners[writer]
82
- (fired_sessions[session] ||= { r: [],w: [] })[:w] << writer
84
+ (fired_sessions[session] ||= { r: [], w: [] })[:w] << writer
83
85
  end
84
86
  end
85
-
86
- fired_sessions.each do |s,rw|
87
- s.ev_do_handle_events(rw[:r],rw[:w])
87
+
88
+ fired_sessions.each do |s, rw|
89
+ s.ev_do_handle_events(rw[:r], rw[:w])
88
90
  end
89
-
91
+
90
92
  @sessions.each { |s| s.ev_do_postprocess(fired_sessions.key?(s)) }
91
93
  true
92
94
  end
@@ -98,18 +100,21 @@ module Net
98
100
  # we call block with session as argument
99
101
  def ev_preprocess(&block)
100
102
  return false if block_given? && !yield(@sessions.first)
103
+
101
104
  @sessions.each(&:ev_preprocess)
102
105
  return false if block_given? && !yield(@sessions.first)
106
+
103
107
  return true
104
108
  end
105
-
109
+
106
110
  def ev_select_and_postprocess(wait)
107
111
  raise "Only one session expected" unless @sessions.count == 1
112
+
108
113
  session = @sessions.first
109
- sr,sw,actwait = session.ev_do_calculate_rw_wait(wait)
114
+ sr, sw, actwait = session.ev_do_calculate_rw_wait(wait)
110
115
  readers, writers, = IO.select(sr, sw, nil, actwait)
111
-
112
- session.ev_do_handle_events(readers,writers)
116
+
117
+ session.ev_do_handle_events(readers, writers)
113
118
  session.ev_do_postprocess(!((readers.nil? || readers.empty?) && (writers.nil? || writers.empty?)))
114
119
  end
115
120
  end
@@ -1,45 +1,46 @@
1
1
  require 'net/ssh/loggable'
2
- module Net
3
- module SSH
2
+ module Net
3
+ module SSH
4
4
  module Connection
5
-
6
5
  class Keepalive
7
6
  include Loggable
8
-
7
+
9
8
  def initialize(session)
10
9
  @last_keepalive_sent_at = nil
11
10
  @unresponded_keepalive_count = 0
12
11
  @session = session
13
12
  self.logger = session.logger
14
13
  end
15
-
14
+
16
15
  def options
17
16
  @session.options
18
17
  end
19
-
18
+
20
19
  def enabled?
21
20
  options[:keepalive]
22
21
  end
23
-
22
+
24
23
  def interval
25
24
  options[:keepalive_interval] || Session::DEFAULT_IO_SELECT_TIMEOUT
26
25
  end
27
-
26
+
28
27
  def should_send?
29
28
  return false unless enabled?
30
29
  return true unless @last_keepalive_sent_at
30
+
31
31
  Time.now - @last_keepalive_sent_at >= interval
32
32
  end
33
-
33
+
34
34
  def keepalive_maxcount
35
35
  (options[:keepalive_maxcount] || 3).to_i
36
36
  end
37
-
37
+
38
38
  def send_as_needed(was_events)
39
39
  return if was_events
40
40
  return unless should_send?
41
+
41
42
  info { "sending keepalive #{@unresponded_keepalive_count}" }
42
-
43
+
43
44
  @unresponded_keepalive_count += 1
44
45
  @session.send_global_request("keepalive@openssh.com") { |success, response|
45
46
  debug { "keepalive response successful. Missed #{@unresponded_keepalive_count - 1} keepalives" }
@@ -53,7 +54,6 @@ module Net
53
54
  end
54
55
  end
55
56
  end
56
-
57
57
  end
58
58
  end
59
59
  end