Skip to content

Instantly share code, notes, and snippets.

@pix0r
Created May 4, 2015 19:33
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 pix0r/7d3d5d10c4bd1e026a76 to your computer and use it in GitHub Desktop.
Save pix0r/7d3d5d10c4bd1e026a76 to your computer and use it in GitHub Desktop.
require "net/http"
require "uri"
require "openssl"
def test_ssl(url, pem_file=nil)
puts "Testing URL: #{url}"
uri = URI.parse(url)
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
if pem_file
pem = File.read(pem_file)
http.cert = OpenSSL::X509::Certificate.new(pem)
http.key = OpenSSL::PKey::RSA.new(pem)
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
end
request = Net::HTTP::Get.new(uri.request_uri)
begin
response = http.request(request)
puts "Received #{response.body.length} bytes from #{url}"
rescue
puts $!, $@
end
puts
end
test_ssl("https://github.com/", ENV['PEM_FILE'])
test_ssl("https://www.box.com/", ENV['PEM_FILE'])
test_ssl("https://view-api.box.com/1/documents", ENV['PEM_FILE'])
@atmosx
Copy link

atmosx commented May 4, 2015

[hilbert:]
[atma]% vim test.rb
[hilbert:
]
[atma]% ruby test.rb
Testing URL: https://github.com/
Received 17219 bytes from https://github.com/

Testing URL: https://www.box.com/
Received 98957 bytes from https://www.box.com/

Testing URL: https://view-api.box.com/1/documents
Received 77 bytes from https://view-api.box.com/1/documents

[hilbert:~]
[atma]%

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