Getting OpenSSL::SSL::SSLError: SSL_set_tlsext_host_name when trying to make a post request through https

Getting OpenSSL::SSL::SSLError: SSL_set_tlsext_host_name when trying to make a post request through https

我正在尝试使用 ruby 中的 net/http class 通过 https 发送 post 请求,但出现此错误:

 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

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

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).