Skip to content

Instantly share code, notes, and snippets.

@luislavena
Last active August 29, 2015 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luislavena/96b7d47bfb6803a9b881 to your computer and use it in GitHub Desktop.
Save luislavena/96b7d47bfb6803a9b881 to your computer and use it in GitHub Desktop.
require "net/https"
require "openssl"
store = OpenSSL::X509::Store.new
ssl_cert_glob =
File.expand_path "../lib/rubygems/ssl_certs/*.pem", __FILE__
Dir.glob(ssl_cert_glob).each do |ssl_cert|
store.add_file ssl_cert
end
hosts = %w(
d2chzxaqi4y7f8.cloudfront.net
rubygems.org
s3.amazonaws.com
staging.rubygems.org
)
hosts.each do |host|
puts "Testing #{host}..."
begin
http = Net::HTTP.new(host, 443)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
http.cert_store = store
http.head('/')
rescue Errno::ENOENT
warn "#{host} seems offline, I can't tell whether ssl would work."
rescue OpenSSL::SSL::SSLError => e
# Only fail for certificate verification errors
if e.message =~ /certificate verify failed/
warn "#{host} is not verifiable using the included certificates. Error was: #{e.message}"
end
end
end
@luislavena
Copy link
Author

Error:

C:\Users\Luis\Code\rubygems\rubygems>ruby checkcerts.rb
Testing d2chzxaqi4y7f8.cloudfront.net...
Testing rubygems.org...
Testing s3.amazonaws.com...
Testing staging.rubygems.org...
checkcerts.rb:34: staging.rubygems.org is not verifiable using the included certificates. Error was: SSL_connect returne
d=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed (RuntimeError)
        from checkcerts.rb:20:in `each'
        from checkcerts.rb:20

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment