46

(仅供参考:我正在关注来自 railscast #241 的 Twitter Omniauth。我成功使用了 Twitter,现在进入 Facebook)

使用 Omniauth 登录 Facebook 后,我立即收到此错误:

Faraday::Error::ConnectionFailed
SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed

这是什么意思?

这是我的代码

Rails.application.config.middleware.use OmniAuth::Builder do
  provider :facebook, '<key from fb>', '<another key from fb>'
end

我的代码中实际上没有什么内容,我所拥有的只是在我想使用 to_yaml 来查看 request.env 中的内容的 sessionController

class SessionsController < ApplicationController
    def create
        raise request.env["omniauth.auth"].to_yaml
    end
end

如何解决法拉第错误?

4

9 回答 9

63

我已经用这个解决方案在 Mac OS X Lion 10.7.4 上解决了这个问题:

$ rvm remove 1.9.3 (or whatever version of ruby you are using)
$ rvm pkg install openssl
$ rvm install 1.9.3 --with-openssl-dir=$rvm_path/usr

在此之后,您将需要下载丢失的 cacert.pem 文件:

$ cd $rvm_path/usr/ssl
$ sudo curl -O http://curl.haxx.se/ca/cacert.pem
$ sudo mv cacert.pem cert.pem
于 2012-06-14T20:55:30.057 回答
29

您收到此错误是因为 Ruby 找不到要信任的根证书。

修复 Windows:https ://gist.github.com/867550

修复 Apple/Linux:http ://martinottenwaelter.fr/2010/12/ruby19-and-the-ssl-error/ <--该站点现已关闭。

这是根据上述站点的 Apple/Linux 修复:

解决方案是安装包含 Firefox 使用的相同根证书的 curl-ca-bundle 端口:

sudo port install curl-ca-bundle

并告诉您的 https 对象使用它:

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

请注意,如果您希望代码在 Ubuntu 上运行,则需要设置 ca_path 属性,默认证书位置为 /etc/ssl/certs。

最后,这将适用于 Mac OS X 和 Ubuntu:

require 'net/https'
https = Net::HTTP.new('encrypted.google.com', 443)
https.use_ssl = true
https.verify_mode = OpenSSL::SSL::VERIFY_PEER
https.ca_path = '/etc/ssl/certs' if File.exists?('/etc/ssl/certs') # Ubuntu
https.ca_file = '/opt/local/share/curl/curl-ca-bundle.crt' if File.exists('/opt/local/share/curl/curl-ca-bundle.crt') # Mac OS X
https.request_get('/')
于 2012-06-03T16:45:04.203 回答
21

Andrei 的回答在 Mac OSX 10.8.3 上对我不起作用。前段时间我重新安装了openssl来安装ruby 2.0,从那以后总是出现这个错误。感谢 Andrei 的回答和Rails 项目的指示,我修复了它。

我跑了:

$ rvm -v
$ rvm get head
# Installation of latest version of rvm...
$ rvm -v
# rvm 1.19.5 (master)
$ rvm osx-ssl-certs status all
# Certificates for /usr/local/etc/openssl/cert.pem: Old.
# Certificates for /Users/mpapis/.sm/pkg/versions/openssl/0.9.8x/ssl/cert.pem: Old.
$ sudo rvm osx-ssl-certs update all
# Updating certificates...

rvm osx-ssl-certs status all然后我通过再次运行检查证书是否正确更新但/usr/local/etc/openssl/cert.pem仍未更新。我不知道这是否有必要,但我做了以下事情:

$ cd /usr/local/etc/openssl/
$ curl -O http://curl.haxx.se/ca/cacert.pem
$ mv cacert.pem cert.pem

之后问题就解决了。希望能帮助遇到同样问题的其他人。

于 2013-04-15T09:25:43.720 回答
8

这对我有用(在 Mac OS X 上):

$ brew install curl-ca-bundle
$ export SSL_CERT_FILE=/usr/local/opt/curl-ca-bundle/share/ca-bundle.crt
于 2013-07-30T10:53:58.073 回答
3

替代解决方案:

[我是手动安装 Ruby 和 Ruby on Rails 的 Win7 用户]

我有同样的问题,但无法通过这个问题给出的答案来解决。顺便说一句,最后,我通过以下网址解决了问题

ruby on rails 中的 Facebook 重定向 URL 打开 ssl 错误 https://github.com/technoweenie/faraday/wiki/Setting-up-SSL-certificates

于 2012-11-12T15:50:59.867 回答
3

RVM 网站建议运行rvm osx-ssl-certs update all

RVM 网站:如何修复操作系统中损坏的证书。

于 2013-09-10T01:44:16.220 回答
1

对于 Windows 7:Neil Hoff 的上述解决方案链接(Windows 修复:https ://gist.github.com/867550 )对我不起作用。

这是有效的:

使用 cmd.exe:

curl -o c:\cacert.pem http://curl.haxx.se/ca/cacert.pem
set SSL_CERT_FILE=c:\cacert.pem

使用 msysgit bash:

curl -o /c/cacert.pem http://curl.haxx.se/ca/cacert.pem
export SSL_CERT_FILE=/c/cacert.pem

如果您的 Windows 7 命令行上没有 curl,请在此处获取:http: //www.confusedbycode.com/curl/#downloads

原始解决方案来自这里 - 归功于: https ://github.com/chef/chef-dk/issues/106

邓恩。

于 2015-05-07T21:05:28.550 回答
0

Andrei 的回答对我有用,但是在尝试重新安装 Ruby 1.9.3 时遇到了巨大的障碍。因为自安装 1.9.3 以来我已经安装了新版本的 Xcode,所以我无法重新安装,直到我打开 Xcode 首选项并从下载选项卡安装命令行工具。

于 2012-07-09T04:55:01.427 回答
0

查看经过认证的宝石。描述:

确保 net/https 使用 OpenSSL::SSL::VERIFY_PEER 来验证 SSL 证书并提供证书包以防 OpenSSL 找不到

于 2014-01-10T10:36:23.673 回答