【问题标题】:OpenSSL trouble with Ruby 1.9.3Ruby 1.9.3 的 OpenSSL 问题
【发布时间】:2012-07-04 12:06:03
【问题描述】:

我在 Ubuntu 12.04 上使用 OpenSSL 1.0.1 + Ruby 1.9.3 时遇到了一个半严重的问题。

所有 rubies 都使用 rvm 安装

require 'uri'
require 'net/http'
require 'net/https'

endpoint = "https://secure.mmoagateway.com/api/transact.php"
RUBY_184_POST_HEADERS = { "Content-Type" => "application/x-www-form-urlencoded" }
body = "orderid=ae5dd847d9f31209cbffeeea076ed966&orderdescription=Active+Merchant+Remote+Test+Purchase&ccnumber=4111111111111111&ccexp=0913&cvv=123&company=Widgets+Inc&address1=1234+My+Street&address2=Apt+1&city=Ottawa&state=ON&zip=K1C2N6&country=CA&phone=%28555%29555-5555&firstname=&lastname=&email=&amount=1.00&type=auth&username=demo&password=password"
headers = {}

endpoint     = endpoint.is_a?(URI) ? endpoint : URI.parse(endpoint)

http = Net::HTTP.new(endpoint.host, endpoint.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
http.set_debug_output(STDOUT)

result = http.post(endpoint.request_uri, body, RUBY_184_POST_HEADERS.merge(headers))
puts(result)

在 Ubuntu 12.04 + Ruby 1.9.3 + Openss 1.0.1 上,我得到以下输出:

% ruby test.rb 
opening connection to secure.mmoagateway.com...
opened
Conn close because of connect error Connection reset by peer - SSL_connect
/usr/lib/ruby/1.9.1/net/http.rb:799:in `connect': Connection reset by peer - SSL_connect (Errno::ECONNRESET)
        from /usr/lib/ruby/1.9.1/net/http.rb:799:in `block in connect'
        from /usr/lib/ruby/1.9.1/timeout.rb:54:in `timeout'
        from /usr/lib/ruby/1.9.1/timeout.rb:99:in `timeout'
        from /usr/lib/ruby/1.9.1/net/http.rb:799:in `connect'
        from /usr/lib/ruby/1.9.1/net/http.rb:755:in `do_start'
        from /usr/lib/ruby/1.9.1/net/http.rb:744:in `start'
        from /usr/lib/ruby/1.9.1/net/http.rb:1284:in `request'
        from /usr/lib/ruby/1.9.1/net/http.rb:1307:in `send_entity'
        from /usr/lib/ruby/1.9.1/net/http.rb:1096:in `post'
        from test.rb:17:in `<main>'

使用 Ruby 1.8.7 我得到正确的输出:

$ ruby test.rb
opening connection to secure.mmoagateway.com...
opened
<- "POST /api/transact.php HTTP/1.1\r\nAccept: */*\r\nContent-Type: application/x-www-form-urlencoded\r\nConnection: close\r\nContent-Length: 347\r\nHost: secure.mmoagateway.com\r\n\r\n"
<- "orderid=ae5dd847d9f31209cbffeeea076ed966&orderdescription=Active+Merchant+Remote+Test+Purchase&ccnumber=4111111111111111&ccexp=0913&cvv=123&company=Widgets+Inc&address1=1234+My+Street&address2=Apt+1&city=Ottawa&state=ON&zip=K1C2N6&country=CA&phone=%28555%29555-5555&firstname=&lastname=&email=&amount=1.00&type=auth&username=demo&password=password"
-> "HTTP/1.1 200 OK\r\n"
-> "Date: Wed, 04 Jul 2012 01:26:35 GMT\r\n"
-> "Server: Apache\r\n"
-> "Content-Length: 240\r\n"
-> "Connection: close\r\n"
-> "Content-Type: text/html\r\n"
-> "\r\n"
reading 240 bytes...
-> "response=1&responsetext=SUCCESS&authcode=123456&transactionid=1648894346&avsresponse=N&cvvresponse=N&orderid=ae5dd847d9f31209cbffeeea076ed966&type=auth&response_code=100&merchant_defined_field_6=&merchant_defined_field_7=&customer_vault_id="
read 240 bytes
Conn close
#<Net::HTTPOK:0xb74175c8>
response=1&responsetext=SUCCESS&authcode=123456&transactionid=1648894346&avsresponse=N&cvvresponse=N&orderid=ae5dd847d9f31209cbffeeea076ed966&type=auth&response_code=100&merchant_defined_field_6=&merchant_defined_field_7=&customer_vault_id=

我在 1.9.3 和 1.0.1 的 arch 中遇到了同样的问题。

如果我在我的 12.04 系统上从 oneiric 安装 1.0.0e,它也适用于 ruby​​ 1.9.3

我认为这可能与此处的 ubuntu 错误有关:https://bugs.launchpad.net/ubuntu/+source/openssl/+bug/965371

虽然我从 Debian 下载了软件包,他们说它已修复并且没有运气。

有没有其他人遇到过类似的问题?

【问题讨论】:

  • 我没有修复,只有一些数据点:问题在我的机器上重现(Debian 测试,Ruby 1.8.7 或 1.9.3,openssl 1.0.1b-1)。如果我尝试连接到不同的 https 主机,问题不会重现。哦,我不确定该错误报告中的症状是否与您的症状非常匹配。

标签: ruby openssl ruby-1.9.3 ubuntu-12.04


【解决方案1】:

我也有同样的问题...here 是信息,rvm pkg install opensslrvm reinstall 1.9.3-p194 --with-openssl-dir=~/.rvm/usr 解决了问题,但对我没有帮助

【讨论】:

  • 是的,这仅在主要版本 OSX 升级和 brew/macports/...也许他在编译 ruby​​ 1.9 后更新了 openssl
  • 仍然对我不起作用。我在基本 linux 系统上有最新的 1.0.1,rvm openssl 也完全一样,我尝试了所有可能的解决方案,没有为我解决......有什么想法吗?
  • --with-openssl-dir=... 不是 1.9.3 的有效配置选项:configure: WARNING: unrecognized options: --with-openssl-dir
【解决方案2】:

我在连接到授权网关时遇到了同样的问题。最后我能够通过强制 sslv3 进行连接

http = Net::HTTP.new(uri.host, uri.port)

http.use_ssl = true if @is_https
http.verify_mode = OpenSSL::SSL::VERIFY_NONE if @is_https
http.ssl_version = :SSLv3

【讨论】:

  • 我已经有一段时间没有查看这篇文章了,但是。是的!这对我有用。似乎它应该能够自行协商,但这将解决我的问题。
  • 这里有一个解决方案,可以在不禁用证书验证的情况下解决此问题
猜你喜欢
  • 2012-08-14
  • 2012-04-13
  • 1970-01-01
  • 1970-01-01
  • 2012-06-29
  • 1970-01-01
  • 1970-01-01
  • 2015-03-13
相关资源
最近更新 更多