Skip to content

Commit d3150e0

Browse files
PR to set SNI during boost lib websocket next_layer() SSL handshake process happen during launch of app tunneling. (#142)
* with Private VPN, it is important that SNI are supplied for SSL handshake, hence this change ensure that SNI is set for next_layer() which is client hello call. Test and working fine. * Add host Param in function discription
1 parent b6c31b4 commit d3150e0

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

src/TcpAdapterProxy.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -885,8 +885,8 @@ namespace aws { namespace iot { namespace securedtunneling {
885885
{
886886
BOOST_LOG_SEV(log, debug) << "SSL host verification is off";
887887
}
888-
//next ssl handshake
889-
tac.wss->async_ssl_handshake(boost::asio::ssl::stream_base::client, [=, &tac](boost::system::error_code const &ec)
888+
//next ssl handshake and providing host string
889+
tac.wss->async_ssl_handshake(boost::asio::ssl::stream_base::client, tac.adapter_config.proxy_host.c_str(), [=, &tac](boost::system::error_code const &ec)
890890
{
891891
if (ec)
892892
{
@@ -2266,4 +2266,4 @@ namespace aws { namespace iot { namespace securedtunneling {
22662266
return false;
22672267
}
22682268
}
2269-
}}}
2269+
}}}

src/WebSocketStream.cpp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,15 +173,35 @@ namespace aws {
173173
}
174174
}
175175

176-
void WebSocketStream::async_ssl_handshake(const ssl::stream_base::handshake_type &type,
176+
void WebSocketStream::async_ssl_handshake(const ssl::stream_base::handshake_type &type, const std::string &host,
177177
const BoostCallbackFunc &handler) {
178178
if (localproxyConfig.is_web_proxy_using_tls) {
179179
BOOST_LOG_SEV(*log, trace) << "Calling next_layer().async_handshake with type: "
180180
<< WEB_PROXY_WITH_TLS_TYPE_NAME;
181+
// Set SNI Hostname (many hosts need this to handshake successfully)
182+
if(!SSL_set_tlsext_host_name(boost::get<unique_ptr<WEB_PROXY_WITH_TLS_TYPE>>(wss)->next_layer().native_handle(), host.c_str()))
183+
{
184+
BOOST_LOG_SEV(*log, trace) << "SSL next_layer() failed to set SNI";
185+
}
186+
else
187+
{
188+
BOOST_LOG_SEV(*log, trace) << "SSL next_layer() SNI is set : "
189+
<< host;
190+
}
181191
return boost::get<unique_ptr<WEB_PROXY_WITH_TLS_TYPE>>(wss)->next_layer().async_handshake(type, handler);
182192
} else {
183193
BOOST_LOG_SEV(*log, trace) << "Calling next_layer().async_handshake with type: "
184194
<< WEB_PROXY_NO_TLS_TYPE_NAME;
195+
// Set SNI Hostname (many hosts need this to handshake successfully)
196+
if(!SSL_set_tlsext_host_name(boost::get<unique_ptr<WEB_PROXY_NO_TLS_TYPE>>(wss)->next_layer().native_handle(), host.c_str()))
197+
{
198+
BOOST_LOG_SEV(*log, trace) << "SSL next_layer() failed to set SNI";
199+
}
200+
else
201+
{
202+
BOOST_LOG_SEV(*log, trace) << "SSL next_layer() SNI is set : "
203+
<< host;
204+
}
185205
return boost::get<unique_ptr<WEB_PROXY_NO_TLS_TYPE>>(wss)->next_layer().async_handshake(type, handler);
186206
}
187207
}

src/WebSocketStream.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,11 @@ namespace aws {
147147
/**
148148
* Performs the SSL handshake between the localproxy and the proxy server asynchronously.
149149
* @param type The handshake type
150+
* @param host the host subdoman and domain
150151
* @param handler the callback handler when the async operation is complete.
151152
*/
152153
void
153-
async_ssl_handshake(const ssl::stream_base::handshake_type &type, const BoostCallbackFunc &handler);
154+
async_ssl_handshake(const ssl::stream_base::handshake_type &type, const std::string &host, const BoostCallbackFunc &handler);
154155
#endif
155156

156157
/**

0 commit comments

Comments
 (0)