net-ssh 3.2.0 → 7.2.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (210) hide show
  1. checksums.yaml +5 -5
  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 +93 -0
  8. data/.github/workflows/rubocop.yml +16 -0
  9. data/.gitignore +13 -0
  10. data/.rubocop.yml +22 -0
  11. data/.rubocop_todo.yml +1081 -0
  12. data/CHANGES.txt +237 -7
  13. data/DEVELOPMENT.md +23 -0
  14. data/Dockerfile +27 -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 +298 -0
  22. data/Rakefile +125 -74
  23. data/SECURITY.md +4 -0
  24. data/appveyor.yml +58 -0
  25. data/docker-compose.yml +23 -0
  26. data/lib/net/ssh/authentication/agent.rb +279 -18
  27. data/lib/net/ssh/authentication/certificate.rb +183 -0
  28. data/lib/net/ssh/authentication/constants.rb +17 -15
  29. data/lib/net/ssh/authentication/ed25519.rb +186 -0
  30. data/lib/net/ssh/authentication/ed25519_loader.rb +31 -0
  31. data/lib/net/ssh/authentication/key_manager.rb +86 -39
  32. data/lib/net/ssh/authentication/methods/abstract.rb +67 -48
  33. data/lib/net/ssh/authentication/methods/hostbased.rb +34 -37
  34. data/lib/net/ssh/authentication/methods/keyboard_interactive.rb +13 -13
  35. data/lib/net/ssh/authentication/methods/none.rb +16 -19
  36. data/lib/net/ssh/authentication/methods/password.rb +27 -17
  37. data/lib/net/ssh/authentication/methods/publickey.rb +96 -55
  38. data/lib/net/ssh/authentication/pageant.rb +471 -367
  39. data/lib/net/ssh/authentication/pub_key_fingerprint.rb +43 -0
  40. data/lib/net/ssh/authentication/session.rb +131 -121
  41. data/lib/net/ssh/buffer.rb +399 -300
  42. data/lib/net/ssh/buffered_io.rb +154 -150
  43. data/lib/net/ssh/config.rb +308 -185
  44. data/lib/net/ssh/connection/channel.rb +635 -613
  45. data/lib/net/ssh/connection/constants.rb +29 -29
  46. data/lib/net/ssh/connection/event_loop.rb +123 -0
  47. data/lib/net/ssh/connection/keepalive.rb +55 -51
  48. data/lib/net/ssh/connection/session.rb +620 -551
  49. data/lib/net/ssh/connection/term.rb +125 -123
  50. data/lib/net/ssh/errors.rb +101 -99
  51. data/lib/net/ssh/key_factory.rb +197 -105
  52. data/lib/net/ssh/known_hosts.rb +214 -127
  53. data/lib/net/ssh/loggable.rb +50 -49
  54. data/lib/net/ssh/packet.rb +83 -79
  55. data/lib/net/ssh/prompt.rb +50 -81
  56. data/lib/net/ssh/proxy/command.rb +105 -90
  57. data/lib/net/ssh/proxy/errors.rb +12 -10
  58. data/lib/net/ssh/proxy/http.rb +82 -79
  59. data/lib/net/ssh/proxy/https.rb +50 -0
  60. data/lib/net/ssh/proxy/jump.rb +54 -0
  61. data/lib/net/ssh/proxy/socks4.rb +2 -6
  62. data/lib/net/ssh/proxy/socks5.rb +14 -17
  63. data/lib/net/ssh/service/forward.rb +370 -317
  64. data/lib/net/ssh/test/channel.rb +145 -136
  65. data/lib/net/ssh/test/extensions.rb +131 -110
  66. data/lib/net/ssh/test/kex.rb +34 -32
  67. data/lib/net/ssh/test/local_packet.rb +46 -44
  68. data/lib/net/ssh/test/packet.rb +89 -70
  69. data/lib/net/ssh/test/remote_packet.rb +32 -30
  70. data/lib/net/ssh/test/script.rb +156 -142
  71. data/lib/net/ssh/test/socket.rb +49 -48
  72. data/lib/net/ssh/test.rb +82 -77
  73. data/lib/net/ssh/transport/algorithms.rb +462 -359
  74. data/lib/net/ssh/transport/chacha20_poly1305_cipher.rb +117 -0
  75. data/lib/net/ssh/transport/chacha20_poly1305_cipher_loader.rb +17 -0
  76. data/lib/net/ssh/transport/cipher_factory.rb +122 -99
  77. data/lib/net/ssh/transport/constants.rb +32 -24
  78. data/lib/net/ssh/transport/ctr.rb +42 -22
  79. data/lib/net/ssh/transport/hmac/abstract.rb +81 -63
  80. data/lib/net/ssh/transport/hmac/md5.rb +0 -2
  81. data/lib/net/ssh/transport/hmac/md5_96.rb +0 -2
  82. data/lib/net/ssh/transport/hmac/none.rb +0 -2
  83. data/lib/net/ssh/transport/hmac/ripemd160.rb +0 -2
  84. data/lib/net/ssh/transport/hmac/sha1.rb +0 -2
  85. data/lib/net/ssh/transport/hmac/sha1_96.rb +0 -2
  86. data/lib/net/ssh/transport/hmac/sha2_256.rb +7 -11
  87. data/lib/net/ssh/transport/hmac/sha2_256_96.rb +4 -8
  88. data/lib/net/ssh/transport/hmac/sha2_256_etm.rb +12 -0
  89. data/lib/net/ssh/transport/hmac/sha2_512.rb +6 -9
  90. data/lib/net/ssh/transport/hmac/sha2_512_96.rb +4 -8
  91. data/lib/net/ssh/transport/hmac/sha2_512_etm.rb +12 -0
  92. data/lib/net/ssh/transport/hmac.rb +14 -12
  93. data/lib/net/ssh/transport/identity_cipher.rb +54 -44
  94. data/lib/net/ssh/transport/kex/abstract.rb +130 -0
  95. data/lib/net/ssh/transport/kex/abstract5656.rb +72 -0
  96. data/lib/net/ssh/transport/kex/curve25519_sha256.rb +39 -0
  97. data/lib/net/ssh/transport/kex/curve25519_sha256_loader.rb +30 -0
  98. data/lib/net/ssh/transport/kex/diffie_hellman_group14_sha1.rb +33 -40
  99. data/lib/net/ssh/transport/kex/diffie_hellman_group14_sha256.rb +11 -0
  100. data/lib/net/ssh/transport/kex/diffie_hellman_group1_sha1.rb +119 -213
  101. data/lib/net/ssh/transport/kex/diffie_hellman_group_exchange_sha1.rb +53 -61
  102. data/lib/net/ssh/transport/kex/diffie_hellman_group_exchange_sha256.rb +5 -9
  103. data/lib/net/ssh/transport/kex/ecdh_sha2_nistp256.rb +36 -90
  104. data/lib/net/ssh/transport/kex/ecdh_sha2_nistp384.rb +18 -10
  105. data/lib/net/ssh/transport/kex/ecdh_sha2_nistp521.rb +18 -10
  106. data/lib/net/ssh/transport/kex.rb +15 -12
  107. data/lib/net/ssh/transport/key_expander.rb +24 -20
  108. data/lib/net/ssh/transport/openssl.rb +161 -124
  109. data/lib/net/ssh/transport/openssl_cipher_extensions.rb +8 -0
  110. data/lib/net/ssh/transport/packet_stream.rb +246 -185
  111. data/lib/net/ssh/transport/server_version.rb +55 -56
  112. data/lib/net/ssh/transport/session.rb +306 -255
  113. data/lib/net/ssh/transport/state.rb +178 -176
  114. data/lib/net/ssh/verifiers/accept_new.rb +33 -0
  115. data/lib/net/ssh/verifiers/accept_new_or_local_tunnel.rb +33 -0
  116. data/lib/net/ssh/verifiers/always.rb +58 -0
  117. data/lib/net/ssh/verifiers/never.rb +19 -0
  118. data/lib/net/ssh/version.rb +55 -53
  119. data/lib/net/ssh.rb +111 -47
  120. data/net-ssh-public_cert.pem +18 -18
  121. data/net-ssh.gemspec +38 -205
  122. data/support/ssh_tunnel_bug.rb +5 -5
  123. data.tar.gz.sig +0 -0
  124. metadata +173 -118
  125. metadata.gz.sig +0 -0
  126. data/.travis.yml +0 -18
  127. data/README.rdoc +0 -182
  128. data/lib/net/ssh/authentication/agent/java_pageant.rb +0 -85
  129. data/lib/net/ssh/authentication/agent/socket.rb +0 -178
  130. data/lib/net/ssh/ruby_compat.rb +0 -46
  131. data/lib/net/ssh/verifiers/lenient.rb +0 -30
  132. data/lib/net/ssh/verifiers/null.rb +0 -12
  133. data/lib/net/ssh/verifiers/secure.rb +0 -52
  134. data/lib/net/ssh/verifiers/strict.rb +0 -24
  135. data/setup.rb +0 -1585
  136. data/support/arcfour_check.rb +0 -20
  137. data/test/README.txt +0 -18
  138. data/test/authentication/methods/common.rb +0 -28
  139. data/test/authentication/methods/test_abstract.rb +0 -51
  140. data/test/authentication/methods/test_hostbased.rb +0 -114
  141. data/test/authentication/methods/test_keyboard_interactive.rb +0 -121
  142. data/test/authentication/methods/test_none.rb +0 -41
  143. data/test/authentication/methods/test_password.rb +0 -95
  144. data/test/authentication/methods/test_publickey.rb +0 -148
  145. data/test/authentication/test_agent.rb +0 -232
  146. data/test/authentication/test_key_manager.rb +0 -240
  147. data/test/authentication/test_session.rb +0 -107
  148. data/test/common.rb +0 -125
  149. data/test/configs/auth_off +0 -5
  150. data/test/configs/auth_on +0 -4
  151. data/test/configs/empty +0 -0
  152. data/test/configs/eqsign +0 -3
  153. data/test/configs/exact_match +0 -8
  154. data/test/configs/host_plus +0 -10
  155. data/test/configs/multihost +0 -4
  156. data/test/configs/negative_match +0 -6
  157. data/test/configs/nohost +0 -19
  158. data/test/configs/numeric_host +0 -4
  159. data/test/configs/proxy_remote_user +0 -2
  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 -487
  164. data/test/connection/test_session.rb +0 -564
  165. data/test/integration/README.txt +0 -17
  166. data/test/integration/Vagrantfile +0 -12
  167. data/test/integration/common.rb +0 -63
  168. data/test/integration/playbook.yml +0 -56
  169. data/test/integration/test_forward.rb +0 -637
  170. data/test/integration/test_id_rsa_keys.rb +0 -96
  171. data/test/integration/test_proxy.rb +0 -93
  172. data/test/known_hosts/github +0 -1
  173. data/test/known_hosts/github_hash +0 -1
  174. data/test/manual/test_pageant.rb +0 -37
  175. data/test/start/test_connection.rb +0 -53
  176. data/test/start/test_options.rb +0 -57
  177. data/test/start/test_transport.rb +0 -28
  178. data/test/start/test_user_nil.rb +0 -27
  179. data/test/test_all.rb +0 -12
  180. data/test/test_buffer.rb +0 -433
  181. data/test/test_buffered_io.rb +0 -63
  182. data/test/test_config.rb +0 -268
  183. data/test/test_key_factory.rb +0 -191
  184. data/test/test_known_hosts.rb +0 -66
  185. data/test/transport/hmac/test_md5.rb +0 -41
  186. data/test/transport/hmac/test_md5_96.rb +0 -27
  187. data/test/transport/hmac/test_none.rb +0 -34
  188. data/test/transport/hmac/test_ripemd160.rb +0 -36
  189. data/test/transport/hmac/test_sha1.rb +0 -36
  190. data/test/transport/hmac/test_sha1_96.rb +0 -27
  191. data/test/transport/hmac/test_sha2_256.rb +0 -37
  192. data/test/transport/hmac/test_sha2_256_96.rb +0 -27
  193. data/test/transport/hmac/test_sha2_512.rb +0 -37
  194. data/test/transport/hmac/test_sha2_512_96.rb +0 -27
  195. data/test/transport/kex/test_diffie_hellman_group14_sha1.rb +0 -13
  196. data/test/transport/kex/test_diffie_hellman_group1_sha1.rb +0 -150
  197. data/test/transport/kex/test_diffie_hellman_group_exchange_sha1.rb +0 -96
  198. data/test/transport/kex/test_diffie_hellman_group_exchange_sha256.rb +0 -19
  199. data/test/transport/kex/test_ecdh_sha2_nistp256.rb +0 -161
  200. data/test/transport/kex/test_ecdh_sha2_nistp384.rb +0 -38
  201. data/test/transport/kex/test_ecdh_sha2_nistp521.rb +0 -38
  202. data/test/transport/test_algorithms.rb +0 -328
  203. data/test/transport/test_cipher_factory.rb +0 -443
  204. data/test/transport/test_hmac.rb +0 -34
  205. data/test/transport/test_identity_cipher.rb +0 -40
  206. data/test/transport/test_packet_stream.rb +0 -1762
  207. data/test/transport/test_server_version.rb +0 -74
  208. data/test/transport/test_session.rb +0 -331
  209. data/test/transport/test_state.rb +0 -181
  210. data/test/verifiers/test_secure.rb +0 -40
