net-ssh 2.7.0 → 7.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (199) hide show
  1. checksums.yaml +7 -0
  2. checksums.yaml.gz.sig +0 -0
  3. data/.dockerignore +6 -0
  4. data/.github/FUNDING.yml +1 -0
  5. data/.github/config/rubocop_linter_action.yml +4 -0
  6. data/.github/workflows/ci-with-docker.yml +44 -0
  7. data/.github/workflows/ci.yml +94 -0
  8. data/.github/workflows/rubocop.yml +16 -0
  9. data/.gitignore +15 -0
  10. data/.rubocop.yml +22 -0
  11. data/.rubocop_todo.yml +1081 -0
  12. data/CHANGES.txt +387 -0
  13. data/DEVELOPMENT.md +23 -0
  14. data/Dockerfile +29 -0
  15. data/Dockerfile.openssl3 +17 -0
  16. data/Gemfile +13 -0
  17. data/Gemfile.noed25519 +12 -0
  18. data/Gemfile.norbnacl +12 -0
  19. data/ISSUE_TEMPLATE.md +30 -0
  20. data/Manifest +4 -5
  21. data/README.md +303 -0
  22. data/Rakefile +174 -40
  23. data/SECURITY.md +4 -0
  24. data/THANKS.txt +25 -0
  25. data/appveyor.yml +58 -0
  26. data/docker-compose.yml +25 -0
  27. data/lib/net/ssh/authentication/agent.rb +279 -18
  28. data/lib/net/ssh/authentication/certificate.rb +183 -0
  29. data/lib/net/ssh/authentication/constants.rb +17 -15
  30. data/lib/net/ssh/authentication/ed25519.rb +184 -0
  31. data/lib/net/ssh/authentication/ed25519_loader.rb +31 -0
  32. data/lib/net/ssh/authentication/key_manager.rb +125 -54
  33. data/lib/net/ssh/authentication/methods/abstract.rb +67 -48
  34. data/lib/net/ssh/authentication/methods/hostbased.rb +34 -37
  35. data/lib/net/ssh/authentication/methods/keyboard_interactive.rb +19 -12
  36. data/lib/net/ssh/authentication/methods/none.rb +16 -19
  37. data/lib/net/ssh/authentication/methods/password.rb +56 -19
  38. data/lib/net/ssh/authentication/methods/publickey.rb +96 -55
  39. data/lib/net/ssh/authentication/pageant.rb +483 -246
  40. data/lib/net/ssh/authentication/pub_key_fingerprint.rb +43 -0
  41. data/lib/net/ssh/authentication/session.rb +138 -120
  42. data/lib/net/ssh/buffer.rb +399 -300
  43. data/lib/net/ssh/buffered_io.rb +154 -150
  44. data/lib/net/ssh/config.rb +361 -166
  45. data/lib/net/ssh/connection/channel.rb +640 -596
  46. data/lib/net/ssh/connection/constants.rb +29 -29
  47. data/lib/net/ssh/connection/event_loop.rb +123 -0
  48. data/lib/net/ssh/connection/keepalive.rb +59 -0
  49. data/lib/net/ssh/connection/session.rb +628 -548
  50. data/lib/net/ssh/connection/term.rb +125 -123
  51. data/lib/net/ssh/errors.rb +101 -95
  52. data/lib/net/ssh/key_factory.rb +198 -100
  53. data/lib/net/ssh/known_hosts.rb +221 -98
  54. data/lib/net/ssh/loggable.rb +50 -49
  55. data/lib/net/ssh/packet.rb +83 -79
  56. data/lib/net/ssh/prompt.rb +50 -81
  57. data/lib/net/ssh/proxy/command.rb +108 -60
  58. data/lib/net/ssh/proxy/errors.rb +12 -10
  59. data/lib/net/ssh/proxy/http.rb +82 -78
  60. data/lib/net/ssh/proxy/https.rb +50 -0
  61. data/lib/net/ssh/proxy/jump.rb +54 -0
  62. data/lib/net/ssh/proxy/socks4.rb +5 -8
  63. data/lib/net/ssh/proxy/socks5.rb +18 -20
  64. data/lib/net/ssh/service/forward.rb +383 -255
  65. data/lib/net/ssh/test/channel.rb +145 -136
  66. data/lib/net/ssh/test/extensions.rb +131 -110
  67. data/lib/net/ssh/test/kex.rb +34 -32
  68. data/lib/net/ssh/test/local_packet.rb +46 -44
  69. data/lib/net/ssh/test/packet.rb +89 -70
  70. data/lib/net/ssh/test/remote_packet.rb +32 -30
  71. data/lib/net/ssh/test/script.rb +156 -142
  72. data/lib/net/ssh/test/socket.rb +49 -48
  73. data/lib/net/ssh/test.rb +82 -77
  74. data/lib/net/ssh/transport/aes128_gcm.rb +40 -0
  75. data/lib/net/ssh/transport/aes256_gcm.rb +40 -0
  76. data/lib/net/ssh/transport/algorithms.rb +472 -348
  77. data/lib/net/ssh/transport/chacha20_poly1305_cipher.rb +117 -0
  78. data/lib/net/ssh/transport/chacha20_poly1305_cipher_loader.rb +17 -0
  79. data/lib/net/ssh/transport/cipher_factory.rb +124 -100
  80. data/lib/net/ssh/transport/constants.rb +32 -24
  81. data/lib/net/ssh/transport/ctr.rb +42 -22
  82. data/lib/net/ssh/transport/gcm_cipher.rb +207 -0
  83. data/lib/net/ssh/transport/hmac/abstract.rb +97 -63
  84. data/lib/net/ssh/transport/hmac/md5.rb +0 -2
  85. data/lib/net/ssh/transport/hmac/md5_96.rb +0 -2
  86. data/lib/net/ssh/transport/hmac/none.rb +0 -2
  87. data/lib/net/ssh/transport/hmac/ripemd160.rb +0 -2
  88. data/lib/net/ssh/transport/hmac/sha1.rb +0 -2
  89. data/lib/net/ssh/transport/hmac/sha1_96.rb +0 -2
  90. data/lib/net/ssh/transport/hmac/sha2_256.rb +7 -11
  91. data/lib/net/ssh/transport/hmac/sha2_256_96.rb +4 -8
  92. data/lib/net/ssh/transport/hmac/sha2_256_etm.rb +12 -0
  93. data/lib/net/ssh/transport/hmac/sha2_512.rb +6 -9
  94. data/lib/net/ssh/transport/hmac/sha2_512_96.rb +4 -8
  95. data/lib/net/ssh/transport/hmac/sha2_512_etm.rb +12 -0
  96. data/lib/net/ssh/transport/hmac.rb +14 -12
  97. data/lib/net/ssh/transport/identity_cipher.rb +54 -44
  98. data/lib/net/ssh/transport/kex/abstract.rb +130 -0
  99. data/lib/net/ssh/transport/kex/abstract5656.rb +72 -0
  100. data/lib/net/ssh/transport/kex/curve25519_sha256.rb +39 -0
  101. data/lib/net/ssh/transport/kex/curve25519_sha256_loader.rb +30 -0
  102. data/lib/net/ssh/transport/kex/diffie_hellman_group14_sha1.rb +33 -40
  103. data/lib/net/ssh/transport/kex/diffie_hellman_group14_sha256.rb +11 -0
  104. data/lib/net/ssh/transport/kex/diffie_hellman_group1_sha1.rb +119 -213
  105. data/lib/net/ssh/transport/kex/diffie_hellman_group_exchange_sha1.rb +53 -61
  106. data/lib/net/ssh/transport/kex/diffie_hellman_group_exchange_sha256.rb +5 -9
  107. data/lib/net/ssh/transport/kex/ecdh_sha2_nistp256.rb +36 -90
  108. data/lib/net/ssh/transport/kex/ecdh_sha2_nistp384.rb +18 -10
  109. data/lib/net/ssh/transport/kex/ecdh_sha2_nistp521.rb +18 -10
  110. data/lib/net/ssh/transport/kex.rb +15 -12
  111. data/lib/net/ssh/transport/key_expander.rb +24 -20
  112. data/lib/net/ssh/transport/openssl.rb +161 -124
  113. data/lib/net/ssh/transport/openssl_cipher_extensions.rb +8 -0
  114. data/lib/net/ssh/transport/packet_stream.rb +246 -183
  115. data/lib/net/ssh/transport/server_version.rb +57 -51
  116. data/lib/net/ssh/transport/session.rb +307 -235
  117. data/lib/net/ssh/transport/state.rb +178 -176
  118. data/lib/net/ssh/verifiers/accept_new.rb +33 -0
  119. data/lib/net/ssh/verifiers/accept_new_or_local_tunnel.rb +33 -0
  120. data/lib/net/ssh/verifiers/always.rb +58 -0
  121. data/lib/net/ssh/verifiers/never.rb +19 -0
  122. data/lib/net/ssh/version.rb +57 -51
  123. data/lib/net/ssh.rb +140 -40
  124. data/net-ssh-public_cert.pem +21 -0
  125. data/net-ssh.gemspec +39 -184
  126. data/support/ssh_tunnel_bug.rb +5 -5
  127. data.tar.gz.sig +0 -0
  128. metadata +205 -99
  129. metadata.gz.sig +0 -0
  130. data/README.rdoc +0 -219
  131. data/Rudyfile +0 -96
  132. data/gem-public_cert.pem +0 -20
  133. data/lib/net/ssh/authentication/agent/java_pageant.rb +0 -85
  134. data/lib/net/ssh/authentication/agent/socket.rb +0 -170
  135. data/lib/net/ssh/ruby_compat.rb +0 -51
  136. data/lib/net/ssh/verifiers/lenient.rb +0 -30
  137. data/lib/net/ssh/verifiers/null.rb +0 -12
  138. data/lib/net/ssh/verifiers/secure.rb +0 -54
  139. data/lib/net/ssh/verifiers/strict.rb +0 -24
  140. data/setup.rb +0 -1585
  141. data/support/arcfour_check.rb +0 -20
  142. data/test/README.txt +0 -47
  143. data/test/authentication/methods/common.rb +0 -28
  144. data/test/authentication/methods/test_abstract.rb +0 -51
  145. data/test/authentication/methods/test_hostbased.rb +0 -114
  146. data/test/authentication/methods/test_keyboard_interactive.rb +0 -100
  147. data/test/authentication/methods/test_none.rb +0 -41
  148. data/test/authentication/methods/test_password.rb +0 -52
  149. data/test/authentication/methods/test_publickey.rb +0 -148
  150. data/test/authentication/test_agent.rb +0 -205
  151. data/test/authentication/test_key_manager.rb +0 -218
  152. data/test/authentication/test_session.rb +0 -108
  153. data/test/common.rb +0 -108
  154. data/test/configs/eqsign +0 -3
  155. data/test/configs/exact_match +0 -8
  156. data/test/configs/host_plus +0 -10
  157. data/test/configs/multihost +0 -4
  158. data/test/configs/nohost +0 -19
  159. data/test/configs/numeric_host +0 -4
  160. data/test/configs/send_env +0 -2
  161. data/test/configs/substitutes +0 -8
  162. data/test/configs/wild_cards +0 -14
  163. data/test/connection/test_channel.rb +0 -467
  164. data/test/connection/test_session.rb +0 -526
  165. data/test/known_hosts/github +0 -1
  166. data/test/manual/test_forward.rb +0 -223
  167. data/test/start/test_options.rb +0 -36
  168. data/test/start/test_transport.rb +0 -28
  169. data/test/test_all.rb +0 -11
  170. data/test/test_buffer.rb +0 -433
  171. data/test/test_buffered_io.rb +0 -63
  172. data/test/test_config.rb +0 -151
  173. data/test/test_key_factory.rb +0 -173
  174. data/test/test_known_hosts.rb +0 -13
  175. data/test/transport/hmac/test_md5.rb +0 -41
  176. data/test/transport/hmac/test_md5_96.rb +0 -27
  177. data/test/transport/hmac/test_none.rb +0 -34
  178. data/test/transport/hmac/test_ripemd160.rb +0 -36
  179. data/test/transport/hmac/test_sha1.rb +0 -36
  180. data/test/transport/hmac/test_sha1_96.rb +0 -27
  181. data/test/transport/hmac/test_sha2_256.rb +0 -37
  182. data/test/transport/hmac/test_sha2_256_96.rb +0 -27
  183. data/test/transport/hmac/test_sha2_512.rb +0 -37
  184. data/test/transport/hmac/test_sha2_512_96.rb +0 -27
  185. data/test/transport/kex/test_diffie_hellman_group14_sha1.rb +0 -13
  186. data/test/transport/kex/test_diffie_hellman_group1_sha1.rb +0 -146
  187. data/test/transport/kex/test_diffie_hellman_group_exchange_sha1.rb +0 -92
  188. data/test/transport/kex/test_diffie_hellman_group_exchange_sha256.rb +0 -34
  189. data/test/transport/kex/test_ecdh_sha2_nistp256.rb +0 -161
  190. data/test/transport/kex/test_ecdh_sha2_nistp384.rb +0 -38
  191. data/test/transport/kex/test_ecdh_sha2_nistp521.rb +0 -38
  192. data/test/transport/test_algorithms.rb +0 -330
  193. data/test/transport/test_cipher_factory.rb +0 -443
  194. data/test/transport/test_hmac.rb +0 -34
  195. data/test/transport/test_identity_cipher.rb +0 -40
  196. data/test/transport/test_packet_stream.rb +0 -1755
  197. data/test/transport/test_server_version.rb +0 -78
  198. data/test/transport/test_session.rb +0 -319
  199. data/test/transport/test_state.rb +0 -181
