rubygems-update 1.8.30 → 2.0.0.preview2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of rubygems-update might be problematic. Click here for more details.

Files changed (241) hide show
  1. checksums.yaml +6 -6
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +3 -0
  4. data/.autotest +6 -3
  5. data/History.txt +137 -63
  6. data/LICENSE.txt +1 -5
  7. data/Manifest.txt +69 -32
  8. data/README.rdoc +11 -9
  9. data/Rakefile +24 -38
  10. data/bin/gem +0 -9
  11. data/bin/update_rubygems +1 -0
  12. data/lib/rubygems.rb +193 -405
  13. data/lib/rubygems/available_set.rb +95 -0
  14. data/lib/rubygems/command.rb +88 -45
  15. data/lib/rubygems/command_manager.rb +67 -40
  16. data/lib/rubygems/commands/build_command.rb +5 -23
  17. data/lib/rubygems/commands/cert_command.rb +199 -57
  18. data/lib/rubygems/commands/check_command.rb +14 -39
  19. data/lib/rubygems/commands/cleanup_command.rb +9 -1
  20. data/lib/rubygems/commands/contents_command.rb +30 -12
  21. data/lib/rubygems/commands/dependency_command.rb +3 -8
  22. data/lib/rubygems/commands/environment_command.rb +13 -8
  23. data/lib/rubygems/commands/fetch_command.rb +3 -16
  24. data/lib/rubygems/commands/generate_index_command.rb +7 -47
  25. data/lib/rubygems/commands/help_command.rb +1 -1
  26. data/lib/rubygems/commands/install_command.rb +69 -36
  27. data/lib/rubygems/commands/list_command.rb +6 -4
  28. data/lib/rubygems/commands/lock_command.rb +1 -1
  29. data/lib/rubygems/commands/mirror_command.rb +17 -0
  30. data/lib/rubygems/commands/outdated_command.rb +6 -3
  31. data/lib/rubygems/commands/owner_command.rb +13 -5
  32. data/lib/rubygems/commands/pristine_command.rb +19 -4
  33. data/lib/rubygems/commands/push_command.rb +12 -1
  34. data/lib/rubygems/commands/query_command.rb +43 -27
  35. data/lib/rubygems/commands/rdoc_command.rb +23 -28
  36. data/lib/rubygems/commands/search_command.rb +4 -18
  37. data/lib/rubygems/commands/server_command.rb +1 -1
  38. data/lib/rubygems/commands/setup_command.rb +124 -38
  39. data/lib/rubygems/commands/sources_command.rb +16 -16
  40. data/lib/rubygems/commands/specification_command.rb +11 -13
  41. data/lib/rubygems/commands/uninstall_command.rb +24 -7
  42. data/lib/rubygems/commands/unpack_command.rb +7 -3
  43. data/lib/rubygems/commands/update_command.rb +22 -36
  44. data/lib/rubygems/commands/yank_command.rb +98 -0
  45. data/lib/rubygems/compatibility.rb +51 -0
  46. data/lib/rubygems/config_file.rb +82 -54
  47. data/lib/rubygems/core_ext/kernel_gem.rb +53 -0
  48. data/lib/rubygems/core_ext/kernel_require.rb +119 -0
  49. data/lib/rubygems/defaults.rb +10 -21
  50. data/lib/rubygems/dependency.rb +61 -10
  51. data/lib/rubygems/dependency_installer.rb +157 -69
  52. data/lib/rubygems/dependency_list.rb +11 -19
  53. data/lib/rubygems/dependency_resolver.rb +562 -0
  54. data/lib/rubygems/deprecate.rb +40 -40
  55. data/lib/rubygems/errors.rb +77 -24
  56. data/lib/rubygems/exceptions.rb +25 -7
  57. data/lib/rubygems/ext/builder.rb +20 -23
  58. data/lib/rubygems/ext/configure_builder.rb +2 -2
  59. data/lib/rubygems/ext/ext_conf_builder.rb +5 -45
  60. data/lib/rubygems/ext/rake_builder.rb +2 -2
  61. data/lib/rubygems/gem_runner.rb +3 -16
  62. data/lib/rubygems/gemcutter_utilities.rb +22 -7
  63. data/lib/rubygems/indexer.rb +6 -159
  64. data/lib/rubygems/install_message.rb +12 -0
  65. data/lib/rubygems/install_update_options.rb +56 -18
  66. data/lib/rubygems/installer.rb +244 -134
  67. data/lib/rubygems/installer_test_case.rb +71 -19
  68. data/lib/rubygems/mock_gem_ui.rb +17 -0
  69. data/lib/rubygems/name_tuple.rb +110 -0
  70. data/lib/rubygems/package.rb +514 -43
  71. data/lib/rubygems/package/digest_io.rb +64 -0
  72. data/lib/rubygems/package/old.rb +147 -0
  73. data/lib/rubygems/package/tar_header.rb +18 -55
  74. data/lib/rubygems/package/tar_reader.rb +20 -3
  75. data/lib/rubygems/package/tar_writer.rb +63 -7
  76. data/lib/rubygems/package_task.rb +3 -4
  77. data/lib/rubygems/path_support.rb +14 -7
  78. data/lib/rubygems/platform.rb +19 -26
  79. data/lib/rubygems/rdoc.rb +316 -0
  80. data/lib/rubygems/remote_fetcher.rb +117 -54
  81. data/lib/rubygems/request_set.rb +182 -0
  82. data/lib/rubygems/requirement.rb +63 -26
  83. data/lib/rubygems/security.rb +295 -555
  84. data/lib/rubygems/security/policies.rb +115 -0
  85. data/lib/rubygems/security/policy.rb +227 -0
  86. data/lib/rubygems/security/signer.rb +136 -0
  87. data/lib/rubygems/security/trust_dir.rb +104 -0
  88. data/lib/rubygems/server.rb +45 -55
  89. data/lib/rubygems/source.rb +144 -0
  90. data/lib/rubygems/source_list.rb +87 -0
  91. data/lib/rubygems/source_local.rb +92 -0
  92. data/lib/rubygems/source_specific_file.rb +28 -0
  93. data/lib/rubygems/spec_fetcher.rb +116 -184
  94. data/lib/rubygems/specification.rb +731 -335
  95. data/lib/rubygems/ssl_certs/AddTrustExternalCARoot.pem +88 -30
  96. data/lib/rubygems/ssl_certs/Entrust_net-Secure-Server-Certification-Authority.pem +90 -0
  97. data/lib/rubygems/ssl_certs/VerisignClass3PublicPrimaryCertificationAuthority-G2.pem +57 -0
  98. data/lib/rubygems/syck_hack.rb +2 -0
  99. data/lib/rubygems/test_case.rb +199 -109
  100. data/lib/rubygems/test_utilities.rb +25 -5
  101. data/lib/rubygems/uninstaller.rb +62 -20
  102. data/lib/rubygems/user_interaction.rb +10 -0
  103. data/lib/rubygems/validator.rb +33 -40
  104. data/lib/rubygems/version.rb +19 -8
  105. data/setup.rb +8 -1
  106. data/test/rubygems/alternate_cert.pem +9 -0
  107. data/test/rubygems/alternate_cert_32.pem +9 -0
  108. data/test/rubygems/alternate_key.pem +9 -0
  109. data/test/rubygems/bad_rake.rb +1 -0
  110. data/test/rubygems/child_cert.pem +9 -0
  111. data/test/rubygems/child_cert_32.pem +9 -0
  112. data/test/rubygems/child_key.pem +9 -0
  113. data/test/rubygems/data/null-type.gemspec.rz +0 -0
  114. data/test/rubygems/expired_cert.pem +9 -0
  115. data/test/rubygems/future_cert.pem +9 -0
  116. data/test/rubygems/future_cert_32.pem +9 -0
  117. data/test/rubygems/good_rake.rb +1 -0
  118. data/test/rubygems/grandchild_cert.pem +9 -0
  119. data/test/rubygems/grandchild_cert_32.pem +9 -0
  120. data/test/rubygems/grandchild_key.pem +9 -0
  121. data/test/rubygems/invalid_issuer_cert.pem +9 -0
  122. data/test/rubygems/invalid_issuer_cert_32.pem +9 -0
  123. data/test/rubygems/invalid_key.pem +9 -0
  124. data/test/rubygems/invalid_signer_cert.pem +9 -0
  125. data/test/rubygems/invalid_signer_cert_32.pem +9 -0
  126. data/test/rubygems/invalidchild_cert.pem +9 -0
  127. data/test/rubygems/invalidchild_cert_32.pem +9 -0
  128. data/test/rubygems/invalidchild_key.pem +9 -0
  129. data/test/rubygems/plugin/exception/rubygems_plugin.rb +1 -1
  130. data/test/rubygems/plugin/standarderror/rubygems_plugin.rb +1 -1
  131. data/test/rubygems/private_key.pem +7 -25
  132. data/test/rubygems/public_cert.pem +8 -18
  133. data/test/rubygems/public_cert_32.pem +10 -0
  134. data/test/rubygems/public_key.pem +4 -0
  135. data/test/rubygems/rubygems/commands/crash_command.rb +1 -1
  136. data/test/rubygems/test_config.rb +4 -6
  137. data/test/rubygems/test_deprecate.rb +76 -0
  138. data/test/rubygems/test_gem.rb +318 -83
  139. data/test/rubygems/test_gem_available_set.rb +106 -0
  140. data/test/rubygems/test_gem_command.rb +10 -0
  141. data/test/rubygems/test_gem_command_manager.rb +55 -9
  142. data/test/rubygems/test_gem_commands_build_command.rb +11 -19
  143. data/test/rubygems/test_gem_commands_cert_command.rb +441 -42
  144. data/test/rubygems/test_gem_commands_cleanup_command.rb +29 -1
  145. data/test/rubygems/test_gem_commands_contents_command.rb +23 -0
  146. data/test/rubygems/test_gem_commands_dependency_command.rb +5 -0
  147. data/test/rubygems/test_gem_commands_fetch_command.rb +19 -20
  148. data/test/rubygems/test_gem_commands_generate_index_command.rb +2 -83
  149. data/test/rubygems/test_gem_commands_help_command.rb +2 -1
  150. data/test/rubygems/test_gem_commands_install_command.rb +647 -48
  151. data/test/rubygems/test_gem_commands_mirror.rb +32 -0
  152. data/test/rubygems/test_gem_commands_owner_command.rb +4 -8
  153. data/test/rubygems/test_gem_commands_pristine_command.rb +99 -4
  154. data/test/rubygems/test_gem_commands_push_command.rb +62 -8
  155. data/test/rubygems/test_gem_commands_query_command.rb +51 -0
  156. data/test/rubygems/test_gem_commands_search_command.rb +25 -0
  157. data/test/rubygems/test_gem_commands_setup_command.rb +45 -0
  158. data/test/rubygems/test_gem_commands_sources_command.rb +21 -6
  159. data/test/rubygems/test_gem_commands_specification_command.rb +33 -1
  160. data/test/rubygems/test_gem_commands_uninstall_command.rb +91 -31
  161. data/test/rubygems/test_gem_commands_unpack_command.rb +3 -3
  162. data/test/rubygems/test_gem_commands_update_command.rb +56 -38
  163. data/test/rubygems/test_gem_commands_which_command.rb +4 -4
  164. data/test/rubygems/test_gem_commands_yank_command.rb +97 -0
  165. data/test/rubygems/test_gem_config_file.rb +66 -21
  166. data/test/rubygems/test_gem_dependency.rb +46 -0
  167. data/test/rubygems/test_gem_dependency_installer.rb +228 -18
  168. data/test/rubygems/test_gem_dependency_list.rb +0 -9
  169. data/test/rubygems/test_gem_dependency_resolver.rb +327 -0
  170. data/test/rubygems/test_gem_ext_configure_builder.rb +4 -4
  171. data/test/rubygems/test_gem_ext_ext_conf_builder.rb +21 -49
  172. data/test/rubygems/test_gem_ext_rake_builder.rb +13 -13
  173. data/test/rubygems/test_gem_gem_runner.rb +27 -5
  174. data/test/rubygems/test_gem_gemcutter_utilities.rb +19 -0
  175. data/test/rubygems/test_gem_indexer.rb +14 -227
  176. data/test/rubygems/test_gem_install_update_options.rb +83 -3
  177. data/test/rubygems/test_gem_installer.rb +211 -236
  178. data/test/rubygems/test_gem_local_remote_options.rb +8 -2
  179. data/test/rubygems/test_gem_name_tuple.rb +15 -0
  180. data/test/rubygems/test_gem_package.rb +547 -0
  181. data/test/rubygems/test_gem_package_old.rb +37 -0
  182. data/test/rubygems/test_gem_package_tar_reader.rb +32 -0
  183. data/test/rubygems/test_gem_package_tar_writer.rb +84 -1
  184. data/test/rubygems/test_gem_path_support.rb +4 -30
  185. data/test/rubygems/test_gem_platform.rb +3 -6
  186. data/test/rubygems/test_gem_rdoc.rb +245 -0
  187. data/test/rubygems/test_gem_remote_fetcher.rb +51 -5
  188. data/test/rubygems/test_gem_request_set.rb +70 -0
  189. data/test/rubygems/test_gem_requirement.rb +53 -24
  190. data/test/rubygems/test_gem_security.rb +189 -43
  191. data/test/rubygems/test_gem_security_policy.rb +376 -0
  192. data/test/rubygems/test_gem_security_signer.rb +184 -0
  193. data/test/rubygems/test_gem_security_trust_dir.rb +94 -0
  194. data/test/rubygems/test_gem_server.rb +31 -36
  195. data/test/rubygems/test_gem_silent_ui.rb +2 -2
  196. data/test/rubygems/test_gem_source.rb +188 -0
  197. data/test/rubygems/test_gem_source_list.rb +87 -0
  198. data/test/rubygems/test_gem_source_local.rb +83 -0
  199. data/test/rubygems/test_gem_source_specific_file.rb +33 -0
  200. data/test/rubygems/test_gem_spec_fetcher.rb +91 -255
  201. data/test/rubygems/test_gem_specification.rb +293 -39
  202. data/test/rubygems/test_gem_uninstaller.rb +136 -13
  203. data/test/rubygems/test_gem_validator.rb +14 -41
  204. data/test/rubygems/test_gem_version.rb +15 -21
  205. data/test/rubygems/test_require.rb +193 -0
  206. data/test/rubygems/wrong_key_cert.pem +9 -0
  207. data/test/rubygems/wrong_key_cert_32.pem +9 -0
  208. metadata +171 -83
  209. metadata.gz.sig +1 -0
  210. data/CVE-2013-4287.txt +0 -36
  211. data/CVE-2013-4363.txt +0 -45
  212. data/ci_build.sh +0 -27
  213. data/cruise_config.rb +0 -32
  214. data/lib/rbconfig/datadir.rb +0 -13
  215. data/lib/rubygems/builder.rb +0 -99
  216. data/lib/rubygems/custom_require.rb +0 -69
  217. data/lib/rubygems/doc_manager.rb +0 -243
  218. data/lib/rubygems/format.rb +0 -82
  219. data/lib/rubygems/gem_openssl.rb +0 -90
  220. data/lib/rubygems/gem_path_searcher.rb +0 -172
  221. data/lib/rubygems/old_format.rb +0 -153
  222. data/lib/rubygems/package/f_sync_dir.rb +0 -23
  223. data/lib/rubygems/package/tar_input.rb +0 -234
  224. data/lib/rubygems/package/tar_output.rb +0 -146
  225. data/lib/rubygems/require_paths_builder.rb +0 -18
  226. data/lib/rubygems/source_index.rb +0 -406
  227. data/lib/rubygems/ssl_certs/AddTrustExternalCARoot-2048.pem +0 -25
  228. data/lib/rubygems/ssl_certs/Class3PublicPrimaryCertificationAuthority.pem +0 -14
  229. data/lib/rubygems/ssl_certs/DigiCertHighAssuranceEVRootCA.pem +0 -23
  230. data/lib/rubygems/ssl_certs/EntrustnetSecureServerCertificationAuthority.pem +0 -28
  231. data/lib/rubygems/ssl_certs/GeoTrustGlobalCA.pem +0 -20
  232. data/test/rubygems/test_bundled_ca.rb +0 -59
  233. data/test/rubygems/test_gem_builder.rb +0 -44
  234. data/test/rubygems/test_gem_doc_manager.rb +0 -32
  235. data/test/rubygems/test_gem_ext_builder.rb +0 -58
  236. data/test/rubygems/test_gem_format.rb +0 -88
  237. data/test/rubygems/test_gem_gem_path_searcher.rb +0 -94
  238. data/test/rubygems/test_gem_package_tar_input.rb +0 -129
  239. data/test/rubygems/test_gem_package_tar_output.rb +0 -101
  240. data/test/rubygems/test_gem_source_index.rb +0 -250
  241. data/util/update_bundled_ca_certificates.rb +0 -103
@@ -1,5 +1,5 @@
1
1
  require 'rubygems/command'
2
- require 'rubygems/builder'
2
+ require 'rubygems/package'
3
3
 
4
4
  class Gem::Commands::BuildCommand < Gem::Command
5
5
 
@@ -22,11 +22,11 @@ class Gem::Commands::BuildCommand < Gem::Command
22
22
  def execute
23
23
  gemspec = get_one_gem_name
24
24
 
25
- if File.exist? gemspec
26
- spec = load_gemspec gemspec
25
+ if File.exist? gemspec then
26
+ spec = Gem::Specification.load gemspec
27
27
 
28
28
  if spec then
29
- Gem::Builder.new(spec).build options[:force]
29
+ Gem::Package.build spec, options[:force]
30
30
  else
31
31
  alert_error "Error loading gemspec. Aborting."
32
32
  terminate_interaction 1
@@ -37,23 +37,5 @@ class Gem::Commands::BuildCommand < Gem::Command
37
37
  end
38
38
  end
39
39
 
40
- def load_gemspec filename
41
- if yaml?(filename)
42
- open(filename) do |f|
43
- begin
44
- Gem::Specification.from_yaml(f)
45
- rescue Gem::EndOfYAMLException
46
- nil
47
- end
48
- end
49
- else
50
- Gem::Specification.load(filename) # can return nil
51
- end
52
- end
53
-
54
- def yaml?(filename)
55
- line = open(filename) { |f| line = f.gets }
56
- result = line =~ %r{!ruby/object:Gem::Specification}
57
- result
58
- end
59
40
  end
41
+
@@ -4,82 +4,224 @@ require 'rubygems/security'
4
4
  class Gem::Commands::CertCommand < Gem::Command
5
5
 
6
6
  def initialize
7
- super 'cert', 'Manage RubyGems certificates and signing settings'
8
-
9
- add_option('-a', '--add CERT',
10
- 'Add a trusted certificate.') do |value, options|
11
- cert = OpenSSL::X509::Certificate.new(File.read(value))
12
- Gem::Security.add_trusted_cert(cert)
13
- say "Added '#{cert.subject.to_s}'"
14
- end
15
-
16
- add_option('-l', '--list',
17
- 'List trusted certificates.') do |value, options|
18
- glob_str = File::join(Gem::Security::OPT[:trust_dir], '*.pem')
19
- Dir::glob(glob_str) do |path|
20
- begin
21
- cert = OpenSSL::X509::Certificate.new(File.read(path))
22
- # this could probably be formatted more gracefully
23
- say cert.subject.to_s
24
- rescue OpenSSL::X509::CertificateError
25
- next
26
- end
7
+ super 'cert', 'Manage RubyGems certificates and signing settings',
8
+ :add => [], :remove => [], :list => [], :build => [], :sign => []
9
+
10
+ OptionParser.accept OpenSSL::X509::Certificate do |certificate|
11
+ begin
12
+ OpenSSL::X509::Certificate.new File.read certificate
13
+ rescue Errno::ENOENT
14
+ raise OptionParser::InvalidArgument, "#{certificate}: does not exist"
15
+ rescue OpenSSL::X509::CertificateError
16
+ raise OptionParser::InvalidArgument,
17
+ "#{certificate}: invalid X509 certificate"
27
18
  end
