English 中文(简体)
OpenSSL::SSL:SSL:SSLELrror: SSLError: SSL_ connect return=1 roadno=0 state=SSLv3 读取服务器证书 B: 证书验证失败
原标题:OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed

我用RVM在Ubuntu 12.04上安装了Ruby 1.9.3

rvm pkg install openssl
rvm install 1.9.3 --with-openssl-dir=$rvm_path/usr

当我试图按照以下的路线运行时:

require  open-uri 
open( https://www.google.com/ )

我得到错误: OpenSSL::SSL:SSL:SSLELrror: SSL_ connect return=1 错误no=0 state=SSLv3 读取服务器证书 B: 证书验证失败

如何解决呢?我有很多相似的线条, 人们在OSX有这种问题, 但怎样才能在Ubuntu解决呢?

谢谢你的帮助

最佳回答

当默认 OpenSSL 目录与本地 OpenSSL 库不正确设置时,有时会出现这种情况。 Open-uri 使用 OpenSSL:::X509:::Store#set_default_paths 来告诉 OpenSSL 在 OpenSSL 目录中查看包含 OpenSSL 默认信任的可信任的根证书的文件 。

在您的情况下, 此查找失败。 您可以设置一个环境变量, 取代默认设置, 并告诉 OpenSSL 在目录中查看 :

export SSL_CERT_FILE=/etc/pki/tls/cert.pem

s 在我 Fedora 16 64 位上的根 CA捆绑的默认位置,其他受欢迎位置为 / etc/ sl/ca- bundle. crt 等。在您的情况下, RVM 使用的 OpenSSL 库位于 $rvm_ path/ usr 中, 因此您应该在那里寻找默认 root CA 文件的合适候选人。 在环境变量设置正确后, 打开- uri 的调用将会成功 。

使环境变数永久化,使用通常的方式,例如以.bashrc、/etc/profile或任何最适合你情况的方式界定出口。

问题回答

将经认证的宝石添加到你的宝石档案里

更多信息:https://rubygems.org/gems/经认证的>https://rubygems.org/gems/经认证的

从已安装的 rvm 打开器中缺少 cacert. pem 文件 。

$ cd $rvm_path/usr/ssl
$ sudo curl -O http://curl.haxx.se/ca/cacert.pem
$ sudo mv cacert.pem cert.pem

,作为回答你问题的替代答案,它应为Ubuntu和Mac OS X用户服务,不需要环境变量的变化。

上述链接的解决方案 :

# config/initializers/fix_ssl.rb
# 
# Work around errors that look like:
#
#   SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed (OpenSSL::SSL::SSLError)

require  open-uri 
require  net/https 

module Net
  class HTTP
    alias_method :original_use_ssl=, :use_ssl=

    def use_ssl=(flag)
      # Ubuntu
      if File.exists?( /etc/ssl/certs )
        self.ca_path =  /etc/ssl/certs 

      # MacPorts on OS X
      # You ll need to run: sudo port install curl-ca-bundle
      elsif File.exists?( /opt/local/share/curl/curl-ca-bundle.crt )
        self.ca_file =  /opt/local/share/curl/curl-ca-bundle.crt 
      end

      self.verify_mode = OpenSSL::SSL::VERIFY_PEER
      self.original_use_ssl = flag
    end
  end
end

现在这对我管用。事情从我做"brew医生"开始就起作用了, 这使我发现了一些线索,比如"SSL_CERT_DIR"

Check your system clock!!

在长时间(1周)不使用虚拟机器上点击错误。 更新我的系统时钟会立即解决这个问题 。

如果您重新运行 untpd ,那么 ntpdate -b -u cool.ntp.org 将为您这样做。





相关问题
rails collection_select vs. select

collection_select and select Rails helpers: Which one should I use? I can t see a difference in both ways. Both helpers take a collection and generates options tags inside a select tag. Is there a ...

SSL slowness in EC2

We ve deployed our rails app to EC2. In our setup, we have two proxies on small instances behind round-robin DNS. These run nginx load balancers for a dynamically growing and shrinking farm of web ...

Auth-code with A-Za-z0-9 to use in an URL parameter

As part of a web application I need an auth-code to pass as a URL parameter. I am currently using (in Rails) : Digest::SHA1.hexdigest((object_id + rand(255)).to_s) Which provides long strings like : ...

RubyCAS-Client question: Rails

I ve installed RubyCAS-Client version 2.1.0 as a plugin within a rails app. It s working, but I d like to remove the ?ticket= in the url. Is this possible?

activerecord has_many :through find with one sql call

I have a these 3 models: class User < ActiveRecord::Base has_many :permissions, :dependent => :destroy has_many :roles, :through => :permissions end class Permission < ActiveRecord::...

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

Text Editor for Ruby-on-Rails

guys which text editor is good for Rubyonrails? i m using Windows and i was using E-Texteditor but its not free n its expired now can anyone plese tell me any free texteditor? n which one is best an ...

How to get SQL queries for each user where env is production

I’m developing an application dedicated to generate statistical reports, I would like that user after saving their stat report they save sql queries too. To do that I wrote the following module: ...

热门标签