net-ssh 2.7.0 → 7.3.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.
Files changed (199) hide show
  1. checksums.yaml +7 -0
  2. checksums.yaml.gz.sig +0 -0
  3. data/.dockerignore +6 -0
  4. data/.github/FUNDING.yml +1 -0
  5. data/.github/config/rubocop_linter_action.yml +4 -0
  6. data/.github/workflows/ci-with-docker.yml +44 -0
  7. data/.github/workflows/ci.yml +94 -0
  8. data/.github/workflows/rubocop.yml +16 -0
  9. data/.gitignore +15 -0
  10. data/.rubocop.yml +22 -0
  11. data/.rubocop_todo.yml +1081 -0
  12. data/CHANGES.txt +387 -0
  13. data/DEVELOPMENT.md +23 -0
  14. data/Dockerfile +29 -0
  15. data/Dockerfile.openssl3 +17 -0
  16. data/Gemfile +13 -0
  17. data/Gemfile.noed25519 +12 -0
  18. data/Gemfile.norbnacl +12 -0
  19. data/ISSUE_TEMPLATE.md +30 -0
  20. data/Manifest +4 -5
  21. data/README.md +303 -0
  22. data/Rakefile +174 -40
  23. data/SECURITY.md +4 -0
  24. data/THANKS.txt +25 -0
  25. data/appveyor.yml +58 -0
  26. data/docker-compose.yml +25 -0
  27. data/lib/net/ssh/authentication/agent.rb +279 -18
  28. data/lib/net/ssh/authentication/certificate.rb +183 -0
  29. data/lib/net/ssh/authentication/constants.rb +17 -15
  30. data/lib/net/ssh/authentication/ed25519.rb +184 -0
  31. data/lib/net/ssh/authentication/ed25519_loader.rb +31 -0
  32. data/lib/net/ssh/authentication/key_manager.rb +125 -54
  33. data/lib/net/ssh/authentication/methods/abstract.rb +67 -48
  34. data/lib/net/ssh/authentication/methods/hostbased.rb +34 -37
  35. data/lib/net/ssh/authentication/methods/keyboard_interactive.rb +19 -12
  36. data/lib/net/ssh/authentication/methods/none.rb +16 -19
  37. data/lib/net/ssh/authentication/methods/password.rb +56 -19
  38. data/lib/net/ssh/authentication/methods/publickey.rb +96 -55
  39. data/lib/net/ssh/authentication/pageant.rb +483 -246
  40. data/lib/net/ssh/authentication/pub_key_fingerprint.rb +43 -0
  41. data/lib/net/ssh/authentication/session.rb +138 -120
  42. data/lib/net/ssh/buffer.rb +399 -300
  43. data/lib/net/ssh/buffered_io.rb +154 -150
  44. data/lib/net/ssh/config.rb +361 -166
  45. data/lib/net/ssh/connection/channel.rb +640 -596
  46. data/lib/net/ssh/connection/constants.rb +29 -29
  47. data/lib/net/ssh/connection/event_loop.rb +123 -0
  48. data/lib/net/ssh/connection/keepalive.rb +59 -0
  49. data/lib/net/ssh/connection/session.rb +628 -548
  50. data/lib/net/ssh/connection/term.rb +125 -123
  51. data/lib/net/ssh/errors.rb +101 -95
  52. data/lib/net/ssh/key_factory.rb +198 -100
  53. data/lib/net/ssh/known_hosts.rb +221 -98
  54. data/lib/net/ssh/loggable.rb +50 -49
  55. data/lib/net/ssh/packet.rb +83 -79
  56. data/lib/net/ssh/prompt.rb +50 -81
  57. data/lib/net/ssh/proxy/command.rb +108 -60
  58. data/lib/net/ssh/proxy/errors.rb +12 -10
  59. data/lib/net/ssh/proxy/http.rb +82 -78
  60. data/lib/net/ssh/proxy/https.rb +50 -0
  61. data/lib/net/ssh/proxy/jump.rb +54 -0
  62. data/lib/net/ssh/proxy/socks4.rb +5 -8
  63. data/lib/net/ssh/proxy/socks5.rb +18 -20
  64. data/lib/net/ssh/service/forward.rb +383 -255
  65. data/lib/net/ssh/test/channel.rb +145 -136
  66. data/lib/net/ssh/test/extensions.rb +131 -110
  67. data/lib/net/ssh/test/kex.rb +34 -32
  68. data/lib/net/ssh/test/local_packet.rb +46 -44
  69. data/lib/net/ssh/test/packet.rb +89 -70
  70. data/lib/net/ssh/test/remote_packet.rb +32 -30
  71. data/lib/net/ssh/test/script.rb +156 -142
  72. data/lib/net/ssh/test/socket.rb +49 -48
  73. data/lib/net/ssh/test.rb +82 -77
  74. data/lib/net/ssh/transport/aes128_gcm.rb +40 -0
  75. data/lib/net/ssh/transport/aes256_gcm.rb +40 -0
  76. data/lib/net/ssh/transport/algorithms.rb +472 -348
  77. data/lib/net/ssh/transport/chacha20_poly1305_cipher.rb +117 -0
  78. data/lib/net/ssh/transport/chacha20_poly1305_cipher_loader.rb +17 -0
  79. data/lib/net/ssh/transport/cipher_factory.rb +124 -100
  80. data/lib/net/ssh/transport/constants.rb +32 -24
  81. data/lib/net/ssh/transport/ctr.rb +42 -22
  82. data/lib/net/ssh/transport/gcm_cipher.rb +207 -0
  83. data/lib/net/ssh/transport/hmac/abstract.rb +97 -63
  84. data/lib/net/ssh/transport/hmac/md5.rb +0 -2
  85. data/lib/net/ssh/transport/hmac/md5_96.rb +0 -2
  86. data/lib/net/ssh/transport/hmac/none.rb +0 -2
  87. data/lib/net/ssh/transport/hmac/ripemd160.rb +0 -2
  88. data/lib/net/ssh/transport/hmac/sha1.rb +0 -2
  89. data/lib/net/ssh/transport/hmac/sha1_96.rb +0 -2
  90. data/lib/net/ssh/transport/hmac/sha2_256.rb +7 -11
  91. data/lib/net/ssh/transport/hmac/sha2_256_96.rb +4 -8
  92. data/lib/net/ssh/transport/hmac/sha2_256_etm.rb +12 -0
  93. data/lib/net/ssh/transport/hmac/sha2_512.rb +6 -9
  94. data/lib/net/ssh/transport/hmac/sha2_512_96.rb +4 -8
  95. data/lib/net/ssh/transport/hmac/sha2_512_etm.rb +12 -0
  96. data/lib/net/ssh/transport/hmac.rb +14 -12
  97. data/lib/net/ssh/transport/identity_cipher.rb +54 -44
  98. data/lib/net/ssh/transport/kex/abstract.rb +130 -0
  99. data/lib/net/ssh/transport/kex/abstract5656.rb +72 -0
  100. data/lib/net/ssh/transport/kex/curve25519_sha256.rb +39 -0
  101. data/lib/net/ssh/transport/kex/curve25519_sha256_loader.rb +30 -0
  102. data/lib/net/ssh/transport/kex/diffie_hellman_group14_sha1.rb +33 -40
  103. data/lib/net/ssh/transport/kex/diffie_hellman_group14_sha256.rb +11 -0
  104. data/lib/net/ssh/transport/kex/diffie_hellman_group1_sha1.rb +119 -213
  105. data/lib/net/ssh/transport/kex/diffie_hellman_group_exchange_sha1.rb +53 -61
  106. data/lib/net/ssh/transport/kex/diffie_hellman_group_exchange_sha256.rb +5 -9
  107. data/lib/net/ssh/transport/kex/ecdh_sha2_nistp256.rb +36 -90
  108. data/lib/net/ssh/transport/kex/ecdh_sha2_nistp384.rb +18 -10
  109. data/lib/net/ssh/transport/kex/ecdh_sha2_nistp521.rb +18 -10
  110. data/lib/net/ssh/transport/kex.rb +15 -12
  111. data/lib/net/ssh/transport/key_expander.rb +24 -20
  112. data/lib/net/ssh/transport/openssl.rb +161 -124
  113. data/lib/net/ssh/transport/openssl_cipher_extensions.rb +8 -0
  114. data/lib/net/ssh/transport/packet_stream.rb +246 -183
  115. data/lib/net/ssh/transport/server_version.rb +57 -51
  116. data/lib/net/ssh/transport/session.rb +307 -235
  117. data/lib/net/ssh/transport/state.rb +178 -176
  118. data/lib/net/ssh/verifiers/accept_new.rb +33 -0
  119. data/lib/net/ssh/verifiers/accept_new_or_local_tunnel.rb +33 -0
  120. data/lib/net/ssh/verifiers/always.rb +58 -0
  121. data/lib/net/ssh/verifiers/never.rb +19 -0
  122. data/lib/net/ssh/version.rb +57 -51
  123. data/lib/net/ssh.rb +140 -40
  124. data/net-ssh-public_cert.pem +21 -0
  125. data/net-ssh.gemspec +39 -184
  126. data/support/ssh_tunnel_bug.rb +5 -5
  127. data.tar.gz.sig +0 -0
  128. metadata +205 -99
  129. metadata.gz.sig +0 -0
  130. data/README.rdoc +0 -219
  131. data/Rudyfile +0 -96
  132. data/gem-public_cert.pem +0 -20
  133. data/lib/net/ssh/authentication/agent/java_pageant.rb +0 -85
  134. data/lib/net/ssh/authentication/agent/socket.rb +0 -170
  135. data/lib/net/ssh/ruby_compat.rb +0 -51
  136. data/lib/net/ssh/verifiers/lenient.rb +0 -30
  137. data/lib/net/ssh/verifiers/null.rb +0 -12
  138. data/lib/net/ssh/verifiers/secure.rb +0 -54
  139. data/lib/net/ssh/verifiers/strict.rb +0 -24
  140. data/setup.rb +0 -1585
  141. data/support/arcfour_check.rb +0 -20
  142. data/test/README.txt +0 -47
  143. data/test/authentication/methods/common.rb +0 -28
  144. data/test/authentication/methods/test_abstract.rb +0 -51
  145. data/test/authentication/methods/test_hostbased.rb +0 -114
  146. data/test/authentication/methods/test_keyboard_interactive.rb +0 -100
  147. data/test/authentication/methods/test_none.rb +0 -41
  148. data/test/authentication/methods/test_password.rb +0 -52
  149. data/test/authentication/methods/test_publickey.rb +0 -148
  150. data/test/authentication/test_agent.rb +0 -205
  151. data/test/authentication/test_key_manager.rb +0 -218
  152. data/test/authentication/test_session.rb +0 -108
  153. data/test/common.rb +0 -108
  154. data/test/configs/eqsign +0 -3
  155. data/test/configs/exact_match +0 -8
  156. data/test/configs/host_plus +0 -10
  157. data/test/configs/multihost +0 -4
  158. data/test/configs/nohost +0 -19
  159. data/test/configs/numeric_host +0 -4
  160. data/test/configs/send_env +0 -2
  161. data/test/configs/substitutes +0 -8
  162. data/test/configs/wild_cards +0 -14
  163. data/test/connection/test_channel.rb +0 -467
  164. data/test/connection/test_session.rb +0 -526
  165. data/test/known_hosts/github +0 -1
  166. data/test/manual/test_forward.rb +0 -223
  167. data/test/start/test_options.rb +0 -36
  168. data/test/start/test_transport.rb +0 -28
  169. data/test/test_all.rb +0 -11
  170. data/test/test_buffer.rb +0 -433
  171. data/test/test_buffered_io.rb +0 -63
  172. data/test/test_config.rb +0 -151
  173. data/test/test_key_factory.rb +0 -173
  174. data/test/test_known_hosts.rb +0 -13
  175. data/test/transport/hmac/test_md5.rb +0 -41
  176. data/test/transport/hmac/test_md5_96.rb +0 -27
  177. data/test/transport/hmac/test_none.rb +0 -34
  178. data/test/transport/hmac/test_ripemd160.rb +0 -36
  179. data/test/transport/hmac/test_sha1.rb +0 -36
  180. data/test/transport/hmac/test_sha1_96.rb +0 -27
  181. data/test/transport/hmac/test_sha2_256.rb +0 -37
  182. data/test/transport/hmac/test_sha2_256_96.rb +0 -27
  183. data/test/transport/hmac/test_sha2_512.rb +0 -37
  184. data/test/transport/hmac/test_sha2_512_96.rb +0 -27
  185. data/test/transport/kex/test_diffie_hellman_group14_sha1.rb +0 -13
  186. data/test/transport/kex/test_diffie_hellman_group1_sha1.rb +0 -146
  187. data/test/transport/kex/test_diffie_hellman_group_exchange_sha1.rb +0 -92
  188. data/test/transport/kex/test_diffie_hellman_group_exchange_sha256.rb +0 -34
  189. data/test/transport/kex/test_ecdh_sha2_nistp256.rb +0 -161
  190. data/test/transport/kex/test_ecdh_sha2_nistp384.rb +0 -38
  191. data/test/transport/kex/test_ecdh_sha2_nistp521.rb +0 -38
  192. data/test/transport/test_algorithms.rb +0 -330
  193. data/test/transport/test_cipher_factory.rb +0 -443
  194. data/test/transport/test_hmac.rb +0 -34
  195. data/test/transport/test_identity_cipher.rb +0 -40
  196. data/test/transport/test_packet_stream.rb +0 -1755
  197. data/test/transport/test_server_version.rb +0 -78
  198. data/test/transport/test_session.rb +0 -319
  199. data/test/transport/test_state.rb +0 -181