28
19
  end
29
20
 
30
- add_option('-r', '--remove STRING',
31
- 'Remove trusted certificates containing',
32
- 'STRING.') do |value, options|
33
- trust_dir = Gem::Security::OPT[:trust_dir]
34
- glob_str = File::join(trust_dir, '*.pem')
35
-
36
- Dir::glob(glob_str) do |path|
37
- begin
38
- cert = OpenSSL::X509::Certificate.new(File.read(path))
39
- if cert.subject.to_s.downcase.index(value)
40
- say "Removed '#{cert.subject.to_s}'"
41
- File.unlink(path)
42
- end
43
- rescue OpenSSL::X509::CertificateError
44
- next
45
- end
21
+ OptionParser.accept OpenSSL::PKey::RSA do |key_file|
22
+ begin
23
+ key = OpenSSL::PKey::RSA.new File.read key_file
24
+ rescue Errno::ENOENT
25
+ raise OptionParser::InvalidArgument, "#{key_file}: does not exist"
26
+ rescue OpenSSL::PKey::RSAError
27
+ raise OptionParser::InvalidArgument, "#{key_file}: invalid RSA key"
46
28
  end
29
+
30
+ raise OptionParser::InvalidArgument,
31
+ "#{key_file}: private key not found" unless key.private?
32
+
33
+ key
34
+ end
35
+
36
+ add_option('-a', '--add CERT', OpenSSL::X509::Certificate,
37
+ 'Add a trusted certificate.') do |cert, options|
38
+ options[:add] << cert
39
+ end
40
+
41
+ add_option('-l', '--list [FILTER]',
42
+ 'List trusted certificates where the',
43
+ 'subject contains FILTER') do |filter, options|
44
+ filter ||= ''
45
+
46
+ options[:list] << filter
47
+ end
48
+
49
+ add_option('-r', '--remove FILTER',
50
+ 'Remove trusted certificates where the',
51
+ 'subject contains FILTER') do |filter, options|
52
+ options[:remove] << filter
47
53
  end
