How to fix boost::beast handshake: no protocols available (SSL routines)

Problem:

While running your boost::beast application, you see the following exception:

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

Solution

You are connecting using a SSL or TLS version the server does not support.

The TLS/SSL version is selected while initializing theĀ boost::asio::ssl::context:

namespace ssl = boost::asio::ssl;

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

In this case, we’re using the outdated TLSv1.1 protocol.

Change the line to

ssl::context ctx(ssl::context::tlsv13_client);

to use TLSv1.3 instead. Keep in mind that some older TLS/SSL versions are considered to be insecure.