data/lib/net/ssh.rb CHANGED
@@ -3,6 +3,8 @@
3
3
  ENV['HOME'] ||= ENV['HOMEPATH'] ? "#{ENV['HOMEDRIVE']}#{ENV['HOMEPATH']}" : Dir.pwd
4
4
 
5
5
  require 'logger'
6
+ require 'etc'
7
+ require 'shellwords'
6
8
 
7
9
  require 'net/ssh/config'
8
10
  require 'net/ssh/errors'
@@ -10,9 +12,9 @@ require 'net/ssh/loggable'
10
12
  require 'net/ssh/transport/session'
11
13
  require 'net/ssh/authentication/session'
12
14
  require 'net/ssh/connection/session'
15
+ require 'net/ssh/prompt'
13
16
 
14
17
  module Net
15
-
16
18
  # Net::SSH is a library for interacting, programmatically, with remote
17
19
  # processes via the SSH2 protocol. Sessions are always initiated via
18
20
  # Net::SSH.start. From there, a program interacts with the new SSH session
@@ -39,36 +41,39 @@ module Net
39
41
  #
40
42
  # == X == "execute a command and capture the output"
41
43
  #
42
- # Net::SSH.start("host", "user", :password => "password") do |ssh|
44
+ # Net::SSH.start("host", "user", password: "password") do |ssh|
43
45
  # result = ssh.exec!("ls -l")
