net-ssh 2.9.2 → 4.0.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 (138) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/.gitignore +6 -0
  4. data/.rubocop.yml +5 -0
  5. data/.rubocop_todo.yml +1129 -0
  6. data/.travis.yml +41 -5
  7. data/CHANGES.txt +133 -1
  8. data/Gemfile +13 -0
  9. data/Gemfile.norbnacl +10 -0
  10. data/Gemfile.norbnacl.lock +41 -0
  11. data/ISSUE_TEMPLATE.md +30 -0
  12. data/README.rdoc +26 -81
  13. data/Rakefile +63 -45
  14. data/appveyor.yml +51 -0
  15. data/lib/net/ssh/authentication/agent.rb +174 -14
  16. data/lib/net/ssh/authentication/ed25519.rb +137 -0
  17. data/lib/net/ssh/authentication/ed25519_loader.rb +21 -0
  18. data/lib/net/ssh/authentication/key_manager.rb +36 -30
  19. data/lib/net/ssh/authentication/methods/abstract.rb +4 -0
  20. data/lib/net/ssh/authentication/methods/keyboard_interactive.rb +16 -9
  21. data/lib/net/ssh/authentication/methods/password.rb +17 -4
  22. data/lib/net/ssh/authentication/pageant.rb +166 -45
  23. data/lib/net/ssh/authentication/session.rb +3 -2
  24. data/lib/net/ssh/buffer.rb +49 -10
  25. data/lib/net/ssh/buffered_io.rb +17 -12
  26. data/lib/net/ssh/config.rb +39 -8
  27. data/lib/net/ssh/connection/channel.rb +42 -20
  28. data/lib/net/ssh/connection/event_loop.rb +114 -0
  29. data/lib/net/ssh/connection/keepalive.rb +2 -2
  30. data/lib/net/ssh/connection/session.rb +120 -34
  31. data/lib/net/ssh/errors.rb +6 -6
  32. data/lib/net/ssh/key_factory.rb +49 -43
  33. data/lib/net/ssh/known_hosts.rb +49 -3
  34. data/lib/net/ssh/prompt.rb +47 -78
  35. data/lib/net/ssh/proxy/command.rb +31 -5
  36. data/lib/net/ssh/proxy/http.rb +15 -11
  37. data/lib/net/ssh/proxy/https.rb +49 -0
  38. data/lib/net/ssh/proxy/socks4.rb +2 -1
  39. data/lib/net/ssh/proxy/socks5.rb +3 -2
  40. data/lib/net/ssh/ruby_compat.rb +2 -29
  41. data/lib/net/ssh/service/forward.rb +2 -2
  42. data/lib/net/ssh/test/channel.rb +7 -0
  43. data/lib/net/ssh/test/extensions.rb +17 -0
  44. data/lib/net/ssh/test/kex.rb +4 -4
  45. data/lib/net/ssh/test/packet.rb +18 -2
  46. data/lib/net/ssh/test/script.rb +16 -2
  47. data/lib/net/ssh/test/socket.rb +1 -1
  48. data/lib/net/ssh/test.rb +5 -5
  49. data/lib/net/ssh/transport/algorithms.rb +92 -75
  50. data/lib/net/ssh/transport/cipher_factory.rb +19 -26
  51. data/lib/net/ssh/transport/ctr.rb +7 -9
  52. data/lib/net/ssh/transport/kex/diffie_hellman_group1_sha1.rb +20 -9
  53. data/lib/net/ssh/transport/kex/diffie_hellman_group_exchange_sha1.rb +5 -3
  54. data/lib/net/ssh/transport/kex/ecdh_sha2_nistp256.rb +1 -1
  55. data/lib/net/ssh/transport/key_expander.rb +1 -0
  56. data/lib/net/ssh/transport/openssl.rb +1 -1
  57. data/lib/net/ssh/transport/packet_stream.rb +11 -3
  58. data/lib/net/ssh/transport/server_version.rb +13 -6
  59. data/lib/net/ssh/transport/session.rb +20 -10
  60. data/lib/net/ssh/transport/state.rb +1 -1
  61. data/lib/net/ssh/verifiers/secure.rb +8 -10
  62. data/lib/net/ssh/version.rb +4 -4
  63. data/lib/net/ssh.rb +62 -14
  64. data/net-ssh-public_cert.pem +19 -18
  65. data/net-ssh.gemspec +34 -194
  66. data/support/arcfour_check.rb +1 -1
  67. data/support/ssh_tunnel_bug.rb +1 -1
  68. data.tar.gz.sig +0 -0
  69. metadata +125 -109
  70. metadata.gz.sig +0 -0
  71. data/Rudyfile +0 -96
  72. data/lib/net/ssh/authentication/agent/java_pageant.rb +0 -85
  73. data/lib/net/ssh/authentication/agent/socket.rb +0 -178
  74. data/setup.rb +0 -1585
  75. data/test/README.txt +0 -47
  76. data/test/authentication/methods/common.rb +0 -28
  77. data/test/authentication/methods/test_abstract.rb +0 -51
  78. data/test/authentication/methods/test_hostbased.rb +0 -114
  79. data/test/authentication/methods/test_keyboard_interactive.rb +0 -100
  80. data/test/authentication/methods/test_none.rb +0 -41
  81. data/test/authentication/methods/test_password.rb +0 -95
  82. data/test/authentication/methods/test_publickey.rb +0 -148
  83. data/test/authentication/test_agent.rb +0 -224
  84. data/test/authentication/test_key_manager.rb +0 -227
  85. data/test/authentication/test_session.rb +0 -107
  86. data/test/common.rb +0 -108
  87. data/test/configs/auth_off +0 -5
  88. data/test/configs/auth_on +0 -4
  89. data/test/configs/empty +0 -0
  90. data/test/configs/eqsign +0 -3
  91. data/test/configs/exact_match +0 -8
  92. data/test/configs/host_plus +0 -10
  93. data/test/configs/multihost +0 -4
  94. data/test/configs/negative_match +0 -6
  95. data/test/configs/nohost +0 -19
  96. data/test/configs/numeric_host +0 -4
  97. data/test/configs/send_env +0 -2
  98. data/test/configs/substitutes +0 -8
  99. data/test/configs/wild_cards +0 -14
  100. data/test/connection/test_channel.rb +0 -467
  101. data/test/connection/test_session.rb +0 -543
  102. data/test/known_hosts/github +0 -1
  103. data/test/manual/test_forward.rb +0 -285
  104. data/test/manual/test_pageant.rb +0 -37
  105. data/test/start/test_connection.rb +0 -53
  106. data/test/start/test_options.rb +0 -43
  107. data/test/start/test_transport.rb +0 -28
  108. data/test/test_all.rb +0 -11
  109. data/test/test_buffer.rb +0 -433
  110. data/test/test_buffered_io.rb +0 -63
  111. data/test/test_config.rb +0 -221
  112. data/test/test_key_factory.rb +0 -191
  113. data/test/test_known_hosts.rb +0 -13
  114. data/test/transport/hmac/test_md5.rb +0 -41
  115. data/test/transport/hmac/test_md5_96.rb +0 -27
  116. data/test/transport/hmac/test_none.rb +0 -34
  117. data/test/transport/hmac/test_ripemd160.rb +0 -36
  118. data/test/transport/hmac/test_sha1.rb +0 -36
  119. data/test/transport/hmac/test_sha1_96.rb +0 -27
  120. data/test/transport/hmac/test_sha2_256.rb +0 -37
  121. data/test/transport/hmac/test_sha2_256_96.rb +0 -27
  122. data/test/transport/hmac/test_sha2_512.rb +0 -37
  123. data/test/transport/hmac/test_sha2_512_96.rb +0 -27
  124. data/test/transport/kex/test_diffie_hellman_group14_sha1.rb +0 -13
  125. data/test/transport/kex/test_diffie_hellman_group1_sha1.rb +0 -146
  126. data/test/transport/kex/test_diffie_hellman_group_exchange_sha1.rb +0 -92
  127. data/test/transport/kex/test_diffie_hellman_group_exchange_sha256.rb +0 -34
  128. data/test/transport/kex/test_ecdh_sha2_nistp256.rb +0 -161
  129. data/test/transport/kex/test_ecdh_sha2_nistp384.rb +0 -38
  130. data/test/transport/kex/test_ecdh_sha2_nistp521.rb +0 -38
  131. data/test/transport/test_algorithms.rb +0 -324
  132. data/test/transport/test_cipher_factory.rb +0 -443
  133. data/test/transport/test_hmac.rb +0 -34
  134. data/test/transport/test_identity_cipher.rb +0 -40
  135. data/test/transport/test_packet_stream.rb +0 -1761
  136. data/test/transport/test_server_version.rb +0 -78
  137. data/test/transport/test_session.rb +0 -331
  138. data/test/transport/test_state.rb +0 -181
