【发布时间】:2020-09-02 11:56:54
【问题描述】:
我在 Ruby 中使用 OpenSSL 库编写了以下代码,该库从 cloudflare.com 获取证书链。但是 Cloudflare 有一个混合系统,旧浏览器接收 RSA 证书,新客户端接收 ECDSA 证书(请参阅https://www.ssllabs.com/ssltest/analyze.html?d=cloudflare.com&s=104.17.176.85)。
就我而言,我想获得较旧的 RSA 证书,这就是我设置ctx.ciphers = 'aRSA' 的原因。但不知何故,我总是收到 ECDSA 证书。
以下命令通过 openssl s_client -cipher aRSA -connect cloudflare.com:443 -showcerts 起作用。
require 'openssl'
ctx = OpenSSL::SSL::SSLContext.new
ctx.ciphers = 'aRSA'
sock = Socket.tcp("https://www.cloudflare.com", 443, connect_timeout: 10)
connection = connect(sock, ctx, hostname)
connection.peer_cert_chain
def connect(sock, ctx, url)
ssl = OpenSSL::SSL::SSLSocket.new(sock, ctx)
ssl.hostname = url
begin
ssl.connect_nonblock
rescue IO::WaitReadable
return nil unless IO.select([ssl], nil, nil, 10)
retry
rescue IO::WaitWritable
return nil unless IO.select(nil, [ssl], nil, 10)
retry
end
ssl
end
谢谢
Ruby 版本:2.6.3 Ruby OpenSSL 版本:2.2.0 OpenSSL 版本:LibreSSL 2.8.3
【问题讨论】:
标签: ruby ssl openssl ssl-certificate