(仅供参考:我正在关注来自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中的内容。
class SessionsController < ApplicationController
def create
raise request.env["omniauth.auth"].to_yaml
end
end
如何解决法拉第误差?
我已经使用此解决方案在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
您收到此错误是因为 Ruby 找不到要信任的根证书。
修复视窗:https://gist.github.com/867550
修复Apple/Linux:http://martinottenwaelter.fr/2010/12/ruby19-and-the-ssl-error/<--此站点现已关闭。
根据上面的网站,这是Apple/Linux修复程序:
解决方案是安装 curl-ca-bundle 端口,其中包含与 Firefox 相同的根证书:
sudo port install curl-ca-bundle
并告诉您的 https 对象使用它:
https.ca_file = '/opt/local/share/curl/curl-ca-bundle.crt'
请注意,如果您希望代码在 Ubuntu 上运行,则需要使用 默认证书位置/etc/ssl/certs 设置 ca_path 属性。
最后,这就是在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('/')
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
之后问题得到解决。希望能帮助遇到相同问题的其他人。
我有用(在Mac OS X上):
$ brew install curl-ca-bundle
$ export SSL_CERT_FILE=/usr/local/opt/curl-ca-bundle/share/ca-bundle.crt
替代解决方案:
[我是Win7用户,手动安装Ruby和Ruby on Rails]
我有同样的问题,但无法通过这个问题给出的答案来解决。顺便说一句,最后,我通过以下网址解决了问题
Facebook 重定向网址在 ruby on rails 打开 ssl 错误 https://github.com/technoweenie/faraday/wiki/Setting-up-SSL-certificates
RVM网站建议运行rvm osx-ssl-certs update all
RVM 网站:如何修复操作系统中损坏的证书。
对于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
邓 恩。
Andrei 的回答对我有用,但是在尝试重新安装 Ruby 1.9.3 时遇到了巨大的障碍。 因为我在安装 1.9.3 后安装了新版本的 Xcode,所以我无法重新安装,直到我打开 Xcode 首选项并从"下载"选项卡安装命令行工具。
查看经过认证的宝石。描述:
确保 net/https 使用 OpenSSL::SSL::VERIFY_PEER 来验证 SSL 证书并提供证书捆绑包,以防 OpenSSL 无法 找一个