如何修复 boost::beast handshake: no protocols available (SSL routines)

问题:

运行 boost::beast 应用程序时,你看到以下异常:

handshake_error_output.txt
terminate called after throwing an instance of 'boost::wrapexcept<boost::system::system_error>'
  what():  handshake: no protocols available (SSL routines) [asio.ssl:167772351]

解决方案

你正在使用服务器不支持的 SSL 或 TLS 版本连接。

TLS/SSL 版本在初始化 boost::asio::ssl::context 时选择:

ssl_context_example.cpp
namespace ssl = boost::asio::ssl;

ssl::context ctx(ssl::context::tlsv11_client);

在这种情况下,我们使用的是过时的 TLSv1.1 协议。

将该行改为

ssl_context_tlsv13.cpp
ssl::context ctx(ssl::context::tlsv13_client);

来使用 TLSv1.3。请记住,一些较旧的 TLS/SSL 版本被认为是不安全的。


Check out similar posts by category: Boost, C/C++