Skip to content

Instantly share code, notes, and snippets.

@thomaswitt
Created March 11, 2015 14:32
Show Gist options
  • Save thomaswitt/7b459aafd84e16c4c72b to your computer and use it in GitHub Desktop.
Save thomaswitt/7b459aafd84e16c4c72b to your computer and use it in GitHub Desktop.
test_api_ssl_endpoints.rb
#!/usr/bin/env ruby
require 'openssl'
require 'socket'
require 'uri'
CA_BUNDLE_URL='https://raw.githubusercontent.com/bagder/ca-bundle/master/ca-bundle.crt'
#CA_BUNDLE_URL='https://raw.githubusercontent.com/bagder/ca-bundle/e9175fec5d0c4d42de24ed6d84a06d504d5e5a09/ca-bundle.crt'
puts "Downloading ca-bundle.crt from github to local file"
`curl -s -O #{CA_BUNDLE_URL}`
def verify(url)
print "verifying #{url} ... "
uri = URI.parse(url)
context = OpenSSL::SSL::SSLContext.new
context.ca_file = File.expand_path('../ca-bundle.crt', __FILE__)
context.verify_mode = OpenSSL::SSL::VERIFY_PEER
tcp_socket = TCPSocket.new(uri.host, uri.port)
ssl_socket = OpenSSL::SSL::SSLSocket.new(tcp_socket, context)
begin
ssl_socket.connect # Raises an error if verification fails.
puts "ok!"
rescue => e
puts "FAILED!\n #{e}"
end
end
verify('https://google.com:443')
verify('https://api.github.com:443')
verify('https://api.honeybadger.io:443')
verify('https://api.newrelic.com:443')
verify('https://api.pingdom.com:443')
verify('https://dynamodb.eu-west-1.amazonaws.com:443')
verify('https://dynamodb.eu-central-1.amazonaws.com:443')
verify('https://elasticache.eu-west-1.amazonaws.com:443')
verify('https://ec2.eu-west-1.amazonaws.com:443')
verify('https://ec2.eu-central-1.amazonaws.com:443')
verify('https://opsworks.us-east-1.amazonaws.com:443')
verify('https://s3-eu-west-1.amazonaws.com:443')
verify('https://s3.eu-central-1.amazonaws.com:443')
verify('https://s3-eu-central-1.amazonaws.com:443')
verify('https://s3.amazonaws.com:443')
verify('https://email.eu-west-1.amazonaws.com:443')
puts "Done."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment