Skip to content

Commit 5f0c2b2

Browse files
committed
Insert Server Name Indication (SNI) only for hostnames, not for IP addresses
1 parent 1b11fd3 commit 5f0c2b2

File tree

1 file changed

+10
-5
lines changed
  • websocketpp/transport/asio/security

1 file changed

+10
-5
lines changed

websocketpp/transport/asio/security/tls.hpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -234,16 +234,21 @@ class connection : public lib::enable_shared_from_this<connection> {
234234
void pre_init(init_handler callback) {
235235
// TODO: is this the best way to check whether this function is
236236
// available in the version of OpenSSL being used?
237-
// TODO: consider case where host is an IP address
238237
#if OPENSSL_VERSION_NUMBER >= 0x90812f
239238
if (!m_is_server) {
240239
// For clients on systems with a suitable OpenSSL version, set the
241240
// TLS SNI hostname header so connecting to TLS servers using SNI
242241
// will work.
243-
long res = SSL_set_tlsext_host_name(
244-
get_socket().native_handle(), m_uri->get_host().c_str());
245-
if (!(1 == res)) {
246-
callback(socket::make_error_code(socket::error::tls_failed_sni_hostname));
242+
auto host = m_uri->get_host();
243+
lib::asio::error_code ec_addr;
244+
boost::asio::ip::address addr = boost::asio::ip::make_address(host, ec_addr);
245+
if (ec_addr) {
246+
// The SNI applies only to DNS host names, not for IP addresses
247+
long res = SSL_set_tlsext_host_name(
248+
get_socket().native_handle(), host.c_str());
249+
if (!(1 == res)) {
250+
callback(socket::make_error_code(socket::error::tls_failed_sni_hostname));
251+
}
247252
}
248253
}
249254
#endif

0 commit comments

Comments
 (0)