net-ssh 1.1.4 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +37 -0
- data/Manifest +101 -0
- data/README.rdoc +110 -0
- data/Rakefile +26 -0
- data/{THANKS → THANKS.rdoc} +2 -5
- data/lib/net/ssh.rb +189 -57
- data/lib/net/ssh/authentication/agent.rb +175 -0
- data/lib/net/ssh/authentication/constants.rb +18 -0
- data/lib/net/ssh/authentication/key_manager.rb +166 -0
- data/lib/net/ssh/authentication/methods/abstract.rb +60 -0
- data/lib/net/ssh/authentication/methods/hostbased.rb +71 -0
- data/lib/net/ssh/authentication/methods/keyboard_interactive.rb +66 -0
- data/lib/net/ssh/authentication/methods/password.rb +39 -0
- data/lib/net/ssh/authentication/methods/publickey.rb +92 -0
- data/lib/net/ssh/authentication/pageant.rb +176 -0
- data/lib/net/ssh/authentication/session.rb +116 -0
- data/lib/net/ssh/buffer.rb +339 -0
- data/lib/net/ssh/buffered_io.rb +149 -0
- data/lib/net/ssh/config.rb +173 -0
- data/lib/net/ssh/connection/channel.rb +575 -454
- data/lib/net/ssh/connection/constants.rb +31 -45
- data/lib/net/ssh/connection/session.rb +569 -0
- data/lib/net/ssh/connection/term.rb +176 -88
- data/lib/net/ssh/errors.rb +83 -61
- data/lib/net/ssh/key_factory.rb +85 -0
- data/lib/net/ssh/known_hosts.rb +129 -0
- data/lib/net/ssh/loggable.rb +61 -0
- data/lib/net/ssh/packet.rb +102 -0
- data/lib/net/ssh/prompt.rb +93 -0
- data/lib/net/ssh/proxy/errors.rb +8 -28
- data/lib/net/ssh/proxy/http.rb +75 -107
- data/lib/net/ssh/proxy/socks4.rb +35 -48
- data/lib/net/ssh/proxy/socks5.rb +76 -108
- data/lib/net/ssh/service/forward.rb +267 -0
- data/lib/net/ssh/test.rb +89 -0
- data/lib/net/ssh/test/channel.rb +129 -0
- data/lib/net/ssh/test/extensions.rb +152 -0
- data/lib/net/ssh/test/kex.rb +44 -0
- data/lib/net/ssh/test/local_packet.rb +51 -0
- data/lib/net/ssh/test/packet.rb +81 -0
- data/lib/net/ssh/test/remote_packet.rb +38 -0
- data/lib/net/ssh/test/script.rb +157 -0
- data/lib/net/ssh/test/socket.rb +59 -0
- data/lib/net/ssh/transport/algorithms.rb +384 -0
- data/lib/net/ssh/transport/cipher_factory.rb +72 -0
- data/lib/net/ssh/transport/constants.rb +22 -58
- data/lib/net/ssh/transport/hmac.rb +31 -0
- data/lib/net/ssh/transport/hmac/abstract.rb +48 -0
- data/lib/net/ssh/transport/hmac/md5.rb +12 -0
- data/lib/net/ssh/transport/hmac/md5_96.rb +11 -0
- data/lib/net/ssh/transport/hmac/none.rb +15 -0
- data/lib/net/ssh/transport/hmac/sha1.rb +13 -0
- data/lib/net/ssh/transport/hmac/sha1_96.rb +11 -0
- data/lib/net/ssh/transport/identity_cipher.rb +40 -0
- data/lib/net/ssh/transport/kex.rb +13 -0
- data/lib/net/ssh/transport/kex/diffie_hellman_group1_sha1.rb +208 -0
- data/lib/net/ssh/transport/kex/diffie_hellman_group_exchange_sha1.rb +77 -0
- data/lib/net/ssh/{util → transport}/openssl.rb +22 -40
- data/lib/net/ssh/transport/packet_stream.rb +230 -0
- data/lib/net/ssh/transport/server_version.rb +61 -0
- data/lib/net/ssh/transport/session.rb +225 -303
- data/lib/net/ssh/transport/state.rb +170 -0
- data/lib/net/ssh/verifiers/lenient.rb +30 -0
- data/lib/net/ssh/verifiers/null.rb +12 -0
- data/lib/net/ssh/verifiers/strict.rb +53 -0
- data/lib/net/ssh/version.rb +57 -26
- data/net-ssh.gemspec +54 -0
- data/setup.rb +1585 -0
- data/test/authentication/methods/common.rb +28 -0
- data/test/authentication/methods/test_abstract.rb +51 -0
- data/test/authentication/methods/test_hostbased.rb +108 -0
- data/test/authentication/methods/test_keyboard_interactive.rb +98 -0
- data/test/authentication/methods/test_password.rb +50 -0
- data/test/authentication/methods/test_publickey.rb +123 -0
- data/test/authentication/test_agent.rb +205 -0
- data/test/authentication/test_key_manager.rb +100 -0
- data/test/authentication/test_session.rb +93 -0
- data/test/common.rb +106 -0
- data/test/configs/exact_match +8 -0
- data/test/configs/wild_cards +14 -0
- data/test/connection/test_channel.rb +452 -0
- data/test/connection/test_session.rb +483 -0
- data/test/test_all.rb +6 -0
- data/test/test_buffer.rb +336 -0
- data/test/test_buffered_io.rb +63 -0
- data/test/test_config.rb +78 -0
- data/test/test_key_factory.rb +67 -0
- data/test/transport/hmac/test_md5.rb +34 -0
- data/test/transport/hmac/test_md5_96.rb +25 -0
- data/test/transport/hmac/test_none.rb +34 -0
- data/test/transport/hmac/test_sha1.rb +34 -0
- data/test/transport/hmac/test_sha1_96.rb +25 -0
- data/test/transport/kex/test_diffie_hellman_group1_sha1.rb +146 -0
- data/test/transport/kex/test_diffie_hellman_group_exchange_sha1.rb +92 -0
- data/test/transport/test_algorithms.rb +302 -0
- data/test/transport/test_cipher_factory.rb +163 -0
- data/test/transport/test_hmac.rb +34 -0
- data/test/transport/test_identity_cipher.rb +40 -0
- data/test/transport/test_packet_stream.rb +433 -0
- data/test/transport/test_server_version.rb +55 -0
- data/test/transport/test_session.rb +312 -0
- data/test/transport/test_state.rb +173 -0
- metadata +102 -253
- data/ChangeLog +0 -560
- data/LICENSE +0 -7
- data/NEWS +0 -152
- data/README +0 -14
- data/bin/rb-keygen +0 -210
- data/doc/LICENSE-BSD +0 -27
- data/doc/LICENSE-GPL +0 -280
- data/doc/LICENSE-RUBY +0 -56
- data/doc/manual-html/chapter-1.html +0 -388
- data/doc/manual-html/chapter-2.html +0 -552
- data/doc/manual-html/chapter-3.html +0 -470
- data/doc/manual-html/chapter-4.html +0 -413
- data/doc/manual-html/chapter-5.html +0 -525
- data/doc/manual-html/chapter-6.html +0 -456
- data/doc/manual-html/chapter-7.html +0 -343
- data/doc/manual-html/index.html +0 -235
- data/doc/manual-html/stylesheets/manual.css +0 -270
- data/doc/manual-html/stylesheets/ruby.css +0 -17
- data/doc/manual/chapter.erb +0 -38
- data/doc/manual/example.erb +0 -18
- data/doc/manual/index.erb +0 -29
- data/doc/manual/manual.rb +0 -311
- data/doc/manual/manual.yml +0 -73
- data/doc/manual/page.erb +0 -87
- data/doc/manual/parts/0000.txt +0 -5
- data/doc/manual/parts/0001.txt +0 -3
- data/doc/manual/parts/0002.txt +0 -40
- data/doc/manual/parts/0003.txt +0 -6
- data/doc/manual/parts/0004.txt +0 -7
- data/doc/manual/parts/0005.txt +0 -1
- data/doc/manual/parts/0006.txt +0 -49
- data/doc/manual/parts/0007.txt +0 -67
- data/doc/manual/parts/0008.txt +0 -43
- data/doc/manual/parts/0009.txt +0 -14
- data/doc/manual/parts/0010.txt +0 -7
- data/doc/manual/parts/0011.txt +0 -14
- data/doc/manual/parts/0012.txt +0 -3
- data/doc/manual/parts/0013.txt +0 -20
- data/doc/manual/parts/0014.txt +0 -32
- data/doc/manual/parts/0015.txt +0 -14
- data/doc/manual/parts/0016.txt +0 -28
- data/doc/manual/parts/0017.txt +0 -50
- data/doc/manual/parts/0018.txt +0 -35
- data/doc/manual/parts/0019.txt +0 -7
- data/doc/manual/parts/0020.txt +0 -72
- data/doc/manual/parts/0021.txt +0 -50
- data/doc/manual/parts/0022.txt +0 -42
- data/doc/manual/parts/0023.txt +0 -51
- data/doc/manual/parts/0024.txt +0 -18
- data/doc/manual/parts/0025.txt +0 -18
- data/doc/manual/parts/0026.txt +0 -15
- data/doc/manual/parts/0027.txt +0 -37
- data/doc/manual/parts/0028.txt +0 -16
- data/doc/manual/parts/0029.txt +0 -1
- data/doc/manual/parts/0030.txt +0 -52
- data/doc/manual/parts/0031.txt +0 -25
- data/doc/manual/stylesheets/manual.css +0 -270
- data/doc/manual/stylesheets/ruby.css +0 -17
- data/doc/manual/tutorial.erb +0 -30
- data/examples/auth-forward.rb +0 -41
- data/examples/channel-demo.rb +0 -81
- data/examples/port-forward.rb +0 -51
- data/examples/process-demo.rb +0 -91
- data/examples/remote-net-port-forward.rb +0 -45
- data/examples/remote-port-forward.rb +0 -80
- data/examples/shell-demo.rb +0 -46
- data/examples/ssh-client.rb +0 -67
- data/examples/sync-shell-demo.rb +0 -69
- data/examples/tail-demo.rb +0 -49
- data/lib/net/ssh/connection/driver.rb +0 -446
- data/lib/net/ssh/connection/services.rb +0 -72
- data/lib/net/ssh/host-key-verifier.rb +0 -52
- data/lib/net/ssh/known-hosts.rb +0 -96
- data/lib/net/ssh/lenient-host-key-verifier.rb +0 -25
- data/lib/net/ssh/null-host-key-verifier.rb +0 -14
- data/lib/net/ssh/service/agentforward/driver.rb +0 -78
- data/lib/net/ssh/service/agentforward/services.rb +0 -41
- data/lib/net/ssh/service/forward/driver.rb +0 -319
- data/lib/net/ssh/service/forward/local-network-handler.rb +0 -71
- data/lib/net/ssh/service/forward/remote-network-handler.rb +0 -83
- data/lib/net/ssh/service/forward/services.rb +0 -76
- data/lib/net/ssh/service/process/driver.rb +0 -153
- data/lib/net/ssh/service/process/open.rb +0 -193
- data/lib/net/ssh/service/process/popen3.rb +0 -178
- data/lib/net/ssh/service/process/services.rb +0 -66
- data/lib/net/ssh/service/services.rb +0 -60
- data/lib/net/ssh/service/shell/driver.rb +0 -86
- data/lib/net/ssh/service/shell/services.rb +0 -54
- data/lib/net/ssh/service/shell/shell.rb +0 -222
- data/lib/net/ssh/service/shell/sync.rb +0 -114
- data/lib/net/ssh/session.rb +0 -305
- data/lib/net/ssh/transport/algorithm-negotiator.rb +0 -275
- data/lib/net/ssh/transport/compress/compressor.rb +0 -53
- data/lib/net/ssh/transport/compress/decompressor.rb +0 -53
- data/lib/net/ssh/transport/compress/none-compressor.rb +0 -39
- data/lib/net/ssh/transport/compress/none-decompressor.rb +0 -39
- data/lib/net/ssh/transport/compress/services.rb +0 -68
- data/lib/net/ssh/transport/compress/zlib-compressor.rb +0 -60
- data/lib/net/ssh/transport/compress/zlib-decompressor.rb +0 -52
- data/lib/net/ssh/transport/errors.rb +0 -47
- data/lib/net/ssh/transport/identity-cipher.rb +0 -61
- data/lib/net/ssh/transport/kex/dh-gex.rb +0 -106
- data/lib/net/ssh/transport/kex/dh.rb +0 -249
- data/lib/net/ssh/transport/kex/services.rb +0 -62
- data/lib/net/ssh/transport/ossl/buffer-factory.rb +0 -52
- data/lib/net/ssh/transport/ossl/buffer.rb +0 -87
- data/lib/net/ssh/transport/ossl/cipher-factory.rb +0 -98
- data/lib/net/ssh/transport/ossl/digest-factory.rb +0 -51
- data/lib/net/ssh/transport/ossl/hmac-factory.rb +0 -71
- data/lib/net/ssh/transport/ossl/hmac/hmac.rb +0 -62
- data/lib/net/ssh/transport/ossl/hmac/md5-96.rb +0 -44
- data/lib/net/ssh/transport/ossl/hmac/md5.rb +0 -46
- data/lib/net/ssh/transport/ossl/hmac/none.rb +0 -46
- data/lib/net/ssh/transport/ossl/hmac/services.rb +0 -68
- data/lib/net/ssh/transport/ossl/hmac/sha1-96.rb +0 -44
- data/lib/net/ssh/transport/ossl/hmac/sha1.rb +0 -45
- data/lib/net/ssh/transport/ossl/key-factory.rb +0 -116
- data/lib/net/ssh/transport/ossl/services.rb +0 -149
- data/lib/net/ssh/transport/packet-stream.rb +0 -236
- data/lib/net/ssh/transport/services.rb +0 -146
- data/lib/net/ssh/transport/version-negotiator.rb +0 -73
- data/lib/net/ssh/userauth/agent.rb +0 -222
- data/lib/net/ssh/userauth/constants.rb +0 -35
- data/lib/net/ssh/userauth/driver.rb +0 -183
- data/lib/net/ssh/userauth/methods/hostbased.rb +0 -119
- data/lib/net/ssh/userauth/methods/keyboard-interactive.rb +0 -104
- data/lib/net/ssh/userauth/methods/password.rb +0 -70
- data/lib/net/ssh/userauth/methods/publickey.rb +0 -137
- data/lib/net/ssh/userauth/methods/services.rb +0 -90
- data/lib/net/ssh/userauth/pageant.rb +0 -197
- data/lib/net/ssh/userauth/services.rb +0 -141
- data/lib/net/ssh/userauth/userkeys.rb +0 -258
- data/lib/net/ssh/util/buffer.rb +0 -274
- data/lib/net/ssh/util/prompter.rb +0 -73
- data/test/ALL-TESTS.rb +0 -18
- data/test/connection/tc_channel.rb +0 -136
- data/test/connection/tc_driver.rb +0 -287
- data/test/connection/tc_integration.rb +0 -87
- data/test/proxy/tc_http.rb +0 -209
- data/test/proxy/tc_socks4.rb +0 -148
- data/test/proxy/tc_socks5.rb +0 -214
- data/test/service/agentforward/tc_driver.rb +0 -138
- data/test/service/forward/tc_driver.rb +0 -289
- data/test/service/forward/tc_local_network_handler.rb +0 -123
- data/test/service/forward/tc_remote_network_handler.rb +0 -111
- data/test/service/process/tc_driver.rb +0 -79
- data/test/service/process/tc_integration.rb +0 -119
- data/test/service/process/tc_open.rb +0 -179
- data/test/service/process/tc_popen3.rb +0 -164
- data/test/tc_integration.rb +0 -80
- data/test/transport/compress/tc_none_compress.rb +0 -41
- data/test/transport/compress/tc_none_decompress.rb +0 -45
- data/test/transport/compress/tc_zlib_compress.rb +0 -61
- data/test/transport/compress/tc_zlib_decompress.rb +0 -48
- data/test/transport/kex/tc_dh.rb +0 -312
- data/test/transport/kex/tc_dh_gex.rb +0 -71
- data/test/transport/ossl/fixtures/dsa-encrypted +0 -15
- data/test/transport/ossl/fixtures/dsa-encrypted-bad +0 -15
- data/test/transport/ossl/fixtures/dsa-unencrypted +0 -12
- data/test/transport/ossl/fixtures/dsa-unencrypted-bad +0 -12
- data/test/transport/ossl/fixtures/dsa-unencrypted.pub +0 -1
- data/test/transport/ossl/fixtures/not-a-private-key +0 -4
- data/test/transport/ossl/fixtures/not-supported +0 -2
- data/test/transport/ossl/fixtures/rsa-encrypted +0 -18
- data/test/transport/ossl/fixtures/rsa-encrypted-bad +0 -18
- data/test/transport/ossl/fixtures/rsa-unencrypted +0 -15
- data/test/transport/ossl/fixtures/rsa-unencrypted-bad +0 -15
- data/test/transport/ossl/fixtures/rsa-unencrypted.pub +0 -1
- data/test/transport/ossl/hmac/tc_hmac.rb +0 -58
- data/test/transport/ossl/hmac/tc_md5.rb +0 -50
- data/test/transport/ossl/hmac/tc_md5_96.rb +0 -50
- data/test/transport/ossl/hmac/tc_none.rb +0 -50
- data/test/transport/ossl/hmac/tc_sha1.rb +0 -50
- data/test/transport/ossl/hmac/tc_sha1_96.rb +0 -50
- data/test/transport/ossl/tc_buffer.rb +0 -97
- data/test/transport/ossl/tc_buffer_factory.rb +0 -67
- data/test/transport/ossl/tc_cipher_factory.rb +0 -84
- data/test/transport/ossl/tc_digest_factory.rb +0 -39
- data/test/transport/ossl/tc_hmac_factory.rb +0 -72
- data/test/transport/ossl/tc_key_factory.rb +0 -199
- data/test/transport/tc_algorithm_negotiator.rb +0 -170
- data/test/transport/tc_identity_cipher.rb +0 -52
- data/test/transport/tc_integration.rb +0 -115
- data/test/transport/tc_packet_stream.rb +0 -184
- data/test/transport/tc_session.rb +0 -296
- data/test/transport/tc_version_negotiator.rb +0 -86
- data/test/userauth/methods/tc_hostbased.rb +0 -136
- data/test/userauth/methods/tc_password.rb +0 -89
- data/test/userauth/methods/tc_publickey.rb +0 -167
- data/test/userauth/tc_agent.rb +0 -223
- data/test/userauth/tc_driver.rb +0 -190
- data/test/userauth/tc_integration.rb +0 -97
- data/test/userauth/tc_userkeys.rb +0 -265
- data/test/util/tc_buffer.rb +0 -217
@@ -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,433 @@
|
|
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
|
+
hmacs.each do |hmac_name|
|
374
|
+
[false, :standard].each do |compress|
|
375
|
+
cipher_method_name = cipher_name.gsub(/\W/, "_")
|
376
|
+
hmac_method_name = hmac_name.gsub(/\W/, "_")
|
377
|
+
|
378
|
+
define_method("test_next_packet_with_#{cipher_method_name}_and_#{hmac_method_name}_and_#{compress}_compression") do
|
379
|
+
cipher = Net::SSH::Transport::CipherFactory.get(cipher_name, :key => "ABC", :iv => "abc", :shared => "123", :digester => OpenSSL::Digest::SHA1, :hash => "^&*", :decrypt => true)
|
380
|
+
hmac = Net::SSH::Transport::HMAC.get(hmac_name, "{}|")
|
381
|
+
|
382
|
+
stream.server.set :cipher => cipher, :hmac => hmac, :compression => compress
|
383
|
+
stream.stubs(:recv).returns(PACKETS[cipher_name][hmac_name][compress])
|
384
|
+
IO.stubs(:select).returns([[stream]])
|
385
|
+
packet = stream.next_packet(:nonblock)
|
386
|
+
assert_not_nil packet
|
387
|
+
assert_equal DEBUG, packet.type
|
388
|
+
assert packet[:always_display]
|
389
|
+
assert_equal "debugging", packet[:message]
|
390
|
+
assert_equal "", packet[:language]
|
391
|
+
stream.cleanup
|
392
|
+
end
|
393
|
+
|
394
|
+
define_method("test_enqueue_packet_with_#{cipher_method_name}_and_#{hmac_method_name}_and_#{compress}_compression") do
|
395
|
+
cipher = Net::SSH::Transport::CipherFactory.get(cipher_name, :key => "ABC", :iv => "abc", :shared => "123", :digester => OpenSSL::Digest::SHA1, :hash => "^&*", :encrypt => true)
|
396
|
+
hmac = Net::SSH::Transport::HMAC.get(hmac_name, "{}|")
|
397
|
+
|
398
|
+
srand(100)
|
399
|
+
stream.client.set :cipher => cipher, :hmac => hmac, :compression => compress
|
400
|
+
stream.enqueue_packet(ssh_packet)
|
401
|
+
assert_equal stream.write_buffer, PACKETS[cipher_name][hmac_name][compress]
|
402
|
+
stream.cleanup
|
403
|
+
end
|
404
|
+
end
|
405
|
+
end
|
406
|
+
end
|
407
|
+
|
408
|
+
private
|
409
|
+
|
410
|
+
def stream
|
411
|
+
@stream ||= begin
|
412
|
+
stream = mock("packet_stream")
|
413
|
+
stream.extend(Net::SSH::Transport::PacketStream)
|
414
|
+
stream
|
415
|
+
end
|
416
|
+
end
|
417
|
+
|
418
|
+
def ssh_packet
|
419
|
+
Net::SSH::Buffer.from(:byte, DEBUG, :bool, true, :string, "debugging", :string, "")
|
420
|
+
end
|
421
|
+
|
422
|
+
def packet
|
423
|
+
@packet ||= begin
|
424
|
+
data = ssh_packet
|
425
|
+
length = data.length + 4 + 1 # length + padding length
|
426
|
+
padding = stream.server.cipher.block_size - (length % stream.server.cipher.block_size)
|
427
|
+
padding += stream.server.cipher.block_size if padding < 4
|
428
|
+
Net::SSH::Buffer.from(:long, length + padding - 4, :byte, padding, :raw, data, :raw, "\0" * padding).to_s
|
429
|
+
end
|
430
|
+
end
|
431
|
+
end
|
432
|
+
|
433
|
+
end
|