Last active
December 19, 2015 03:19
-
-
Save docwhat/5889652 to your computer and use it in GitHub Desktop.
A simple script to troubleshoot SSL problems; notably a missing CA bundle.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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