Skip to content

Instantly share code, notes, and snippets.

@floehopper
Created November 24, 2010 22:35
Show Gist options
  • Save floehopper/714559 to your computer and use it in GitHub Desktop.
Save floehopper/714559 to your computer and use it in GitHub Desktop.
SSL Mutual Authentication using Ruby Net::HTTP
require 'net/https'
url = ARGV[0] || 'www.random.org'
https = Net::HTTP.new(url, Net::HTTP.https_default_port)
https.use_ssl = true
https.ssl_timeout = 2
https.verify_mode = OpenSSL::SSL::VERIFY_PEER
https.ca_file = '/usr/share/curl/curl-ca-bundle.crt'
https.verify_depth = 2
https.enable_post_connection_check = true
https.start do |http|
request = Net::HTTP::Get.new('/')
response = https.request(request)
end
# ca_file has to point to a file containing certificates from certificate authorities. Usually, you can find such a file on nearly every system, because it comes with web browsers, curl, and so on.
# Then, you have to set enable_post_connection_check to true! Otherwise, a message gets logged to the console, but no exception is raised.
@floehopper
Copy link
Author

I copied this from a comment on this page. I haven't tried it, but it looks plausible.

@anewusername1
Copy link

I get this:
```undefined method`enable_post_connection_check=' for #<Net::HTTP https://www.chase.com:443 open=false>

using ruby 1.9.2-p0. They must've changed something there..

@floehopper
Copy link
Author

I'm sure the above was using Ruby 1.8, so I'm not surprised you had a problem using it with Ruby 1.9.

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