ruby - SYSCALL returned=5 errno=0 state=SSLv3 read server hello A with Ruby RESTful client

标签 ruby ssl openssl

我一直在为这个问题苦苦挣扎一段时间。我正在尝试使用 Rest-Client ruby​​ gem 来使用 SSL 证书访问 API 端点。我确定服务器仅响应 TLSv_1_2 和 TLSv_1_1,但我似乎无法使其正常工作。 这是代码片段:

resource = RestClient::Resource.new(
                endpoint,
                :ssl_client_cert  => OpenSSL::X509::Certificate.new(File.read(config["cert"])),
                :ssl_client_key   =>  OpenSSL::PKey::RSA.new(File.read(config["key"])),
                :ssl_version      => :TLSv1_2,
                :verify_mode      =>  OpenSSL::SSL::VERIFY_PEER
            )

response = resource.delete(:params => {:name => 'test'})

p endpoint + " | " + response.code.to_s

这就是我得到的:

/usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/net/http.rb:923:in `connect': SSL_connect SYSCALL returned=5 errno=0 state=SSLv3 read server hello A (OpenSSL::SSL::SSLError)
from /usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/net/http.rb:923:in `block in connect'
from /usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/timeout.rb:74:in `timeout'
from /usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/net/http.rb:923:in `connect'
from /usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/net/http.rb:863:in `do_start'
from /usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/net/http.rb:852:in `start'
from /usr/local/rvm/gems/ruby-2.2.1/gems/rest-client-1.8.0/lib/restclient/request.rb:413:in `transmit'
from /usr/local/rvm/gems/ruby-2.2.1/gems/rest-client-1.8.0/lib/restclient/request.rb:176:in `execute'
from /usr/local/rvm/gems/ruby-2.2.1/gems/rest-client-1.8.0/lib/restclient/request.rb:41:in `execute'
from /usr/local/rvm/gems/ruby-2.2.1/gems/rest-client-1.8.0/lib/restclient
from test.rb:47:in `<main>'

我一直在看this有一段时间了,但没什么帮助。

最佳答案

强烈建议使用顶级初始化程序:

conf/initializer/tls_settings.rb

OpenSSL::SSL::SSLContext::DEFAULT_PARAMS[:ssl_version] = 'TLSv1_2'

关于ruby - SYSCALL returned=5 errno=0 state=SSLv3 read server hello A with Ruby RESTful client,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31358003/

相关文章:

ruby - 对 Ruby 类扩展自身但在模块下有效吗?

ruby-on-rails - Rails partials 的依赖关系图

iis - 当 SSL 证书不再有效时从 https 重定向到 http

security - PEM 文件格式在哪里指定?

ruby-on-rails - 如何在 ruby​​ on rails 中按日期对二维数组(2d 数组)进行排序?

ruby-on-rails - 如何模拟 Rails::configuration

c++ - boost asio ssl async_shutdown总是以错误结束?

redirect - 如何在 Apache2 上将 IP 和域的 http 重定向到 https

ruby-on-rails - 由于缺少扩展名 : openssl, readline、zlib 编译错误,Ruby 安装中止

.net - 对于 HTTPS,Invoke-WebRequest 总是失败。根据验证程序,远程证书无效