Skip to content

Commit 3025d90

Browse files
committed
Merge branch 'development' of https://git01.codeplex.com/casablanca into 4gb_file_fix
2 parents 68e22be + bad74a2 commit 3025d90

File tree

3 files changed

+45
-62
lines changed

3 files changed

+45
-62
lines changed

Release/src/http/client/http_linux.cpp

Lines changed: 43 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,10 @@ namespace web { namespace http
282282
boost::asio::deadline_timer m_timeout_timer;
283283
std::shared_ptr<linux_connection> m_connection;
284284

285+
#if defined(__APPLE__) || defined(ANDROID)
286+
bool m_openssl_failed;
287+
#endif
288+
285289
virtual ~linux_client_request_context();
286290

287291
void handle_timeout_timer(const boost::system::error_code& ec)
@@ -334,9 +338,7 @@ namespace web { namespace http
334338

335339
if (m_uri.scheme() == "https")
336340
{
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));
341+
reset_ssl_stream(ctx);
340342
}
341343

342344
auto encoded_resource = uri_builder(m_uri).append(ctx->m_request.relative_uri()).to_uri().resource().to_string();
@@ -398,8 +400,6 @@ namespace web { namespace http
398400
else
399401
{
400402
has_body = false;
401-
extra_headers.append(header_names::content_length);
402-
extra_headers.append(":0" + CRLF);
403403
}
404404
}
405405

