c++sslboostboost-asiocpprest-sdk

Error on compiling 'set_ssl_context_callback': on Windows


I want to add some TLS specifications to my context , hence I am using the set_ssl_context_callback.
But I get the error "set_ssl_context_callback is not a member of web::http::client::http_client_config" since it is surrounded by :

#if !defined(_WIN32) && !defined(__cplusplus_winrt)

How do I disable these flags?

Is there a workaound?I am using Visual Studio 2017.(15.6.7)

http_client_config config;
        config.set_ssl_context_callback([](boost::asio::ssl::context &context){
            context.set_options(boost::asio::ssl::context::no_sslv2
                | boost::asio::ssl::context::no_sslv3
                | boost::asio::ssl::context::no_tlsv1
                | boost::asio::ssl::context::no_tlsv1_1);
        });
        http_client raw_client(SessionData::get_instance().GetServerUrl(), config);

I get the following error "set_ssl_context_callback is not a member of web::http::client::http_client_config"


Solution

  • This is not available for Windows as it has been disabled :

    if !defined(_WIN32) && !defined(__cplusplus_winrt)

    Use the following instead, with cpprest 2.10:

        auto func = [&](native_handle handle) {
            BOOL win32Result = FALSE;
            DWORD secure_protocols = WINHTTP_FLAG_SECURE_PROTOCOL_TLS1_2;
            win32Result = ::WinHttpSetOption(handle,
                WINHTTP_OPTION_SECURE_PROTOCOLS,
                &secure_protocols,
                sizeof(secure_protocols));
            if (FALSE == win32Result) {
                MessageBox(NULL, L"error", L"Failed to set minimum TLS option", MB_OK);
            }
            else
                MessageBox(NULL, L"error", L"Set minimum TLS option to Success", MB_OK);
    
        };
    
       config.set_nativesessionhandle_options(func)