minmb-net-ssh 2.5.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 (137) hide show
  1. data/CHANGELOG.rdoc +291 -0
  2. data/Manifest +132 -0
  3. data/README.rdoc +184 -0
  4. data/Rakefile +86 -0
  5. data/Rudyfile +96 -0
  6. data/THANKS.rdoc +19 -0
  7. data/lib/net/ssh.rb +223 -0
  8. data/lib/net/ssh/authentication/agent.rb +23 -0
  9. data/lib/net/ssh/authentication/agent/java_pageant.rb +85 -0
  10. data/lib/net/ssh/authentication/agent/socket.rb +170 -0
  11. data/lib/net/ssh/authentication/constants.rb +18 -0
  12. data/lib/net/ssh/authentication/key_manager.rb +253 -0
  13. data/lib/net/ssh/authentication/methods/abstract.rb +60 -0
  14. data/lib/net/ssh/authentication/methods/hostbased.rb +75 -0
  15. data/lib/net/ssh/authentication/methods/keyboard_interactive.rb +70 -0
  16. data/lib/net/ssh/authentication/methods/password.rb +43 -0
  17. data/lib/net/ssh/authentication/methods/publickey.rb +96 -0
  18. data/lib/net/ssh/authentication/pageant.rb +301 -0
  19. data/lib/net/ssh/authentication/session.rb +154 -0
  20. data/lib/net/ssh/buffer.rb +350 -0
  21. data/lib/net/ssh/buffered_io.rb +207 -0
  22. data/lib/net/ssh/config.rb +207 -0
  23. data/lib/net/ssh/connection/channel.rb +630 -0
  24. data/lib/net/ssh/connection/constants.rb +33 -0
  25. data/lib/net/ssh/connection/session.rb +603 -0
  26. data/lib/net/ssh/connection/term.rb +178 -0
  27. data/lib/net/ssh/errors.rb +88 -0
  28. data/lib/net/ssh/key_factory.rb +107 -0
  29. data/lib/net/ssh/known_hosts.rb +141 -0
  30. data/lib/net/ssh/loggable.rb +61 -0
  31. data/lib/net/ssh/packet.rb +102 -0
  32. data/lib/net/ssh/prompt.rb +93 -0
  33. data/lib/net/ssh/proxy/command.rb +75 -0
  34. data/lib/net/ssh/proxy/errors.rb +14 -0
  35. data/lib/net/ssh/proxy/http.rb +94 -0
  36. data/lib/net/ssh/proxy/socks4.rb +70 -0
  37. data/lib/net/ssh/proxy/socks5.rb +142 -0
  38. data/lib/net/ssh/ruby_compat.rb +77 -0
  39. data/lib/net/ssh/service/forward.rb +327 -0
  40. data/lib/net/ssh/test.rb +89 -0
  41. data/lib/net/ssh/test/channel.rb +129 -0
  42. data/lib/net/ssh/test/extensions.rb +152 -0
  43. data/lib/net/ssh/test/kex.rb +44 -0
  44. data/lib/net/ssh/test/local_packet.rb +51 -0
  45. data/lib/net/ssh/test/packet.rb +81 -0
  46. data/lib/net/ssh/test/remote_packet.rb +38 -0
  47. data/lib/net/ssh/test/script.rb +157 -0
  48. data/lib/net/ssh/test/socket.rb +64 -0
  49. data/lib/net/ssh/transport/algorithms.rb +407 -0
  50. data/lib/net/ssh/transport/cipher_factory.rb +106 -0
  51. data/lib/net/ssh/transport/constants.rb +32 -0
  52. data/lib/net/ssh/transport/ctr.rb +95 -0
  53. data/lib/net/ssh/transport/hmac.rb +45 -0
  54. data/lib/net/ssh/transport/hmac/abstract.rb +79 -0
  55. data/lib/net/ssh/transport/hmac/md5.rb +12 -0
  56. data/lib/net/ssh/transport/hmac/md5_96.rb +11 -0
  57. data/lib/net/ssh/transport/hmac/none.rb +15 -0
  58. data/lib/net/ssh/transport/hmac/ripemd160.rb +13 -0
  59. data/lib/net/ssh/transport/hmac/sha1.rb +13 -0
  60. data/lib/net/ssh/transport/hmac/sha1_96.rb +11 -0
  61. data/lib/net/ssh/transport/hmac/sha2_256.rb +15 -0
  62. data/lib/net/ssh/transport/hmac/sha2_256_96.rb +13 -0
  63. data/lib/net/ssh/transport/hmac/sha2_512.rb +14 -0
  64. data/lib/net/ssh/transport/hmac/sha2_512_96.rb +13 -0
  65. data/lib/net/ssh/transport/identity_cipher.rb +55 -0
  66. data/lib/net/ssh/transport/kex.rb +28 -0
  67. data/lib/net/ssh/transport/kex/diffie_hellman_group14_sha1.rb +44 -0
  68. data/lib/net/ssh/transport/kex/diffie_hellman_group1_sha1.rb +216 -0
  69. data/lib/net/ssh/transport/kex/diffie_hellman_group_exchange_sha1.rb +80 -0
  70. data/lib/net/ssh/transport/kex/diffie_hellman_group_exchange_sha256.rb +15 -0
  71. data/lib/net/ssh/transport/kex/ecdh_sha2_nistp256.rb +93 -0
  72. data/lib/net/ssh/transport/kex/ecdh_sha2_nistp384.rb +13 -0
  73. data/lib/net/ssh/transport/kex/ecdh_sha2_nistp521.rb +13 -0
  74. data/lib/net/ssh/transport/key_expander.rb +26 -0
  75. data/lib/net/ssh/transport/openssl.rb +237 -0
  76. data/lib/net/ssh/transport/packet_stream.rb +235 -0
  77. data/lib/net/ssh/transport/server_version.rb +71 -0
  78. data/lib/net/ssh/transport/session.rb +278 -0
  79. data/lib/net/ssh/transport/state.rb +206 -0
  80. data/lib/net/ssh/verifiers/lenient.rb +30 -0
  81. data/lib/net/ssh/verifiers/null.rb +12 -0
  82. data/lib/net/ssh/verifiers/strict.rb +53 -0
  83. data/lib/net/ssh/version.rb +62 -0
  84. data/net-ssh.gemspec +164 -0
  85. data/setup.rb +1585 -0
  86. data/support/arcfour_check.rb +20 -0
  87. data/support/ssh_tunnel_bug.rb +65 -0
  88. data/test/authentication/methods/common.rb +28 -0
  89. data/test/authentication/methods/test_abstract.rb +51 -0
  90. data/test/authentication/methods/test_hostbased.rb +114 -0
  91. data/test/authentication/methods/test_keyboard_interactive.rb +100 -0
  92. data/test/authentication/methods/test_password.rb +52 -0
  93. data/test/authentication/methods/test_publickey.rb +148 -0
  94. data/test/authentication/test_agent.rb +205 -0
  95. data/test/authentication/test_key_manager.rb +218 -0
  96. data/test/authentication/test_session.rb +106 -0
  97. data/test/common.rb +107 -0
  98. data/test/configs/eqsign +3 -0
  99. data/test/configs/exact_match +8 -0
  100. data/test/configs/host_plus +10 -0
  101. data/test/configs/multihost +4 -0
  102. data/test/configs/wild_cards +14 -0
  103. data/test/connection/test_channel.rb +467 -0
  104. data/test/connection/test_session.rb +488 -0
  105. data/test/known_hosts/github +1 -0
  106. data/test/test_all.rb +9 -0
  107. data/test/test_buffer.rb +426 -0
  108. data/test/test_buffered_io.rb +63 -0
  109. data/test/test_config.rb +120 -0
  110. data/test/test_key_factory.rb +121 -0
  111. data/test/test_known_hosts.rb +13 -0
  112. data/test/transport/hmac/test_md5.rb +39 -0
  113. data/test/transport/hmac/test_md5_96.rb +25 -0
  114. data/test/transport/hmac/test_none.rb +34 -0
  115. data/test/transport/hmac/test_ripemd160.rb +34 -0
  116. data/test/transport/hmac/test_sha1.rb +34 -0
  117. data/test/transport/hmac/test_sha1_96.rb +25 -0
  118. data/test/transport/hmac/test_sha2_256.rb +35 -0
  119. data/test/transport/hmac/test_sha2_256_96.rb +25 -0
  120. data/test/transport/hmac/test_sha2_512.rb +35 -0
  121. data/test/transport/hmac/test_sha2_512_96.rb +25 -0
  122. data/test/transport/kex/test_diffie_hellman_group14_sha1.rb +13 -0
  123. data/test/transport/kex/test_diffie_hellman_group1_sha1.rb +146 -0
  124. data/test/transport/kex/test_diffie_hellman_group_exchange_sha1.rb +92 -0
  125. data/test/transport/kex/test_diffie_hellman_group_exchange_sha256.rb +33 -0
  126. data/test/transport/kex/test_ecdh_sha2_nistp256.rb +161 -0
  127. data/test/transport/kex/test_ecdh_sha2_nistp384.rb +37 -0
  128. data/test/transport/kex/test_ecdh_sha2_nistp521.rb +37 -0
  129. data/test/transport/test_algorithms.rb +330 -0
  130. data/test/transport/test_cipher_factory.rb +441 -0
  131. data/test/transport/test_hmac.rb +34 -0
  132. data/test/transport/test_identity_cipher.rb +40 -0
  133. data/test/transport/test_packet_stream.rb +1745 -0
  134. data/test/transport/test_server_version.rb +78 -0
  135. data/test/transport/test_session.rb +315 -0
  136. data/test/transport/test_state.rb +179 -0
  137. metadata +208 -0