44
46
  # puts result
45
47
  # end
46
48
  #
47
49
  # == X == "forward connections on a local port to a remote host"
48
50
  #
49
- # Net::SSH.start("host", "user", :password => "password") do |ssh|
51
+ # Net::SSH.start("host", "user", password: "password") do |ssh|
50
52
  # ssh.forward.local(1234, "www.google.com", 80)
51
53
  # ssh.loop { true }
52
54
  # end
53
55
  #
54
56
  # == X == "forward connections on a remote port to the local host"
55
57
  #
56
- # Net::SSH.start("host", "user", :password => "password") do |ssh|
58
+ # Net::SSH.start("host", "user", password: "password") do |ssh|
57
59
  # ssh.forward.remote(80, "www.google.com", 1234)
58
60
  # ssh.loop { true }
59
61
  # end
60
62
  module SSH
61
63
  # This is the set of options that Net::SSH.start recognizes. See
62
64
  # Net::SSH.start for a description of each option.
63
- VALID_OPTIONS = [
64
- :auth_methods, :bind_address, :compression, :compression_level, :config,
65
- :encryption, :forward_agent, :hmac, :host_key,
66
- :keepalive, :keepalive_interval, :kex, :keys, :key_data,
67
- :languages, :logger, :paranoid, :password, :port, :proxy,
68
- :rekey_blocks_limit,:rekey_limit, :rekey_packet_limit, :timeout, :verbose,
69
- :global_known_hosts_file, :user_known_hosts_file, :host_key_alias,
70
- :host_name, :user, :properties, :passphrase, :keys_only, :max_pkt_size,
71
- :max_win_size, :send_env
65
+ VALID_OPTIONS = %i[
66
+ auth_methods bind_address compression compression_level config
67
+ encryption forward_agent hmac host_key identity_agent remote_user
68
+ keepalive keepalive_interval keepalive_maxcount kex keys key_data
69
+ keycerts keycert_data languages logger paranoid password port proxy
70
+ rekey_blocks_limit rekey_limit rekey_packet_limit timeout verbose
71
+ known_hosts global_known_hosts_file user_known_hosts_file host_key_alias
72
+ host_name user properties passphrase keys_only max_pkt_size
73
+ max_win_size send_env set_env use_agent number_of_password_prompts
74
+ append_all_supported_algorithms non_interactive password_prompt
75
+ agent_socket_factory minimum_dh_bits verify_host_key
76
+ fingerprint_hash check_host_ip pubkey_algorithms
72
77
  ]
73
78
 
74
79
  # The standard means of starting a new SSH connection. When used with a
@@ -103,6 +108,8 @@ module Net
103
108
  # * :bind_address => the IP address on the connecting machine to use in
104
109
  # establishing connection. (:bind_address is discarded if :proxy
105
110
  # is set.)
111
+ # * :check_host_ip => Also ckeck IP address when connecting to remote host.
112
+ # Defaults to +true+.
106
113
  # * :compression => the compression algorithm to use, or +true+ to use
107
114
  # whatever is supported.
108
115
  # * :compression_level => the compression level to use when sending data
@@ -113,9 +120,11 @@ module Net
113
120
  # * :encryption => the encryption cipher (or ciphers) to use
114
121
  # * :forward_agent => set to true if you want the SSH agent connection to
115
122
  # be forwarded
123
+ # * :known_hosts => a custom object holding known hosts records.
124
+ # It must implement #search_for and `add` in a similiar manner as KnownHosts.
116
125
  # * :global_known_hosts_file => the location of the global known hosts
117
126
  # file. Set to an array if you want to specify multiple global known
118
- # hosts files. Defaults to %w(/etc/ssh/known_hosts /etc/ssh/known_hosts2).
127
+ # hosts files. Defaults to %w(/etc/ssh/ssh_known_hosts /etc/ssh/ssh_known_hosts2).
119
128
  # * :hmac => the hmac algorithm (or algorithms) to use
120
129
  # * :host_key => the host key algorithm (or algorithms) to use
121
130
  # * :host_key_alias => the host name to use when looking up or adding a
@@ -125,14 +134,20 @@ module Net
125
134
  # specified in an SSH configuration file. It lets you specify an
126
135
  # "alias", similarly to adding an entry in /etc/hosts but without needing
127
136
  # to modify /etc/hosts.
128
- # :keepalive => set to +true+ to send a keepalive packet to the SSH server
137
+ # * :keepalive => set to +true+ to send a keepalive packet to the SSH server
129
138
  # when there's no traffic between the SSH server and Net::SSH client for
130
139
  # the keepalive_interval seconds. Defaults to +false+.
131
- # :keepalive_interval => the interval seconds for keepalive.
140
+ # * :keepalive_interval => the interval seconds for keepalive.
132
141
  # Defaults to +300+ seconds.
142
+ # * :keepalive_maxcount => the maximun number of keepalive packet miss allowed.
143
+ # Defaults to 3
133
144
  # * :kex => the key exchange algorithm (or algorithms) to use
134
145
  # * :keys => an array of file names of private keys to use for publickey
135
146
  # and hostbased authentication
147
+ # * :keycerts => an array of file names of key certificates to use
148
+ # with publickey authentication
149
+ # * :keycert_data => an array of strings, which each element of the array
150
+ # being a key certificate to use with publickey authentication
136
151
  # * :key_data => an array of strings, with each element of the array being
137
152
  # a raw private key in PEM format.
138
153
  # * :keys_only => set to +true+ to use only private keys from +keys+ and
@@ -145,8 +160,11 @@ module Net
145
160
  # for better performance if your SSH server supports it (most do).
146
161
  # * :max_win_size => maximum size we tell the other side that is supported for
147
162
  # the window.
148
- # * :paranoid => either false, true, :very, or :secure specifying how
149
- # strict host-key verification should be (in increasing order here)
163
+ # * :non_interactive => set to true if your app is non interactive and prefers
164
+ # authentication failure vs password prompt. Non-interactive applications
165
+ # should set it to true to prefer failing a password/etc auth methods vs.
166
+ # asking for password.
167
+ # * :paranoid => deprecated alias for :verify_host_key
150
168
  # * :passphrase => the passphrase to use when loading a private key (default
151
169
  # is +nil+, for no passphrase)
152
170
  # * :password => the password to use to login
@@ -154,65 +172,107 @@ module Net
154
172
  # * :properties => a hash of key/value pairs to add to the new connection's
155
173
  # properties (see Net::SSH::Connection::Session#properties)
156
174
  # * :proxy => a proxy instance (see Proxy) to use when connecting
175
+ # * :pubkey_algorithms => the public key authentication algorithms to use for
176
+ # this connection. Valid values are 'rsa-sha2-256-cert-v01@openssh.com',
177
+ # 'ssh-rsa-cert-v01@openssh.com', 'rsa-sha2-256', 'ssh-rsa'. Currently, this
178
+ # option is only used for RSA public key authentication and ignored for other
179
+ # types.
157
180
  # * :rekey_blocks_limit => the max number of blocks to process before rekeying
158
181
  # * :rekey_limit => the max number of bytes to process before rekeying
159
182
  # * :rekey_packet_limit => the max number of packets to process before rekeying
160
183
  # * :send_env => an array of local environment variable names to export to the
161
184
  # remote environment. Names may be given as String or Regexp.
185
+ # * :set_env => a hash of environment variable names and values to set to the
186
+ # remote environment. Override the ones if specified in +send_env+.
162
187
  # * :timeout => how long to wait for the initial connection to be made
163
188
  # * :user => the user name to log in as; this overrides the +user+
164
189
  # parameter, and is primarily only useful when provided via an SSH
165
190
  # configuration file.
191
+ # * :remote_user => used for substitution into the '%r' part of a ProxyCommand
166
192
  # * :user_known_hosts_file => the location of the user known hosts file.
167
193
  # Set to an array to specify multiple user known hosts files.
168
194
  # Defaults to %w(~/.ssh/known_hosts ~/.ssh/known_hosts2).
195
+ # * :use_agent => Set false to disable the use of ssh-agent. Defaults to
196
+ # true
197
+ # * :identity_agent => the path to the ssh-agent's UNIX socket
169
198
  # * :verbose => how verbose to be (Logger verbosity constants, Logger::DEBUG
170
199
  # is very verbose, Logger::FATAL is all but silent). Logger::FATAL is the
171
200
  # default. The symbols :debug, :info, :warn, :error, and :fatal are also
172
201
  # supported and are translated to the corresponding Logger constant.
173
- def self.start(host, user, options={}, &block)
202
+ # * :append_all_supported_algorithms => set to +true+ to append all supported
203
+ # algorithms by net-ssh. Was the default behaviour until 2.10
204
+ # * :number_of_password_prompts => Number of prompts for the password
205
+ # authentication method defaults to 3 set to 0 to disable prompt for
206
+ # password auth method
207
+ # * :password_prompt => a custom prompt object with ask method. See Net::SSH::Prompt
208
+ #
209
+ # * :agent_socket_factory => enables the user to pass a lambda/block that will serve as the socket factory
210
+ # Net::SSH.start(host,user,agent_socket_factory: ->{ UNIXSocket.open('/foo/bar') })
211
+ # example: ->{ UNIXSocket.open('/foo/bar')}
212
+ # * :verify_host_key => specify how strict host-key verification should be.
213
+ # In order of increasing strictness:
214
+ # * :never (very insecure) ::Net::SSH::Verifiers::Never
215
+ # * :accept_new_or_local_tunnel (insecure) ::Net::SSH::Verifiers::AcceptNewOrLocalTunnel
216
+ # * :accept_new (insecure) ::Net::SSH::Verifiers::AcceptNew
217
+ # * :always (secure) ::Net::SSH::Verifiers::Always
218
+ # You can also provide an own Object which responds to +verify+. The argument
219
+ # given to +verify+ is a hash consisting of the +:key+, the +:key_blob+,
220
+ # the +:fingerprint+ and the +:session+. Returning true accepts the host key,
221
+ # returning false declines it and closes the connection.
222
+ # * :fingerprint_hash => 'MD5' or 'SHA256', defaults to 'SHA256'
223
+ # If +user+ parameter is nil it defaults to USER from ssh_config, or
224
+ # local username
225
+ def self.start(host, user = nil, options = {}, &block)
174
226
  invalid_options = options.keys - VALID_OPTIONS
175
227
  if invalid_options.any?
176
228
  raise ArgumentError, "invalid option(s): #{invalid_options.join(', ')}"
177
229
  end
178
230
 
231
+ assign_defaults(options)
232
+ _sanitize_options(options)
233
+
179
234
  options[:user] = user if user
180
235
  options = configuration_for(host, options.fetch(:config, true)).merge(options)
181
236
  host = options.fetch(:host_name, host)
182
237
 
183
- if !options.key?(:logger)
184
- options[:logger] = Logger.new(STDERR)
185
- options[:logger].level = Logger::FATAL
238
+ options[:check_host_ip] = true unless options.key?(:check_host_ip)
239
+
240
+ if options[:non_interactive]
241
+ options[:number_of_password_prompts] = 0
186
242
  end
187
243
 
244
+ _support_deprecated_option_paranoid(options)
245
+
188
246
  if options[:verbose]
189
247
  options[:logger].level = case options[:verbose]
190
- when Fixnum then options[:verbose]
191
- when :debug then Logger::DEBUG
192
- when :info then Logger::INFO
193
- when :warn then Logger::WARN
194
- when :error then Logger::ERROR
195
- when :fatal then Logger::FATAL
196
- else raise ArgumentError, "can't convert #{options[:verbose].inspect} to any of the Logger level constants"
197
- end
248
+ when Integer then options[:verbose]
249
+ when :debug then Logger::DEBUG
250
+ when :info then Logger::INFO
251
+ when :warn then Logger::WARN
252
+ when :error then Logger::ERROR
253
+ when :fatal then Logger::FATAL
254
+ else raise ArgumentError, "can't convert #{options[:verbose].inspect} to any of the Logger level constants"
255
+ end
198
256
  end
199
257
 
200
258
  transport = Transport::Session.new(host, options)
201
259
  auth = Authentication::Session.new(transport, options)
202
260
 
203
- user = options.fetch(:user, user)
261
+ user = options.fetch(:user, user) || Etc.getpwuid.name
204
262
  if auth.authenticate("ssh-connection", user, options[:password])
205
263
  connection = Connection::Session.new(transport, options)
206
264
  if block_given?
207
- retval = yield connection
208
- connection.close
209
- retval
265
+ begin
266
+ yield connection
267
+ ensure
268
+ connection.close unless connection.closed?
269
+ end
210
270
  else
211
271
  return connection
212
272
  end
213
273
  else
214
274
  transport.close
215
- raise AuthenticationFailed, user
275
+ raise AuthenticationFailed, "Authentication failed for user #{user}@#{host}"
216
276
  end
217
277
  end
218
278
 
@@ -225,14 +285,54 @@ module Net
225
285
  # to read.
226
286
  #
227
287
  # See Net::SSH::Config for the full description of all supported options.
228
- def self.configuration_for(host, use_ssh_config=true)
288
+ def self.configuration_for(host, use_ssh_config)
229
289
  files = case use_ssh_config
230
- when true then Net::SSH::Config.default_files
231
- when false, nil then return {}
232
- else Array(use_ssh_config)
233
- end
290
+ when true then Net::SSH::Config.expandable_default_files
291
+ when false, nil then return {}
292
+ else Array(use_ssh_config)
293
+ end
234
294
 
235
295
  Net::SSH::Config.for(host, files)
236
296
  end
297
+
298
+ def self.assign_defaults(options)
299
+ if !options[:logger]
300
+ options[:logger] = Logger.new(STDERR)
301
+ options[:logger].level = Logger::FATAL
302
+ end
303
+
304
+ options[:password_prompt] ||= Prompt.default(options)
305
+
306
+ %i[password passphrase].each do |key|
307
+ options.delete(key) if options.key?(key) && options[key].nil?
308
+ end
309
+ end
310
+
311
+ def self._sanitize_options(options)
312
+ invalid_option_values = [nil, [nil]]
313
+ unless (options.values & invalid_option_values).empty?
314
+ nil_options = options.select { |_k, v| invalid_option_values.include?(v) }.map(&:first)
315
+ Kernel.warn "#{caller_locations(2, 1)[0]}: Passing nil, or [nil] to Net::SSH.start is deprecated for keys: #{nil_options.join(', ')}"
316
+ end
317
+ end
318
+ private_class_method :_sanitize_options
319
+
320
+ def self._support_deprecated_option_paranoid(options)
321
+ if options.key?(:paranoid)
322
+ Kernel.warn(
323
+ ":paranoid is deprecated, please use :verify_host_key. Supported " \
324
+ "values are exactly the same, only the name of the option has changed."
325
+ )
326
+ if options.key?(:verify_host_key)
327
+ Kernel.warn(
328
+ "Both :paranoid and :verify_host_key were specified. " \
329
+ ":verify_host_key takes precedence, :paranoid will be ignored."
330
+ )
331
+ else
332
+ options[:verify_host_key] = options.delete(:paranoid)
333
+ end
334
+ end
335
+ end
336
+ private_class_method :_support_deprecated_option_paranoid
237
337
  end
238
338
  end
@@ -0,0 +1,21 @@
1
+ -----BEGIN CERTIFICATE-----
2
+ MIIDeDCCAmCgAwIBAgIBATANBgkqhkiG9w0BAQsFADBBMQ8wDQYDVQQDDAZuZXRz
3
+ c2gxGTAXBgoJkiaJk/IsZAEZFglzb2x1dGlvdXMxEzARBgoJkiaJk/IsZAEZFgNj
4
+ b20wHhcNMjQwNDAxMDk1NjIxWhcNMjUwNDAxMDk1NjIxWjBBMQ8wDQYDVQQDDAZu
5
+ ZXRzc2gxGTAXBgoJkiaJk/IsZAEZFglzb2x1dGlvdXMxEzARBgoJkiaJk/IsZAEZ
6
+ FgNjb20wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDGJ4TbZ9H+qZ08
7
+ pQfJhPJTHaDCyQvCsKTFrL5O9z3tllQ7B/zksMMM+qFBpNYu9HCcg4yBATacE/PB
8
+ qVVyUrpr6lbH/XwoN5ljXm+bdCfmnjZvTCL2FTE6o+bcnaF0IsJyC0Q2B1fbWdXN
9
+ 6Off1ZWoUk6We2BIM1bn6QJLxBpGyYhvOPXsYoqSuzDf2SJDDsWFZ8kV5ON13Ohm
10
+ JbBzn0oD8HF8FuYOewwsC0C1q4w7E5GtvHcQ5juweS7+RKsyDcVcVrLuNzoGRttS
11
+ KP4yMn+TzaXijyjRg7gECfJr3TGASaA4bQsILFGG5dAWcwO4OMrZedR7SHj/o0Kf
12
+ 3gL7P0axAgMBAAGjezB5MAkGA1UdEwQCMAAwCwYDVR0PBAQDAgSwMB0GA1UdDgQW
13
+ BBQF8qLA7Z4zg0SJGtUbv3eoQ8tjIzAfBgNVHREEGDAWgRRuZXRzc2hAc29sdXRp
14
+ b3VzLmNvbTAfBgNVHRIEGDAWgRRuZXRzc2hAc29sdXRpb3VzLmNvbTANBgkqhkiG
15
+ 9w0BAQsFAAOCAQEAfY2WbsBKwRtBep4l+Y2/84H1BKH9UVOsFxqQzYkvM2LFDyup
16
+ UkjYf8nPSjg3mquhaiA5KSoSVUPpNDfQo+UvY3+mlxRs96ttWiUGwz27fy82rx1B
17
+ ZnfKjsWOntemNON6asOD0mtv0xsNBfOB2VNIKW/uqHsiPpa0OaVy5uENhX+5OFan
18
+ 2P1Uy+WcMiv38RlRkn4cdEIZUFupDgKFsguYlaJy473/wsae4exUgc5bvi3Splob
19
+ 1uE/LmB/qWBVSNW8e9KDtJynhDDZBlpESyQHFQCZj6UapzxlnC46LaDncPoAtJPc
20
+ MlWxJ8mKghIcyXc5y4cSyGypNG5BralqnvQUyg==
21
+ -----END CERTIFICATE-----
data/net-ssh.gemspec CHANGED
@@ -1,192 +1,47 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
- # -*- encoding: utf-8 -*-
1
+ require_relative 'lib/net/ssh/version'
5
2
 
6
- Gem::Specification.new do |s|
7
- s.name = "net-ssh"
8
- s.version = "2.7.0"
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "net-ssh"
5
+ spec.version = Net::SSH::Version::STRING
6
+ spec.authors = ["Jamis Buck", "Delano Mandelbaum", "Mikl\u{f3}s Fazekas"]
7
+ spec.email = ["net-ssh@solutious.com"]
9
8
 
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Jamis Buck", "Delano Mandelbaum"]
12
- s.date = "2013-09-11"
13
- s.description = "Net::SSH: a pure-Ruby implementation of the SSH2 client protocol. It allows you to write programs that invoke and interact with processes on remote servers, via SSH2."
14
- s.email = "net-ssh@solutious.com"
15
- s.extra_rdoc_files = [
16
- "LICENSE.txt",
17
- "README.rdoc"
18
- ]
19
- s.files = [
20
- "CHANGES.txt",
9
+ if ENV['NET_SSH_BUILDGEM_SIGNED']
10
+ spec.cert_chain = ["net-ssh-public_cert.pem"]
11
+ spec.signing_key = "/mnt/gem/net-ssh-private_key.pem"
12
+ end
13
+
14
+ spec.summary = %q{Net::SSH: a pure-Ruby implementation of the SSH2 client protocol.}
15
+ spec.description = %q{Net::SSH: a pure-Ruby implementation of the SSH2 client protocol. It allows you to write programs that invoke and interact with processes on remote servers, via SSH2.}
16
+ spec.homepage = "https://github.com/net-ssh/net-ssh"
17
+ spec.license = "MIT"
18
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.6")
19
+ spec.metadata = {
20
+ "changelog_uri" => "https://github.com/net-ssh/net-ssh/blob/master/CHANGES.txt"
21
+ }
22
+
23
+ spec.extra_rdoc_files = [
21
24
  "LICENSE.txt",
22
- "Manifest",
23
- "README.rdoc",
24
- "Rakefile",
25
- "Rudyfile",
26
- "THANKS.txt",
27
- "gem-public_cert.pem",
28
- "lib/net/ssh.rb",
29
- "lib/net/ssh/authentication/agent.rb",
30
- "lib/net/ssh/authentication/agent/java_pageant.rb",
31
- "lib/net/ssh/authentication/agent/socket.rb",
32
- "lib/net/ssh/authentication/constants.rb",
33
- "lib/net/ssh/authentication/key_manager.rb",
34
- "lib/net/ssh/authentication/methods/abstract.rb",
35
- "lib/net/ssh/authentication/methods/hostbased.rb",
36
- "lib/net/ssh/authentication/methods/keyboard_interactive.rb",
37
- "lib/net/ssh/authentication/methods/none.rb",
38
- "lib/net/ssh/authentication/methods/password.rb",
39
- "lib/net/ssh/authentication/methods/publickey.rb",
40
- "lib/net/ssh/authentication/pageant.rb",
41
- "lib/net/ssh/authentication/session.rb",
42
- "lib/net/ssh/buffer.rb",
43
- "lib/net/ssh/buffered_io.rb",
44
- "lib/net/ssh/config.rb",
45
- "lib/net/ssh/connection/channel.rb",
46
- "lib/net/ssh/connection/constants.rb",
47
- "lib/net/ssh/connection/session.rb",
48
- "lib/net/ssh/connection/term.rb",
49
- "lib/net/ssh/errors.rb",
50
- "lib/net/ssh/key_factory.rb",
51
- "lib/net/ssh/known_hosts.rb",
52
- "lib/net/ssh/loggable.rb",
53
- "lib/net/ssh/packet.rb",
54
- "lib/net/ssh/prompt.rb",
55
- "lib/net/ssh/proxy/command.rb",
56
- "lib/net/ssh/proxy/errors.rb",
57
- "lib/net/ssh/proxy/http.rb",
58
- "lib/net/ssh/proxy/socks4.rb",
59
- "lib/net/ssh/proxy/socks5.rb",
60
- "lib/net/ssh/ruby_compat.rb",
61
- "lib/net/ssh/service/forward.rb",
62
- "lib/net/ssh/test.rb",
63
- "lib/net/ssh/test/channel.rb",
64
- "lib/net/ssh/test/extensions.rb",
65
- "lib/net/ssh/test/kex.rb",
66
- "lib/net/ssh/test/local_packet.rb",
67
- "lib/net/ssh/test/packet.rb",
68
- "lib/net/ssh/test/remote_packet.rb",
69
- "lib/net/ssh/test/script.rb",
70
- "lib/net/ssh/test/socket.rb",
71
- "lib/net/ssh/transport/algorithms.rb",
72
- "lib/net/ssh/transport/cipher_factory.rb",
73
- "lib/net/ssh/transport/constants.rb",
74
- "lib/net/ssh/transport/ctr.rb",
75
- "lib/net/ssh/transport/hmac.rb",
76
- "lib/net/ssh/transport/hmac/abstract.rb",
77
- "lib/net/ssh/transport/hmac/md5.rb",
78
- "lib/net/ssh/transport/hmac/md5_96.rb",
79
- "lib/net/ssh/transport/hmac/none.rb",
80
- "lib/net/ssh/transport/hmac/ripemd160.rb",
81
- "lib/net/ssh/transport/hmac/sha1.rb",
82
- "lib/net/ssh/transport/hmac/sha1_96.rb",
83
- "lib/net/ssh/transport/hmac/sha2_256.rb",
84
- "lib/net/ssh/transport/hmac/sha2_256_96.rb",
85
- "lib/net/ssh/transport/hmac/sha2_512.rb",
86
- "lib/net/ssh/transport/hmac/sha2_512_96.rb",
87
- "lib/net/ssh/transport/identity_cipher.rb",
88
- "lib/net/ssh/transport/kex.rb",
89
- "lib/net/ssh/transport/kex/diffie_hellman_group14_sha1.rb",
90
- "lib/net/ssh/transport/kex/diffie_hellman_group1_sha1.rb",
91
- "lib/net/ssh/transport/kex/diffie_hellman_group_exchange_sha1.rb",
92
- "lib/net/ssh/transport/kex/diffie_hellman_group_exchange_sha256.rb",
93
- "lib/net/ssh/transport/kex/ecdh_sha2_nistp256.rb",
94
- "lib/net/ssh/transport/kex/ecdh_sha2_nistp384.rb",
95
- "lib/net/ssh/transport/kex/ecdh_sha2_nistp521.rb",
96
- "lib/net/ssh/transport/key_expander.rb",
97
- "lib/net/ssh/transport/openssl.rb",
98
- "lib/net/ssh/transport/packet_stream.rb",
99
- "lib/net/ssh/transport/server_version.rb",
100
- "lib/net/ssh/transport/session.rb",
101
- "lib/net/ssh/transport/state.rb",
102
- "lib/net/ssh/verifiers/lenient.rb",
103
- "lib/net/ssh/verifiers/null.rb",
104
- "lib/net/ssh/verifiers/secure.rb",
105
- "lib/net/ssh/verifiers/strict.rb",
106
- "lib/net/ssh/version.rb",
107
- "net-ssh.gemspec",
108
- "setup.rb",
109
- "support/arcfour_check.rb",
110
- "support/ssh_tunnel_bug.rb",
111
- "test/README.txt",
112
- "test/authentication/methods/common.rb",
113
- "test/authentication/methods/test_abstract.rb",
114
- "test/authentication/methods/test_hostbased.rb",
115
- "test/authentication/methods/test_keyboard_interactive.rb",
116
- "test/authentication/methods/test_none.rb",
117
- "test/authentication/methods/test_password.rb",
118
- "test/authentication/methods/test_publickey.rb",
119
- "test/authentication/test_agent.rb",
120
- "test/authentication/test_key_manager.rb",
121
- "test/authentication/test_session.rb",
122
- "test/common.rb",
123
- "test/configs/eqsign",
124
- "test/configs/exact_match",
125
- "test/configs/host_plus",
126
- "test/configs/multihost",
127
- "test/configs/nohost",
128
- "test/configs/numeric_host",
129
- "test/configs/send_env",
130
- "test/configs/substitutes",
131
- "test/configs/wild_cards",
132
- "test/connection/test_channel.rb",
133
- "test/connection/test_session.rb",
134
- "test/known_hosts/github",
135
- "test/manual/test_forward.rb",
136
- "test/start/test_options.rb",
137
- "test/start/test_transport.rb",
138
- "test/test_all.rb",
139
- "test/test_buffer.rb",
140
- "test/test_buffered_io.rb",
141
- "test/test_config.rb",
142
- "test/test_key_factory.rb",
143
- "test/test_known_hosts.rb",
144
- "test/transport/hmac/test_md5.rb",
145
- "test/transport/hmac/test_md5_96.rb",
146
- "test/transport/hmac/test_none.rb",
147
- "test/transport/hmac/test_ripemd160.rb",
148
- "test/transport/hmac/test_sha1.rb",
149
- "test/transport/hmac/test_sha1_96.rb",
150
- "test/transport/hmac/test_sha2_256.rb",
151
- "test/transport/hmac/test_sha2_256_96.rb",
152
- "test/transport/hmac/test_sha2_512.rb",
153
- "test/transport/hmac/test_sha2_512_96.rb",
154
- "test/transport/kex/test_diffie_hellman_group14_sha1.rb",
155
- "test/transport/kex/test_diffie_hellman_group1_sha1.rb",
156
- "test/transport/kex/test_diffie_hellman_group_exchange_sha1.rb",
157
- "test/transport/kex/test_diffie_hellman_group_exchange_sha256.rb",
158
- "test/transport/kex/test_ecdh_sha2_nistp256.rb",
159
- "test/transport/kex/test_ecdh_sha2_nistp384.rb",
160
- "test/transport/kex/test_ecdh_sha2_nistp521.rb",
161
- "test/transport/test_algorithms.rb",
162
- "test/transport/test_cipher_factory.rb",
163
- "test/transport/test_hmac.rb",
164
- "test/transport/test_identity_cipher.rb",
165
- "test/transport/test_packet_stream.rb",
166
- "test/transport/test_server_version.rb",
167
- "test/transport/test_session.rb",
168
- "test/transport/test_state.rb"
25
+ "README.md"
169
26
  ]
170
- s.homepage = "https://github.com/net-ssh/net-ssh"
171
- s.licenses = ["MIT"]
172
- s.require_paths = ["lib"]
173
- s.rubyforge_project = "net-ssh"
174
- s.rubygems_version = "1.8.25"
175
- s.summary = "Net::SSH: a pure-Ruby implementation of the SSH2 client protocol."
176
27
 
177
- if s.respond_to? :specification_version then
178
- s.specification_version = 3
28
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
29
+ spec.bindir = "exe"
30
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib"]
179
32
 
180
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
181
- s.add_development_dependency(%q<test-unit>, [">= 0"])
182
- s.add_development_dependency(%q<mocha>, [">= 0"])
183
- else
184
- s.add_dependency(%q<test-unit>, [">= 0"])
185
- s.add_dependency(%q<mocha>, [">= 0"])
186
- end
187
- else
188
- s.add_dependency(%q<test-unit>, [">= 0"])
189
- s.add_dependency(%q<mocha>, [">= 0"])
33
+ unless ENV['NET_SSH_NO_ED25519']
34
+ spec.add_development_dependency("bcrypt_pbkdf", "~> 1.0") unless RUBY_PLATFORM == "java"
35
+ spec.add_development_dependency("ed25519", "~> 1.2")
36
+ spec.add_development_dependency('x25519') unless RUBY_PLATFORM == 'java'
190
37
  end
191
- end
192
38
 
39
+ spec.add_development_dependency('rbnacl', '~> 7.1') unless ENV['NET_SSH_NO_RBNACL']
40
+
41
+ spec.add_development_dependency "base64"
42
+ spec.add_development_dependency "bundler", ">= 1.17"
43
+ spec.add_development_dependency "minitest", "~> 5.19"
44
+ spec.add_development_dependency "mocha", "~> 2.1.0"
45
+ spec.add_development_dependency "rake", "~> 12.0"
46
+ spec.add_development_dependency "rubocop", "~> 1.28.0"
47
+ end
@@ -15,12 +15,12 @@
15
15
  # visible_hostname netsshtest
16
16
  # * Start squid squid -N -d 1 -D
17
17
  # * Run this script
18
- # * Configure browser proxy to use localhost with LOCAL_PORT.
18
+ # * Configure browser proxy to use localhost with LOCAL_PORT.
19
19
  # * Load any page, wait for it to load fully. If the page loads
20
20
  # correctly, move on. If not, something needs to be corrected.
21
21
  # * Refresh the page several times. This should cause this
22
22
  # script to failed with the error: "closed stream". You may
23
- # need to try a few times.
23
+ # need to try a few times.
24
24
  #
25
25
 
26
26
  require 'highline/import'
@@ -37,10 +37,10 @@ pass = ask("Password: ") { |q| q.echo = "*" }
37
37
  puts "Configure your browser proxy to localhost:#{LOCAL_PORT}"
38
38
 
39
39
  begin
40
- session = Net::SSH.start(host, user, :password => pass)
40
+ session = Net::SSH.start(host, user, password: pass)
41
41
  session.forward.local(LOCAL_PORT, host, PROXY_PORT)
42
- session.loop{true}
43
- rescue => e
42
+ session.loop {true}
43
+ rescue StandardError => e
44
44
  puts e.message
45
45
  puts e.backtrace
46
46
  end
data.tar.gz.sig ADDED
Binary file