cifrado 0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (361) hide show
  1. data.tar.gz.sig +0 -0
  2. data/.gitignore +18 -0
  3. data/CHANGELOG.md +44 -0
  4. data/Gemfile +4 -0
  5. data/LICENSE.txt +22 -0
  6. data/README.md +247 -0
  7. data/RELEASE.md +10 -0
  8. data/Rakefile +21 -0
  9. data/TODO.md +6 -0
  10. data/bin/cifrado +7 -0
  11. data/cifrado.gemspec +31 -0
  12. data/gem-public_cert.pem +20 -0
  13. data/lib/cifrado.rb +48 -0
  14. data/lib/cifrado/cli.rb +140 -0
  15. data/lib/cifrado/cli/cinema.rb +81 -0
  16. data/lib/cifrado/cli/delete.rb +36 -0
  17. data/lib/cifrado/cli/download.rb +54 -0
  18. data/lib/cifrado/cli/jukebox.rb +94 -0
  19. data/lib/cifrado/cli/list.rb +64 -0
  20. data/lib/cifrado/cli/post.rb +10 -0
  21. data/lib/cifrado/cli/progressbar.rb +86 -0
  22. data/lib/cifrado/cli/saio.rb +11 -0
  23. data/lib/cifrado/cli/saio/base.rb +20 -0
  24. data/lib/cifrado/cli/saio/bootstrap.rb +118 -0
  25. data/lib/cifrado/cli/saio/destroy.rb +16 -0
  26. data/lib/cifrado/cli/saio/scripts/saio.sh.erb +445 -0
  27. data/lib/cifrado/cli/set_acl.rb +10 -0
  28. data/lib/cifrado/cli/setup.rb +64 -0
  29. data/lib/cifrado/cli/stat.rb +41 -0
  30. data/lib/cifrado/cli/upload.rb +269 -0
  31. data/lib/cifrado/config.rb +18 -0
  32. data/lib/cifrado/core_ext/ruby18_base64.rb +15 -0
  33. data/lib/cifrado/crypto_services.rb +218 -0
  34. data/lib/cifrado/file_splitter.rb +67 -0
  35. data/lib/cifrado/rate_limit.rb +23 -0
  36. data/lib/cifrado/streaming_downloader.rb +49 -0
  37. data/lib/cifrado/streaming_uploader.rb +57 -0
  38. data/lib/cifrado/swift_client.rb +313 -0
  39. data/lib/cifrado/utils.rb +59 -0
  40. data/lib/cifrado/version.rb +3 -0
  41. data/tests/cli/list_tests.rb +28 -0
  42. data/tests/cli/upload_multi_tests.rb +94 -0
  43. data/tests/cli/upload_tests.rb +167 -0
  44. data/tests/cli_tests.rb +2 -0
  45. data/tests/crypto_services_tests.rb +145 -0
  46. data/tests/file_splitter_tests.rb +61 -0
  47. data/tests/helper.rb +117 -0
  48. data/tests/swift_client/create_directory.rb +14 -0
  49. data/tests/swift_client/download_tests.rb +208 -0
  50. data/tests/swift_client/file_available.rb +25 -0
  51. data/tests/swift_client/head_tests.rb +34 -0
  52. data/tests/swift_client/match_tests.rb +29 -0
  53. data/tests/swift_client/upload_tests.rb +70 -0
  54. data/tests/swift_client_tests.rb +29 -0
  55. data/tests/utils_tests.rb +33 -0
  56. data/vendor/fog/.document +3 -0
  57. data/vendor/fog/.gitignore +23 -0
  58. data/vendor/fog/.irbrc +82 -0
  59. data/vendor/fog/.travis.yml +21 -0
  60. data/vendor/fog/README.cifrado +3 -0
  61. data/vendor/fog/README.md +156 -0
  62. data/vendor/fog/RELEASE.md +39 -0
  63. data/vendor/fog/changelog.txt +4156 -0
  64. data/vendor/fog/fog.gemspec +70 -0
  65. data/vendor/fog/lib/fog.rb +17 -0
  66. data/vendor/fog/lib/fog/cdn.rb +30 -0
  67. data/vendor/fog/lib/fog/compute.rb +127 -0
  68. data/vendor/fog/lib/fog/compute/models/server.rb +73 -0
  69. data/vendor/fog/lib/fog/core.rb +38 -0
  70. data/vendor/fog/lib/fog/core/attributes.rb +221 -0
  71. data/vendor/fog/lib/fog/core/collection.rb +145 -0
  72. data/vendor/fog/lib/fog/core/connection.rb +36 -0
  73. data/vendor/fog/lib/fog/core/credentials.rb +65 -0
  74. data/vendor/fog/lib/fog/core/current_machine.rb +34 -0
  75. data/vendor/fog/lib/fog/core/deprecated_connection_accessors.rb +41 -0
  76. data/vendor/fog/lib/fog/core/deprecation.rb +23 -0
  77. data/vendor/fog/lib/fog/core/errors.rb +108 -0
  78. data/vendor/fog/lib/fog/core/hmac.rb +48 -0
  79. data/vendor/fog/lib/fog/core/json.rb +34 -0
  80. data/vendor/fog/lib/fog/core/logger.rb +45 -0
  81. data/vendor/fog/lib/fog/core/mock.rb +92 -0
  82. data/vendor/fog/lib/fog/core/model.rb +79 -0
  83. data/vendor/fog/lib/fog/core/parser.rb +116 -0
  84. data/vendor/fog/lib/fog/core/provider.rb +35 -0
  85. data/vendor/fog/lib/fog/core/scp.rb +96 -0
  86. data/vendor/fog/lib/fog/core/service.rb +223 -0
  87. data/vendor/fog/lib/fog/core/ssh.rb +137 -0
  88. data/vendor/fog/lib/fog/core/time.rb +32 -0
  89. data/vendor/fog/lib/fog/core/timeout.rb +11 -0
  90. data/vendor/fog/lib/fog/core/wait_for.rb +15 -0
  91. data/vendor/fog/lib/fog/digitalocean.rb +9 -0
  92. data/vendor/fog/lib/fog/digitalocean/compute.rb +100 -0
  93. data/vendor/fog/lib/fog/digitalocean/examples/getting_started.md +106 -0
  94. data/vendor/fog/lib/fog/digitalocean/models/compute/flavor.rb +14 -0
  95. data/vendor/fog/lib/fog/digitalocean/models/compute/flavors.rb +25 -0
  96. data/vendor/fog/lib/fog/digitalocean/models/compute/image.rb +15 -0
  97. data/vendor/fog/lib/fog/digitalocean/models/compute/images.rb +25 -0
  98. data/vendor/fog/lib/fog/digitalocean/models/compute/region.rb +14 -0
  99. data/vendor/fog/lib/fog/digitalocean/models/compute/regions.rb +25 -0
  100. data/vendor/fog/lib/fog/digitalocean/models/compute/server.rb +150 -0
  101. data/vendor/fog/lib/fog/digitalocean/models/compute/servers.rb +27 -0
  102. data/vendor/fog/lib/fog/digitalocean/requests/compute/create_server.rb +49 -0
  103. data/vendor/fog/lib/fog/digitalocean/requests/compute/create_ssh_key.rb +26 -0
  104. data/vendor/fog/lib/fog/digitalocean/requests/compute/destroy_server.rb +28 -0
  105. data/vendor/fog/lib/fog/digitalocean/requests/compute/get_server_details.rb +25 -0
  106. data/vendor/fog/lib/fog/digitalocean/requests/compute/list_flavors.rb +25 -0
  107. data/vendor/fog/lib/fog/digitalocean/requests/compute/list_images.rb +25 -0
  108. data/vendor/fog/lib/fog/digitalocean/requests/compute/list_regions.rb +25 -0
  109. data/vendor/fog/lib/fog/digitalocean/requests/compute/list_servers.rb +25 -0
  110. data/vendor/fog/lib/fog/digitalocean/requests/compute/list_ssh_keys.rb +25 -0
  111. data/vendor/fog/lib/fog/digitalocean/requests/compute/power_cycle_server.rb +25 -0
  112. data/vendor/fog/lib/fog/digitalocean/requests/compute/power_off_server.rb +25 -0
  113. data/vendor/fog/lib/fog/digitalocean/requests/compute/power_on_server.rb +25 -0
  114. data/vendor/fog/lib/fog/digitalocean/requests/compute/reboot_server.rb +25 -0
  115. data/vendor/fog/lib/fog/digitalocean/requests/compute/shutdown_server.rb +25 -0
  116. data/vendor/fog/lib/fog/dns.rb +59 -0
  117. data/vendor/fog/lib/fog/identity.rb +27 -0
  118. data/vendor/fog/lib/fog/image.rb +24 -0
  119. data/vendor/fog/lib/fog/local.rb +11 -0
  120. data/vendor/fog/lib/fog/local/models/storage/directories.rb +33 -0
  121. data/vendor/fog/lib/fog/local/models/storage/directory.rb +57 -0
  122. data/vendor/fog/lib/fog/local/models/storage/file.rb +131 -0
  123. data/vendor/fog/lib/fog/local/models/storage/files.rb +87 -0
  124. data/vendor/fog/lib/fog/local/storage.rb +103 -0
  125. data/vendor/fog/lib/fog/network.rb +26 -0
  126. data/vendor/fog/lib/fog/openstack.rb +214 -0
  127. data/vendor/fog/lib/fog/openstack/README.identity.md +69 -0
  128. data/vendor/fog/lib/fog/openstack/compute.rb +423 -0
  129. data/vendor/fog/lib/fog/openstack/identity.rb +299 -0
  130. data/vendor/fog/lib/fog/openstack/image.rb +217 -0
  131. data/vendor/fog/lib/fog/openstack/models/compute/address.rb +71 -0
  132. data/vendor/fog/lib/fog/openstack/models/compute/addresses.rb +33 -0
  133. data/vendor/fog/lib/fog/openstack/models/compute/flavor.rb +45 -0
  134. data/vendor/fog/lib/fog/openstack/models/compute/flavors.rb +28 -0
  135. data/vendor/fog/lib/fog/openstack/models/compute/host.rb +29 -0
  136. data/vendor/fog/lib/fog/openstack/models/compute/hosts.rb +32 -0
  137. data/vendor/fog/lib/fog/openstack/models/compute/image.rb +58 -0
  138. data/vendor/fog/lib/fog/openstack/models/compute/images.rb +33 -0
  139. data/vendor/fog/lib/fog/openstack/models/compute/key_pair.rb +60 -0
  140. data/vendor/fog/lib/fog/openstack/models/compute/key_pairs.rb +31 -0
  141. data/vendor/fog/lib/fog/openstack/models/compute/metadata.rb +68 -0
  142. data/vendor/fog/lib/fog/openstack/models/compute/metadatum.rb +29 -0
  143. data/vendor/fog/lib/fog/openstack/models/compute/network.rb +13 -0
  144. data/vendor/fog/lib/fog/openstack/models/compute/networks.rb +29 -0
  145. data/vendor/fog/lib/fog/openstack/models/compute/security_group.rb +44 -0
  146. data/vendor/fog/lib/fog/openstack/models/compute/security_groups.rb +27 -0
  147. data/vendor/fog/lib/fog/openstack/models/compute/server.rb +278 -0
  148. data/vendor/fog/lib/fog/openstack/models/compute/servers.rb +44 -0
  149. data/vendor/fog/lib/fog/openstack/models/compute/snapshot.rb +44 -0
  150. data/vendor/fog/lib/fog/openstack/models/compute/snapshots.rb +26 -0
  151. data/vendor/fog/lib/fog/openstack/models/compute/tenant.rb +24 -0
  152. data/vendor/fog/lib/fog/openstack/models/compute/tenants.rb +24 -0
  153. data/vendor/fog/lib/fog/openstack/models/compute/volume.rb +59 -0
  154. data/vendor/fog/lib/fog/openstack/models/compute/volumes.rb +26 -0
  155. data/vendor/fog/lib/fog/openstack/models/identity/ec2_credential.rb +44 -0
  156. data/vendor/fog/lib/fog/openstack/models/identity/ec2_credentials.rb +53 -0
  157. data/vendor/fog/lib/fog/openstack/models/identity/role.rb +50 -0
  158. data/vendor/fog/lib/fog/openstack/models/identity/roles.rb +21 -0
  159. data/vendor/fog/lib/fog/openstack/models/identity/tenant.rb +62 -0
  160. data/vendor/fog/lib/fog/openstack/models/identity/tenants.rb +29 -0
  161. data/vendor/fog/lib/fog/openstack/models/identity/user.rb +70 -0
  162. data/vendor/fog/lib/fog/openstack/models/identity/users.rb +32 -0
  163. data/vendor/fog/lib/fog/openstack/models/image/image.rb +91 -0
  164. data/vendor/fog/lib/fog/openstack/models/image/images.rb +60 -0
  165. data/vendor/fog/lib/fog/openstack/models/meta_parent.rb +33 -0
  166. data/vendor/fog/lib/fog/openstack/models/network/floating_ip.rb +52 -0
  167. data/vendor/fog/lib/fog/openstack/models/network/floating_ips.rb +34 -0
  168. data/vendor/fog/lib/fog/openstack/models/network/network.rb +47 -0
  169. data/vendor/fog/lib/fog/openstack/models/network/networks.rb +34 -0
  170. data/vendor/fog/lib/fog/openstack/models/network/port.rb +53 -0
  171. data/vendor/fog/lib/fog/openstack/models/network/ports.rb +34 -0
  172. data/vendor/fog/lib/fog/openstack/models/network/subnet.rb +56 -0
  173. data/vendor/fog/lib/fog/openstack/models/network/subnets.rb +34 -0
  174. data/vendor/fog/lib/fog/openstack/models/storage/directories.rb +39 -0
  175. data/vendor/fog/lib/fog/openstack/models/storage/directory.rb +50 -0
  176. data/vendor/fog/lib/fog/openstack/models/storage/file.rb +152 -0
  177. data/vendor/fog/lib/fog/openstack/models/storage/files.rb +94 -0
  178. data/vendor/fog/lib/fog/openstack/models/volume/volume.rb +47 -0
  179. data/vendor/fog/lib/fog/openstack/models/volume/volumes.rb +27 -0
  180. data/vendor/fog/lib/fog/openstack/network.rb +247 -0
  181. data/vendor/fog/lib/fog/openstack/requests/compute/add_fixed_ip.rb +29 -0
  182. data/vendor/fog/lib/fog/openstack/requests/compute/allocate_address.rb +42 -0
  183. data/vendor/fog/lib/fog/openstack/requests/compute/associate_address.rb +27 -0
  184. data/vendor/fog/lib/fog/openstack/requests/compute/attach_volume.rb +38 -0
  185. data/vendor/fog/lib/fog/openstack/requests/compute/boot_from_snapshot.rb +41 -0
  186. data/vendor/fog/lib/fog/openstack/requests/compute/change_server_password.rb +24 -0
  187. data/vendor/fog/lib/fog/openstack/requests/compute/confirm_resize_server.rb +24 -0
  188. data/vendor/fog/lib/fog/openstack/requests/compute/create_flavor.rb +85 -0
  189. data/vendor/fog/lib/fog/openstack/requests/compute/create_image.rb +49 -0
  190. data/vendor/fog/lib/fog/openstack/requests/compute/create_key_pair.rb +49 -0
  191. data/vendor/fog/lib/fog/openstack/requests/compute/create_security_group.rb +52 -0
  192. data/vendor/fog/lib/fog/openstack/requests/compute/create_security_group_rule.rb +59 -0
  193. data/vendor/fog/lib/fog/openstack/requests/compute/create_server.rb +131 -0
  194. data/vendor/fog/lib/fog/openstack/requests/compute/create_volume.rb +54 -0
  195. data/vendor/fog/lib/fog/openstack/requests/compute/create_volume_snapshot.rb +47 -0
  196. data/vendor/fog/lib/fog/openstack/requests/compute/delete_flavor.rb +28 -0
  197. data/vendor/fog/lib/fog/openstack/requests/compute/delete_image.rb +40 -0
  198. data/vendor/fog/lib/fog/openstack/requests/compute/delete_key_pair.rb +31 -0
  199. data/vendor/fog/lib/fog/openstack/requests/compute/delete_metadata.rb +28 -0
  200. data/vendor/fog/lib/fog/openstack/requests/compute/delete_security_group.rb +33 -0
  201. data/vendor/fog/lib/fog/openstack/requests/compute/delete_security_group_rule.rb +31 -0
  202. data/vendor/fog/lib/fog/openstack/requests/compute/delete_server.rb +38 -0
  203. data/vendor/fog/lib/fog/openstack/requests/compute/delete_snapshot.rb +26 -0
  204. data/vendor/fog/lib/fog/openstack/requests/compute/delete_volume.rb +26 -0
  205. data/vendor/fog/lib/fog/openstack/requests/compute/detach_volume.rb +26 -0
  206. data/vendor/fog/lib/fog/openstack/requests/compute/disassociate_address.rb +27 -0
  207. data/vendor/fog/lib/fog/openstack/requests/compute/get_address.rb +41 -0
  208. data/vendor/fog/lib/fog/openstack/requests/compute/get_console_output.rb +28 -0
  209. data/vendor/fog/lib/fog/openstack/requests/compute/get_flavor_details.rb +43 -0
  210. data/vendor/fog/lib/fog/openstack/requests/compute/get_host_details.rb +74 -0
  211. data/vendor/fog/lib/fog/openstack/requests/compute/get_image_details.rb +33 -0
  212. data/vendor/fog/lib/fog/openstack/requests/compute/get_limits.rb +93 -0
  213. data/vendor/fog/lib/fog/openstack/requests/compute/get_metadata.rb +29 -0
  214. data/vendor/fog/lib/fog/openstack/requests/compute/get_quota.rb +31 -0
  215. data/vendor/fog/lib/fog/openstack/requests/compute/get_quota_defaults.rb +31 -0
  216. data/vendor/fog/lib/fog/openstack/requests/compute/get_security_group.rb +49 -0
  217. data/vendor/fog/lib/fog/openstack/requests/compute/get_server_details.rb +32 -0
  218. data/vendor/fog/lib/fog/openstack/requests/compute/get_server_volumes.rb +23 -0
  219. data/vendor/fog/lib/fog/openstack/requests/compute/get_snapshot_details.rb +39 -0
  220. data/vendor/fog/lib/fog/openstack/requests/compute/get_usage.rb +53 -0
  221. data/vendor/fog/lib/fog/openstack/requests/compute/get_vnc_console.rb +40 -0
  222. data/vendor/fog/lib/fog/openstack/requests/compute/get_volume_details.rb +42 -0
  223. data/vendor/fog/lib/fog/openstack/requests/compute/list_address_pools.rb +23 -0
  224. data/vendor/fog/lib/fog/openstack/requests/compute/list_addresses.rb +32 -0
  225. data/vendor/fog/lib/fog/openstack/requests/compute/list_all_addresses.rb +64 -0
  226. data/vendor/fog/lib/fog/openstack/requests/compute/list_flavors.rb +38 -0
  227. data/vendor/fog/lib/fog/openstack/requests/compute/list_flavors_detail.rb +38 -0
  228. data/vendor/fog/lib/fog/openstack/requests/compute/list_hosts.rb +32 -0
  229. data/vendor/fog/lib/fog/openstack/requests/compute/list_images.rb +33 -0
  230. data/vendor/fog/lib/fog/openstack/requests/compute/list_images_detail.rb +39 -0
  231. data/vendor/fog/lib/fog/openstack/requests/compute/list_key_pairs.rb +39 -0
  232. data/vendor/fog/lib/fog/openstack/requests/compute/list_metadata.rb +28 -0
  233. data/vendor/fog/lib/fog/openstack/requests/compute/list_private_addresses.rb +32 -0
  234. data/vendor/fog/lib/fog/openstack/requests/compute/list_public_addresses.rb +32 -0
  235. data/vendor/fog/lib/fog/openstack/requests/compute/list_security_groups.rb +50 -0
  236. data/vendor/fog/lib/fog/openstack/requests/compute/list_servers.rb +37 -0
  237. data/vendor/fog/lib/fog/openstack/requests/compute/list_servers_detail.rb +44 -0
  238. data/vendor/fog/lib/fog/openstack/requests/compute/list_snapshots.rb +32 -0
  239. data/vendor/fog/lib/fog/openstack/requests/compute/list_tenants.rb +45 -0
  240. data/vendor/fog/lib/fog/openstack/requests/compute/list_usages.rb +43 -0
  241. data/vendor/fog/lib/fog/openstack/requests/compute/list_volumes.rb +51 -0
  242. data/vendor/fog/lib/fog/openstack/requests/compute/live_migrate_server.rb +31 -0
  243. data/vendor/fog/lib/fog/openstack/requests/compute/migrate_server.rb +24 -0
  244. data/vendor/fog/lib/fog/openstack/requests/compute/pause_server.rb +24 -0
  245. data/vendor/fog/lib/fog/openstack/requests/compute/reboot_server.rb +24 -0
  246. data/vendor/fog/lib/fog/openstack/requests/compute/rebuild_server.rb +31 -0
  247. data/vendor/fog/lib/fog/openstack/requests/compute/release_address.rb +34 -0
  248. data/vendor/fog/lib/fog/openstack/requests/compute/remove_fixed_ip.rb +29 -0
  249. data/vendor/fog/lib/fog/openstack/requests/compute/rescue_server.rb +24 -0
  250. data/vendor/fog/lib/fog/openstack/requests/compute/reset_server_state.rb +24 -0
  251. data/vendor/fog/lib/fog/openstack/requests/compute/resize_server.rb +24 -0
  252. data/vendor/fog/lib/fog/openstack/requests/compute/resume_server.rb +24 -0
  253. data/vendor/fog/lib/fog/openstack/requests/compute/revert_resize_server.rb +30 -0
  254. data/vendor/fog/lib/fog/openstack/requests/compute/server_action.rb +18 -0
  255. data/vendor/fog/lib/fog/openstack/requests/compute/server_actions.rb +27 -0
  256. data/vendor/fog/lib/fog/openstack/requests/compute/server_diagnostics.rb +25 -0
  257. data/vendor/fog/lib/fog/openstack/requests/compute/set_metadata.rb +45 -0
  258. data/vendor/fog/lib/fog/openstack/requests/compute/set_tenant.rb +21 -0
  259. data/vendor/fog/lib/fog/openstack/requests/compute/suspend_server.rb +24 -0
  260. data/vendor/fog/lib/fog/openstack/requests/compute/unpause_server.rb +24 -0
  261. data/vendor/fog/lib/fog/openstack/requests/compute/update_metadata.rb +46 -0
  262. data/vendor/fog/lib/fog/openstack/requests/compute/update_quota.rb +32 -0
  263. data/vendor/fog/lib/fog/openstack/requests/compute/update_server.rb +35 -0
  264. data/vendor/fog/lib/fog/openstack/requests/identity/add_user_to_tenant.rb +34 -0
  265. data/vendor/fog/lib/fog/openstack/requests/identity/check_token.rb +23 -0
  266. data/vendor/fog/lib/fog/openstack/requests/identity/create_ec2_credential.rb +58 -0
  267. data/vendor/fog/lib/fog/openstack/requests/identity/create_role.rb +37 -0
  268. data/vendor/fog/lib/fog/openstack/requests/identity/create_tenant.rb +32 -0
  269. data/vendor/fog/lib/fog/openstack/requests/identity/create_user.rb +47 -0
  270. data/vendor/fog/lib/fog/openstack/requests/identity/create_user_role.rb +26 -0
  271. data/vendor/fog/lib/fog/openstack/requests/identity/delete_ec2_credential.rb +44 -0
  272. data/vendor/fog/lib/fog/openstack/requests/identity/delete_role.rb +32 -0
  273. data/vendor/fog/lib/fog/openstack/requests/identity/delete_tenant.rb +31 -0
  274. data/vendor/fog/lib/fog/openstack/requests/identity/delete_user.rb +32 -0
  275. data/vendor/fog/lib/fog/openstack/requests/identity/delete_user_role.rb +26 -0
  276. data/vendor/fog/lib/fog/openstack/requests/identity/get_ec2_credential.rb +49 -0
  277. data/vendor/fog/lib/fog/openstack/requests/identity/get_role.rb +28 -0
  278. data/vendor/fog/lib/fog/openstack/requests/identity/get_tenant.rb +31 -0
  279. data/vendor/fog/lib/fog/openstack/requests/identity/get_tenants_by_id.rb +23 -0
  280. data/vendor/fog/lib/fog/openstack/requests/identity/get_tenants_by_name.rb +23 -0
  281. data/vendor/fog/lib/fog/openstack/requests/identity/get_user_by_id.rb +34 -0
  282. data/vendor/fog/lib/fog/openstack/requests/identity/get_user_by_name.rb +31 -0
  283. data/vendor/fog/lib/fog/openstack/requests/identity/list_ec2_credentials.rb +44 -0
  284. data/vendor/fog/lib/fog/openstack/requests/identity/list_endpoints_for_token.rb +23 -0
  285. data/vendor/fog/lib/fog/openstack/requests/identity/list_roles.rb +36 -0
  286. data/vendor/fog/lib/fog/openstack/requests/identity/list_roles_for_user_on_tenant.rb +30 -0
  287. data/vendor/fog/lib/fog/openstack/requests/identity/list_tenants.rb +45 -0
  288. data/vendor/fog/lib/fog/openstack/requests/identity/list_user_global_roles.rb +22 -0
  289. data/vendor/fog/lib/fog/openstack/requests/identity/list_users.rb +34 -0
  290. data/vendor/fog/lib/fog/openstack/requests/identity/remove_user_from_tenant.rb +20 -0
  291. data/vendor/fog/lib/fog/openstack/requests/identity/set_tenant.rb +21 -0
  292. data/vendor/fog/lib/fog/openstack/requests/identity/update_tenant.rb +28 -0
  293. data/vendor/fog/lib/fog/openstack/requests/identity/update_user.rb +36 -0
  294. data/vendor/fog/lib/fog/openstack/requests/identity/validate_token.rb +23 -0
  295. data/vendor/fog/lib/fog/openstack/requests/image/add_member_to_image.rb +23 -0
  296. data/vendor/fog/lib/fog/openstack/requests/image/create_image.rb +79 -0
  297. data/vendor/fog/lib/fog/openstack/requests/image/delete_image.rb +25 -0
  298. data/vendor/fog/lib/fog/openstack/requests/image/get_image.rb +45 -0
  299. data/vendor/fog/lib/fog/openstack/requests/image/get_image_by_id.rb +32 -0
  300. data/vendor/fog/lib/fog/openstack/requests/image/get_image_members.rb +29 -0
  301. data/vendor/fog/lib/fog/openstack/requests/image/get_shared_images.rb +29 -0
  302. data/vendor/fog/lib/fog/openstack/requests/image/list_public_images.rb +32 -0
  303. data/vendor/fog/lib/fog/openstack/requests/image/list_public_images_detailed.rb +31 -0
  304. data/vendor/fog/lib/fog/openstack/requests/image/remove_member_from_image.rb +23 -0
  305. data/vendor/fog/lib/fog/openstack/requests/image/set_tenant.rb +21 -0
  306. data/vendor/fog/lib/fog/openstack/requests/image/update_image.rb +70 -0
  307. data/vendor/fog/lib/fog/openstack/requests/image/update_image_members.rb +37 -0
  308. data/vendor/fog/lib/fog/openstack/requests/network/associate_floating_ip.rb +49 -0
  309. data/vendor/fog/lib/fog/openstack/requests/network/create_floating_ip.rb +50 -0
  310. data/vendor/fog/lib/fog/openstack/requests/network/create_network.rb +44 -0
  311. data/vendor/fog/lib/fog/openstack/requests/network/create_port.rb +52 -0
  312. data/vendor/fog/lib/fog/openstack/requests/network/create_subnet.rb +56 -0
  313. data/vendor/fog/lib/fog/openstack/requests/network/delete_floating_ip.rb +30 -0
  314. data/vendor/fog/lib/fog/openstack/requests/network/delete_network.rb +30 -0
  315. data/vendor/fog/lib/fog/openstack/requests/network/delete_port.rb +30 -0
  316. data/vendor/fog/lib/fog/openstack/requests/network/delete_subnet.rb +30 -0
  317. data/vendor/fog/lib/fog/openstack/requests/network/disassociate_floating_ip.rb +49 -0
  318. data/vendor/fog/lib/fog/openstack/requests/network/get_floating_ip.rb +42 -0
  319. data/vendor/fog/lib/fog/openstack/requests/network/get_network.rb +42 -0
  320. data/vendor/fog/lib/fog/openstack/requests/network/get_port.rb +48 -0
  321. data/vendor/fog/lib/fog/openstack/requests/network/get_subnet.rb +49 -0
  322. data/vendor/fog/lib/fog/openstack/requests/network/list_floating_ips.rb +27 -0
  323. data/vendor/fog/lib/fog/openstack/requests/network/list_networks.rb +27 -0
  324. data/vendor/fog/lib/fog/openstack/requests/network/list_ports.rb +27 -0
  325. data/vendor/fog/lib/fog/openstack/requests/network/list_subnets.rb +27 -0
  326. data/vendor/fog/lib/fog/openstack/requests/network/set_tenant.rb +21 -0
  327. data/vendor/fog/lib/fog/openstack/requests/network/update_network.rb +41 -0
  328. data/vendor/fog/lib/fog/openstack/requests/network/update_port.rb +44 -0
  329. data/vendor/fog/lib/fog/openstack/requests/network/update_subnet.rb +44 -0
  330. data/vendor/fog/lib/fog/openstack/requests/storage/copy_object.rb +27 -0
  331. data/vendor/fog/lib/fog/openstack/requests/storage/delete_container.rb +22 -0
  332. data/vendor/fog/lib/fog/openstack/requests/storage/delete_object.rb +23 -0
  333. data/vendor/fog/lib/fog/openstack/requests/storage/get_container.rb +44 -0
  334. data/vendor/fog/lib/fog/openstack/requests/storage/get_containers.rb +33 -0
  335. data/vendor/fog/lib/fog/openstack/requests/storage/get_object.rb +29 -0
  336. data/vendor/fog/lib/fog/openstack/requests/storage/get_object_https_url.rb +51 -0
  337. data/vendor/fog/lib/fog/openstack/requests/storage/head_container.rb +28 -0
  338. data/vendor/fog/lib/fog/openstack/requests/storage/head_containers.rb +25 -0
  339. data/vendor/fog/lib/fog/openstack/requests/storage/head_object.rb +23 -0
  340. data/vendor/fog/lib/fog/openstack/requests/storage/post_set_meta_temp_url_key.rb +37 -0
  341. data/vendor/fog/lib/fog/openstack/requests/storage/put_container.rb +22 -0
  342. data/vendor/fog/lib/fog/openstack/requests/storage/put_object.rb +30 -0
  343. data/vendor/fog/lib/fog/openstack/requests/storage/put_object_manifest.rb +25 -0
  344. data/vendor/fog/lib/fog/openstack/requests/volume/create_volume.rb +54 -0
  345. data/vendor/fog/lib/fog/openstack/requests/volume/create_volume_snapshot.rb +47 -0
  346. data/vendor/fog/lib/fog/openstack/requests/volume/delete_snapshot.rb +26 -0
  347. data/vendor/fog/lib/fog/openstack/requests/volume/delete_volume.rb +26 -0
  348. data/vendor/fog/lib/fog/openstack/requests/volume/get_snapshot_details.rb +39 -0
  349. data/vendor/fog/lib/fog/openstack/requests/volume/get_volume_details.rb +42 -0
  350. data/vendor/fog/lib/fog/openstack/requests/volume/list_snapshots.rb +32 -0
  351. data/vendor/fog/lib/fog/openstack/requests/volume/list_volumes.rb +55 -0
  352. data/vendor/fog/lib/fog/openstack/requests/volume/set_tenant.rb +21 -0
  353. data/vendor/fog/lib/fog/openstack/storage.rb +162 -0
  354. data/vendor/fog/lib/fog/openstack/volume.rb +219 -0
  355. data/vendor/fog/lib/fog/providers.rb +2 -0
  356. data/vendor/fog/lib/fog/schema/data_validator.rb +154 -0
  357. data/vendor/fog/lib/fog/storage.rb +97 -0
  358. data/vendor/fog/lib/fog/version.rb +3 -0
  359. data/vendor/fog/lib/fog/volume.rb +25 -0
  360. metadata +576 -0
  361. metadata.gz.sig +0 -0
