net-ssh 3.2.0.rc2 → 7.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (204) hide show
  1. checksums.yaml +5 -5
  2. checksums.yaml.gz.sig +2 -2
  3. data/.dockerignore +6 -0
  4. data/.github/config/rubocop_linter_action.yml +4 -0
  5. data/.github/workflows/ci-with-docker.yml +44 -0
  6. data/.github/workflows/ci.yml +87 -0
  7. data/.github/workflows/rubocop.yml +16 -0
  8. data/.gitignore +13 -0
  9. data/.rubocop.yml +22 -0
  10. data/.rubocop_todo.yml +1081 -0
  11. data/CHANGES.txt +228 -7
  12. data/Dockerfile +27 -0
  13. data/Dockerfile.openssl3 +17 -0
  14. data/Gemfile +13 -0
  15. data/Gemfile.noed25519 +12 -0
  16. data/ISSUE_TEMPLATE.md +30 -0
  17. data/Manifest +4 -5
  18. data/README.md +297 -0
  19. data/Rakefile +125 -74
  20. data/SECURITY.md +4 -0
  21. data/appveyor.yml +58 -0
  22. data/docker-compose.yml +23 -0
  23. data/lib/net/ssh/authentication/agent.rb +279 -18
  24. data/lib/net/ssh/authentication/certificate.rb +183 -0
  25. data/lib/net/ssh/authentication/constants.rb +17 -15
  26. data/lib/net/ssh/authentication/ed25519.rb +186 -0
  27. data/lib/net/ssh/authentication/ed25519_loader.rb +31 -0
  28. data/lib/net/ssh/authentication/key_manager.rb +86 -39
  29. data/lib/net/ssh/authentication/methods/abstract.rb +67 -48
  30. data/lib/net/ssh/authentication/methods/hostbased.rb +34 -37
  31. data/lib/net/ssh/authentication/methods/keyboard_interactive.rb +13 -13
  32. data/lib/net/ssh/authentication/methods/none.rb +16 -19
  33. data/lib/net/ssh/authentication/methods/password.rb +27 -17
  34. data/lib/net/ssh/authentication/methods/publickey.rb +96 -55
  35. data/lib/net/ssh/authentication/pageant.rb +471 -367
  36. data/lib/net/ssh/authentication/pub_key_fingerprint.rb +43 -0
  37. data/lib/net/ssh/authentication/session.rb +131 -121
  38. data/lib/net/ssh/buffer.rb +399 -300
  39. data/lib/net/ssh/buffered_io.rb +154 -150
  40. data/lib/net/ssh/config.rb +308 -185
  41. data/lib/net/ssh/connection/channel.rb +635 -613
  42. data/lib/net/ssh/connection/constants.rb +29 -29
  43. data/lib/net/ssh/connection/event_loop.rb +123 -0
  44. data/lib/net/ssh/connection/keepalive.rb +55 -51
  45. data/lib/net/ssh/connection/session.rb +620 -551
  46. data/lib/net/ssh/connection/term.rb +125 -123
  47. data/lib/net/ssh/errors.rb +101 -99
  48. data/lib/net/ssh/key_factory.rb +197 -105
  49. data/lib/net/ssh/known_hosts.rb +214 -127
  50. data/lib/net/ssh/loggable.rb +50 -49
  51. data/lib/net/ssh/packet.rb +83 -79
  52. data/lib/net/ssh/prompt.rb +50 -81
  53. data/lib/net/ssh/proxy/command.rb +105 -90
  54. data/lib/net/ssh/proxy/errors.rb +12 -10
  55. data/lib/net/ssh/proxy/http.rb +82 -79
  56. data/lib/net/ssh/proxy/https.rb +50 -0
  57. data/lib/net/ssh/proxy/jump.rb +54 -0
  58. data/lib/net/ssh/proxy/socks4.rb +2 -6
  59. data/lib/net/ssh/proxy/socks5.rb +14 -17
  60. data/lib/net/ssh/service/forward.rb +370 -317
  61. data/lib/net/ssh/test/channel.rb +145 -136
  62. data/lib/net/ssh/test/extensions.rb +131 -110
  63. data/lib/net/ssh/test/kex.rb +34 -32
  64. data/lib/net/ssh/test/local_packet.rb +46 -44
  65. data/lib/net/ssh/test/packet.rb +89 -70
  66. data/lib/net/ssh/test/remote_packet.rb +32 -30
  67. data/lib/net/ssh/test/script.rb +156 -142
  68. data/lib/net/ssh/test/socket.rb +49 -48
  69. data/lib/net/ssh/test.rb +82 -77
  70. data/lib/net/ssh/transport/algorithms.rb +441 -360
  71. data/lib/net/ssh/transport/cipher_factory.rb +96 -98
  72. data/lib/net/ssh/transport/constants.rb +32 -24
  73. data/lib/net/ssh/transport/ctr.rb +42 -22
  74. data/lib/net/ssh/transport/hmac/abstract.rb +81 -63
  75. data/lib/net/ssh/transport/hmac/md5.rb +0 -2
  76. data/lib/net/ssh/transport/hmac/md5_96.rb +0 -2
  77. data/lib/net/ssh/transport/hmac/none.rb +0 -2
  78. data/lib/net/ssh/transport/hmac/ripemd160.rb +0 -2
  79. data/lib/net/ssh/transport/hmac/sha1.rb +0 -2
  80. data/lib/net/ssh/transport/hmac/sha1_96.rb +0 -2
  81. data/lib/net/ssh/transport/hmac/sha2_256.rb +7 -11
  82. data/lib/net/ssh/transport/hmac/sha2_256_96.rb +4 -8
  83. data/lib/net/ssh/transport/hmac/sha2_256_etm.rb +12 -0
  84. data/lib/net/ssh/transport/hmac/sha2_512.rb +6 -9
  85. data/lib/net/ssh/transport/hmac/sha2_512_96.rb +4 -8
  86. data/lib/net/ssh/transport/hmac/sha2_512_etm.rb +12 -0
  87. data/lib/net/ssh/transport/hmac.rb +14 -12
  88. data/lib/net/ssh/transport/identity_cipher.rb +54 -52
  89. data/lib/net/ssh/transport/kex/abstract.rb +130 -0
  90. data/lib/net/ssh/transport/kex/abstract5656.rb +72 -0
  91. data/lib/net/ssh/transport/kex/curve25519_sha256.rb +39 -0
  92. data/lib/net/ssh/transport/kex/curve25519_sha256_loader.rb +30 -0
  93. data/lib/net/ssh/transport/kex/diffie_hellman_group14_sha1.rb +33 -40
  94. data/lib/net/ssh/transport/kex/diffie_hellman_group14_sha256.rb +11 -0
  95. data/lib/net/ssh/transport/kex/diffie_hellman_group1_sha1.rb +119 -213
  96. data/lib/net/ssh/transport/kex/diffie_hellman_group_exchange_sha1.rb +53 -61
  97. data/lib/net/ssh/transport/kex/diffie_hellman_group_exchange_sha256.rb +5 -9
  98. data/lib/net/ssh/transport/kex/ecdh_sha2_nistp256.rb +36 -90
  99. data/lib/net/ssh/transport/kex/ecdh_sha2_nistp384.rb +18 -10
  100. data/lib/net/ssh/transport/kex/ecdh_sha2_nistp521.rb +18 -10
  101. data/lib/net/ssh/transport/kex.rb +15 -12
  102. data/lib/net/ssh/transport/key_expander.rb +24 -20
  103. data/lib/net/ssh/transport/openssl.rb +161 -124
  104. data/lib/net/ssh/transport/packet_stream.rb +225 -185
  105. data/lib/net/ssh/transport/server_version.rb +55 -56
  106. data/lib/net/ssh/transport/session.rb +306 -255
  107. data/lib/net/ssh/transport/state.rb +178 -176
  108. data/lib/net/ssh/verifiers/accept_new.rb +33 -0
  109. data/lib/net/ssh/verifiers/accept_new_or_local_tunnel.rb +33 -0
  110. data/lib/net/ssh/verifiers/always.rb +58 -0
  111. data/lib/net/ssh/verifiers/never.rb +19 -0
  112. data/lib/net/ssh/version.rb +55 -53
  113. data/lib/net/ssh.rb +110 -47
  114. data/net-ssh-public_cert.pem +18 -18
  115. data/net-ssh.gemspec +36 -205
  116. data/support/ssh_tunnel_bug.rb +5 -5
  117. data.tar.gz.sig +0 -0
  118. metadata +153 -118
  119. metadata.gz.sig +0 -0
  120. data/.travis.yml +0 -18
  121. data/README.rdoc +0 -182
  122. data/lib/net/ssh/authentication/agent/java_pageant.rb +0 -85
  123. data/lib/net/ssh/authentication/agent/socket.rb +0 -178
  124. data/lib/net/ssh/ruby_compat.rb +0 -46
  125. data/lib/net/ssh/verifiers/lenient.rb +0 -30
  126. data/lib/net/ssh/verifiers/null.rb +0 -12
  127. data/lib/net/ssh/verifiers/secure.rb +0 -52
  128. data/lib/net/ssh/verifiers/strict.rb +0 -24
  129. data/setup.rb +0 -1585
  130. data/support/arcfour_check.rb +0 -20
  131. data/test/README.txt +0 -18
  132. data/test/authentication/methods/common.rb +0 -28
  133. data/test/authentication/methods/test_abstract.rb +0 -51
  134. data/test/authentication/methods/test_hostbased.rb +0 -114
  135. data/test/authentication/methods/test_keyboard_interactive.rb +0 -121
  136. data/test/authentication/methods/test_none.rb +0 -41
  137. data/test/authentication/methods/test_password.rb +0 -95
  138. data/test/authentication/methods/test_publickey.rb +0 -148
  139. data/test/authentication/test_agent.rb +0 -232
  140. data/test/authentication/test_key_manager.rb +0 -240
  141. data/test/authentication/test_session.rb +0 -107
  142. data/test/common.rb +0 -125
  143. data/test/configs/auth_off +0 -5
  144. data/test/configs/auth_on +0 -4
  145. data/test/configs/empty +0 -0
  146. data/test/configs/eqsign +0 -3
  147. data/test/configs/exact_match +0 -8
  148. data/test/configs/host_plus +0 -10
  149. data/test/configs/multihost +0 -4
  150. data/test/configs/negative_match +0 -6
  151. data/test/configs/nohost +0 -19
  152. data/test/configs/numeric_host +0 -4
  153. data/test/configs/proxy_remote_user +0 -2
  154. data/test/configs/send_env +0 -2
  155. data/test/configs/substitutes +0 -8
  156. data/test/configs/wild_cards +0 -14
  157. data/test/connection/test_channel.rb +0 -487
  158. data/test/connection/test_session.rb +0 -564
  159. data/test/integration/README.txt +0 -17
  160. data/test/integration/Vagrantfile +0 -12
  161. data/test/integration/common.rb +0 -63
  162. data/test/integration/playbook.yml +0 -56
  163. data/test/integration/test_forward.rb +0 -637
  164. data/test/integration/test_id_rsa_keys.rb +0 -96
  165. data/test/integration/test_proxy.rb +0 -93
  166. data/test/known_hosts/github +0 -1
  167. data/test/known_hosts/github_hash +0 -1
  168. data/test/manual/test_pageant.rb +0 -37
  169. data/test/start/test_connection.rb +0 -53
  170. data/test/start/test_options.rb +0 -57
  171. data/test/start/test_transport.rb +0 -28
  172. data/test/start/test_user_nil.rb +0 -27
  173. data/test/test_all.rb +0 -12
  174. data/test/test_buffer.rb +0 -433
  175. data/test/test_buffered_io.rb +0 -63
  176. data/test/test_config.rb +0 -268
  177. data/test/test_key_factory.rb +0 -191
  178. data/test/test_known_hosts.rb +0 -66
  179. data/test/transport/hmac/test_md5.rb +0 -41
  180. data/test/transport/hmac/test_md5_96.rb +0 -27
  181. data/test/transport/hmac/test_none.rb +0 -34
  182. data/test/transport/hmac/test_ripemd160.rb +0 -36
  183. data/test/transport/hmac/test_sha1.rb +0 -36
  184. data/test/transport/hmac/test_sha1_96.rb +0 -27
  185. data/test/transport/hmac/test_sha2_256.rb +0 -37
  186. data/test/transport/hmac/test_sha2_256_96.rb +0 -27
  187. data/test/transport/hmac/test_sha2_512.rb +0 -37
  188. data/test/transport/hmac/test_sha2_512_96.rb +0 -27
  189. data/test/transport/kex/test_diffie_hellman_group14_sha1.rb +0 -13
  190. data/test/transport/kex/test_diffie_hellman_group1_sha1.rb +0 -150
  191. data/test/transport/kex/test_diffie_hellman_group_exchange_sha1.rb +0 -96
  192. data/test/transport/kex/test_diffie_hellman_group_exchange_sha256.rb +0 -19
  193. data/test/transport/kex/test_ecdh_sha2_nistp256.rb +0 -161
  194. data/test/transport/kex/test_ecdh_sha2_nistp384.rb +0 -38
  195. data/test/transport/kex/test_ecdh_sha2_nistp521.rb +0 -38
  196. data/test/transport/test_algorithms.rb +0 -328
  197. data/test/transport/test_cipher_factory.rb +0 -443
  198. data/test/transport/test_hmac.rb +0 -34
  199. data/test/transport/test_identity_cipher.rb +0 -40
  200. data/test/transport/test_packet_stream.rb +0 -1762
  201. data/test/transport/test_server_version.rb +0 -74
  202. data/test/transport/test_session.rb +0 -331
  203. data/test/transport/test_state.rb +0 -181
  204. data/test/verifiers/test_secure.rb +0 -40
