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,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,146 +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 test_exchange_keys_should_return_expected_results_when_successful
16
- result = exchange!
17
- assert_equal session_id, result[:session_id]
18
- assert_equal server_key.to_blob, result[:server_key].to_blob
19
- assert_equal shared_secret, result[:shared_secret]
20
- assert_equal OpenSSL::Digest::SHA1, result[:hashing_algorithm]
21
- end
22
-
23
- def test_exchange_keys_with_unverifiable_host_should_raise_exception
24
- connection.verifier { false }
25
- assert_raises(Net::SSH::Exception) { exchange! }
26
- end
27
-
28
- def test_exchange_keys_with_signature_key_type_mismatch_should_raise_exception
29
- assert_raises(Net::SSH::Exception) { exchange! :key_type => "ssh-dss" }
30
- end
31
-
32
- def test_exchange_keys_with_host_key_type_mismatch_should_raise_exception
33
- algorithms :host_key => "ssh-dss"
34
- assert_raises(Net::SSH::Exception) { exchange! :key_type => "ssh-dss" }
35
- end
36
-
37
- def test_exchange_keys_when_server_signature_could_not_be_verified_should_raise_exception
38
- @signature = "1234567890"
39
- assert_raises(Net::SSH::Exception) { exchange! }
40
- end
41
-
42
- def test_exchange_keys_should_pass_expected_parameters_to_host_key_verifier
43
- verified = false
44
- connection.verifier do |data|
45
- verified = true
46
- assert_equal server_key.to_blob, data[:key].to_blob
47
-
48
- blob = b(:key, data[:key]).to_s
49
- fingerprint = OpenSSL::Digest::MD5.hexdigest(blob).scan(/../).join(":")
50
-
51
- assert_equal blob, data[:key_blob]
52
- assert_equal fingerprint, data[:fingerprint]
53
- assert_equal connection, data[:session]
54
-
55
- true
56
- end
57
-
58
- assert_nothing_raised { exchange! }
59
- assert verified
60
- end
61
-
62
- private
63
-
64
- def exchange!(options={})
65
- connection.expect do |t, buffer|
66
- assert_equal KEXDH_INIT, buffer.type
67
- assert_equal dh.dh.pub_key, buffer.read_bignum
68
- t.return(KEXDH_REPLY, :string, b(:key, server_key), :bignum, server_dh_pubkey, :string, b(:string, options[:key_type] || "ssh-rsa", :string, signature))
69
- connection.expect do |t2, buffer2|
70
- assert_equal NEWKEYS, buffer2.type
71
- t2.return(NEWKEYS)
72
- end
73
- end
74
-
75
- dh.exchange_keys
76
- end
77
-
78
- def dh_options(options={})
79
- @dh_options = options
80
- end
81
-
82
- def dh
83
- @dh ||= subject.new(algorithms, connection, packet_data.merge(:need_bytes => 20).merge(@dh_options || {}))
84
- end
85
-
86
- def algorithms(options={})
87
- @algorithms ||= OpenStruct.new(:host_key => options[:host_key] || "ssh-rsa")
88
- end
89
-
90
- def connection
91
- @connection ||= MockTransport.new
92
- end
93
-
94
- def subject
95
- Net::SSH::Transport::Kex::DiffieHellmanGroup1SHA1
96
- end
97
-
98
- # 512 bits is the smallest possible key that will work with this, so
99
- # we use it for speed reasons
100
- def server_key(bits=512)
101
- @server_key ||= OpenSSL::PKey::RSA.new(bits)
102
- end
103
-
104
- def packet_data
105
- @packet_data ||= { :client_version_string => "client version string",
106
- :server_version_string => "server version string",
107
- :server_algorithm_packet => "server algorithm packet",
108
- :client_algorithm_packet => "client algorithm packet" }
109
- end
110
-
111
- def server_dh_pubkey
112
- @server_dh_pubkey ||= bn(1234567890)
113
- end
114
-
115
- def shared_secret
116
- @shared_secret ||= OpenSSL::BN.new(dh.dh.compute_key(server_dh_pubkey), 2)
117
- end
118
-
119
- def session_id
120
- @session_id ||= begin
121
- buffer = Net::SSH::Buffer.from(:string, packet_data[:client_version_string],
122
- :string, packet_data[:server_version_string],
123
- :string, packet_data[:client_algorithm_packet],
124
- :string, packet_data[:server_algorithm_packet],
125
- :string, Net::SSH::Buffer.from(:key, server_key),
126
- :bignum, dh.dh.pub_key,
127
- :bignum, server_dh_pubkey,
128
- :bignum, shared_secret)
129
- OpenSSL::Digest::SHA1.digest(buffer.to_s)
130
- end
131
- end
132
-
133
- def signature
134
- @signature ||= server_key.ssh_do_sign(session_id)
135
- end
136
-
137
- def bn(number, base=10)
138
- OpenSSL::BN.new(number.to_s, base)
139
- end
140
-
141
- def b(*args)
142
- Net::SSH::Buffer.from(*args)
143
- end
144
- end
145
-
146
- end; end
@@ -1,92 +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 session_id
73
- @session_id ||= begin
74
- buffer = Net::SSH::Buffer.from(:string, packet_data[:client_version_string],
75
- :string, packet_data[:server_version_string],
76
- :string, packet_data[:client_algorithm_packet],
77
- :string, packet_data[:server_algorithm_packet],
78
- :string, Net::SSH::Buffer.from(:key, server_key),
79
- :long, 1024,
80
- :long, need_bits, # need bits, figure this part out,
81
- :long, 8192,
82
- :bignum, dh.dh.p,
83
- :bignum, dh.dh.g,
84
- :bignum, dh.dh.pub_key,
85
- :bignum, server_dh_pubkey,
86
- :bignum, shared_secret)
87
- OpenSSL::Digest::SHA1.digest(buffer.to_s)
88
- end
89
- end
90
- end
91
-
92
- end; end
@@ -1,34 +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 session_id
15
- @session_id ||= begin
16
- buffer = Net::SSH::Buffer.from(:string, packet_data[:client_version_string],
17
- :string, packet_data[:server_version_string],
18
- :string, packet_data[:client_algorithm_packet],
19
- :string, packet_data[:server_algorithm_packet],
20
- :string, Net::SSH::Buffer.from(:key, server_key),
21
- :long, 1024,
22
- :long, 1024,
23
- :long, 8192,
24
- :bignum, dh.dh.p,
25
- :bignum, dh.dh.g,
26
- :bignum, dh.dh.pub_key,
27
- :bignum, server_dh_pubkey,
28
- :bignum, shared_secret)
29
- OpenSSL::Digest::SHA256.digest(buffer.to_s)
30
- end
31
- end
32
- end
33
-
34
- 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
@@ -1,38 +0,0 @@
1
- require 'openssl'
2
-
3
- unless defined?(OpenSSL::PKey::EC)
4
- puts "Skipping tests for ecdh-sha2-nistp521 key exchange"
5
- else
6
- require 'transport/kex/test_ecdh_sha2_nistp256'
7
- module Transport; module Kex
8
- class TestEcdhSHA2NistP521 < 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::SHA512
27
- end
28
-
29
- def subject
30
- Net::SSH::Transport::Kex::EcdhSHA2NistP521
31
- end
32
-
33
- def ecparam
34
- "secp521r1"
35
- end
36
- end
37
- end; end
38
- end