Quantcast
Channel: WE MOVED to github.com/microsoft/cpprestsdk. This site is not monitored!
Viewing all 4845 articles
Browse latest View live

New Post: Conflict between Cacablanca headers and Boost Math

$
0
0
I've managed to narrow down a conflict between these because of the fact that Casablanca defines the "U" macro. Trying to compile a project where both headers are included will generate compile errors in the boost headers.

Using a define to ensure Casablanca does not define this causes the compile errors to go away. I'm still using 2.4, and don't really want to upgrade right now, but I figure it still applies to the latest version. This is unfortunate and really problematic since the errors generated will typically be nonsensical due to macro involvement.

I'm just reporting this in case you don't know. I'd argue that the "U" macro should be disabled by default, but of course the decision on how to use this information goes to you guys.

Thanks again for an incredibly useful library.

New Post: Conflict between Cacablanca headers and Boost Math

$
0
0
Hi Essentia,

Yes I agree the 'U' macro isn't great, but I don't it is going to be removed or default off anytime soon. It currently still does exist in the latest version, but thank you for the feedback.

I know you've discovered the option on how to turn it off, but just so others know if you define the macro _TURN_OFF_PLATFORM_STRING the 'U' macro will not be defined.

Steve

Updated Release: C++ REST SDK 2.7.0

$
0
0
websockets
  • Merged pull request allowing through CMake to use an external version of Websocket++. #294

miscellaneous
  • Fixed issue with utf16toutf8 utility function when encoding certain surrogate pairs. #392
  • Merged a couple of pull requests (here, here, and here) fixing several issues with arm64. #312, #291
  • Merged pull request fixing double include issues when building with CMake.
  • Merged pull request fixing cast issue on FreeBSD.

Windows
  • Removed some unnecessary _MSC_VER macro checks as Visual Studio 2012 is no longer supported.
  • Fixed several incorrect assumptions of thread safe function local static initialization with Visual Studio 2013. #391

Updated Release: C++ REST SDK 2.7.0

$
0
0
websockets
  • Merged pull request allowing through CMake to use an external version of Websocket++. #294

miscellaneous
  • Fixed issue with utf16_to_utf8 utility function when encoding certain surrogate pairs. #392
  • Merged a couple of pull requests (here, here, and here) fixing several issues with arm64. #312, #291
  • Merged pull request fixing double include issues when building with CMake.
  • Merged pull request fixing cast issue on FreeBSD.

Windows
  • Removed some unnecessary _MSC_VER macro checks as Visual Studio 2012 is no longer supported.
  • Fixed several incorrect assumptions of thread safe function local static initialization with Visual Studio 2013. #391

New Post: Regarding Security on http_listener

$
0
0
HI Steve,

Can you name the athentication protocols libraries. I am struggling to find code for that.

-Ram

Edited Issue: Round tripping utf conversion fails for some surrogate pairs [392]

$
0
0
Round tripping utf conversions fails for some surrogate pairs (below test). Starting with 0xD840, 0xDC00 which returns 0xD800, 0xDC00 after the converstions back and forth. Using version 2.6 on Windows. The test passed through on version 2.3

```
#include "stdafx.h"
#include "CppUnitTest.h"
#include <cpprest/json.h>

using namespace Microsoft::VisualStudio::CppUnitTestFramework;

namespace UnitTest
{
TEST_CLASS(UtfConversionTest)
{
void IsConvertedCharacterEqualToOriginal(const std::wstring& original)
{
using namespace utility::conversions;
const auto converted = to_utf16string(to_utf8string(original));
Assert::IsTrue(original == converted);
}
public:

TEST_METHOD(UtfConversionExhaustiveTest)
{
// This test is crude -- it covers all potential Unicode code points,
// without regard to semantics, if they are even defined, or anything.
for (wchar_t c = 1; c < 0xd800u; ++c)
{
IsConvertedCharacterEqualToOriginal(std::wstring(1, c));
}
for (wchar_t c = 0xe000u; c < 0xfffeu; ++c)
{
IsConvertedCharacterEqualToOriginal(std::wstring(1, c));
}
// surrogate pairs
for (wchar_t highSurrogate = 0xd800; highSurrogate <= 0xdbff; ++highSurrogate)
{
for (wchar_t lowSurrogate = 0xdc00; lowSurrogate <= 0xdfff; ++lowSurrogate)
{
std::wstring c;
c.push_back(highSurrogate);
c.push_back(lowSurrogate);
IsConvertedCharacterEqualToOriginal(c);
}
}
}
};
}
```

Commented Issue: Round tripping utf conversion fails for some surrogate pairs [392]

