How to set ca-bundle path for OpenSSL in ruby

2019-04-04 11:05发布

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?

3条回答
爱情/是我丢掉的垃圾
2楼-- · 2019-04-04 11:21

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.

查看更多
别忘想泡老子
3楼-- · 2019-04-04 11:24

You can do so by the following:

SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt
查看更多
Luminary・发光体
4楼-- · 2019-04-04 11:34

It's all because SSL_CERT_FILE has a wrong value, the value it has might not exist. So, you have to set its value to your certificate file as ENV['SSL_CERT_FILE]='path/to/ca-bundle.p'. If you are using Rails, you can put it in an initializer. If you want a gem that does everything for you, use https://github.com/stevegraham/certified.

查看更多
登录 后发表回答