Skip to content

Instantly share code, notes, and snippets.

@pkrnjevic
Created March 18, 2012 16:31
Show Gist options
  • Save pkrnjevic/2076910 to your computer and use it in GitHub Desktop.
Save pkrnjevic/2076910 to your computer and use it in GitHub Desktop.
One line fix for ruby 1.9.3 net/http to find ca-bundle.crt
# Turn on/off SSL.
# This flag must be set before starting session.
# If you change use_ssl value after session started,
# a Net::HTTP object raises IOError.
def use_ssl=(flag)
flag = flag ? true : false
if started? and @use_ssl != flag
raise IOError, "use_ssl value changed, but session already started"
end
self.ca_file = '/opt/local/share/curl/ca-bundle.crt' if File.exists?('/opt/local/share/curl/ca-bundle.crt') && flag
@use_ssl = flag
end
@pkrnjevic
Copy link
Author

OSX Lion is strangely setup when it comes to OpenSSL CRT files. In Linux these are usually found in /etc/ssl/certs but this isn't the case with Mac. Whenever I tried to place the CRT file in what appeared to be default folders, it wouldn't work.
But this does.
Just add this one line (self.ca_file = ...) and point it to your ca_file.
This is a really ugly hack but was necessary to fix a bunch of scripts I couldn't modify.
A far better solution is to override (monkey match) use_ssl in your app.

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