123456789_123456789_123456789_123456789_123456789_

Module: Bundler::CLI::Doctor::SSL::Explanation

Relationships & Source Files
Defined in: lib/bundler/cli/doctor/ssl.rb

Instance Method Summary

Instance Method Details

#explain_bundler_or_rubygems_error(error)

[ GitHub ]

  
# File 'lib/bundler/cli/doctor/ssl.rb', line 148

def explain_bundler_or_rubygems_error(error)
  case error.message
  when /certificate verify failed/
    "certificate verification"
  when /read server hello A/
    "SSL/TLS protocol version mismatch"
  when /tlsv1 alert protocol version/
    "requested TLS version is too old"
  else
    error.message
  end
end

#explain_net_http_error(error, host, tls_version)

[ GitHub ]

  
# File 'lib/bundler/cli/doctor/ssl.rb', line 161

def explain_net_http_error(error, host, tls_version)
  case error.message
  # Check for certificate errors
  when /certificate verify failed/
    <<~MSG
      #{show_ssl_certs}
      Your Ruby can't connect to #{host} because you are missing the certificate files OpenSSL needs to verify you are connecting to the genuine #{host} servers.
    MSG
  # Check for TLS version errors
  when /read server hello A/, /tlsv1 alert protocol version/
    if tls_version.to_s == "TLS1_3"
      "Your Ruby can't connect to #{host} because #{tls_version} isn't supported yet.\n"
    else
      <<~MSG
        Your Ruby can't connect to #{host} because your version of OpenSSL is too old.
        You'll need to upgrade your OpenSSL install and/or recompile Ruby to use a newer OpenSSL.
      MSG
    end
  # OpenSSL doesn't support TLS version specified by argument
  when /unknown SSL method/
    "Your Ruby can't connect because #{tls_version} isn't supported by your version of OpenSSL."
  else
    <<~MSG
      Even worse, we're not sure why.

      Here's the full error information:
      #{error.class}: #{error.message}
        #{error.backtrace.join("\n  ")}

      You might have more luck using Mislav's SSL doctor.rb script. You can get it here:
      https://github.com/mislav/ssl-tools/blob/8b3dec4/doctor.rb

      Read more about the script and how to use it in this blog post:
      https://mislav.net/2013/07/ruby-openssl/
    MSG
  end
end

#show_ssl_certs (private)

[ GitHub ]

  
# File 'lib/bundler/cli/doctor/ssl.rb', line 237

def show_ssl_certs
  ssl_cert_file = ENV["SSL_CERT_FILE"] || OpenSSL::X509::DEFAULT_CERT_FILE
  ssl_cert_dir  = ENV["SSL_CERT_DIR"]  || OpenSSL::X509::DEFAULT_CERT_DIR

  <<~MSG
    Below affect only Ruby net/http connections:
    SSL_CERT_FILE: #{File.exist?(ssl_cert_file) ? "exists     #{ssl_cert_file}" : "is missing #{ssl_cert_file}"}
    SSL_CERT_DIR:  #{Dir.exist?(ssl_cert_dir)   ? "exists     #{ssl_cert_dir}"  : "is missing #{ssl_cert_dir}"}
  MSG
end

#summarize(bundler_success, rubygems_success, host)

[ GitHub ]

  
# File 'lib/bundler/cli/doctor/ssl.rb', line 199

def summarize(bundler_success, rubygems_success, host)
  guide_url = "http://ruby.to/ssl-check-failed"

  message = if bundler_success && rubygems_success
    <<~MSG
      Hooray! This Ruby can connect to #{host}.
      You are all set to use Bundler and RubyGems.

    MSG
  elsif !bundler_success && !rubygems_success
    <<~MSG
      For some reason, your Ruby installation can connect to #{host}, but neither RubyGems nor Bundler can.
      The most likely fix is to manually upgrade RubyGems by following the instructions at #{guide_url}.
      After you've done that, run `gem install bundler` to upgrade Bundler, and then run this script again to make sure everything worked. ❣

    MSG
  elsif !bundler_success
    <<~MSG
      Although your Ruby installation and RubyGems can both connect to #{host}, Bundler is having trouble.
      The most likely way to fix this is to upgrade Bundler by running `gem install bundler`.
      Run this script again after doing that to make sure everything is all set.
      If you're still having trouble, check out the troubleshooting guide at #{guide_url}.

    MSG
  else
    <<~MSG
      It looks like Ruby and Bundler can connect to #{host}, but RubyGems itself cannot.
      You can likely solve this by manually downloading and installing a RubyGems update.
      Visit #{guide_url} for instructions on how to manually upgrade RubyGems.

    MSG
  end

  Bundler.ui.info("\n#{message}")
end