@@ -0,0 +1,10 @@
1
+ module Cifrado
2
+ class CLI
3
+ desc "set-acl CONTAINER", 'Set an ACL on containers and objects'
4
+ option :acl, :type => :string, :required => true
5
+ def set_acl(container, object = nil)
6
+ client = client_instance
7
+ client.set_acl options[:acl], container
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,64 @@
1
+ module Cifrado
2
+ class CLI
3
+ desc "setup", "Initial Cifrado configuration"
4
+ def setup
5
+ config_file = File.join(ENV['HOME'], '.config/cifrado/cifradorc')
6
+ unless File.directory?('.config/cifrado')
7
+ FileUtils.mkdir_p '.config/cifrado'
8
+ end
9
+ if File.exist?(config_file)
10
+ Log.warn "Config file #{set_color config_file, :bold} already exist."
11
+ Log.warn "IMPORTANT: Make sure you backup the current config"
12
+ Log.warn "before saving a new configuration."
13
+ unless yes? "Continue?"
14
+ return
15
+ end
16
+ config = YAML.load_file(config_file)
17
+ else
18
+ config = {}
19
+ end
20
+
21
+
22
+ puts "Running cifrado setup..."
23
+ puts "Please provide OpenStack/Rackspace credentials."
24
+ puts
25
+ puts "Cifrado can save this settings in #{config_file}"
26
+ puts "for later use."
27
+ puts "The settings (password included) are saved unencrypted."
28
+ puts
29
+ config[:username] = ask(set_color('Username:', :bold))
30
+ config[:tenant] = ask(set_color('Tenant:', :bold))
31
+ system 'stty -echo'
32
+ config[:password] = ask(set_color 'Password:', :bold)
33
+ system 'stty echo'
34
+ puts
35
+ config[:auth_url] = ask(set_color 'Auth URL:', :bold)
36
+
37
+ if !config[:secure_random]
38
+ # shit happens
39
+ if RUBY_VERSION >= '1.9'
40
+ config[:secure_random] = SecureRandom.hex.encode('UTF-8')
41
+ else
42
+ config[:secure_random] = SecureRandom.hex
43
+ end
44
+ end
45
+
46
+ if yes? "Do you want to save these settings? (y/n) "
47
+ if File.exist?(config_file)
48
+ backup = "#{config_file}.bak.#{Time.now.to_i}"
49
+ FileUtils.cp config_file, backup
50
+ Log.info "Saving backup file to #{backup}."
51
+ end
52
+ File.open(config_file, 'w') do |f|
53
+ f.puts config.to_yaml
54
+ f.chmod 0600
55
+ end
56
+ @settings_saved = true
57
+ Log.info "Saved!"
58
+ end
59
+
60
+ Log.debug "Setup done"
61
+ config
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,41 @@
1
+ module Cifrado
2
+ class CLI
3
+ desc "stat [CONTAINER] [OBJECT]", "Displays information for the account, container, or object."
4
+ def stat(container = nil, object = nil)
5
+ client = client_instance
6
+ creds = client.service.credentials
7
+ mgmt_url = creds[:server_management_url]
8
+
9
+ reject_headers = ['Accept-Ranges', 'X-Trans-Id']
10
+ unless container and object
11
+ reject_headers << 'Content-Length'
12
+ end
13
+ reject_headers << 'Content-Type' unless object
14
+
15
+ object = clean_object_name(object) if object
16
+ headers = client.head(container, object)
17
+ if headers
18
+ puts "Account:".ljust(30) + File.basename(URI.parse(mgmt_url).path)
19
+ headers.sort.each do |k, v|
20
+ next if reject_headers.include?(k)
21
+ if k == 'X-Timestamp'
22
+ puts "#{(k + ":").ljust(30)}#{v} (#{unix_time(v)})"
23
+ elsif k == 'X-Account-Bytes-Used' or k == 'Content-Length'
24
+ puts "#{(k + ":").ljust(30)}#{v} (#{humanize_bytes(v)})"
25
+ elsif k == 'X-Object-Meta-Encrypted-Name'
26
+ puts "#{(k + ":").ljust(30)}#{v}"
27
+ else
28
+ puts "#{(k + ":").ljust(30)}#{v}"
29
+ end
30
+ end
31
+ else
32
+ if object
33
+ raise "Object not found."
34
+ else
35
+ raise "Container not found."
36
+ end
37
+ end
38
+ headers
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,269 @@
1
+ module Cifrado
2
+ class CLI
3
+
4
+ desc "upload CONTAINER FILE1 [FILE2] ...",
5
+ "Upload files or directories"
6
+ option :encrypt,
7
+ :desc => 'Encrypt files when uploading'
8
+
9
+ option :segments,
10
+ :type => :numeric,
11
+ :desc => "Split the data into segments"
12
+
13
+ option :strip_path,
14
+ :type => :boolean,
15
+ :desc => 'Strip path from file when uploading'
16
+
17
+ option :progressbar,
18
+ :default => :fancy,
19
+ :desc => 'Progressbar style'
20
+
21
+ option :bwlimit,
22
+ :type => :numeric,
23
+ :desc => 'Limit the bandwidth available for uploads'
24
+
25
+ option :force,
26
+ :type => :boolean,
27
+ :desc => 'Overwrite files when uploading'
28
+ def upload(container, *args)
29
+
30
+ if args.empty?
31
+ help 'upload'
32
+ raise "No files specified"
33
+ end
34
+
35
+ client = client_instance
36
+
37
+ uploaded = []
38
+ args.each do |file|
39
+ unless file and File.exist?(file)
40
+ raise "File '#{file}' does not exist"
41
+ end
42
+
43
+ if File.directory?(file)
44
+ files = Dir["#{file}/**/*"].reject { |f| File.directory?(f) }
45
+ else
46
+ files = [file]
47
+ end
48
+
49
+ files.each do |f|
50
+ begin
51
+ if options[:segments]
52
+ uploaded << split_and_upload(client, container, f)
53
+ else
54
+ headers = client.head container, clean_object_name(f)
55
+ if headers
56
+ if headers['Etag'] == Digest::MD5.file(f).to_s
57
+ if options[:force]
58
+ Log.warn "File #{f} already uploaded and MD5 matches."
59
+ Log.warn "Since --force was used, uploading it again."
60
+ uploaded << upload_single(client, container, f)
61
+ else
62
+ Log.warn "File #{f} already uploaded and MD5 matches, skipping."
63
+ end
64
+ else
65
+ Log.warn "File #{f} already uploaded, but it has changed."
66
+ if options[:force]
67
+ Log.warn "Overwriting it as requested (--force)."
68
+ uploaded << upload_single(client, container, f)
69
+ else
70
+ Log.warn "Since --force was not used, skipping it."
71
+ end
72
+ end
73
+ else
74
+ uploaded << upload_single(client, container, f)
75
+ end
76
+ end
77
+ rescue Errno::ENOENT => e
78
+ Log.error "Error uploading #{f}: " + e.message
79
+ end
80
+ end
81
+ end
82
+ uploaded.flatten
83
+ end
84
+
85
+ private
86
+ def upload_single(client, container, object)
87
+ fsize = File.size(object)
88
+ fbasename = File.basename(object)
89
+ Log.info "Uploading #{object} (#{humanize_bytes(fsize)})"
90
+
91
+ pb = Progressbar.new 1, 1, :style => options[:progressbar]
92
+
93
+ config = Cifrado::Config.instance
94
+ object_path = object
95
+ object_path = File.basename(object) if options[:strip_path]
96
+ if cs = needs_encryption
97
+ encrypted_file = File.join(config.cache_dir, File.basename(object))
98
+ Log.debug "Writing encrypted file to #{encrypted_file}"
99
+ encrypted_output = cs.encrypt object,
100
+ encrypted_file
101
+ encrypted_name = encrypt_filename object, secure_password
102
+ client.upload container,
103
+ encrypted_output,
104
+ :headers => {
105
+ 'X-Object-Meta-Encrypted-Name' => encrypted_name
106
+ },
107
+ :object_path => File.basename(encrypted_output),
108
+ :progress_callback => pb.block,
109
+ :bwlimit => bwlimit
110
+ object_path = File.basename(encrypted_output)
111
+ File.delete encrypted_output
112
+ else
113
+ client.upload container,
114
+ object,
115
+ :object_path => object_path,
116
+ :progress_callback => pb.block,
117
+ :bwlimit => bwlimit
118
+ end
119
+ object_path
120
+ end
121
+
122
+ def needs_encryption
123
+ return nil unless options[:encrypt]
124
+
125
+ tokens = options[:encrypt].split(':')
126
+ etype = tokens.first
127
+ if etype == 'a'
128
+ recipient = tokens[1..-1].join(':')
129
+ CryptoServices.new :type => :asymmetric,
130
+ :recipient => recipient,
131
+ :encrypt_name => true
132
+ elsif etype == 's' or etype == 'symmetric'
133
+ if etype == 'symmetric'
134
+ Log.info "Password to encrypt the data required"
135
+ system 'stty -echo'
136
+ passphrase = ask("Enter passphrase:")
137
+ puts
138
+ passphrase2 = ask("Repeat passphrase:")
139
+ puts
140
+ if passphrase != passphrase2
141
+ raise 'Passphrase does not match'
142
+ end
143
+ system 'stty echo'
144
+ else
145
+ passphrase = tokens[1..-1].join(':')
146
+ end
147
+ unless passphrase
148
+ raise "Invalid symmetric encryption passprase"
149
+ end
150
+ CryptoServices.new :type => :symmetric,
151
+ :passphrase => passphrase,
152
+ :encrypt_name => true
153
+ else
154
+ raise "Invalid encryption type #{etype}."
155
+ end
156
+ end
157
+
158
+ def encrypt_if_required(file)
159
+ if cs = needs_encryption
160
+ Log.debug "Encrypting object #{file}"
161
+ cache_dir = Cifrado::Config.instance.cache_dir
162
+ encrypted_output = cs.encrypt file,
163
+ File.join(cache_dir, File.basename(file))
164
+ else
165
+ file
166
+ end
167
+ end
168
+
169
+ # FIXME: needs refactoring
170
+ def split_and_upload(client, container, object)
171
+ fbasename = File.basename(object)
172
+
173
+ # Encrypts the file if required
174
+ out = encrypt_if_required(object)
175
+
176
+ splitter = FileSplitter.new out, options[:segments]
177
+
178
+ if options[:encrypt]
179
+ target_manifest = File.basename(out)
180
+ else
181
+ target_manifest = (options[:strip_path] ? \
182
+ File.basename(object) : clean_object_name(object))
183
+ end
184
+
185
+ Log.info "Segmenting file, #{options[:segments]} segments..."
186
+ Log.info "Uploading #{fbasename} segments"
187
+
188
+ segments_uploaded = []
189
+ splitter.split do |n, segment|
190
+ segment_size = File.size segment
191
+ hsegment_size = humanize_bytes segment_size
192
+ Log.info "Uploading segment #{n}/#{options[:segments]} (#{hsegment_size})"
193
+
194
+ segment_number = "%08d" % n
195
+ if options[:encrypt]
196
+ suffix = splitter.chunk_suffix + segment_number
197
+ obj_path = File.basename(out) + suffix
198
+ Log.debug "Encrypted object path: #{obj_path}"
199
+ encrypted_name = encrypt_filename object + suffix,
200
+ secure_password
201
+ headers = {
202
+ 'X-Object-Meta-Encrypted-Name' => encrypted_name
203
+ }
204
+ else
205
+ obj_path = object + splitter.chunk_suffix + segment_number
206
+ Log.debug "Unencrypted object path #{obj_path}"
207
+ if options[:strip_path]
208
+ obj_path = File.basename(obj_path)
209
+ Log.debug "Stripping path from object: #{obj_path}"
210
+ end
211
+ Log.debug "Uploading segment #{obj_path} (#{segment_size} bytes)..."
212
+ headers = {}
213
+ end
214
+
215
+ case client.match(segment, container + "_segments", obj_path)
216
+ when 1
217
+ Log.warn 'Segment already uploaded, skipping.'
218
+ File.delete segment
219
+ next
220
+ when 2
221
+ Log.warn 'Segment already uploaded but looks different. Updating.'
222
+ end
223
+
224
+ pb = Progressbar.new options[:segments],
225
+ n,
226
+ :style => options[:progressbar]
227
+
228
+ client.upload container + "_segments",
229
+ segment,
230
+ :headers => headers,
231
+ :object_path => obj_path,
232
+ :progress_callback => pb.block,
233
+ :bwlimit => bwlimit
234
+
235
+ File.delete segment
236
+ segments_uploaded << obj_path
237
+ end
238
+
239
+ if options[:encrypt]
240
+ Log.debug "Deleting temporal encrypted file #{out}"
241
+ File.delete out
242
+ end
243
+
244
+ if segments_uploaded.size == 0
245
+ Log.warn 'All the segments have been previously uploaded.'
246
+ Log.warn 'Skipping manifest creation.'
247
+ return segments_uploaded
248
+ end
249
+
250
+ # We need this for segmented uploads
251
+ Log.debug "Adding manifest path #{target_manifest}"
252
+ xom = "#{Fog::OpenStack.escape(container + '_segments')}/" +
253
+ "#{Fog::OpenStack.escape(target_manifest)}"
254
+ headers = { 'X-Object-Manifest' => xom }
255
+ if options[:encrypt]
256
+ encrypted_name = encrypt_filename object, secure_password
257
+ headers['X-Object-Meta-Encrypted-Name'] = encrypted_name
258
+ end
259
+ client.create_directory container
260
+ client.service.put_object_manifest container,
261
+ target_manifest,
262
+ headers
263
+ segments_uploaded.insert 0, target_manifest
264
+
265
+ segments_uploaded
266
+ end
267
+
268
+ end
269
+ end
@@ -0,0 +1,18 @@
1
+ require 'singleton'
2
+
3
+ module Cifrado
4
+ class Config
5
+ include Singleton
6
+
7
+ def initialize
8
+ unless File.directory?(cache_dir)
9
+ Log.debug "Creating cache dir: #{cache_dir}"
10
+ FileUtils.mkdir_p(cache_dir)
11
+ end
12
+ end
13
+
14
+ def cache_dir
15
+ File.join(ENV['HOME'], '.cache/cifrado')
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,15 @@
1
+ # Adds urlsafe_encode64 and urlsafe_decode64 for Ruby 1.8.
2
+ if RUBY_VERSION < '1.9'
3
+ module Base64
4
+ module_function
5
+
6
+ def urlsafe_encode64(str)
7
+ [str].pack("m0").tr("\n",'').tr("+/", "-_")
8
+ end
9
+
10
+ def urlsafe_decode64(str)
11
+ str.tr("-_", "+/").unpack("m0").first
12
+ end
13
+ end
14
+ end
15
+
@@ -0,0 +1,218 @@
1
+ require 'digest/sha2'
2
+ require 'base64'
3
+
4
+ module Cifrado
5
+ class CryptoServices
6
+
7
+ def initialize(options = {})
8
+ @options = options
9
+ @gpg_binary = @options[:gpg_binary] || '/usr/bin/gpg'
10
+ @gpg_extra_args = @options[:gpg_extra_args] || []
11
+ @gpg_extra_args = @gpg_extra_args.concat %w(--batch --yes)
12
+ @encrypt_name = @options[:encrypt_name] || false
13
+ end
14
+
15
+ def encrypt(file, output)
16
+ unless file and File.exist?(file)
17
+ raise ArgumentError.new "Invalid file #{file}"
18
+ end
19
+
20
+ if output.nil?
21
+ raise ArgumentError.new "Invalid output file path"
22
+ end
23
+
24
+ # so we can use --use-embedded-filename to recover the original
25
+ # filename
26
+ Log.debug "Setting GPG filename #{file} (Base64 URL encoded)"
27
+ clean_path = Pathname.new(file).cleanpath.to_s
28
+ @gpg_extra_args << "--set-filename '#{Base64.urlsafe_encode64(clean_path)}'"
29
+
30
+ check_args
31
+ raise ArgumentError.new("#{@gpg_binary} not found") unless File.exist?(@gpg_binary)
32
+
33
+ Log.debug "Encrypting file #{file}..."
34
+ if @encrypt_name and output != '-'
35
+ Log.debug "Scrambling file name #{file}..."
36
+ dir = File.dirname(output)
37
+ #output = File.join dir, (Digest::SHA2.new << (output + SecureRandom.hex)).to_s
38
+ output = File.join dir, (Digest::SHA2.new << file).to_s
39
+ end
40
+
41
+ if output != '-'
42
+ @gpg_extra_args << ["--output #{Shellwords.escape(output)}"]
43
+ end
44
+
45
+ if @options[:type] == :asymmetric
46
+ asymmetric file, output
47
+ else @options[:type] == :symmetric
48
+ symmetric file, output
49
+ end
50
+ end
51
+
52
+ def self.encrypted?(file)
53
+ output = `/usr/bin/gpg --yes --batch --no-use-agent --list-packets #{file} 2>&1`
54
+ Log.debug output
55
+ if output.match(/AES256 encrypted|encrypted with\s.*\skey,\sID\s.*created/m).nil?
56
+ return false
57
+ end
58
+ true
59
+ end
60
+
61
+ def decrypt(file, output)
62
+ unless file and File.exist?(file)
63
+ raise ArgumentError.new "Invalid file #{file}"
64
+ end
65
+
66
+ if output.nil?
67
+ raise ArgumentError.new "Invalid output file path"
68
+ end
69
+
70
+ raise ArgumentError.new("#{@gpg_binary} not found") unless File.exist?(@gpg_binary)
71
+
72
+ Log.debug "Decrypting file #{file}..."
73
+
74
+ if output != '-'
75
+ @gpg_extra_args << "--output #{Shellwords.escape(output)}"
76
+ end
77
+
78
+ if @options[:passphrase]
79
+ @gpg_extra_args << "--no-use-agent --passphrase #{@options[:passphrase]}"
80
+ end
81
+
82
+ cmd = "#{@gpg_binary} #{@gpg_extra_args.join(' ')} --decrypt #{Shellwords.escape(file)}"
83
+ Log.debug "Decrypting with: #{cmd}"
84
+ out = `#{cmd} 2>&1`
85
+
86
+ if $? != 0
87
+ raise "Failed to decrypt file #{file}\n#{out}"
88
+ else
89
+ if @options[:delete_source]
90
+ File.delete file
91
+ Log.debug "Deleting encrypted file #{file}"
92
+ end
93
+ end
94
+
95
+ Log.debug out
96
+ output
97
+ end
98
+
99
+ private
100
+
101
+ def check_args
102
+ if @options[:type] == :asymmetric
103
+ unless @options[:recipient]
104
+ raise ArgumentError.new('Missing encryption recipient')
105
+ end
106
+ elsif @options[:type] == :symmetric
107
+ unless @options[:passphrase]
108
+ raise ArgumentError.new('Missing encryption passphrase')
109
+ end
110
+ else
111
+ raise ArgumentError.new "Unknown encryption type #{@options[:type]}"
112
+ end
113
+ end
114
+
115
+ def symmetric(file, output)
116
+ pfile = "/tmp/#{SecureRandom.hex}"
117
+ File.open(pfile, 'w') { |f| f.puts @options[:passphrase]; f.sync }
118
+ cmd = "#{@gpg_binary} #{@gpg_extra_args.join(' ')} --no-use-agent --passphrase-file #{pfile} --cipher-algo aes256 --symmetric #{Shellwords.escape(file)}"
119
+ #File.delete(pfile)
120
+ Log.debug "Encrypting with: #{cmd}"
121
+ out = `#{cmd} 2>&1`
122
+
123
+ if $? != 0
124
+ raise "Failed to encrypt file #{file}\n#{out}"
125
+ else
126
+ if @options[:delete_source]
127
+ File.delete file
128
+ Log.debug "Deleting unencrypted chunk #{file}"
129
+ end
130
+ end
131
+
132
+ Log.debug out
133
+ output
134
+ end
135
+
136
+ def asymmetric(file, output)
137
+ recipient = @options[:recipient]
138
+ cmd = "#{@gpg_binary} #{@gpg_extra_args.join(' ')} --no-encrypt-to --no-default-recipient --recipient '#{recipient}' --encrypt #{Shellwords.escape(file)}"
139
+ Log.debug "Encrypting with: #{cmd}"
140
+ out = `#{cmd} 2>&1`
141
+
142
+ if $? != 0
143
+ raise "Failed to encrypt file #{file}\n#{out}"
144
+ else
145
+ if @options[:delete_source]
146
+ File.delete file
147
+ Log.debug "Deleting unencrypted chunk #{file}"
148
+ end
149
+ end
150
+
151
+ Log.debug out
152
+ output
153
+ end
154
+
155
+ end
156
+
157
+ #
158
+ # Shamelessly stolen from Gibberish, from Mark Percival
159
+ # so I don't have to depend on yet another gem.
160
+ #
161
+ # See: https://github.com/mdp/gibberish
162
+ #
163
+ # Added a few small modifications:
164
+ #
165
+ # * Use Base64 urlsafe_encode/decode
166
+ #
167
+ class CryptoEngineAES
168
+
169
+ attr_reader :password, :size, :cipher
170
+
171
+ # Initialize with the password
172
+ #
173
+ # @param [String] password
174
+ # @param [Integer] size
175
+ def initialize(password, size=256)
176
+ @password = password
177
+ @size = size
178
+ @cipher = OpenSSL::Cipher::Cipher.new("aes-#{size}-cbc")
179
+ end
180
+
181
+ def encrypt(data, opts={})
182
+ salt = generate_salt(opts[:salt])
183
+ setup_cipher(:encrypt, salt)
184
+ e = cipher.update(data) + cipher.final
185
+ e = "Salted__#{salt}#{e}" #OpenSSL compatible
186
+ opts[:binary] ? e : Base64.urlsafe_encode64(e)
187
+ end
188
+ alias :enc :encrypt
189
+ alias :e :encrypt
190
+
191
+ def decrypt(data, opts={})
192
+ data = Base64.urlsafe_decode64(data) unless opts[:binary]
193
+ salt = data[8..15]
194
+ data = data[16..-1]
195
+ setup_cipher(:decrypt, salt)
196
+ cipher.update(data) + cipher.final
197
+ end
198
+ alias :dec :decrypt
199
+ alias :d :decrypt
200
+
201
+ private
202
+
203
+ def generate_salt(supplied_salt)
204
+ if supplied_salt
205
+ return supplied_salt.to_s[0,8].ljust(8,'.')
206
+ end
207
+ s = ''
208
+ 8.times {s << rand(255).chr}
209
+ s
210
+ end
211
+
212
+ def setup_cipher(method, salt)
213
+ cipher.send(method)
214
+ cipher.pkcs5_keyivgen(password, salt, 1)
215
+ end
216
+ end
217
+
218
+ end