Skip to content

Commit c57a227

Browse files
Set SNI Hostname for WSS connection
1 parent ac83fc0 commit c57a227

4 files changed

Lines changed: 10 additions & 3 deletions

File tree

src/etp/AbstractClientSessionCRTP.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ namespace ETP_NS
3232

3333
void on_connect(boost::system::error_code ec) {
3434
if (ec) {
35-
std::cerr << "on_connect : " << ec.message() << std::endl;
35+
std::cerr << "Websocket on connect : " << ec.message() << std::endl;
3636
}
3737

3838
#if BOOST_VERSION < 107000

src/etp/ClientSession.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ namespace ETP_NS
7575
void on_handshake(boost::system::error_code ec)
7676
{
7777
if (ec) {
78-
std::cerr << "on_handshake : " << ec.message() << std::endl;
78+
std::cerr << "on WS handshake : " << ec.message() << std::endl;
7979
std::cerr << "Sometimes some ETP server require a trailing slash at the end of their URL. Did you also check your optional \"data-partition-id\" additional Header Field?" << std::endl;
8080
return;
8181
}

src/etp/ssl/HttpsClientSession.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ namespace ETP_NS
7474
if (!SSL_set_tlsext_host_name(stream_.native_handle(), etpServerHost.data()))
7575
{
7676
boost::system::error_code ec{ static_cast<int>(::ERR_get_error()), boost::asio::error::get_ssl_category() };
77-
std::cerr << ec.message() << "\n";
77+
std::cerr << "HTTPS on connect (SNI): " << ec.message() << "\n";
7878
return;
7979
}
8080

src/etp/ssl/SslClientSession.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,13 @@ namespace ETP_NS
6666
std::cerr << "on_resolve : " << ec.message() << std::endl;
6767
}
6868

69+
// Set SNI Hostname (many hosts need this to handshake successfully)
70+
if (!SSL_set_tlsext_host_name(ws_.next_layer().native_handle(), etpServerHost.c_str()))
71+
{
72+
boost::system::error_code ecSNI{ static_cast<int>(::ERR_get_error()), boost::asio::error::get_ssl_category() };
73+
std::cerr << "Websocket on connect (SNI): " << ecSNI.message() << std::endl;
74+
}
75+
6976
// Reality check: IPv6 is unlikely to be available yet
7077
std::vector<tcp::endpoint> endpoints(results.begin(), results.end());
7178
std::stable_partition(endpoints.begin(), endpoints.end(), [](auto entry) {return entry.protocol() == tcp::v4(); });

0 commit comments

Comments
 (0)