3

I get the following error:

C:\Users\user\Desktop\folder>ruby exchange_rate.rb
C:/Ruby23-x64/lib/ruby/2.3.0/net/http.rb:933:in `connect_nonblock': SSL_connect
returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify fai
led (OpenSSL::SSL::SSLError)
        from C:/Ruby23-x64/lib/ruby/2.3.0/net/http.rb:933:in `connect'
        from C:/Ruby23-x64/lib/ruby/2.3.0/net/http.rb:863:in `do_start'
        from C:/Ruby23-x64/lib/ruby/2.3.0/net/http.rb:852:in `start'
        from exchange_rate.rb:55:in `<main>'

According to

https://gist.github.com/luislavena/f064211759ee0f806c88

and other places with the exact same info this affects only rubygems versions up to 2.2.x

However my installation is: ruby 2.3.0p0 (2015-12-25 revision 53290) [x64-mingw32] with rubygems 2.5.1 and I still get it

I tried the manual solution there, after looking for the .pem file somewhere else https://github.com/rubygems/rubygems/blob/master/lib/rubygems/ssl_certs/rubygems.org/AddTrustExternalCARoot.pem

since the link doesn't work anymore, this is the content of that

-----BEGIN CERTIFICATE-----
MIIENjCCAx6gAwIBAgIBATANBgkqhkiG9w0BAQUFADBvMQswCQYDVQQGEwJTRTEU
MBIGA1UEChMLQWRkVHJ1c3QgQUIxJjAkBgNVBAsTHUFkZFRydXN0IEV4dGVybmFs
IFRUUCBOZXR3b3JrMSIwIAYDVQQDExlBZGRUcnVzdCBFeHRlcm5hbCBDQSBSb290
MB4XDTAwMDUzMDEwNDgzOFoXDTIwMDUzMDEwNDgzOFowbzELMAkGA1UEBhMCU0Ux
FDASBgNVBAoTC0FkZFRydXN0IEFCMSYwJAYDVQQLEx1BZGRUcnVzdCBFeHRlcm5h
bCBUVFAgTmV0d29yazEiMCAGA1UEAxMZQWRkVHJ1c3QgRXh0ZXJuYWwgQ0EgUm9v
dDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALf3GjPm8gAELTngTlvt
H7xsD821+iO2zt6bETOXpClMfZOfvUq8k+0DGuOPz+VtUFrWlymUWoCwSXrbLpX9
uMq/NzgtHj6RQa1wVsfwTz/oMp50ysiQVOnGXw94nZpAPA6sYapeFI+eh6FqUNzX
mk6vBbOmcZSccbNQYArHE504B4YCqOmoaSYYkKtMsE8jqzpPhNjfzp/haW+710LX
a0Tkx63ubUFfclpxCDezeWWkWaCUN/cALw3CknLa0Dhy2xSoRcRdKn23tNbE7qzN
E0S3ySvdQwAl+mG5aWpYIxG3pzOPVnVZ9c0p10a3CitlttNCbxWyuHv77+ldU9U0
WicCAwEAAaOB3DCB2TAdBgNVHQ4EFgQUrb2YejS0Jvf6xCZU7wO94CTLVBowCwYD
VR0PBAQDAgEGMA8GA1UdEwEB/wQFMAMBAf8wgZkGA1UdIwSBkTCBjoAUrb2YejS0
Jvf6xCZU7wO94CTLVBqhc6RxMG8xCzAJBgNVBAYTAlNFMRQwEgYDVQQKEwtBZGRU
cnVzdCBBQjEmMCQGA1UECxMdQWRkVHJ1c3QgRXh0ZXJuYWwgVFRQIE5ldHdvcmsx
IjAgBgNVBAMTGUFkZFRydXN0IEV4dGVybmFsIENBIFJvb3SCAQEwDQYJKoZIhvcN
AQEFBQADggEBALCb4IUlwtYj4g+WBpKdQZic2YR5gdkeWxQHIzZlj7DYd7usQWxH
YINRsPkyPef89iYTx4AWpb9a/IfPeHmJIZriTAcKhjW88t5RxNKWt9x+Tu5w/Rw5
6wwCURQtjr0W4MHfRnXnJK3s9EK0hZNwEGe6nQY1ShjTK3rMUUKhemPR5ruhxSvC
Nr4TDea9Y355e6cJDUCrat2PisP29owaQgVR1EX1n6diIWgVIEM8med8vSTYqZEX
c4g/VhsxOBi0cQ+azcgOno4uG+GMmIPLHzHxREzGBHNJdmAPx/i9F4BrLunMTA5a
mnkPIAou1Z5jJh5VkpTYghdae9C8x49OhgQ=
-----END CERTIFICATE-----

which is exactly the same thing I have

I upgraded rubygems to 2.6.4 still getting the same problem

Can anyone can help me get this working?

Gus
  • 573
  • 1
  • 5
  • 18
  • I can't think of a solution but wanted to point out something. The link talks about issues connecting to the Rubygems server by the `gem` utility. Since your use case is to make a new HTTP connection to an arbitrary server, those instructions might not be accurate. – Kashyap May 20 '16 at 07:00

4 Answers4

3

What worked for me is downloading a certificate file and pointing the SSL_CERT_FILE environment variable to it. My source is this gist by fnichol. (I was following the "The Manual Way (Boring)" instructions.)

  1. Download http://curl.haxx.se/ca/cacert.pem to some permanent location.
  2. Set environment variable SSL_CERT_FILE to the path of the downloaded file.

Now suddenly HTTPS requests (not related to gem installation) would work for me on Windows 10 using Ruby 2.2.x (x64).

Henrik Heimbuerger
  • 9,924
  • 6
  • 56
  • 69
  • ie `set SSL_CERT_FILE=C:\pathto\cacert.pem` before running the ruby script throwing the error – reuns Sep 04 '21 at 15:11
2

Solved my problem by installing this gem

net_http_ssl_fix

Documentation here:

http://blog.liveeditorcms.com/net-http-ssl-fix-gem/

I don't know why it fixes, why the need of another gem on top of the regular one, but, what the hell, it works!

Gus
  • 573
  • 1
  • 5
  • 18
  • The net_http_ssl_fix gem attempts to force an up-to-date `cacert.pem` into your runtime (as long as you keep the gem updated). The last I checked, the references to the certificate was completely incorrect in Ruby for Windows. (Maybe they've since fixed it; not sure.) – Chris Peters Dec 05 '16 at 21:33
2

Any one that has installed 2.3.1 this link solved my SSL problems with installing gems in windows.

https://superdevresources.com/ssl-error-ruby-gems-windows/

Summary:

  1. Download .pem file from here http://curl.haxx.se/ca/cacert.pem and save to C:\Rails\Installer\cacert.pem.

  2. Right click computer and select properties.

  3. Then click Advanced system settings and then Environment Variables.

  4. Create a new system variable with SSL_CERT_FILE as name and C:\Rails\Installer\cacert.pem as path.

  5. Open a command prompt and verify that you can install a gem.

I.E - gem install watir

  • Whilst links to resources are quite valuable, they can break over time. Consider putting a summary of the linked information that will help others searching for a solution in the future. – David Nov 01 '16 at 11:05
0

For me, upgrading to ruby v2.4.3 via the RubyInstaller-2.4.3-1 (for windows) helped. The installer can be downloaded from https://rubyinstaller.org.

jechterhoff
  • 175
  • 2
  • 9