我在尝试请求使用 TLS 1.3 的端点时遇到问题
require 'base64'
require 'openssl'
require 'rest-client'
auth_payload = {
grant_type: 'client_credentials',
scope: 'cobrancas.boletos-info cobrancas.boletos-requisicao'
}
encoded_token = Base64.strict_encode64(
'MY_CLIENT_ID:MY_CLIENT_SECRET'
)
response = RestClient::Request.execute(
method: 'post',
url: "https://oauth.sandbox.bb.com.br/oauth/token",
payload: auth_payload,
verify_ssl: OpenSSL::SSL::VERIFY_NONE,
headers: {
content_type: 'application/x-www-form-urlencoded',
authorization: "Basic #{encoded_token}"
}
)
我尝试删除
verify_ssl
并添加ssl_version: 'TLSv1_3'
并返回错误unknown SSL method TLSv1_3 (ArgumentError)
传递
verify_ssl: OpenSSL::SSL::VERIFY_NONE
属性有时有效,有时返回错误Connection reset by peer - SSL_connect (Errno::ECONNRESET)
不传递
verify_ssl
和ssl_version
属性返回错误SSL_connect returned=1 errno=0 peeraddr=1.1.1.1:443 state=error: certificate verify failed (unable to get local issuer certificate) (OpenSSL::SSL::SSLError)
尝试使用 Ruby 2.7.6 和 3.1.2 都不起作用。
通过 CURL,每次我尝试时它都有效(并且有很多)
curl -X POST https://oauth.sandbox.bb.com.br/oauth/token -v \
-H "Authorization: Basic ${MY_TOKEN}" \
-d "grant_type=client_credentials"
我在互联网上做了很多研究,据我了解,Ruby 仍然不支持使用 TLS 1.3 的 https 端点,对吗?
OPEN_SSL
已弃用 ssl_version
参数,请尝试使用 min_version
,如 here.
我看到你正在使用
RestClient
gem 可能没有更新以使用 OpenSSL 的新格式。
您可以使用下面的代码来测试控制台的SSL版本。
hostname = "google.com"
ctx = OpenSSL::SSL::SSLContext.new()
s = TCPSocket.new(hostname, 443)
ssl = OpenSSL::SSL::SSLSocket.new(s, ctx)
ssl.hostname = hostname
ssl.connect
p ssl.ssl_version # "TLSv1.3"