0

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.

1
  • CURLOPT_DEBUGDATA expects void* you pass long, this is undefined behavior. CURLOPT_VERBOSE expects long you pass int, this is undefined behavior on non Windows platforms. Commented Dec 20, 2022 at 20:34

1 Answer 1

1

This error indicates the TLS handshake key exchange does not finish successfully. Try to experiment with adding one of the lines below:

curl_easy_setopt(curl, CURLOPT_SSLVERSION, CURL_SSLVERSION_SSLv3 | CURL_SSLVERSION_MAX_TLSv1_2);
curl_easy_setopt(curl, CURLOPT_SSLVERSION, CURL_SSLVERSION_SSLv3 | CURL_SSLVERSION_MAX_TLSv1_1);
curl_easy_setopt(curl, CURLOPT_SSLVERSION, CURL_SSLVERSION_SSLv3 | CURL_SSLVERSION_MAX_TLSv1_0);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.