$
0
0
Round tripping utf conversions fails for some surrogate pairs (below test). Starting with 0xD840, 0xDC00 which returns 0xD800, 0xDC00 after the converstions back and forth. Using version 2.6 on Windows. The test passed through on version 2.3

```
#include "stdafx.h"
#include "CppUnitTest.h"
#include <cpprest/json.h>

using namespace Microsoft::VisualStudio::CppUnitTestFramework;

namespace UnitTest
{
TEST_CLASS(UtfConversionTest)
{
void IsConvertedCharacterEqualToOriginal(const std::wstring& original)
{
using namespace utility::conversions;
const auto converted = to_utf16string(to_utf8string(original));
Assert::IsTrue(original == converted);
}
public:

TEST_METHOD(UtfConversionExhaustiveTest)
{
// This test is crude -- it covers all potential Unicode code points,
// without regard to semantics, if they are even defined, or anything.
for (wchar_t c = 1; c < 0xd800u; ++c)
{
IsConvertedCharacterEqualToOriginal(std::wstring(1, c));
}
for (wchar_t c = 0xe000u; c < 0xfffeu; ++c)
{
IsConvertedCharacterEqualToOriginal(std::wstring(1, c));
}
// surrogate pairs
for (wchar_t highSurrogate = 0xd800; highSurrogate <= 0xdbff; ++highSurrogate)
{
for (wchar_t lowSurrogate = 0xdc00; lowSurrogate <= 0xdfff; ++lowSurrogate)
{
std::wstring c;
c.push_back(highSurrogate);
c.push_back(lowSurrogate);
IsConvertedCharacterEqualToOriginal(c);
}
}
}
};
}
```
Comments: Hi MarkkuM, Yes you are absolutely correct there is a bad bug here. Looking back in the utf16_to_utf8 method during the code review process an addition was replaced with a bitwise OR, in asyncrt_utils.cpp at line 390: ... // To get from surrogate pair to Unicode code point: // - subract 0xD800 from high surrogate, this forms top ten bits // - subract 0xDC00 from low surrogate, this forms low ten bits // - add 0x10000 // Leaves a code point in U+10000 to U+10FFFF range. uint32_t codePoint = highSurrogate - H_SURROGATE_START; codePoint <<= 10; codePoint |= lowSurrogate - L_SURROGATE_START; codePoint |= SURROGATE_PAIR_START; // HERE IS THE BUG ... Thanks for reporting the issue, I'll have a fix out shortly as it is only a one character change. Steve

Commented Issue: Round tripping utf conversion fails for some surrogate pairs [392]

$
0
0
Round tripping utf conversions fails for some surrogate pairs (below test). Starting with 0xD840, 0xDC00 which returns 0xD800, 0xDC00 after the converstions back and forth. Using version 2.6 on Windows. The test passed through on version 2.3

```
#include "stdafx.h"
#include "CppUnitTest.h"
#include <cpprest/json.h>

using namespace Microsoft::VisualStudio::CppUnitTestFramework;

namespace UnitTest
{
TEST_CLASS(UtfConversionTest)
{
void IsConvertedCharacterEqualToOriginal(const std::wstring& original)
{
using namespace utility::conversions;
const auto converted = to_utf16string(to_utf8string(original));
Assert::IsTrue(original == converted);
}
public:

TEST_METHOD(UtfConversionExhaustiveTest)
{
// This test is crude -- it covers all potential Unicode code points,
// without regard to semantics, if they are even defined, or anything.
for (wchar_t c = 1; c < 0xd800u; ++c)
{
IsConvertedCharacterEqualToOriginal(std::wstring(1, c));
}
for (wchar_t c = 0xe000u; c < 0xfffeu; ++c)
{
IsConvertedCharacterEqualToOriginal(std::wstring(1, c));
}
// surrogate pairs
for (wchar_t highSurrogate = 0xd800; highSurrogate <= 0xdbff; ++highSurrogate)
{
for (wchar_t lowSurrogate = 0xdc00; lowSurrogate <= 0xdfff; ++lowSurrogate)
{
std::wstring c;
c.push_back(highSurrogate);
c.push_back(lowSurrogate);
IsConvertedCharacterEqualToOriginal(c);
}
}
}
};
}
```
Comments: A fix has been added in the development branch. Thanks for reporting the issue, will be release 2.7.0. Steve

Closed Issue: Round tripping utf conversion fails for some surrogate pairs [392]