48
54
 
49
55
  add_option('-b', '--build EMAIL_ADDR',
50
56
  'Build private key and self-signed',
51
- 'certificate for EMAIL_ADDR.') do |value, options|
52
- vals = Gem::Security.build_self_signed_cert(value)
53
- FileUtils.chmod 0600, vals[:key_path]
54
- say "Public Cert: #{vals[:cert_path]}"
55
- say "Private Key: #{vals[:key_path]}"
56
- say "Don't forget to move the key file to somewhere private..."
57
+ 'certificate for EMAIL_ADDR') do |email_address, options|
58
+ options[:build] << email_address
57
59
  end
58
60
 
59
- add_option('-C', '--certificate CERT',
60
- 'Certificate for --sign command.') do |value, options|
61
- cert = OpenSSL::X509::Certificate.new(File.read(value))
61
+ add_option('-C', '--certificate CERT', OpenSSL::X509::Certificate,
62
+ 'Signing certificate for --sign') do |cert, options|
62
63
  options[:issuer_cert] = cert
63
64
  end
64
65
 
65
- add_option('-K', '--private-key KEY',
66
- 'Private key for --sign command.') do |value, options|
67
- key = OpenSSL::PKey::RSA.new(File.read(value))
68
- options[:issuer_key] = key
66
+ add_option('-K', '--private-key KEY', OpenSSL::PKey::RSA,
67
+ 'Key for --sign or --build') do |key, options|
68
+ options[:key] = key
69
69
  end
