Skip to content

Commit c82795c

Browse files
committed
Merge branch 'megaposer-master' into development
2 parents fff0b91 + 57c2e9e commit c82795c

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

CONTRIBUTORS.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ Gery Vessere ([email protected])
3535
Cisco Systems
3636
Gergely Lukacsy (glukacsy)
3737

38+
Ocedo GmbH
39+
Henning Pfeiffer (megaposer)
40+
3841
thomasschaub
3942

4043
Trimble

Release/include/cpprest/http_client.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ class http_client_config
101101
, m_set_user_nativehandle_options([](native_handle)->void{})
102102
#if !defined(_WIN32) && !defined(__cplusplus_winrt)
103103
, m_ssl_context_callback([](boost::asio::ssl::context&)->void{})
104+
, m_tlsext_sni_enabled(true)
104105
#endif
105106
#if defined(_WIN32) && !defined(__cplusplus_winrt)
106107
, m_buffer_request(false)
@@ -347,6 +348,25 @@ class http_client_config
347348
{
348349
return m_ssl_context_callback;
349350
}
351+
352+
/// <summary>
353+
/// Gets the TLS extension server name indication (SNI) status.
354+
/// </summary>
355+
/// <returns>True if TLS server name indication is enabled, false otherwise.</returns>
356+
bool is_tlsext_sni_enabled() const
357+
{
358+
return m_tlsext_sni_enabled;
359+
}
360+
361+
/// <summary>
362+
/// Sets the TLS extension server name indication (SNI) status.
363+
/// </summary>
364+
/// <param name="tlsext_sni_enabled">False to disable the TLS (ClientHello) extension for server name indication, true otherwise.</param>
365+
/// <remarks>Note: This setting is enabled by default as it is required in most virtual hosting scenarios.</remarks>
366+
void set_tlsext_sni_enabled(bool tlsext_sni_enabled)
367+
{
368+
m_tlsext_sni_enabled = tlsext_sni_enabled;
369+
}
350370
#endif
351371

352372
private:
@@ -372,6 +392,7 @@ class http_client_config
372392

373393
#if !defined(_WIN32) && !defined(__cplusplus_winrt)
374394
std::function<void(boost::asio::ssl::context&)> m_ssl_context_callback;
395+
bool m_tlsext_sni_enabled;
375396
#endif
376397
#if defined(_WIN32) && !defined(__cplusplus_winrt)
377398
bool m_buffer_request;

Release/src/http/client/http_client_asio.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ class asio_connection
136136
template <typename HandshakeHandler, typename CertificateHandler>
137137
void async_handshake(boost::asio::ssl::stream_base::handshake_type type,
138138
const http_client_config &config,
139+
const utility::string_t &host_name,
139140
const HandshakeHandler &handshake_handler,
140141
const CertificateHandler &cert_handler)
141142
{
@@ -152,6 +153,13 @@ class asio_connection
152153
{
153154
m_ssl_stream->set_verify_mode(boost::asio::ssl::context::verify_none);
154155
}
156+
157+
// Check to set host name for Server Name Indication (SNI)
158+
if (config.is_tlsext_sni_enabled())
159+
{
160+
SSL_set_tlsext_host_name(m_ssl_stream->native_handle(), const_cast<char *>(host_name.data()));
161+
}
162+
155163
m_ssl_stream->async_handshake(type, handshake_handler);
156164
}
157165

@@ -561,6 +569,7 @@ class asio_context : public request_context, public std::enable_shared_from_this
561569
const auto weakCtx = std::weak_ptr<asio_context>(shared_from_this());
562570
m_connection->async_handshake(boost::asio::ssl::stream_base::client,
563571
m_http_client->client_config(),
572+
m_http_client->base_uri().host(),
564573
boost::bind(&asio_context::handle_handshake, shared_from_this(), boost::asio::placeholders::error),
565574

566575
// Use a weak_ptr since the verify_callback is stored until the connection is destroyed.

0 commit comments

Comments
 (0)