@@ -0,0 +1,120 @@
1
+ require 'common'
2
+ require 'net/ssh/config'
3
+
4
+ class TestConfig < Test::Unit::TestCase
5
+ def test_load_for_non_existant_file_should_return_empty_hash
6
+ bogus_file = File.expand_path("/bogus/file")
7
+ File.expects(:readable?).with(bogus_file).returns(false)
8
+ assert_equal({}, Net::SSH::Config.load(bogus_file, "host.name"))
9
+ end
10
+
11
+ def test_load_should_expand_path
12
+ expected = File.expand_path("~/.ssh/config")
13
+ File.expects(:readable?).with(expected).returns(false)
14
+ Net::SSH::Config.load("~/.ssh/config", "host.name")
15
+ end
16
+
17
+ def test_load_with_exact_host_match_should_load_that_section
18
+ config = Net::SSH::Config.load(config(:exact_match), "test.host")
19
+ assert config['compression']
20
+ assert config['forwardagent']
21
+ assert_equal 1234, config['port']
22
+ end
23
+
24
+ def test_load_with_wild_card_matches_should_load_all_matches_with_first_match_taking_precedence
25
+ config = Net::SSH::Config.load(config(:wild_cards), "test.host")
26
+ assert_equal 1234, config['port']
27
+ assert !config['compression']
28
+ assert config['forwardagent']
29
+ assert_equal %w(~/.ssh/id_dsa), config['identityfile']
30
+ assert !config.key?('rekeylimit')
31
+ end
32
+
33
+ def test_for_should_load_all_files_and_translate_to_net_ssh_options
34
+ config = Net::SSH::Config.for("test.host", [config(:exact_match), config(:wild_cards)])
35
+ assert_equal 1234, config[:port]
36
+ assert config[:compression]
37
+ assert config[:forward_agent]
38
+ assert_equal %w(~/.ssh/id_dsa), config[:keys]
39
+ assert !config.key?(:rekey_limit)
40
+ end
41
+
42
+ def test_load_with_no_host
43
+ config = Net::SSH::Config.load(config(:nohost), "test.host")
44
+ assert_equal %w(~/.ssh/id_dsa ~/.ssh/id_rsa), config['identityfile']
45
+ assert_equal 1985, config['port']
46
+ end
47
+
48
+ def test_load_with_multiple_hosts
49
+ config = Net::SSH::Config.load(config(:multihost), "test.host")
50
+ assert config['compression']
51
+ assert_equal '2G', config['rekeylimit']
52
+ assert_equal 1980, config['port']
53
+ end
54
+
55
+ def test_load_with_multiple_hosts_and_config_should_match_for_both
56
+ aconfig = Net::SSH::Config.load(config(:multihost), "test.host")
57
+ bconfig = Net::SSH::Config.load(config(:multihost), "other.host")
58
+ assert_equal aconfig['port'], bconfig['port']
59
+ assert_equal aconfig['compression'], bconfig['compression']
60
+ assert_equal aconfig['rekeylimit'], bconfig['rekeylimit']
61
+ end
62
+
63
+ def test_load_should_parse_equal_sign_delimiters
64
+ config = Net::SSH::Config.load(config(:eqsign), "test.test")
65
+ assert config['compression']
66
+ assert_equal 1234, config['port']
67
+ end
68
+
69
+ def test_translate_should_correctly_translate_from_openssh_to_net_ssh_names
70
+ open_ssh = {
71
+ 'bindaddress' => "127.0.0.1",
72
+ 'ciphers' => "a,b,c",
73
+ 'compression' => true,
74
+ 'compressionlevel' => 6,
75
+ 'connecttimeout' => 100,
76
+ 'forwardagent' => true,
77
+ 'hostbasedauthentication' => true,
78
+ 'hostkeyalgorithms' => "d,e,f",
79
+ 'identityfile' => %w(g h i),
80
+ 'macs' => "j,k,l",
81
+ 'passwordauthentication' => true,
82
+ 'port' => 1234,
83
+ 'pubkeyauthentication' => true,
84
+ 'rekeylimit' => 1024
85
+ }
86
+
87
+ net_ssh = Net::SSH::Config.translate(open_ssh)
88
+
89
+ assert_equal %w(a b c), net_ssh[:encryption]
90
+ assert_equal true, net_ssh[:compression]
91
+ assert_equal 6, net_ssh[:compression_level]
92
+ assert_equal 100, net_ssh[:timeout]
93
+ assert_equal true, net_ssh[:forward_agent]
94
+ assert_equal %w(hostbased password publickey), net_ssh[:auth_methods].sort
95
+ assert_equal %w(d e f), net_ssh[:host_key]
96
+ assert_equal %w(g h i), net_ssh[:keys]
97
+ assert_equal %w(j k l), net_ssh[:hmac]
98
+ assert_equal 1234, net_ssh[:port]
99
+ assert_equal 1024, net_ssh[:rekey_limit]
100
+ assert_equal "127.0.0.1", net_ssh[:bind_address]
101
+ end
102
+
103
+ def test_load_with_plus_sign_hosts
104
+ config = Net::SSH::Config.load(config(:host_plus), "test.host")
105
+ assert config['compression']
106
+ end
107
+
108
+ def test_load_with_numeric_host
109
+ config = Net::SSH::Config.load(config(:numeric_host), "1234")
110
+ assert config['compression']
111
+ assert_equal '2G', config['rekeylimit']
112
+ assert_equal 1980, config['port']
113
+ end
114
+
115
+ private
116
+
117
+ def config(name)
118
+ "test/configs/#{name}"
119
+ end
120
+ end
@@ -0,0 +1,121 @@
1
+ require 'common'
2
+ require 'net/ssh/key_factory'
3
+
4
+ class TestKeyFactory < Test::Unit::TestCase
5
+ def setup
6
+ @key_file = File.expand_path("/key-file")
7
+ end
8
+
9
+ def test_load_unencrypted_private_RSA_key_should_return_key
10
+ File.expects(:read).with(@key_file).returns(rsa_key.export)
11
+ assert_equal rsa_key.to_der, Net::SSH::KeyFactory.load_private_key(@key_file).to_der
12
+ end
13
+
14
+ def test_load_unencrypted_private_DSA_key_should_return_key
15
+ File.expects(:read).with(@key_file).returns(dsa_key.export)
16
+ assert_equal dsa_key.to_der, Net::SSH::KeyFactory.load_private_key(@key_file).to_der
17
+ end
18
+
19
+ def test_load_encrypted_private_RSA_key_should_prompt_for_password_and_return_key
20
+ File.expects(:read).with(@key_file).returns(encrypted(rsa_key, "password"))
21
+ Net::SSH::KeyFactory.expects(:prompt).with("Enter passphrase for #{@key_file}:", false).returns("password")
22
+ assert_equal rsa_key.to_der, Net::SSH::KeyFactory.load_private_key(@key_file).to_der
23
+ end
24
+
25
+ def test_load_encrypted_private_RSA_key_with_password_should_not_prompt_and_return_key
26
+ File.expects(:read).with(@key_file).returns(encrypted(rsa_key, "password"))
27
+ assert_equal rsa_key.to_der, Net::SSH::KeyFactory.load_private_key(@key_file, "password").to_der
28
+ end
29
+
30
+ def test_load_encrypted_private_DSA_key_should_prompt_for_password_and_return_key
31
+ File.expects(:read).with(@key_file).returns(encrypted(dsa_key, "password"))
32
+ Net::SSH::KeyFactory.expects(:prompt).with("Enter passphrase for #{@key_file}:", false).returns("password")
33
+ assert_equal dsa_key.to_der, Net::SSH::KeyFactory.load_private_key(@key_file).to_der
34
+ end
35
+
36
+ def test_load_encrypted_private_DSA_key_with_password_should_not_prompt_and_return_key
37
+ File.expects(:read).with(@key_file).returns(encrypted(dsa_key, "password"))
38
+ assert_equal dsa_key.to_der, Net::SSH::KeyFactory.load_private_key(@key_file, "password").to_der
39
+ end
40
+
41
+ def test_load_encrypted_private_key_should_give_three_tries_for_the_password_and_then_raise_exception
42
+ File.expects(:read).with(@key_file).returns(encrypted(rsa_key, "password"))
43
+ Net::SSH::KeyFactory.expects(:prompt).times(3).with("Enter passphrase for #{@key_file}:", false).returns("passwod","passphrase","passwd")
44
+ assert_raises(OpenSSL::PKey::RSAError) { Net::SSH::KeyFactory.load_private_key(@key_file) }
45
+ end
46
+
47
+ def test_load_encrypted_private_key_should_raise_exception_without_asking_passphrase
48
+ File.expects(:read).with(@key_file).returns(encrypted(rsa_key, "password"))
49
+ Net::SSH::KeyFactory.expects(:prompt).never
50
+ assert_raises(OpenSSL::PKey::RSAError) { Net::SSH::KeyFactory.load_private_key(@key_file, nil, false) }
51
+ end
52
+
53
+ def test_load_public_rsa_key_should_return_key
54
+ File.expects(:read).with(@key_file).returns(public(rsa_key))
55
+ assert_equal rsa_key.to_blob, Net::SSH::KeyFactory.load_public_key(@key_file).to_blob
56
+ end
57
+
58
+ if defined?(OpenSSL::PKey::EC)
59
+ def test_load_unencrypted_private_ecdsa_sha2_nistp256_key_should_return_key
60
+ File.expects(:read).with("/key-file").returns(ecdsa_sha2_nistp256_key.to_pem)
61
+ assert_equal ecdsa_sha2_nistp256_key.to_der, Net::SSH::KeyFactory.load_private_key("/key-file").to_der
62
+ end
63
+ def test_load_unencrypted_private_ecdsa_sha2_nistp384_key_should_return_key
64
+ File.expects(:read).with("/key-file").returns(ecdsa_sha2_nistp384_key.to_pem)
65
+ assert_equal ecdsa_sha2_nistp384_key.to_der, Net::SSH::KeyFactory.load_private_key("/key-file").to_der
66
+ end
67
+ def test_load_unencrypted_private_ecdsa_sha2_nistp521_key_should_return_key
68
+ File.expects(:read).with("/key-file").returns(ecdsa_sha2_nistp521_key.to_pem)
69
+ assert_equal ecdsa_sha2_nistp521_key.to_der, Net::SSH::KeyFactory.load_private_key("/key-file").to_der
70
+ end
71
+
72
+ def test_load_public_ecdsa_sha2_nistp256_key_should_return_key
73
+ File.expects(:read).with("/key-file").returns(public(ecdsa_sha2_nistp256_key))
74
+ assert_equal ecdsa_sha2_nistp256_key.to_blob, Net::SSH::KeyFactory.load_public_key("/key-file").to_blob
75
+ end
76
+ def test_load_public_ecdsa_sha2_nistp384_key_should_return_key
77
+ File.expects(:read).with("/key-file").returns(public(ecdsa_sha2_nistp384_key))
78
+ assert_equal ecdsa_sha2_nistp384_key.to_blob, Net::SSH::KeyFactory.load_public_key("/key-file").to_blob
79
+ end
80
+ def test_load_public_ecdsa_sha2_nistp521_key_should_return_key
81
+ File.expects(:read).with("/key-file").returns(public(ecdsa_sha2_nistp521_key))
82
+ assert_equal ecdsa_sha2_nistp521_key.to_blob, Net::SSH::KeyFactory.load_public_key("/key-file").to_blob
83
+ end
84
+ end
85
+
86
+ private
87
+
88
+ def rsa_key
89
+ # 512 bits
90
+ @rsa_key ||= OpenSSL::PKey::RSA.new("0\202\001;\002\001\000\002A\000\235\236\374N\e@2E\321\3757\003\354c\276N\f\003\3479Ko\005\317\0027\a\255=\345!\306\220\340\211;\027u\331\260\362\2063x\332\301y4\353\v%\032\214v\312\304\212\271GJ\353\2701\031\002\003\001\000\001\002@\022Y\306*\031\306\031\224Cde\231QV3{\306\256U\2477\377\017\000\020\323\363R\332\027\351\034\224OU\020\227H|pUS\n\263+%\304\341\321\273/\271\e\004L\250\273\020&,\t\304By\002!\000\311c\246%a\002\305\277\262R\266\244\250\025V_\351]\264\016\265\341\355\305\223\347Z$8\205#\023\002!\000\310\\\367|\243I\363\350\020\307\246\302\365\ed\212L\273\2158M\223w\a\367 C\t\224A4\243\002!\000\262]+}\327\231\331\002\2331^\312\036\204'g\363\f&\271\020\245\365-\024}\306\374e\202\2459\002 }\231\341\276\3551\277\307{5\\\361\233\353G\024wS\237\fk}\004\302&\205\277\340rb\211\327\002!\000\223\307\025I:\215_\260\370\252\3757\256Y&X\364\354\342\215\350\203E8\227|\f\237M\375D|")
91
+ end
92
+
93
+ def dsa_key
94
+ # 512 bits
95
+ @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")
96
+ end
97
+
98
+ if defined?(OpenSSL::PKey::EC)
99
+ def ecdsa_sha2_nistp256_key
100
+ @ecdsa_sha2_nistp256_key ||= OpenSSL::PKey::EC.new("-----BEGIN EC PRIVATE KEY-----\nMHcCAQEEINv6pPVLlkqvT1v5MJlWgaSWGwqupISG4U79bUXQDNCaoAoGCCqGSM49\nAwEHoUQDQgAElqubvi/GkSme+bwtncU1NiE0dWQ0EO07VufUQg8lUJ5+Fi6f96qa\n95T1zwOMQhY1h8PP9rQIZr4S48vN/ZnQLw==\n-----END EC PRIVATE KEY-----\n")
101
+ end
102
+
103
+ def ecdsa_sha2_nistp384_key
104
+ @ecdsa_sha2_nistp384_key ||= OpenSSL::PKey::EC.new("-----BEGIN EC PRIVATE KEY-----\nMIGkAgEBBDBxwkmydCn4mP4KMhlMpeBvIroQolWKVNoRPXpG7brFgK+Yiikqw8wd\nIZW5OlL4y3mgBwYFK4EEACKhZANiAARkoIR1oABi+aQJbKcmvzeYSKURQOyXM0HU\nR4T68v4hd/lJE4fFQRczj3wAaECe9u3CWI/oDlow4Vr0vab82ZGjIoblxblKQWYl\nyzENgzl226waGg1bLBo8Auilyf1B5yI=\n-----END EC PRIVATE KEY-----\n")
105
+ end
106
+
107
+ def ecdsa_sha2_nistp521_key
108
+ @ecdsa_sha2_nistp521_key ||= OpenSSL::PKey::EC.new("-----BEGIN EC PRIVATE KEY-----\nMIHbAgEBBEHQ2i7kjEGQHQB4pUQW9a2eCLWR2S5Go8U3CDyfbRCrYEp/pTSgI8uu\nMXyR3bf3SjqFQgZ6MZk5lkyrissJuwmvZKAHBgUrgQQAI6GBiQOBhgAEAN14FACK\nbs/KTqw4rxijeozGTVJTh1hNzBl2XaIhM4Fv8o3fE/pvogymyFu53GCng6gC4dmx\n/hycF41iIM29xVKPAeBnRNl6MdFBjuthOmE8eCRezgk1Bak8aBDUrzNT8OQssscw\npvQK4nc6ga/wTDaQGy5kV8tCOHNs2wKH+p2LpWTJ\n-----END EC PRIVATE KEY-----\n")
109
+ end
110
+ end
111
+
112
+ def encrypted(key, password)
113
+ key.export(OpenSSL::Cipher::Cipher.new("des-ede3-cbc"), password)
114
+ end
115
+
116
+ def public(key)
117
+ result = "#{key.ssh_type} "
118
+ result << [Net::SSH::Buffer.from(:key, key).to_s].pack("m*").strip.tr("\n\r\t ", "")
119
+ result << " joe@host.test"
120
+ end
121
+ end
@@ -0,0 +1,13 @@
1
+ require 'common'
2
+
3
+ class TestKnownHosts < Test::Unit::TestCase
4
+
5
+ def test_key_for_when_all_hosts_are_recognized
6
+ source = File.join(File.dirname(__FILE__),"known_hosts/github")
7
+ kh = Net::SSH::KnownHosts.new(source)
8
+ keys = kh.keys_for("github.com")
9
+ assert_equal(1, keys.count)
10
+ assert_equal("ssh-rsa", keys[0].ssh_type)
11
+ end
12
+
13
+ end
@@ -0,0 +1,39 @@
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
+ def test_key_should_be_truncated_to_required_length
28
+ hmac = subject.new("12345678901234567890")
29
+ assert_equal "1234567890123456", hmac.key
30
+ end
31
+
32
+ private
33
+
34
+ def subject
35
+ Net::SSH::Transport::HMAC::MD5
36
+ end
37
+ end
38
+
39
+ 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/ripemd160'
3
+
4
+ module Transport; module HMAC
5
+
6
+ class TestRipemd160 < Test::Unit::TestCase
7
+ def test_expected_digest_class
8
+ assert_equal OpenSSL::Digest::RIPEMD160, subject.digest_class
9
+ assert_equal OpenSSL::Digest::RIPEMD160, 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 "\xE4\x10\t\xB3\xD8,\x14\xA0k\x10\xB5\x0F?\x0E\x96q\x02\x16;E", hmac.digest("hello world")
25
+ end
26
+
27
+ private
28
+
29
+ def subject
30
+ Net::SSH::Transport::HMAC::RIPEMD160
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