70
70
 
71
- add_option('-s', '--sign NEWCERT',
72
- 'Sign a certificate with my key and',
73
- 'certificate.') do |value, options|
74
- cert = OpenSSL::X509::Certificate.new(File.read(value))
75
- my_cert = options[:issuer_cert]
76
- my_key = options[:issuer_key]
77
- cert = Gem::Security.sign_cert(cert, my_key, my_cert)
78
- File.open(value, 'wb') { |file| file.write(cert.to_pem) }
71
+ add_option('-s', '--sign CERT',
72
+ 'Signs CERT with the key from -K',
73
+ 'and the certificate from -C') do |cert_file, options|
74
+ raise OptionParser::InvalidArgument, "#{cert_file}: does not exist" unless
75
+ File.file? cert_file
76
+
77
+ options[:sign] << cert_file
79
78
  end
80
79
  end
81
80
 
82
81
  def execute
82
+ options[:add].each do |certificate|
83
+ Gem::Security.trust_dir.trust_cert certificate
84
+
85
+ say "Added '#{certificate.subject}'"
86
+ end
87
+
88
+ options[:remove].each do |filter|
89
+ certificates_matching filter do |certificate, path|
90
+ FileUtils.rm path
91
+ say "Removed '#{certificate.subject}'"
92
+ end
93
+ end
94
+
95
+ options[:list].each do |filter|
96
+ certificates_matching filter do |certificate, _|
97
+ # this could probably be formatted more gracefully
98
+ say certificate.subject.to_s
99
+ end
100
+ end
101
+
102
+ options[:build].each do |name|
103
+ build name
104
+ end
105
+
106
+ unless options[:sign].empty? then
107
+ load_default_cert unless options[:issuer_cert]
108
+ load_default_key unless options[:key]
109
+ end
110
+
111
+ options[:sign].each do |cert_file|
112
+ sign cert_file
113
+ end
114
+ end
115
+
116
+ def build name
117
+ key = options[:key] || Gem::Security.create_key
118
+
119
+ cert = Gem::Security.create_cert_email name, key
120
+
121
+ key_path = Gem::Security.write key, "gem-private_key.pem"
122
+ cert_path = Gem::Security.write cert, "gem-public_cert.pem"
123
+
124
+ say "Certificate: #{cert_path}"
125
+ say "Private Key: #{key_path}"
126
+ say "Don't forget to move the key file to somewhere private!"
127
+ end
128
+
129
+ def certificates_matching filter
130
+ return enum_for __method__, filter unless block_given?
131
+
132
+ Gem::Security.trusted_certificates.select do |certificate, _|
133
+ subject = certificate.subject.to_s
134
+ subject.downcase.index filter
135
+ end.sort_by do |certificate, _|
136
+ certificate.subject.to_a.map { |name, data,| [name, data] }
137
+ end.each do |certificate, path|
138
+ yield certificate, path
139
+ end
140
+ end
141
+
142
+ def description # :nodoc:
143
+ <<-EOF
144
+ The cert command manages signing keys and certificates for creating signed
145
+ gems. Your signing certificate and private key are typically stored in
146
+ ~/.gem/gem-public_cert.pem and ~/.gem/gem-private_key.pem respectively.
147
+
148
+ To build a certificate for signing gems:
149
+
150
+ gem cert --build you@example
151
+
152
+ If you already have an RSA key, or are creating a new certificate for an
153
+ existing key:
154
+
155
+ gem cert --build you@example --private-key /path/to/key.pem
156
+
157
+ If you wish to trust a certificate you can add it to the trust list with:
158
+
159
+ gem cert --add /path/to/cert.pem
160
+
161
+ You can list trusted certificates with:
162
+
163
+ gem cert --list
164
+
165
+ or:
166
+
167
+ gem cert --list cert_subject_substring
168
+
169
+ If you wish to remove a previously trusted certificate:
170
+
171
+ gem cert --remove cert_subject_substring
172
+
173
+ To sign another gem author's certificate:
174
+
175
+ gem cert --sign /path/to/other_cert.pem
176
+
177
+ For further reading on signing gems see `ri Gem::Security`.
178
+ EOF
179
+ end
180
+
181
+ def load_default_cert
182
+ cert_file = File.join Gem.user_home, 'gem-public_cert.pem'
183
+ cert = File.read cert_file
184
+ options[:issuer_cert] = OpenSSL::X509::Certificate.new cert
185
+ rescue Errno::ENOENT
186
+ alert_error \
187
+ "--certificate not specified and ~/.gem/gem-public_cert.pem does not exist"
188
+
189
+ terminate_interaction 1
190
+ rescue OpenSSL::X509::CertificateError
191
+ alert_error \
192
+ "--certificate not specified and ~/.gem/gem-public_cert.pem is not valid"
193
+
194
+ terminate_interaction 1
195
+ end
196
+
197
+ def load_default_key
198
+ key_file = File.join Gem.user_home, 'gem-private_key.pem'
199
+ key = File.read key_file
200
+ options[:key] = OpenSSL::PKey::RSA.new key
201
+ rescue Errno::ENOENT
202
+ alert_error \
203
+ "--private-key not specified and ~/.gem/gem-private_key.pem does not exist"
204
+
205
+ terminate_interaction 1
206
+ rescue OpenSSL::PKey::RSAError
207
+ alert_error \
208
+ "--private-key not specified and ~/.gem/gem-private_key.pem is not valid"
209
+
210
+ terminate_interaction 1
211
+ end
212
+
213
+ def sign cert_file
214
+ cert = File.read cert_file
215
+ cert = OpenSSL::X509::Certificate.new cert
216
+
217
+ permissions = File.stat(cert_file).mode & 0777
218
+
219
+ issuer_cert = options[:issuer_cert]
220
+ issuer_key = options[:key]
221
+
222
+ cert = Gem::Security.sign cert, issuer_key, issuer_cert
223
+
224
+ Gem::Security.write cert, cert_file, permissions
83
225
  end