@@ -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
@@ -1,27 +0,0 @@
1
- # encoding: ASCII-8BIT
2
-
3
- require 'common'
4
- require 'transport/hmac/test_sha2_256'
5
- require 'net/ssh/transport/hmac/sha2_256_96'
6
-
7
- module Transport; module HMAC
8
-
9
- class TestSHA2_256_96 < TestSHA2_256
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 "\x16^>\x9FhO}\xB1>(\xBAF", hmac.digest("hello world")
18
- end
19
-
20
- private
21
-
22
- def subject
23
- Net::SSH::Transport::HMAC::SHA2_256_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_512'
5
-
6
- module Transport; module HMAC
7
-
8
- class TestSHA2_512 < Test::Unit::TestCase
9
- def test_expected_digest_class
10
- assert_equal OpenSSL::Digest::SHA512, subject.digest_class
11
- assert_equal OpenSSL::Digest::SHA512, subject.new.digest_class
12
- end
13
-
14
- def test_expected_key_length
15
- assert_equal 64, subject.key_length
16
- assert_equal 64, subject.new.key_length
17
- end
18
-
19
- def test_expected_mac_length
20
- assert_equal 64, subject.mac_length
21
- assert_equal 64, subject.new.mac_length
22
- end
23
-
24
- def test_expected_digest
25
- hmac = subject.new("1234567890123456")
26
- assert_equal "^\xB6\"\xED\x8B\xC4\xDE\xD4\xCF\xD0\r\x18\xA0<\xF4\xB5\x01Efz\xA80i\xFC\x18\xC1\x9A+\xDD\xFE<\xA2\xFDE1Ac\xF4\xADU\r\xFB^0\x90= \x837z\xCC\xD5p4a4\x83\xC6\x04m\xAA\xC1\xC0m", hmac.digest("hello world")
27
-
28
- end
29
-
30
- private
31
-
32
- def subject
33
- Net::SSH::Transport::HMAC::SHA2_512
34
- end
35
- end
36
-
37
- end; end
@@ -1,27 +0,0 @@
1
- # encoding: ASCII-8BIT
2
-
3
- require 'common'
4
- require 'transport/hmac/test_sha2_512'
5
- require 'net/ssh/transport/hmac/sha2_512_96'
6
-
7
- module Transport; module HMAC
8
-
9
- class TestSHA2_512_96 < TestSHA2_512
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 "^\xB6\"\xED\x8B\xC4\xDE\xD4\xCF\xD0\r\x18", hmac.digest("hello world")
18
- end
19
-
20
- private
21
-
22
- def subject
23
- Net::SSH::Transport::HMAC::SHA2_512_96
24
- end
25
- end
26
-
27
- end; end
@@ -1,13 +0,0 @@
1
- require 'common'
2
- require 'net/ssh/transport/kex/diffie_hellman_group14_sha1'
3
- require 'transport/kex/test_diffie_hellman_group1_sha1'
4
- require 'ostruct'
5
-
6
- module Transport; module Kex
7
-
8
- class TestDiffieHellmanGroup14SHA1 < TestDiffieHellmanGroup1SHA1
9
- def subject
10
- Net::SSH::Transport::Kex::DiffieHellmanGroup14SHA1
11
- end
12
- end
13
- end; end
@@ -1,150 +0,0 @@
1
- require 'common'
2
- require 'net/ssh/transport/kex/diffie_hellman_group1_sha1'
3
- require 'ostruct'
4
-
5
- module Transport; module Kex
6
-
7
- class TestDiffieHellmanGroup1SHA1 < Test::Unit::TestCase
8
- include Net::SSH::Transport::Constants
9
-
10
- def setup
11
- @dh_options = @dh = @algorithms = @connection = @server_key =
12
- @packet_data = @shared_secret = nil
13
- end
14
-
15
- def digest_type
16
- OpenSSL::Digest::SHA1
17
- end
18
-
19
- def test_exchange_keys_should_return_expected_results_when_successful
20
- result = exchange!
21
- assert_equal session_id, result[:session_id]
22
- assert_equal server_key.to_blob, result[:server_key].to_blob
23
- assert_equal shared_secret, result[:shared_secret]
24
- assert_equal digest_type, result[:hashing_algorithm]
25
- end
26
-
27
- def test_exchange_keys_with_unverifiable_host_should_raise_exception
28
- connection.verifier { false }
29
- assert_raises(Net::SSH::Exception) { exchange! }
30
- end
31
-
32
- def test_exchange_keys_with_signature_key_type_mismatch_should_raise_exception
33
- assert_raises(Net::SSH::Exception) { exchange! :key_type => "ssh-dss" }
34
- end
35
-
36
- def test_exchange_keys_with_host_key_type_mismatch_should_raise_exception
37
- algorithms :host_key => "ssh-dss"
38
- assert_raises(Net::SSH::Exception) { exchange! :key_type => "ssh-dss" }
39
- end
40
-
41
- def test_exchange_keys_when_server_signature_could_not_be_verified_should_raise_exception
42
- @signature = "1234567890"
43
- assert_raises(Net::SSH::Exception) { exchange! }
44
- end
45
-
46
- def test_exchange_keys_should_pass_expected_parameters_to_host_key_verifier
47
- verified = false
48
- connection.verifier do |data|
49
- verified = true
50
- assert_equal server_key.to_blob, data[:key].to_blob
51
-
52
- blob = b(:key, data[:key]).to_s
53
- fingerprint = OpenSSL::Digest::MD5.hexdigest(blob).scan(/../).join(":")
54
-
55
- assert_equal blob, data[:key_blob]
56
- assert_equal fingerprint, data[:fingerprint]
57
- assert_equal connection, data[:session]
58
-
59
- true
60
- end
61
-
62
- assert_nothing_raised { exchange! }
63
- assert verified
64
- end
65
-
66
- private
67
-
68
- def exchange!(options={})
69
- connection.expect do |t, buffer|
70
- assert_equal KEXDH_INIT, buffer.type
71
- assert_equal dh.dh.pub_key, buffer.read_bignum
72
- t.return(KEXDH_REPLY, :string, b(:key, server_key), :bignum, server_dh_pubkey, :string, b(:string, options[:key_type] || "ssh-rsa", :string, signature))
73
- connection.expect do |t2, buffer2|
74
- assert_equal NEWKEYS, buffer2.type
75
- t2.return(NEWKEYS)
76
- end
77
- end
78
-
79
- dh.exchange_keys
80
- end
81
-
82
- def dh_options(options={})
83
- @dh_options = options
84
- end
85
-
86
- def dh
87
- @dh ||= subject.new(algorithms, connection, packet_data.merge(:need_bytes => 20).merge(@dh_options || {}))
88
- end
89
-
90
- def algorithms(options={})
91
- @algorithms ||= OpenStruct.new(:host_key => options[:host_key] || "ssh-rsa")
92
- end
93
-
94
- def connection
95
- @connection ||= MockTransport.new
96
- end
97
-
98
- def subject
99
- Net::SSH::Transport::Kex::DiffieHellmanGroup1SHA1
100
- end
101
-
102
- # 512 bits is the smallest possible key that will work with this, so
103
- # we use it for speed reasons
104
- def server_key(bits=512)
105
- @server_key ||= OpenSSL::PKey::RSA.new(bits)
106
- end
107
-
108
- def packet_data
109
- @packet_data ||= { :client_version_string => "client version string",
110
- :server_version_string => "server version string",
111
- :server_algorithm_packet => "server algorithm packet",
112
- :client_algorithm_packet => "client algorithm packet" }
113
- end
114
-
115
- def server_dh_pubkey
116
- @server_dh_pubkey ||= bn(1234567890)
117
- end
118
-
119
- def shared_secret
120
- @shared_secret ||= OpenSSL::BN.new(dh.dh.compute_key(server_dh_pubkey), 2)
121
- end
122
-
123
- def session_id
124
- @session_id ||= begin
125
- buffer = Net::SSH::Buffer.from(:string, packet_data[:client_version_string],
126
- :string, packet_data[:server_version_string],
127
- :string, packet_data[:client_algorithm_packet],
128
- :string, packet_data[:server_algorithm_packet],
129
- :string, Net::SSH::Buffer.from(:key, server_key),
130
- :bignum, dh.dh.pub_key,
131
- :bignum, server_dh_pubkey,
132
- :bignum, shared_secret)
133
- OpenSSL::Digest::SHA1.digest(buffer.to_s)
134
- end
135
- end
136
-
137
- def signature
138
- @signature ||= server_key.ssh_do_sign(session_id)
139
- end
140
-
141
- def bn(number, base=10)
142
- OpenSSL::BN.new(number.to_s, base)
143
- end
144
-
145
- def b(*args)
146
- Net::SSH::Buffer.from(*args)
147
- end
148
- end
149
-
150
- end; end
@@ -1,96 +0,0 @@
1
- require 'common'
2
- require 'transport/kex/test_diffie_hellman_group1_sha1'
3
- require 'net/ssh/transport/kex/diffie_hellman_group_exchange_sha1'
4
-
5
- module Transport; module Kex
6
-
7
- class TestDiffieHellmanGroupExchangeSHA1 < TestDiffieHellmanGroup1SHA1
8
- KEXDH_GEX_GROUP = 31
9
- KEXDH_GEX_INIT = 32
10
- KEXDH_GEX_REPLY = 33
11
- KEXDH_GEX_REQUEST = 34
12
-
13
- def test_exchange_with_fewer_than_minimum_bits_uses_minimum_bits
14
- dh_options :need_bytes => 20
15
- assert_equal 1024, need_bits
16
- assert_nothing_raised { exchange! }
17
- end
18
-
19
- def test_exchange_with_fewer_than_maximum_bits_uses_need_bits
20
- dh_options :need_bytes => 500
21
- need_bits(8001)
22
- assert_nothing_raised { exchange! }
23
- end
24
-
25
- def test_exchange_with_more_than_maximum_bits_uses_maximum_bits
26
- dh_options :need_bytes => 2000
27
- need_bits(8192)
28
- assert_nothing_raised { exchange! }
29
- end
30
-
31
- def test_that_p_and_g_are_provided_by_the_server
32
- assert_nothing_raised { exchange! :p => default_p+2, :g => 3 }
33
- assert_equal default_p+2, dh.dh.p
34
- assert_equal 3, dh.dh.g
35
- end
36
-
37
- private
38
-
39
- def need_bits(bits=1024)
40
- @need_bits ||= bits
41
- end
42
-
43
- def default_p
44
- 142326151570335518660743995281621698377057354949884468943021767573608899048361360422513557553514790045512299468953431585300812548859419857171094366358158903433167915517332113861059747425408670144201099811846875730766487278261498262568348338476437200556998366087779709990807518291581860338635288400119315130179
45
- end
46
-
47
- def exchange!(options={})
48
- connection.expect do |t, buffer|
49
- assert_equal KEXDH_GEX_REQUEST, buffer.type
50
- assert_equal 1024, buffer.read_long
51
- assert_equal need_bits, buffer.read_long
52
- assert_equal 8192, buffer.read_long
53
- t.return(KEXDH_GEX_GROUP, :bignum, bn(options[:p] || default_p), :bignum, bn(options[:g] || 2))
54
- t.expect do |t2, buffer2|
55
- assert_equal KEXDH_GEX_INIT, buffer2.type
56
- assert_equal dh.dh.pub_key, buffer2.read_bignum
57
- t2.return(KEXDH_GEX_REPLY, :string, b(:key, server_key), :bignum, server_dh_pubkey, :string, b(:string, options[:key_type] || "ssh-rsa", :string, signature))
58
- t2.expect do |t3, buffer3|
59
- assert_equal NEWKEYS, buffer3.type
60
- t3.return(NEWKEYS)
61
- end
62
- end
63
- end
64
-
65
- dh.exchange_keys
66
- end
67
-
68
- def subject
69
- Net::SSH::Transport::Kex::DiffieHellmanGroupExchangeSHA1
70
- end
71
-
72
- def digest_type
73
- OpenSSL::Digest::SHA1
74
- end
75
-
76
- def session_id
77
- @session_id ||= begin
78
- buffer = Net::SSH::Buffer.from(:string, packet_data[:client_version_string],
79
- :string, packet_data[:server_version_string],
80
- :string, packet_data[:client_algorithm_packet],
81
- :string, packet_data[:server_algorithm_packet],
82
- :string, Net::SSH::Buffer.from(:key, server_key),
83
- :long, 1024,
84
- :long, need_bits, # need bits, figure this part out,
85
- :long, 8192,
86
- :bignum, dh.dh.p,
87
- :bignum, dh.dh.g,
88
- :bignum, dh.dh.pub_key,
89
- :bignum, server_dh_pubkey,
90
- :bignum, shared_secret)
91
- digest_type.digest(buffer.to_s)
92
- end
93
- end
94
- end
95
-
96
- end; end
@@ -1,19 +0,0 @@
1
- require 'common'
2
- require 'net/ssh/transport/kex/diffie_hellman_group_exchange_sha1'
3
- require 'transport/kex/test_diffie_hellman_group_exchange_sha1'
4
-
5
- module Transport; module Kex
6
-
7
- class TestDiffieHellmanGroupExchangeSHA256 < TestDiffieHellmanGroupExchangeSHA1
8
- private
9
-
10
- def subject
11
- Net::SSH::Transport::Kex::DiffieHellmanGroupExchangeSHA256
12
- end
13
-
14
- def digest_type
15
- OpenSSL::Digest::SHA256
16
- end
17
- end
18
-
19
- end; end
@@ -1,161 +0,0 @@
1
- require 'openssl'
2
-
3
- unless defined?(OpenSSL::PKey::EC)
4
- puts "Skipping tests for ecdh-sha2-nistp256 key exchange"
5
- else
6
- require 'common'
7
- require 'transport/kex/test_diffie_hellman_group1_sha1'
8
- require 'net/ssh/transport/kex/ecdh_sha2_nistp256'
9
- require 'ostruct'
10
-
11
- module Transport; module Kex
12
-
13
- class TestEcdhSHA2NistP256 < Test::Unit::TestCase
14
- include Net::SSH::Transport::Constants
15
-
16
- def setup
17
- @ecdh = @algorithms = @connection = @server_key =
18
- @packet_data = @shared_secret = nil
19
- end
20
-
21
- def test_exchange_keys_should_return_expected_results_when_successful
22
- result = exchange!
23
- assert_equal session_id, result[:session_id]
24
- assert_equal server_host_key.to_blob, result[:server_key].to_blob
25
- assert_equal shared_secret, result[:shared_secret]
26
- assert_equal digester, result[:hashing_algorithm]
27
- end
28
-
29
- def test_exchange_keys_with_unverifiable_host_should_raise_exception
30
- connection.verifier { false }
31
- assert_raises(Net::SSH::Exception) { exchange! }
32
- end
33
-
34
- def test_exchange_keys_with_signature_key_type_mismatch_should_raise_exception
35
- assert_raises(Net::SSH::Exception) { exchange! :key_type => "ssh-dss" }
36
- end
37
-
38
- def test_exchange_keys_with_host_key_type_mismatch_should_raise_exception
39
- algorithms :host_key => "ssh-dss"
40
- assert_raises(Net::SSH::Exception) { exchange! :key_type => "ssh-dss" }
41
- end
42
-
43
- def test_exchange_keys_when_server_signature_could_not_be_verified_should_raise_exception
44
- @signature = "1234567890"
45
- assert_raises(Net::SSH::Exception) { exchange! }
46
- end
47
-
48
- def test_exchange_keys_should_pass_expected_parameters_to_host_key_verifier
49
- verified = false
50
- connection.verifier do |data|
51
- verified = true
52
- assert_equal server_host_key.to_blob, data[:key].to_blob
53
-
54
- blob = b(:key, data[:key]).to_s
55
- fingerprint = OpenSSL::Digest::MD5.hexdigest(blob).scan(/../).join(":")
56
-
57
- assert_equal blob, data[:key_blob]
58
- assert_equal fingerprint, data[:fingerprint]
59
- assert_equal connection, data[:session]
60
-
61
- true
62
- end
63
-
64
- assert_nothing_raised { exchange! }
65
- assert verified
66
- end
67
-
68
- private
69
-
70
- def digester
71
- OpenSSL::Digest::SHA256
72
- end
73
-
74
- def subject
75
- Net::SSH::Transport::Kex::EcdhSHA2NistP256
76
- end
77
-
78
- def ecparam
79
- "prime256v1"
80
- end
81
-
82
- def key_type
83
- "ecdsa-sha2-nistp256"
84
- end
85
-
86
- def exchange!(options={})
87
- connection.expect do |t, buffer|
88
- assert_equal KEXECDH_INIT, buffer.type
89
- assert_equal ecdh.ecdh.public_key.to_bn.to_s(2), buffer.read_string
90
- t.return(KEXECDH_REPLY,
91
- :string, b(:key, server_host_key),
92
- :string, server_ecdh_pubkey.to_bn.to_s(2),
93
- :string, b(:string, options[:key_type] || key_type,
94
- :string, signature))
95
- connection.expect do |t2, buffer2|
96
- assert_equal NEWKEYS, buffer2.type
97
- t2.return(NEWKEYS)
98
- end
99
- end
100
- ecdh.exchange_keys
101
- end
102
-
103
- def ecdh
104
- @ecdh ||= subject.new(algorithms, connection, packet_data)
105
- end
106
-
107
- def algorithms(options={})
108
- @algorithms ||= OpenStruct.new(:host_key => options[:server_host_key] || "ecdsa-sha2-nistp256")
109
- end
110
-
111
- def connection
112
- @connection ||= MockTransport.new
113
- end
114
-
115
- def server_key
116
- @server_key ||= OpenSSL::PKey::EC.new(ecparam).generate_key
117
- end
118
-
119
- def server_host_key
120
- @server_host_key ||= OpenSSL::PKey::EC.new("prime256v1").generate_key
121
- end
122
-
123
- def packet_data
124
- @packet_data ||= { :client_version_string => "client version string",
125
- :server_version_string => "server version string",
126
- :server_algorithm_packet => "server algorithm packet",
127
- :client_algorithm_packet => "client algorithm packet" }
128
- end
129
-
130
- def server_ecdh_pubkey
131
- @server_ecdh_pubkey ||= server_key.public_key
132
- end
133
-
134
- def shared_secret
135
- @shared_secret ||= OpenSSL::BN.new(ecdh.ecdh.dh_compute_key(server_ecdh_pubkey), 2)
136
- end
137
-
138
- def session_id
139
- @session_id ||= begin
140
- buffer = Net::SSH::Buffer.from(:string, packet_data[:client_version_string],
141
- :string, packet_data[:server_version_string],
142
- :string, packet_data[:client_algorithm_packet],
143
- :string, packet_data[:server_algorithm_packet],
144
- :string, Net::SSH::Buffer.from(:key, server_host_key),
145
- :string, ecdh.ecdh.public_key.to_bn.to_s(2),
146
- :string, server_ecdh_pubkey.to_bn.to_s(2),
147
- :bignum, shared_secret)
148
- digester.digest(buffer.to_s)
149
- end
150
- end
151
-
152
- def signature
153
- @signature ||= server_host_key.ssh_do_sign(session_id)
154
- end
155
-
156
- def b(*args)
157
- Net::SSH::Buffer.from(*args)
158
- end
159
- end
160
- end; end;
161
- end
@@ -1,38 +0,0 @@
1
- require 'openssl'
2
-
3
- unless defined?(OpenSSL::PKey::EC)
4
- puts "Skipping tests for ecdh-sha2-nistp384 key exchange"
5
- else
6
- require 'transport/kex/test_ecdh_sha2_nistp256'
7
- module Transport; module Kex
8
- class TestEcdhSHA2NistP384 < TestEcdhSHA2NistP256
9
-
10
- def setup
11
- @ecdh = @algorithms = @connection = @server_key =
12
- @packet_data = @shared_secret = nil
13
- end
14
-
15
- def test_exchange_keys_should_return_expected_results_when_successful
16
- result = exchange!
17
- assert_equal session_id, result[:session_id]
18
- assert_equal server_host_key.to_blob, result[:server_key].to_blob
19
- assert_equal shared_secret, result[:shared_secret]
20
- assert_equal digester, result[:hashing_algorithm]
21
- end
22
-
23
- private
24
-
25
- def digester
26
- OpenSSL::Digest::SHA384
27
- end
28
-
29
- def subject
30
- Net::SSH::Transport::Kex::EcdhSHA2NistP384
31
- end
32
-
33
- def ecparam
34
- "secp384r1"
35
- end
36
- end
37
- end; end
38
- end