Skip to content

Commit c9b857b

Browse files
committed
Adding Boost's default_workarounds option for somewhat broken servers.
1 parent 5a09eb6 commit c9b857b

File tree

1 file changed

+27
-39
lines changed

1 file changed

+27
-39
lines changed

Release/src/http/client/http_linux.cpp

Lines changed: 27 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -334,9 +334,7 @@ namespace web { namespace http
334334

335335
if (m_uri.scheme() == "https")
336336
{
337-
boost::asio::ssl::context context(boost::asio::ssl::context::sslv23);
338-
context.set_default_verify_paths();
339-
ctx->m_ssl_stream.reset(new boost::asio::ssl::stream<boost::asio::ip::tcp::socket &>(ctx->m_connection->socket(), context));
337+
reset_ssl_stream(ctx);
340338
}
341339

342340
auto encoded_resource = uri_builder(m_uri).append(ctx->m_request.relative_uri()).to_uri().resource().to_string();
@@ -474,6 +472,29 @@ namespace web { namespace http
474472
return rdbuf.is_open();
475473
}
476474

475+
// Helper function to create ssl stream and set verification options.
476+
void reset_ssl_stream(std::shared_ptr<linux_client_request_context> &ctx)
477+
{
478+
boost::asio::ssl::context sslContext(boost::asio::ssl::context::sslv23);
479+
sslContext.set_default_verify_paths();
480+
sslContext.set_options(boost::asio::ssl::context::default_workarounds);
481+
ctx->m_ssl_stream.reset(new boost::asio::ssl::stream<boost::asio::ip::tcp::socket &>(ctx->m_connection->socket(), sslContext));
482+
483+
// Check to turn off server certificate verification.
484+
if (client_config().validate_certificates())
485+
{
486+
ctx->m_ssl_stream->set_verify_mode(boost::asio::ssl::context::verify_peer);
487+
ctx->m_ssl_stream->set_verify_callback(boost::bind(&linux_client::handle_cert_verification, shared_from_this(), _1, _2));
488+
#if defined(__APPLE__) || defined(ANDROID)
489+
m_openssl_failed = false;
490+
#endif
491+
}
492+
else
493+
{
494+
ctx->m_ssl_stream->set_verify_mode(boost::asio::ssl::context::verify_none);
495+
}
496+
}
497+
477498
void handle_resolve(const boost::system::error_code& ec, tcp::resolver::iterator endpoints, std::shared_ptr<linux_client_request_context> ctx)
478499
{
479500
if (ec)
@@ -483,22 +504,6 @@ namespace web { namespace http
483504
else
484505
{
485506
auto endpoint = *endpoints;
486-
if (ctx->m_ssl_stream)
487-
{
488-
// Check to turn off server certificate verification.
489-
if(client_config().validate_certificates())
490-
{
491-
ctx->m_ssl_stream->set_verify_mode(boost::asio::ssl::context::verify_peer);
492-
ctx->m_ssl_stream->set_verify_callback(boost::bind(&linux_client::handle_cert_verification, shared_from_this(), _1, _2));
493-
#if defined(__APPLE__) || defined(ANDROID)
494-
m_openssl_failed = false;
495-
#endif
496-
}
497-
else
498-
{
499-
ctx->m_ssl_stream->set_verify_mode(boost::asio::ssl::context::verify_none);
500-
}
501-
}
502507
ctx->m_connection->socket().async_connect(endpoint, boost::bind(&linux_client::handle_connect, shared_from_this(), boost::asio::placeholders::error, ++endpoints, ctx));
503508
}
504509
}
@@ -531,29 +536,12 @@ namespace web { namespace http
531536

532537
// Replace the connection. This causes old connection object to go out of scope.
533538
ctx->m_connection = m_pool.obtain();
534-
535-
auto endpoint = *endpoints;
539+
536540
if (ctx->m_ssl_stream)
537541
{
538-
boost::asio::ssl::context context(boost::asio::ssl::context::sslv23);
539-
context.set_default_verify_paths();
540-
ctx->m_ssl_stream.reset(new boost::asio::ssl::stream<boost::asio::ip::tcp::socket &>(ctx->m_connection->socket(), context));
541-
542-
// Check to turn off server certificate verification.
543-
if(client_config().validate_certificates())
544-
{
545-
ctx->m_ssl_stream->set_verify_mode(boost::asio::ssl::context::verify_peer);
546-
ctx->m_ssl_stream->set_verify_callback(boost::bind(&linux_client::handle_cert_verification, shared_from_this(), _1, _2));
547-
#if defined(__APPLE__) || defined(ANDROID)
548-
m_openssl_failed = false;
549-
#endif
550-
}
551-
else
552-
{
553-
ctx->m_ssl_stream->set_verify_mode(boost::asio::ssl::context::verify_none);
554-
}
542+
reset_ssl_stream(ctx);
555543
}
556-
544+
auto endpoint = *endpoints;
557545
ctx->m_connection->socket().async_connect(endpoint, boost::bind(&linux_client::handle_connect, shared_from_this(), boost::asio::placeholders::error, ++endpoints, ctx));
558546
}
559547
}

0 commit comments

Comments
 (0)