@@ -453,9 +453,6 @@ namespace web { namespace http
453453

454454
private:
455455
tcp::resolver m_resolver;
456-
#if defined(__APPLE__) || defined(ANDROID)
457-
bool m_openssl_failed;
458-
#endif
459456

460457
static bool _check_streambuf(std::shared_ptr<linux_client_request_context> ctx, concurrency::streams::streambuf<uint8_t> rdbuf, const utility::char_t* msg)
461458
{
@@ -474,6 +471,29 @@ namespace web { namespace http
474471
return rdbuf.is_open();
475472
}
476473

474+
// Helper function to create ssl stream and set verification options.
475+
void reset_ssl_stream(const std::shared_ptr<linux_client_request_context> &ctx)
476+
{
477+
boost::asio::ssl::context sslContext(boost::asio::ssl::context::sslv23);
478+
sslContext.set_default_verify_paths();
479+
sslContext.set_options(boost::asio::ssl::context::default_workarounds);
480+
ctx->m_ssl_stream.reset(new boost::asio::ssl::stream<boost::asio::ip::tcp::socket &>(ctx->m_connection->socket(), sslContext));
481+
482+
// Check to turn off server certificate verification.
483+
if (client_config().validate_certificates())
484+
{
485+
ctx->m_ssl_stream->set_verify_mode(boost::asio::ssl::context::verify_peer);
486+
ctx->m_ssl_stream->set_verify_callback(boost::bind(&linux_client::handle_cert_verification, shared_from_this(), _1, _2, ctx));
487+
#if defined(__APPLE__) || defined(ANDROID)
488+
ctx->m_openssl_failed = false;
489+
#endif
490+
}
491+
else
492+
{
493+
ctx->m_ssl_stream->set_verify_mode(boost::asio::ssl::context::verify_none);
494+
}
495+
}
496+
477497
void handle_resolve(const boost::system::error_code& ec, tcp::resolver::iterator endpoints, std::shared_ptr<linux_client_request_context> ctx)
478498
{
479499
if (ec)
@@ -483,22 +503,6 @@ namespace web { namespace http
483503
else
484504
{
485505
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-
}
502506
ctx->m_connection->socket().async_connect(endpoint, boost::bind(&linux_client::handle_connect, shared_from_this(), boost::asio::placeholders::error, ++endpoints, ctx));
503507
}
504508
}
@@ -515,7 +519,7 @@ namespace web { namespace http
515519
}
516520
}
517521

518-
void handle_connect(const boost::system::error_code& ec, tcp::resolver::iterator endpoints, std::shared_ptr<linux_client_request_context> ctx)
522+
void handle_connect(const boost::system::error_code& ec, tcp::resolver::iterator endpoints, const std::shared_ptr<linux_client_request_context> &ctx)
519523
{
520524
if (!ec)
521525
{
@@ -531,35 +535,21 @@ namespace web { namespace http
531535

532536
// Replace the connection. This causes old connection object to go out of scope.
533537
ctx->m_connection = m_pool.obtain();
534-
535-
auto endpoint = *endpoints;
538+
536539
if (ctx->m_ssl_stream)
537540
{
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-
}
541+
reset_ssl_stream(ctx);
555542
}
556-
543+
auto endpoint = *endpoints;
557544
ctx->m_connection->socket().async_connect(endpoint, boost::bind(&linux_client::handle_connect, shared_from_this(), boost::asio::placeholders::error, ++endpoints, ctx));
558545
}
559546
}
560547

561-
bool handle_cert_verification(bool preverified, boost::asio::ssl::verify_context &ctx)
548+
bool handle_cert_verification(bool preverified, boost::asio::ssl::verify_context &verifyCtx, const std::shared_ptr<linux_client_request_context> &requestCtx)
562549
{
550+
// Unreferenced parameter on some platforms.
551+
requestCtx;
552+
563553
// OpenSSL calls the verification callback once per certificate in the chain,
564554
// starting with the root CA certificate. The 'leaf', non-Certificate Authority (CA)
565555
// certificate, i.e. actual server certificate is at the '0' position in the
@@ -569,15 +559,15 @@ namespace web { namespace http
569559
#if defined(__APPLE__) || defined(ANDROID)
570560
if(!preverified)
571561
{
572-
m_openssl_failed = true;
562+
requestCtx->m_openssl_failed = true;
573563
}
574-
if(m_openssl_failed)
564+
if(requestCtx->m_openssl_failed)
575565
{
576566
// On OS X, iOS, and Android, OpenSSL doesn't have access to where the OS
577567
// stores keychains. If OpenSSL fails we will doing verification at the
578568
// end using the whole certificate chain so wait until the 'leaf' cert.
579569
// For now return true so OpenSSL continues down the certificate chain.
580-
X509_STORE_CTX *storeContext = ctx.native_handle();
570+
X509_STORE_CTX *storeContext = verifyCtx.native_handle();
581571
int currentDepth = X509_STORE_CTX_get_error_depth(storeContext);
582572
if(currentDepth != 0)
583573
{
@@ -621,7 +611,7 @@ namespace web { namespace http
621611
#endif
622612

623613
boost::asio::ssl::rfc2818_verification rfc2818(m_uri.host());
624-
return rfc2818(preverified, ctx);
614+
return rfc2818(preverified, verifyCtx);
625615
}
626616

627617
void handle_handshake(const boost::system::error_code& ec, std::shared_ptr<linux_client_request_context> ctx)
@@ -1184,6 +1174,9 @@ namespace web { namespace http
11841174
, m_timedout(false)
11851175
, m_timeout_timer(crossplat::threadpool::shared_instance().service())
11861176
, m_connection(std::move(connection))
1177+
#if defined(__APPLE__) || defined(ANDROID)
1178+
, m_openssl_failed(false)
1179+
#endif
11871180
{}
11881181

11891182
std::shared_ptr<request_context> linux_client_request_context::create_request_context(

Release/tests/Functional/http/client/connections_and_errors.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ TEST_FIXTURE(uri_address, cancel_while_uploading_data, "Ignore:Linux", "220", "I
328328

329329
// This test can't be implemented with our test server since it doesn't stream data so isn't avaliable on WinRT.
330330
#ifndef __cplusplus_winrt
331-
TEST_FIXTURE(uri_address, cancel_while_downloading_data)
331+
TEST_FIXTURE(uri_address, cancel_while_downloading_data, "Ignore:Apple", "220")
332332
{
333333
web::http::experimental::listener::http_listener listener(m_uri);
334334
listener.open().wait();

casablanca120.desktop.sln

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio 2013
4-
VisualStudioVersion = 12.0.30501.0
4+
VisualStudioVersion = 12.0.30723.0
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "casablanca120.xp", "Release\src\build\casablanca120.xp.vcxproj", "{15F3B200-1AED-4B57-AF37-B21CD67914B1}"
77
EndProject
@@ -50,8 +50,6 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SearchFile120", "Release\sa
5050
{1014C621-BC2D-4813-B8C1-6D83AD6F9249} = {1014C621-BC2D-4813-B8C1-6D83AD6F9249}
5151
EndProjectSection
5252
EndProject
53-
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "codeplex165", "..\codeplex165\codeplex165.vcxproj", "{70E24896-422E-4CB4-B671-94D33D60BA1A}"
54-
EndProject
5553
Global
5654
GlobalSection(SolutionConfigurationPlatforms) = preSolution
5755
Debug|ARM = Debug|ARM
@@ -154,14 +152,6 @@ Global
154152
{F03BEE03-BEFB-4B17-A774-D9C8246530D4}.Release|Win32.Build.0 = Release|Win32
155153
{F03BEE03-BEFB-4B17-A774-D9C8246530D4}.Release|x64.ActiveCfg = Release|x64
156154
{F03BEE03-BEFB-4B17-A774-D9C8246530D4}.Release|x64.Build.0 = Release|x64
157-
{70E24896-422E-4CB4-B671-94D33D60BA1A}.Debug|ARM.ActiveCfg = Debug|Win32
158-
{70E24896-422E-4CB4-B671-94D33D60BA1A}.Debug|Win32.ActiveCfg = Debug|Win32
159-
{70E24896-422E-4CB4-B671-94D33D60BA1A}.Debug|Win32.Build.0 = Debug|Win32
160-
{70E24896-422E-4CB4-B671-94D33D60BA1A}.Debug|x64.ActiveCfg = Debug|Win32
161-
{70E24896-422E-4CB4-B671-94D33D60BA1A}.Release|ARM.ActiveCfg = Release|Win32
162-
{70E24896-422E-4CB4-B671-94D33D60BA1A}.Release|Win32.ActiveCfg = Release|Win32
163-
{70E24896-422E-4CB4-B671-94D33D60BA1A}.Release|Win32.Build.0 = Release|Win32
164-
{70E24896-422E-4CB4-B671-94D33D60BA1A}.Release|x64.ActiveCfg = Release|Win32
165155
EndGlobalSection
166156
GlobalSection(SolutionProperties) = preSolution
167157
HideSolutionNode = FALSE

0 commit comments

Comments
 (0)