net-ssh 3.2.0.rc2 → 7.1.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 (204) hide show
  1. checksums.yaml +5 -5
  2. checksums.yaml.gz.sig +2 -2
  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 +16 -0
  8. data/.gitignore +13 -0
  9. data/.rubocop.yml +22 -0
  10. data/.rubocop_todo.yml +1081 -0
  11. data/CHANGES.txt +228 -7
  12. data/Dockerfile +27 -0
  13. data/Dockerfile.openssl3 +17 -0
  14. data/Gemfile +13 -0
  15. data/Gemfile.noed25519 +12 -0
  16. data/ISSUE_TEMPLATE.md +30 -0
  17. data/Manifest +4 -5
  18. data/README.md +297 -0
  19. data/Rakefile +125 -74
  20. data/SECURITY.md +4 -0
  21. data/appveyor.yml +58 -0
  22. data/docker-compose.yml +23 -0
  23. data/lib/net/ssh/authentication/agent.rb +279 -18
  24. data/lib/net/ssh/authentication/certificate.rb +183 -0
  25. data/lib/net/ssh/authentication/constants.rb +17 -15
  26. data/lib/net/ssh/authentication/ed25519.rb +186 -0
  27. data/lib/net/ssh/authentication/ed25519_loader.rb +31 -0
  28. data/lib/net/ssh/authentication/key_manager.rb +86 -39
  29. data/lib/net/ssh/authentication/methods/abstract.rb +67 -48
  30. data/lib/net/ssh/authentication/methods/hostbased.rb +34 -37
  31. data/lib/net/ssh/authentication/methods/keyboard_interactive.rb +13 -13
  32. data/lib/net/ssh/authentication/methods/none.rb +16 -19
  33. data/lib/net/ssh/authentication/methods/password.rb +27 -17
  34. data/lib/net/ssh/authentication/methods/publickey.rb +96 -55
  35. data/lib/net/ssh/authentication/pageant.rb +471 -367
  36. data/lib/net/ssh/authentication/pub_key_fingerprint.rb +43 -0
  37. data/lib/net/ssh/authentication/session.rb +131 -121
  38. data/lib/net/ssh/buffer.rb +399 -300
  39. data/lib/net/ssh/buffered_io.rb +154 -150
  40. data/lib/net/ssh/config.rb +308 -185
  41. data/lib/net/ssh/connection/channel.rb +635 -613
  42. data/lib/net/ssh/connection/constants.rb +29 -29
  43. data/lib/net/ssh/connection/event_loop.rb +123 -0
  44. data/lib/net/ssh/connection/keepalive.rb +55 -51
  45. data/lib/net/ssh/connection/session.rb +620 -551
  46. data/lib/net/ssh/connection/term.rb +125 -123
  47. data/lib/net/ssh/errors.rb +101 -99
  48. data/lib/net/ssh/key_factory.rb +197 -105
  49. data/lib/net/ssh/known_hosts.rb +214 -127
  50. data/lib/net/ssh/loggable.rb +50 -49
  51. data/lib/net/ssh/packet.rb +83 -79
  52. data/lib/net/ssh/prompt.rb +50 -81
  53. data/lib/net/ssh/proxy/command.rb +105 -90
  54. data/lib/net/ssh/proxy/errors.rb +12 -10
  55. data/lib/net/ssh/proxy/http.rb +82 -79
  56. data/lib/net/ssh/proxy/https.rb +50 -0
  57. data/lib/net/ssh/proxy/jump.rb +54 -0
  58. data/lib/net/ssh/proxy/socks4.rb +2 -6
  59. data/lib/net/ssh/proxy/socks5.rb +14 -17
  60. data/lib/net/ssh/service/forward.rb +370 -317
  61. data/lib/net/ssh/test/channel.rb +145 -136
  62. data/lib/net/ssh/test/extensions.rb +131 -110
  63. data/lib/net/ssh/test/kex.rb +34 -32
  64. data/lib/net/ssh/test/local_packet.rb +46 -44
  65. data/lib/net/ssh/test/packet.rb +89 -70
  66. data/lib/net/ssh/test/remote_packet.rb +32 -30
  67. data/lib/net/ssh/test/script.rb +156 -142
  68. data/lib/net/ssh/test/socket.rb +49 -48
  69. data/lib/net/ssh/test.rb +82 -77
  70. data/lib/net/ssh/transport/algorithms.rb +441 -360
  71. data/lib/net/ssh/transport/cipher_factory.rb +96 -98
  72. data/lib/net/ssh/transport/constants.rb +32 -24
  73. data/lib/net/ssh/transport/ctr.rb +42 -22
  74. data/lib/net/ssh/transport/hmac/abstract.rb +81 -63
  75. data/lib/net/ssh/transport/hmac/md5.rb +0 -2
  76. data/lib/net/ssh/transport/hmac/md5_96.rb +0 -2
  77. data/lib/net/ssh/transport/hmac/none.rb +0 -2
  78. data/lib/net/ssh/transport/hmac/ripemd160.rb +0 -2
  79. data/lib/net/ssh/transport/hmac/sha1.rb +0 -2
  80. data/lib/net/ssh/transport/hmac/sha1_96.rb +0 -2
  81. data/lib/net/ssh/transport/hmac/sha2_256.rb +7 -11
  82. data/lib/net/ssh/transport/hmac/sha2_256_96.rb +4 -8
  83. data/lib/net/ssh/transport/hmac/sha2_256_etm.rb +12 -0
  84. data/lib/net/ssh/transport/hmac/sha2_512.rb +6 -9
  85. data/lib/net/ssh/transport/hmac/sha2_512_96.rb +4 -8
  86. data/lib/net/ssh/transport/hmac/sha2_512_etm.rb +12 -0
  87. data/lib/net/ssh/transport/hmac.rb +14 -12
  88. data/lib/net/ssh/transport/identity_cipher.rb +54 -52
  89. data/lib/net/ssh/transport/kex/abstract.rb +130 -0
  90. data/lib/net/ssh/transport/kex/abstract5656.rb +72 -0
  91. data/lib/net/ssh/transport/kex/curve25519_sha256.rb +39 -0
  92. data/lib/net/ssh/transport/kex/curve25519_sha256_loader.rb +30 -0
  93. data/lib/net/ssh/transport/kex/diffie_hellman_group14_sha1.rb +33 -40
  94. data/lib/net/ssh/transport/kex/diffie_hellman_group14_sha256.rb +11 -0
  95. data/lib/net/ssh/transport/kex/diffie_hellman_group1_sha1.rb +119 -213
  96. data/lib/net/ssh/transport/kex/diffie_hellman_group_exchange_sha1.rb +53 -61
  97. data/lib/net/ssh/transport/kex/diffie_hellman_group_exchange_sha256.rb +5 -9
  98. data/lib/net/ssh/transport/kex/ecdh_sha2_nistp256.rb +36 -90
  99. data/lib/net/ssh/transport/kex/ecdh_sha2_nistp384.rb +18 -10
  100. data/lib/net/ssh/transport/kex/ecdh_sha2_nistp521.rb +18 -10
  101. data/lib/net/ssh/transport/kex.rb +15 -12
  102. data/lib/net/ssh/transport/key_expander.rb +24 -20
  103. data/lib/net/ssh/transport/openssl.rb +161 -124
  104. data/lib/net/ssh/transport/packet_stream.rb +225 -185
  105. data/lib/net/ssh/transport/server_version.rb +55 -56
  106. data/lib/net/ssh/transport/session.rb +306 -255
  107. data/lib/net/ssh/transport/state.rb +178 -176
  108. data/lib/net/ssh/verifiers/accept_new.rb +33 -0
  109. data/lib/net/ssh/verifiers/accept_new_or_local_tunnel.rb +33 -0
  110. data/lib/net/ssh/verifiers/always.rb +58 -0
  111. data/lib/net/ssh/verifiers/never.rb +19 -0
  112. data/lib/net/ssh/version.rb +55 -53
  113. data/lib/net/ssh.rb +110 -47
  114. data/net-ssh-public_cert.pem +18 -18
  115. data/net-ssh.gemspec +36 -205
  116. data/support/ssh_tunnel_bug.rb +5 -5
  117. data.tar.gz.sig +0 -0
  118. metadata +153 -118
  119. metadata.gz.sig +0 -0
  120. data/.travis.yml +0 -18
  121. data/README.rdoc +0 -182
  122. data/lib/net/ssh/authentication/agent/java_pageant.rb +0 -85
  123. data/lib/net/ssh/authentication/agent/socket.rb +0 -178
  124. data/lib/net/ssh/ruby_compat.rb +0 -46
  125. data/lib/net/ssh/verifiers/lenient.rb +0 -30
  126. data/lib/net/ssh/verifiers/null.rb +0 -12
  127. data/lib/net/ssh/verifiers/secure.rb +0 -52
  128. data/lib/net/ssh/verifiers/strict.rb +0 -24
  129. data/setup.rb +0 -1585
  130. data/support/arcfour_check.rb +0 -20
  131. data/test/README.txt +0 -18
  132. data/test/authentication/methods/common.rb +0 -28
  133. data/test/authentication/methods/test_abstract.rb +0 -51
  134. data/test/authentication/methods/test_hostbased.rb +0 -114
  135. data/test/authentication/methods/test_keyboard_interactive.rb +0 -121
  136. data/test/authentication/methods/test_none.rb +0 -41
  137. data/test/authentication/methods/test_password.rb +0 -95
  138. data/test/authentication/methods/test_publickey.rb +0 -148
  139. data/test/authentication/test_agent.rb +0 -232
  140. data/test/authentication/test_key_manager.rb +0 -240
  141. data/test/authentication/test_session.rb +0 -107
  142. data/test/common.rb +0 -125
  143. data/test/configs/auth_off +0 -5
  144. data/test/configs/auth_on +0 -4
  145. data/test/configs/empty +0 -0
  146. data/test/configs/eqsign +0 -3
  147. data/test/configs/exact_match +0 -8
  148. data/test/configs/host_plus +0 -10
  149. data/test/configs/multihost +0 -4
  150. data/test/configs/negative_match +0 -6
  151. data/test/configs/nohost +0 -19
  152. data/test/configs/numeric_host +0 -4
  153. data/test/configs/proxy_remote_user +0 -2
  154. data/test/configs/send_env +0 -2
  155. data/test/configs/substitutes +0 -8
  156. data/test/configs/wild_cards +0 -14
  157. data/test/connection/test_channel.rb +0 -487
  158. data/test/connection/test_session.rb +0 -564
  159. data/test/integration/README.txt +0 -17
  160. data/test/integration/Vagrantfile +0 -12
  161. data/test/integration/common.rb +0 -63
  162. data/test/integration/playbook.yml +0 -56
  163. data/test/integration/test_forward.rb +0 -637
  164. data/test/integration/test_id_rsa_keys.rb +0 -96
  165. data/test/integration/test_proxy.rb +0 -93
  166. data/test/known_hosts/github +0 -1
  167. data/test/known_hosts/github_hash +0 -1
  168. data/test/manual/test_pageant.rb +0 -37
  169. data/test/start/test_connection.rb +0 -53
  170. data/test/start/test_options.rb +0 -57
  171. data/test/start/test_transport.rb +0 -28
  172. data/test/start/test_user_nil.rb +0 -27
  173. data/test/test_all.rb +0 -12
  174. data/test/test_buffer.rb +0 -433
  175. data/test/test_buffered_io.rb +0 -63
  176. data/test/test_config.rb +0 -268
  177. data/test/test_key_factory.rb +0 -191
  178. data/test/test_known_hosts.rb +0 -66
  179. data/test/transport/hmac/test_md5.rb +0 -41
  180. data/test/transport/hmac/test_md5_96.rb +0 -27
  181. data/test/transport/hmac/test_none.rb +0 -34
  182. data/test/transport/hmac/test_ripemd160.rb +0 -36
  183. data/test/transport/hmac/test_sha1.rb +0 -36
  184. data/test/transport/hmac/test_sha1_96.rb +0 -27
  185. data/test/transport/hmac/test_sha2_256.rb +0 -37
  186. data/test/transport/hmac/test_sha2_256_96.rb +0 -27
  187. data/test/transport/hmac/test_sha2_512.rb +0 -37
  188. data/test/transport/hmac/test_sha2_512_96.rb +0 -27
  189. data/test/transport/kex/test_diffie_hellman_group14_sha1.rb +0 -13
  190. data/test/transport/kex/test_diffie_hellman_group1_sha1.rb +0 -150
  191. data/test/transport/kex/test_diffie_hellman_group_exchange_sha1.rb +0 -96
  192. data/test/transport/kex/test_diffie_hellman_group_exchange_sha256.rb +0 -19
  193. data/test/transport/kex/test_ecdh_sha2_nistp256.rb +0 -161
  194. data/test/transport/kex/test_ecdh_sha2_nistp384.rb +0 -38
  195. data/test/transport/kex/test_ecdh_sha2_nistp521.rb +0 -38
  196. data/test/transport/test_algorithms.rb +0 -328
  197. data/test/transport/test_cipher_factory.rb +0 -443
  198. data/test/transport/test_hmac.rb +0 -34
  199. data/test/transport/test_identity_cipher.rb +0 -40
  200. data/test/transport/test_packet_stream.rb +0 -1762
  201. data/test/transport/test_server_version.rb +0 -74
  202. data/test/transport/test_session.rb +0 -331
  203. data/test/transport/test_state.rb +0 -181
  204. data/test/verifiers/test_secure.rb +0 -40
