Ruby SSL 错误 - sslv3 警报意外消息 [英] Ruby SSL error - sslv3 alert unexpected message

查看:30
本文介绍了Ruby SSL 错误 - sslv3 警报意外消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 ruby​​ 脚本连接到服务器 https://www.xpiron.com/schedule.但是,当我尝试连接时:

I'm trying to connect to the server https://www.xpiron.com/schedule in a ruby script. However, when I try connecting:

require 'open-uri'
doc = open('https://www.xpiron.com/schedule')

我收到以下错误消息:

OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv2/v3 read server hello A:  sslv3 alert unexpected message         
    from /usr/local/lib/ruby/1.9.1/net/http.rb:678:in `connect'
    from /usr/local/lib/ruby/1.9.1/net/http.rb:678:in `block in connect'
    from /usr/local/lib/ruby/1.9.1/timeout.rb:44:in `timeout'
    from /usr/local/lib/ruby/1.9.1/timeout.rb:87:in `timeout'
    from /usr/local/lib/ruby/1.9.1/net/http.rb:678:in `connect'
    from /usr/local/lib/ruby/1.9.1/net/http.rb:637:in `do_start'
    from /usr/local/lib/ruby/1.9.1/net/http.rb:626:in `start'
    from /usr/local/lib/ruby/1.9.1/net/http.rb:1168:in `request'
    from /usr/local/lib/ruby/1.9.1/net/http.rb:888:in `get'
    from (irb):32
    from /usr/local/bin/irb:12:in `<main>'

我正在运行 Ruby 1.9.2p180.它似乎在其他一些机器上工作,所以它可能是 OpenSSL 或 Ruby 的配置问题.我尝试重新安装所有 SSL 库,并从头开始重建 Ruby,但似乎没有任何效果.有没有人遇到过这个问题?

I'm running Ruby 1.9.2p180. It seems to work on some other machines, so it could be a configuration problem with OpenSSL or Ruby. I tried reinstalling all the SSL libraries, and rebuilding Ruby from scratch, but nothing seems to work. Has anyone encountered this problem?

更新

在非工作机器上,openssl 版本为 0.9.8o 01 Jun 2010

On the non-working machine, the openssl version is 0.9.8o 01 Jun 2010

在工作机器上,它是 0.9.8k 25 Mar 2009

所以最近的那个好像坏了.

So the more recent one seems to be breaking.

此外,如果我使用不同的 HTTP 客户端(Patron,基于 libcurl),它可以工作:

Furthermore, if I use a different HTTP client (Patron, based on libcurl), it works:

require 'patron'

sess = Patron::Session.new
sess.timeout = 5
url = 'https://www.xpiron.com/schedule'
resp = sess.get(url)
puts "#{resp.body}"

所以这似乎是 Ruby 的 OpenSSL 绑定的问题.

So this appears to be an issue with Ruby's OpenSSL bindings.

推荐答案

只是为了回答我自己的问题.

Just to answer my own question.

问题似乎在于 Ruby 如何协商 SSL 连接.Xpiron 的 TLS 机制存在错误,它会抛出错误而不是重试其他 SSL 版本.

The problem seems to be with how Ruby negotiates SSL connections. There's an error in Xpiron's TLS mechanism, and it throws an error instead of retrying to other SSL versions.

如果您将 SSL 版本强制为 3.0,则它有效:

If you force the SSL version to 3.0, it works:

require 'net/http'
url = URI.parse('https://www.xpiron.com/schedule')
req = Net::HTTP::Get.new(url.path)
sock = Net::HTTP.new(url.host, 443)
sock.use_ssl = true
sock.ssl_version="SSLv3"
sock.start do |http|
    response = http.request(req)
end

我还在 Ruby 的错误跟踪器上创建了一个问题.

I also created an issue on Ruby's bug tracker.

这篇关于Ruby SSL 错误 - sslv3 警报意外消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