84
226
 
85
227
  end
@@ -8,13 +8,7 @@ class Gem::Commands::CheckCommand < Gem::Command
8
8
 
9
9
  def initialize
10
10
  super 'check', 'Check installed gems',
11
- :verify => false, :alien => false
12
-
13
- add_option( '--verify FILE',
14
- 'Verify gem file against its internal',
15
- 'checksum') do |value, options|
16
- options[:verify] = value
17
- end
11
+ :alien => true
18
12
 
19
13
  add_option('-a', '--alien', "Report 'unmanaged' or rogue files in the",
20
14
  "gem repository") do |value, options|
@@ -25,40 +19,21 @@ class Gem::Commands::CheckCommand < Gem::Command
25
19
  end
26
20
 
27
21
  def execute
28
- if options[:alien]
29
- say "Performing the 'alien' operation"
30
- say
31
- gems = get_all_gem_names rescue []
32
- Gem::Validator.new.alien(gems).sort.each do |key, val|
33
- unless val.empty? then
34
- say "#{key} has #{val.size} problems"
35
- val.each do |error_entry|
36
- say " #{error_entry.path}:"
37
- say " #{error_entry.problem}"
38
- end
39
- else
40
- say "#{key} is error-free" if Gem.configuration.verbose
22
+ say "Checking gems..."
23
+ say
24
+ gems = get_all_gem_names rescue []
25
+
26
+ Gem::Validator.new.alien(gems).sort.each do |key, val|
27
+ unless val.empty? then
28
+ say "#{key} has #{val.size} problems"
29
+ val.each do |error_entry|
30
+ say " #{error_entry.path}:"
31
+ say " #{error_entry.problem}"
41
32
  end