$
0
0
Round tripping utf conversions fails for some surrogate pairs (below test). Starting with 0xD840, 0xDC00 which returns 0xD800, 0xDC00 after the converstions back and forth. Using version 2.6 on Windows. The test passed through on version 2.3

```
#include "stdafx.h"
#include "CppUnitTest.h"
#include <cpprest/json.h>

using namespace Microsoft::VisualStudio::CppUnitTestFramework;

namespace UnitTest
{
TEST_CLASS(UtfConversionTest)
{
void IsConvertedCharacterEqualToOriginal(const std::wstring& original)
{
using namespace utility::conversions;
const auto converted = to_utf16string(to_utf8string(original));
Assert::IsTrue(original == converted);
}
public:

TEST_METHOD(UtfConversionExhaustiveTest)
{
// This test is crude -- it covers all potential Unicode code points,
// without regard to semantics, if they are even defined, or anything.
for (wchar_t c = 1; c < 0xd800u; ++c)
{
IsConvertedCharacterEqualToOriginal(std::wstring(1, c));
}
for (wchar_t c = 0xe000u; c < 0xfffeu; ++c)
{
IsConvertedCharacterEqualToOriginal(std::wstring(1, c));
}
// surrogate pairs
for (wchar_t highSurrogate = 0xd800; highSurrogate <= 0xdbff; ++highSurrogate)
{
for (wchar_t lowSurrogate = 0xdc00; lowSurrogate <= 0xdfff; ++lowSurrogate)
{
std::wstring c;
c.push_back(highSurrogate);
c.push_back(lowSurrogate);
IsConvertedCharacterEqualToOriginal(c);
}
}
}
};
}
```

Created Unassigned: test failures with websocketpp 0.6.0 [393]

$
0
0
as in the title,

/casablanca/Release/tests/functional/websockets/client/authentication_tests.cpp:181: error: Failure in disable_sni: Unhandled exception: set_fail_handler: 20: Invalid HTTP status. FAILED
Test case authentication_tests:disable_sni FAILED

do you have any clue?
thanks!

Commented Unassigned: test failures with websocketpp 0.6.0 [393]

$
0
0
as in the title,

/casablanca/Release/tests/functional/websockets/client/authentication_tests.cpp:181: error: Failure in disable_sni: Unhandled exception: set_fail_handler: 20: Invalid HTTP status. FAILED
Test case authentication_tests:disable_sni FAILED

do you have any clue?
thanks!
Comments: Hi LocutusOfBorg, No I'm not sure what this issue is. SNI support was added semi-recently, back in March to our library. The title mentions test failures, is this the only websocket test failure you are seeing? Thanks, Steve

Commented Unassigned: test failures with websocketpp 0.6.0 [393]

$
0
0
as in the title,

/casablanca/Release/tests/functional/websockets/client/authentication_tests.cpp:181: error: Failure in disable_sni: Unhandled exception: set_fail_handler: 20: Invalid HTTP status. FAILED
Test case authentication_tests:disable_sni FAILED

do you have any clue?
thanks!
Comments: yes, I get the build complete correctly and the above testsuite failure with the new websocketpp it is the only one.

Edited Issue: websocket client test disable_sni fails with websocketpp 0.6.0 [393]

$
0
0
as in the title,

/casablanca/Release/tests/functional/websockets/client/authentication_tests.cpp:181: error: Failure in disable_sni: Unhandled exception: set_fail_handler: 20: Invalid HTTP status. FAILED
Test case authentication_tests:disable_sni FAILED

do you have any clue?
thanks!

Edited Issue: websocket client test disable_sni fails with websocketpp 0.6.0 [393]

$
0
0
as in the title,

/casablanca/Release/tests/functional/websockets/client/authentication_tests.cpp:181: error: Failure in disable_sni: Unhandled exception: set_fail_handler: 20: Invalid HTTP status. FAILED
Test case authentication_tests:disable_sni FAILED

do you have any clue?
thanks!

New Post: Validating a digitally signed JSon Web Token with a public key

$
0
0
I have a digitally signed JSon Compact-serialized string produced by Microsoft's .NET
JSON Web Token Handler
https://msdn.microsoft.com/en-us/library/dn205065(v=vs.110).aspx

Is there a way with the C++ REST SDK to convert this to a web::json::value instance and also validate the digital signature?

