@@ -334,9 +334,7 @@ namespace web { namespace http
334
334
335
335
if (m_uri.scheme () == " https" )
336
336
{
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);
340
338
}
341
339
342
340
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
474
472
return rdbuf.is_open ();
475
473
}
476
474
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
+
477
498
void handle_resolve (const boost::system::error_code& ec, tcp::resolver::iterator endpoints, std::shared_ptr<linux_client_request_context> ctx)
478
499
{
479
500
if (ec)
@@ -483,22 +504,6 @@ namespace web { namespace http
483
504
else
484
505
{
485
506
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
- }
502
507
ctx->m_connection ->socket ().async_connect (endpoint, boost::bind (&linux_client::handle_connect, shared_from_this (), boost::asio::placeholders::error, ++endpoints, ctx));
503
508
}
504
509
}
@@ -531,29 +536,12 @@ namespace web { namespace http
531
536
532
537
// Replace the connection. This causes old connection object to go out of scope.
533
538
ctx->m_connection = m_pool.obtain ();
534
-
535
- auto endpoint = *endpoints;
539
+
536
540
if (ctx->m_ssl_stream )
537
541
{
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);
555
543
}
556
-
544
+ auto endpoint = *endpoints;
557
545
ctx->m_connection ->socket ().async_connect (endpoint, boost::bind (&linux_client::handle_connect, shared_from_this (), boost::asio::placeholders::error, ++endpoints, ctx));
558
546
}
559
547
}
0 commit comments