mirror of
https://github.com/boostorg/beast.git
synced 2025-07-30 21:07:26 +02:00
Update WebSocket examples to set TLS SNI
This commit is contained in:
@ -1,5 +1,6 @@
|
|||||||
Version XXX:
|
Version XXX:
|
||||||
|
|
||||||
|
* Update WebSocket examples to set TLS SNI.
|
||||||
* Add handler tracking locations to websocket.
|
* Add handler tracking locations to websocket.
|
||||||
* Add handler tracking locations to tcp teardown.
|
* Add handler tracking locations to tcp teardown.
|
||||||
* Eliminate spurious uninitialised variable warning in detect_ssl.
|
* Eliminate spurious uninitialised variable warning in detect_ssl.
|
||||||
|
@ -122,6 +122,16 @@ public:
|
|||||||
// Set a timeout on the operation
|
// Set a timeout on the operation
|
||||||
beast::get_lowest_layer(ws_).expires_after(std::chrono::seconds(30));
|
beast::get_lowest_layer(ws_).expires_after(std::chrono::seconds(30));
|
||||||
|
|
||||||
|
// Set SNI Hostname (many hosts need this to handshake successfully)
|
||||||
|
if(! SSL_set_tlsext_host_name(
|
||||||
|
ws_.next_layer().native_handle(),
|
||||||
|
host_.c_str()))
|
||||||
|
{
|
||||||
|
ec = beast::error_code(static_cast<int>(::ERR_get_error()),
|
||||||
|
net::error::get_ssl_category());
|
||||||
|
return fail(ec, "connect");
|
||||||
|
}
|
||||||
|
|
||||||
// Perform the SSL handshake
|
// Perform the SSL handshake
|
||||||
ws_.next_layer().async_handshake(
|
ws_.next_layer().async_handshake(
|
||||||
ssl::stream_base::client,
|
ssl::stream_base::client,
|
||||||
|
@ -114,6 +114,16 @@ public:
|
|||||||
// Set a timeout on the operation
|
// Set a timeout on the operation
|
||||||
beast::get_lowest_layer(ws_).expires_after(std::chrono::seconds(30));
|
beast::get_lowest_layer(ws_).expires_after(std::chrono::seconds(30));
|
||||||
|
|
||||||
|
// Set SNI Hostname (many hosts need this to handshake successfully)
|
||||||
|
if(! SSL_set_tlsext_host_name(
|
||||||
|
ws_.next_layer().native_handle(),
|
||||||
|
host_.c_str()))
|
||||||
|
{
|
||||||
|
ec = beast::error_code(static_cast<int>(::ERR_get_error()),
|
||||||
|
net::error::get_ssl_category());
|
||||||
|
return fail(ec, "connect");
|
||||||
|
}
|
||||||
|
|
||||||
// Perform the SSL handshake
|
// Perform the SSL handshake
|
||||||
ws_.next_layer().async_handshake(
|
ws_.next_layer().async_handshake(
|
||||||
ssl::stream_base::client,
|
ssl::stream_base::client,
|
||||||
|
@ -71,7 +71,17 @@ do_session(
|
|||||||
if(ec)
|
if(ec)
|
||||||
return fail(ec, "connect");
|
return fail(ec, "connect");
|
||||||
|
|
||||||
// Update the host_ string. This will provide the value of the
|
// Set SNI Hostname (many hosts need this to handshake successfully)
|
||||||
|
if(! SSL_set_tlsext_host_name(
|
||||||
|
ws.next_layer().native_handle(),
|
||||||
|
host.c_str()))
|
||||||
|
{
|
||||||
|
ec = beast::error_code(static_cast<int>(::ERR_get_error()),
|
||||||
|
net::error::get_ssl_category());
|
||||||
|
return fail(ec, "connect");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update the host string. This will provide the value of the
|
||||||
// Host HTTP header during the WebSocket handshake.
|
// Host HTTP header during the WebSocket handshake.
|
||||||
// See https://tools.ietf.org/html/rfc7230#section-5.4
|
// See https://tools.ietf.org/html/rfc7230#section-5.4
|
||||||
host += ':' + std::to_string(ep.port());
|
host += ':' + std::to_string(ep.port());
|
||||||
|
@ -70,6 +70,14 @@ int main(int argc, char** argv)
|
|||||||
// Make the connection on the IP address we get from a lookup
|
// Make the connection on the IP address we get from a lookup
|
||||||
auto ep = net::connect(get_lowest_layer(ws), results);
|
auto ep = net::connect(get_lowest_layer(ws), results);
|
||||||
|
|
||||||
|
// Set SNI Hostname (many hosts need this to handshake successfully)
|
||||||
|
if(! SSL_set_tlsext_host_name(ws.next_layer().native_handle(), host.c_str()))
|
||||||
|
throw beast::system_error(
|
||||||
|
beast::error_code(
|
||||||
|
static_cast<int>(::ERR_get_error()),
|
||||||
|
net::error::get_ssl_category()),
|
||||||
|
"Failed to set SNI Hostname");
|
||||||
|
|
||||||
// Update the host_ string. This will provide the value of the
|
// Update the host_ string. This will provide the value of the
|
||||||
// Host HTTP header during the WebSocket handshake.
|
// Host HTTP header during the WebSocket handshake.
|
||||||
// See https://tools.ietf.org/html/rfc7230#section-5.4
|
// See https://tools.ietf.org/html/rfc7230#section-5.4
|
||||||
|
Reference in New Issue
Block a user