Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge RubyGems changes up to latest 1.8.x release

This brings in the new SSL changes and various other small fixes.
  • Loading branch information...
commit 874b0dfc0241fc7d235836c4a29539321047d0c8 1 parent afd97dd
@ferrous26 ferrous26 authored
View
2  lib/rubygems.rb
@@ -120,7 +120,7 @@ class << Gem
# -The RubyGems Team
module Gem
- VERSION = '1.8.20'
+ VERSION = '1.8.24'
##
# Raised when RubyGems is unable to load or activate a gem. Contains the
View
1  lib/rubygems/commands/fetch_command.rb
@@ -13,6 +13,7 @@ def initialize
add_bulk_threshold_option
add_proxy_option
add_source_option
+ add_clear_sources_option
add_version_option
add_platform_option
View
5 lib/rubygems/commands/setup_command.rb
@@ -165,7 +165,7 @@ def install_executables(bin_dir)
end
dest_file = File.join bin_dir, bin_file_formatted
- bin_tmp_file = File.join Dir.tmpdir, bin_file
+ bin_tmp_file = File.join Dir.tmpdir, "#{bin_file}.#{$$}"
begin
bin = File.readlines bin_file
@@ -211,6 +211,9 @@ def install_lib(lib_dir)
Dir.chdir 'lib' do
lib_files = Dir[File.join('**', '*rb')]
+ # Be sure to include our SSL ca bundles
+ lib_files += Dir[File.join('**', '*pem')]
+
lib_files.each do |lib_file|
dest_file = File.join lib_dir, lib_file
dest_dir = File.dirname dest_file
View
14 lib/rubygems/config_file.rb
@@ -25,6 +25,8 @@
# +:sources+:: Sets Gem::sources
# +:verbose+:: See #verbose
+require 'rbconfig'
+
class Gem::ConfigFile
DEFAULT_BACKTRACE = false
@@ -129,6 +131,16 @@ class Gem::ConfigFile
attr_reader :api_keys
##
+ # openssl verify mode value, used for remote https connection
+
+ attr_reader :ssl_verify_mode
+
+ ##
+ # Path name of directory or file of openssl CA certificate, used for remote https connection
+
+ attr_reader :ssl_ca_cert
+
+ ##
# Create the config file object. +args+ is the list of arguments
# from the command line.
#
@@ -190,6 +202,8 @@ def initialize(arg_list)
@path = @hash[:gempath] if @hash.key? :gempath
@update_sources = @hash[:update_sources] if @hash.key? :update_sources
@verbose = @hash[:verbose] if @hash.key? :verbose
+ @ssl_verify_mode = @hash[:ssl_verify_mode] if @hash.key? :ssl_verify_mode
+ @ssl_ca_cert = @hash[:ssl_ca_cert] if @hash.key? :ssl_ca_cert
load_api_keys
View
18 lib/rubygems/installer.rb
@@ -467,7 +467,13 @@ def process_options
def check_that_user_bin_dir_is_in_path
user_bin_dir = @bin_dir || Gem.bindir(gem_home)
user_bin_dir.gsub!(File::SEPARATOR, File::ALT_SEPARATOR) if File::ALT_SEPARATOR
- unless ENV['PATH'].split(File::PATH_SEPARATOR).include? user_bin_dir then
+ path = ENV['PATH']
+ if Gem.win_platform? then
+ path = path.downcase
+ user_bin_dir = user_bin_dir.downcase
+ end
+
+ unless path.split(File::PATH_SEPARATOR).include? user_bin_dir then
unless self.class.path_warning then
alert_warning "You don't have #{user_bin_dir} in your PATH,\n\t gem executables will not run."
self.class.path_warning = true
@@ -498,9 +504,13 @@ def app_script_text(bin_file_name)
version = "#{Gem::Requirement.default}"
-if ARGV.first =~ /^_(.*)_$/ and Gem::Version.correct? $1 then
- version = $1
- ARGV.shift
+if ARGV.first
+ str = ARGV.first
+ str = str.dup.force_encoding("BINARY") if str.respond_to? :force_encoding
+ if str =~ /\\A_(.*)_\\z/
+ version = $1
+ ARGV.shift
+ end
end
gem '#{spec.name}', version
View
4 lib/rubygems/installer_test_case.rb
@@ -118,7 +118,9 @@ def util_setup_gem(ui = @ui) # HACK fix use_ui to make this automatic
FileUtils.mkdir_p 'bin'
FileUtils.mkdir_p 'lib'
FileUtils.mkdir_p File.join('ext', 'a')
- File.open File.join('bin', 'executable'), 'w' do |f| f.puts '1' end
+ File.open File.join('bin', 'executable'), 'w' do |f|
+ f.puts "raise 'ran executable'"
+ end
File.open File.join('lib', 'code.rb'), 'w' do |f| f.puts '1' end
File.open File.join('ext', 'a', 'mkrf_conf.rb'), 'w' do |f|
f << <<-EOF
View
11 lib/rubygems/psych_tree.rb
@@ -12,5 +12,16 @@ def visit_String(str)
def register(target, obj)
end
end
+
+ # This is ported over from the yaml_tree in 1.9.3
+ def format_time time
+ if time.utc?
+ time.strftime("%Y-%m-%d %H:%M:%S.%9N Z")
+ else
+ time.strftime("%Y-%m-%d %H:%M:%S.%9N %:z")
+ end
+ end
+
+ private :format_time
end
end
View
67 lib/rubygems/remote_fetcher.rb
@@ -8,6 +8,8 @@
class Gem::RemoteFetcher
+ BuiltinSSLCerts = File.expand_path("./ssl_certs/*.pem", File.dirname(__FILE__))
+
include Gem::UserInteraction
##
@@ -174,7 +176,7 @@ def download(spec, source_uri, install_dir = Gem.dir)
begin
FileUtils.cp source_path, local_gem_path unless
- File.expand_path(source_path) == File.expand_path(local_gem_path)
+ File.identical?(source_path, local_gem_path)
rescue Errno::EACCES
local_gem_path = source_uri.to_s
end
@@ -210,6 +212,11 @@ def fetch_http uri, last_modified = nil, head = false, depth = 0
raise FetchError.new('too many redirects', uri) if depth > 10
location = URI.parse response['Location']
+
+ if https?(uri) && !https?(location)
+ raise FetchError.new("redirecting to non-https resource: #{location}", uri)
+ end
+
fetch_http(location, last_modified, head, depth + 1)
else
raise FetchError.new("bad response #{response.message} #{response.code}", uri)
@@ -312,17 +319,55 @@ def connection_for(uri)
@connections[connection_id] ||= Net::HTTP.new(*net_http_args)
connection = @connections[connection_id]
- if uri.scheme == 'https' and not connection.started? then
- require 'net/https'
- connection.use_ssl = true
- connection.verify_mode = OpenSSL::SSL::VERIFY_NONE
- end
+ if https?(uri) and !connection.started? then
+ configure_connection_for_https(connection)
- connection.start unless connection.started?
+ # Don't refactor this with the else branch. We don't want the
+ # http-only code path to not depend on anything in OpenSSL
+ #
+ begin
+ connection.start
+ rescue OpenSSL::SSL::SSLError, Errno::EHOSTDOWN => e
+ raise FetchError.new(e.message, uri)
+ end
+ else
+ begin
+ connection.start unless connection.started?
+ rescue Errno::EHOSTDOWN => e
+ raise FetchError.new(e.message, uri)
+ end
+ end
connection
- rescue Errno::EHOSTDOWN => e
- raise FetchError.new(e.message, uri)
+ end
+
+ def configure_connection_for_https(connection)
+ require 'net/https'
+
+ connection.use_ssl = true
+ connection.verify_mode =
+ Gem.configuration.ssl_verify_mode || OpenSSL::SSL::VERIFY_PEER
+
+ store = OpenSSL::X509::Store.new
+
+ if Gem.configuration.ssl_ca_cert
+ if File.directory? Gem.configuration.ssl_ca_cert
+ store.add_path Gem.configuration.ssl_ca_cert
+ else
+ store.add_file Gem.configuration.ssl_ca_cert
+ end
+ else
+ store.set_default_paths
+ add_rubygems_trusted_certs(store)
+ end
+
+ connection.cert_store = store
+ end
+
+ def add_rubygems_trusted_certs(store)
+ Dir.glob(BuiltinSSLCerts).each do |ssl_cert_file|
+ store.add_file ssl_cert_file
+ end
end
def correct_for_windows_path(path)
@@ -465,5 +510,9 @@ def user_agent
ua
end
+ def https?(uri)
+ uri.scheme.downcase == 'https'
+ end
+
end
View
9 lib/rubygems/specification.rb
@@ -1003,6 +1003,12 @@ def date= date
when String then
if /\A(\d{4})-(\d{2})-(\d{2})\Z/ =~ date then
Time.utc($1.to_i, $2.to_i, $3.to_i)
+
+ # Workaround for where the date format output from psych isn't
+ # parsed as a Time object by syck and thus comes through as a
+ # string.
+ elsif /\A(\d{4})-(\d{2})-(\d{2}) \d{2}:\d{2}:\d{2}\.\d+?Z\z/ =~ date then
+ Time.utc($1.to_i, $2.to_i, $3.to_i)
else
raise(Gem::InvalidSpecificationException,
"invalid date format in specification: #{date.inspect}")
@@ -1379,7 +1385,7 @@ def initialize_copy other_spec
val = other_spec.instance_variable_get(name)
if val then
instance_variable_set name, val.dup
- else
+ elsif Gem.configuration.really_verbose
warn "WARNING: #{full_name} has an invalid nil value for #{name}"
end
rescue TypeError
@@ -1941,6 +1947,7 @@ def to_yaml(opts = {}) # :nodoc:
ast = builder.tree
io = StringIO.new
+ io.set_encoding Encoding::UTF_8 if Object.const_defined? :Encoding
Psych::Visitors::Emitter.new(io).accept(ast)
View
3,366 lib/rubygems/ssl_certs/ca-bundle.pem
3,366 additions, 0 deletions not shown
View
8 lib/rubygems/syck_hack.rb
@@ -15,6 +15,10 @@ module YAML
# being underneith YAML. If so, reference it back under YAML as
# well.
if defined? ::Syck
+ # for tests that change YAML::ENGINE
+ # 1.8 does not support the second argument to const_defined?
+ remove_const :Syck rescue nil
+
Syck = ::Syck
# JRuby's "Syck" is called "Yecht"
@@ -35,6 +39,8 @@ class DefaultKey
# should.
module Syck
class DefaultKey
+ remove_method :to_s rescue nil
+
def to_s
'='
end
@@ -59,6 +65,8 @@ def to_s
# place to find the DefaultKey class for comparison.
module Gem
+ # for tests that change YAML::ENGINE
+ remove_const :SyckDefaultKey if const_defined? :SyckDefaultKey
SyckDefaultKey = YAML::Syck::DefaultKey
end
View
4 lib/rubygems/version.rb
@@ -218,6 +218,10 @@ def hash # :nodoc:
@hash ||= segments.hash
end
+ def init_with coder # :nodoc:
+ yaml_initialize coder.tag, coder.map
+ end
+
def inspect # :nodoc:
"#<#{self.class} #{version.inspect}>"
end
Please sign in to comment.
Something went wrong with that request. Please try again.