Created
May 11, 2012 13:29
-
-
Save plexus/2659619 to your computer and use it in GitHub Desktop.
Monkey patch Ruby 1.9 net/http to read system's root certificates
This file contains hidden or 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
# Please fork if you can improve this. (e.g. Windows support) | |
# | |
# Ruby 1.9 doesn't contain any SSL root certificates, neither does it read the ones | |
# installed with your operating system. This results in an error like | |
# | |
# SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed | |
# | |
# This solution is based on http://martinottenwaelter.fr/2010/12/ruby19-and-the-ssl-error/ | |
# but can be used to monkey patch 3rd party tools, e.g. Github's 'gist' command. | |
# | |
# It should work on Debian/Ubuntu Linux and Mac OS X. | |
require 'net/https' | |
class Net::HTTP | |
alias orig_initialize initialize | |
def initialize(*args,&blk) | |
orig_initialize(*args,&blk) | |
self.ca_path = '/etc/ssl/certs' if File.exists?('/etc/ssl/certs') # Ubuntu | |
self.ca_file = '/opt/local/share/curl/curl-ca-bundle.crt' if File.exists?('/opt/local/share/curl/curl-ca-bundle.crt') # Mac OS X | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for this solution. This is the closest to what we needed amongst all the monkeypatch-nethttp solutions.