SSL examples verify peer cert hostname

Fixes #2974
This commit is contained in:
Mohammad Nejati authored and Mohammad Nejati committed 2025-02-11 19:43:58 +03:30
1 parent 4e384f086b
commit ea38d841b0
11 files changed
+109 -28

No files matched your search

@@ -77,7 +77,19 @@ public:
// Set SNI Hostname (many hosts need this to handshake successfully)
if(! SSL_set_tlsext_host_name(stream_.native_handle(), host))
{
beast::error_code ec{static_cast<int>(::ERR_get_error()), net::error::get_ssl_category()};
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
if(! SSL_set1_host(stream_.native_handle(), host))
{
beast::error_code ec{
static_cast<int>(::ERR_get_error()),
net::error::get_ssl_category()};
std::cerr << ec.message() << "\n";
return;
}
@@ -69,7 +69,19 @@ public:
// Set SNI Hostname (many hosts need this to handshake successfully)
if(! SSL_set_tlsext_host_name(stream_.native_handle(), host))
{
beast::error_code ec{static_cast<int>(::ERR_get_error()), net::error::get_ssl_category()};
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
if(! SSL_set1_host(stream_.native_handle(), host))
{
beast::error_code ec{
static_cast<int>(::ERR_get_error()),
net::error::get_ssl_category()};
std::cerr << ec.message() << "\n";
return;
}
@@ -51,9 +51,17 @@ do_session(
auto stream = ssl::stream<beast::tcp_stream>{ executor, ctx };
// Set SNI Hostname (many hosts need this to handshake successfully)
if(!SSL_set_tlsext_host_name(stream.native_handle(), host.c_str()))
if(! SSL_set_tlsext_host_name(stream.native_handle(), host.c_str()))
{
throw boost::system::system_error(
throw beast::system_error(
static_cast<int>(::ERR_get_error()),
net::error::get_ssl_category());
}
// Set the expected hostname in the peer certificate for verification
if(! SSL_set1_host(stream.native_handle(), host.c_str()))
{
throw beast::system_error(
static_cast<int>(::ERR_get_error()),
net::error::get_ssl_category());
}
@@ -65,6 +65,14 @@ do_session(
return;
}
// Set the expected hostname in the peer certificate for verification
if(! SSL_set1_host(stream.native_handle(), host.c_str()))
{
ec.assign(static_cast<int>(::ERR_get_error()), net::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)
@@ -69,8 +69,17 @@ int main(int argc, char** argv)
// Set SNI Hostname (many hosts need this to handshake successfully)
if(! SSL_set_tlsext_host_name(stream.native_handle(), host))
{
beast::error_code ec{static_cast<int>(::ERR_get_error()), net::error::get_ssl_category()};
throw beast::system_error{ec};
throw beast::system_error(
static_cast<int>(::ERR_get_error()),
net::error::get_ssl_category());
}
// Set the expected hostname in the peer certificate for verification
if(! SSL_set1_host(stream.native_handle(), host))
{
throw beast::system_error(
static_cast<int>(::ERR_get_error()),
net::error::get_ssl_category());
}
// Look up the domain name