请考虑以下代码:
require 'net/https'
uri = URI.parse("https://host/index.html")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
request = Net::HTTP::Get.new(uri.path)
response = http.request(request)
Run Code Online (Sandbox Code Playgroud)
其中https://host/index.html是服务器上的证书无效的有效地址.
在旧版本的ruby(特别是1.8.7-p334和1.9.2-p180)上,这段代码运行正常.在所有最新版本(1.8.7-p352,1.9.2-p290和1.9.3-p0)中,它抛出以下异常:
OpenSSL::SSL::SSLError: SSL_connect SYSCALL returned=5 errno=0 state=unknown state
Run Code Online (Sandbox Code Playgroud)
在最后一行.
更改verify_mode以OpenSSL::SSL::VERIFY_PEER准确提供错误,表明它正在尝试验证证书,尽管设置.
我如何说服ruby忽略无效证书并连接?
我在这里看到了许多答案,但没有一个有效.
我正在使用omniauth-oauth2 gem与第三方客户集成.
Authentication failure! failed_to_connect: Faraday::Error::ConnectionFailed, SSL_connect SYSCALL returned=5 errno=0 state=SSLv2/v3 read server hello A
Faraday::Error::ConnectionFailed (SSL_connect SYSCALL returned=5 errno=0 state=SSLv2/v3 read server hello A):
.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/net/http.rb:918:in `connect'
.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/net/http.rb:918:in `block in connect'
Run Code Online (Sandbox Code Playgroud)
我的初始化程序config/initializers是:
Rails.application.config.middleware.use OmniAuth::Builder do
client_id = 'my_client_id'
client_secret = 'secret'
ca_file = Rails.root.join('config', 'cacert.pem').to_s
ssl_options = {}
ssl_options[:ca_path] = '/usr/local/etc/openssl'
ssl_options[:ca_file] = ca_file
provider :my_partner_provider, client_id, client_secret, :client_options => {:ssl => ssl_options},
setup: ->(env){
req = Rack::Request.new(env)
site = …Run Code Online (Sandbox Code Playgroud)