get http_exception while access to https site in mac os x

Jul 16, 2014 at 6:00 PM
I am getting http_exception while trying to access https site in mac os x. The same piece of code works perfect in windows environment.

exception:
libc++abi.dylib: terminating with uncaught exception of type web::http::http_exception: Error code in handle_handshake is
utility::string_t token;
utility::string_t str = server.userName + U(":") + server.passWord;
std::vector<unsigned char> vec(str.begin(), str.end());
auto authCode = conversions::to_base64(vec);

http_client client(conversions::to_string_t(server.serverName).append(server.serverPath));
http_request request(methods::GET);
request.headers().add(U("consumer-key"), conversions::to_string_t(server.consumerKey));
request.headers().add(U("Authorization"), U("Basic " + authCode));

http_response response = client.request(request).get();

if (response.status_code() == status_codes::OK)
{
    http_headers headers = response.headers();
    auto it = headers.find(U("ssosession"));
    token = it->second;
}
Coordinator
Jul 24, 2014 at 10:24 PM
Hi Zhong,

Did you install OpenSSL via Homebrew? OSX has an issue with certificate authorities and OpenSSL, which the homebrew installation fixes.

If you have installed via homebrew, then could you put a try-catch block around your code and give me more details about which exception is being caught? Alternatively, if you're using an IDE, compile Casablanca with symbols and find which line the exception comes from.

Sincerely,
roschuma
Aug 5, 2014 at 5:10 PM
Edited Aug 5, 2014 at 5:23 PM
roschuma, thanks for your reply. I am using Homebrew. I will add try-catch block and recompile casablanca.
Aug 5, 2014 at 6:33 PM
here is what i got:

e web::http::http_exception & 0x0000000102f4bf98 0x0000000102f4bf98
m_msg std::__1::string "Error code in handle_handshake is "
m_errorCode std::__1::error_code
_val int 60 60
_cat const std::__1::error_category * 0x7fff7324df48 0x00007fff7324df48
Aug 21, 2014 at 5:19 PM
Hi roschuma,

just returned back to work on this mac project. i had a different version of openssl installed in my mac which was installed by macport. after i took over this computer, i use homebrew and remove macport. will that be my problem? how can i check which version of openssl casablanca using?

as you directed, i add try-catch block around my code. here is what i got:
e web::http::http_exception & 0x0000000102f4bf98 0x0000000102f4bf98
m_msg std::__1::string "Error code in handle_handshake is "
m_errorCode std::__1::error_code
_val int 60 60
_cat const std::__1::error_category * 0x7fff7324df48 0x00007fff7324df48

how can i build casblanca with symbols? change GCC_GENERATE_DEBUGGING_SYMBOLS => YES?

-Zhong
Coordinator
Aug 21, 2014 at 9:27 PM
Edited Aug 21, 2014 at 10:56 PM
Hi Zhong,

The previous macports installation shouldn't be a problem.

To check the version of openssl we end up using, you can either pay close attention to the cmake configuration step (it lists it out) or simply run
otool -L libcpprest.dylib
on the resulting binary.

Thanks for the information.

The binary should be built with symbols as long as you're using -DCMAKE_BUILD_TYPE=Debug.

Now onto a possible solution: if you're linking against a version like 0.9.xy, then you're linking against the original system's copy and not the homebrew version. You can fix this by adding the following extra options to your cmake configuration line:
-DOPENSSL_ROOT_DIR=/usr/local/Cellar/openssl/1.0.1i/
This assumes you're using the latest version of openssl: version 1.0.1i. To get the latest, you can do
brew update; brew upgrade
Let us know if this fixes the problem,
roschuma
Aug 22, 2014 at 12:38 AM
i have openssl 1.0.1i installed in /usr/local/Cellar/openssl/1.0.1i/

while otool output is
/usr/local/opt/openssl/lib/libssl.1.0.0.dylib (compatibility version 1.0.0, current version 1.0.0)
/usr/local/opt/openssl/lib/libcrypto.1.0.0.dylib (compatibility version 1.0.0, current version 1.0.0)
how can i make cpprest.dylib to link to homebrew openssl?

-Zhong
Coordinator
Aug 22, 2014 at 1:40 AM
When running the cmake command to configure the project, it should look like
cmake ../Release -DCMAKE_BUILD_TYPE=Debug -DOPENSSL_ROOT_DIR=/usr/local/Cellar/openssl/1.0.1i/
Aug 26, 2014 at 4:54 PM
it still doesnt work for me.

i upgraded openssl to latest through homebrew, link homebrew openssl to /usr/bin/openssl and rebuild everything.

is there anything else i should check?

-Zhong