42
- say
43
- end
44
- end
45
-
46
- if options[:verify]
47
- gem_name = options[:verify]
48
- unless gem_name
49
- alert_error "Must specify a .gem file with --verify NAME"
50
- return
51
- end
52
- unless File.exist?(gem_name)
53
- alert_error "Unknown file: #{gem_name}."
54
- return
55
- end
56
- say "Verifying gem: '#{gem_name}'"
57
- begin
58
- Gem::Validator.new.verify_gem_file(gem_name)
59
- rescue Exception
60
- alert_error "#{gem_name} is invalid."
33
+ else
34
+ say "#{key} is error-free" if Gem.configuration.verbose
61
35
  end
36
+ say
62
37
  end
63
38
  end
64
39
 
@@ -26,6 +26,9 @@ class Gem::Commands::CleanupCommand < Gem::Command
26
26
  <<-EOF
27
27
  The cleanup command removes old gems from GEM_HOME. If an older version is
28
28
  installed elsewhere in GEM_PATH the cleanup command won't touch it.
29
+
30
+ Older gems that are required to satisify the dependencies of gems
31
+ are not removed.
29
32
  EOF
30
33
  end
31
34
 
@@ -56,14 +59,19 @@ installed elsewhere in GEM_PATH the cleanup command won't touch it.
56
59
  primary_gems[spec.name].version != spec.version
57
60
  }
58
61
 
62
+ full = Gem::DependencyList.from_specs
63
+
59
64
  deplist = Gem::DependencyList.new
60
65
  gems_to_cleanup.uniq.each do |spec| deplist.add spec end
61
66
 
62
67
  deps = deplist.strongly_connected_components.flatten.reverse
63
68
 
69
+ original_home = Gem.dir
64
70
  original_path = Gem.path
65
71
 
66
72
  deps.each do |spec|
73
+ next unless full.ok_to_remove?(spec.full_name)
74
+
67
75
  if options[:dryrun] then
68
76
  say "Dry Run Mode: Would uninstall #{spec.full_name}"
69
77
  else
@@ -90,7 +98,7 @@ installed elsewhere in GEM_PATH the cleanup command won't touch it.
90
98
  end
91
99
 
92
100
  # Restore path Gem::Uninstaller may have change
93
- Gem.use_paths(*original_path)
101
+ Gem.use_paths(original_home, *original_path)
94
102
  end
95
103
 
96
104
  say "Clean Up Complete"
@@ -1,3 +1,4 @@
1
+ require 'English'
1
2
  require 'rubygems/command'
2
3
  require 'rubygems/version_option'
3
4
 
@@ -74,25 +75,42 @@ class Gem::Commands::ContentsCommand < Gem::Command
74
75
 
75
76
  if Gem.configuration.verbose then
76
77
  say "\nDirectories searched:"
77
- spec_dirs.each { |dir| say dir }
78
+ spec_dirs.sort.each { |dir| say dir }
78
79
  end
79
80
 
80
81
  terminate_interaction 1 if gem_names.length == 1
81
82
  end
82
83
 
83
- gem_path = spec.full_gem_path
84
- extra = "/{#{spec.require_paths.join ','}}" if options[:lib_only]
85
- glob = "#{gem_path}#{extra}/**/*"
86
- files = Dir[glob]
87
-
88
- gem_path = File.join gem_path, '' # add trailing / if missing
89
-
90
- files.sort.each do |file|
91
- next if File.directory? file
84
+ if spec.default_gem?
85
+ files = spec.files.sort.map do |file|
86
+ case file
87
+ when /\A#{spec.bindir}\//
88
+ [Gem::ConfigMap[:bindir], $POSTMATCH]
89
+ when /\.so\z/
90
+ [Gem::ConfigMap[:archdir], file]
91
+ else
92
+ [Gem::ConfigMap[:rubylibdir], file]
93
+ end
94
+ end
95
+ else
96
+ gem_path = spec.full_gem_path
97
+ extra = "/{#{spec.require_paths.join ','}}" if options[:lib_only]
98
+ glob = "#{gem_path}#{extra}/**/*"
99
+ prefix_re = /#{Regexp.escape(gem_path)}\//
100
+ files = Dir[glob].map do |file|
101
+ [gem_path, file.sub(prefix_re, "")]
102
+ end
103
+ end
92
104
 
93
- file = file.sub gem_path, '' unless options[:prefix]
105
+ files.sort.each do |prefix, basename|
106
+ absolute_path = File.join(prefix, basename)
107
+ next if File.directory? absolute_path
94
108
 
95
- say file
109
+ if options[:prefix]
110
+ say absolute_path
111
+ else
112
+ say basename
113
+ end
96
114
  end
97
115
  end
98
116
  end