net-ssh 2.9.2 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -1,324 +0,0 @@
1
- require 'common'
2
- require 'net/ssh/transport/algorithms'
3
-
4
- module Transport
5
-
6
- class TestAlgorithms < Test::Unit::TestCase
7
- include Net::SSH::Transport::Constants
8
-
9
- def test_allowed_packets
10
- (0..255).each do |type|
11
- packet = stub("packet", :type => type)
12
- case type
13
- when 1..4, 6..19, 21..49 then assert(Net::SSH::Transport::Algorithms.allowed_packet?(packet), "#{type} should be allowed during key exchange")
14
- else assert(!Net::SSH::Transport::Algorithms.allowed_packet?(packet), "#{type} should not be allowed during key exchange")
15
- end
16
- end
17
- end
18
-
19
- def test_constructor_should_build_default_list_of_preferred_algorithms
20
- assert_equal %w(ssh-rsa ssh-dss ssh-rsa-cert-v01@openssh.com ssh-rsa-cert-v00@openssh.com)+ec_host_keys, algorithms[:host_key]
21
- assert_equal %w(diffie-hellman-group-exchange-sha1 diffie-hellman-group1-sha1 diffie-hellman-group14-sha1 diffie-hellman-group-exchange-sha256)+ec_kex, algorithms[:kex]
22
- assert_equal %w(aes128-cbc 3des-cbc blowfish-cbc cast128-cbc aes192-cbc aes256-cbc rijndael-cbc@lysator.liu.se idea-cbc none arcfour128 arcfour256 arcfour aes128-ctr aes192-ctr aes256-ctr camellia128-cbc camellia192-cbc camellia256-cbc camellia128-cbc@openssh.org camellia192-cbc@openssh.org camellia256-cbc@openssh.org camellia128-ctr camellia192-ctr camellia256-ctr camellia128-ctr@openssh.org camellia192-ctr@openssh.org camellia256-ctr@openssh.org cast128-ctr blowfish-ctr 3des-ctr), algorithms[:encryption]
23
- if defined?(OpenSSL::Digest::SHA256)
24
- assert_equal %w(hmac-sha1 hmac-md5 hmac-sha1-96 hmac-md5-96 hmac-ripemd160 hmac-ripemd160@openssh.com hmac-sha2-256 hmac-sha2-512 hmac-sha2-256-96 hmac-sha2-512-96 none), algorithms[:hmac]
25
- else
26
- assert_equal %w(hmac-sha1 hmac-md5 hmac-sha1-96 hmac-md5-96 hmac-ripemd160 hmac-ripemd160@openssh.com none umac-128-etm@openssh.com), algorithms[:hmac] end
27
- assert_equal %w(none zlib@openssh.com zlib), algorithms[:compression]
28
- assert_equal %w(), algorithms[:language]
29
- end
30
-
31
- def test_constructor_should_set_client_and_server_prefs_identically
32
- %w(encryption hmac compression language).each do |key|
33
- assert_equal algorithms[key.to_sym], algorithms[:"#{key}_client"], key
34
- assert_equal algorithms[key.to_sym], algorithms[:"#{key}_server"], key
35
- end
36
- end
37
-
38
- def test_constructor_with_preferred_host_key_type_should_put_preferred_host_key_type_first
39
- assert_equal %w(ssh-dss ssh-rsa ssh-rsa-cert-v01@openssh.com ssh-rsa-cert-v00@openssh.com)+ec_host_keys, algorithms(:host_key => "ssh-dss")[:host_key]
40
- end
41
-
42
- def test_constructor_with_known_hosts_reporting_known_host_key_should_use_that_host_key_type
43
- Net::SSH::KnownHosts.expects(:search_for).with("net.ssh.test,127.0.0.1", {}).returns([stub("key", :ssh_type => "ssh-dss")])
44
- assert_equal %w(ssh-dss ssh-rsa ssh-rsa-cert-v01@openssh.com ssh-rsa-cert-v00@openssh.com )+ec_host_keys, algorithms[:host_key]
45
- end
46
-
47
- def ec_host_keys
48
- if defined?(OpenSSL::PKey::EC)
49
- %w(ecdsa-sha2-nistp256 ecdsa-sha2-nistp384 ecdsa-sha2-nistp521)
50
- else
51
- []
52
- end
53
- end
54
-
55
- def test_constructor_with_unrecognized_host_key_type_should_return_whats_supported
56
- assert_equal %w(ssh-rsa ssh-dss ssh-rsa-cert-v01@openssh.com ssh-rsa-cert-v00@openssh.com )+ec_host_keys, algorithms(:host_key => "bogus ssh-rsa")[:host_key]
57
- end
58
-
59
- def ec_kex
60
- if defined?(OpenSSL::PKey::EC)
61
- %w(ecdh-sha2-nistp256 ecdh-sha2-nistp384 ecdh-sha2-nistp521)
62
- else
63
- []
64
- end
65
- end
66
-
67
- def test_constructor_with_preferred_kex_should_put_preferred_kex_first
68
- assert_equal %w(diffie-hellman-group1-sha1 diffie-hellman-group-exchange-sha1 diffie-hellman-group14-sha1 diffie-hellman-group-exchange-sha256)+ec_kex, algorithms(:kex => "diffie-hellman-group1-sha1")[:kex]
69
- end
70
-
71
- def test_constructor_with_unrecognized_kex_should_raise_exception
72
- assert_equal %w(diffie-hellman-group1-sha1 diffie-hellman-group-exchange-sha1 diffie-hellman-group14-sha1 diffie-hellman-group-exchange-sha256)+ec_kex, algorithms(:kex => %w(bogus diffie-hellman-group1-sha1))[:kex]
73
- end
74
-
75
- def test_constructor_with_preferred_encryption_should_put_preferred_encryption_first
76
- assert_equal %w(aes256-cbc aes128-cbc 3des-cbc blowfish-cbc cast128-cbc aes192-cbc rijndael-cbc@lysator.liu.se idea-cbc none arcfour128 arcfour256 arcfour aes128-ctr aes192-ctr aes256-ctr camellia128-cbc camellia192-cbc camellia256-cbc camellia128-cbc@openssh.org camellia192-cbc@openssh.org camellia256-cbc@openssh.org camellia128-ctr camellia192-ctr camellia256-ctr camellia128-ctr@openssh.org camellia192-ctr@openssh.org camellia256-ctr@openssh.org cast128-ctr blowfish-ctr 3des-ctr), algorithms(:encryption => "aes256-cbc")[:encryption]
77
- end
78
-
79
- def test_constructor_with_multiple_preferred_encryption_should_put_all_preferred_encryption_first
80
- assert_equal %w(aes256-cbc 3des-cbc idea-cbc aes128-cbc blowfish-cbc cast128-cbc aes192-cbc rijndael-cbc@lysator.liu.se none arcfour128 arcfour256 arcfour aes128-ctr aes192-ctr aes256-ctr camellia128-cbc camellia192-cbc camellia256-cbc camellia128-cbc@openssh.org camellia192-cbc@openssh.org camellia256-cbc@openssh.org camellia128-ctr camellia192-ctr camellia256-ctr camellia128-ctr@openssh.org camellia192-ctr@openssh.org camellia256-ctr@openssh.org cast128-ctr blowfish-ctr 3des-ctr), algorithms(:encryption => %w(aes256-cbc 3des-cbc idea-cbc))[:encryption]
81
- end
82
-
83
- def test_constructor_with_unrecognized_encryption_should_keep_whats_supported
84
- assert_equal %w(aes256-cbc aes128-cbc 3des-cbc blowfish-cbc cast128-cbc aes192-cbc rijndael-cbc@lysator.liu.se idea-cbc none arcfour128 arcfour256 arcfour aes128-ctr aes192-ctr aes256-ctr camellia128-cbc camellia192-cbc camellia256-cbc camellia128-cbc@openssh.org camellia192-cbc@openssh.org camellia256-cbc@openssh.org camellia128-ctr camellia192-ctr camellia256-ctr camellia128-ctr@openssh.org camellia192-ctr@openssh.org camellia256-ctr@openssh.org cast128-ctr blowfish-ctr 3des-ctr), algorithms(:encryption => %w(bogus aes256-cbc))[:encryption]
85
- end
86
-
87
- def test_constructor_with_preferred_hmac_should_put_preferred_hmac_first
88
- assert_equal %w(hmac-md5-96 hmac-sha1 hmac-md5 hmac-sha1-96 hmac-ripemd160 hmac-ripemd160@openssh.com hmac-sha2-256 hmac-sha2-512 hmac-sha2-256-96 hmac-sha2-512-96 none), algorithms(:hmac => "hmac-md5-96")[:hmac]
89
- end
90
-
91
- def test_constructor_with_multiple_preferred_hmac_should_put_all_preferred_hmac_first
92
- assert_equal %w(hmac-md5-96 hmac-sha1-96 hmac-sha1 hmac-md5 hmac-ripemd160 hmac-ripemd160@openssh.com hmac-sha2-256 hmac-sha2-512 hmac-sha2-256-96 hmac-sha2-512-96 none), algorithms(:hmac => %w(hmac-md5-96 hmac-sha1-96))[:hmac]
93
- end
94
-
95
- def test_constructor_with_unrecognized_hmac_should_ignore_those
96
- assert_equal %w(hmac-md5-96 hmac-sha1 hmac-md5 hmac-sha1-96 hmac-ripemd160 hmac-ripemd160@openssh.com hmac-sha2-256 hmac-sha2-512 hmac-sha2-256-96 hmac-sha2-512-96 none),
97
- algorithms(:hmac => "hmac-md5-96")[:hmac]
98
- end
99
-
100
- def test_constructor_with_preferred_compression_should_put_preferred_compression_first
101
- assert_equal %w(zlib none zlib@openssh.com), algorithms(:compression => "zlib")[:compression]
102
- end
103
-
104
- def test_constructor_with_multiple_preferred_compression_should_put_all_preferred_compression_first
105
- assert_equal %w(zlib@openssh.com zlib none), algorithms(:compression => %w(zlib@openssh.com zlib))[:compression]
106
- end
107
-
108
- def test_constructor_with_general_preferred_compression_should_put_none_last
109
- assert_equal %w(zlib@openssh.com zlib none), algorithms(:compression => true)[:compression]
110
- end
111
-
112
- def test_constructor_with_unrecognized_compression_should_return_whats_supported
113
- assert_equal %w(none zlib zlib@openssh.com), algorithms(:compression => %w(bogus none zlib))[:compression]
114
- end
115
-
116
- def test_initial_state_should_be_neither_pending_nor_initialized
117
- assert !algorithms.pending?
118
- assert !algorithms.initialized?
119
- end
120
-
121
- def test_key_exchange_when_initiated_by_server
122
- transport.expect do |t, buffer|
123
- assert_kexinit(buffer)
124
- install_mock_key_exchange(buffer)
125
- end
126
-
127
- install_mock_algorithm_lookups
128
- algorithms.accept_kexinit(kexinit)
129
-
130
- assert_exchange_results
131
- end
132
-
133
- def test_key_exchange_when_initiated_by_client
134
- state = nil
135
- transport.expect do |t, buffer|
136
- assert_kexinit(buffer)
137
- state = :sent_kexinit
138
- install_mock_key_exchange(buffer)
139
- end
140
-
141
- algorithms.rekey!
142
- assert_equal state, :sent_kexinit
143
- assert algorithms.pending?
144
-
145
- install_mock_algorithm_lookups
146
- algorithms.accept_kexinit(kexinit)
147
-
148
- assert_exchange_results
149
- end
150
-
151
- def test_key_exchange_when_server_does_not_support_preferred_kex_should_fallback_to_secondary
152
- kexinit :kex => "diffie-hellman-group1-sha1"
153
- transport.expect do |t,buffer|
154
- assert_kexinit(buffer)
155
- install_mock_key_exchange(buffer, :kex => Net::SSH::Transport::Kex::DiffieHellmanGroup1SHA1)
156
- end
157
- algorithms.accept_kexinit(kexinit)
158
- end
159
-
160
- def test_key_exchange_when_server_does_not_support_any_preferred_kex_should_raise_error
161
- kexinit :kex => "something-obscure"
162
- transport.expect { |t,buffer| assert_kexinit(buffer) }
163
- assert_raises(Net::SSH::Exception) { algorithms.accept_kexinit(kexinit) }
164
- end
165
-
166
- def test_allow_when_not_pending_should_be_true_for_all_packets
167
- (0..255).each do |type|
168
- packet = stub("packet", :type => type)
169
- assert algorithms.allow?(packet), type.to_s
170
- end
171
- end
172
-
173
- def test_allow_when_pending_should_be_true_only_for_packets_valid_during_key_exchange
174
- transport.expect!
175
- algorithms.rekey!
176
- assert algorithms.pending?
177
-
178
- (0..255).each do |type|
179
- packet = stub("packet", :type => type)
180
- case type
181
- when 1..4, 6..19, 21..49 then assert(algorithms.allow?(packet), "#{type} should be allowed during key exchange")
182
- else assert(!algorithms.allow?(packet), "#{type} should not be allowed during key exchange")
183
- end
184
- end
185
- end
186
-
187
- def test_exchange_with_zlib_compression_enabled_sets_compression_to_standard
188
- algorithms :compression => "zlib"
189
-
190
- transport.expect do |t, buffer|
191
- assert_kexinit(buffer, :compression_client => "zlib,none,zlib@openssh.com", :compression_server => "zlib,none,zlib@openssh.com")
192
- install_mock_key_exchange(buffer)
193
- end
194
-
195
- install_mock_algorithm_lookups
196
- algorithms.accept_kexinit(kexinit)
197
-
198
- assert_equal :standard, transport.client_options[:compression]
199
- assert_equal :standard, transport.server_options[:compression]
200
- end
201
-
202
- def test_exchange_with_zlib_at_openssh_dot_com_compression_enabled_sets_compression_to_delayed
203
- algorithms :compression => "zlib@openssh.com"
204
-
205
- transport.expect do |t, buffer|
206
- assert_kexinit(buffer, :compression_client => "zlib@openssh.com,none,zlib", :compression_server => "zlib@openssh.com,none,zlib")
207
- install_mock_key_exchange(buffer)
208
- end
209
-
210
- install_mock_algorithm_lookups
211
- algorithms.accept_kexinit(kexinit)
212
-
213
- assert_equal :delayed, transport.client_options[:compression]
214
- assert_equal :delayed, transport.server_options[:compression]
215
- end
216
-
217
- private
218
-
219
- def install_mock_key_exchange(buffer, options={})
220
- kex = options[:kex] || Net::SSH::Transport::Kex::DiffieHellmanGroupExchangeSHA1
221
-
222
- Net::SSH::Transport::Kex::MAP.each do |name, klass|
223
- next if klass == kex
224
- klass.expects(:new).never
225
- end
226
-
227
- kex.expects(:new).
228
- with(algorithms, transport,
229
- :client_version_string => Net::SSH::Transport::ServerVersion::PROTO_VERSION,
230
- :server_version_string => transport.server_version.version,
231
- :server_algorithm_packet => kexinit.to_s,
232
- :client_algorithm_packet => buffer.to_s,
233
- :need_bytes => 20,
234
- :logger => nil).
235
- returns(stub("kex", :exchange_keys => { :shared_secret => shared_secret, :session_id => session_id, :hashing_algorithm => hashing_algorithm }))
236
- end
237
-
238
- def install_mock_algorithm_lookups(options={})
239
- params = { :shared => shared_secret.to_ssh, :hash => session_id, :digester => hashing_algorithm }
240
- Net::SSH::Transport::CipherFactory.expects(:get).
241
- with(options[:client_cipher] || "aes128-cbc", params.merge(:iv => key("A"), :key => key("C"), :encrypt => true)).
242
- returns(:client_cipher)
243
-
244
- Net::SSH::Transport::CipherFactory.expects(:get).
245
- with(options[:server_cipher] || "aes128-cbc", params.merge(:iv => key("B"), :key => key("D"), :decrypt => true)).
246
- returns(:server_cipher)
247
-
248
- Net::SSH::Transport::HMAC.expects(:get).with(options[:client_hmac] || "hmac-sha1", key("E"), params).returns(:client_hmac)
249
- Net::SSH::Transport::HMAC.expects(:get).with(options[:server_hmac] || "hmac-sha1", key("F"), params).returns(:server_hmac)
250
- end
251
-
252
- def shared_secret
253
- @shared_secret ||= OpenSSL::BN.new("1234567890", 10)
254
- end
255
-
256
- def session_id
257
- @session_id ||= "this is the session id"
258
- end
259
-
260
- def hashing_algorithm
261
- OpenSSL::Digest::SHA1
262
- end
263
-
264
- def key(salt)
265
- hashing_algorithm.digest(shared_secret.to_ssh + session_id + salt + session_id)
266
- end
267
-
268
- def cipher(type, options={})
269
- Net::SSH::Transport::CipherFactory.get(type, options)
270
- end
271
-
272
- def kexinit(options={})
273
- @kexinit ||= P(:byte, KEXINIT,
274
- :long, rand(0xFFFFFFFF), :long, rand(0xFFFFFFFF), :long, rand(0xFFFFFFFF), :long, rand(0xFFFFFFFF),
275
- :string, options[:kex] || "diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1,diffie-hellman-group-exchange-sha256",
276
- :string, options[:host_key] || "ssh-rsa,ssh-dss",
277
- :string, options[:encryption_client] || "aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,rijndael-cbc@lysator.liu.se,idea-cbc",
278
- :string, options[:encryption_server] || "aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,rijndael-cbc@lysator.liu.se,idea-cbc",
279
- :string, options[:hmac_client] || "hmac-sha1,hmac-md5,hmac-sha1-96,hmac-md5-96",
280
- :string, options[:hmac_server] || "hmac-sha1,hmac-md5,hmac-sha1-96,hmac-md5-96",
281
- :string, options[:compression_client] || "none,zlib@openssh.com,zlib",
282
- :string, options[:compression_server] || "none,zlib@openssh.com,zlib",
283
- :string, options[:language_client] || "",
284
- :string, options[:langauge_server] || "",
285
- :bool, options[:first_kex_follows])
286
- end
287
-
288
- def assert_kexinit(buffer, options={})
289
- assert_equal KEXINIT, buffer.type
290
- assert_equal 16, buffer.read(16).length
291
- assert_equal options[:kex] || (%w(diffie-hellman-group-exchange-sha1 diffie-hellman-group1-sha1 diffie-hellman-group14-sha1 diffie-hellman-group-exchange-sha256)+ec_kex).join(','), buffer.read_string
292
- assert_equal options[:host_key] || (%w(ssh-rsa ssh-dss ssh-rsa-cert-v01@openssh.com ssh-rsa-cert-v00@openssh.com)+ec_host_keys).join(','), buffer.read_string
293
- assert_equal options[:encryption_client] || "aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,rijndael-cbc@lysator.liu.se,idea-cbc,none,arcfour128,arcfour256,arcfour,aes128-ctr,aes192-ctr,aes256-ctr,camellia128-cbc,camellia192-cbc,camellia256-cbc,camellia128-cbc@openssh.org,camellia192-cbc@openssh.org,camellia256-cbc@openssh.org,camellia128-ctr,camellia192-ctr,camellia256-ctr,camellia128-ctr@openssh.org,camellia192-ctr@openssh.org,camellia256-ctr@openssh.org,cast128-ctr,blowfish-ctr,3des-ctr", buffer.read_string
294
- assert_equal options[:encryption_server] || "aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,rijndael-cbc@lysator.liu.se,idea-cbc,none,arcfour128,arcfour256,arcfour,aes128-ctr,aes192-ctr,aes256-ctr,camellia128-cbc,camellia192-cbc,camellia256-cbc,camellia128-cbc@openssh.org,camellia192-cbc@openssh.org,camellia256-cbc@openssh.org,camellia128-ctr,camellia192-ctr,camellia256-ctr,camellia128-ctr@openssh.org,camellia192-ctr@openssh.org,camellia256-ctr@openssh.org,cast128-ctr,blowfish-ctr,3des-ctr", buffer.read_string
295
- assert_equal options[:hmac_client] || "hmac-sha1,hmac-md5,hmac-sha1-96,hmac-md5-96,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-sha2-256-96,hmac-sha2-512-96,none", buffer.read_string
296
- assert_equal options[:hmac_server] || "hmac-sha1,hmac-md5,hmac-sha1-96,hmac-md5-96,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-sha2-256-96,hmac-sha2-512-96,none", buffer.read_string
297
- assert_equal options[:compression_client] || "none,zlib@openssh.com,zlib", buffer.read_string
298
- assert_equal options[:compression_server] || "none,zlib@openssh.com,zlib", buffer.read_string
299
- assert_equal options[:language_client] || "", buffer.read_string
300
- assert_equal options[:language_server] || "", buffer.read_string
301
- assert_equal options[:first_kex_follows] || false, buffer.read_bool
302
- end
303
-
304
- def assert_exchange_results
305
- assert algorithms.initialized?
306
- assert !algorithms.pending?
307
- assert !transport.client_options[:compression]
308
- assert !transport.server_options[:compression]
309
- assert_equal :client_cipher, transport.client_options[:cipher]
310
- assert_equal :server_cipher, transport.server_options[:cipher]
311
- assert_equal :client_hmac, transport.client_options[:hmac]
312
- assert_equal :server_hmac, transport.server_options[:hmac]
313
- end
314
-
315
- def algorithms(options={})
316
- @algorithms ||= Net::SSH::Transport::Algorithms.new(transport, options)
317
- end
318
-
319
- def transport
320
- @transport ||= MockTransport.new
321
- end
322
- end
323
-
324
- end