mirror of
https://github.com/boostorg/beast.git
synced 2025-07-29 20:37:31 +02:00
Replace SSL_set1_host with asio::ssl::host_name_verification
`SSL_set1_host` fails when host is an IP address
This commit is contained in:
committed by
Mohammad Nejati
parent
ea38d841b0
commit
ee2b5b2ff9
@ -85,14 +85,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Set the expected hostname in the peer certificate for verification
|
// Set the expected hostname in the peer certificate for verification
|
||||||
if(! SSL_set1_host(stream_.native_handle(), host))
|
stream_.set_verify_callback(ssl::host_name_verification(host));
|
||||||
{
|
|
||||||
beast::error_code ec{
|
|
||||||
static_cast<int>(::ERR_get_error()),
|
|
||||||
net::error::get_ssl_category()};
|
|
||||||
std::cerr << ec.message() << "\n";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set up an HTTP GET request message
|
// Set up an HTTP GET request message
|
||||||
req_.version(version);
|
req_.version(version);
|
||||||
|
@ -77,14 +77,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Set the expected hostname in the peer certificate for verification
|
// Set the expected hostname in the peer certificate for verification
|
||||||
if(! SSL_set1_host(stream_.native_handle(), host))
|
stream_.set_verify_callback(ssl::host_name_verification(host));
|
||||||
{
|
|
||||||
beast::error_code ec{
|
|
||||||
static_cast<int>(::ERR_get_error()),
|
|
||||||
net::error::get_ssl_category()};
|
|
||||||
std::cerr << ec.message() << "\n";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set up an HTTP GET request message
|
// Set up an HTTP GET request message
|
||||||
req_.version(version);
|
req_.version(version);
|
||||||
|
@ -59,12 +59,7 @@ do_session(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Set the expected hostname in the peer certificate for verification
|
// Set the expected hostname in the peer certificate for verification
|
||||||
if(! SSL_set1_host(stream.native_handle(), host.c_str()))
|
stream.set_verify_callback(ssl::host_name_verification(host));
|
||||||
{
|
|
||||||
throw beast::system_error(
|
|
||||||
static_cast<int>(::ERR_get_error()),
|
|
||||||
net::error::get_ssl_category());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Look up the domain name
|
// Look up the domain name
|
||||||
auto const results = co_await resolver.async_resolve(host, port);
|
auto const results = co_await resolver.async_resolve(host, port);
|
||||||
|
@ -66,12 +66,7 @@ do_session(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Set the expected hostname in the peer certificate for verification
|
// Set the expected hostname in the peer certificate for verification
|
||||||
if(! SSL_set1_host(stream.native_handle(), host.c_str()))
|
stream.set_verify_callback(ssl::host_name_verification(host));
|
||||||
{
|
|
||||||
ec.assign(static_cast<int>(::ERR_get_error()), net::error::get_ssl_category());
|
|
||||||
std::cerr << ec.message() << "\n";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Look up the domain name
|
// Look up the domain name
|
||||||
auto const results = resolver.async_resolve(host, port, yield[ec]);
|
auto const results = resolver.async_resolve(host, port, yield[ec]);
|
||||||
|
@ -75,12 +75,7 @@ int main(int argc, char** argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Set the expected hostname in the peer certificate for verification
|
// Set the expected hostname in the peer certificate for verification
|
||||||
if(! SSL_set1_host(stream.native_handle(), host))
|
stream.set_verify_callback(ssl::host_name_verification(host));
|
||||||
{
|
|
||||||
throw beast::system_error(
|
|
||||||
static_cast<int>(::ERR_get_error()),
|
|
||||||
net::error::get_ssl_category());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Look up the domain name
|
// Look up the domain name
|
||||||
auto const results = resolver.resolve(host, port);
|
auto const results = resolver.resolve(host, port);
|
||||||
|
@ -74,6 +74,19 @@ public:
|
|||||||
char const* port,
|
char const* port,
|
||||||
char const* text)
|
char const* text)
|
||||||
{
|
{
|
||||||
|
// Set SNI Hostname (many hosts need this to handshake successfully)
|
||||||
|
if(! SSL_set_tlsext_host_name(ws_.next_layer().native_handle(), host))
|
||||||
|
{
|
||||||
|
beast::error_code ec{
|
||||||
|
static_cast<int>(::ERR_get_error()),
|
||||||
|
net::error::get_ssl_category()};
|
||||||
|
std::cerr << ec.message() << "\n";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set the expected hostname in the peer certificate for verification
|
||||||
|
ws_.next_layer().set_verify_callback(ssl::host_name_verification(host));
|
||||||
|
|
||||||
// Save these for later
|
// Save these for later
|
||||||
host_ = host;
|
host_ = host;
|
||||||
text_ = text;
|
text_ = text;
|
||||||
@ -115,20 +128,6 @@ 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.assign(static_cast<int>(::ERR_get_error()), net::error::get_ssl_category());
|
|
||||||
return fail(ec, "connect");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set the expected hostname in the peer certificate for verification
|
|
||||||
if(! SSL_set1_host(ws_.next_layer().native_handle(), host_.c_str()))
|
|
||||||
{
|
|
||||||
ec.assign(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
|
// 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
|
||||||
|
@ -66,6 +66,19 @@ public:
|
|||||||
char const* port,
|
char const* port,
|
||||||
char const* text)
|
char const* text)
|
||||||
{
|
{
|
||||||
|
// Set SNI Hostname (many hosts need this to handshake successfully)
|
||||||
|
if(! SSL_set_tlsext_host_name(ws_.next_layer().native_handle(), host))
|
||||||
|
{
|
||||||
|
beast::error_code ec{
|
||||||
|
static_cast<int>(::ERR_get_error()),
|
||||||
|
net::error::get_ssl_category()};
|
||||||
|
std::cerr << ec.message() << "\n";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set the expected hostname in the peer certificate for verification
|
||||||
|
ws_.next_layer().set_verify_callback(ssl::host_name_verification(host));
|
||||||
|
|
||||||
// Save these for later
|
// Save these for later
|
||||||
host_ = host;
|
host_ = host;
|
||||||
text_ = text;
|
text_ = text;
|
||||||
@ -106,21 +119,7 @@ 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.assign(static_cast<int>(::ERR_get_error()), net::error::get_ssl_category());
|
|
||||||
return fail(ec, "connect");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set the expected hostname in the peer certificate for verification
|
|
||||||
if(! SSL_set1_host(ws_.next_layer().native_handle(), host_.c_str()))
|
|
||||||
{
|
|
||||||
ec.assign(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
|
// 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
|
||||||
|
@ -78,11 +78,7 @@ do_session(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Set the expected hostname in the peer certificate for verification
|
// Set the expected hostname in the peer certificate for verification
|
||||||
if(! SSL_set1_host(ws.next_layer().native_handle(), host.c_str()))
|
ws.next_layer().set_verify_callback(ssl::host_name_verification(host));
|
||||||
{
|
|
||||||
ec.assign(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
|
// 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.
|
||||||
|
@ -81,12 +81,7 @@ int main(int argc, char** argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Set the expected hostname in the peer certificate for verification
|
// Set the expected hostname in the peer certificate for verification
|
||||||
if(! SSL_set1_host(ws.next_layer().native_handle(), host.c_str()))
|
ws.next_layer().set_verify_callback(ssl::host_name_verification(host));
|
||||||
{
|
|
||||||
throw beast::system_error(
|
|
||||||
static_cast<int>(::ERR_get_error()),
|
|
||||||
net::error::get_ssl_category());
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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.
|
||||||
|
Reference in New Issue
Block a user