@@ -1,178 +0,0 @@
1
- require 'net/ssh/transport/server_version'
2
-
3
- # Only load pageant on Windows
4
- if Net::SSH::Authentication::PLATFORM == :win32
5
- require 'net/ssh/authentication/pageant'
6
- end
7
-
8
- module Net; module SSH; module Authentication
9
-
10
- # This class implements a simple client for the ssh-agent protocol. It
11
- # does not implement any specific protocol, but instead copies the
12
- # behavior of the ssh-agent functions in the OpenSSH library (3.8).
13
- #
14
- # This means that although it behaves like a SSH1 client, it also has
15
- # some SSH2 functionality (like signing data).
16
- class Agent
17
- include Loggable
18
-
19
- # A simple module for extending keys, to allow comments to be specified
20
- # for them.
21
- module Comment
22
- attr_accessor :comment
23
- end
24
-
25
- SSH2_AGENT_REQUEST_VERSION = 1
26
- SSH2_AGENT_REQUEST_IDENTITIES = 11
27
- SSH2_AGENT_IDENTITIES_ANSWER = 12
28
- SSH2_AGENT_SIGN_REQUEST = 13
29
- SSH2_AGENT_SIGN_RESPONSE = 14
30
- SSH2_AGENT_FAILURE = 30
31
- SSH2_AGENT_VERSION_RESPONSE = 103
32
-
33
- SSH_COM_AGENT2_FAILURE = 102
34
-
35
- SSH_AGENT_REQUEST_RSA_IDENTITIES = 1
36
- SSH_AGENT_RSA_IDENTITIES_ANSWER1 = 2
37
- SSH_AGENT_RSA_IDENTITIES_ANSWER2 = 5
38
- SSH_AGENT_FAILURE = 5
39
-
40
- # The underlying socket being used to communicate with the SSH agent.
41
- attr_reader :socket
42
-
43
- # Instantiates a new agent object, connects to a running SSH agent,
44
- # negotiates the agent protocol version, and returns the agent object.
45
- def self.connect(logger=nil, agent_socket_factory = nil)
46
- agent = new(logger)
47
- agent.connect!(agent_socket_factory)
48
- agent.negotiate!
49
- agent
50
- end
51
-
52
- # Creates a new Agent object, using the optional logger instance to
53
- # report status.
54
- def initialize(logger=nil)
55
- self.logger = logger
56
- end
57
-
58
- # Connect to the agent process using the socket factory and socket name
59
- # given by the attribute writers. If the agent on the other end of the
60
- # socket reports that it is an SSH2-compatible agent, this will fail
61
- # (it only supports the ssh-agent distributed by OpenSSH).
62
- def connect!(agent_socket_factory = nil)
63
- begin
64
- debug { "connecting to ssh-agent" }
65
- @socket = agent_socket_factory.nil? ? socket_class.open(ENV['SSH_AUTH_SOCK']) : agent_socket_factory.call
66
- rescue
67
- error { "could not connect to ssh-agent" }
68
- raise AgentNotAvailable, $!.message
69
- end
70
- end
71
-
72
- # Attempts to negotiate the SSH agent protocol version. Raises an error
73
- # if the version could not be negotiated successfully.
74
- def negotiate!
75
- # determine what type of agent we're communicating with
76
- type, body = send_and_wait(SSH2_AGENT_REQUEST_VERSION, :string, Transport::ServerVersion::PROTO_VERSION)
77
-
78
- if type == SSH2_AGENT_VERSION_RESPONSE
79
- raise AgentNotAvailable, "SSH2 agents are not yet supported"
80
- elsif type == SSH2_AGENT_FAILURE
81
- debug { "Unexpected response type==#{type}, this will be ignored" }
82
- elsif type != SSH_AGENT_RSA_IDENTITIES_ANSWER1 && type != SSH_AGENT_RSA_IDENTITIES_ANSWER2
83
- raise AgentNotAvailable, "unknown response from agent: #{type}, #{body.to_s.inspect}"
84
- end
85
- end
86
-
87
- # Return an array of all identities (public keys) known to the agent.
88
- # Each key returned is augmented with a +comment+ property which is set
89
- # to the comment returned by the agent for that key.
90
- def identities
91
- type, body = send_and_wait(SSH2_AGENT_REQUEST_IDENTITIES)
92
- raise AgentError, "could not get identity count" if agent_failed(type)
93
- raise AgentError, "bad authentication reply: #{type}" if type != SSH2_AGENT_IDENTITIES_ANSWER
94
-
95
- identities = []
96
- body.read_long.times do
97
- key_str = body.read_string
98
- comment_str = body.read_string
99
- begin
100
- key = Buffer.new(key_str).read_key
101
- key.extend(Comment)
102
- key.comment = comment_str
103
- identities.push key
104
- rescue NotImplementedError => e
105
- error { "ignoring unimplemented key:#{e.message} #{comment_str}" }
106
- end
107
- end
108
-
109
- return identities
110
- end
111
-
112
- # Closes this socket. This agent reference is no longer able to
113
- # query the agent.
114
- def close
115
- @socket.close
116
- end
117
-
118
- # Using the agent and the given public key, sign the given data. The
119
- # signature is returned in SSH2 format.
120
- def sign(key, data)
121
- type, reply = send_and_wait(SSH2_AGENT_SIGN_REQUEST, :string, Buffer.from(:key, key), :string, data, :long, 0)
122
-
123
- if agent_failed(type)
124
- raise AgentError, "agent could not sign data with requested identity"
125
- elsif type != SSH2_AGENT_SIGN_RESPONSE
126
- raise AgentError, "bad authentication response #{type}"
127
- end
128
-
129
- return reply.read_string
130
- end
131
-
132
- private
133
-
134
- # Returns the agent socket factory to use.
135
- def socket_class
136
- if Net::SSH::Authentication::PLATFORM == :win32
137
- Pageant::Socket
138
- else
139
- UNIXSocket
140
- end
141
- end
142
-
143
- # Send a new packet of the given type, with the associated data.
144
- def send_packet(type, *args)
145
- buffer = Buffer.from(*args)
146
- data = [buffer.length + 1, type.to_i, buffer.to_s].pack("NCA*")
147
- debug { "sending agent request #{type} len #{buffer.length}" }
148
- @socket.send data, 0
149
- end
150
-
151
- # Read the next packet from the agent. This will return a two-part
152
- # tuple consisting of the packet type, and the packet's body (which
153
- # is returned as a Net::SSH::Buffer).
154
- def read_packet
155
- buffer = Net::SSH::Buffer.new(@socket.read(4))
156
- buffer.append(@socket.read(buffer.read_long))
157
- type = buffer.read_byte
158
- debug { "received agent packet #{type} len #{buffer.length-4}" }
159
- return type, buffer
160
- end
161
-
162
- # Send the given packet and return the subsequent reply from the agent.
163
- # (See #send_packet and #read_packet).
164
- def send_and_wait(type, *args)
165
- send_packet(type, *args)
166
- read_packet
167
- end
168
-
169
- # Returns +true+ if the parameter indicates a "failure" response from
170
- # the agent, and +false+ otherwise.
171
- def agent_failed(type)
172
- type == SSH_AGENT_FAILURE ||
173
- type == SSH2_AGENT_FAILURE ||
174
- type == SSH_COM_AGENT2_FAILURE
175
- end
176
- end
177
-
178
- end; end; end
@@ -1,46 +0,0 @@
1
- require 'thread'
2
-
3
- class String
4
- if RUBY_VERSION < "1.9"
5
- def getbyte(index)
6
- self[index]
7
- end
8
- def setbyte(index, c)
9
- self[index] = c
10
- end
11
- end
12
- end
13
-
14
- module Net; module SSH
15
-
16
- # This class contains miscellaneous patches and workarounds
17
- # for different ruby implementations.
18
- class Compat
19
-
20
- # A workaround for an IO#select threading bug in certain versions of MRI 1.8.
21
- # See: http://net-ssh.lighthouseapp.com/projects/36253/tickets/1-ioselect-threading-bug-in-ruby-18
22
- # The root issue is documented here: http://redmine.ruby-lang.org/issues/show/1993
23
- if RUBY_VERSION >= '1.9' || RUBY_PLATFORM == 'java'
24
- def self.io_select(*params)
25
- IO.select(*params)
26
- end
27
- else
28
- SELECT_MUTEX = Mutex.new
29
- def self.io_select(*params)
30
- # It should be safe to wrap calls in a mutex when the timeout is 0
31
- # (that is, the call is not supposed to block).
32
- # We leave blocking calls unprotected to avoid causing deadlocks.
33
- # This should still catch the main case for Capistrano users.
34
- if params[3] == 0
35
- SELECT_MUTEX.synchronize do
36
- IO.select(*params)
37
- end
38
- else
39
- IO.select(*params)
40
- end
41
- end
42
- end
43
-
44
- end
45
-
46
- end; end
@@ -1,30 +0,0 @@
1
- require 'net/ssh/verifiers/strict'
2
-
3
- module Net; module SSH; module Verifiers
4
-
5
- # Basically the same as the Strict verifier, but does not try to actually
6
- # verify a connection if the server is the localhost and the port is a
7
- # nonstandard port number. Those two conditions will typically mean the
8
- # connection is being tunnelled through a forwarded port, so the known-hosts
9
- # file will not be helpful (in general).
10
- class Lenient < Strict
11
- # Tries to determine if the connection is being tunnelled, and if so,
12
- # returns true. Otherwise, performs the standard strict verification.
13
- def verify(arguments)
14
- return true if tunnelled?(arguments)
15
- super
16
- end
17
-
18
- private
19
-
20
- # A connection is potentially being tunnelled if the port is not 22,
21
- # and the ip refers to the localhost.
22
- def tunnelled?(args)
23
- return false if args[:session].port == Net::SSH::Transport::Session::DEFAULT_PORT
24
-
25
- ip = args[:session].peer[:ip]
26
- return ip == "127.0.0.1" || ip == "::1"
27
- end
28
- end
29
-
30
- end; end; end
@@ -1,12 +0,0 @@
1
- module Net; module SSH; module Verifiers
2
-
3
- # The Null host key verifier simply allows every key it sees, without
4
- # bothering to verify. This is simple, but is not particularly secure.
5
- class Null
6
- # Returns true.
7
- def verify(arguments)
8
- true
9
- end
10
- end
11
-
12
- end; end; end
@@ -1,52 +0,0 @@
1
- require 'net/ssh/errors'
2
- require 'net/ssh/known_hosts'
3
-
4
- module Net; module SSH; module Verifiers
5
-
6
- # Does a strict host verification, looking the server up in the known
7
- # host files to see if a key has already been seen for this server. If this
8
- # server does not appear in any host file, an exception will be raised
9
- # (HostKeyUnknown). This is in contrast to the "Strict" class, which will
10
- # silently add the key to your known_hosts file. If the server does appear at
11
- # least once, but the key given does not match any known for the server, an
12
- # exception will be raised (HostKeyMismatch).
13
- # Otherwise, this returns true.
14
- class Secure
15
- def verify(arguments)
16
- host_keys = arguments[:session].host_keys
17
-
18
- # We've never seen this host before, so raise an exception.
19
- if host_keys.empty?
20
- process_cache_miss(host_keys, arguments, HostKeyUnknown, "is unknown")
21
- end
22
-
23
- # If we found any matches, check to see that the key type and
24
- # blob also match.
25
- found = host_keys.any? do |key|
26
- key.ssh_type == arguments[:key].ssh_type &&
27
- key.to_blob == arguments[:key].to_blob
28
- end
29
-
30
- # If a match was found, return true. Otherwise, raise an exception
31
- # indicating that the key was not recognized.
32
- unless found
33
- process_cache_miss(host_keys, arguments, HostKeyMismatch, "does not match")
34
- end
35
-
36
- found
37
- end
38
-
39
- private
40
-
41
- def process_cache_miss(host_keys, args, exc_class, message)
42
- exception = exc_class.new("fingerprint #{args[:fingerprint]} " +
43
- "#{message} for #{host_keys.host.inspect}")
44
- exception.data = args
45
- exception.callback = Proc.new do
46
- host_keys.add_host_key(args[:key])
47
- end
48
- raise exception
49
- end
50
- end
51
-
52
- end; end; end
@@ -1,24 +0,0 @@
1
- require 'net/ssh/errors'
2
- require 'net/ssh/known_hosts'
3
- require 'net/ssh/verifiers/secure'
4
-
5
- module Net; module SSH; module Verifiers
6
-
7
- # Does a strict host verification, looking the server up in the known
8
- # host files to see if a key has already been seen for this server. If this
9
- # server does not appear in any host file, this will silently add the
10
- # server. If the server does appear at least once, but the key given does
11
- # not match any known for the server, an exception will be raised (HostKeyMismatch).
12
- # Otherwise, this returns true.
13
- class Strict < Secure
14
- def verify(arguments)
15
- begin
16
- super
17
- rescue HostKeyUnknown => err
18
- err.remember_host!
19
- return true
20
- end
21
- end
22
- end
23
-
24
- end; end; end