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

查看:98
本文介绍了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

On the working machine, it's 0.9.8k 25 Mar 2009

所以最近的一个似乎正在崩溃.

So the more recent one seems to be breaking.

此外,如果我使用其他HTTP客户端(基于libcurl的Patron),则可以使用:

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天全站免登陆