I am trying to set TLSv1.1 or v1.2
from C++ (Win) code using cpprest
API calls as mentioned. But WinHttpSetOption()
is failing with error ERROR_INTERNET_INCORRECT_HANDLE_TYPE
(12018).
OS:Windows(7/8)
- Tried to set TLSv1.1 and TLS1.2 from registry setting did not work.
- Tried to get OpenSLL but opensll1.0.1(which supports TLS1.1 and more) is not available for windows.
- Tried to get other than native handle did not find API
auto func = [&](web::http::client::native_handle handle){
BOOL win32Result{ FALSE };
DWORD secure_protocols{ WINHTTP_FLAG_SECURE_PROTOCOL_TLS1_1
| WINHTTP_FLAG_SECURE_PROTOCOL_TLS1_2 };
win32Result = ::WinHttpSetOption(handle,
WINHTTP_OPTION_SECURE_PROTOCOLS,
&secure_protocols,
sizeof(secure_protocols));
if (FALSE == win32Result) {
std::cout << "Can not set TLS 1.1 or TLS 1.2." << std::endl;
auto err = GetLastError();
CString cstr;
cstr.Format(_T("err = %d"),err);
AfxMessageBox(cstr);
}
};
config.set_validate_certificates(false);
config.set_nativehandle_options(func);
Please help me to set TLSv1.1 or v1.2 using C++ REST API. Or
how to make WinHttpSetOption()
successful.