redcar 0.3.7.1 → 0.3.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (246) hide show
  1. data/CHANGES +16 -0
  2. data/README.md +5 -0
  3. data/ROADMAP.md +7 -9
  4. data/Rakefile +55 -22
  5. data/lib/redcar.rb +12 -6
  6. data/lib/redcar/installer.rb +119 -44
  7. data/plugins/application/features/step_definitions/speedbar_steps.rb +62 -0
  8. data/plugins/application/features/step_definitions/tree_steps.rb +3 -3
  9. data/plugins/application/features/support/env.rb +2 -1
  10. data/plugins/application/lib/application/notebook.rb +53 -7
  11. data/plugins/application/lib/application/speedbar.rb +12 -0
  12. data/plugins/application/lib/application/tab.rb +16 -5
  13. data/plugins/application/lib/application/treebook.rb +21 -1
  14. data/plugins/application_swt/lib/application_swt.rb +12 -2
  15. data/plugins/application_swt/lib/application_swt/html_tab.rb +4 -0
  16. data/plugins/application_swt/lib/application_swt/notebook.rb +5 -3
  17. data/plugins/application_swt/lib/application_swt/speedbar.rb +15 -27
  18. data/plugins/application_swt/lib/application_swt/swt_wrapper.rb +1 -0
  19. data/plugins/application_swt/lib/application_swt/tab.rb +1 -0
  20. data/plugins/application_swt/lib/application_swt/treebook.rb +36 -8
  21. data/plugins/application_swt/lib/application_swt/window.rb +24 -18
  22. data/plugins/auto_completer/lib/auto_completer.rb +5 -20
  23. data/plugins/core/lib/core.rb +7 -4
  24. data/plugins/core/lib/core/observable_struct.rb +2 -2
  25. data/plugins/declarations/lib/declarations.rb +3 -17
  26. data/plugins/document_search/features/search.feature +163 -0
  27. data/plugins/document_search/features/support/env.rb +4 -0
  28. data/plugins/document_search/lib/document_search.rb +121 -0
  29. data/plugins/document_search/plugin.rb +8 -0
  30. data/plugins/edit_view/features/line_delimiter.feature +7 -0
  31. data/plugins/edit_view/features/step_definitions/editing_steps.rb +49 -1
  32. data/plugins/edit_view/features/step_definitions/tab_steps.rb +10 -11
  33. data/plugins/edit_view/features/switch_tabs.feature +61 -10
  34. data/plugins/edit_view/lib/edit_view.rb +4 -0
  35. data/plugins/edit_view/lib/edit_view/document.rb +56 -0
  36. data/plugins/edit_view/lib/edit_view/document/command.rb +1 -1
  37. data/plugins/edit_view/lib/edit_view/edit_tab.rb +0 -8
  38. data/plugins/edit_view_swt/lib/edit_view_swt.rb +4 -0
  39. data/plugins/html_view/lib/html_controller.rb +19 -1
  40. data/plugins/html_view/lib/html_view.rb +28 -1
  41. data/plugins/html_view/lib/html_view/html_tab.rb +10 -1
  42. data/plugins/plugin_manager_ui/lib/plugin_manager_ui.rb +3 -1
  43. data/plugins/project/features/open_directory_tree.feature +3 -3
  44. data/plugins/project/lib/project.rb +4 -6
  45. data/plugins/project/lib/project/commands.rb +17 -0
  46. data/plugins/project/lib/project/dir_controller.rb +2 -1
  47. data/plugins/project/lib/project/dir_mirror.rb +8 -0
  48. data/plugins/project/lib/project/manager.rb +2 -0
  49. data/plugins/project/plugin.rb +2 -1
  50. data/plugins/project/vendor/net-sftp/Manifest +55 -0
  51. data/plugins/project/vendor/net-sftp/Rakefile +30 -0
  52. data/plugins/project/vendor/net-sftp/lib/net/sftp.rb +70 -0
  53. data/plugins/project/vendor/net-sftp/lib/net/sftp/constants.rb +187 -0
  54. data/plugins/project/vendor/net-sftp/lib/net/sftp/errors.rb +39 -0
  55. data/plugins/project/vendor/net-sftp/lib/net/sftp/operations/dir.rb +93 -0
  56. data/plugins/project/vendor/net-sftp/lib/net/sftp/operations/download.rb +364 -0
  57. data/plugins/project/vendor/net-sftp/lib/net/sftp/operations/file.rb +176 -0
  58. data/plugins/project/vendor/net-sftp/lib/net/sftp/operations/file_factory.rb +60 -0
  59. data/plugins/project/vendor/net-sftp/lib/net/sftp/operations/upload.rb +387 -0
  60. data/plugins/project/vendor/net-sftp/lib/net/sftp/packet.rb +21 -0
  61. data/plugins/project/vendor/net-sftp/lib/net/sftp/protocol.rb +32 -0
  62. data/plugins/project/vendor/net-sftp/lib/net/sftp/protocol/01/attributes.rb +315 -0
  63. data/plugins/project/vendor/net-sftp/lib/net/sftp/protocol/01/base.rb +268 -0
  64. data/plugins/project/vendor/net-sftp/lib/net/sftp/protocol/01/name.rb +43 -0
  65. data/plugins/project/vendor/net-sftp/lib/net/sftp/protocol/02/base.rb +31 -0
  66. data/plugins/project/vendor/net-sftp/lib/net/sftp/protocol/03/base.rb +35 -0
  67. data/plugins/project/vendor/net-sftp/lib/net/sftp/protocol/04/attributes.rb +152 -0
  68. data/plugins/project/vendor/net-sftp/lib/net/sftp/protocol/04/base.rb +94 -0
  69. data/plugins/project/vendor/net-sftp/lib/net/sftp/protocol/04/name.rb +67 -0
  70. data/plugins/project/vendor/net-sftp/lib/net/sftp/protocol/05/base.rb +66 -0
  71. data/plugins/project/vendor/net-sftp/lib/net/sftp/protocol/06/attributes.rb +107 -0
  72. data/plugins/project/vendor/net-sftp/lib/net/sftp/protocol/06/base.rb +63 -0
  73. data/plugins/project/vendor/net-sftp/lib/net/sftp/protocol/base.rb +50 -0
  74. data/plugins/project/vendor/net-sftp/lib/net/sftp/request.rb +91 -0
  75. data/plugins/project/vendor/net-sftp/lib/net/sftp/response.rb +76 -0
  76. data/plugins/project/vendor/net-sftp/lib/net/sftp/session.rb +951 -0
  77. data/plugins/project/vendor/net-sftp/lib/net/sftp/version.rb +18 -0
  78. data/plugins/project/vendor/net-sftp/setup.rb +1331 -0
  79. data/plugins/project/vendor/net-sftp/test/common.rb +171 -0
  80. data/plugins/project/vendor/net-sftp/test/protocol/01/test_attributes.rb +97 -0
  81. data/plugins/project/vendor/net-sftp/test/protocol/01/test_base.rb +210 -0
  82. data/plugins/project/vendor/net-sftp/test/protocol/01/test_name.rb +27 -0
  83. data/plugins/project/vendor/net-sftp/test/protocol/02/test_base.rb +26 -0
  84. data/plugins/project/vendor/net-sftp/test/protocol/03/test_base.rb +27 -0
  85. data/plugins/project/vendor/net-sftp/test/protocol/04/test_attributes.rb +148 -0
  86. data/plugins/project/vendor/net-sftp/test/protocol/04/test_base.rb +74 -0
  87. data/plugins/project/vendor/net-sftp/test/protocol/04/test_name.rb +53 -0
  88. data/plugins/project/vendor/net-sftp/test/protocol/05/test_base.rb +62 -0
  89. data/plugins/project/vendor/net-sftp/test/protocol/06/test_attributes.rb +124 -0
  90. data/plugins/project/vendor/net-sftp/test/protocol/06/test_base.rb +51 -0
  91. data/plugins/project/vendor/net-sftp/test/protocol/test_base.rb +42 -0
  92. data/plugins/project/vendor/net-sftp/test/test_all.rb +7 -0
  93. data/plugins/project/vendor/net-sftp/test/test_dir.rb +47 -0
  94. data/plugins/project/vendor/net-sftp/test/test_download.rb +252 -0
  95. data/plugins/project/vendor/net-sftp/test/test_file.rb +159 -0
  96. data/plugins/project/vendor/net-sftp/test/test_file_factory.rb +48 -0
  97. data/plugins/project/vendor/net-sftp/test/test_packet.rb +9 -0
  98. data/plugins/project/vendor/net-sftp/test/test_protocol.rb +17 -0
  99. data/plugins/project/vendor/net-sftp/test/test_request.rb +71 -0
  100. data/plugins/project/vendor/net-sftp/test/test_response.rb +53 -0
  101. data/plugins/project/vendor/net-sftp/test/test_session.rb +741 -0
  102. data/plugins/project/vendor/net-sftp/test/test_upload.rb +219 -0
  103. data/plugins/project/vendor/net-ssh/Manifest +110 -0
  104. data/plugins/project/vendor/net-ssh/Rakefile +85 -0
  105. data/plugins/project/vendor/net-ssh/Rudyfile +96 -0
  106. data/plugins/project/vendor/net-ssh/lib/net/ssh.rb +215 -0
  107. data/plugins/project/vendor/net-ssh/lib/net/ssh/authentication/agent.rb +179 -0
  108. data/plugins/project/vendor/net-ssh/lib/net/ssh/authentication/constants.rb +18 -0
  109. data/plugins/project/vendor/net-ssh/lib/net/ssh/authentication/key_manager.rb +193 -0
  110. data/plugins/project/vendor/net-ssh/lib/net/ssh/authentication/methods/abstract.rb +60 -0
  111. data/plugins/project/vendor/net-ssh/lib/net/ssh/authentication/methods/hostbased.rb +71 -0
  112. data/plugins/project/vendor/net-ssh/lib/net/ssh/authentication/methods/keyboard_interactive.rb +66 -0
  113. data/plugins/project/vendor/net-ssh/lib/net/ssh/authentication/methods/password.rb +39 -0
  114. data/plugins/project/vendor/net-ssh/lib/net/ssh/authentication/methods/publickey.rb +92 -0
  115. data/plugins/project/vendor/net-ssh/lib/net/ssh/authentication/pageant.rb +183 -0
  116. data/plugins/project/vendor/net-ssh/lib/net/ssh/authentication/session.rb +134 -0
  117. data/plugins/project/vendor/net-ssh/lib/net/ssh/buffer.rb +340 -0
  118. data/plugins/project/vendor/net-ssh/lib/net/ssh/buffered_io.rb +198 -0
  119. data/plugins/project/vendor/net-ssh/lib/net/ssh/config.rb +202 -0
  120. data/plugins/project/vendor/net-ssh/lib/net/ssh/connection/channel.rb +630 -0
  121. data/plugins/project/vendor/net-ssh/lib/net/ssh/connection/constants.rb +33 -0
  122. data/plugins/project/vendor/net-ssh/lib/net/ssh/connection/session.rb +597 -0
  123. data/plugins/project/vendor/net-ssh/lib/net/ssh/connection/term.rb +178 -0
  124. data/plugins/project/vendor/net-ssh/lib/net/ssh/errors.rb +85 -0
  125. data/plugins/project/vendor/net-ssh/lib/net/ssh/key_factory.rb +102 -0
  126. data/plugins/project/vendor/net-ssh/lib/net/ssh/known_hosts.rb +129 -0
  127. data/plugins/project/vendor/net-ssh/lib/net/ssh/loggable.rb +61 -0
  128. data/plugins/project/vendor/net-ssh/lib/net/ssh/packet.rb +102 -0
  129. data/plugins/project/vendor/net-ssh/lib/net/ssh/prompt.rb +93 -0
  130. data/plugins/project/vendor/net-ssh/lib/net/ssh/proxy/command.rb +75 -0
  131. data/plugins/project/vendor/net-ssh/lib/net/ssh/proxy/errors.rb +14 -0
  132. data/plugins/project/vendor/net-ssh/lib/net/ssh/proxy/http.rb +94 -0
  133. data/plugins/project/vendor/net-ssh/lib/net/ssh/proxy/socks4.rb +70 -0
  134. data/plugins/project/vendor/net-ssh/lib/net/ssh/proxy/socks5.rb +142 -0
  135. data/plugins/project/vendor/net-ssh/lib/net/ssh/ruby_compat.rb +43 -0
  136. data/plugins/project/vendor/net-ssh/lib/net/ssh/service/forward.rb +288 -0
  137. data/plugins/project/vendor/net-ssh/lib/net/ssh/test.rb +89 -0
  138. data/plugins/project/vendor/net-ssh/lib/net/ssh/test/channel.rb +129 -0
  139. data/plugins/project/vendor/net-ssh/lib/net/ssh/test/extensions.rb +152 -0
  140. data/plugins/project/vendor/net-ssh/lib/net/ssh/test/kex.rb +44 -0
  141. data/plugins/project/vendor/net-ssh/lib/net/ssh/test/local_packet.rb +51 -0
  142. data/plugins/project/vendor/net-ssh/lib/net/ssh/test/packet.rb +81 -0
  143. data/plugins/project/vendor/net-ssh/lib/net/ssh/test/remote_packet.rb +38 -0
  144. data/plugins/project/vendor/net-ssh/lib/net/ssh/test/script.rb +157 -0
  145. data/plugins/project/vendor/net-ssh/lib/net/ssh/test/socket.rb +64 -0
  146. data/plugins/project/vendor/net-ssh/lib/net/ssh/transport/algorithms.rb +384 -0
  147. data/plugins/project/vendor/net-ssh/lib/net/ssh/transport/cipher_factory.rb +97 -0
  148. data/plugins/project/vendor/net-ssh/lib/net/ssh/transport/constants.rb +30 -0
  149. data/plugins/project/vendor/net-ssh/lib/net/ssh/transport/hmac.rb +31 -0
  150. data/plugins/project/vendor/net-ssh/lib/net/ssh/transport/hmac/abstract.rb +79 -0
  151. data/plugins/project/vendor/net-ssh/lib/net/ssh/transport/hmac/md5.rb +12 -0
  152. data/plugins/project/vendor/net-ssh/lib/net/ssh/transport/hmac/md5_96.rb +11 -0
  153. data/plugins/project/vendor/net-ssh/lib/net/ssh/transport/hmac/none.rb +15 -0
  154. data/plugins/project/vendor/net-ssh/lib/net/ssh/transport/hmac/sha1.rb +13 -0
  155. data/plugins/project/vendor/net-ssh/lib/net/ssh/transport/hmac/sha1_96.rb +11 -0
  156. data/plugins/project/vendor/net-ssh/lib/net/ssh/transport/identity_cipher.rb +55 -0
  157. data/plugins/project/vendor/net-ssh/lib/net/ssh/transport/kex.rb +13 -0
  158. data/plugins/project/vendor/net-ssh/lib/net/ssh/transport/kex/diffie_hellman_group1_sha1.rb +208 -0
  159. data/plugins/project/vendor/net-ssh/lib/net/ssh/transport/kex/diffie_hellman_group_exchange_sha1.rb +77 -0
  160. data/plugins/project/vendor/net-ssh/lib/net/ssh/transport/openssl.rb +128 -0
  161. data/plugins/project/vendor/net-ssh/lib/net/ssh/transport/packet_stream.rb +235 -0
  162. data/plugins/project/vendor/net-ssh/lib/net/ssh/transport/server_version.rb +71 -0
  163. data/plugins/project/vendor/net-ssh/lib/net/ssh/transport/session.rb +276 -0
  164. data/plugins/project/vendor/net-ssh/lib/net/ssh/transport/state.rb +206 -0
  165. data/plugins/project/vendor/net-ssh/lib/net/ssh/verifiers/lenient.rb +30 -0
  166. data/plugins/project/vendor/net-ssh/lib/net/ssh/verifiers/null.rb +12 -0
  167. data/plugins/project/vendor/net-ssh/lib/net/ssh/verifiers/strict.rb +53 -0
  168. data/plugins/project/vendor/net-ssh/lib/net/ssh/version.rb +62 -0
  169. data/plugins/project/vendor/net-ssh/net-ssh.gemspec +138 -0
  170. data/plugins/project/vendor/net-ssh/setup.rb +1585 -0
  171. data/plugins/project/vendor/net-ssh/support/arcfour_check.rb +20 -0
  172. data/plugins/project/vendor/net-ssh/support/ssh_tunnel_bug.rb +65 -0
  173. data/plugins/project/vendor/net-ssh/test/README.txt +42 -0
  174. data/plugins/project/vendor/net-ssh/test/authentication/methods/common.rb +28 -0
  175. data/plugins/project/vendor/net-ssh/test/authentication/methods/test_abstract.rb +51 -0
  176. data/plugins/project/vendor/net-ssh/test/authentication/methods/test_hostbased.rb +114 -0
  177. data/plugins/project/vendor/net-ssh/test/authentication/methods/test_keyboard_interactive.rb +98 -0
  178. data/plugins/project/vendor/net-ssh/test/authentication/methods/test_password.rb +50 -0
  179. data/plugins/project/vendor/net-ssh/test/authentication/methods/test_publickey.rb +127 -0
  180. data/plugins/project/vendor/net-ssh/test/authentication/test_agent.rb +205 -0
  181. data/plugins/project/vendor/net-ssh/test/authentication/test_key_manager.rb +105 -0
  182. data/plugins/project/vendor/net-ssh/test/authentication/test_session.rb +93 -0
  183. data/plugins/project/vendor/net-ssh/test/common.rb +107 -0
  184. data/plugins/project/vendor/net-ssh/test/configs/eqsign +3 -0
  185. data/plugins/project/vendor/net-ssh/test/configs/exact_match +8 -0
  186. data/plugins/project/vendor/net-ssh/test/configs/host_plus +10 -0
  187. data/plugins/project/vendor/net-ssh/test/configs/multihost +4 -0
  188. data/plugins/project/vendor/net-ssh/test/configs/nohost +19 -0
  189. data/plugins/project/vendor/net-ssh/test/configs/numeric_host +4 -0
  190. data/plugins/project/vendor/net-ssh/test/configs/wild_cards +14 -0
  191. data/plugins/project/vendor/net-ssh/test/connection/test_channel.rb +467 -0
  192. data/plugins/project/vendor/net-ssh/test/connection/test_session.rb +488 -0
  193. data/plugins/project/vendor/net-ssh/test/manual/test_forward.rb +185 -0
  194. data/plugins/project/vendor/net-ssh/test/test_all.rb +9 -0
  195. data/plugins/project/vendor/net-ssh/test/test_buffer.rb +336 -0
  196. data/plugins/project/vendor/net-ssh/test/test_buffered_io.rb +63 -0
  197. data/plugins/project/vendor/net-ssh/test/test_config.rb +117 -0
  198. data/plugins/project/vendor/net-ssh/test/test_key_factory.rb +67 -0
  199. data/plugins/project/vendor/net-ssh/test/transport/hmac/test_md5.rb +39 -0
  200. data/plugins/project/vendor/net-ssh/test/transport/hmac/test_md5_96.rb +25 -0
  201. data/plugins/project/vendor/net-ssh/test/transport/hmac/test_none.rb +34 -0
  202. data/plugins/project/vendor/net-ssh/test/transport/hmac/test_sha1.rb +34 -0
  203. data/plugins/project/vendor/net-ssh/test/transport/hmac/test_sha1_96.rb +25 -0
  204. data/plugins/project/vendor/net-ssh/test/transport/kex/test_diffie_hellman_group1_sha1.rb +146 -0
  205. data/plugins/project/vendor/net-ssh/test/transport/kex/test_diffie_hellman_group_exchange_sha1.rb +92 -0
  206. data/plugins/project/vendor/net-ssh/test/transport/test_algorithms.rb +302 -0
  207. data/plugins/project/vendor/net-ssh/test/transport/test_cipher_factory.rb +213 -0
  208. data/plugins/project/vendor/net-ssh/test/transport/test_hmac.rb +34 -0
  209. data/plugins/project/vendor/net-ssh/test/transport/test_identity_cipher.rb +40 -0
  210. data/plugins/project/vendor/net-ssh/test/transport/test_packet_stream.rb +441 -0
  211. data/plugins/project/vendor/net-ssh/test/transport/test_server_version.rb +78 -0
  212. data/plugins/project/vendor/net-ssh/test/transport/test_session.rb +315 -0
  213. data/plugins/project/vendor/net-ssh/test/transport/test_state.rb +173 -0
  214. data/plugins/redcar/plugin.rb +3 -1
  215. data/plugins/redcar/redcar.rb +108 -121
  216. data/plugins/redcar_debug/lib/redcar_debug.rb +2 -0
  217. data/plugins/runnables/lib/runnables.rb +80 -23
  218. data/plugins/runnables/lib/runnables/command_output_controller.rb +102 -0
  219. data/plugins/runnables/lib/runnables/running_process_checker.rb +34 -0
  220. data/plugins/runnables/{plugin_no_load.rb → plugin.rb} +2 -1
  221. data/plugins/runnables/vendor/session-2.4.0/HISTORY +73 -0
  222. data/plugins/runnables/vendor/session-2.4.0/README +89 -0
  223. data/plugins/runnables/vendor/session-2.4.0/TODO +3 -0
  224. data/plugins/runnables/vendor/session-2.4.0/VERSION +1 -0
  225. data/plugins/runnables/vendor/session-2.4.0/gemspec.rb +22 -0
  226. data/plugins/runnables/vendor/session-2.4.0/install.rb +143 -0
  227. data/plugins/runnables/vendor/session-2.4.0/lib/session.rb +757 -0
  228. data/plugins/runnables/vendor/session-2.4.0/sample/bash.rb +60 -0
  229. data/plugins/runnables/vendor/session-2.4.0/sample/driver.rb +47 -0
  230. data/plugins/runnables/vendor/session-2.4.0/sample/session_idl.rb +25 -0
  231. data/plugins/runnables/vendor/session-2.4.0/sample/session_sh.rb +29 -0
  232. data/plugins/runnables/vendor/session-2.4.0/sample/sh0.rb +23 -0
  233. data/plugins/runnables/vendor/session-2.4.0/sample/stdin.rb +17 -0
  234. data/plugins/runnables/vendor/session-2.4.0/sample/threadtest.rb +42 -0
  235. data/plugins/runnables/vendor/session-2.4.0/session-2.4.0.gem +0 -0
  236. data/plugins/runnables/vendor/session-2.4.0/test/session.rb +227 -0
  237. data/plugins/runnables/views/command_output.html.erb +32 -0
  238. data/plugins/task_manager/lib/task_manager.rb +2 -0
  239. data/plugins/textmate/lib/textmate/plist.rb +1 -1
  240. data/plugins/textmate/lib/textmate/snippet.rb +1 -0
  241. data/plugins/tree/lib/tree/mirror.rb +8 -1
  242. data/plugins/tree_view_swt/lib/tree_view_swt.rb +29 -2
  243. metadata +191 -6
  244. data/plugins/declarations/TODO +0 -3
  245. data/plugins/redcar/spec/redcar/redcar_spec.rb +0 -70
  246. data/plugins/redcar/spec/spec_helper.rb +0 -4
