net-ssh-net-ssh 2.0.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (105) hide show
  1. data/CHANGELOG.rdoc +137 -0
  2. data/Manifest +104 -0
  3. data/README.rdoc +110 -0
  4. data/Rakefile +79 -0
  5. data/THANKS.rdoc +16 -0
  6. data/lib/net/ssh.rb +215 -0
  7. data/lib/net/ssh/authentication/agent.rb +176 -0
  8. data/lib/net/ssh/authentication/constants.rb +18 -0
  9. data/lib/net/ssh/authentication/key_manager.rb +193 -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 +183 -0
  16. data/lib/net/ssh/authentication/session.rb +134 -0
  17. data/lib/net/ssh/buffer.rb +340 -0
  18. data/lib/net/ssh/buffered_io.rb +149 -0
  19. data/lib/net/ssh/config.rb +181 -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 +596 -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 +102 -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 +129 -0
  34. data/lib/net/ssh/ruby_compat.rb +7 -0
  35. data/lib/net/ssh/service/forward.rb +267 -0
  36. data/lib/net/ssh/test.rb +89 -0
  37. data/lib/net/ssh/test/channel.rb +129 -0
  38. data/lib/net/ssh/test/extensions.rb +152 -0
  39. data/lib/net/ssh/test/kex.rb +44 -0
  40. data/lib/net/ssh/test/local_packet.rb +51 -0
  41. data/lib/net/ssh/test/packet.rb +81 -0
  42. data/lib/net/ssh/test/remote_packet.rb +38 -0
  43. data/lib/net/ssh/test/script.rb +157 -0
  44. data/lib/net/ssh/test/socket.rb +59 -0
  45. data/lib/net/ssh/transport/algorithms.rb +384 -0
  46. data/lib/net/ssh/transport/cipher_factory.rb +84 -0
  47. data/lib/net/ssh/transport/constants.rb +30 -0
  48. data/lib/net/ssh/transport/hmac.rb +31 -0
  49. data/lib/net/ssh/transport/hmac/abstract.rb +78 -0
  50. data/lib/net/ssh/transport/hmac/md5.rb +12 -0
  51. data/lib/net/ssh/transport/hmac/md5_96.rb +11 -0
  52. data/lib/net/ssh/transport/hmac/none.rb +15 -0
  53. data/lib/net/ssh/transport/hmac/sha1.rb +13 -0
  54. data/lib/net/ssh/transport/hmac/sha1_96.rb +11 -0
  55. data/lib/net/ssh/transport/identity_cipher.rb +55 -0
  56. data/lib/net/ssh/transport/kex.rb +13 -0
  57. data/lib/net/ssh/transport/kex/diffie_hellman_group1_sha1.rb +208 -0
  58. data/lib/net/ssh/transport/kex/diffie_hellman_group_exchange_sha1.rb +77 -0
  59. data/lib/net/ssh/transport/openssl.rb +128 -0
  60. data/lib/net/ssh/transport/packet_stream.rb +230 -0
  61. data/lib/net/ssh/transport/server_version.rb +69 -0
  62. data/lib/net/ssh/transport/session.rb +276 -0
  63. data/lib/net/ssh/transport/state.rb +206 -0
  64. data/lib/net/ssh/verifiers/lenient.rb +30 -0
  65. data/lib/net/ssh/verifiers/null.rb +12 -0
  66. data/lib/net/ssh/verifiers/strict.rb +53 -0
  67. data/lib/net/ssh/version.rb +62 -0
  68. data/net-ssh.gemspec +128 -0
  69. data/setup.rb +1585 -0
  70. data/test/authentication/methods/common.rb +28 -0
  71. data/test/authentication/methods/test_abstract.rb +51 -0
  72. data/test/authentication/methods/test_hostbased.rb +114 -0
  73. data/test/authentication/methods/test_keyboard_interactive.rb +98 -0
  74. data/test/authentication/methods/test_password.rb +50 -0
  75. data/test/authentication/methods/test_publickey.rb +127 -0
  76. data/test/authentication/test_agent.rb +205 -0
  77. data/test/authentication/test_key_manager.rb +105 -0
  78. data/test/authentication/test_session.rb +93 -0
  79. data/test/common.rb +106 -0
  80. data/test/configs/eqsign +3 -0
  81. data/test/configs/exact_match +8 -0
  82. data/test/configs/wild_cards +14 -0
  83. data/test/connection/test_channel.rb +452 -0
  84. data/test/connection/test_session.rb +488 -0
  85. data/test/test_all.rb +6 -0
  86. data/test/test_buffer.rb +336 -0
  87. data/test/test_buffered_io.rb +63 -0
  88. data/test/test_config.rb +84 -0
  89. data/test/test_key_factory.rb +67 -0
  90. data/test/transport/hmac/test_md5.rb +39 -0
  91. data/test/transport/hmac/test_md5_96.rb +25 -0
  92. data/test/transport/hmac/test_none.rb +34 -0
  93. data/test/transport/hmac/test_sha1.rb +34 -0
  94. data/test/transport/hmac/test_sha1_96.rb +25 -0
  95. data/test/transport/kex/test_diffie_hellman_group1_sha1.rb +146 -0
  96. data/test/transport/kex/test_diffie_hellman_group_exchange_sha1.rb +92 -0
  97. data/test/transport/test_algorithms.rb +302 -0
  98. data/test/transport/test_cipher_factory.rb +171 -0
  99. data/test/transport/test_hmac.rb +34 -0
  100. data/test/transport/test_identity_cipher.rb +40 -0
  101. data/test/transport/test_packet_stream.rb +435 -0
  102. data/test/transport/test_server_version.rb +68 -0
  103. data/test/transport/test_session.rb +315 -0
  104. data/test/transport/test_state.rb +173 -0
  105. metadata +162 -0