Here is an example string:
eyJ0eXAiOiJKV1QiLCJhbGciOiJodHRwOi8vd3d3LnczLm9yZy8yMDAwLzA5L3htbGRzaWcjcnNhLXNoYTEifQ.eyJ1bmlxdWVfbmFtZSI6ImJvYlRoZUJ1aWxkZXIiLCJyb2xlIjoiQ3VzdG9tUm9sZU9mQXdlc29tZW5lc3MiLCJpc3MiOiJodHRwczovL3Rlc3QubmRpLm51YW5jZS5jb20vP2Zvbz1iYXIiLCJhdWQiOiJodHRwczovL3d3dy5udWFuY2UuY29tLyIsImV4cCI6MTQzNDczMTQ5NiwibmJmIjoxNDM0NjQ1MDk2fQ.DMe2Xvh6Zv2KrJC7iitnSadqBm-2vLmYP_KPxVmyMD_Pg_VJR37J4wKNHUKduYz3ENyMRFm42q1qI3tr8iDWJS2uATtEeSUTiirz-hnF_nopvBx3fQM3xvojAt5tLpZQq227pEu_BD2_i9VNnlg2yBygIn2yPKFOseJrI7509OV5kTFFqpmPXkTe9o2rAX1WGnEPhKtmuLxkmS46u-el94zkr1usqnQquSY7LSL6qpjO0BXSFuY7_xpxuigGn-6vGo9QWx2pVg6nIQZRY4Zkj071gPWeeugw9p-JzWSfdw9At1AgUbso6n2jkeHDEwpbEeoLg7X94T4jjZdfAmAymg

Here is the public key that can validate the token's integrity (this is a temp certificate for testing):
30 82 01 0a 02 82 01 01 00 e5 69 ab d7 0f 8a 3c b6 f5 22 ea 5d b3 94 c9 ec 5f 78 61 b8 40 d3 27 aa 68 5a 5a 3d db 30 ff 5d 70 41 d7 1c 5f 47 9c d6 52 55 3b e3 50 d7 03 fe c9 ff 9e 62 2b 8c 29 75 3e ff 24 08 8a 90 12 e8 46 8a 16 31 ce 4f c3 43 10 e0 1e 3d 3a 2e df 0e a7 73 dc e9 76 b7 d9 cc 43 02 d4 bf 4a 85 e1 48 7a e8 40 9e ca 0e 34 1b 10 39 ed 65 5c 6c d2 8f 81 d6 75 a9 ec 07 e5 da 1e d9 96 40 1c 5d 0c 38 8a ec dc df 10 49 83 21 e2 a5 18 16 81 3b b8 de 82 d9 a5 7a 8b 0b 93 a6 77 5a bf 64 46 93 e0 03 5a 5c b6 b2 6a 41 ef 1f 8a 11 bb f3 bf a6 0b 77 8a 3b a3 66 b4 4b 76 a2 ce fe bc 2e 8c 07 09 f2 9e 70 e6 16 34 02 9b a9 98 ab 00 82 05 75 d6 57 7c 35 fe e4 a6 ab a3 2e 3f 06 41 9b fa 16 21 e3 a9 74 3d b7 02 01 05 46 84 a3 23 3a 55 28 f8 0c 25 ac 0c 04 4c 71 16 7b 19 93 64 39 3b 60 28 fb 02 03 01 00 01

Thanks!

New Post: Validating a digitally signed JSon Web Token with a public key

$
0
0
Ok, so I am on the path to self enlightenment via reading the RFCs
http://tools.ietf.org/html/draft-ietf-oauth-json-web-token-07
http://tools.ietf.org/html/draft-ietf-oauth-json-web-token-07#ref-JWS

So each piece of the token (header, payload, signature) is part of the example string, delimited by a '.' character so we get three distinct packages

eyJ0eXAiOiJKV1QiLCJhbGciOiJodHRwOi8vd3d3LnczLm9yZy8yMDAwLzA5L3htbGRzaWcjcnNhLXNoYTEifQ
base64 decoded into
{"typ":"JWT","alg":"http://www.w3.org/2000/09/xmldsig#rsa-sha1"}

eyJ1bmlxdWVfbmFtZSI6ImJvYlRoZUJ1aWxkZXIiLCJyb2xlIjoiQ3VzdG9tUm9sZU9mQXdlc29tZW5lc3MiLCJpc3MiOiJodHRwczovL3Rlc3QubmRpLm51YW5jZS5jb20vP2Zvbz1iYXIiLCJhdWQiOiJodHRwczovL3d3dy5udWFuY2UuY29tLyIsImV4cCI6MTQzNDczMTQ5NiwibmJmIjoxNDM0NjQ1MDk2fQ
base64 decoded into
{"unique_name":"bobTheBuilder","role":"CustomRoleOfAwesomeness","iss":"https://test.ndi.nuance.com/?foo=bar","aud":"https://www.nuance.com/","exp":1434731496,"nbf":1434645096}

And the last piece is simply the digital signature of the first two pieces in PKCS1.5 format (according to the RFC that is). My next step will be to create the hash of the first two pieces and try to reproduce the signature with the private key (that I have on me).

New Post: Validating a digitally signed JSon Web Token with a public key

$
0
0
Hi stunney,

No we don't have any APIs that directly will take care of this. You can manually do this yourself, as you've started. We have some utilities for base64 encoding/decoding that might be helpful under the utility::conversions namespace, for example from_base64(...).

Steve

New Post: Validating a digitally signed JSon Web Token with a public key

$
0
0
Hello Steve and thank you! Found an annoying thing with from_base64. One must right-pad the string to make the length evenly divisible by 4.

std::string base64Decode(const std::wstring& encoded)
{
try
{
    std::wstring toPossiblyPad(encoded); //copy!
    toPossiblyPad += std::wstring(toPossiblyPad.length() % 4, L'=');        
    std::vector<unsigned char> decoded = utility::conversions::from_base64(toPossiblyPad.c_str());
    std::string strDecoded(decoded.begin(), decoded.end());
    return strDecoded;
}
catch (std::exception ex)
{
    //TODO!
}
catch (...)
{
            //TODO!
}
}

New Post: .then() / .wait() on task tree?

$
0
0
I have a function pplx::task<void> Authorize() that calls a REST API, then parses the response afterwards when the extract_json() task completes.

If I return the first client.request() task from inside Authorize(), then call Authorize().then([]{}); the lambda will be executed before the result is processed by the inner most task in Authorize().

Is there a pattern I can use to execute my lambda only when all the nested tasks are complete? How should cases like this be handled?

Updated Wiki: Use on Android

$
0
0

How to use the C++ REST SDK on Android (2.3+)

The easiest way to use the C++ REST SDK on android is to add the "C++ REST SDK - Android" NuGet package available via Visual Studio 2015 (including the free Community Edition). Go to Using NuGet to add the C++ REST SDK to a VS project for general information about adding NuGet packages.

After adding the package, you will need to enable exceptions, rtti, c++11, and the GNU standard library (gnustl_static). These options are all found under Configuration Properties as follows:
  • General -> Use of STL = gnustl_static
  • C++ -> Code Generation -> Enable C++ Exceptions = Unwind Tables (-funwind-tables)
  • C++ -> Language -> Enable Run-Time Type Information = Yes
  • C++ -> Language -> C++ Language Standard = C++11

Finally, you will need to add some small initialization code detailed under StaticLinking. In addition to the instructions mentioned here, you can get a walkthrough with a simple sample application from this blog post.

Non-NuGet

First, follow the steps here: Setup and Build on Android

You will need to link against the following from your project:
  • build.armv7.debug/Binaries/libcpprest.a
  • Boost-for-Android/build/lib/libboost_*-clang-mt-1_55.a
  • libiconv/armeabi-v7a/lib/libiconv.a (removed in version 2.6.0)
  • openssl/armeabi-v7a/lib/libssl.a
  • openssl/armeabi-v7a/lib/libcrypto.a
  • libm (math library, link with -lm)
  • liblog (logging library, link with -llog)

You will also need to include the headers for boost and the C++ REST SDK:
  • ../../Release/include
  • Boost-for-Android/build/include/boost-1_55

Use the included documentation with your NDK to add these prebuilt libraries and include paths. An outdated version of the relevant documentation is hosted at http://www.kandroid.org/ndk/docs/PREBUILTS.html.

Static Linking and Initialization

The C++ REST SDK prefers static linking for Android since version 2.3. This makes it much simpler for both Native Activities and Java-based Activities since there is only one shared object file in the final app bundle.

However, in order to prevent conflicts with other code, you must provide a pointer to the JVM to the SDK before it can initialize. This pointer is provided through the method cpprest_init(vm) which is located in the pplx/pplxtasks.h header file.

Note: If you do not do this, your application will terminate upon attempting to create a task.

Native Activity (android_main)

For most NativeActivity projects, if you have an entry point like
void android_main(struct android_app* state) {

You can add the following code at the top of the android_main function:
    cpprest_init(state->activity->vm);

Other Shared Libraries (JNI_OnLoad)

For most shared library projects, you will simply need to copy the following code into your main cpp file:
extern "C" jint JNI_OnLoad(JavaVM* vm, void* reserved)
{
    JNIEnv* env;
    if (vm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6) != JNI_OK)
    {
        return -1;
    }

    cpprest_init(vm);
    return JNI_VERSION_1_6;
}

Viewing all 4845 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>