Skip to content

curl error 35 through a proxy: where the TLS handshake broke

curl exits with code 35 (CURLE_SSL_CONNECT_ERROR) when a TLS handshake fails. Through a proxy there can be two handshakes: one with the proxy itself if you wrote -x https://, and one with the website inside the tunnel. %{http_connect} tells them apart: 200 means the tunnel opened and the handshake with the site failed, 000 means it failed before that, with the proxy.

Reviewed by John Hale. Last updated .

What it looks like

curl 8.7.1 (LibreSSL 3.3.6), tunnel opened and then cut
curl: (35) Recv failure: Connection reset by peer

curl 8.7.1 (LibreSSL 3.3.6), the other end did not speak TLS
curl: (35) LibreSSL/3.3.6: error:1404B42E:SSL routines:ST_CONNECT:tlsv1 alert protocol version

Python requests and Node.js fetch, the same two failures
requests.exceptions.ConnectionError: ('Connection aborted.', ConnectionResetError(54, 'Connection reset by peer'))
requests.exceptions.SSLError: ... [SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1129)
TypeError: fetch failed  cause: read ECONNRESET
TypeError: fetch failed  cause: ...SSL routines:tls_validate_record_header:wrong version number

What does curl error 35 mean?

libcurl documents CURLE_SSL_CONNECT_ERROR (35) as a problem somewhere in the SSL/TLS handshake, with the detail in the message. The number says only that a handshake started and did not finish. A certificate that fails verification is a different error, 60.

With -x http://HOST:PORT, curl speaks plain text to the proxy, sends CONNECT host:443, and starts TLS with the site only after 200 Connection established. From then on the proxy carries encrypted bytes it cannot read. With -x https://HOST:PORT, curl first does a TLS handshake with the proxy, and that one can fail with 35 before any CONNECT is sent.

What causes curl error 35 through a proxy?

Most likely first.

  1. The connection was reset during the handshake. Recv failure: Connection reset by peer with CONNECT 200. The tunnel opened, then the exit, the route or the site cut it while TLS was starting. One reset is noise. The same site resetting every exit is the site, or a filter in front of it, refusing the connection. See ECONNRESET through a proxy.
  2. The other end is not speaking TLS. The macOS build prints tlsv1 alert protocol version; Python and Node.js print wrong version number for the same test. curl sent a TLS hello and got plain bytes back: an https:// URL on a port that serves plain HTTP, or a proxy or captive portal that answered inside the tunnel with an HTTP page of its own.
  3. `-x https://` on a plain HTTP proxy port. The same message with CONNECT 000. https:// in the proxy URL means TLS to the proxy, which only a provider's TLS port accepts. The scheme of the proxy URL describes the hop to the proxy, not the site.
  4. TLS versions or ciphers do not overlap. A server that offers only TLS 1.0 or 1.1, or an old curl that cannot do TLS 1.2 or 1.3, ends the handshake with a protocol version or handshake failure alert.
  5. Something on the path inspects TLS. Corporate proxies and antivirus that intercept TLS, and filters that drop connections by server name, break the handshake for some sites and not for others.

How do you find which handshake failed?

  1. Print the proxy's answer next to the exit code

    CONNECT 200 | site 000 | exit 35 is the site's handshake inside the tunnel. CONNECT 000 | exit 35 happens only with an https:// proxy URL and is the handshake with the proxy.

    One line per request
    curl -s -o /dev/null -w "CONNECT %{http_connect} | site %{http_code} | exit %{exitcode}\n" \
      -x http://HOST:PORT -U "USER:PASS" https://TARGET/

  2. Read the handshake

    The lines after Connection established show the hello curl sent and the alert or reset that ended it.

    Only the tunnel and TLS lines
    curl -v -x http://HOST:PORT -U "USER:PASS" https://TARGET/ -o /dev/null 2>&1 \
      | grep -E "CONNECT|Connection established|TLS|SSL|alert|curl: \("

  3. Ask the site without the proxy

    This prints the TLS version and cipher the site settles on. If it fails here too, the problem is the site or your client, not the proxy.

    The site's TLS, direct
    openssl s_client -connect TARGET:443 -servername TARGET </dev/null 2>/dev/null | grep -E "Protocol|Cipher"

How do you fix curl error 35?

  • Use the scheme that matches the proxy port

    Write -x http://HOST:PORT for an HTTP proxy port even when the site is https://. Use -x https:// only with the port your provider documents for TLS to the proxy.

  • Retry resets on safe requests

    A reset during the handshake is not on curl's list of transient errors, so plain --retry skips it. --retry-all-errors includes it. Use it only for requests that are safe to repeat.

    Retry every failure three times
    curl --retry 3 --retry-all-errors --retry-delay 2 -x http://HOST:PORT -U "USER:PASS" https://TARGET/

  • Update the client before you weaken TLS

    If the site needs TLS 1.2 or 1.3 and your curl cannot offer it, update curl and its TLS library. --tlsv1.2 sets the lowest version curl offers; it does not make an old build newer. -k does not help either: it turns off certificate checks, which are not the step that failed.

  • Change the exit when one route resets

    With a rotating proxy, send the request again and it leaves from another exit. With a sticky session, start a new session ID.

If you use TrueProxies

Use -x http://HOST:8080 for both http:// and https:// sites, and -x https://HOST:8443 only when you want TLS to the gateway itself. -x https://HOST:8080 fails with error 35, because port 8080 speaks plain HTTP.

The gateway takes no part in the handshake with the site. After 200 Connection established it carries encrypted bytes between you and the site and cannot read or change them, so a TLS error inside the tunnel is between your client and the site through that exit.

A login problem never shows as error 35 on port 8080: a refusal is answered with 407 and a reason before any tunnel opens.

Test the proxy from outside your network

The free proxy checker connects from our servers and reports the failed stage as a code, so you can tell a proxy problem from one on your computer or network.

Run the proxy checker

Questions about curl error 35

What does curl error 35 mean?

CURLE_SSL_CONNECT_ERROR: a TLS handshake started and did not finish. Through a proxy it is usually the handshake with the website inside the tunnel, and the text after (35) says how it ended.

Why do I get wrong version number?

The client sent a TLS hello and the reply was not TLS. Check for an https:// URL on a port that serves plain HTTP, or https:// in the proxy URL for a proxy port that speaks plain HTTP.

Is curl error 35 a certificate problem?

No. A certificate that fails verification exits 60. Error 35 means the handshake itself did not complete.

Can -k or --insecure fix curl error 35?

No. -k skips certificate verification, which comes after the step that failed. The handshake failure stays, and you lose a check you need.

What is the difference between curl error 35 and 56?

Both can say Recv failure: Connection reset by peer. 35 is a reset during the TLS handshake inside the tunnel. 56 is a failure while reading the proxy's answer or the response itself.