Skip to content

Instantly share code, notes, and snippets.

@docwhat
Last active December 19, 2015 03:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save docwhat/5889652 to your computer and use it in GitHub Desktop.
Save docwhat/5889652 to your computer and use it in GitHub Desktop.
A simple script to troubleshoot SSL problems; notably a missing CA bundle.
#!/usr/bin/env ruby
# A simple script to troubleshoot SSL problems; notably
# a missing CA bundle.
#
# Example errors that can be troubleshot:
# SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed
#
# Christian Höltje / docwhat.org
require 'net/https'
require 'uri'
url = ARGV.first || "https://google.com/"
uri = URI.parse url
https = Net::HTTP.new uri.host, uri.port
https.use_ssl = true
https.verify_mode = OpenSSL::SSL::VERIFY_PEER
begin
response = https.get(uri.request_uri)
message = "Your CA bundle is working."
rescue OpenSSL::SSL::SSLError => e
https.verify_mode = OpenSSL::SSL::VERIFY_NONE
response = https.get(uri.request_uri)
message = "Your CA bundle is missing or very out-of-date: #{e}"
end
puts "OpenSSL state: #{message}"
puts "Requested: #{uri}"
puts "Code: #{response.code}"
puts "Body length: #{response.body.length} characters"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment