Skip to content

Commit daad374

Browse files
committed
merge from tfs to codeplex
1 parent 5bf7e65 commit daad374

File tree

13 files changed

+173
-48
lines changed

13 files changed

+173
-48
lines changed

Release/include/cpprest/http_client.h

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@ class http_client_config
127127
m_guarantee_order(false),
128128
m_timeout(utility::seconds(30)),
129129
m_chunksize(64 * 1024)
130+
#if !defined(__cplusplus_winrt)
131+
, m_validate_certificates(true)
132+
#endif
130133
{
131134
}
132135

@@ -203,7 +206,7 @@ class http_client_config
203206
}
204207

205208
/// <summary>
206-
/// Get the client chunk size
209+
/// Get the client chunk size.
207210
/// </summary>
208211
/// <returns>The internal buffer size used by the http client when sending and receiving data from the network.</returns>
209212
size_t chunksize() const
@@ -212,7 +215,7 @@ class http_client_config
212215
}
213216

214217
/// <summary>
215-
/// Get the client chunk size
218+
/// Sets the client chunk size.
216219
/// </summary>
217220
/// <param name="size">The internal buffer size used by the http client when sending and receiving data from the network.</param>
218221
/// <remarks>This is a hint -- an implementation may disregard the setting and use some other chunk size.</remarks>
@@ -221,11 +224,38 @@ class http_client_config
221224
m_chunksize = size;
222225
}
223226

227+
#if !defined(__cplusplus_winrt)
228+
/// <summary>
229+
/// Gets the server certificate validation property.
230+
/// </summary>
231+
/// <returns>True if certificates are to be verified, false otherwise.</returns>
232+
bool validate_certificates() const
233+
{
234+
return m_validate_certificates;
235+
}
236+
237+
/// <summary>
238+
/// Sets the server certificate validation property.
239+
/// </summary>
240+
/// <param name="validate_cert">False to turn ignore all server certificate validation errors, true otherwise.</param>
241+
/// <remarks>Note ignoring certificate errors can be dangerous and should be done with caution.</remarks>
242+
void set_validate_certificates(bool validate_certs)
243+
{
244+
m_validate_certificates = validate_certs;
245+
}
246+
#endif
247+
224248
private:
225249
web_proxy m_proxy;
226250
http::client::credentials m_credentials;
227251
// Whether or not to guarantee ordering, i.e. only using one underlying TCP connection.
228252
bool m_guarantee_order;
253+
254+
// IXmlHttpRequest2 doesn't allow configuration of certificate verification.
255+
#if !defined(__cplusplus_winrt)
256+
bool m_validate_certificates;
257+
#endif
258+
229259
utility::seconds m_timeout;
230260
size_t m_chunksize;
231261
};

Release/include/pplx/pplxcancellation_token.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,13 +320,13 @@ namespace details
320320
#pragma warning(push)
321321
#pragma warning(disable: 6001)
322322
auto node = _M_begin;
323-
#pragma warning(pop)
324323
while (node != nullptr)
325324
{
326325
Node* tmp = node;
327326
node = node->_M_next;
328327
::free(tmp);
329328
}
329+
#pragma warning(pop)
330330
}
331331

332332
void swap(TokenRegistrationContainer& list)

Release/setup/CasablancaSetup.wxs

Lines changed: 30 additions & 12 deletions
Large diffs are not rendered by default.

Release/src/build/casablanca110.xp.vcxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), build.root))\Build\version.props" />
44
<PropertyGroup Label="Globals">
5-
<ProjectGuid>{90D85FF4-F0AE-4816-923F-0EF2758F30AB}</ProjectGuid>
5+
<ProjectGuid>{4D9ED383-673B-4E48-A6AF-6BD9F108150E}</ProjectGuid>
66
<Keyword>Win32Proj</Keyword>
77
<RootNamespace>casablanca</RootNamespace>
88
<SccProjectName>SAK</SccProjectName>

Release/src/dirs.proj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
<ItemGroup Condition="'$(DevToolsVersion)'=='110'">
1010
<ProjectFile Include="build\casablanca110.vcxproj" Condition="'$(Platform)'!='ARM' or '$(WindowsSDKDesktopARMSupport)' == 'true'" />
11+
<ProjectFile Include="build\casablanca110.xp.vcxproj" Condition="'$(Platform)'!='ARM'" />
1112
</ItemGroup>
1213

1314
<ItemGroup Condition="'$(OsVersion)|$(DevToolsVersion)'=='6.2|110' or '$(OsVersion)|$(DevToolsVersion)'=='6.3|110'">

Release/src/http/client/http_linux.cpp

Lines changed: 43 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -169,20 +169,20 @@ namespace web { namespace http
169169

170170
struct client
171171
{
172-
client(boost::asio::io_service& io_service, size_t chunk_size)
172+
client(boost::asio::io_service& io_service, const http_client_config &config)
173173
: m_resolver(io_service)
174174
, m_io_service(io_service)
175-
, m_chunksize(chunk_size) {}
175+
, m_config(config) {}
176176

177-
void send_request(linux_request_context* ctx, int timeout)
177+
void send_request(linux_request_context* ctx)
178178
{
179179
auto what = ctx->m_what;
180180
auto resource = what.resource().to_string();
181181

182182
if (what.scheme() == "https")
183183
{
184184
boost::asio::ssl::context context(boost::asio::ssl::context::sslv23);
185-
context.set_verify_mode(boost::asio::ssl::context::verify_none);
185+
context.set_default_verify_paths();
186186
ctx->m_ssl_stream.reset(new boost::asio::ssl::stream<boost::asio::ip::tcp::socket>(m_io_service, context));
187187
}
188188
else
@@ -250,7 +250,9 @@ namespace web { namespace http
250250
tcp::resolver::query query(host, utility::conversions::print_string(port));
251251

252252
ctx->m_timer.reset(new boost::asio::deadline_timer(m_io_service));
253-
ctx->m_timer->expires_from_now(boost::posix_time::milliseconds(timeout));
253+
auto timeout = m_config.timeout();
254+
int secs = static_cast<int>(timeout.count());
255+
ctx->m_timer->expires_from_now(boost::posix_time::milliseconds(secs * 1000));
254256
ctx->m_timer->async_wait(boost::bind(&linux_request_context::cancel, ctx, boost::asio::placeholders::error));
255257

256258
m_resolver.async_resolve(query, boost::bind(&client::handle_resolve, this, boost::asio::placeholders::error, boost::asio::placeholders::iterator, ctx));
@@ -259,7 +261,7 @@ namespace web { namespace http
259261
private:
260262
boost::asio::io_service& m_io_service;
261263
tcp::resolver m_resolver;
262-
size_t m_chunksize;
264+
http_client_config m_config;
263265

264266
static bool _check_streambuf(linux_request_context * ctx, concurrency::streams::streambuf<uint8_t> rdbuf, const utility::char_t* msg)
265267
{
@@ -288,7 +290,20 @@ namespace web { namespace http
288290
{
289291
auto endpoint = *endpoints;
290292
if (ctx->m_ssl_stream)
293+
{
294+
// Check to turn off server certificate verification.
295+
if(m_config.validate_certificates())
296+
{
297+
ctx->m_ssl_stream->set_verify_mode(boost::asio::ssl::context::verify_peer);
298+
ctx->m_ssl_stream->set_verify_callback(boost::asio::ssl::rfc2818_verification(ctx->m_what.host()));
299+
}
300+
else
301+
{
302+
ctx->m_ssl_stream->set_verify_mode(boost::asio::ssl::context::verify_none);
303+
}
304+
291305
ctx->m_ssl_stream->lowest_layer().async_connect(endpoint, boost::bind(&client::handle_connect, this, boost::asio::placeholders::error, ++endpoints, ctx));
306+
}
292307
else
293308
ctx->m_socket->async_connect(endpoint, boost::bind(&client::handle_connect, this, boost::asio::placeholders::error, ++endpoints, ctx));
294309
}
@@ -316,8 +331,21 @@ namespace web { namespace http
316331
ctx->m_ssl_stream->lowest_layer().shutdown(tcp::socket::shutdown_both, ignore);
317332
ctx->m_ssl_stream->lowest_layer().close();
318333
boost::asio::ssl::context context(boost::asio::ssl::context::sslv23);
319-
context.set_verify_mode(boost::asio::ssl::context::verify_none);
334+
context.set_default_verify_paths();
320335
ctx->m_ssl_stream.reset(new boost::asio::ssl::stream<boost::asio::ip::tcp::socket>(m_io_service, context));
336+
337+
// Check to turn off server certificate verification.
338+
if(m_config.validate_certificates())
339+
{
340+
ctx->m_ssl_stream->set_verify_mode(boost::asio::ssl::context::verify_peer);
341+
ctx->m_ssl_stream->set_verify_callback(boost::asio::ssl::rfc2818_verification(ctx->m_what.host()));
342+
}
343+
else
344+
{
345+
ctx->m_ssl_stream->set_verify_mode(boost::asio::ssl::context::verify_none);
346+
}
347+
348+
321349
ctx->m_ssl_stream->lowest_layer().async_connect(endpoint, boost::bind(&client::handle_connect, this, boost::asio::placeholders::error, ++endpoints, ctx));
322350
}
323351
else
@@ -350,8 +378,8 @@ namespace web { namespace http
350378
}
351379

352380
auto readbuf = ctx->_get_readbuffer();
353-
uint8_t *buf = boost::asio::buffer_cast<uint8_t *>(ctx->m_request_buf.prepare(m_chunksize + http::details::chunked_encoding::additional_encoding_space));
354-
readbuf.getn(buf + http::details::chunked_encoding::data_offset, m_chunksize).then([=](pplx::task<size_t> op)
381+
uint8_t *buf = boost::asio::buffer_cast<uint8_t *>(ctx->m_request_buf.prepare(m_config.chunksize() + http::details::chunked_encoding::additional_encoding_space));
382+
readbuf.getn(buf + http::details::chunked_encoding::data_offset, m_config.chunksize()).then([=](pplx::task<size_t> op)
355383
{
356384
size_t readSize = 0;
357385
try { readSize = op.get(); }
@@ -360,7 +388,7 @@ namespace web { namespace http
360388
ctx->report_exception(std::current_exception());
361389
return;
362390
}
363-
size_t offset = http::details::chunked_encoding::add_chunked_delimiters(buf, m_chunksize+http::details::chunked_encoding::additional_encoding_space, readSize);
391+
size_t offset = http::details::chunked_encoding::add_chunked_delimiters(buf, m_config.chunksize() + http::details::chunked_encoding::additional_encoding_space, readSize);
364392
ctx->m_request_buf.commit(readSize + http::details::chunked_encoding::additional_encoding_space);
365393
ctx->m_request_buf.consume(offset);
366394
ctx->m_current_size += readSize;
@@ -388,7 +416,7 @@ namespace web { namespace http
388416
}
389417

390418
auto readbuf = ctx->_get_readbuffer();
391-
size_t readSize = std::min(m_chunksize, ctx->m_known_size - ctx->m_current_size);
419+
size_t readSize = std::min(m_config.chunksize(), ctx->m_known_size - ctx->m_current_size);
392420

393421
readbuf.getn(boost::asio::buffer_cast<uint8_t *>(ctx->m_request_buf.prepare(readSize)), readSize).then([=](pplx::task<size_t> op)
394422
{
@@ -529,7 +557,7 @@ namespace web { namespace http
529557
{
530558
ctx->m_current_size = 0;
531559
if (!ctx->m_needChunked)
532-
async_read_until_buffersize(std::min(ctx->m_known_size, m_chunksize),
560+
async_read_until_buffersize(std::min(ctx->m_known_size, m_config.chunksize()),
533561
boost::bind(&client::handle_read_content, this, boost::asio::placeholders::error, ctx), ctx);
534562
else
535563
{
@@ -675,7 +703,7 @@ namespace web { namespace http
675703
ctx->m_downloaded += (size64_t)writtenSize;
676704
ctx->m_current_size += writtenSize;
677705
ctx->m_response_buf.consume(writtenSize);
678-
async_read_until_buffersize(std::min(m_chunksize, ctx->m_known_size - ctx->m_current_size),
706+
async_read_until_buffersize(std::min(m_config.chunksize(), ctx->m_known_size - ctx->m_current_size),
679707
boost::bind(&client::handle_read_content, this, boost::asio::placeholders::error, ctx), ctx);
680708
}
681709
catch (...)
@@ -716,7 +744,7 @@ namespace web { namespace http
716744

717745
unsigned long open()
718746
{
719-
m_client.reset(new client(crossplat::threadpool::shared_instance().service(), client_config().chunksize()));
747+
m_client.reset(new client(crossplat::threadpool::shared_instance().service(), client_config()));
720748
return 0;
721749
}
722750

@@ -725,15 +753,9 @@ namespace web { namespace http
725753
auto linux_ctx = static_cast<linux_request_context*>(request_ctx);
726754

727755
auto encoded_resource = uri_builder(m_address).append(linux_ctx->m_request.relative_uri()).to_uri();
728-
729756
linux_ctx->m_what = encoded_resource;
730757

731-
auto& config = client_config();
732-
733-
auto timeout = config.timeout();
734-
int secs = static_cast<int>(timeout.count());
735-
736-
m_client->send_request(linux_ctx, secs * 1000);
758+
m_client->send_request(linux_ctx);
737759
}
738760
};
739761
} // namespace details

Release/src/http/client/http_win7.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -578,8 +578,27 @@ namespace web { namespace http
578578
}
579579
}
580580

581-
size_t content_length = msg._get_impl()->_get_content_length();
581+
// Check to turn off server certificate verification.
582+
if(!client_config().validate_certificates())
583+
{
584+
DWORD data = SECURITY_FLAG_IGNORE_UNKNOWN_CA
585+
| SECURITY_FLAG_IGNORE_CERT_DATE_INVALID
586+
| SECURITY_FLAG_IGNORE_CERT_CN_INVALID
587+
| SECURITY_FLAG_IGNORE_CERT_WRONG_USAGE;
588+
589+
auto result = WinHttpSetOption(
590+
winhttp_context->m_request_handle,
591+
WINHTTP_OPTION_SECURITY_FLAGS,
592+
&data,
593+
sizeof(data));
594+
if(!result)
595+
{
596+
request->report_error(U("Error setting WinHttp to ignore server certification validation errors."));
597+
return;
598+
}
599+
}
582600

601+
size_t content_length = msg._get_impl()->_get_content_length();
583602
if (content_length > 0)
584603
{
585604
if ( msg.method() == http::methods::GET || msg.method() == http::methods::HEAD )

Release/src/http/listener/http_windows_server.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ pplx::task<void> http_windows_server::start()
364364
}
365365

366366
// Create request queue.
367-
errorCode = HttpCreateRequestQueue(httpApiVersion, U("HttpReceiver"), NULL, NULL, &m_hRequestQueue);
367+
errorCode = HttpCreateRequestQueue(httpApiVersion, NULL, NULL, NULL, &m_hRequestQueue);
368368
if(errorCode)
369369
{
370370
return pplx::task_from_exception<void>(http_exception(errorCode));

Release/src/json/json.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ CharType get_unescaped_char(typename std::basic_string<CharType>::iterator & inp
286286
for (int i = 0; i < 4; i++)
287287
{
288288
CharType c = *(++inputIter);
289-
_ASSERTE(isxdigit(c));
289+
_ASSERTE(isxdigit((unsigned char)(c)));
290290
int val = _hexval[c];
291291
decoded |= (val << (4*(3-i)));
292292
}

Release/src/pplx/windows/pplxwin.cpp

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,23 @@ namespace details
7979
}
8080

8181
#endif // defined(__cplusplus_winrt)
82+
83+
void InitializeCriticalSection(LPCRITICAL_SECTION _cs)
84+
{
85+
#ifndef __cplusplus_winrt
86+
// InitializeCriticalSection can cause STATUS_NO_MEMORY see C28125
87+
__try {
88+
::InitializeCriticalSection(_cs);
89+
}
90+
__except(GetExceptionCode() == STATUS_NO_MEMORY ? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH)
91+
{
92+
throw ::std::bad_alloc();
93+
}
94+
#else
95+
InitializeCriticalSectionEx(_cs, 0, 0);
96+
#endif // !__cplusplus_winrt
97+
}
98+
8299
}
83100

84101
//
@@ -132,11 +149,7 @@ namespace details
132149
{
133150
static_assert(sizeof(CRITICAL_SECTION) <= sizeof(_M_impl), "CRITICAL_SECTION version mismatch");
134151

135-
#ifndef __cplusplus_winrt
136-
InitializeCriticalSection(reinterpret_cast<LPCRITICAL_SECTION>(&_M_impl));
137-
#else
138-
InitializeCriticalSectionEx(reinterpret_cast<LPCRITICAL_SECTION>(&_M_impl), 0, 0);
139-
#endif // !__cplusplus_winrt
152+
platform::InitializeCriticalSection(reinterpret_cast<LPCRITICAL_SECTION>(&_M_impl));
140153
}
141154

142155
_PPLXIMP critical_section_impl::~critical_section_impl()

0 commit comments

Comments
 (0)