我的 rails 应用程序通过 Net::HTTP 向另一台服务器发出请求,但是我收到错误消息:
OpenSSL::SSL::SSLError (SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed):
我环顾四周并尝试添加http.ca_path
,http.ca_file
如下所示:
uri = URI.parse("https://#{host}/#{path}")
args = {:encrypted_credit_card_number => order.billing_info.card_number,
:expiration_date => order.billing_info.authorize_expiration_date.to_s,
:cvv => order.billing_info.cvv.to_s,
}
http = Net::HTTP.new(uri.host, uri.port)
http.ca_path = '/etc/ssl/certs'
http.ca_file = "/etc/ssl/certs/ca-certificates.crt"
http.use_ssl = true #Enabling SSL
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
http.verify_mode = OpenSSL::SSL::VERIFY_NONE if Rails.env.development? || Rails.env.test? || Rails.env.cucumber?
request = Net::HTTP::Post.new(uri.request_uri)
request.set_form_data(args)
response = http.request(request)
final_response = eval(response.body)
然而,错误仍然发生在这一行response = http.request(request)
。有人知道ubuntu上的解决方案吗?我没有在这台服务器上使用 RVM,所以我需要一个不使用 RVM 的解决方案。
======
我想我可能已经找到了解决方案,但我不知道如何实现它。所以在这个网站上:http ://railsapps.github.io/openssl-certificate-verify-failed.html有一个“Ubuntu 解决方案”部分。并且有一个下载链接:https ://launchpad.net/ubuntu/+source/openssl/1.0.1-4ubuntu5 。但是当我只能通过终端访问服务器时,如何下载打开执行文件?
尝试安装 openssl(看起来已经存在?):
emai@web1:~$ sudo apt-get install openssl ca-certificates
[sudo] password for emai:
Reading package lists... Done
Building dependency tree
Reading state information... Done
ca-certificates is already the newest version.
openssl is already the newest version.
The following packages were automatically installed and are no longer required:
libxxf86dga1 x11-utils libxxf86vm1 xterm libgl1-mesa-dri libxcb-glx0 libgl1-mesa-glx libx11-xcb1 libglapi-mesa xbitmaps libxaw7 libxmu6 libxpm4 libfontenc1 libxtst6 libutempter0 tk8.5
libxcb-shape0 libxv1 libllvm3.0
Use 'apt-get autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 24 not upgraded.