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/test/test_buffer.rb DELETED
@@ -1,433 +0,0 @@
1
- # encoding: ASCII-8BIT
2
-
3
- require 'common'
4
- require 'net/ssh/buffer'
5
-
6
- class TestBuffer < Test::Unit::TestCase
7
- def test_constructor_should_initialize_buffer_to_empty_by_default
8
- buffer = new
9
- assert buffer.empty?
10
- assert_equal 0, buffer.position
11
- end
12
-
13
- def test_constructor_with_string_should_initialize_buffer_to_the_string
14
- buffer = new("hello")
15
- assert !buffer.empty?
16
- assert_equal "hello", buffer.to_s
17
- assert_equal 0, buffer.position
18
- end
19
-
20
- def test_from_should_require_an_even_number_of_arguments
21
- assert_raises(ArgumentError) { Net::SSH::Buffer.from("this") }
22
- end
23
-
24
- def test_from_should_build_new_buffer_from_definition
25
- buffer = Net::SSH::Buffer.from(:byte, 1, :long, 2, :int64, 3, :string, "4", :bool, true, :bool, false, :bignum, OpenSSL::BN.new("1234567890", 10), :raw, "something")
26
- assert_equal "\1\0\0\0\2\0\0\0\0\0\0\0\3\0\0\0\0014\1\0\000\000\000\004I\226\002\322something", buffer.to_s
27
- end
28
-
29
- def test_from_with_array_argument_should_write_multiple_of_the_given_type
30
- buffer = Net::SSH::Buffer.from(:byte, [1,2,3,4,5])
31
- assert_equal "\1\2\3\4\5", buffer.to_s
32
- end
33
-
34
- def test_from_should_measure_bytesize_of_utf_8_string_correctly
35
- buffer = Net::SSH::Buffer.from(:string, "\u2603") # Snowman is 3 bytes
36
- assert_equal "\0\0\0\3\u2603", buffer.to_s
37
- end
38
-
39
- def test_read_without_argument_should_read_to_end
40
- buffer = new("hello world")
41
- assert_equal "hello world", buffer.read
42
- assert buffer.eof?
43
- assert_equal 11, buffer.position
44
- end
45
-
46
- def test_read_with_argument_that_is_less_than_length_should_read_that_many_bytes
47
- buffer = new "hello world"
48
- assert_equal "hello", buffer.read(5)
49
- assert_equal 5, buffer.position
50
- end
51
-
52
- def test_read_with_argument_that_is_more_than_length_should_read_no_more_than_length
53
- buffer = new "hello world"
54
- assert_equal "hello world", buffer.read(500)
55
- assert_equal 11, buffer.position
56
- end
57
-
58
- def test_read_at_eof_should_return_empty_string
59
- buffer = new "hello"
60
- buffer.position = 5
61
- assert_equal "", buffer.read
62
- end
63
-
64
- def test_consume_without_argument_should_resize_buffer_to_start_at_position
65
- buffer = new "hello world"
66
- buffer.read(5)
67
- assert_equal 5, buffer.position
68
- assert_equal 11, buffer.length
69
- buffer.consume!
70
- assert_equal 0, buffer.position
71
- assert_equal 6, buffer.length
72
- assert_equal " world", buffer.to_s
73
- end
74
-
75
- def test_consume_with_argument_should_resize_buffer_starting_at_n
76
- buffer = new "hello world"
77
- assert_equal 0, buffer.position
78
- buffer.consume!(5)
79
- assert_equal 0, buffer.position
80
- assert_equal 6, buffer.length
81
- assert_equal " world", buffer.to_s
82
- end
83
-
84
- def test_read_bang_should_read_and_consume_and_return_read_portion
85
- buffer = new "hello world"
86
- assert_equal "hello", buffer.read!(5)
87
- assert_equal 0, buffer.position
88
- assert_equal 6, buffer.length
89
- assert_equal " world", buffer.to_s
90
- end
91
-
92
- def test_available_should_return_length_after_position_to_end_of_string
93
- buffer = new "hello world"
94
- buffer.read(5)
95
- assert_equal 6, buffer.available
96
- end
97
-
98
- def test_clear_bang_should_reset_buffer_contents_and_counters
99
- buffer = new "hello world"
100
- buffer.read(5)
101
- buffer.clear!
102
- assert_equal 0, buffer.length
103
- assert_equal 0, buffer.position
104
- assert_equal "", buffer.to_s
105
- end
106
-
107
- def test_append_should_append_argument_without_changing_position_and_should_return_self
108
- buffer = new "hello world"
109
- buffer.read(5)
110
- buffer.append(" again")
111
- assert_equal 5, buffer.position
112
- assert_equal 12, buffer.available
113
- assert_equal 17, buffer.length
114
- assert_equal "hello world again", buffer.to_s
115
- end
116
-
117
- def test_remainder_as_buffer_should_return_a_new_buffer_filled_with_the_text_after_the_current_position
118
- buffer = new "hello world"
119
- buffer.read(6)
120
- b2 = buffer.remainder_as_buffer
121
- assert_equal 6, buffer.position
122
- assert_equal 0, b2.position
123
- assert_equal "world", b2.to_s
124
- end
125
-
126
- def test_read_int64_should_return_8_byte_integer
127
- buffer = new "\xff\xee\xdd\xcc\xbb\xaa\x99\x88"
128
- assert_equal 0xffeeddccbbaa9988, buffer.read_int64
129
- assert_equal 8, buffer.position
130
- end
131
-
132
- def test_read_int64_should_return_nil_on_partial_read
133
- buffer = new "\0\0\0\0\0\0\0"
134
- assert_nil buffer.read_int64
135
- assert buffer.eof?
136
- end
137
-
138
- def test_read_long_should_return_4_byte_integer
139
- buffer = new "\xff\xee\xdd\xcc\xbb\xaa\x99\x88"
140
- assert_equal 0xffeeddcc, buffer.read_long
141
- assert_equal 4, buffer.position
142
- end
143
-
144
- def test_read_long_should_return_nil_on_partial_read
145
- buffer = new "\0\0\0"
146
- assert_nil buffer.read_long
147
- assert buffer.eof?
148
- end
149
-
150
- def test_read_byte_should_return_single_byte_integer
151
- buffer = new "\xfe\xdc"
152
- assert_equal 0xfe, buffer.read_byte
153
- assert_equal 1, buffer.position
154
- end
155
-
156
- def test_read_byte_should_return_nil_at_eof
157
- assert_nil new.read_byte
158
- end
159
-
160
- def test_read_string_should_read_length_and_data_from_buffer
161
- buffer = new "\0\0\0\x0bhello world"
162
- assert_equal "hello world", buffer.read_string
163
- end
164
-
165
- def test_read_string_should_return_nil_if_4_byte_length_cannot_be_read
166
- assert_nil new("\0\1").read_string
167
- end
168
-
169
- def test_read_bool_should_return_true_if_non_zero_byte_is_read
170
- buffer = new "\1\2\3\4\5\6"
171
- 6.times { assert_equal true, buffer.read_bool }
172
- end
173
-
174
- def test_read_bool_should_return_false_if_zero_byte_is_read
175
- buffer = new "\0"
176
- assert_equal false, buffer.read_bool
177
- end
178
-
179
- def test_read_bool_should_return_nil_at_eof
180
- assert_nil new.read_bool
181
- end
182
-
183
- def test_read_bignum_should_read_openssl_formatted_bignum
184
- buffer = new("\000\000\000\004I\226\002\322")
185
- assert_equal OpenSSL::BN.new("1234567890", 10), buffer.read_bignum
186
- end
187
-
188
- def test_read_bignum_should_return_nil_if_length_cannot_be_read
189
- assert_nil new("\0\1\2").read_bignum
190
- end
191
-
192
- def test_read_key_blob_should_read_dsa_keys
193
- random_dss { |buffer| buffer.read_keyblob("ssh-dss") }
194
- end
195
-
196
- def test_read_key_blob_should_read_rsa_keys
197
- random_rsa { |buffer| buffer.read_keyblob("ssh-rsa") }
198
- end
199
-
200
- def test_read_key_should_read_dsa_key_type_and_keyblob
201
- random_dss do |buffer|
202
- b2 = Net::SSH::Buffer.from(:string, "ssh-dss", :raw, buffer)
203
- b2.read_key
204
- end
205
- end
206
-
207
- def test_read_key_should_read_rsa_key_type_and_keyblob
208
- random_rsa do |buffer|
209
- b2 = Net::SSH::Buffer.from(:string, "ssh-rsa", :raw, buffer)
210
- b2.read_key
211
- end
212
- end
213
-
214
- def test_read_buffer_should_read_a_string_and_return_it_wrapped_in_a_buffer
215
- buffer = new("\0\0\0\x0bhello world")
216
- b2 = buffer.read_buffer
217
- assert_equal 0, b2.position
218
- assert_equal 11, b2.length
219
- assert_equal "hello world", b2.read
220
- end
221
-
222
- def test_read_to_should_return_nil_if_pattern_does_not_exist_in_buffer
223
- buffer = new("one two three")
224
- assert_nil buffer.read_to("\n")
225
- end
226
-
227
- def test_read_to_should_grok_string_patterns
228
- buffer = new("one two three")
229
- assert_equal "one tw", buffer.read_to("tw")
230
- assert_equal 6, buffer.position
231
- end
232
-
233
- def test_read_to_should_grok_regex_patterns
234
- buffer = new("one two three")
235
- assert_equal "one tw", buffer.read_to(/tw/)
236
- assert_equal 6, buffer.position
237
- end
238
-
239
- def test_read_to_should_grok_fixnum_patterns
240
- buffer = new("one two three")
241
- assert_equal "one tw", buffer.read_to(?w)
242
- assert_equal 6, buffer.position
243
- end
244
-
245
- def test_reset_bang_should_reset_position_to_0
246
- buffer = new("hello world")
247
- buffer.read(5)
248
- assert_equal 5, buffer.position
249
- buffer.reset!
250
- assert_equal 0, buffer.position
251
- end
252
-
253
- def test_write_should_write_arguments_directly_to_end_buffer
254
- buffer = new("start")
255
- buffer.write "hello", " ", "world"
256
- assert_equal "starthello world", buffer.to_s
257
- assert_equal 0, buffer.position
258
- end
259
-
260
- def test_write_int64_should_write_arguments_as_8_byte_integers_to_end_of_buffer
261
- buffer = new("start")
262
- buffer.write_int64 0xffeeddccbbaa9988, 0x7766554433221100
263
- assert_equal "start\xff\xee\xdd\xcc\xbb\xaa\x99\x88\x77\x66\x55\x44\x33\x22\x11\x00", buffer.to_s
264
- end
265
-
266
- def test_write_long_should_write_arguments_as_4_byte_integers_to_end_of_buffer
267
- buffer = new("start")
268
- buffer.write_long 0xffeeddcc, 0xbbaa9988
269
- assert_equal "start\xff\xee\xdd\xcc\xbb\xaa\x99\x88", buffer.to_s
270
- end
271
-
272
- def test_write_byte_should_write_arguments_as_1_byte_integers_to_end_of_buffer
273
- buffer = new("start")
274
- buffer.write_byte 1, 2, 3, 4, 5
275
- assert_equal "start\1\2\3\4\5", buffer.to_s
276
- end
277
-
278
- def test_write_bool_should_write_arguments_as_1_byte_boolean_values_to_end_of_buffer
279
- buffer = new("start")
280
- buffer.write_bool nil, false, true, 1, Object.new
281
- assert_equal "start\0\0\1\1\1", buffer.to_s
282
- end
283
-
284
- def test_write_bignum_should_write_arguments_as_ssh_formatted_bignum_values_to_end_of_buffer
285
- buffer = new("start")
286
- buffer.write_bignum OpenSSL::BN.new('1234567890', 10)
287
- assert_equal "start\000\000\000\004I\226\002\322", buffer.to_s
288
- end
289
-
290
- def test_write_dss_key_should_write_argument_to_end_of_buffer
291
- buffer = new("start")
292
-
293
- key = OpenSSL::PKey::DSA.new
294
- key.p = 0xffeeddccbbaa9988
295
- key.q = 0x7766554433221100
296
- key.g = 0xffddbb9977553311
297
- key.pub_key = 0xeeccaa8866442200
298
-
299
- buffer.write_key(key)
300
- assert_equal "start\0\0\0\7ssh-dss\0\0\0\011\0\xff\xee\xdd\xcc\xbb\xaa\x99\x88\0\0\0\010\x77\x66\x55\x44\x33\x22\x11\x00\0\0\0\011\0\xff\xdd\xbb\x99\x77\x55\x33\x11\0\0\0\011\0\xee\xcc\xaa\x88\x66\x44\x22\x00", buffer.to_s
301
- end
302
-
303
- def test_write_rsa_key_should_write_argument_to_end_of_buffer
304
- buffer = new("start")
305
-
306
- key = OpenSSL::PKey::RSA.new
307
- key.e = 0xffeeddccbbaa9988
308
- key.n = 0x7766554433221100
309
-
310
- buffer.write_key(key)
311
- assert_equal "start\0\0\0\7ssh-rsa\0\0\0\011\0\xff\xee\xdd\xcc\xbb\xaa\x99\x88\0\0\0\010\x77\x66\x55\x44\x33\x22\x11\x00", buffer.to_s
312
- end
313
-
314
- if defined?(OpenSSL::PKey::EC)
315
- def test_read_key_blob_should_read_ecdsa_sha2_nistp256_keys
316
- random_ecdsa_sha2_nistp256 { |buffer|
317
- buffer.read_keyblob("ecdsa-sha2-nistp256")
318
- }
319
- end
320
- def test_read_key_blob_should_read_ecdsa_sha2_nistp384_keys
321
- random_ecdsa_sha2_nistp384 { |buffer|
322
- buffer.read_keyblob("ecdsa-sha2-nistp384")
323
- }
324
- end
325
- def test_read_key_blob_should_read_ecdsa_sha2_nistp521_keys
326
- random_ecdsa_sha2_nistp521 { |buffer|
327
- buffer.read_keyblob("ecdsa-sha2-nistp521")
328
- }
329
- end
330
-
331
- def test_read_key_should_read_ecdsa_sha2_nistp256_key_type_and_keyblob
332
- random_ecdsa_sha2_nistp256 do |buffer|
333
- b2 = Net::SSH::Buffer.from(:string, "ecdsa-sha2-nistp256", :raw, buffer)
334
- b2.read_key
335
- end
336
- end
337
- def test_read_key_should_read_ecdsa_sha2_nistp384_key_type_and_keyblob
338
- random_ecdsa_sha2_nistp384 do |buffer|
339
- b2 = Net::SSH::Buffer.from(:string, "ecdsa-sha2-nistp384", :raw, buffer)
340
- b2.read_key
341
- end
342
- end
343
- def test_read_key_should_read_ecdsa_sha2_nistp521_key_type_and_keyblob
344
- random_ecdsa_sha2_nistp521 do |buffer|
345
- b2 = Net::SSH::Buffer.from(:string, "ecdsa-sha2-nistp521", :raw, buffer)
346
- b2.read_key
347
- end
348
- end
349
-
350
- def test_write_ecdsa_sha2_nistp256_key_should_write_argument_to_end_of_buffer
351
- buffer = new("start")
352
- key = OpenSSL::PKey::EC.new("-----BEGIN EC PRIVATE KEY-----\nMHcCAQEEIISGj5vAJCWt2KPI8NwaWVDSNLl2vbRxDIOkY+n6O0VVoAoGCCqGSM49\nAwEHoUQDQgAEnKbs0yEogTKT4QRu8T9nb2svl2mEWXb6g224oCpD2o6TYNXNw54H\nmWkdCv+kFCqSlfSi5fqFhrXdfEY6zSzQYQ==\n-----END EC PRIVATE KEY-----\n")
353
-
354
- buffer.write_key(key)
355
- assert_equal "start\000\000\000\023ecdsa-sha2-nistp256\000\000\000\bnistp256\000\000\000A\004\234\246\354\323!(\2012\223\341\004n\361?gok/\227i\204Yv\372\203m\270\240*C\332\216\223`\325\315\303\236\a\231i\035\n\377\244\024*\222\225\364\242\345\372\205\206\265\335|F:\315,\320a", buffer.to_s
356
- end
357
-
358
- def test_write_ecdsa_sha2_nistp384_key_should_write_argument_to_end_of_buffer
359
- buffer = new("start")
360
- key = OpenSSL::PKey::EC.new("-----BEGIN EC PRIVATE KEY-----\nMIGkAgEBBDBAfxJpzhsR7O+wMol6BcDgualR8rJBvYegUDYbBUrDnPzDx2/gD1lZ\nnwG1FuD2s9igBwYFK4EEACKhZANiAATsfiU4Kxyvvj1DdvFYsdDnZIT7loRlan9I\n8geCWPPl6x7NFRP+awrnTaarMgieGqxG8IQaIA0SsDOICfbDBkuatRi0S1Et/in4\nZwVEZvO81Ro5YSrjuUDAsytnI6OXS28=\n-----END EC PRIVATE KEY-----\n")
361
-
362
- buffer.write_key(key)
363
- assert_equal "start\000\000\000\023ecdsa-sha2-nistp384\000\000\000\bnistp384\000\000\000a\004\354~%8+\034\257\276=Cv\361X\261\320\347d\204\373\226\204ej\177H\362\a\202X\363\345\353\036\315\025\023\376k\n\347M\246\2532\b\236\032\254F\360\204\032 \r\022\2603\210\t\366\303\006K\232\265\030\264KQ-\376)\370g\005Df\363\274\325\0329a*\343\271@\300\263+g#\243\227Ko", buffer.to_s
364
- end
365
-
366
- def test_write_ecdsa_sha2_nistp521_key_should_write_argument_to_end_of_buffer
367
- buffer = new("start")
368
- key = OpenSSL::PKey::EC.new("-----BEGIN EC PRIVATE KEY-----\nMIHbAgEBBEGhnQF/SFo4Vym88HnCfc6BR8WwYqDh9wNTPeqzR8auxIpp0GKQlCG2\nuHzyteJX5/YalV8empYhEzNmNLNn8x7j0aAHBgUrgQQAI6GBiQOBhgAEAYygOgV9\nVI8UyLQ3BDlv+rb3es+ufrIcj++cqcc9QcmRn237NiWRr/1NKy2AKijsEdACtZXo\nxPC0x9Vs9ieC2oR+ANOBubcxPl2giDnBYm8ywAmmlXsP5ByAM17k97CzW5O+Z/uO\nbxGUzzhoXTNcjqpAckhRVKdnh6FL/rKelT0tBYi+\n-----END EC PRIVATE KEY-----\n")
369
-
370
- buffer.write_key(key)
371
- assert_equal "start\000\000\000\023ecdsa-sha2-nistp521\000\000\000\bnistp521\000\000\000\205\004\001\214\240:\005}T\217\024\310\2647\0049o\372\266\367z\317\256~\262\034\217\357\234\251\307=A\311\221\237m\3736%\221\257\375M+-\200*(\354\021\320\002\265\225\350\304\360\264\307\325l\366'\202\332\204~\000\323\201\271\2671>]\240\2109\301bo2\300\t\246\225{\017\344\034\2003^\344\367\260\263[\223\276g\373\216o\021\224\3178h]3\\\216\252@rHQT\247g\207\241K\376\262\236\225=-\005\210\276", buffer.to_s
372
- end
373
- end
374
-
375
- private
376
-
377
- def random_rsa
378
- n1 = OpenSSL::BN.new(rand(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF).to_s, 10)
379
- n2 = OpenSSL::BN.new(rand(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF).to_s, 10)
380
- buffer = Net::SSH::Buffer.from(:bignum, [n1, n2])
381
- key = yield(buffer)
382
- assert_equal "ssh-rsa", key.ssh_type
383
- assert_equal n1, key.e
384
- assert_equal n2, key.n
385
- end
386
-
387
- def random_dss
388
- n1 = OpenSSL::BN.new(rand(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF).to_s, 10)
389
- n2 = OpenSSL::BN.new(rand(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF).to_s, 10)
390
- n3 = OpenSSL::BN.new(rand(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF).to_s, 10)
391
- n4 = OpenSSL::BN.new(rand(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF).to_s, 10)
392
- buffer = Net::SSH::Buffer.from(:bignum, [n1, n2, n3, n4])
393
- key = yield(buffer)
394
- assert_equal "ssh-dss", key.ssh_type
395
- assert_equal n1, key.p
396
- assert_equal n2, key.q
397
- assert_equal n3, key.g
398
- assert_equal n4, key.pub_key
399
- end
400
-
401
- if defined?(OpenSSL::PKey::EC)
402
- def random_ecdsa_sha2_nistp256
403
- k = OpenSSL::PKey::EC.new("prime256v1").generate_key
404
- buffer = Net::SSH::Buffer.from(:string, "nistp256",
405
- :string, k.public_key.to_bn.to_s(2))
406
- key = yield(buffer)
407
- assert_equal "ecdsa-sha2-nistp256", key.ssh_type
408
- assert_equal k.public_key, key.public_key
409
- end
410
-
411
- def random_ecdsa_sha2_nistp384
412
- k = OpenSSL::PKey::EC.new("secp384r1").generate_key
413
- buffer = Net::SSH::Buffer.from(:string, "nistp384",
414
- :string, k.public_key.to_bn.to_s(2))
415
- key = yield(buffer)
416
- assert_equal "ecdsa-sha2-nistp384", key.ssh_type
417
- assert_equal k.public_key, key.public_key
418
- end
419
-
420
- def random_ecdsa_sha2_nistp521
421
- k = OpenSSL::PKey::EC.new("secp521r1").generate_key
422
- buffer = Net::SSH::Buffer.from(:string, "nistp521",
423
- :string, k.public_key.to_bn.to_s(2))
424
- key = yield(buffer)
425
- assert_equal "ecdsa-sha2-nistp521", key.ssh_type
426
- assert_equal k.public_key, key.public_key
427
- end
428
- end
429
-
430
- def new(*args)
431
- Net::SSH::Buffer.new(*args)
432
- end
433
- end
@@ -1,63 +0,0 @@
1
- require 'common'
2
- require 'net/ssh/buffered_io'
3
-
4
- class TestBufferedIo < Test::Unit::TestCase
5
- def test_fill_should_pull_from_underlying_io
6
- io.expects(:recv).with(8192).returns("here is some data")
7
- assert_equal 17, io.fill
8
- assert_equal 17, io.available
9
- assert_equal "here is some data", io.read_available(20)
10
- end
11
-
12
- def test_enqueue_should_not_write_to_underlying_io
13
- assert !io.pending_write?
14
- io.expects(:send).never
15
- io.enqueue("here is some data")
16
- assert io.pending_write?
17
- end
18
-
19
- def test_send_pending_should_not_fail_when_no_writes_are_pending
20
- assert !io.pending_write?
21
- io.expects(:send).never
22
- assert_nothing_raised { io.send_pending }
23
- end
24
-
25
- def test_send_pending_with_pending_writes_should_write_to_underlying_io
26
- io.enqueue("here is some data")
27
- io.expects(:send).with("here is some data", 0).returns(17)
28
- assert io.pending_write?
29
- assert_nothing_raised { io.send_pending }
30
- assert !io.pending_write?
31
- end
32
-
33
- def test_wait_for_pending_sends_should_write_only_once_if_all_can_be_written_at_once
34
- io.enqueue("here is some data")
35
- io.expects(:send).with("here is some data", 0).returns(17)
36
- assert io.pending_write?
37
- assert_nothing_raised { io.wait_for_pending_sends }
38
- assert !io.pending_write?
39
- end
40
-
41
- def test_wait_for_pending_sends_should_write_multiple_times_if_first_write_was_partial
42
- io.enqueue("here is some data")
43
-
44
- io.expects(:send).with("here is some data", 0).returns(10)
45
- io.expects(:send).with("me data", 0).returns(4)
46
- io.expects(:send).with("ata", 0).returns(3)
47
-
48
- IO.expects(:select).times(2).with(nil, [io]).returns([[], [io]])
49
-
50
- assert_nothing_raised { io.wait_for_pending_sends }
51
- assert !io.pending_write?
52
- end
53
-
54
- private
55
-
56
- def io
57
- @io ||= begin
58
- io = mock("io")
59
- io.extend(Net::SSH::BufferedIo)
60
- io
61
- end
62
- end
63
- end
data/test/test_config.rb DELETED
@@ -1,151 +0,0 @@
1
- require 'common'
2
- require 'net/ssh/config'
3
- require 'pathname'
4
-
5
- class TestConfig < Test::Unit::TestCase
6
- def test_home_should_be_absolute_path
7
- assert Pathname.new(ENV['HOME']).absolute?
8
- end
9
-
10
- def test_load_for_non_existant_file_should_return_empty_hash
11
- bogus_file = File.expand_path("/bogus/file")
12
- File.expects(:readable?).with(bogus_file).returns(false)
13
- assert_equal({}, Net::SSH::Config.load(bogus_file, "host.name"))
14
- end
15
-
16
- def test_load_should_expand_path
17
- expected = File.expand_path("~/.ssh/config")
18
- File.expects(:readable?).with(expected).returns(false)
19
- Net::SSH::Config.load("~/.ssh/config", "host.name")
20
- end
21
-
22
- def test_load_with_exact_host_match_should_load_that_section
23
- config = Net::SSH::Config.load(config(:exact_match), "test.host")
24
- assert config['compression']
25
- assert config['forwardagent']
26
- assert_equal 1234, config['port']
27
- end
28
-
29
- def test_load_with_wild_card_matches_should_load_all_matches_with_first_match_taking_precedence
30
- config = Net::SSH::Config.load(config(:wild_cards), "test.host")
31
- assert_equal 1234, config['port']
32
- assert !config['compression']
33
- assert config['forwardagent']
34
- assert_equal %w(~/.ssh/id_dsa), config['identityfile']
35
- assert !config.key?('rekeylimit')
36
- end
37
-
38
- def test_for_should_load_all_files_and_translate_to_net_ssh_options
39
- config = Net::SSH::Config.for("test.host", [config(:exact_match), config(:wild_cards)])
40
- assert_equal 1234, config[:port]
41
- assert config[:compression]
42
- assert config[:forward_agent]
43
- assert_equal %w(~/.ssh/id_dsa), config[:keys]
44
- assert !config.key?(:rekey_limit)
45
- end
46
-
47
- def test_load_with_no_host
48
- config = Net::SSH::Config.load(config(:nohost), "test.host")
49
- assert_equal %w(~/.ssh/id_dsa ~/.ssh/id_rsa), config['identityfile']
50
- assert_equal 1985, config['port']
51
- end
52
-
53
- def test_load_with_multiple_hosts
54
- config = Net::SSH::Config.load(config(:multihost), "test.host")
55
- assert config['compression']
56
- assert_equal '2G', config['rekeylimit']
57
- assert_equal 1980, config['port']
58
- end
59
-
60
- def test_load_with_multiple_hosts_and_config_should_match_for_both
61
- aconfig = Net::SSH::Config.load(config(:multihost), "test.host")
62
- bconfig = Net::SSH::Config.load(config(:multihost), "other.host")
63
- assert_equal aconfig['port'], bconfig['port']
64
- assert_equal aconfig['compression'], bconfig['compression']
65
- assert_equal aconfig['rekeylimit'], bconfig['rekeylimit']
66
- end
67
-
68
- def test_load_should_parse_equal_sign_delimiters
69
- config = Net::SSH::Config.load(config(:eqsign), "test.test")
70
- assert config['compression']
71
- assert_equal 1234, config['port']
72
- end
73
-
74
- def test_translate_should_correctly_translate_from_openssh_to_net_ssh_names
75
- open_ssh = {
76
- 'bindaddress' => "127.0.0.1",
77
- 'ciphers' => "a,b,c",
78
- 'compression' => true,
79
- 'compressionlevel' => 6,
80
- 'connecttimeout' => 100,
81
- 'forwardagent' => true,
82
- 'hostbasedauthentication' => true,
83
- 'hostkeyalgorithms' => "d,e,f",
84
- 'identityfile' => %w(g h i),
85
- 'macs' => "j,k,l",
86
- 'passwordauthentication' => true,
87
- 'port' => 1234,
88
- 'pubkeyauthentication' => true,
89
- 'rekeylimit' => 1024,
90
- 'sendenv' => "LC_*"
91
- }
92
-
93
- net_ssh = Net::SSH::Config.translate(open_ssh)
94
-
95
- assert_equal %w(a b c), net_ssh[:encryption]
96
- assert_equal true, net_ssh[:compression]
97
- assert_equal 6, net_ssh[:compression_level]
98
- assert_equal 100, net_ssh[:timeout]
99
- assert_equal true, net_ssh[:forward_agent]
100
- assert_equal %w(hostbased password publickey), net_ssh[:auth_methods].sort
101
- assert_equal %w(d e f), net_ssh[:host_key]
102
- assert_equal %w(g h i), net_ssh[:keys]
103
- assert_equal %w(j k l), net_ssh[:hmac]
104
- assert_equal 1234, net_ssh[:port]
105
- assert_equal 1024, net_ssh[:rekey_limit]
106
- assert_equal "127.0.0.1", net_ssh[:bind_address]
107
- assert_equal [/^LC_.*$/], net_ssh[:send_env]
108
- end
109
-
110
- def test_load_with_plus_sign_hosts
111
- config = Net::SSH::Config.load(config(:host_plus), "test.host")
112
- assert config['compression']
113
- end
114
-
115
- def test_load_with_numeric_host
116
- config = Net::SSH::Config.load(config(:numeric_host), "1234")
117
- assert config['compression']
118
- assert_equal '2G', config['rekeylimit']
119
- assert_equal 1980, config['port']
120
- end
121
-
122
- def test_load_wildcar_with_substitutes
123
- config = Net::SSH::Config.load(config(:substitutes), "toto")
124
- net_ssh = Net::SSH::Config.translate(config)
125
- assert_equal 'toto', net_ssh[:host_name]
126
- end
127
-
128
- def test_load_sufix_with_substitutes
129
- config = Net::SSH::Config.load(config(:substitutes), "test")
130
- net_ssh = Net::SSH::Config.translate(config)
131
- assert_equal 'test.sufix', net_ssh[:host_name]
132
- end
133
-
134
- def test_load_prefix_and_sufix_with_substitutes
135
- config = Net::SSH::Config.load(config(:substitutes), "1234")
136
- net_ssh = Net::SSH::Config.translate(config)
137
- assert_equal 'prefix.1234.sufix', net_ssh[:host_name]
138
- end
139
-
140
- def test_load_with_send_env
141
- config = Net::SSH::Config.load(config(:send_env), "1234")
142
- net_ssh = Net::SSH::Config.translate(config)
143
- assert_equal [/^GIT_.*$/, /^LANG$/, /^LC_.*$/], net_ssh[:send_env]
144
- end
145
-
146
- private
147
-
148
- def config(name)
149
- "test/configs/#{name}"
150
- end
151
- end