data/test/test_config.rb DELETED
@@ -1,268 +0,0 @@
1
- require 'common'
2
- require 'net/ssh/config'
3
- require 'pathname'
4
- require 'tempfile'
5
-
6
- class TestConfig < Test::Unit::TestCase
7
- def test_home_should_be_absolute_path
8
- assert Pathname.new(ENV['HOME']).absolute?
9
- end
10
-
11
- def test_load_for_non_existant_file_should_return_empty_hash
12
- bogus_file = File.expand_path("/bogus/file")
13
- File.expects(:readable?).with(bogus_file).returns(false)
14
- assert_equal({}, Net::SSH::Config.load(bogus_file, "host.name"))
15
- end
16
-
17
- def test_load_should_expand_path
18
- expected = File.expand_path("~/.ssh/config")
19
- File.expects(:readable?).with(expected).returns(false)
20
- Net::SSH::Config.load("~/.ssh/config", "host.name")
21
- end
22
-
23
- def test_load_with_exact_host_match_should_load_that_section
24
- config = Net::SSH::Config.load(config(:exact_match), "test.host")
25
- assert config['compression']
26
- assert config['forwardagent']
27
- assert_equal 1234, config['port']
28
- end
29
-
30
- def test_load_with_wild_card_matches_should_load_all_matches_with_first_match_taking_precedence
31
- config = Net::SSH::Config.load(config(:wild_cards), "test.host")
32
- assert_equal 1234, config['port']
33
- assert !config['compression']
34
- assert config['forwardagent']
35
- assert_equal %w(~/.ssh/id_dsa), config['identityfile']
36
- assert !config.key?('rekeylimit')
37
- end
38
-
39
- def test_load_with_wild_card_and_negative_pattern_does_not_match
40
- config = Net::SSH::Config.load(config(:negative_match), "test.host")
41
- assert_equal 9876, config['port']
42
- assert !config.key?('compression')
43
- end
44
-
45
- def test_load_with_pattern_does_match
46
- data = %q{
47
- Host test.*
48
- Port 1234
49
- Compression no
50
- }
51
- with_config_from_data data do |f|
52
- config = Net::SSH::Config.load(f, "test.host")
53
- assert_equal 1234, config['port']
54
- end
55
- end
56
-
57
- def test_load_with_regex_chars
58
- data = %q{
59
- Host |
60
- Port 1234
61
- Compression no
62
- }
63
- with_config_from_data data do |f|
64
- config = Net::SSH::Config.load(f, "test.host")
65
- assert_equal nil, config['port']
66
- config = Net::SSH::Config.load(f, "|")
67
- assert_equal 1234, config['port']
68
- end
69
- end
70
-
71
-
72
- def test_for_should_load_all_files_and_translate_to_net_ssh_options
73
- config = Net::SSH::Config.for("test.host", [config(:exact_match), config(:wild_cards)])
74
- assert_equal 1234, config[:port]
75
- assert config[:compression]
76
- assert config[:forward_agent]
77
- assert_equal %w(~/.ssh/id_dsa), config[:keys]
78
- assert !config.key?(:rekey_limit)
79
- end
80
-
81
- def test_load_with_no_host
82
- config = Net::SSH::Config.load(config(:nohost), "test.host")
83
- assert_equal %w(~/.ssh/id_dsa ~/.ssh/id_rsa), config['identityfile']
84
- assert_equal 1985, config['port']
85
- end
86
-
87
- def test_load_with_multiple_hosts
88
- config = Net::SSH::Config.load(config(:multihost), "test.host")
89
- assert config['compression']
90
- assert_equal '2G', config['rekeylimit']
91
- assert_equal 1980, config['port']
92
- end
93
-
94
- def test_load_with_multiple_hosts_and_config_should_match_for_both
95
- aconfig = Net::SSH::Config.load(config(:multihost), "test.host")
96
- bconfig = Net::SSH::Config.load(config(:multihost), "other.host")
97
- assert_equal aconfig['port'], bconfig['port']
98
- assert_equal aconfig['compression'], bconfig['compression']
99
- assert_equal aconfig['rekeylimit'], bconfig['rekeylimit']
100
- end
101
-
102
- def test_load_should_parse_equal_sign_delimiters
103
- config = Net::SSH::Config.load(config(:eqsign), "test.test")
104
- assert config['compression']
105
- assert_equal 1234, config['port']
106
- end
107
-
108
- def test_translate_should_correctly_translate_from_openssh_to_net_ssh_names
109
- open_ssh = {
110
- 'bindaddress' => "127.0.0.1",
111
- 'ciphers' => "a,b,c",
112
- 'compression' => true,
113
- 'compressionlevel' => 6,
114
- 'connecttimeout' => 100,
115
- 'forwardagent' => true,
116
- 'hostbasedauthentication' => true,
117
- 'hostkeyalgorithms' => "d,e,f",
118
- 'identityfile' => %w(g h i),
119
- 'macs' => "j,k,l",
120
- 'passwordauthentication' => true,
121
- 'port' => 1234,
122
- 'pubkeyauthentication' => true,
123
- 'rekeylimit' => 1024,
124
- 'sendenv' => "LC_*",
125
- 'numberofpasswordprompts' => '123',
126
- 'serveraliveinterval' => '2',
127
- 'serveralivecountmax' => '4'
128
- }
129
-
130
- net_ssh = Net::SSH::Config.translate(open_ssh)
131
-
132
- assert_equal %w(a b c), net_ssh[:encryption]
133
- assert_equal true, net_ssh[:compression]
134
- assert_equal 6, net_ssh[:compression_level]
135
- assert_equal 100, net_ssh[:timeout]
136
- assert_equal true, net_ssh[:forward_agent]
137
- assert_equal %w(hostbased keyboard-interactive none password publickey), net_ssh[:auth_methods].sort
138
- assert_equal %w(d e f), net_ssh[:host_key]
139
- assert_equal %w(g h i), net_ssh[:keys]
140
- assert_equal %w(j k l), net_ssh[:hmac]
141
- assert_equal 1234, net_ssh[:port]
142
- assert_equal 1024, net_ssh[:rekey_limit]
143
- assert_equal "127.0.0.1", net_ssh[:bind_address]
144
- assert_equal [/^LC_.*$/], net_ssh[:send_env]
145
- assert_equal 123, net_ssh[:number_of_password_prompts]
146
- assert_equal 4, net_ssh[:keepalive_maxcount]
147
- assert_equal 2, net_ssh[:keepalive_interval]
148
- assert_equal true, net_ssh[:keepalive]
149
- end
150
-
151
- def test_translate_should_turn_off_authentication_methods
152
- open_ssh = {
153
- 'hostbasedauthentication' => false,
154
- 'passwordauthentication' => false,
155
- 'pubkeyauthentication' => false,
156
- 'challengeresponseauthentication' => false,
157
- 'kbdinteractiveauthentication' => false
158
- }
159
-
160
- net_ssh = Net::SSH::Config.translate(open_ssh)
161
-
162
- assert_equal %w(none), net_ssh[:auth_methods].sort
163
- end
164
-
165
- def test_translate_should_turn_on_authentication_methods
166
- open_ssh = {
167
- 'hostbasedauthentication' => true,
168
- 'passwordauthentication' => true,
169
- 'pubkeyauthentication' => true,
170
- 'challengeresponseauthentication' => true,
171
- 'kbdinteractiveauthentication' => true
172
- }
173
-
174
- net_ssh = Net::SSH::Config.translate(open_ssh)
175
-
176
- assert_equal %w(hostbased keyboard-interactive none password publickey), net_ssh[:auth_methods].sort
177
- end
178
-
179
- def test_translate_should_not_disable_keyboard_interactive_when_challange_or_keyboardinterective_is_on
180
- open_ssh = {
181
- 'kbdinteractiveauthentication' => false
182
- }
183
- net_ssh = Net::SSH::Config.translate(open_ssh)
184
- assert_equal %w(keyboard-interactive none password publickey), net_ssh[:auth_methods].sort
185
-
186
- open_ssh = {
187
- 'challengeresponseauthentication' => false
188
- }
189
- net_ssh = Net::SSH::Config.translate(open_ssh)
190
- assert_equal %w(keyboard-interactive none password publickey), net_ssh[:auth_methods].sort
191
- end
192
-
193
- def test_should_ddisable_keyboard_interactive_when_challeng_and_keyboardinteractive_is_off
194
- open_ssh = {
195
- 'challengeresponseauthentication' => false,
196
- 'kbdinteractiveauthentication' => false
197
- }
198
-
199
- net_ssh = Net::SSH::Config.translate(open_ssh)
200
- assert_equal %w(none password publickey), net_ssh[:auth_methods].sort
201
- end
202
-
203
- def test_for_should_turn_off_authentication_methods
204
- config = Net::SSH::Config.for("test.host", [config(:empty), config(:auth_off), config(:auth_on)])
205
- assert_equal %w(none), config[:auth_methods].sort
206
- end
207
-
208
- def test_for_should_turn_on_authentication_methods
209
- config = Net::SSH::Config.for("test.host", [config(:empty), config(:auth_on), config(:auth_off)])
210
- assert_equal %w(hostbased keyboard-interactive none password publickey), config[:auth_methods].sort
211
- end
212
-
213
- def test_load_with_plus_sign_hosts
214
- config = Net::SSH::Config.load(config(:host_plus), "test.host")
215
- assert config['compression']
216
- end
217
-
218
- def test_load_with_numeric_host
219
- config = Net::SSH::Config.load(config(:numeric_host), "1234")
220
- assert config['compression']
221
- assert_equal '2G', config['rekeylimit']
222
- assert_equal 1980, config['port']
223
- end
224
-
225
- def test_load_wildcar_with_substitutes
226
- config = Net::SSH::Config.load(config(:substitutes), "toto")
227
- net_ssh = Net::SSH::Config.translate(config)
228
- assert_equal 'toto', net_ssh[:host_name]
229
- end
230
-
231
- def test_load_sufix_with_substitutes
232
- config = Net::SSH::Config.load(config(:substitutes), "test")
233
- net_ssh = Net::SSH::Config.translate(config)
234
- assert_equal 'test.sufix', net_ssh[:host_name]
235
- end
236
-
237
- def test_load_prefix_and_sufix_with_substitutes
238
- config = Net::SSH::Config.load(config(:substitutes), "1234")
239
- net_ssh = Net::SSH::Config.translate(config)
240
- assert_equal 'prefix.1234.sufix', net_ssh[:host_name]
241
- end
242
-
243
- def test_load_with_send_env
244
- config = Net::SSH::Config.load(config(:send_env), "1234")
245
- net_ssh = Net::SSH::Config.translate(config)
246
- assert_equal [/^GIT_.*$/, /^LANG$/, /^LC_.*$/], net_ssh[:send_env]
247
- end
248
-
249
- def test_load_with_remote_user
250
- config = Net::SSH::Config.load(config(:proxy_remote_user), "behind-proxy")
251
- net_ssh = Net::SSH::Config.translate(config)
252
- assert net_ssh[:proxy]
253
- end
254
-
255
- private
256
-
257
- def config(name)
258
- "test/configs/#{name}"
259
- end
260
-
261
- def with_config_from_data(data, &block)
262
- Tempfile.open('config') do |f|
263
- f.write(data)
264
- f.close
265
- yield(f.path)
266
- end
267
- end
268
- end
@@ -1,191 +0,0 @@
1
- require 'common'
2
- require 'net/ssh/key_factory'
3
-
4
- class TestKeyFactory < Test::Unit::TestCase
5
- def setup
6
- @key_file = File.expand_path("/key-file")
7
- end
8
-
9
- def test_load_unencrypted_private_RSA_key_should_return_key
10
- File.expects(:read).with(@key_file).returns(rsa_key.export)
11
- assert_equal rsa_key.to_der, Net::SSH::KeyFactory.load_private_key(@key_file).to_der
12
- end
13
-
14
- def test_load_unencrypted_private_DSA_key_should_return_key
15
- File.expects(:read).with(@key_file).returns(dsa_key.export)
16
- assert_equal dsa_key.to_der, Net::SSH::KeyFactory.load_private_key(@key_file).to_der
17
- end
18
-
19
- def test_load_encrypted_private_RSA_key_should_prompt_for_password_and_return_key
20
- File.expects(:read).with(@key_file).returns(encrypted(rsa_key, "password"))
21
- Net::SSH::KeyFactory.expects(:prompt).with("Enter passphrase for #{@key_file}:", false).returns("password")
22
- assert_equal rsa_key.to_der, Net::SSH::KeyFactory.load_private_key(@key_file).to_der
23
- end
24
-
25
- def test_load_encrypted_private_RSA_key_with_password_should_not_prompt_and_return_key
26
- File.expects(:read).with(@key_file).returns(encrypted(rsa_key, "password"))
27
- assert_equal rsa_key.to_der, Net::SSH::KeyFactory.load_private_key(@key_file, "password").to_der
28
- end
29
-
30
- def test_load_encrypted_private_DSA_key_should_prompt_for_password_and_return_key
31
- File.expects(:read).with(@key_file).returns(encrypted(dsa_key, "password"))
32
- Net::SSH::KeyFactory.expects(:prompt).with("Enter passphrase for #{@key_file}:", false).returns("password")
33
- assert_equal dsa_key.to_der, Net::SSH::KeyFactory.load_private_key(@key_file).to_der
34
- end
35
-
36
- def test_load_encrypted_private_DSA_key_with_password_should_not_prompt_and_return_key
37
- File.expects(:read).with(@key_file).returns(encrypted(dsa_key, "password"))
38
- assert_equal dsa_key.to_der, Net::SSH::KeyFactory.load_private_key(@key_file, "password").to_der
39
- end
40
-
41
- def test_load_encrypted_private_key_should_give_three_tries_for_the_password_and_then_raise_exception
42
- File.expects(:read).with(@key_file).returns(encrypted(rsa_key, "password"))
43
- Net::SSH::KeyFactory.expects(:prompt).times(3).with("Enter passphrase for #{@key_file}:", false).returns("passwod","passphrase","passwd")
44
- if OpenSSL::PKey.respond_to?(:read)
45
- error_class = ArgumentError
46
- else
47
- error_class = OpenSSL::PKey::RSAError
48
- end
49
- assert_raises(error_class) { Net::SSH::KeyFactory.load_private_key(@key_file) }
50
- end
51
-
52
- def test_load_encrypted_private_key_should_raise_exception_without_asking_passphrase
53
- File.expects(:read).with(@key_file).returns(encrypted(rsa_key, "password"))
54
- Net::SSH::KeyFactory.expects(:prompt).never
55
- if OpenSSL::PKey.respond_to?(:read)
56
- error_class = ArgumentError
57
- else
58
- error_class = OpenSSL::PKey::RSAError
59
- end
60
- assert_raises(error_class) { Net::SSH::KeyFactory.load_private_key(@key_file, nil, false) }
61
- end
62
-
63
- def test_load_public_rsa_key_should_return_key
64
- File.expects(:read).with(@key_file).returns(public(rsa_key))
65
- assert_equal rsa_key.to_blob, Net::SSH::KeyFactory.load_public_key(@key_file).to_blob
66
- end
67
-
68
- def test_load_public_rsa_key_with_comment_should_return_key
69
- File.expects(:read).with(@key_file).returns(public(rsa_key) + " key_comment")
70
- assert_equal rsa_key.to_blob, Net::SSH::KeyFactory.load_public_key(@key_file).to_blob
71
- end
72
-
73
- def test_load_public_rsa_key_with_options_should_return_key
74
- File.expects(:read).with(@key_file).returns(public(rsa_key, 'environment="FOO=bar"'))
75
- assert_equal rsa_key.to_blob, Net::SSH::KeyFactory.load_public_key(@key_file).to_blob
76
- end
77
-
78
- def test_load_public_rsa_key_with_options_and_comment_should_return_key
79
- File.expects(:read).with(@key_file).returns(public(rsa_key, 'environment="FOO=bar"') + " key_comment")
80
- assert_equal rsa_key.to_blob, Net::SSH::KeyFactory.load_public_key(@key_file).to_blob
81
- end
82
- if defined?(OpenSSL::PKey::EC)
83
- def test_load_unencrypted_private_ecdsa_sha2_nistp256_key_should_return_key
84
- File.expects(:read).with("/key-file").returns(ecdsa_sha2_nistp256_key.to_pem)
85
- assert_equal ecdsa_sha2_nistp256_key.to_der, Net::SSH::KeyFactory.load_private_key("/key-file").to_der
86
- end
87
- def test_load_unencrypted_private_ecdsa_sha2_nistp384_key_should_return_key
88
- File.expects(:read).with("/key-file").returns(ecdsa_sha2_nistp384_key.to_pem)
89
- assert_equal ecdsa_sha2_nistp384_key.to_der, Net::SSH::KeyFactory.load_private_key("/key-file").to_der
90
- end
91
- def test_load_unencrypted_private_ecdsa_sha2_nistp521_key_should_return_key
92
- File.expects(:read).with("/key-file").returns(ecdsa_sha2_nistp521_key.to_pem)
93
- assert_equal ecdsa_sha2_nistp521_key.to_der, Net::SSH::KeyFactory.load_private_key("/key-file").to_der
94
- end
95
-
96
- def test_load_public_ecdsa_sha2_nistp256_key_should_return_key
97
- File.expects(:read).with("/key-file").returns(public(ecdsa_sha2_nistp256_key))
98
- assert_equal ecdsa_sha2_nistp256_key.to_blob, Net::SSH::KeyFactory.load_public_key("/key-file").to_blob
99
- end
100
- def test_load_public_ecdsa_sha2_nistp384_key_should_return_key
101
- File.expects(:read).with("/key-file").returns(public(ecdsa_sha2_nistp384_key))
102
- assert_equal ecdsa_sha2_nistp384_key.to_blob, Net::SSH::KeyFactory.load_public_key("/key-file").to_blob
103
- end
104
- def test_load_public_ecdsa_sha2_nistp521_key_should_return_key
105
- File.expects(:read).with("/key-file").returns(public(ecdsa_sha2_nistp521_key))
106
- assert_equal ecdsa_sha2_nistp521_key.to_blob, Net::SSH::KeyFactory.load_public_key("/key-file").to_blob
107
- end
108
- end
109
-
110
- def test_load_anonymous_private_key_should_return_key_or_raise_exception
111
- File.expects(:read).with(@key_file).returns(anonymous_private_key)
112
- if OpenSSL::PKey.respond_to?(:read)
113
- assert_equal OpenSSL::PKey::RSA.new(anonymous_private_key).to_der, Net::SSH::KeyFactory.load_private_key(@key_file).to_der
114
- else
115
- assert_raises(OpenSSL::PKey::PKeyError) { Net::SSH::KeyFactory.load_private_key(@key_file) }
116
- end
117
- end
118
-
119
- private
120
-
121
- def rsa_key
122
- # 512 bits
123
- @rsa_key ||= OpenSSL::PKey::RSA.new("0\202\001;\002\001\000\002A\000\235\236\374N\e@2E\321\3757\003\354c\276N\f\003\3479Ko\005\317\0027\a\255=\345!\306\220\340\211;\027u\331\260\362\2063x\332\301y4\353\v%\032\214v\312\304\212\271GJ\353\2701\031\002\003\001\000\001\002@\022Y\306*\031\306\031\224Cde\231QV3{\306\256U\2477\377\017\000\020\323\363R\332\027\351\034\224OU\020\227H|pUS\n\263+%\304\341\321\273/\271\e\004L\250\273\020&,\t\304By\002!\000\311c\246%a\002\305\277\262R\266\244\250\025V_\351]\264\016\265\341\355\305\223\347Z$8\205#\023\002!\000\310\\\367|\243I\363\350\020\307\246\302\365\ed\212L\273\2158M\223w\a\367 C\t\224A4\243\002!\000\262]+}\327\231\331\002\2331^\312\036\204'g\363\f&\271\020\245\365-\024}\306\374e\202\2459\002 }\231\341\276\3551\277\307{5\\\361\233\353G\024wS\237\fk}\004\302&\205\277\340rb\211\327\002!\000\223\307\025I:\215_\260\370\252\3757\256Y&X\364\354\342\215\350\203E8\227|\f\237M\375D|")
124
- end
125
-
126
- def dsa_key
127
- # 512 bits
128
- @dsa_key ||= OpenSSL::PKey::DSA.new("0\201\367\002\001\000\002A\000\203\316/\037u\272&J\265\003l3\315d\324h\372{\t8\252#\331_\026\006\035\270\266\255\343\353Z\302\276\335\336\306\220\375\202L\244\244J\206>\346\b\315\211\302L\246x\247u\a\376\366\345\302\016#\002\025\000\244\274\302\221Og\275/\302+\356\346\360\024\373wI\2573\361\002@\027\215\270r*\f\213\350C\245\021:\350 \006\\\376\345\022`\210b\262\3643\023XLKS\320\370\002\276\347A\nU\204\276\324\256`=\026\240\330\306J\316V\213\024\e\030\215\355\006\037q\337\356ln\002@\017\257\034\f\260\333'S\271#\237\230E\321\312\027\021\226\331\251Vj\220\305\316\036\v\266+\000\230\270\177B\003?t\a\305]e\344\261\334\023\253\323\251\223M\2175)a(\004\"lI8\312\303\307\a\002\024_\aznW\345\343\203V\326\246ua\203\376\201o\350\302\002")
129
- end
130
-
131
- if defined?(OpenSSL::PKey::EC)
132
- def ecdsa_sha2_nistp256_key
133
- @ecdsa_sha2_nistp256_key ||= OpenSSL::PKey::EC.new("-----BEGIN EC PRIVATE KEY-----\nMHcCAQEEINv6pPVLlkqvT1v5MJlWgaSWGwqupISG4U79bUXQDNCaoAoGCCqGSM49\nAwEHoUQDQgAElqubvi/GkSme+bwtncU1NiE0dWQ0EO07VufUQg8lUJ5+Fi6f96qa\n95T1zwOMQhY1h8PP9rQIZr4S48vN/ZnQLw==\n-----END EC PRIVATE KEY-----\n")
134
- end
135
-
136
- def ecdsa_sha2_nistp384_key
137
- @ecdsa_sha2_nistp384_key ||= OpenSSL::PKey::EC.new("-----BEGIN EC PRIVATE KEY-----\nMIGkAgEBBDBxwkmydCn4mP4KMhlMpeBvIroQolWKVNoRPXpG7brFgK+Yiikqw8wd\nIZW5OlL4y3mgBwYFK4EEACKhZANiAARkoIR1oABi+aQJbKcmvzeYSKURQOyXM0HU\nR4T68v4hd/lJE4fFQRczj3wAaECe9u3CWI/oDlow4Vr0vab82ZGjIoblxblKQWYl\nyzENgzl226waGg1bLBo8Auilyf1B5yI=\n-----END EC PRIVATE KEY-----\n")
138
- end
139
-
140
- def ecdsa_sha2_nistp521_key
141
- @ecdsa_sha2_nistp521_key ||= OpenSSL::PKey::EC.new("-----BEGIN EC PRIVATE KEY-----\nMIHbAgEBBEHQ2i7kjEGQHQB4pUQW9a2eCLWR2S5Go8U3CDyfbRCrYEp/pTSgI8uu\nMXyR3bf3SjqFQgZ6MZk5lkyrissJuwmvZKAHBgUrgQQAI6GBiQOBhgAEAN14FACK\nbs/KTqw4rxijeozGTVJTh1hNzBl2XaIhM4Fv8o3fE/pvogymyFu53GCng6gC4dmx\n/hycF41iIM29xVKPAeBnRNl6MdFBjuthOmE8eCRezgk1Bak8aBDUrzNT8OQssscw\npvQK4nc6ga/wTDaQGy5kV8tCOHNs2wKH+p2LpWTJ\n-----END EC PRIVATE KEY-----\n")
142
- end
143
- end
144
-
145
- def anonymous_private_key
146
- @anonymous_key = <<-EOF
147
- -----BEGIN PRIVATE KEY-----
148
- MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQC3id5gZ6bglJth
149
- yli8JNaRxhsqKwwPlReEI/mplzz5IP6gWQ92LogXbdBXtHf9ZpA53BeLmtcNBEY0
150
- Ygd7sPBhlHABS5D5///zltSSX2+L5GCEiC6dpfGsySjqymWF+SZ2PaqfZbkWLmCD
151
- 9u4ysueaHf7xbF6txGprNp69efttWxdy+vU5tno7HVxemMZQUalpShFrdAYKKXEo
152
- cV7MtbkQjzubS14gaWGpWCXIl9uNKQeHpLKtre1Qn5Ft/zVpCHmhLQcYDuB1LAj9
153
- 7eoev4rIiOE2sfdkvKDlmFxvzq3myYH4o27WwAg9OZ5SBusn2zesKkRCBBEZ55rl
154
- uVknOGHXAgMBAAECggEAZE0U2OxsNxkfXS6+lXswQ5PW7pF90towcsdSPgrniGIu
155
- pKRnHbfKKbuaewOl+zZcpTIRL/rbgUKPtzrHSiJlC36aQyrvvJ/ZWV5ZJvC+vd19
156
- nY/qob65NyrrkHwxRSjmiwGiR9/IaUXI+vUsMUqx5Ph1hawqhZ3sZlEAKR4LeDO8
157
- M+OguG77jLaqj5/SNfi+GwyUDe85de4VfEG4S9HrMQk2Cp66rx0BqDnCLacyFQaI
158
- R0VczMXTU52q0uETmgUr8G9A1SaRc5ZWKAfZwxJTvqdIImWC9E+CY7wm+mZD4FE6
159
- iVzVC0ngcdEd596kTDdU2BPVMluWzLkfqIrTt/5CeQKBgQDzgRzCPNxFtai6RAIi
160
- ekBSHqrDnrbeTaw32GVq5ACk1Zfk2I0svctz1iQ9qJ2SRINpygQhcyJKQ4r/LXi1
161
- 7Av9H/d6QV4T2AZzS4WcqBkxxRXFUfARtnKChzuCzNt9tNz4EZiv75RyQmztGZjV
162
- i94+ZvCyqup5be4Svf4MBxin9QKBgQDA9P4nHzFWZakTMei78LGb/4Auc+r0rZp7
163
- 8xg8Z92tvrDeJjMdesdhiFrPP1qiSYHnQ81MSWpn6BycBsHZqitejQmYnYput/s4
164
- qG+m7SrkN8WL6rijYsbB+U14VDjMlBlOgcEgjlSNU2oeS+68u+uVI/fgyXcXn4Jq
165
- 33TSWSgfGwKBgA2tRdE/G9wqfOShZ0FKfoxePpcoNfs8f5zPYbrkPYkEmjh3VU6b
166
- Bm9mKrjv3JHXmU3608qRLe7f5lG42xvUu0OnZP4P59nTe2FEb6fB5VBfUn63wHUu
167
- OzZLpDMPkJB59SNV0a6oFT1pr7aNhoEQDxaQL5rJcMwLOaEB3OAOEft1AoGASz7+
168
- 4Zi7b7rDPVYIMUpCqNfxT6wqovIUPWPmPqAuhXPIm0kAQ+2+VN2MtCc7m+/Ydawu
169
- IiK7GPweNAY6kDxZH00WweolstmSYVzl9Y2lXUwWgGKvUB/T7I7g1Bzb7YOPftsA
170
- ykZW2Kn/xwLLfdQ2oXleT82g4Jh2jmDHuMPF7qMCgYEA6QF45PvOgnrJessgmwO/
171
- dEmkLl07PQYJPGZLaZteuWrvfMrn+AiW5aAdHzhzNaOtNy5B3T7zGUHtgxXegqgd
172
- /QdCVCJgnZUO/zdAxkr22dDn+WEXkL4wgBVStQvvnQp9C2NJcoOExvex5PLzKWQg
173
- WEKt5v3QsUEgVrzkM4K9UbI=
174
- -----END PRIVATE KEY-----
175
- EOF
176
- end
177
-
178
- def encrypted(key, password)
179
- key.export(OpenSSL::Cipher::Cipher.new("des-ede3-cbc"), password)
180
- end
181
-
182
- def public(key, args = nil)
183
- result = ""
184
- if !args.nil?
185
- result << "#{args} "
186
- end
187
- result << "#{key.ssh_type} "
188
- result << [Net::SSH::Buffer.from(:key, key).to_s].pack("m*").strip.tr("\n\r\t ", "")
189
- result << " joe@host.test"
190
- end
191
- end
@@ -1,66 +0,0 @@
1
- require 'common'
2
-
3
- class TestKnownHosts < Test::Unit::TestCase
4
-
5
- def perform_test(source)
6
- kh = Net::SSH::KnownHosts.new(source)
7
- keys = kh.keys_for("github.com")
8
- assert_equal(1, keys.count)
9
- assert_equal("ssh-rsa", keys[0].ssh_type)
10
- end
11
-
12
- def test_key_for_when_all_hosts_are_recognized
13
- perform_test(path("known_hosts/github"))
14
- end
15
-
16
- def test_key_for_when_an_host_hash_is_recognized
17
- perform_test(path("known_hosts/github_hash"))
18
- end
19
-
20
- def test_missing_then_add
21
- Tempfile.open('github') do |f|
22
- f.write(File.read(path("known_hosts/github")))
23
- kh = Net::SSH::KnownHosts.new(f.path)
24
- keys = kh.keys_for("github2.com")
25
- assert_equal(0, keys.count)
26
- assert_equal([], keys.to_a)
27
-
28
- kh.add('github2.com',rsa_key)
29
- keys2 = kh.keys_for("github2.com")
30
- assert_equal([rsa_key.to_blob], keys2.to_a.map(&:to_blob))
31
- end
32
- end
33
-
34
- def test_search_for
35
- options = {user_known_hosts_file: path("known_hosts/github")}
36
- keys = Net::SSH::KnownHosts.search_for('github.com',options)
37
- assert_equal(["ssh-rsa"], keys.map(&:ssh_type))
38
- end
39
-
40
- def test_search_for_then_add
41
- Tempfile.open('github') do |f|
42
- f.write(File.read(path("known_hosts/github")))
43
- options = {user_known_hosts_file: f.path}
44
- keys = Net::SSH::KnownHosts.search_for('github2.com',options)
45
- assert_equal(0, keys.count)
46
-
47
- keys.add_host_key(rsa_key)
48
-
49
- assert_equal([rsa_key.to_blob], keys.map(&:to_blob))
50
- keys = Net::SSH::KnownHosts.search_for('github2.com',options)
51
- assert_equal([rsa_key.to_blob], keys.map(&:to_blob))
52
- end
53
- end
54
-
55
-
56
- def path(relative_path)
57
- File.join(File.dirname(__FILE__), "known_hosts/github")
58
- end
59
-
60
- def rsa_key
61
- key = OpenSSL::PKey::RSA.new
62
- key.e = 0xffeeddccbbaa9988
63
- key.n = 0x7766554433221100
64
- key
65
- end
66
- end
@@ -1,41 +0,0 @@
1
- # encoding: ASCII-8BIT
2
-
3
- require 'common'
4
- require 'net/ssh/transport/hmac/md5'
5
-
6
- module Transport; module HMAC
7
-
8
- class TestMD5 < Test::Unit::TestCase
9
- def test_expected_digest_class
10
- assert_equal OpenSSL::Digest::MD5, subject.digest_class
11
- assert_equal OpenSSL::Digest::MD5, subject.new.digest_class
12
- end
13
-
14
- def test_expected_key_length
15
- assert_equal 16, subject.key_length
16
- assert_equal 16, subject.new.key_length
17
- end
18
-
19
- def test_expected_mac_length
20
- assert_equal 16, subject.mac_length
21
- assert_equal 16, subject.new.mac_length
22
- end
23
-
24
- def test_expected_digest
25
- hmac = subject.new("1234567890123456")
26
- assert_equal "\275\345\006\307y~Oi\035<.\341\031\250<\257", hmac.digest("hello world")
27
- end
28
-
29
- def test_key_should_be_truncated_to_required_length
30
- hmac = subject.new("12345678901234567890")
31
- assert_equal "1234567890123456", hmac.key
32
- end
33
-
34
- private
35
-
36
- def subject
37
- Net::SSH::Transport::HMAC::MD5
38
- end
39
- end
40
-
41
- end; end
@@ -1,27 +0,0 @@
1
- # encoding: ASCII-8BIT
2
-
3
- require 'common'
4
- require 'transport/hmac/test_md5'
5
- require 'net/ssh/transport/hmac/md5_96'
6
-
7
- module Transport; module HMAC
8
-
9
- class TestMD5_96 < TestMD5
10
- def test_expected_mac_length
11
- assert_equal 12, subject.mac_length
12
- assert_equal 12, subject.new.mac_length
13
- end
14
-
15
- def test_expected_digest
16
- hmac = subject.new("1234567890123456")
17
- assert_equal "\275\345\006\307y~Oi\035<.\341", hmac.digest("hello world")
18
- end
19
-
20
- private
21
-
22
- def subject
23
- Net::SSH::Transport::HMAC::MD5_96
24
- end
25
- end
26
-
27
- end; end
@@ -1,34 +0,0 @@
1
- require 'common'
2
- require 'net/ssh/transport/hmac/none'
3
-
4
- module Transport; module HMAC
5
-
6
- class TestNone < Test::Unit::TestCase
7
- def test_expected_digest_class
8
- assert_equal nil, subject.digest_class
9
- assert_equal nil, subject.new.digest_class
10
- end
11
-
12
- def test_expected_key_length
13
- assert_equal 0, subject.key_length
14
- assert_equal 0, subject.new.key_length
15
- end
16
-
17
- def test_expected_mac_length
18
- assert_equal 0, subject.mac_length
19
- assert_equal 0, subject.new.mac_length
20
- end
21
-
22
- def test_expected_digest
23
- hmac = subject.new("1234567890123456")
24
- assert_equal "", hmac.digest("hello world")
25
- end
26
-
27
- private
28
-
29
- def subject
30
- Net::SSH::Transport::HMAC::None
31
- end
32
- end
33
-
34
- end; end
@@ -1,36 +0,0 @@
1
- # encoding: ASCII-8BIT
2
-
3
- require 'common'
4
- require 'net/ssh/transport/hmac/ripemd160'
5
-
6
- module Transport; module HMAC
7
-
8
- class TestRipemd160 < Test::Unit::TestCase
9
- def test_expected_digest_class
10
- assert_equal OpenSSL::Digest::RIPEMD160, subject.digest_class
11
- assert_equal OpenSSL::Digest::RIPEMD160, subject.new.digest_class
12
- end
13
-
14
- def test_expected_key_length
15
- assert_equal 20, subject.key_length
16
- assert_equal 20, subject.new.key_length
17
- end
18
-
19
- def test_expected_mac_length
20
- assert_equal 20, subject.mac_length
21
- assert_equal 20, subject.new.mac_length
22
- end
23
-
24
- def test_expected_digest
25
- hmac = subject.new("1234567890123456")
26
- assert_equal "\xE4\x10\t\xB3\xD8,\x14\xA0k\x10\xB5\x0F?\x0E\x96q\x02\x16;E", hmac.digest("hello world")
27
- end
28
-
29
- private
30
-
31
- def subject
32
- Net::SSH::Transport::HMAC::RIPEMD160
33
- end
34
- end
35
-
36
- end; end