ddollar-net-ssh 2.0.1

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 (103) hide show
  1. data/CHANGELOG.rdoc +42 -0
  2. data/Manifest +101 -0
  3. data/README.rdoc +110 -0
  4. data/Rakefile +26 -0
  5. data/THANKS.rdoc +16 -0
  6. data/lib/net/ssh.rb +199 -0
  7. data/lib/net/ssh/authentication/agent.rb +175 -0
  8. data/lib/net/ssh/authentication/constants.rb +18 -0
  9. data/lib/net/ssh/authentication/key_manager.rb +169 -0
  10. data/lib/net/ssh/authentication/methods/abstract.rb +60 -0
  11. data/lib/net/ssh/authentication/methods/hostbased.rb +71 -0
  12. data/lib/net/ssh/authentication/methods/keyboard_interactive.rb +66 -0
  13. data/lib/net/ssh/authentication/methods/password.rb +39 -0
  14. data/lib/net/ssh/authentication/methods/publickey.rb +92 -0
  15. data/lib/net/ssh/authentication/pageant.rb +176 -0
  16. data/lib/net/ssh/authentication/session.rb +127 -0
  17. data/lib/net/ssh/buffer.rb +339 -0
  18. data/lib/net/ssh/buffered_io.rb +149 -0
  19. data/lib/net/ssh/config.rb +173 -0
  20. data/lib/net/ssh/connection/channel.rb +625 -0
  21. data/lib/net/ssh/connection/constants.rb +33 -0
  22. data/lib/net/ssh/connection/session.rb +569 -0
  23. data/lib/net/ssh/connection/term.rb +178 -0
  24. data/lib/net/ssh/errors.rb +85 -0
  25. data/lib/net/ssh/key_factory.rb +85 -0
  26. data/lib/net/ssh/known_hosts.rb +129 -0
  27. data/lib/net/ssh/loggable.rb +61 -0
  28. data/lib/net/ssh/packet.rb +102 -0
  29. data/lib/net/ssh/prompt.rb +93 -0
  30. data/lib/net/ssh/proxy/errors.rb +14 -0
  31. data/lib/net/ssh/proxy/http.rb +94 -0
  32. data/lib/net/ssh/proxy/socks4.rb +70 -0
  33. data/lib/net/ssh/proxy/socks5.rb +128 -0
  34. data/lib/net/ssh/service/forward.rb +267 -0
  35. data/lib/net/ssh/test.rb +89 -0
  36. data/lib/net/ssh/test/channel.rb +129 -0
  37. data/lib/net/ssh/test/extensions.rb +152 -0
  38. data/lib/net/ssh/test/kex.rb +44 -0
  39. data/lib/net/ssh/test/local_packet.rb +51 -0
  40. data/lib/net/ssh/test/packet.rb +81 -0
  41. data/lib/net/ssh/test/remote_packet.rb +38 -0
  42. data/lib/net/ssh/test/script.rb +157 -0
  43. data/lib/net/ssh/test/socket.rb +59 -0
  44. data/lib/net/ssh/transport/algorithms.rb +384 -0
  45. data/lib/net/ssh/transport/cipher_factory.rb +72 -0
  46. data/lib/net/ssh/transport/constants.rb +30 -0
  47. data/lib/net/ssh/transport/hmac.rb +31 -0
  48. data/lib/net/ssh/transport/hmac/abstract.rb +48 -0
  49. data/lib/net/ssh/transport/hmac/md5.rb +12 -0
  50. data/lib/net/ssh/transport/hmac/md5_96.rb +11 -0
  51. data/lib/net/ssh/transport/hmac/none.rb +15 -0
  52. data/lib/net/ssh/transport/hmac/sha1.rb +13 -0
  53. data/lib/net/ssh/transport/hmac/sha1_96.rb +11 -0
  54. data/lib/net/ssh/transport/identity_cipher.rb +40 -0
  55. data/lib/net/ssh/transport/kex.rb +13 -0
  56. data/lib/net/ssh/transport/kex/diffie_hellman_group1_sha1.rb +208 -0
  57. data/lib/net/ssh/transport/kex/diffie_hellman_group_exchange_sha1.rb +77 -0
  58. data/lib/net/ssh/transport/openssl.rb +128 -0
  59. data/lib/net/ssh/transport/packet_stream.rb +230 -0
  60. data/lib/net/ssh/transport/server_version.rb +61 -0
  61. data/lib/net/ssh/transport/session.rb +262 -0
  62. data/lib/net/ssh/transport/state.rb +170 -0
  63. data/lib/net/ssh/verifiers/lenient.rb +30 -0
  64. data/lib/net/ssh/verifiers/null.rb +12 -0
  65. data/lib/net/ssh/verifiers/strict.rb +53 -0
  66. data/lib/net/ssh/version.rb +60 -0
  67. data/net-ssh.gemspec +56 -0
  68. data/setup.rb +1585 -0
  69. data/test/authentication/methods/common.rb +28 -0
  70. data/test/authentication/methods/test_abstract.rb +51 -0
  71. data/test/authentication/methods/test_hostbased.rb +108 -0
  72. data/test/authentication/methods/test_keyboard_interactive.rb +98 -0
  73. data/test/authentication/methods/test_password.rb +50 -0
  74. data/test/authentication/methods/test_publickey.rb +123 -0
  75. data/test/authentication/test_agent.rb +205 -0
  76. data/test/authentication/test_key_manager.rb +100 -0
  77. data/test/authentication/test_session.rb +93 -0
  78. data/test/common.rb +106 -0
  79. data/test/configs/exact_match +8 -0
  80. data/test/configs/wild_cards +14 -0
  81. data/test/connection/test_channel.rb +452 -0
  82. data/test/connection/test_session.rb +483 -0
  83. data/test/test_all.rb +6 -0
  84. data/test/test_buffer.rb +336 -0
  85. data/test/test_buffered_io.rb +63 -0
  86. data/test/test_config.rb +78 -0
  87. data/test/test_key_factory.rb +67 -0
  88. data/test/transport/hmac/test_md5.rb +34 -0
  89. data/test/transport/hmac/test_md5_96.rb +25 -0
  90. data/test/transport/hmac/test_none.rb +34 -0
  91. data/test/transport/hmac/test_sha1.rb +34 -0
  92. data/test/transport/hmac/test_sha1_96.rb +25 -0
  93. data/test/transport/kex/test_diffie_hellman_group1_sha1.rb +146 -0
  94. data/test/transport/kex/test_diffie_hellman_group_exchange_sha1.rb +92 -0
  95. data/test/transport/test_algorithms.rb +302 -0
  96. data/test/transport/test_cipher_factory.rb +163 -0
  97. data/test/transport/test_hmac.rb +34 -0
  98. data/test/transport/test_identity_cipher.rb +40 -0
  99. data/test/transport/test_packet_stream.rb +433 -0
  100. data/test/transport/test_server_version.rb +55 -0
  101. data/test/transport/test_session.rb +312 -0
  102. data/test/transport/test_state.rb +173 -0
  103. metadata +222 -0