@@ -1,330 +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
- if defined?(OpenSSL::PKey::EC)
21
- assert_equal %w(ssh-rsa ssh-dss ecdsa-sha2-nistp256 ecdsa-sha2-nistp384 ecdsa-sha2-nistp521), algorithms[:host_key]
22
- assert_equal %w(diffie-hellman-group-exchange-sha1 diffie-hellman-group1-sha1 diffie-hellman-group14-sha1 diffie-hellman-group-exchange-sha256 ecdh-sha2-nistp256 ecdh-sha2-nistp384 ecdh-sha2-nistp521), algorithms[:kex]
23
- else
24
- assert_equal %w(ssh-rsa ssh-dss), algorithms[:host_key]
25
- assert_equal %w(diffie-hellman-group-exchange-sha1 diffie-hellman-group1-sha1 diffie-hellman-group14-sha1 diffie-hellman-group-exchange-sha256), algorithms[:kex]
26
- end
27
- 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]
28
- if defined?(OpenSSL::Digest::SHA256)
29
- 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]
30
- else
31
- assert_equal %w(hmac-sha1 hmac-md5 hmac-sha1-96 hmac-md5-96 hmac-ripemd160 hmac-ripemd160@openssh.com none), algorithms[:hmac]
32
- end
33
- assert_equal %w(none zlib@openssh.com zlib), algorithms[:compression]
34
- assert_equal %w(), algorithms[:language]
35
- end
36
-
37
- def test_constructor_should_set_client_and_server_prefs_identically
38
- %w(encryption hmac compression language).each do |key|
39
- assert_equal algorithms[key.to_sym], algorithms[:"#{key}_client"], key
40
- assert_equal algorithms[key.to_sym], algorithms[:"#{key}_server"], key
41
- end
42
- end
43
-
44
- def test_constructor_with_preferred_host_key_type_should_put_preferred_host_key_type_first
45
- if defined?(OpenSSL::PKey::EC)
46
- assert_equal %w(ssh-dss ssh-rsa ecdsa-sha2-nistp256 ecdsa-sha2-nistp384 ecdsa-sha2-nistp521), algorithms(:host_key => "ssh-dss")[:host_key]
47
- else
48
- assert_equal %w(ssh-dss ssh-rsa), algorithms(:host_key => "ssh-dss")[:host_key]
49
- end
50
- end
51
-
52
- def test_constructor_with_known_hosts_reporting_known_host_key_should_use_that_host_key_type
53
- Net::SSH::KnownHosts.expects(:search_for).with("net.ssh.test,127.0.0.1", {}).returns([stub("key", :ssh_type => "ssh-dss")])
54
- if defined?(OpenSSL::PKey::EC)
55
- assert_equal %w(ssh-dss ssh-rsa ecdsa-sha2-nistp256 ecdsa-sha2-nistp384 ecdsa-sha2-nistp521), algorithms[:host_key]
56
- else
57
- assert_equal %w(ssh-dss ssh-rsa), algorithms[:host_key]
58
- end
59
- end
60
-
61
- def test_constructor_with_unrecognized_host_key_type_should_raise_exception
62
- assert_raises(NotImplementedError) { algorithms(:host_key => "bogus") }
63
- end
64
-
65
- def test_constructor_with_preferred_kex_should_put_preferred_kex_first
66
- if defined?(OpenSSL::PKey::EC)
67
- assert_equal %w(diffie-hellman-group1-sha1 diffie-hellman-group-exchange-sha1 diffie-hellman-group14-sha1 diffie-hellman-group-exchange-sha256 ecdh-sha2-nistp256 ecdh-sha2-nistp384 ecdh-sha2-nistp521), algorithms(:kex => "diffie-hellman-group1-sha1")[:kex]
68
- else
69
- assert_equal %w(diffie-hellman-group1-sha1 diffie-hellman-group-exchange-sha1 diffie-hellman-group14-sha1 diffie-hellman-group-exchange-sha256), algorithms(:kex => "diffie-hellman-group1-sha1")[:kex]
70
- end
71
- end
72
-
73
- def test_constructor_with_unrecognized_kex_should_raise_exception
74
- assert_raises(NotImplementedError) { algorithms(:kex => "bogus") }
75
- end
76
-
77
- def test_constructor_with_preferred_encryption_should_put_preferred_encryption_first
78
- 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]
79
- end
80
-
81
- def test_constructor_with_multiple_preferred_encryption_should_put_all_preferred_encryption_first
82
- 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]
83
- end
84
-
85
- def test_constructor_with_unrecognized_encryption_should_raise_exception
86
- assert_raises(NotImplementedError) { algorithms(:encryption => "bogus") }
87
- end
88
-
89
- def test_constructor_with_preferred_hmac_should_put_preferred_hmac_first
90
- 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]
91
- end
92
-
93
- def test_constructor_with_multiple_preferred_hmac_should_put_all_preferred_hmac_first
94
- 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]
95
- end
96
-
97
- def test_constructor_with_unrecognized_hmac_should_raise_exception
98
- assert_raises(NotImplementedError) { algorithms(:hmac => "bogus") }
99
- end
100
-
101
- def test_constructor_with_preferred_compression_should_put_preferred_compression_first
102
- assert_equal %w(zlib none zlib@openssh.com), algorithms(:compression => "zlib")[:compression]
103
- end
104
-
105
- def test_constructor_with_multiple_preferred_compression_should_put_all_preferred_compression_first
106
- assert_equal %w(zlib@openssh.com zlib none), algorithms(:compression => %w(zlib@openssh.com zlib))[:compression]
107
- end
108
-
109
- def test_constructor_with_general_preferred_compression_should_put_none_last
110
- assert_equal %w(zlib@openssh.com zlib none), algorithms(:compression => true)[:compression]
111
- end
112
-
113
- def test_constructor_with_unrecognized_compression_should_raise_exception
114
- assert_raises(NotImplementedError) { algorithms(:compression => "bogus") }
115
- end
116
-
117
- def test_initial_state_should_be_neither_pending_nor_initialized
118
- assert !algorithms.pending?
119
- assert !algorithms.initialized?
120
- end
121
-
122
- def test_key_exchange_when_initiated_by_server
123
- transport.expect do |t, buffer|
124
- assert_kexinit(buffer)
125
- install_mock_key_exchange(buffer)
126
- end
127
-
128
- install_mock_algorithm_lookups
129
- algorithms.accept_kexinit(kexinit)
130
-
131
- assert_exchange_results
132
- end
133
-
134
- def test_key_exchange_when_initiated_by_client
135
- state = nil
136
- transport.expect do |t, buffer|
137
- assert_kexinit(buffer)
138
- state = :sent_kexinit
139
- install_mock_key_exchange(buffer)
140
- end
141
-
142
- algorithms.rekey!
143
- assert_equal state, :sent_kexinit
144
- assert algorithms.pending?
145
-
146
- install_mock_algorithm_lookups
147
- algorithms.accept_kexinit(kexinit)
148
-
149
- assert_exchange_results
150
- end
151
-
152
- def test_key_exchange_when_server_does_not_support_preferred_kex_should_fallback_to_secondary
153
- kexinit :kex => "diffie-hellman-group1-sha1"
154
- transport.expect do |t,buffer|
155
- assert_kexinit(buffer)
156
- install_mock_key_exchange(buffer, :kex => Net::SSH::Transport::Kex::DiffieHellmanGroup1SHA1)
157
- end
158
- algorithms.accept_kexinit(kexinit)
159
- end
160
-
161
- def test_key_exchange_when_server_does_not_support_any_preferred_kex_should_raise_error
162
- kexinit :kex => "something-obscure"
163
- transport.expect { |t,buffer| assert_kexinit(buffer) }
164
- assert_raises(Net::SSH::Exception) { algorithms.accept_kexinit(kexinit) }
165
- end
166
-
167
- def test_allow_when_not_pending_should_be_true_for_all_packets
168
- (0..255).each do |type|
169
- packet = stub("packet", :type => type)
170
- assert algorithms.allow?(packet), type.to_s
171
- end
172
- end
173
-
174
- def test_allow_when_pending_should_be_true_only_for_packets_valid_during_key_exchange
175
- transport.expect!
176
- algorithms.rekey!
177
- assert algorithms.pending?
178
-
179
- (0..255).each do |type|
180
- packet = stub("packet", :type => type)
181
- case type
182
- when 1..4, 6..19, 21..49 then assert(algorithms.allow?(packet), "#{type} should be allowed during key exchange")
183
- else assert(!algorithms.allow?(packet), "#{type} should not be allowed during key exchange")
184
- end
185
- end
186
- end
187
-
188
- def test_exchange_with_zlib_compression_enabled_sets_compression_to_standard
189
- algorithms :compression => "zlib"
190
-
191
- transport.expect do |t, buffer|
192
- assert_kexinit(buffer, :compression_client => "zlib,none,zlib@openssh.com", :compression_server => "zlib,none,zlib@openssh.com")
193
- install_mock_key_exchange(buffer)
194
- end
195
-
196
- install_mock_algorithm_lookups
197
- algorithms.accept_kexinit(kexinit)
198
-
199
- assert_equal :standard, transport.client_options[:compression]
200
- assert_equal :standard, transport.server_options[:compression]
201
- end
202
-
203
- def test_exchange_with_zlib_at_openssh_dot_com_compression_enabled_sets_compression_to_delayed
204
- algorithms :compression => "zlib@openssh.com"
205
-
206
- transport.expect do |t, buffer|
207
- assert_kexinit(buffer, :compression_client => "zlib@openssh.com,none,zlib", :compression_server => "zlib@openssh.com,none,zlib")
208
- install_mock_key_exchange(buffer)
209
- end
210
-
211
- install_mock_algorithm_lookups
212
- algorithms.accept_kexinit(kexinit)
213
-
214
- assert_equal :delayed, transport.client_options[:compression]
215
- assert_equal :delayed, transport.server_options[:compression]
216
- end
217
-
218
- private
219
-
220
- def install_mock_key_exchange(buffer, options={})
221
- kex = options[:kex] || Net::SSH::Transport::Kex::DiffieHellmanGroupExchangeSHA1
222
-
223
- Net::SSH::Transport::Kex::MAP.each do |name, klass|
224
- next if klass == kex
225
- klass.expects(:new).never
226
- end
227
-
228
- kex.expects(:new).
229
- with(algorithms, transport,
230
- :client_version_string => Net::SSH::Transport::ServerVersion::PROTO_VERSION,
231
- :server_version_string => transport.server_version.version,
232
- :server_algorithm_packet => kexinit.to_s,
233
- :client_algorithm_packet => buffer.to_s,
234
- :need_bytes => 20,
235
- :logger => nil).
236
- returns(stub("kex", :exchange_keys => { :shared_secret => shared_secret, :session_id => session_id, :hashing_algorithm => hashing_algorithm }))
237
- end
238
-
239
- def install_mock_algorithm_lookups(options={})
240
- params = { :shared => shared_secret.to_ssh, :hash => session_id, :digester => hashing_algorithm }
241
- Net::SSH::Transport::CipherFactory.expects(:get).
242
- with(options[:client_cipher] || "aes128-cbc", params.merge(:iv => key("A"), :key => key("C"), :encrypt => true)).
243
- returns(:client_cipher)
244
-
245
- Net::SSH::Transport::CipherFactory.expects(:get).
246
- with(options[:server_cipher] || "aes128-cbc", params.merge(:iv => key("B"), :key => key("D"), :decrypt => true)).
247
- returns(:server_cipher)
248
-
249
- Net::SSH::Transport::HMAC.expects(:get).with(options[:client_hmac] || "hmac-sha1", key("E"), params).returns(:client_hmac)
250
- Net::SSH::Transport::HMAC.expects(:get).with(options[:server_hmac] || "hmac-sha1", key("F"), params).returns(:server_hmac)
251
- end
252
-
253
- def shared_secret
254
- @shared_secret ||= OpenSSL::BN.new("1234567890", 10)
255
- end
256
-
257
- def session_id
258
- @session_id ||= "this is the session id"
259
- end
260
-
261
- def hashing_algorithm
262
- OpenSSL::Digest::SHA1
263
- end
264
-
265
- def key(salt)
266
- hashing_algorithm.digest(shared_secret.to_ssh + session_id + salt + session_id)
267
- end
268
-
269
- def cipher(type, options={})
270
- Net::SSH::Transport::CipherFactory.get(type, options)
271
- end
272
-
273
- def kexinit(options={})
274
- @kexinit ||= P(:byte, KEXINIT,
275
- :long, rand(0xFFFFFFFF), :long, rand(0xFFFFFFFF), :long, rand(0xFFFFFFFF), :long, rand(0xFFFFFFFF),
276
- :string, options[:kex] || "diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1,diffie-hellman-group-exchange-sha256",
277
- :string, options[:host_key] || "ssh-rsa,ssh-dss",
278
- :string, options[:encryption_client] || "aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,rijndael-cbc@lysator.liu.se,idea-cbc",
279
- :string, options[:encryption_server] || "aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,rijndael-cbc@lysator.liu.se,idea-cbc",
280
- :string, options[:hmac_client] || "hmac-sha1,hmac-md5,hmac-sha1-96,hmac-md5-96",
281
- :string, options[:hmac_server] || "hmac-sha1,hmac-md5,hmac-sha1-96,hmac-md5-96",
282
- :string, options[:compmression_client] || "none,zlib@openssh.com,zlib",
283
- :string, options[:compmression_server] || "none,zlib@openssh.com,zlib",
284
- :string, options[:language_client] || "",
285
- :string, options[:langauge_server] || "",
286
- :bool, options[:first_kex_follows])
287
- end
288
-
289
- def assert_kexinit(buffer, options={})
290
- assert_equal KEXINIT, buffer.type
291
- assert_equal 16, buffer.read(16).length
292
- if defined?(OpenSSL::PKey::EC)
293
- assert_equal options[:kex] || "diffie-hellman-group-exchange-sha1,diffie-hellman-group1-sha1,diffie-hellman-group14-sha1,diffie-hellman-group-exchange-sha256,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521", buffer.read_string
294
- assert_equal options[:host_key] || "ssh-rsa,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521", buffer.read_string
295
- else
296
- assert_equal options[:kex] || "diffie-hellman-group-exchange-sha1,diffie-hellman-group1-sha1,diffie-hellman-group14-sha1,diffie-hellman-group-exchange-sha256", buffer.read_string
297
- assert_equal options[:host_key] || "ssh-rsa,ssh-dss", buffer.read_string
298
- end
299
- 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
300
- 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
301
- 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
302
- 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
303
- assert_equal options[:compression_client] || "none,zlib@openssh.com,zlib", buffer.read_string
304
- assert_equal options[:compression_server] || "none,zlib@openssh.com,zlib", buffer.read_string
305
- assert_equal options[:language_client] || "", buffer.read_string
306
- assert_equal options[:language_server] || "", buffer.read_string
307
- assert_equal options[:first_kex_follows] || false, buffer.read_bool
308
- end
309
-
310
- def assert_exchange_results
311
- assert algorithms.initialized?
312
- assert !algorithms.pending?
313
- assert !transport.client_options[:compression]
314
- assert !transport.server_options[:compression]
315
- assert_equal :client_cipher, transport.client_options[:cipher]
316
- assert_equal :server_cipher, transport.server_options[:cipher]
317
- assert_equal :client_hmac, transport.client_options[:hmac]
318
- assert_equal :server_hmac, transport.server_options[:hmac]
319
- end
320
-
321
- def algorithms(options={})
322
- @algorithms ||= Net::SSH::Transport::Algorithms.new(transport, options)
323
- end
324
-
325
- def transport
326
- @transport ||= MockTransport.new
327
- end
328
- end
329
-
330
- end