IO::Socket::SSL: SSL 连接尝试失败

IO::Socket::SSL: SSL connect attempt failed

我请求https://bank.gov.ua

my $ua       =  Mojo::UserAgent->new;
$ua->get("https://bank.gov.ua/NBUStatService/v1/statdirectory/exchange?valcode=EUR&date=$date_now&json");

并得到错误:

DEBUG: .../IO/Socket/SSL.pm:3010: new ctx 146452496
DEBUG: .../IO/Socket/SSL.pm:1638: don't start handshake: IO::Socket::SSL=GLOB(0xc955978)
DEBUG: .../IO/Socket/SSL.pm:787: ssl handshake not started
DEBUG: .../IO/Socket/SSL.pm:829: using SNI with hostname bank.gov.ua
DEBUG: .../IO/Socket/SSL.pm:864: request OCSP stapling
DEBUG: .../IO/Socket/SSL.pm:894: call Net::SSLeay::connect
DEBUG: .../IO/Socket/SSL.pm:897: done Net::SSLeay::connect -> -1
DEBUG: .../IO/Socket/SSL.pm:907: ssl handshake in progress
DEBUG: .../IO/Socket/SSL.pm:894: call Net::SSLeay::connect
DEBUG: .../IO/Socket/SSL.pm:897: done Net::SSLeay::connect -> -1
DEBUG: .../IO/Socket/SSL.pm:900: local error: SSL connect attempt failed
DEBUG: .../IO/Socket/SSL.pm:903: fatal SSL error: SSL connect attempt failed
DEBUG: .../IO/Socket/SSL.pm:3059: free ctx 146452496 open=
DEBUG: .../IO/Socket/SSL.pm:3063: free ctx 146452496 callback
DEBUG: .../IO/Socket/SSL.pm:3070: OK free ctx 146452496

我可以用 curl 请求这个主机给 url 没问题。

有人知道我通过 IO::Socket::SSL (Mojo::UserAgent) 执行此操作时出现了什么问题吗?

这个服务器很奇怪:

  • 带有 openssl s_client -connect bank.gov.ua:443 的第一个请求失败,服务器只是关闭连接:“SSL 握手已读取 0 个字节并写入 303 个字节”
  • Mojo::UserAgent 代码也失败了
  • 使用显式 TLS 1.2 发出请求成功:openssl s_client -connect bank.gov.ua:443 -tls1_2
  • 再次尝试第一个请求突然也成功了
  • Mojo::UserAgent 代码现在也成功了

我唯一的解释是某些防火墙或负载平衡器临时将 IP 地址列入白名单,以防它看到有效的 TLS ClientHello - 并且认为 TLS 1.3 无效。