I have been working on an application which uses curl for communication to a server. Sometimes I get an "SSL Connect" error.
curl/libcurl version
7.86
operating system
Windows
I tried to increase verbosity on a machine where this issue is occurring, and got an "ssl handshake" error.
static int trace(CURL* handle, curl_infotype type, char* data, size_t size, void* userp)
{
switch (type)
{
case CURLINFO_TEXT:
CLIENT_LOG_DEBUG("== Info: %s", data);
break;
default:
return 0;
case CURLINFO_HEADER_OUT:
CLIENT_LOG_DEBUG("=> Send header: %s", data);
break;
case CURLINFO_DATA_OUT:
CLIENT_LOG_DEBUG("=> Send data: %s", data);
break;
case CURLINFO_SSL_DATA_OUT:
CLIENT_LOG_DEBUG("=> Send SSL data: %s", data);
break;
case CURLINFO_HEADER_IN:
CLIENT_LOG_DEBUG("<= Recv header: %s", data);
break;
case CURLINFO_DATA_IN:
CLIENT_LOG_DEBUG("<= Recv data: %s", data);
break;
case CURLINFO_SSL_DATA_IN:
CLIENT_LOG_DEBUG("<= Recv SSL data: %s", data);
break;
}
return 0;
}
/// at caller method:
CLIENT_LOG_INFO("TRACE_LEVEL_HIGH");
curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION, trace);
curl_easy_setopt(curl, CURLOPT_DEBUGDATA, 1L);
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
/// Other curl options set while making connection:
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "PUT");
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, payload.c_str());
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, payload.size());
#ifndef PLATFORM_UNIX
curl_easy_setopt(curl, CURLOPT_CAINFO, "curl-ca-bundle.crt");
#endif
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteResponseCallback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response);
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 20L);
curl::SendRequest:314 TRACE_LEVEL_HIGH
trace:45 == Info: Connected to <URL> (<IP>) port 443 (#0)
trace:45 == Info: schannel: disabled automatic use of client certificate
trace:45 == Info: ALPN: offers http/1.1
trace:45 == Info: schannel: failed to receive handshake, SSL/TLS connection failed
trace:45 == Info: Closing connection 0
curl::SendRequest:387 Failed sending curl request with error:SSL connect error
I am only getting CURLINFO_TEXT logs, no header out, data out, etc.
I am stuck here. This doesn't seem to be a certificate-related issue.
CURLOPT_DEBUGDATAexpectsvoid*you passlong, this is undefined behavior.CURLOPT_VERBOSEexpectslongyou passint, this is undefined behavior on non Windows platforms.