2012-07-04 47 views
10

在Ubuntu 12.04上,我遇到了OpenSSL 1.0.1 + Ruby 1.9.3的嚴重問題。Ruby 1.9.3的OpenSSL問題

所有紅寶石都安裝了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 +紅寶石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拱相同的問題。

如果我將12.04系統上安裝從precise中1.0.0e它也工作正常使用Ruby 1.9.3

我想這可能與Ubuntu的錯誤在這裏:https://bugs.launchpad.net/ubuntu/+source/openssl/+bug/965371

雖然我下載的軟件包來自Debian,他們說這是固定的,沒有運氣。

有沒有其他人遇到過類似的問題?

+0

我沒有修復,只有一些數據點連接:我的機器上的問題再現(Debian的測試,紅寶石1.8.7或1.9.3,OpenSSL的1.0.1B -1)。如果我嘗試連接到不同的https主機,則問題不會再現。哦,我不確定那個錯誤報告中的症狀是否與你的症狀非常吻合。 –

回答

15

我必須連接到網關授權同樣的問題。最後,我能夠通過強制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 
+0

已經有段時間了,因爲我有檢查這個職位,但。是!這對我有用。似乎它應該能夠自行協商,但這會解決我的問題。 –

+0

這是一個解決此問題而不禁用證書驗證的解決方案 –

-1

我有同樣的問題... here是信息,即rvm pkg install opensslrvm reinstall 1.9.3-p194 --with-openssl-dir=~/.rvm/usr解決問題,但它並不能幫助我

+0

是的,這隻適用於主版本的OSX升級後,以及與brew/macports /的連接問題......在這種情況下,它可能有助於重新安裝紅寶石。也許他編譯紅寶石後更新了openssl 1.9 –

+0

仍然不適合我。我有最新的基於Linux系統1.0.1,也rvm openssl是完全一樣的,我試過所有可能的解決方案,沒有解決我......任何想法? – CLod

+0

'--with-openssl-dir = ...'不是1.9.3的有效配置選項:'configure:警告:無法識別的選項:--with-openssl-dir' – Barry