data/test/test_config.rb DELETED
@@ -1,221 +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_load_with_wild_card_and_negative_pattern_does_not_match
39
- config = Net::SSH::Config.load(config(:negative_match), "test.host")
40
- assert_equal 9876, config['port']
41
- assert !config.key?('compression')
42
- end
43
-
44
- def test_for_should_load_all_files_and_translate_to_net_ssh_options
45
- config = Net::SSH::Config.for("test.host", [config(:exact_match), config(:wild_cards)])
46
- assert_equal 1234, config[:port]
47
- assert config[:compression]
48
- assert config[:forward_agent]
49
- assert_equal %w(~/.ssh/id_dsa), config[:keys]
50
- assert !config.key?(:rekey_limit)
51
- end
52
-
53
- def test_load_with_no_host
54
- config = Net::SSH::Config.load(config(:nohost), "test.host")
55
- assert_equal %w(~/.ssh/id_dsa ~/.ssh/id_rsa), config['identityfile']
56
- assert_equal 1985, config['port']
57
- end
58
-
59
- def test_load_with_multiple_hosts
60
- config = Net::SSH::Config.load(config(:multihost), "test.host")
61
- assert config['compression']
62
- assert_equal '2G', config['rekeylimit']
63
- assert_equal 1980, config['port']
64
- end
65
-
66
- def test_load_with_multiple_hosts_and_config_should_match_for_both
67
- aconfig = Net::SSH::Config.load(config(:multihost), "test.host")
68
- bconfig = Net::SSH::Config.load(config(:multihost), "other.host")
69
- assert_equal aconfig['port'], bconfig['port']
70
- assert_equal aconfig['compression'], bconfig['compression']
71
- assert_equal aconfig['rekeylimit'], bconfig['rekeylimit']
72
- end
73
-
74
- def test_load_should_parse_equal_sign_delimiters
75
- config = Net::SSH::Config.load(config(:eqsign), "test.test")
76
- assert config['compression']
77
- assert_equal 1234, config['port']
78
- end
79
-
80
- def test_translate_should_correctly_translate_from_openssh_to_net_ssh_names
81
- open_ssh = {
82
- 'bindaddress' => "127.0.0.1",
83
- 'ciphers' => "a,b,c",
84
- 'compression' => true,
85
- 'compressionlevel' => 6,
86
- 'connecttimeout' => 100,
87
- 'forwardagent' => true,
88
- 'hostbasedauthentication' => true,
89
- 'hostkeyalgorithms' => "d,e,f",
90
- 'identityfile' => %w(g h i),
91
- 'macs' => "j,k,l",
92
- 'passwordauthentication' => true,
93
- 'port' => 1234,
94
- 'pubkeyauthentication' => true,
95
- 'rekeylimit' => 1024,
96
- 'sendenv' => "LC_*",
97
- 'numberofpasswordprompts' => '123'
98
- }
99
-
100
- net_ssh = Net::SSH::Config.translate(open_ssh)
101
-
102
- assert_equal %w(a b c), net_ssh[:encryption]
103
- assert_equal true, net_ssh[:compression]
104
- assert_equal 6, net_ssh[:compression_level]
105
- assert_equal 100, net_ssh[:timeout]
106
- assert_equal true, net_ssh[:forward_agent]
107
- assert_equal %w(hostbased keyboard-interactive none password publickey), net_ssh[:auth_methods].sort
108
- assert_equal %w(d e f), net_ssh[:host_key]
109
- assert_equal %w(g h i), net_ssh[:keys]
110
- assert_equal %w(j k l), net_ssh[:hmac]
111
- assert_equal 1234, net_ssh[:port]
112
- assert_equal 1024, net_ssh[:rekey_limit]
113
- assert_equal "127.0.0.1", net_ssh[:bind_address]
114
- assert_equal [/^LC_.*$/], net_ssh[:send_env]
115
- assert_equal 123, net_ssh[:number_of_password_prompts]
116
- end
117
-
118
- def test_translate_should_turn_off_authentication_methods
119
- open_ssh = {
120
- 'hostbasedauthentication' => false,
121
- 'passwordauthentication' => false,
122
- 'pubkeyauthentication' => false,
123
- 'challengeresponseauthentication' => false,
124
- 'kbdinteractiveauthentication' => false
125
- }
126
-
127
- net_ssh = Net::SSH::Config.translate(open_ssh)
128
-
129
- assert_equal %w(none), net_ssh[:auth_methods].sort
130
- end
131
-
132
- def test_translate_should_turn_on_authentication_methods
133
- open_ssh = {
134
- 'hostbasedauthentication' => true,
135
- 'passwordauthentication' => true,
136
- 'pubkeyauthentication' => true,
137
- 'challengeresponseauthentication' => true,
138
- 'kbdinteractiveauthentication' => true
139
- }
140
-
141
- net_ssh = Net::SSH::Config.translate(open_ssh)
142
-
143
- assert_equal %w(hostbased keyboard-interactive none password publickey), net_ssh[:auth_methods].sort
144
- end
145
-
146
- def test_translate_should_not_disable_keyboard_interactive_when_challange_or_keyboardinterective_is_on
147
- open_ssh = {
148
- 'kbdinteractiveauthentication' => false
149
- }
150
- net_ssh = Net::SSH::Config.translate(open_ssh)
151
- assert_equal %w(keyboard-interactive none password publickey), net_ssh[:auth_methods].sort
152
-
153
- open_ssh = {
154
- 'challengeresponseauthentication' => false
155
- }
156
- net_ssh = Net::SSH::Config.translate(open_ssh)
157
- assert_equal %w(keyboard-interactive none password publickey), net_ssh[:auth_methods].sort
158
- end
159
-
160
- def test_should_ddisable_keyboard_interactive_when_challeng_and_keyboardinteractive_is_off
161
- open_ssh = {
162
- 'challengeresponseauthentication' => false,
163
- 'kbdinteractiveauthentication' => false
164
- }
165
-
166
- net_ssh = Net::SSH::Config.translate(open_ssh)
167
- assert_equal %w(none password publickey), net_ssh[:auth_methods].sort
168
- end
169
-
170
- def test_for_should_turn_off_authentication_methods
171
- config = Net::SSH::Config.for("test.host", [config(:empty), config(:auth_off), config(:auth_on)])
172
- assert_equal %w(none), config[:auth_methods].sort
173
- end
174
-
175
- def test_for_should_turn_on_authentication_methods
176
- config = Net::SSH::Config.for("test.host", [config(:empty), config(:auth_on), config(:auth_off)])
177
- assert_equal %w(hostbased keyboard-interactive none password publickey), config[:auth_methods].sort
178
- end
179
-
180
- def test_load_with_plus_sign_hosts
181
- config = Net::SSH::Config.load(config(:host_plus), "test.host")
182
- assert config['compression']
183
- end
184
-
185
- def test_load_with_numeric_host
186
- config = Net::SSH::Config.load(config(:numeric_host), "1234")
187
- assert config['compression']
188
- assert_equal '2G', config['rekeylimit']
189
- assert_equal 1980, config['port']
190
- end
191
-
192
- def test_load_wildcar_with_substitutes
193
- config = Net::SSH::Config.load(config(:substitutes), "toto")
194
- net_ssh = Net::SSH::Config.translate(config)
195
- assert_equal 'toto', net_ssh[:host_name]
196
- end
197
-
198
- def test_load_sufix_with_substitutes
199
- config = Net::SSH::Config.load(config(:substitutes), "test")
200
- net_ssh = Net::SSH::Config.translate(config)
201
- assert_equal 'test.sufix', net_ssh[:host_name]
202
- end
203
-
204
- def test_load_prefix_and_sufix_with_substitutes
205
- config = Net::SSH::Config.load(config(:substitutes), "1234")
206
- net_ssh = Net::SSH::Config.translate(config)
207
- assert_equal 'prefix.1234.sufix', net_ssh[:host_name]
208
- end
209
-
210
- def test_load_with_send_env
211
- config = Net::SSH::Config.load(config(:send_env), "1234")
212
- net_ssh = Net::SSH::Config.translate(config)
213
- assert_equal [/^GIT_.*$/, /^LANG$/, /^LC_.*$/], net_ssh[:send_env]
214
- end
215
-
216
- private
217
-
218
- def config(name)
219
- "test/configs/#{name}"
220
- end
221
- 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,13 +0,0 @@
1
- require 'common'
2
-
3
- class TestKnownHosts < Test::Unit::TestCase
4
-
5
- def test_key_for_when_all_hosts_are_recognized
6
- source = File.join(File.dirname(__FILE__),"known_hosts/github")
7
- kh = Net::SSH::KnownHosts.new(source)
8
- keys = kh.keys_for("github.com")
9
- assert_equal(1, keys.count)
10
- assert_equal("ssh-rsa", keys[0].ssh_type)
11
- end
12
-
13
- 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
@@ -1,36 +0,0 @@
1
- # encoding: ASCII-8BIT
2
-
3
- require 'common'
4
- require 'net/ssh/transport/hmac/sha1'
5
-
6
- module Transport; module HMAC
7
-
8
- class TestSHA1 < Test::Unit::TestCase
9
- def test_expected_digest_class
10
- assert_equal OpenSSL::Digest::SHA1, subject.digest_class
11
- assert_equal OpenSSL::Digest::SHA1, 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 "\000\004W\202\204+&\335\311\251P\266\250\214\276\206;\022U\365", hmac.digest("hello world")
27
- end
28
-
29
- private
30
-
31
- def subject
32
- Net::SSH::Transport::HMAC::SHA1
33
- end
34
- end
35
-
36
- end; end
@@ -1,27 +0,0 @@
1
- # encoding: ASCII-8BIT
2
-
3
- require 'common'
4
- require 'transport/hmac/test_sha1'
5
- require 'net/ssh/transport/hmac/sha1_96'
6
-
7
- module Transport; module HMAC
8
-
9
- class TestSHA1_96 < TestSHA1
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 "\000\004W\202\204+&\335\311\251P\266", hmac.digest("hello world")
18
- end
19
-
20
- private
21
-
22
- def subject
23
- Net::SSH::Transport::HMAC::SHA1_96
24
- end
25
- end
26
-
27
- end; end
@@ -1,37 +0,0 @@
1
- # encoding: ASCII-8BIT
2
-
3
- require 'common'
4
- require 'net/ssh/transport/hmac/sha2_256'
5
-
6
- module Transport; module HMAC
7
-
8
- class TestSHA2_256 < Test::Unit::TestCase
9
- def test_expected_digest_class
10
- assert_equal OpenSSL::Digest::SHA256, subject.digest_class
11
- assert_equal OpenSSL::Digest::SHA256, subject.new.digest_class
12
- end
13
-
14
- def test_expected_key_length
15
- assert_equal 32, subject.key_length
16
- assert_equal 32, subject.new.key_length
17
- end
18
-
19
- def test_expected_mac_length
20
- assert_equal 32, subject.mac_length
21
- assert_equal 32, subject.new.mac_length
22
- end
23
-
24
- def test_expected_digest
25
- hmac = subject.new("1234567890123456")
26
- assert_equal "\x16^>\x9FhO}\xB1>(\xBAF\xFBW\xB8\xF2\xFA\x824+\xC0\x94\x95\xC2\r\xE6\x88/\xEF\t\xF5%", hmac.digest("hello world")
27
-
28
- end
29
-
30
- private
31
-
32
- def subject
33
- Net::SSH::Transport::HMAC::SHA2_256
34
- end
35
- end
36
-
37
- end; end