diff --git a/CHANGELOG.md b/CHANGELOG.md index 32d1c2eb..034a8991 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ Version 131: * basic_fields returns const values +* Set SNI hostname in example SSL clients -------------------------------------------------------------------------------- diff --git a/example/http/client/async-ssl/http_client_async_ssl.cpp b/example/http/client/async-ssl/http_client_async_ssl.cpp index fc5791ee..76b26cb0 100644 --- a/example/http/client/async-ssl/http_client_async_ssl.cpp +++ b/example/http/client/async-ssl/http_client_async_ssl.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -66,6 +67,14 @@ public: char const* target, int version) { + // 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(::ERR_get_error()), boost::asio::error::get_ssl_category()}; + std::cerr << ec.message() << "\n"; + return; + } + // Set up an HTTP GET request message req_.version(version); req_.method(http::verb::get); diff --git a/example/http/client/coro-ssl/http_client_coro_ssl.cpp b/example/http/client/coro-ssl/http_client_coro_ssl.cpp index 2e796704..8b4ff8c6 100644 --- a/example/http/client/coro-ssl/http_client_coro_ssl.cpp +++ b/example/http/client/coro-ssl/http_client_coro_ssl.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -57,6 +58,14 @@ do_session( tcp::resolver resolver{ioc}; ssl::stream stream{ioc, ctx}; + // Set SNI Hostname (many hosts need this to handshake successfully) + if(! SSL_set_tlsext_host_name(stream.native_handle(), host.c_str())) + { + ec.assign(static_cast(::ERR_get_error()), boost::asio::error::get_ssl_category()); + std::cerr << ec.message() << "\n"; + return; + } + // Look up the domain name auto const results = resolver.async_resolve(host, port, yield[ec]); if(ec) diff --git a/example/http/client/sync-ssl/http_client_sync_ssl.cpp b/example/http/client/sync-ssl/http_client_sync_ssl.cpp index 86c9f9e8..db4de566 100644 --- a/example/http/client/sync-ssl/http_client_sync_ssl.cpp +++ b/example/http/client/sync-ssl/http_client_sync_ssl.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -62,6 +63,13 @@ int main(int argc, char** argv) tcp::resolver resolver{ioc}; ssl::stream 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(::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);