Tuesday, November 15, 2011

SSL error with Ruby 1.9

For some sites, whenever you try to open/load a https url it gives a certificate verification failed error.Below is the error detail


C:/Ruby192/lib/ruby/1.9.1/net/http.rb:678:in `connect': SSL_connect returned=1 e
rrno=0 state=SSLv3 read server certificate B: certificate verify failed (OpenSSL
::SSL::SSLError)

Ruby 1.9 installation doesn’t find the certification authority certificates (CA Certs) used to verify the authenticity of secured web servers.Basically ruby can't find any root certificates to trust and hence it throws this error.



The solution is to install the certificate and tell your http object to use it in below 2 steps:

   1. sudo port install curl-ca-bundle

   2. https.ca_file = '/opt/local/share/curl/curl-ca-bundle.crt'


or add the following, just next to http.use_ssl:

http.verify_mode = OpenSSL::SSL::VERIFY_NONE