How to set ca-bundle path for OpenSSL in ruby

Coxer picture Coxer · Feb 7, 2013 · Viewed 10.2k times · Source

I am experiencing a problem in ruby, where an SSL cert could not be validated by OpenSSL. I think this is caused by the ca-bundle.pem not being known by the script. Is there a possibility to configure the path of the ca-bundle.pem manually?

Answer

Daniel Roethlisberger picture Daniel Roethlisberger · Feb 10, 2013

OpenSSL uses the SSL_CERT_FILE environment variable. You can set it in your ruby script using something like before the first require which pulls in OpenSSL:

ENV['SSL_CERT_FILE'] = '/path/to/ca-bundle.pem'

or, if you prefer, you can set the SSL_CERT_FILE environment variable in your OS environment, web server configuration etc depending on your situation.