lostisland / faraday

Simple, but flexible HTTP client library, with support for multiple backends.

Home Page:https://lostisland.github.io/faraday

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SSL Verification failed on Windows

briceo opened this issue · comments

It appears that when trying to use Faraday on Windows to communicate with a site that is SSL, a certificate verify failed error occurs:

irb(main):001:0> require 'faraday'
=> true
irb(main):002:0> Faraday.get('https://google.com')
Faraday::SSLError: SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed
        from C:/Ruby200/lib/ruby/2.0.0/net/http.rb:918:in `connect'
        from C:/Ruby200/lib/ruby/2.0.0/net/http.rb:918:in `block in connect'
        from C:/Ruby200/lib/ruby/2.0.0/timeout.rb:52:in `timeout'
        from C:/Ruby200/lib/ruby/2.0.0/net/http.rb:918:in `connect'
        from C:/Ruby200/lib/ruby/2.0.0/net/http.rb:862:in `do_start'
        from C:/Ruby200/lib/ruby/2.0.0/net/http.rb:851:in `start'
        from C:/Ruby200/lib/ruby/2.0.0/net/http.rb:1367:in `request'
        from C:/Ruby200/lib/ruby/2.0.0/net/http.rb:1126:in `get'
        from C:/Ruby200/lib/ruby/gems/2.0.0/gems/faraday-0.9.0/lib/faraday/adapter/net_http.rb:78:in `perform_request'
        from C:/Ruby200/lib/ruby/gems/2.0.0/gems/faraday-0.9.0/lib/faraday/adapter/net_http.rb:39:in `call'
        from C:/Ruby200/lib/ruby/gems/2.0.0/gems/faraday-0.9.0/lib/faraday/request/url_encoded.rb:15:in `call'
        from C:/Ruby200/lib/ruby/gems/2.0.0/gems/faraday-0.9.0/lib/faraday/rack_builder.rb:139:in `build_response'
        from C:/Ruby200/lib/ruby/gems/2.0.0/gems/faraday-0.9.0/lib/faraday/connection.rb:377:in `run_request'
        from C:/Ruby200/lib/ruby/gems/2.0.0/gems/faraday-0.9.0/lib/faraday/connection.rb:140:in `get'
        from C:/Ruby200/lib/ruby/gems/2.0.0/gems/faraday-0.9.0/lib/faraday.rb:99:in `method_missing'
        from (irb):2
        from C:/Ruby200/bin/irb:12:in `<main>'

This same example works correctly from a linux system, and retrieves the expected webpage with no errors.

I was able to work around this issue by setting the environment variable SSL_CERT_FILE to the full path of my cacert.pem file (which I obtained from here: http://curl.haxx.se/docs/caextract.html).

that is the correct solution to the problem, faraday has nothing to do with it, see oneclick/rubyinstaller#226

i have same issue with ubuntu system with facebook authentication.

@timcy I suspect your issue is unrelated.

Unless there is some proposal for a built-in workaround I think this issue should be closed. It's still present but I can confirm it has nothing to do with faraday; I'm confirming it's a windows/ruby-installer issue.

@briceo Thanks for sharing the workaround!

I'm afraid there's not much we can do from Faraday. Developers who need to connect to sites over HTTPS are responsible for ensuring that root certificates are already in place.

@briceo Hi, can you give a more specific solution to this problem? I'm on windows and also have this problem. But I already have SSL_CERT_FILE to cacert.pem full pacht (i.e., D:\RailsInstaller\cacert.pem)

The problem is SSL_CERT_FILE (or maybe it was some other environment variable) needs to be an aboslute path for some reason, and that path is hard coded into something that was generated by whoever compiled that component of the rails installer.

Grab the root certs from somewhere else, save them locally, then point to them. EG:
https://github.com/emojidex/emojidex/blob/master/lib/emojidex/service/transactor.rb#L110