@@ -0,0 +1,67 @@
1
+ require 'common'
2
+ require 'net/ssh/key_factory'
3
+
4
+ class TestKeyFactory < Test::Unit::TestCase
5
+ def test_load_unencrypted_private_RSA_key_should_return_key
6
+ File.expects(:read).with("/key-file").returns(rsa_key.export)
7
+ assert_equal rsa_key.to_der, Net::SSH::KeyFactory.load_private_key("/key-file").to_der
8
+ end
9
+
10
+ def test_load_unencrypted_private_DSA_key_should_return_key
11
+ File.expects(:read).with("/key-file").returns(dsa_key.export)
12
+ assert_equal dsa_key.to_der, Net::SSH::KeyFactory.load_private_key("/key-file").to_der
13
+ end
14
+
15
+ def test_load_encrypted_private_RSA_key_should_prompt_for_password_and_return_key
16
+ File.expects(:read).with("/key-file").returns(encrypted(rsa_key, "password"))
17
+ Net::SSH::KeyFactory.expects(:prompt).with("Enter passphrase for /key-file:", false).returns("password")
18
+ assert_equal rsa_key.to_der, Net::SSH::KeyFactory.load_private_key("/key-file").to_der
19
+ end
20
+
21
+ def test_load_encrypted_private_RSA_key_with_password_should_not_prompt_and_return_key
22
+ File.expects(:read).with("/key-file").returns(encrypted(rsa_key, "password"))
23
+ assert_equal rsa_key.to_der, Net::SSH::KeyFactory.load_private_key("/key-file", "password").to_der
24
+ end
25
+
26
+ def test_load_encrypted_private_DSA_key_should_prompt_for_password_and_return_key
27
+ File.expects(:read).with("/key-file").returns(encrypted(dsa_key, "password"))
28
+ Net::SSH::KeyFactory.expects(:prompt).with("Enter passphrase for /key-file:", false).returns("password")
29
+ assert_equal dsa_key.to_der, Net::SSH::KeyFactory.load_private_key("/key-file").to_der
30
+ end
31
+
32
+ def test_load_encrypted_private_DSA_key_with_password_should_not_prompt_and_return_key
33
+ File.expects(:read).with("/key-file").returns(encrypted(dsa_key, "password"))
34
+ assert_equal dsa_key.to_der, Net::SSH::KeyFactory.load_private_key("/key-file", "password").to_der
35
+ end
36
+
37
+ def test_load_encrypted_private_key_should_give_three_tries_for_the_password_and_then_raise_exception
38
+ File.expects(:read).with("/key-file").returns(encrypted(rsa_key, "password"))
39
+ Net::SSH::KeyFactory.expects(:prompt).times(3).with("Enter passphrase for /key-file:", false).returns("passwod","passphrase","passwd")
40
+ assert_raises(OpenSSL::PKey::RSAError) { Net::SSH::KeyFactory.load_private_key("/key-file") }
41
+ end
42
+
43
+ def test_load_public_rsa_key_should_return_key
44
+ File.expects(:read).with("/key-file").returns(public(rsa_key))
45
+ assert_equal rsa_key.to_blob, Net::SSH::KeyFactory.load_public_key("/key-file").to_blob
46
+ end
47
+
48
+ private
49
+
50
+ def rsa_key
51
+ @rsa_key ||= OpenSSL::PKey::RSA.new("0@\002\001\000\002\t\000\300\030\317\2132\340 \267\002\003\001\000\001\002\t\000\236~\232\025\350Y=\341\002\005\000\352D\217\a\002\005\000\321\352\304\321\002\005\000\242\350\206%\002\005\000\270\021\217\361\002\004~\253\214j")
52
+ end
53
+
54
+ def dsa_key
55
+ @dsa_key ||= OpenSSL::PKey::DSA.new("0\201\367\002\001\000\002A\000\203\316/\037u\272&J\265\003l3\315d\324h\372{\t8\252#\331_\026\006\035\270\266\255\343\353Z\302\276\335\336\306\220\375\202L\244\244J\206>\346\b\315\211\302L\246x\247u\a\376\366\345\302\016#\002\025\000\244\274\302\221Og\275/\302+\356\346\360\024\373wI\2573\361\002@\027\215\270r*\f\213\350C\245\021:\350 \006\\\376\345\022`\210b\262\3643\023XLKS\320\370\002\276\347A\nU\204\276\324\256`=\026\240\330\306J\316V\213\024\e\030\215\355\006\037q\337\356ln\002@\017\257\034\f\260\333'S\271#\237\230E\321\312\027\021\226\331\251Vj\220\305\316\036\v\266+\000\230\270\177B\003?t\a\305]e\344\261\334\023\253\323\251\223M\2175)a(\004\"lI8\312\303\307\a\002\024_\aznW\345\343\203V\326\246ua\203\376\201o\350\302\002")
56
+ end
57
+
58
+ def encrypted(key, password)
59
+ key.export(OpenSSL::Cipher::Cipher.new("des-ede3-cbc"), password)
60
+ end
61
+
62
+ def public(key)
63
+ result = "#{key.ssh_type} "
64
+ result << [Net::SSH::Buffer.from(:key, key).to_s].pack("m*").strip.tr("\n\r\t ", "")
65
+ result << " joe@host.test"
66
+ end
67
+ end
@@ -0,0 +1,34 @@
1
+ require 'common'
2
+ require 'net/ssh/transport/hmac/md5'
3
+
4
+ module Transport; module HMAC
5
+
6
+ class TestMD5 < Test::Unit::TestCase
7
+ def test_expected_digest_class
8
+ assert_equal OpenSSL::Digest::MD5, subject.digest_class
9
+ assert_equal OpenSSL::Digest::MD5, subject.new.digest_class
10
+ end
11
+
12
+ def test_expected_key_length
13
+ assert_equal 16, subject.key_length
14
+ assert_equal 16, subject.new.key_length
15
+ end
16
+
17
+ def test_expected_mac_length
18
+ assert_equal 16, subject.mac_length
19
+ assert_equal 16, subject.new.mac_length
20
+ end
21
+
22
+ def test_expected_digest
23
+ hmac = subject.new("1234567890123456")
24
+ assert_equal "\275\345\006\307y~Oi\035<.\341\031\250<\257", hmac.digest("hello world")
25
+ end
26
+
27
+ private
28
+
29
+ def subject
30
+ Net::SSH::Transport::HMAC::MD5
31
+ end
32
+ end
33
+
34
+ end; end
@@ -0,0 +1,25 @@
1
+ require 'common'
2
+ require 'transport/hmac/test_md5'
3
+ require 'net/ssh/transport/hmac/md5_96'
4
+
5
+ module Transport; module HMAC
6
+
7
+ class TestMD5_96 < TestMD5
8
+ def test_expected_mac_length
9
+ assert_equal 12, subject.mac_length
10
+ assert_equal 12, subject.new.mac_length
11
+ end
12
+
13
+ def test_expected_digest
14
+ hmac = subject.new("1234567890123456")
15
+ assert_equal "\275\345\006\307y~Oi\035<.\341", hmac.digest("hello world")
16
+ end
17
+
18
+ private
19
+
20
+ def subject
21
+ Net::SSH::Transport::HMAC::MD5_96
22
+ end
23
+ end
24
+
25
+ end; end
@@ -0,0 +1,34 @@
1
+ require 'common'
2
+ require 'net/ssh/transport/hmac/none'
3
+
4
+ module Transport; module HMAC
5
+
6
+ class TestNone < Test::Unit::TestCase
7
+ def test_expected_digest_class
8
+ assert_equal nil, subject.digest_class
9
+ assert_equal nil, subject.new.digest_class
10
+ end
11
+
12
+ def test_expected_key_length
13
+ assert_equal 0, subject.key_length
14
+ assert_equal 0, subject.new.key_length
15
+ end
16
+
17
+ def test_expected_mac_length
18
+ assert_equal 0, subject.mac_length
19
+ assert_equal 0, subject.new.mac_length
20
+ end
21
+
22
+ def test_expected_digest
23
+ hmac = subject.new("1234567890123456")
24
+ assert_equal "", hmac.digest("hello world")
25
+ end
26
+
27
+ private
28
+
29
+ def subject
30
+ Net::SSH::Transport::HMAC::None
31
+ end
32
+ end
33
+
34
+ end; end
@@ -0,0 +1,34 @@
1
+ require 'common'
2
+ require 'net/ssh/transport/hmac/sha1'
3
+
4
+ module Transport; module HMAC
5
+
6
+ class TestSHA1 < Test::Unit::TestCase
7
+ def test_expected_digest_class
8
+ assert_equal OpenSSL::Digest::SHA1, subject.digest_class
9
+ assert_equal OpenSSL::Digest::SHA1, subject.new.digest_class
10
+ end
11
+
12
+ def test_expected_key_length
13
+ assert_equal 20, subject.key_length
14
+ assert_equal 20, subject.new.key_length
15
+ end
16
+
17
+ def test_expected_mac_length
18
+ assert_equal 20, subject.mac_length
19
+ assert_equal 20, subject.new.mac_length
20
+ end
21
+
22
+ def test_expected_digest
23
+ hmac = subject.new("1234567890123456")
24
+ assert_equal "\000\004W\202\204+&\335\311\251P\266\250\214\276\206;\022U\365", hmac.digest("hello world")
25
+ end
26
+
27
+ private
28
+
29
+ def subject
30
+ Net::SSH::Transport::HMAC::SHA1
31
+ end
32
+ end
33
+
34
+ end; end
@@ -0,0 +1,25 @@
1
+ require 'common'
2
+ require 'transport/hmac/test_sha1'
3
+ require 'net/ssh/transport/hmac/sha1_96'
4
+
5
+ module Transport; module HMAC
6
+
7
+ class TestSHA1_96 < TestSHA1
8
+ def test_expected_mac_length
9
+ assert_equal 12, subject.mac_length
10
+ assert_equal 12, subject.new.mac_length
11
+ end
12
+
13
+ def test_expected_digest
14
+ hmac = subject.new("1234567890123456")
15
+ assert_equal "\000\004W\202\204+&\335\311\251P\266", hmac.digest("hello world")
16
+ end
17
+
18
+ private
19
+
20
+ def subject
21
+ Net::SSH::Transport::HMAC::SHA1_96
22
+ end
23
+ end
24
+
25
+ end; end
@@ -0,0 +1,146 @@
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 |t, buffer|
70
+ assert_equal NEWKEYS, buffer.type
71
+ t.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
+ # 368 bits is the smallest possible key that will work with this, so
99
+ # we use it for speed reasons
100
+ def server_key(bits=368)
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
@@ -0,0 +1,92 @@
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(4000)
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 |t, buffer|
55
+ assert_equal KEXDH_GEX_INIT, buffer.type
56
+ assert_equal dh.dh.pub_key, buffer.read_bignum
57
+ t.return(KEXDH_GEX_REPLY, :string, b(:key, server_key), :bignum, server_dh_pubkey, :string, b(:string, options[:key_type] || "ssh-rsa", :string, signature))
58
+ t.expect do |t, buffer|
59
+ assert_equal NEWKEYS, buffer.type
60
+ t.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