@@ -337,9 +337,7 @@ namespace web { namespace http
337
337
338
338
if (m_uri.scheme () == " https" )
339
339
{
340
- boost::asio::ssl::context context (boost::asio::ssl::context::sslv23);
341
- context.set_default_verify_paths ();
342
- ctx->m_ssl_stream .reset (new boost::asio::ssl::stream<boost::asio::ip::tcp::socket &>(ctx->m_connection ->socket (), context));
340
+ reset_ssl_stream (ctx);
343
341
}
344
342
345
343
auto encoded_resource = uri_builder (m_uri).append (ctx->m_request .relative_uri ()).to_uri ().resource ().to_string ();
@@ -475,6 +473,29 @@ namespace web { namespace http
475
473
return rdbuf.is_open ();
476
474
}
477
475
476
+ // Helper function to create ssl stream and set verification options.
477
+ void reset_ssl_stream (std::shared_ptr<linux_client_request_context> &ctx)
478
+ {
479
+ boost::asio::ssl::context sslContext (boost::asio::ssl::context::sslv23);
480
+ sslContext.set_default_verify_paths ();
481
+ sslContext.set_options (boost::asio::ssl::context::default_workarounds);
482
+ ctx->m_ssl_stream .reset (new boost::asio::ssl::stream<boost::asio::ip::tcp::socket &>(ctx->m_connection ->socket (), sslContext));
483
+
484
+ // Check to turn off server certificate verification.
485
+ if (client_config ().validate_certificates ())
486
+ {
487
+ ctx->m_ssl_stream ->set_verify_mode (boost::asio::ssl::context::verify_peer);
488
+ ctx->m_ssl_stream ->set_verify_callback (boost::bind (&linux_client::handle_cert_verification, shared_from_this (), _1, _2));
489
+ #if defined(__APPLE__) || defined(ANDROID)
490
+ m_openssl_failed = false ;
491
+ #endif
492
+ }
493
+ else
494
+ {
495
+ ctx->m_ssl_stream ->set_verify_mode (boost::asio::ssl::context::verify_none);
496
+ }
497
+ }
498
+
478
499
void handle_resolve (const boost::system::error_code& ec, tcp::resolver::iterator endpoints, std::shared_ptr<linux_client_request_context> ctx)
479
500
{
480
501
if (ec)
@@ -484,22 +505,6 @@ namespace web { namespace http
484
505
else
485
506
{
486
507
auto endpoint = *endpoints;
487
- if (ctx->m_ssl_stream )
488
- {
489
- // Check to turn off server certificate verification.
490
- if (client_config ().validate_certificates ())
491
- {
492
- ctx->m_ssl_stream ->set_verify_mode (boost::asio::ssl::context::verify_peer);
493
- ctx->m_ssl_stream ->set_verify_callback (boost::bind (&linux_client::handle_cert_verification, shared_from_this (), _1, _2));
494
- #if defined(__APPLE__) || defined(ANDROID)
495
- m_openssl_failed = false ;
496
- #endif
497
- }
498
- else
499
- {
500
- ctx->m_ssl_stream ->set_verify_mode (boost::asio::ssl::context::verify_none);
501
- }
502
- }
503
508
ctx->m_connection ->socket ().async_connect (endpoint, boost::bind (&linux_client::handle_connect, shared_from_this (), boost::asio::placeholders::error, ++endpoints, ctx));
504
509
}
505
510
}
@@ -532,29 +537,12 @@ namespace web { namespace http
532
537
533
538
// Replace the connection. This causes old connection object to go out of scope.
534
539
ctx->m_connection = m_pool.obtain ();
535
-
536
- auto endpoint = *endpoints;
540
+
537
541
if (ctx->m_ssl_stream )
538
542
{
539
- boost::asio::ssl::context context (boost::asio::ssl::context::sslv23);
540
- context.set_default_verify_paths ();
541
- ctx->m_ssl_stream .reset (new boost::asio::ssl::stream<boost::asio::ip::tcp::socket &>(ctx->m_connection ->socket (), context));
542
-
543
- // Check to turn off server certificate verification.
544
- if (client_config ().validate_certificates ())
545
- {
546
- ctx->m_ssl_stream ->set_verify_mode (boost::asio::ssl::context::verify_peer);
547
- ctx->m_ssl_stream ->set_verify_callback (boost::bind (&linux_client::handle_cert_verification, shared_from_this (), _1, _2));
548
- #if defined(__APPLE__) || defined(ANDROID)
549
- m_openssl_failed = false ;
550
- #endif
551
- }
552
- else
553
- {
554
- ctx->m_ssl_stream ->set_verify_mode (boost::asio::ssl::context::verify_none);
555
- }
543
+ reset_ssl_stream (ctx);
556
544
}
557
-
545
+ auto endpoint = *endpoints;
558
546
ctx->m_connection ->socket ().async_connect (endpoint, boost::bind (&linux_client::handle_connect, shared_from_this (), boost::asio::placeholders::error, ++endpoints, ctx));
559
547
}
560
548
}
0 commit comments