尝试通过https发布请求时获取OpenSSL :: SSL :: SSLError:SSL_set_tlsext_host_name

时间:2015-07-22 21:37:50

标签: ruby rest ssl openssl net-http

我正在尝试使用ruby中的net / http类通过https发送帖子请求,我收到此错误:

 OpenSSL::SSL::SSLError: SSL_set_tlsext_host_name
        from C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/net/http.rb:920:in `connect'
        from C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/net/http.rb:920:in `block in connect'
        from C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/timeout.rb:76:in `timeout'
        from C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/net/http.rb:920:in `connect'
        from C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/net/http.rb:863:in `do_start'
        from C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/net/http.rb:852:in `start'
        from C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/net/http.rb:1369:in `request'

以下是我正在使用的代码示例:

uri = URI.parse('https://somehost/1')
proxy = "proxy-chain.domain.com"
port = 911
http = Net::HTTP.new(uri.host, uri.port, proxy, port)
http.use_ssl = true
http.ssl_version = 'SSLv2'
http.ciphers = OpenSSL::Cipher.ciphers      
req = Net::HTTP::Post.new(uri.request_uri)
req.set_form_data(JSON.parse(some_jsonstring_data))
res = http.request(req)

更多信息:

我知道我想要击中的主机使用TLS1.2

我试图按照@ jww的答案中的建议设置ssl_options,但没有运气......如果我没有设置ssl_version,我会收到此错误:

OpenSSL::SSL::SSLError: SSL_connect SYSCALL returned=5 errno=0 state=SSLv2/v3 read server hello A

非常欢迎任何帮助。谢谢大家!!

1 个答案:

答案 0 :(得分:1)

  

http.ssl_version =' SSLv2'

Server Name Indication或SNI是TLS扩展。在TLS 1.0之前无法使用扩展程序。

SSLv2不安全。你应该在2015年避免它(和SSLv3)。另见How to set TLS context options in Ruby (like OpenSSL::SSL::SSL_OP_NO_SSLv2)