Skip to content

Commit e80089c

Browse files
authored
Merge pull request #226 from c-jimenez/fix/ssl_certificate_verify
[websockets] Add server name parameter to allow the use of an IP address for the connection URL (DNS resolution done beforehand) when using a TLS link (server name is used for certificate hostname check)
2 parents 8d3eff3 + f2e0833 commit e80089c

File tree

4 files changed

+22
-6
lines changed

4 files changed

+22
-6
lines changed

3rdparty/libwebsockets/lib/core-net/client/connect4.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ lws_client_connect_4_established(struct lws *wsi, struct lws *wsi_piggyback,
5757
if (wsi->a.vhost->http.http_proxy_port) {
5858
const char *cpa;
5959

60-
cpa = lws_wsi_client_stash_item(wsi, CIS_ADDRESS,
60+
cpa = lws_wsi_client_stash_item(wsi, CIS_HOST,
6161
_WSI_TOKEN_CLIENT_PEER_ADDRESS);
6262
if (!cpa)
6363
goto failed;

src/websockets/IWebsocketClient.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ class IWebsocketClient
149149
/** @brief Skip server name check in certificates for TLS connections
150150
* (Warning : enabling this feature is not recommended in production) */
151151
bool skip_server_name_check;
152+
/** @brief Server name (used for server certificate check) */
153+
std::string server_name;
152154
};
153155
};
154156

src/websockets/libwebsockets/LibWebsocketClient.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,8 +358,15 @@ void LibWebsocketClient::connectCallback(struct lws_sorted_usec_list* sul) noexc
358358
i.context = client->m_context;
359359
i.address = client->m_url.address().c_str();
360360
i.path = client->m_url.path().c_str();
361-
i.host = i.address;
362-
i.origin = i.address;
361+
if (client->m_credentials.server_name.empty())
362+
{
363+
i.host = i.address;
364+
}
365+
else
366+
{
367+
i.host = client->m_credentials.server_name.c_str();
368+
}
369+
i.origin = i.address;
363370
if (client->m_url.protocol() == "wss")
364371
{
365372
i.ssl_connection = LCCSCF_USE_SSL;

src/websockets/libwebsockets/LibWebsocketClientPool.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ void LibWebsocketClientPool::process()
147147

148148
// Dummy vhost to handle context related events
149149
struct lws_protocols protocols[] = {{"LibWebsocketClientPool", &LibWebsocketClientPool::eventCallback, 0, 0, 0, this, 0},
150-
LWS_PROTOCOL_LIST_TERM};
150+
LWS_PROTOCOL_LIST_TERM};
151151
struct lws_context_creation_info vhost_info;
152152
memset(&vhost_info, 0, sizeof(vhost_info));
153153
vhost_info.protocols = protocols;
@@ -537,8 +537,15 @@ void LibWebsocketClientPool::Client::connectCallback(struct lws_sorted_usec_list
537537
connect_info.vhost = client->m_vhost;
538538
connect_info.address = client->m_url.address().c_str();
539539
connect_info.path = client->m_url.path().c_str();
540-
connect_info.host = connect_info.address;
541-
connect_info.origin = connect_info.address;
540+
if (client->m_credentials.server_name.empty())
541+
{
542+
connect_info.host = connect_info.address;
543+
}
544+
else
545+
{
546+
connect_info.host = client->m_credentials.server_name.c_str();
547+
}
548+
connect_info.origin = connect_info.address;
542549
if (client->m_url.protocol() == "wss")
543550
{
544551
connect_info.ssl_connection = LCCSCF_USE_SSL;

0 commit comments

Comments
 (0)