Ruby on Windows XP: How to change directory of SSL certificates

380 views Asked by At

I installed Ruby 2.0.0 on Windows XP, and run this script:

# testSSL.rb
require 'open-uri'
open('https://www.google.com')

I get a "certificate verify failed" error on http.rb line 921. Testing further, it seems that Ruby looks for the SSL certificates files here:

C:/Users/Justin/Projects/knap-build/var/knapsack/software/x86-windows/openssl/1.0.1l/ssl

How can I tell Ruby to look for these files where they were installed:

C:/Ruby200/lib/ruby/2.0.0/rubygems/ssl_certs.

Any help will be greatly appreciated!

1

There are 1 answers

2
peter On BEST ANSWER

Like this, but you get a warning because you overwrite a constant

OpenSSL::X509::DEFAULT_CERT_FILE = 'C:/Users/Gebruiker/cert.pem'
puts OpenSSL::X509::DEFAULT_CERT_FILE

or like this

ENV['SSL_CERT_FILE']="C:/users/username/cert.pem" #make sure a correct certificate is there

In both cases followed by

http.use_ssl = true

You can download a valid .pem file from http://curl.haxx.se/ca/cacert.pem. Save this file to with the extension .pem in the path and with the name you reference in your script.