Set SNI hostname in example SSL clients

fix #853
This commit is contained in:
Vinnie Falco
2017-10-29 14:58:57 -07:00
parent c5a1615301
commit b75d4e5e14
4 changed files with 27 additions and 0 deletions
@@ -20,6 +20,7 @@
#include <boost/beast/version.hpp>
#include <boost/asio/connect.hpp>
#include <boost/asio/ip/tcp.hpp>
#include <boost/asio/ssl/error.hpp>
#include <boost/asio/ssl/stream.hpp>
#include <cstdlib>
#include <iostream>
@@ -62,6 +63,13 @@ int main(int argc, char** argv)
tcp::resolver resolver{ioc};
ssl::stream<tcp::socket> stream{ioc, ctx};
// Set SNI Hostname (many hosts need this to handshake successfully)
if(! SSL_set_tlsext_host_name(stream.native_handle(), host))
{
boost::system::error_code ec{static_cast<int>(::ERR_get_error()), boost::asio::error::get_ssl_category()};
throw boost::system::system_error{ec};
}
// Look up the domain name
auto const results = resolver.resolve(host, port);