@@ -0,0 +1,34 @@
1
+ require 'common'
2
+ require 'net/ssh/transport/hmac'
3
+
4
+ module Transport
5
+
6
+ class TestHMAC < Test::Unit::TestCase
7
+ Net::SSH::Transport::HMAC::MAP.each do |name, value|
8
+ method = name.tr("-", "_")
9
+ define_method("test_get_with_#{method}_returns_new_hmac_instance") do
10
+ key = "abcdefghijklmnopqrstuvwxyz"[0,Net::SSH::Transport::HMAC::MAP[name].key_length]
11
+ hmac = Net::SSH::Transport::HMAC.get(name, key)
12
+ assert_instance_of Net::SSH::Transport::HMAC::MAP[name], hmac
13
+ assert_equal key, hmac.key
14
+ end
15
+
16
+ define_method("test_key_length_with_#{method}_returns_correct_key_length") do
17
+ assert_equal Net::SSH::Transport::HMAC::MAP[name].key_length, Net::SSH::Transport::HMAC.key_length(name)
18
+ end
19
+ end
20
+
21
+ def test_get_with_unrecognized_hmac_raises_argument_error
22
+ assert_raises(ArgumentError) do
23
+ Net::SSH::Transport::HMAC.get("bogus")
24
+ end
25
+ end
26
+
27
+ def test_key_length_with_unrecognized_hmac_raises_argument_error
28
+ assert_raises(ArgumentError) do
29
+ Net::SSH::Transport::HMAC.get("bogus")
30
+ end
31
+ end
32
+ end
33
+
34
+ end
@@ -0,0 +1,40 @@
1
+ require 'common'
2
+ require 'net/ssh/transport/identity_cipher'
3
+
4
+ module Transport
5
+
6
+ class TestIdentityCipher < Test::Unit::TestCase
7
+
8
+ def test_block_size_should_be_8
9
+ assert_equal 8, cipher.block_size
10
+ end
11
+
12
+ def test_encrypt_should_return_self
13
+ assert_equal cipher, cipher.encrypt
14
+ end
15
+
16
+ def test_decrypt_should_return_self
17
+ assert_equal cipher, cipher.decrypt
18
+ end
19
+
20
+ def test_update_should_return_argument
21
+ assert_equal "hello, world", cipher.update("hello, world")
22
+ end
23
+
24
+ def test_final_should_return_empty_string
25
+ assert_equal "", cipher.final
26
+ end
27
+
28
+ def test_name_should_be_identity
29
+ assert_equal "identity", cipher.name
30
+ end
31
+
32
+ private
33
+
34
+ def cipher
35
+ Net::SSH::Transport::IdentityCipher
36
+ end
37
+
38
+ end
39
+
40
+ end
@@ -0,0 +1,435 @@
1
+ require 'common'
2
+ require 'net/ssh/transport/packet_stream'
3
+
4
+ module Transport
5
+
6
+ class TestPacketStream < Test::Unit::TestCase
7
+ include Net::SSH::Transport::Constants
8
+
9
+ def test_client_name_when_getnameinfo_works
10
+ stream.expects(:getsockname).returns(:sockaddr)
11
+ Socket.expects(:getnameinfo).with(:sockaddr, Socket::NI_NAMEREQD).returns(["net.ssh.test"])
12
+ assert_equal "net.ssh.test", stream.client_name
13
+ end
14
+
15
+ def test_client_name_when_getnameinfo_fails_first_and_then_works
16
+ stream.expects(:getsockname).returns(:sockaddr)
17
+ Socket.expects(:getnameinfo).with(:sockaddr, Socket::NI_NAMEREQD).raises(SocketError)
18
+ Socket.expects(:getnameinfo).with(:sockaddr).returns(["1.2.3.4"])
19
+ assert_equal "1.2.3.4", stream.client_name
20
+ end
21
+
22
+ def test_client_name_when_getnameinfo_fails_but_gethostbyname_works
23
+ stream.expects(:getsockname).returns(:sockaddr)
24
+ Socket.expects(:getnameinfo).with(:sockaddr, Socket::NI_NAMEREQD).raises(SocketError)
25
+ Socket.expects(:getnameinfo).with(:sockaddr).raises(SocketError)
26
+ Socket.expects(:gethostname).returns(:hostname)
27
+ Socket.expects(:gethostbyname).with(:hostname).returns(["net.ssh.test"])
28
+ assert_equal "net.ssh.test", stream.client_name
29
+ end
30
+
31
+ def test_client_name_when_getnameinfo_and_gethostbyname_all_fail
32
+ stream.expects(:getsockname).returns(:sockaddr)
33
+ Socket.expects(:getnameinfo).with(:sockaddr, Socket::NI_NAMEREQD).raises(SocketError)
34
+ Socket.expects(:getnameinfo).with(:sockaddr).raises(SocketError)
35
+ Socket.expects(:gethostname).returns(:hostname)
36
+ Socket.expects(:gethostbyname).with(:hostname).raises(SocketError)
37
+ assert_equal "unknown", stream.client_name
38
+ end
39
+
40
+ def test_peer_ip_should_query_socket_for_info_about_peer
41
+ stream.expects(:getpeername).returns(:sockaddr)
42
+ Socket.expects(:getnameinfo).with(:sockaddr, Socket::NI_NUMERICHOST | Socket::NI_NUMERICSERV).returns(["1.2.3.4"])
43
+ assert_equal "1.2.3.4", stream.peer_ip
44
+ end
45
+
46
+ def test_available_for_read_should_return_nontrue_when_select_fails
47
+ IO.expects(:select).returns(nil)
48
+ assert !stream.available_for_read?
49
+ end
50
+
51
+ def test_available_for_read_should_return_nontrue_when_self_is_not_ready
52
+ IO.expects(:select).with([stream], nil, nil, 0).returns([[],[],[]])
53
+ assert !stream.available_for_read?
54
+ end
55
+
56
+ def test_available_for_read_should_return_true_when_self_is_ready
57
+ IO.expects(:select).with([stream], nil, nil, 0).returns([[self],[],[]])
58
+ assert stream.available_for_read?
59
+ end
60
+
61
+ def test_cleanup_should_delegate_cleanup_to_client_and_server_states
62
+ stream.client.expects(:cleanup)
63
+ stream.server.expects(:cleanup)
64
+ stream.cleanup
65
+ end
66
+
67
+ def test_if_needs_rekey_should_not_yield_if_neither_client_nor_server_states_need_rekey
68
+ stream.if_needs_rekey? { flunk "shouldn't need rekey" }
69
+ assert(true)
70
+ end
71
+
72
+ def test_if_needs_rekey_should_yield_and_cleanup_if_client_needs_rekey
73
+ stream.client.stubs(:needs_rekey?).returns(true)
74
+ stream.client.expects(:reset!)
75
+ stream.server.expects(:reset!).never
76
+ rekeyed = false
77
+ stream.if_needs_rekey? { rekeyed = true }
78
+ assert(rekeyed)
79
+ end
80
+
81
+ def test_if_needs_rekey_should_yield_and_cleanup_if_server_needs_rekey
82
+ stream.server.stubs(:needs_rekey?).returns(true)
83
+ stream.server.expects(:reset!)
84
+ stream.client.expects(:reset!).never
85
+ rekeyed = false
86
+ stream.if_needs_rekey? { rekeyed = true }
87
+ assert(rekeyed)
88
+ end
89
+
90
+ def test_if_needs_rekey_should_yield_and_cleanup_if_both_need_rekey
91
+ stream.server.stubs(:needs_rekey?).returns(true)
92
+ stream.client.stubs(:needs_rekey?).returns(true)
93
+ stream.server.expects(:reset!)
94
+ stream.client.expects(:reset!)
95
+ rekeyed = false
96
+ stream.if_needs_rekey? { rekeyed = true }
97
+ assert(rekeyed)
98
+ end
99
+
100
+ def test_next_packet_should_not_block_by_default
101
+ IO.expects(:select).returns(nil)
102
+ assert_nothing_raised do
103
+ timeout(1) { stream.next_packet }
104
+ end
105
+ end
106
+
107
+ def test_next_packet_should_return_nil_when_non_blocking_and_not_ready
108
+ IO.expects(:select).returns(nil)
109
+ assert_nil stream.next_packet(:nonblock)
110
+ end
111
+
112
+ def test_next_packet_should_return_nil_when_non_blocking_and_partial_read
113
+ IO.expects(:select).returns([[stream]])
114
+ stream.expects(:recv).returns([8].pack("N"))
115
+ assert_nil stream.next_packet(:nonblock)
116
+ assert !stream.read_buffer.empty?
117
+ end
118
+
119
+ def test_next_packet_should_return_packet_when_non_blocking_and_full_read
120
+ IO.expects(:select).returns([[stream]])
121
+ stream.expects(:recv).returns(packet)
122
+ packet = stream.next_packet(:nonblock)
123
+ assert_not_nil packet
124
+ assert_equal DEBUG, packet.type
125
+ end
126
+
127
+ def test_next_packet_should_eventually_return_packet_when_non_blocking_and_partial_read
128
+ IO.stubs(:select).returns([[stream]])
129
+ stream.stubs(:recv).returns(packet[0,10], packet[10..-1])
130
+ assert_nil stream.next_packet(:nonblock)
131
+ packet = stream.next_packet(:nonblock)
132
+ assert_not_nil packet
133
+ assert_equal DEBUG, packet.type
134
+ end
135
+
136
+ def test_next_packet_should_block_when_requested_until_entire_packet_is_available
137
+ IO.stubs(:select).returns([[stream]])
138
+ stream.stubs(:recv).returns(packet[0,10], packet[10,20], packet[20..-1])
139
+ packet = stream.next_packet(:block)
140
+ assert_not_nil packet
141
+ assert_equal DEBUG, packet.type
142
+ end
143
+
144
+ def test_next_packet_when_blocking_should_fail_when_fill_could_not_read_any_data
145
+ IO.stubs(:select).returns([[stream]])
146
+ stream.stubs(:recv).returns("")
147
+ assert_raises(Net::SSH::Disconnect) { stream.next_packet(:block) }
148
+ end
149
+
150
+ def test_next_packet_fails_with_invalid_argument
151
+ assert_raises(ArgumentError) { stream.next_packet("invalid") }
152
+ end
153
+
154
+ def test_send_packet_should_enqueue_and_send_data_immediately
155
+ stream.expects(:send).times(3).with { |a,b| a == stream.write_buffer && b == 0 }.returns(15)
156
+ IO.expects(:select).times(2).returns([[], [stream]])
157
+ stream.send_packet(ssh_packet)
158
+ assert !stream.pending_write?
159
+ end
160
+
161
+ def test_enqueue_short_packet_should_ensure_packet_is_at_least_16_bytes_long
162
+ packet = Net::SSH::Buffer.from(:byte, 0)
163
+ stream.enqueue_packet(packet)
164
+ # 12 originally, plus the block-size (8), plus the 4-byte length field
165
+ assert_equal 24, stream.write_buffer.length
166
+ end
167
+
168
+ PACKETS = {
169
+ "3des-cbc" => {
170
+ "hmac-md5" => {
171
+ false => "\003\352\031\261k\243\200\204\301\203]!\a\306\217\201\a[^\304\317\322\264\265~\361\017\n\205\272, #[\343\200Sb\377\265\322\003=S\255N\2654",
172
+ :standard => "\317\222v\316\234<\310\377\310\034\346\351\020:\025{\372PDS\246\344\312J\364\301\n\262\r<\037\231Mu\031\240\255\026\362\200A\305\027\341\261\331x\353\0372\3643h`\177\202",
173
+ },
174
+ "hmac-md5-96" => {
175
+ false => "\003\352\031\261k\243\200\204\301\203]!\a\306\217\201\a[^\304\317\322\264\265~\361\017\n\205\272, #[\343\200Sb\377\265\322\003=S",
176
+ :standard => "\317\222v\316\234<\310\377\310\034\346\351\020:\025{\372PDS\246\344\312J\364\301\n\262\r<\037\231Mu\031\240\255\026\362\200A\305\027\341\261\331x\353\0372\3643",
177
+ },
178
+ "hmac-sha1" => {
179
+ false => "\003\352\031\261k\243\200\204\301\203]!\a\306\217\201\a[^\304\317\322\264\265~\361\017\n\205\272, \235J\004f\262\3730t\376\273\323n\260\275\202\223\214\370D\204",
180
+ :standard => "\317\222v\316\234<\310\377\310\034\346\351\020:\025{\372PDS\246\344\312J\364\301\n\262\r<\037\231Mu\031\240\255\026\362\200\345\a{|\0367\355\2735\310'\n\342\250\246\030*1\353\330",
181
+ },
182
+ "hmac-sha1-96" => {
183
+ false => "\003\352\031\261k\243\200\204\301\203]!\a\306\217\201\a[^\304\317\322\264\265~\361\017\n\205\272, \235J\004f\262\3730t\376\273\323n",
184
+ :standard => "\317\222v\316\234<\310\377\310\034\346\351\020:\025{\372PDS\246\344\312J\364\301\n\262\r<\037\231Mu\031\240\255\026\362\200\345\a{|\0367\355\2735\310'\n",
185
+ },
186
+ "none" => {
187
+ false => "\003\352\031\261k\243\200\204\301\203]!\a\306\217\201\a[^\304\317\322\264\265~\361\017\n\205\272, ",
188
+ :standard => "\317\222v\316\234<\310\377\310\034\346\351\020:\025{\372PDS\246\344\312J\364\301\n\262\r<\037\231Mu\031\240\255\026\362\200",
189
+ },
190
+ },
191
+ "aes128-cbc" => {
192
+ "hmac-md5" => {
193
+ false => "\240\016\243k]0\330\253\030\320\334\261(\034E\211\230#\326\374\267\311O\211E(\234\325n\306NY#[\343\200Sb\377\265\322\003=S\255N\2654",
194
+ :standard => "\273\367\324\032\3762\334\026\r\246\342\022\016\325\024\270.\273\005\314\036\312\211\261\037A\361\362:W\316\352K\204\216b\2124>A\265g\331\177\233dK\251\337\227`9L\324[bPd\253XY\205\241\310",
195
+ },
196
+ "hmac-md5-96" => {
197
+ false => "\240\016\243k]0\330\253\030\320\334\261(\034E\211\230#\326\374\267\311O\211E(\234\325n\306NY#[\343\200Sb\377\265\322\003=S",
198
+ :standard => "\273\367\324\032\3762\334\026\r\246\342\022\016\325\024\270.\273\005\314\036\312\211\261\037A\361\362:W\316\352K\204\216b\2124>A\265g\331\177\233dK\251\337\227`9L\324[bPd\253X",
199
+ },
200
+ "hmac-sha1" => {
201
+ false => "\240\016\243k]0\330\253\030\320\334\261(\034E\211\230#\326\374\267\311O\211E(\234\325n\306NY\235J\004f\262\3730t\376\273\323n\260\275\202\223\214\370D\204",
202
+ :standard => "\273\367\324\032\3762\334\026\r\246\342\022\016\325\024\270.\273\005\314\036\312\211\261\037A\361\362:W\316\352K\204\216b\2124>A\265g\331\177\233dK\251\314\r\224%\316I\370t\251\372]\031\322pH%\267\337r\247",
203
+ },
204
+ "hmac-sha1-96" => {
205
+ false => "\240\016\243k]0\330\253\030\320\334\261(\034E\211\230#\326\374\267\311O\211E(\234\325n\306NY\235J\004f\262\3730t\376\273\323n",
206
+ :standard => "\273\367\324\032\3762\334\026\r\246\342\022\016\325\024\270.\273\005\314\036\312\211\261\037A\361\362:W\316\352K\204\216b\2124>A\265g\331\177\233dK\251\314\r\224%\316I\370t\251\372]\031",
207
+ },
208
+ "none" => {
209
+ false => "\240\016\243k]0\330\253\030\320\334\261(\034E\211\230#\326\374\267\311O\211E(\234\325n\306NY",
210
+ :standard => "\273\367\324\032\3762\334\026\r\246\342\022\016\325\024\270.\273\005\314\036\312\211\261\037A\361\362:W\316\352K\204\216b\2124>A\265g\331\177\233dK\251",
211
+ },
212
+ },
213
+ "aes192-cbc" => {
214
+ "hmac-md5" => {
215
+ false => "P$\377\302\326\262\276\215\206\343&\257#\315>Mp\232P\345o\215\330\213\t\027\300\360\300\037\267\003#[\343\200Sb\377\265\322\003=S\255N\2654",
216
+ :standard => "se\347\230\026\311\212\250yH\241\302n\364:\276\270M=H1\317\222^\362\237D\225N\354:\343\205M\006[\313$U/yZ\330\235\032\307\320D\337\227`9L\324[bPd\253XY\205\241\310",
217
+ },
218
+ "hmac-md5-96" => {
219
+ false => "P$\377\302\326\262\276\215\206\343&\257#\315>Mp\232P\345o\215\330\213\t\027\300\360\300\037\267\003#[\343\200Sb\377\265\322\003=S",
220
+ :standard => "se\347\230\026\311\212\250yH\241\302n\364:\276\270M=H1\317\222^\362\237D\225N\354:\343\205M\006[\313$U/yZ\330\235\032\307\320D\337\227`9L\324[bPd\253X",
221
+ },
222
+ "hmac-sha1" => {
223
+ false => "P$\377\302\326\262\276\215\206\343&\257#\315>Mp\232P\345o\215\330\213\t\027\300\360\300\037\267\003\235J\004f\262\3730t\376\273\323n\260\275\202\223\214\370D\204",
224
+ :standard => "se\347\230\026\311\212\250yH\241\302n\364:\276\270M=H1\317\222^\362\237D\225N\354:\343\205M\006[\313$U/yZ\330\235\032\307\320D\314\r\224%\316I\370t\251\372]\031\322pH%\267\337r\247",
225
+ },
226
+ "hmac-sha1-96" => {
227
+ false => "P$\377\302\326\262\276\215\206\343&\257#\315>Mp\232P\345o\215\330\213\t\027\300\360\300\037\267\003\235J\004f\262\3730t\376\273\323n",
228
+ :standard => "se\347\230\026\311\212\250yH\241\302n\364:\276\270M=H1\317\222^\362\237D\225N\354:\343\205M\006[\313$U/yZ\330\235\032\307\320D\314\r\224%\316I\370t\251\372]\031",
229
+ },
230
+ "none" => {
231
+ false => "P$\377\302\326\262\276\215\206\343&\257#\315>Mp\232P\345o\215\330\213\t\027\300\360\300\037\267\003",
232
+ :standard => "se\347\230\026\311\212\250yH\241\302n\364:\276\270M=H1\317\222^\362\237D\225N\354:\343\205M\006[\313$U/yZ\330\235\032\307\320D",
233
+ },
234
+ },
235
+ "aes256-cbc" => {
236
+ "hmac-md5" => {
237
+ false => "\266\001oG(\201s\255[\202j\031-\354\353]\022\374\367j2\257\b#\273r\275\341\232\264\255\340#[\343\200Sb\377\265\322\003=S\255N\2654",
238
+ :standard => "\251!O/_\253\321\217e\225\202\202W\261p\r\357\357\375\231\264Y,nZ/\366\225G\256\3000\036\223\237\353\265vG\231\215cvY\236%\315\365\337\227`9L\324[bPd\253XY\205\241\310",
239
+ },
240
+ "hmac-md5-96" => {
241
+ false => "\266\001oG(\201s\255[\202j\031-\354\353]\022\374\367j2\257\b#\273r\275\341\232\264\255\340#[\343\200Sb\377\265\322\003=S",
242
+ :standard => "\251!O/_\253\321\217e\225\202\202W\261p\r\357\357\375\231\264Y,nZ/\366\225G\256\3000\036\223\237\353\265vG\231\215cvY\236%\315\365\337\227`9L\324[bPd\253X",
243
+ },
244
+ "hmac-sha1" => {
245
+ false => "\266\001oG(\201s\255[\202j\031-\354\353]\022\374\367j2\257\b#\273r\275\341\232\264\255\340\235J\004f\262\3730t\376\273\323n\260\275\202\223\214\370D\204",
246
+ :standard => "\251!O/_\253\321\217e\225\202\202W\261p\r\357\357\375\231\264Y,nZ/\366\225G\256\3000\036\223\237\353\265vG\231\215cvY\236%\315\365\314\r\224%\316I\370t\251\372]\031\322pH%\267\337r\247",
247
+ },
248
+ "hmac-sha1-96" => {
249
+ false => "\266\001oG(\201s\255[\202j\031-\354\353]\022\374\367j2\257\b#\273r\275\341\232\264\255\340\235J\004f\262\3730t\376\273\323n",
250
+ :standard => "\251!O/_\253\321\217e\225\202\202W\261p\r\357\357\375\231\264Y,nZ/\366\225G\256\3000\036\223\237\353\265vG\231\215cvY\236%\315\365\314\r\224%\316I\370t\251\372]\031",
251
+ },
252
+ "none" => {
253
+ false => "\266\001oG(\201s\255[\202j\031-\354\353]\022\374\367j2\257\b#\273r\275\341\232\264\255\340",
254
+ :standard => "\251!O/_\253\321\217e\225\202\202W\261p\r\357\357\375\231\264Y,nZ/\366\225G\256\3000\036\223\237\353\265vG\231\215cvY\236%\315\365",
255
+ },
256
+ },
257
+ "blowfish-cbc" => {
258
+ "hmac-md5" => {
259
+ false => "vT\353\203\247\206L\255e\371\001 6B/\234g\332\371\224l\227\257\346\373E\237C2\212u)#[\343\200Sb\377\265\322\003=S\255N\2654",
260
+ :standard => "U\257\231e\347\274\bh\016X\232h\334\v\005\316e1G$-\367##\256$rW\000\210\335_\360\f\000\205#\370\201\006A\305\027\341\261\331x\353\0372\3643h`\177\202",
261
+ },
262
+ "hmac-md5-96" => {
263
+ false => "vT\353\203\247\206L\255e\371\001 6B/\234g\332\371\224l\227\257\346\373E\237C2\212u)#[\343\200Sb\377\265\322\003=S",
264
+ :standard => "U\257\231e\347\274\bh\016X\232h\334\v\005\316e1G$-\367##\256$rW\000\210\335_\360\f\000\205#\370\201\006A\305\027\341\261\331x\353\0372\3643",
265
+ },
266
+ "hmac-sha1" => {
267
+ false => "vT\353\203\247\206L\255e\371\001 6B/\234g\332\371\224l\227\257\346\373E\237C2\212u)\235J\004f\262\3730t\376\273\323n\260\275\202\223\214\370D\204",
268
+ :standard => "U\257\231e\347\274\bh\016X\232h\334\v\005\316e1G$-\367##\256$rW\000\210\335_\360\f\000\205#\370\201\006\345\a{|\0367\355\2735\310'\n\342\250\246\030*1\353\330",
269
+ },
270
+ "hmac-sha1-96" => {
271
+ false => "vT\353\203\247\206L\255e\371\001 6B/\234g\332\371\224l\227\257\346\373E\237C2\212u)\235J\004f\262\3730t\376\273\323n",
272
+ :standard => "U\257\231e\347\274\bh\016X\232h\334\v\005\316e1G$-\367##\256$rW\000\210\335_\360\f\000\205#\370\201\006\345\a{|\0367\355\2735\310'\n",
273
+ },
274
+ "none" => {
275
+ false => "vT\353\203\247\206L\255e\371\001 6B/\234g\332\371\224l\227\257\346\373E\237C2\212u)",
276
+ :standard => "U\257\231e\347\274\bh\016X\232h\334\v\005\316e1G$-\367##\256$rW\000\210\335_\360\f\000\205#\370\201\006",
277
+ },
278
+ },
279
+ "cast128-cbc" => {
280
+ "hmac-md5" => {
281
+ false => "\361\026\313!\31235|w~\n\261\257\277\e\277b\246b\342\333\eE\021N\345\343m\314\272\315\376#[\343\200Sb\377\265\322\003=S\255N\2654",
282
+ :standard => "\375i\253\004\311E\2011)\220$\251A\245\f(\371\263\314\242\353\260\272\367\276\"\031\224$\244\311W\307Oe\224\0017\336\325A\305\027\341\261\331x\353\0372\3643h`\177\202",
283
+ },
284
+ "hmac-md5-96" => {
285
+ false => "\361\026\313!\31235|w~\n\261\257\277\e\277b\246b\342\333\eE\021N\345\343m\314\272\315\376#[\343\200Sb\377\265\322\003=S",
286
+ :standard => "\375i\253\004\311E\2011)\220$\251A\245\f(\371\263\314\242\353\260\272\367\276\"\031\224$\244\311W\307Oe\224\0017\336\325A\305\027\341\261\331x\353\0372\3643",
287
+ },
288
+ "hmac-sha1" => {
289
+ false => "\361\026\313!\31235|w~\n\261\257\277\e\277b\246b\342\333\eE\021N\345\343m\314\272\315\376\235J\004f\262\3730t\376\273\323n\260\275\202\223\214\370D\204",
290
+ :standard => "\375i\253\004\311E\2011)\220$\251A\245\f(\371\263\314\242\353\260\272\367\276\"\031\224$\244\311W\307Oe\224\0017\336\325\345\a{|\0367\355\2735\310'\n\342\250\246\030*1\353\330",
291
+ },
292
+ "hmac-sha1-96" => {
293
+ false => "\361\026\313!\31235|w~\n\261\257\277\e\277b\246b\342\333\eE\021N\345\343m\314\272\315\376\235J\004f\262\3730t\376\273\323n",
294
+ :standard => "\375i\253\004\311E\2011)\220$\251A\245\f(\371\263\314\242\353\260\272\367\276\"\031\224$\244\311W\307Oe\224\0017\336\325\345\a{|\0367\355\2735\310'\n",
295
+ },
296
+ "none" => {
297
+ false => "\361\026\313!\31235|w~\n\261\257\277\e\277b\246b\342\333\eE\021N\345\343m\314\272\315\376",
298
+ :standard => "\375i\253\004\311E\2011)\220$\251A\245\f(\371\263\314\242\353\260\272\367\276\"\031\224$\244\311W\307Oe\224\0017\336\325",
299
+ },
300
+ },
301
+ "idea-cbc" => {
302
+ "hmac-md5" => {
303
+ false => "\342\255\202$\273\201\025#\245\2341F\263\005@{\000<\266&s\016\251NH=J\322/\220 H#[\343\200Sb\377\265\322\003=S\255N\2654",
304
+ :standard => "F\3048\360\357\265\215I\021)\a\254/\315%\354M\004\330\006\356\vFr\250K\225\223x\277+Q)\022\327\311K\025\322\317A\305\027\341\261\331x\353\0372\3643h`\177\202",
305
+ },
306
+ "hmac-md5-96" => {
307
+ false => "\342\255\202$\273\201\025#\245\2341F\263\005@{\000<\266&s\016\251NH=J\322/\220 H#[\343\200Sb\377\265\322\003=S",
308
+ :standard => "F\3048\360\357\265\215I\021)\a\254/\315%\354M\004\330\006\356\vFr\250K\225\223x\277+Q)\022\327\311K\025\322\317A\305\027\341\261\331x\353\0372\3643",
309
+ },
310
+ "hmac-sha1" => {
311
+ false => "\342\255\202$\273\201\025#\245\2341F\263\005@{\000<\266&s\016\251NH=J\322/\220 H\235J\004f\262\3730t\376\273\323n\260\275\202\223\214\370D\204",
312
+ :standard => "F\3048\360\357\265\215I\021)\a\254/\315%\354M\004\330\006\356\vFr\250K\225\223x\277+Q)\022\327\311K\025\322\317\345\a{|\0367\355\2735\310'\n\342\250\246\030*1\353\330",
313
+ },
314
+ "hmac-sha1-96" => {
315
+ false => "\342\255\202$\273\201\025#\245\2341F\263\005@{\000<\266&s\016\251NH=J\322/\220 H\235J\004f\262\3730t\376\273\323n",
316
+ :standard => "F\3048\360\357\265\215I\021)\a\254/\315%\354M\004\330\006\356\vFr\250K\225\223x\277+Q)\022\327\311K\025\322\317\345\a{|\0367\355\2735\310'\n",
317
+ },
318
+ "none" => {
319
+ false => "\342\255\202$\273\201\025#\245\2341F\263\005@{\000<\266&s\016\251NH=J\322/\220 H",
320
+ :standard => "F\3048\360\357\265\215I\021)\a\254/\315%\354M\004\330\006\356\vFr\250K\225\223x\277+Q)\022\327\311K\025\322\317",
321
+ },
322
+ },
323
+ "none" => {
324
+ "hmac-md5" => {
325
+ false => "\000\000\000\034\b\004\001\000\000\000\tdebugging\000\000\000\000\b\030CgWO\260\212#[\343\200Sb\377\265\322\003=S\255N\2654",
326
+ :standard => "\000\000\000$\tx\234bad``\340LIM*MO\317\314K\ar\030\000\000\000\000\377\377\b\030CgWO\260\212^A\305\027\341\261\331x\353\0372\3643h`\177\202",
327
+ },
328
+ "hmac-md5-96" => {
329
+ false => "\000\000\000\034\b\004\001\000\000\000\tdebugging\000\000\000\000\b\030CgWO\260\212#[\343\200Sb\377\265\322\003=S",
330
+ :standard => "\000\000\000$\tx\234bad``\340LIM*MO\317\314K\ar\030\000\000\000\000\377\377\b\030CgWO\260\212^A\305\027\341\261\331x\353\0372\3643",
331
+ },
332
+ "hmac-sha1" => {
333
+ false => "\000\000\000\034\b\004\001\000\000\000\tdebugging\000\000\000\000\b\030CgWO\260\212\235J\004f\262\3730t\376\273\323n\260\275\202\223\214\370D\204",
334
+ :standard => "\000\000\000$\tx\234bad``\340LIM*MO\317\314K\ar\030\000\000\000\000\377\377\b\030CgWO\260\212^\345\a{|\0367\355\2735\310'\n\342\250\246\030*1\353\330",
335
+ },
336
+ "hmac-sha1-96" => {
337
+ false => "\000\000\000\034\b\004\001\000\000\000\tdebugging\000\000\000\000\b\030CgWO\260\212\235J\004f\262\3730t\376\273\323n",
338
+ :standard => "\000\000\000$\tx\234bad``\340LIM*MO\317\314K\ar\030\000\000\000\000\377\377\b\030CgWO\260\212^\345\a{|\0367\355\2735\310'\n",
339
+ },
340
+ "none" => {
341
+ false => "\000\000\000\034\b\004\001\000\000\000\tdebugging\000\000\000\000\b\030CgWO\260\212",
342
+ :standard => "\000\000\000$\tx\234bad``\340LIM*MO\317\314K\ar\030\000\000\000\000\377\377\b\030CgWO\260\212^",
343
+ },
344
+ },
345
+ "rijndael-cbc@lysator.liu.se" => {
346
+ "hmac-md5" => {
347
+ false => "\266\001oG(\201s\255[\202j\031-\354\353]\022\374\367j2\257\b#\273r\275\341\232\264\255\340#[\343\200Sb\377\265\322\003=S\255N\2654",
348
+ :standard => "\251!O/_\253\321\217e\225\202\202W\261p\r\357\357\375\231\264Y,nZ/\366\225G\256\3000\036\223\237\353\265vG\231\215cvY\236%\315\365\337\227`9L\324[bPd\253XY\205\241\310",
349
+ },
350
+ "hmac-md5-96" => {
351
+ false => "\266\001oG(\201s\255[\202j\031-\354\353]\022\374\367j2\257\b#\273r\275\341\232\264\255\340#[\343\200Sb\377\265\322\003=S",
352
+ :standard => "\251!O/_\253\321\217e\225\202\202W\261p\r\357\357\375\231\264Y,nZ/\366\225G\256\3000\036\223\237\353\265vG\231\215cvY\236%\315\365\337\227`9L\324[bPd\253X",
353
+ },
354
+ "hmac-sha1" => {
355
+ false => "\266\001oG(\201s\255[\202j\031-\354\353]\022\374\367j2\257\b#\273r\275\341\232\264\255\340\235J\004f\262\3730t\376\273\323n\260\275\202\223\214\370D\204",
356
+ :standard => "\251!O/_\253\321\217e\225\202\202W\261p\r\357\357\375\231\264Y,nZ/\366\225G\256\3000\036\223\237\353\265vG\231\215cvY\236%\315\365\314\r\224%\316I\370t\251\372]\031\322pH%\267\337r\247",
357
+ },
358
+ "hmac-sha1-96" => {
359
+ false => "\266\001oG(\201s\255[\202j\031-\354\353]\022\374\367j2\257\b#\273r\275\341\232\264\255\340\235J\004f\262\3730t\376\273\323n",
360
+ :standard => "\251!O/_\253\321\217e\225\202\202W\261p\r\357\357\375\231\264Y,nZ/\366\225G\256\3000\036\223\237\353\265vG\231\215cvY\236%\315\365\314\r\224%\316I\370t\251\372]\031",
361
+ },
362
+ "none" => {
363
+ false => "\266\001oG(\201s\255[\202j\031-\354\353]\022\374\367j2\257\b#\273r\275\341\232\264\255\340",
364
+ :standard => "\251!O/_\253\321\217e\225\202\202W\261p\r\357\357\375\231\264Y,nZ/\366\225G\256\3000\036\223\237\353\265vG\231\215cvY\236%\315\365",
365
+ },
366
+ },
367
+ }
368
+
369
+ ciphers = Net::SSH::Transport::CipherFactory::SSH_TO_OSSL.keys
370
+ hmacs = Net::SSH::Transport::HMAC::MAP.keys
371
+
372
+ ciphers.each do |cipher_name|
373
+ next unless Net::SSH::Transport::CipherFactory.supported?(cipher_name)
374
+
375
+ hmacs.each do |hmac_name|
376
+ [false, :standard].each do |compress|
377
+ cipher_method_name = cipher_name.gsub(/\W/, "_")
378
+ hmac_method_name = hmac_name.gsub(/\W/, "_")
379
+
380
+ define_method("test_next_packet_with_#{cipher_method_name}_and_#{hmac_method_name}_and_#{compress}_compression") do
381
+ cipher = Net::SSH::Transport::CipherFactory.get(cipher_name, :key => "ABC", :iv => "abc", :shared => "123", :digester => OpenSSL::Digest::SHA1, :hash => "^&*", :decrypt => true)
382
+ hmac = Net::SSH::Transport::HMAC.get(hmac_name, "{}|")
383
+
384
+ stream.server.set :cipher => cipher, :hmac => hmac, :compression => compress
385
+ stream.stubs(:recv).returns(PACKETS[cipher_name][hmac_name][compress])
386
+ IO.stubs(:select).returns([[stream]])
387
+ packet = stream.next_packet(:nonblock)
388
+ assert_not_nil packet
389
+ assert_equal DEBUG, packet.type
390
+ assert packet[:always_display]
391
+ assert_equal "debugging", packet[:message]
392
+ assert_equal "", packet[:language]
393
+ stream.cleanup
394
+ end
395
+
396
+ define_method("test_enqueue_packet_with_#{cipher_method_name}_and_#{hmac_method_name}_and_#{compress}_compression") do
397
+ cipher = Net::SSH::Transport::CipherFactory.get(cipher_name, :key => "ABC", :iv => "abc", :shared => "123", :digester => OpenSSL::Digest::SHA1, :hash => "^&*", :encrypt => true)
398
+ hmac = Net::SSH::Transport::HMAC.get(hmac_name, "{}|")
399
+
400
+ srand(100)
401
+ stream.client.set :cipher => cipher, :hmac => hmac, :compression => compress
402
+ stream.enqueue_packet(ssh_packet)
403
+ assert_equal stream.write_buffer, PACKETS[cipher_name][hmac_name][compress]
404
+ stream.cleanup
405
+ end
406
+ end
407
+ end
408
+ end
409
+
410
+ private
411
+
412
+ def stream
413
+ @stream ||= begin
414
+ stream = mock("packet_stream")
415
+ stream.extend(Net::SSH::Transport::PacketStream)
416
+ stream
417
+ end
418
+ end
419
+
420
+ def ssh_packet
421
+ Net::SSH::Buffer.from(:byte, DEBUG, :bool, true, :string, "debugging", :string, "")
422
+ end
423
+
424
+ def packet
425
+ @packet ||= begin
426
+ data = ssh_packet
427
+ length = data.length + 4 + 1 # length + padding length
428
+ padding = stream.server.cipher.block_size - (length % stream.server.cipher.block_size)
429
+ padding += stream.server.cipher.block_size if padding < 4
430
+ Net::SSH::Buffer.from(:long, length + padding - 4, :byte, padding, :raw, data, :raw, "\0" * padding).to_s
431
+ end
432
+ end
433
+ end
434
+
435
+ end