@@ -0,0 +1,92 @@
1
+ require 'common'
2
+ require 'transport/kex/test_diffie_hellman_group1_sha1'
3
+ require 'net/ssh/transport/kex/diffie_hellman_group_exchange_sha1'
4
+
5
+ module Transport; module Kex
6
+
7
+ class TestDiffieHellmanGroupExchangeSHA1 < TestDiffieHellmanGroup1SHA1
8
+ KEXDH_GEX_GROUP = 31
9
+ KEXDH_GEX_INIT = 32
10
+ KEXDH_GEX_REPLY = 33
11
+ KEXDH_GEX_REQUEST = 34
12
+
13
+ def test_exchange_with_fewer_than_minimum_bits_uses_minimum_bits
14
+ dh_options :need_bytes => 20
15
+ assert_equal 1024, need_bits
16
+ assert_nothing_raised { exchange! }
17
+ end
18
+
19
+ def test_exchange_with_fewer_than_maximum_bits_uses_need_bits
20
+ dh_options :need_bytes => 500
21
+ need_bits(4000)
22
+ assert_nothing_raised { exchange! }
23
+ end
24
+
25
+ def test_exchange_with_more_than_maximum_bits_uses_maximum_bits
26
+ dh_options :need_bytes => 2000
27
+ need_bits(8192)
28
+ assert_nothing_raised { exchange! }
29
+ end
30
+
31
+ def test_that_p_and_g_are_provided_by_the_server
32
+ assert_nothing_raised { exchange! :p => default_p+2, :g => 3 }
33
+ assert_equal default_p+2, dh.dh.p
34
+ assert_equal 3, dh.dh.g
35
+ end
36
+
37
+ private
38
+
39
+ def need_bits(bits=1024)
40
+ @need_bits ||= bits
41
+ end
42
+
43
+ def default_p
44
+ 142326151570335518660743995281621698377057354949884468943021767573608899048361360422513557553514790045512299468953431585300812548859419857171094366358158903433167915517332113861059747425408670144201099811846875730766487278261498262568348338476437200556998366087779709990807518291581860338635288400119315130179
45
+ end
46
+
47
+ def exchange!(options={})
48
+ connection.expect do |t, buffer|
49
+ assert_equal KEXDH_GEX_REQUEST, buffer.type
50
+ assert_equal 1024, buffer.read_long
51
+ assert_equal need_bits, buffer.read_long
52
+ assert_equal 8192, buffer.read_long
53
+ t.return(KEXDH_GEX_GROUP, :bignum, bn(options[:p] || default_p), :bignum, bn(options[:g] || 2))
54
+ t.expect do |t2, buffer2|
55
+ assert_equal KEXDH_GEX_INIT, buffer2.type
56
+ assert_equal dh.dh.pub_key, buffer2.read_bignum
57
+ t2.return(KEXDH_GEX_REPLY, :string, b(:key, server_key), :bignum, server_dh_pubkey, :string, b(:string, options[:key_type] || "ssh-rsa", :string, signature))
58
+ t2.expect do |t3, buffer3|
59
+ assert_equal NEWKEYS, buffer3.type
60
+ t3.return(NEWKEYS)
61
+ end
62
+ end
63
+ end
64
+
65
+ dh.exchange_keys
66
+ end
67
+
68
+ def subject
69
+ Net::SSH::Transport::Kex::DiffieHellmanGroupExchangeSHA1
70
+ end
71
+
72
+ def session_id
73
+ @session_id ||= begin
74
+ buffer = Net::SSH::Buffer.from(:string, packet_data[:client_version_string],
75
+ :string, packet_data[:server_version_string],
76
+ :string, packet_data[:client_algorithm_packet],
77
+ :string, packet_data[:server_algorithm_packet],
78
+ :string, Net::SSH::Buffer.from(:key, server_key),
79
+ :long, 1024,
80
+ :long, need_bits, # need bits, figure this part out,
81
+ :long, 8192,
82
+ :bignum, dh.dh.p,
83
+ :bignum, dh.dh.g,
84
+ :bignum, dh.dh.pub_key,
85
+ :bignum, server_dh_pubkey,
86
+ :bignum, shared_secret)
87
+ OpenSSL::Digest::SHA1.digest(buffer.to_s)
88
+ end
89
+ end
90
+ end
91
+
92
+ end; end
@@ -0,0 +1,302 @@
1
+ require 'common'
2
+ require 'net/ssh/transport/algorithms'
3
+
4
+ module Transport
5
+
6
+ class TestAlgorithms < Test::Unit::TestCase
7
+ include Net::SSH::Transport::Constants
8
+
9
+ def test_allowed_packets
10
+ (0..255).each do |type|
11
+ packet = stub("packet", :type => type)
12
+ case type
13
+ when 1..4, 6..19, 21..49 then assert(Net::SSH::Transport::Algorithms.allowed_packet?(packet), "#{type} should be allowed during key exchange")
14
+ else assert(!Net::SSH::Transport::Algorithms.allowed_packet?(packet), "#{type} should not be allowed during key exchange")
15
+ end
16
+ end
17
+ end
18
+
19
+ def test_constructor_should_build_default_list_of_preferred_algorithms
20
+ assert_equal %w(ssh-rsa ssh-dss), algorithms[:host_key]
21
+ assert_equal %w(diffie-hellman-group-exchange-sha1 diffie-hellman-group1-sha1), algorithms[:kex]
22
+ assert_equal %w(aes128-cbc 3des-cbc blowfish-cbc cast128-cbc aes192-cbc aes256-cbc rijndael-cbc@lysator.liu.se idea-cbc none arcfour128 arcfour256), algorithms[:encryption]
23
+ assert_equal %w(hmac-sha1 hmac-md5 hmac-sha1-96 hmac-md5-96 none), algorithms[:hmac]
24
+ assert_equal %w(none zlib@openssh.com zlib), algorithms[:compression]
25
+ assert_equal %w(), algorithms[:language]
26
+ end
27
+
28
+ def test_constructor_should_set_client_and_server_prefs_identically
29
+ %w(encryption hmac compression language).each do |key|
30
+ assert_equal algorithms[key.to_sym], algorithms[:"#{key}_client"], key
31
+ assert_equal algorithms[key.to_sym], algorithms[:"#{key}_server"], key
32
+ end
33
+ end
34
+
35
+ def test_constructor_with_preferred_host_key_type_should_put_preferred_host_key_type_first
36
+ assert_equal %w(ssh-dss ssh-rsa), algorithms(:host_key => "ssh-dss")[:host_key]
37
+ end
38
+
39
+ def test_constructor_with_known_hosts_reporting_known_host_key_should_use_that_host_key_type
40
+ Net::SSH::KnownHosts.expects(:search_for).with("net.ssh.test,127.0.0.1", {}).returns([stub("key", :ssh_type => "ssh-dss")])
41
+ assert_equal %w(ssh-dss ssh-rsa), algorithms[:host_key]
42
+ end
43
+
44
+ def test_constructor_with_unrecognized_host_key_type_should_raise_exception
45
+ assert_raises(NotImplementedError) { algorithms(:host_key => "bogus") }
46
+ end
47
+
48
+ def test_constructor_with_preferred_kex_should_put_preferred_kex_first
49
+ assert_equal %w(diffie-hellman-group1-sha1 diffie-hellman-group-exchange-sha1), algorithms(:kex => "diffie-hellman-group1-sha1")[:kex]
50
+ end
51
+
52
+ def test_constructor_with_unrecognized_kex_should_raise_exception
53
+ assert_raises(NotImplementedError) { algorithms(:kex => "bogus") }
54
+ end
55
+
56
+ def test_constructor_with_preferred_encryption_should_put_preferred_encryption_first
57
+ assert_equal %w(aes256-cbc aes128-cbc 3des-cbc blowfish-cbc cast128-cbc aes192-cbc rijndael-cbc@lysator.liu.se idea-cbc none arcfour128 arcfour256), algorithms(:encryption => "aes256-cbc")[:encryption]
58
+ end
59
+
60
+ def test_constructor_with_multiple_preferred_encryption_should_put_all_preferred_encryption_first
61
+ assert_equal %w(aes256-cbc 3des-cbc idea-cbc aes128-cbc blowfish-cbc cast128-cbc aes192-cbc rijndael-cbc@lysator.liu.se none arcfour128 arcfour256), algorithms(:encryption => %w(aes256-cbc 3des-cbc idea-cbc))[:encryption]
62
+ end
63
+
64
+ def test_constructor_with_unrecognized_encryption_should_raise_exception
65
+ assert_raises(NotImplementedError) { algorithms(:encryption => "bogus") }
66
+ end
67
+
68
+ def test_constructor_with_preferred_hmac_should_put_preferred_hmac_first
69
+ assert_equal %w(hmac-md5-96 hmac-sha1 hmac-md5 hmac-sha1-96 none), algorithms(:hmac => "hmac-md5-96")[:hmac]
70
+ end
71
+
72
+ def test_constructor_with_multiple_preferred_hmac_should_put_all_preferred_hmac_first
73
+ assert_equal %w(hmac-md5-96 hmac-sha1-96 hmac-sha1 hmac-md5 none), algorithms(:hmac => %w(hmac-md5-96 hmac-sha1-96))[:hmac]
74
+ end
75
+
76
+ def test_constructor_with_unrecognized_hmac_should_raise_exception
77
+ assert_raises(NotImplementedError) { algorithms(:hmac => "bogus") }
78
+ end
79
+
80
+ def test_constructor_with_preferred_compression_should_put_preferred_compression_first
81
+ assert_equal %w(zlib none zlib@openssh.com), algorithms(:compression => "zlib")[:compression]
82
+ end
83
+
84
+ def test_constructor_with_multiple_preferred_compression_should_put_all_preferred_compression_first
85
+ assert_equal %w(zlib@openssh.com zlib none), algorithms(:compression => %w(zlib@openssh.com zlib))[:compression]
86
+ end
87
+
88
+ def test_constructor_with_general_preferred_compression_should_put_none_last
89
+ assert_equal %w(zlib@openssh.com zlib none), algorithms(:compression => true)[:compression]
90
+ end
91
+
92
+ def test_constructor_with_unrecognized_compression_should_raise_exception
93
+ assert_raises(NotImplementedError) { algorithms(:compression => "bogus") }
94
+ end
95
+
96
+ def test_initial_state_should_be_neither_pending_nor_initialized
97
+ assert !algorithms.pending?
98
+ assert !algorithms.initialized?
99
+ end
100
+
101
+ def test_key_exchange_when_initiated_by_server
102
+ transport.expect do |t, buffer|
103
+ assert_kexinit(buffer)
104
+ install_mock_key_exchange(buffer)
105
+ end
106
+
107
+ install_mock_algorithm_lookups
108
+ algorithms.accept_kexinit(kexinit)
109
+
110
+ assert_exchange_results
111
+ end
112
+
113
+ def test_key_exchange_when_initiated_by_client
114
+ state = nil
115
+ transport.expect do |t, buffer|
116
+ assert_kexinit(buffer)
117
+ state = :sent_kexinit
118
+ install_mock_key_exchange(buffer)
119
+ end
120
+
121
+ algorithms.rekey!
122
+ assert_equal state, :sent_kexinit
123
+ assert algorithms.pending?
124
+
125
+ install_mock_algorithm_lookups
126
+ algorithms.accept_kexinit(kexinit)
127
+
128
+ assert_exchange_results
129
+ end
130
+
131
+ def test_key_exchange_when_server_does_not_support_preferred_kex_should_fallback_to_secondary
132
+ kexinit :kex => "diffie-hellman-group1-sha1"
133
+ transport.expect do |t,buffer|
134
+ assert_kexinit(buffer)
135
+ install_mock_key_exchange(buffer, :kex => Net::SSH::Transport::Kex::DiffieHellmanGroup1SHA1)
136
+ end
137
+ algorithms.accept_kexinit(kexinit)
138
+ end
139
+
140
+ def test_key_exchange_when_server_does_not_support_any_preferred_kex_should_raise_error
141
+ kexinit :kex => "something-obscure"
142
+ transport.expect { |t,buffer| assert_kexinit(buffer) }
143
+ assert_raises(Net::SSH::Exception) { algorithms.accept_kexinit(kexinit) }
144
+ end
145
+
146
+ def test_allow_when_not_pending_should_be_true_for_all_packets
147
+ (0..255).each do |type|
148
+ packet = stub("packet", :type => type)
149
+ assert algorithms.allow?(packet), type
150
+ end
151
+ end
152
+
153
+ def test_allow_when_pending_should_be_true_only_for_packets_valid_during_key_exchange
154
+ transport.expect!
155
+ algorithms.rekey!
156
+ assert algorithms.pending?
157
+
158
+ (0..255).each do |type|
159
+ packet = stub("packet", :type => type)
160
+ case type
161
+ when 1..4, 6..19, 21..49 then assert(algorithms.allow?(packet), "#{type} should be allowed during key exchange")
162
+ else assert(!algorithms.allow?(packet), "#{type} should not be allowed during key exchange")
163
+ end
164
+ end
165
+ end
166
+
167
+ def test_exchange_with_zlib_compression_enabled_sets_compression_to_standard
168
+ algorithms :compression => "zlib"
169
+
170
+ transport.expect do |t, buffer|
171
+ assert_kexinit(buffer, :compression_client => "zlib,none,zlib@openssh.com", :compression_server => "zlib,none,zlib@openssh.com")
172
+ install_mock_key_exchange(buffer)
173
+ end
174
+
175
+ install_mock_algorithm_lookups
176
+ algorithms.accept_kexinit(kexinit)
177
+
178
+ assert_equal :standard, transport.client_options[:compression]
179
+ assert_equal :standard, transport.server_options[:compression]
180
+ end
181
+
182
+ def test_exchange_with_zlib_at_openssh_dot_com_compression_enabled_sets_compression_to_delayed
183
+ algorithms :compression => "zlib@openssh.com"
184
+
185
+ transport.expect do |t, buffer|
186
+ assert_kexinit(buffer, :compression_client => "zlib@openssh.com,none,zlib", :compression_server => "zlib@openssh.com,none,zlib")
187
+ install_mock_key_exchange(buffer)
188
+ end
189
+
190
+ install_mock_algorithm_lookups
191
+ algorithms.accept_kexinit(kexinit)
192
+
193
+ assert_equal :delayed, transport.client_options[:compression]
194
+ assert_equal :delayed, transport.server_options[:compression]
195
+ end
196
+
197
+ private
198
+
199
+ def install_mock_key_exchange(buffer, options={})
200
+ kex = options[:kex] || Net::SSH::Transport::Kex::DiffieHellmanGroupExchangeSHA1
201
+
202
+ Net::SSH::Transport::Kex::MAP.each do |name, klass|
203
+ next if klass == kex
204
+ klass.expects(:new).never
205
+ end
206
+
207
+ kex.expects(:new).
208
+ with(algorithms, transport,
209
+ :client_version_string => Net::SSH::Transport::ServerVersion::PROTO_VERSION,
210
+ :server_version_string => transport.server_version.version,
211
+ :server_algorithm_packet => kexinit.to_s,
212
+ :client_algorithm_packet => buffer.to_s,
213
+ :need_bytes => 20,
214
+ :logger => nil).
215
+ returns(stub("kex", :exchange_keys => { :shared_secret => shared_secret, :session_id => session_id, :hashing_algorithm => hashing_algorithm }))
216
+ end
217
+
218
+ def install_mock_algorithm_lookups(options={})
219
+ Net::SSH::Transport::CipherFactory.expects(:get).
220
+ with(options[:client_cipher] || "aes128-cbc", :iv => key("A"), :key => key("C"), :shared => shared_secret.to_ssh, :hash => session_id, :digester => hashing_algorithm, :encrypt => true).
221
+ returns(:client_cipher)
222
+ Net::SSH::Transport::CipherFactory.expects(:get).
223
+ with(options[:server_cipher] || "aes128-cbc", :iv => key("B"), :key => key("D"), :shared => shared_secret.to_ssh, :hash => session_id, :digester => hashing_algorithm, :decrypt => true).
224
+ returns(:server_cipher)
225
+
226
+ Net::SSH::Transport::HMAC.expects(:get).with(options[:client_hmac] || "hmac-sha1", key("E")).returns(:client_hmac)
227
+ Net::SSH::Transport::HMAC.expects(:get).with(options[:server_hmac] || "hmac-sha1", key("F")).returns(:server_hmac)
228
+ end
229
+
230
+ def shared_secret
231
+ @shared_secret ||= OpenSSL::BN.new("1234567890", 10)
232
+ end
233
+
234
+ def session_id
235
+ @session_id ||= "this is the session id"
236
+ end
237
+
238
+ def hashing_algorithm
239
+ OpenSSL::Digest::SHA1
240
+ end
241
+
242
+ def key(salt)
243
+ hashing_algorithm.digest(shared_secret.to_ssh + session_id + salt + session_id)
244
+ end
245
+
246
+ def cipher(type, options={})
247
+ Net::SSH::Transport::CipherFactory.get(type, options)
248
+ end
249
+
250
+ def kexinit(options={})
251
+ @kexinit ||= P(:byte, KEXINIT,
252
+ :long, rand(0xFFFFFFFF), :long, rand(0xFFFFFFFF), :long, rand(0xFFFFFFFF), :long, rand(0xFFFFFFFF),
253
+ :string, options[:kex] || "diffie-hellman-group-exchange-sha1,diffie-hellman-group1-sha1",
254
+ :string, options[:host_key] || "ssh-rsa,ssh-dss",
255
+ :string, options[:encryption_client] || "aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,rijndael-cbc@lysator.liu.se,idea-cbc",
256
+ :string, options[:encryption_server] || "aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,rijndael-cbc@lysator.liu.se,idea-cbc",
257
+ :string, options[:hmac_client] || "hmac-sha1,hmac-md5,hmac-sha1-96,hmac-md5-96",
258
+ :string, options[:hmac_server] || "hmac-sha1,hmac-md5,hmac-sha1-96,hmac-md5-96",
259
+ :string, options[:compmression_client] || "none,zlib@openssh.com,zlib",
260
+ :string, options[:compmression_server] || "none,zlib@openssh.com,zlib",
261
+ :string, options[:language_client] || "",
262
+ :string, options[:langauge_server] || "",
263
+ :bool, options[:first_kex_follows])
264
+ end
265
+
266
+ def assert_kexinit(buffer, options={})
267
+ assert_equal KEXINIT, buffer.type
268
+ assert_equal 16, buffer.read(16).length
269
+ assert_equal options[:kex] || "diffie-hellman-group-exchange-sha1,diffie-hellman-group1-sha1", buffer.read_string
270
+ assert_equal options[:host_key] || "ssh-rsa,ssh-dss", buffer.read_string
271
+ assert_equal options[:encryption_client] || "aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,rijndael-cbc@lysator.liu.se,idea-cbc,none,arcfour128,arcfour256", buffer.read_string
272
+ assert_equal options[:encryption_server] || "aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,rijndael-cbc@lysator.liu.se,idea-cbc,none,arcfour128,arcfour256", buffer.read_string
273
+ assert_equal options[:hmac_client] || "hmac-sha1,hmac-md5,hmac-sha1-96,hmac-md5-96,none", buffer.read_string
274
+ assert_equal options[:hmac_server] || "hmac-sha1,hmac-md5,hmac-sha1-96,hmac-md5-96,none", buffer.read_string
275
+ assert_equal options[:compression_client] || "none,zlib@openssh.com,zlib", buffer.read_string
276
+ assert_equal options[:compression_server] || "none,zlib@openssh.com,zlib", buffer.read_string
277
+ assert_equal options[:language_client] || "", buffer.read_string
278
+ assert_equal options[:language_server] || "", buffer.read_string
279
+ assert_equal options[:first_kex_follows] || false, buffer.read_bool
280
+ end
281
+
282
+ def assert_exchange_results
283
+ assert algorithms.initialized?
284
+ assert !algorithms.pending?
285
+ assert !transport.client_options[:compression]
286
+ assert !transport.server_options[:compression]
287
+ assert_equal :client_cipher, transport.client_options[:cipher]
288
+ assert_equal :server_cipher, transport.server_options[:cipher]
289
+ assert_equal :client_hmac, transport.client_options[:hmac]
290
+ assert_equal :server_hmac, transport.server_options[:hmac]
291
+ end
292
+
293
+ def algorithms(options={})
294
+ @algorithms ||= Net::SSH::Transport::Algorithms.new(transport, options)
295
+ end
296
+
297
+ def transport
298
+ @transport ||= MockTransport.new
299
+ end
300
+ end
301
+
302
+ end
@@ -0,0 +1,213 @@
1
+ require 'common'
2
+ require 'net/ssh/transport/cipher_factory'
3
+
4
+ module Transport
5
+
6
+ class TestCipherFactory < Test::Unit::TestCase
7
+ def self.if_supported?(name)
8
+ yield if Net::SSH::Transport::CipherFactory.supported?(name)
9
+ end
10
+
11
+ def test_lengths_for_none
12
+ assert_equal [0,0], factory.get_lengths("none")
13
+ assert_equal [0,0], factory.get_lengths("bogus")
14
+ end
15
+
16
+ def test_lengths_for_blowfish_cbc
17
+ assert_equal [16,8], factory.get_lengths("blowfish-cbc")
18
+ end
19
+
20
+ if_supported?("idea-cbc") do
21
+ def test_lengths_for_idea_cbc
22
+ assert_equal [16,8], factory.get_lengths("idea-cbc")
23
+ end
24
+ end
25
+
26
+ def test_lengths_for_rijndael_cbc
27
+ assert_equal [32,16], factory.get_lengths("rijndael-cbc@lysator.liu.se")
28
+ end
29
+
30
+ def test_lengths_for_cast128_cbc
31
+ assert_equal [16,8], factory.get_lengths("cast128-cbc")
32
+ end
33
+
34
+ def test_lengths_for_3des_cbc
35
+ assert_equal [24,8], factory.get_lengths("3des-cbc")
36
+ end
37
+
38
+ def test_lengths_for_aes192_cbc
39
+ assert_equal [24,16], factory.get_lengths("aes192-cbc")
40
+ end
41
+
42
+ def test_lengths_for_aes128_cbc
43
+ assert_equal [16,16], factory.get_lengths("aes128-cbc")
44
+ end
45
+
46
+ def test_lengths_for_aes256_cbc
47
+ assert_equal [32,16], factory.get_lengths("aes256-cbc")
48
+ end
49
+
50
+ def test_lengths_for_arcfour128
51
+ assert_equal [16,8], factory.get_lengths("arcfour128")
52
+ end
53
+
54
+ def test_lengths_for_arcfour256
55
+ assert_equal [32,8], factory.get_lengths("arcfour256")
56
+ end
57
+
58
+ def test_lengths_for_arcfour512
59
+ assert_equal [64,8], factory.get_lengths("arcfour512")
60
+ end
61
+
62
+ BLOWFISH = "\210\021\200\315\240_\026$\352\204g\233\244\242x\332e\370\001\327\224Nv@9_\323\037\252kb\037\036\237\375]\343/y\037\237\312Q\f7]\347Y\005\275%\377\0010$G\272\250B\265Nd\375\342\372\025r6}+Y\213y\n\237\267\\\374^\346BdJ$\353\220Ik\023<\236&H\277=\225"
63
+
64
+ def test_blowfish_cbc_for_encryption
65
+ assert_equal BLOWFISH, encrypt("blowfish-cbc")
66
+ end
67
+
68
+ def test_blowfish_cbc_for_decryption
69
+ assert_equal TEXT, decrypt("blowfish-cbc", BLOWFISH)
70
+ end
71
+
72
+ if_supported?("idea-cbc") do
73
+ IDEA = "W\234\017G\231\b\357\370H\b\256U]\343M\031k\233]~\023C\363\263\177\262-\261\341$\022\376mv\217\322\b\2763\270H\306\035\343z\313\312\3531\351\t\201\302U\022\360\300\354ul7$z\320O]\360g\024\305\005`V\005\335A\351\312\270c\320D\232\eQH1\340\265\2118\031g*\303v"
74
+
75
+ def test_idea_cbc_for_encryption
76
+ assert_equal IDEA, encrypt("idea-cbc")
77
+ end
78
+
79
+ def test_idea_cbc_for_decryption
80
+ assert_equal TEXT, decrypt("idea-cbc", IDEA)
81
+ end
82
+ end
83
+
84
+ RIJNDAEL = "$\253\271\255\005Z\354\336&\312\324\221\233\307Mj\315\360\310Fk\241EfN\037\231\213\361{'\310\204\347I\343\271\005\240`\325;\034\346uM>#\241\231C`\374\261\vo\226;Z\302:\b\250\366T\330\\#V\330\340\226\363\374!\bm\266\232\207!\232\347\340\t\307\370\356z\236\343=v\210\206y"
85
+
86
+ def test_rijndael_cbc_for_encryption
87
+ assert_equal RIJNDAEL, encrypt("rijndael-cbc@lysator.liu.se")
88
+ end
89
+
90
+ def test_rijndael_cbc_for_decryption
91
+ assert_equal TEXT, decrypt("rijndael-cbc@lysator.liu.se", RIJNDAEL)
92
+ end
93
+
94
+ CAST128 = "qW\302\331\333P\223t[9 ~(sg\322\271\227\272\022I\223\373p\255>k\326\314\260\2003\236C_W\211\227\373\205>\351\334\322\227\223\e\236\202Ii\032!P\214\035:\017\360h7D\371v\210\264\317\236a\262w1\2772\023\036\331\227\240:\f/X\351\324I\t[x\350\323E\2301\016m"
95
+
96
+ def test_cast128_cbc_for_encryption
97
+ assert_equal CAST128, encrypt("cast128-cbc")
98
+ end
99
+
100
+ def test_cast128_cbc_for_decryption
101
+ assert_equal TEXT, decrypt("cast128-cbc", CAST128)
102
+ end
103
+
104
+ TRIPLE_DES = "\322\252\216D\303Q\375gg\367A{\177\313\3436\272\353%\223K?\257\206|\r&\353/%\340\336 \203E8rY\206\234\004\274\267\031\233T/{\"\227/B!i?[qGaw\306T\206\223\213n \212\032\244%]@\355\250\334\312\265E\251\017\361\270\357\230\274KP&^\031r+r%\370"
105
+
106
+ def test_3des_cbc_for_encryption
107
+ assert_equal TRIPLE_DES, encrypt("3des-cbc")
108
+ end
109
+
110
+ def test_3des_cbc_for_decryption
111
+ assert_equal TEXT, decrypt("3des-cbc", TRIPLE_DES)
112
+ end
113
+
114
+ AES128 = "k\026\350B\366-k\224\313\3277}B\035\004\200\035\r\233\024$\205\261\231Q\2214r\245\250\360\315\237\266hg\262C&+\321\346Pf\267v\376I\215P\327\345-\232&HK\375\326_\030<\a\276\212\303g\342C\242O\233\260\006\001a&V\345`\\T\e\236.\207\223l\233ri^\v\252\363\245"
115
+
116
+ def test_aes128_cbc_for_encryption
117
+ assert_equal AES128, encrypt("aes128-cbc")
118
+ end
119
+
120
+ def test_aes128_cbc_for_decryption
121
+ assert_equal TEXT, decrypt("aes128-cbc", AES128)
122
+ end
123
+
124
+ AES192 = "\256\017)x\270\213\336\303L\003f\235'jQ\3231k9\225\267\242\364C4\370\224\201\302~\217I\202\374\2167='\272\037\225\223\177Y\r\212\376(\275\n\3553\377\177\252C\254\236\016MA\274Z@H\331<\rL\317\205\323[\305X8\376\237=\374\352bH9\244\0231\353\204\352p\226\326~J\242"
125
+
126
+ def test_aes192_cbc_for_encryption
127
+ assert_equal AES192, encrypt("aes192-cbc")
128
+ end
129
+
130
+ def test_aes192_cbc_for_decryption
131
+ assert_equal TEXT, decrypt("aes192-cbc", AES192)
132
+ end
133
+
134
+ AES256 = "$\253\271\255\005Z\354\336&\312\324\221\233\307Mj\315\360\310Fk\241EfN\037\231\213\361{'\310\204\347I\343\271\005\240`\325;\034\346uM>#\241\231C`\374\261\vo\226;Z\302:\b\250\366T\330\\#V\330\340\226\363\374!\bm\266\232\207!\232\347\340\t\307\370\356z\236\343=v\210\206y"
135
+
136
+ def test_aes256_cbc_for_encryption
137
+ assert_equal AES256, encrypt("aes256-cbc")
138
+ end
139
+
140
+ def test_aes256_cbc_for_decryption
141
+ assert_equal TEXT, decrypt("aes256-cbc", AES256)
142
+ end
143
+
144
+ ARCFOUR128 = "\n\x90\xED*\xD4\xBE\xCBg5\xA5\a\xEC]\x97\xB7L\x06)6\x12FL\x90@\xF4Sqxqh\r\x11\x1Aq \xC8\xE6v\xC6\x12\xD9<A\xDAZ\xFE\x7F\x88\x19f.\x06\xA7\xFE:\xFF\x93\x9B\x8D\xA0\\\x9E\xCA\x03\x15\xE1\xE2\f\xC0\b\xA2C\xE1\xBD\xB6\x13D\xD1\xB4'g\x89\xDC\xEB\f\x19Z)U"
145
+
146
+ def test_arcfour128_for_encryption
147
+ assert_equal ARCFOUR128, encrypt("arcfour128")
148
+ end
149
+
150
+ def test_arcfour128_for_decryption
151
+ assert_equal TEXT, decrypt("arcfour128", ARCFOUR128)
152
+ end
153
+
154
+ ARCFOUR256 = "|g\xCCw\xF5\xC1y\xEB\xF0\v\xF7\x83\x14\x03\xC8\xAB\xE8\xC2\xFCY\xDC,\xB8\xD4dVa\x8B\x18%\xA4S\x00\xE0at\x86\xE8\xA6W\xAB\xD2\x9D\xA8\xDE[g\aZy.\xFB\xFC\x82c\x04h\f\xBFYq\xB7U\x80\x0EG\x91\x88\xDF\xA3\xA2\xFA(\xEC\xDB\xA4\xE7\xFE)\x12u\xAF\x0EZ\xA0\xBA\x97\n\xFC"
155
+
156
+ def test_arcfour256_for_encryption
157
+ assert_equal ARCFOUR256, encrypt("arcfour256")
158
+ end
159
+
160
+ def test_arcfour256_for_decryption
161
+ assert_equal TEXT, decrypt("arcfour256", ARCFOUR256)
162
+ end
163
+
164
+ ARCFOUR512 = "|8\"v\xE7\xE3\b\xA8\x19\x9Aa\xB6Vv\x00\x11\x8A$C\xB6xE\xEF\xF1j\x90\xA8\xFA\x10\xE4\xA1b8\xF6\x04\xF2+\xC0\xD1(8\xEBT]\xB0\xF3/\xD9\xE0@\x83\a\x93\x9D\xCA\x04RXS\xB7A\x0Fj\x94\bE\xEB\x84j\xB4\xDF\nU\xF7\x83o\n\xE8\xF9\x01{jH\xEE\xCDQym\x9E"
165
+
166
+ def test_arcfour512_for_encryption
167
+ assert_equal ARCFOUR512, encrypt("arcfour512")
168
+ end
169
+
170
+ def test_arcfour512_for_decryption
171
+ assert_equal TEXT, decrypt("arcfour512", ARCFOUR512)
172
+ end
173
+
174
+ def test_none_for_encryption
175
+ assert_equal TEXT, encrypt("none").strip
176
+ end
177
+
178
+ def test_none_for_decryption
179
+ assert_equal TEXT, decrypt("none", TEXT)
180
+ end
181
+
182
+ private
183
+
184
+ TEXT = "But soft! What light through yonder window breaks? It is the east, and Juliet is the sun!"
185
+
186
+ OPTIONS = { :iv => "ABC",
187
+ :key => "abc",
188
+ :digester => OpenSSL::Digest::MD5,
189
+ :shared => "1234567890123456780",
190
+ :hash => '!@#$%#$^%$&^&%#$@$'
191
+ }
192
+
193
+ def factory
194
+ Net::SSH::Transport::CipherFactory
195
+ end
196
+
197
+ def encrypt(type)
198
+ cipher = factory.get(type, OPTIONS.merge(:encrypt => true))
199
+ padding = TEXT.length % cipher.block_size
200
+ result = cipher.update(TEXT.dup)
201
+ result << cipher.update(" " * (cipher.block_size - padding)) if padding > 0
202
+ result << cipher.final
203
+ end
204
+
205
+ def decrypt(type, data)
206
+ cipher = factory.get(type, OPTIONS.merge(:decrypt => true))
207
+ result = cipher.update(data.dup)
208
+ result << cipher.final
209
+ result.strip
210
+ end
211
+ end
212
+
213
+ end