Created
May 4, 2015 19:33
-
-
Save pix0r/7d3d5d10c4bd1e026a76 to your computer and use it in GitHub Desktop.
SSL issues w/ https://view-api.box.com/
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
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']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
[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]%