DMARC Monitoring is coming soon: collect and analyze DMARC and TLS-RPT reports in one place. Learn more
Certificate Monitoring

SSL Handshake Failed: How to Fix It

SSL handshake failed hides several different faults. Real error strings from curl, openssl, browsers, and app runtimes, each with its cause and the fix.

"SSL handshake failed" is what you get when a client and server couldn't finish setting up an encrypted connection, and on its own it tells you almost nothing. The handshake has to do several things before any data moves: both sides must speak TLS on that port, agree on a protocol version and a cipher, and the client has to accept the server's certificate. Sometimes the server wants a certificate back. Any one of those steps can fail, and each failure has its own error string. The string is the diagnosis, so the first job is getting the real one.

Every error below was captured on a Linux box running OpenSSL 3.5 and curl 8.18, against public test hosts or a local openssl s_server. OpenSSL starts each error line with a thread ID that changes on every run, so that's trimmed, and the source file and line numbers vary by build. The text after SSL routines is what to search for.

Quick Lookup

Error text What it usually means
wrong version number, packet length too long, ERR_SSL_PROTOCOL_ERROR You're speaking TLS to a port that isn't serving TLS
unsupported protocol The server only offers TLS 1.0 or 1.1, and your client won't go that low
tlsv1 alert protocol version The server refused the TLS version your client offered
alert handshake failure (alert 40) No cipher in common, or the server needed SNI and didn't get it
ERR_SSL_VERSION_OR_CIPHER_MISMATCH Chrome's name for either of the two rows above
certificate verify failed, curl error 60 The certificate was rejected: expired, wrong name, or untrusted chain
tlsv13 alert certificate required The server wants a client certificate (mTLS)
key values mismatch The server can't start: its certificate and key don't belong together

Get the Real Error First

Browsers and app logs often flatten the failure to one generic line. Reproduce it from a shell where you can see the whole exchange. curl -v shows how far the handshake got (progress meter and trust store lines trimmed):

$ curl -v https://rc4.badssl.com/
* Host rc4.badssl.com:443 was resolved.
*   Trying 104.154.89.105:443...
* ALPN: curl offers h2,http/1.1
* TLSv1.3 (OUT), TLS handshake, Client hello (1):
* TLSv1.3 (IN), TLS alert, handshake failure (552):
* TLS connect error: error:0A000410:SSL routines::ssl/tls alert handshake failure
curl: (35) TLS connect error: error:0A000410:SSL routines::ssl/tls alert handshake failure

The client sent its hello and the server answered with an alert, so the server is the one that gave up. openssl s_client gives more detail, including the TLS alert number. Always pass -servername, or you're testing a different handshake from the one your client makes:

openssl s_client -connect example.com:443 -servername example.com -brief </dev/null

If the failure comes from a server that's on the internet, run it through our free SSL checker as well, which reports the certificate's expiry, hostname coverage, and chain as an outside client sees them.

Plain HTTP on a TLS Port

The most common cause is also the dullest: the client is speaking TLS and the server is answering in plain HTTP. Every tool words this differently, and none of them say it plainly. The same plain HTTP port, three clients:

$ curl https://127.0.0.1:8080/
curl: (35) TLS connect error: error:0A00010B:SSL routines::wrong version number

$ openssl s_client -connect 127.0.0.1:8080
error:0A0000C6:SSL routines:tls_get_more_records:packet length too long

# Python 3.9 on OpenSSL 3.5
ssl.SSLError: [SSL] record layer failure (_ssl.c:1147)

Chrome shows ERR_SSL_PROTOCOL_ERROR, and Firefox SSL_ERROR_RX_RECORD_TOO_LONG. They all mean the first bytes back were plain text, something like HTTP/1.1 400 Bad Request, where a TLS record should be. Check for an https:// URL pointing at port 80 or 8080, a reverse proxy forwarding to the wrong port, or an nginx listen 443; line missing its ssl parameter.

Protocol Version Mismatch

This failure comes in two directions, and the error tells you which side is out of date. When the server is too old, your client refuses first. Here's curl against a server that only speaks TLS 1.0:

$ curl https://tls-v1-0.badssl.com:1010/
curl: (35) TLS connect error: error:0A000102:SSL routines::unsupported protocol

Chrome reports ERR_SSL_VERSION_OR_CIPHER_MISMATCH and Firefox SSL_ERROR_UNSUPPORTED_VERSION. Current browsers and most Linux distributions won't negotiate below TLS 1.2. The fix belongs on the server: enable TLS 1.2 and 1.3. Re-enabling TLS 1.0 on every client to reach one old box is the wrong trade.

When the client is too old, the server sends the alert. Forcing a client to TLS 1.2 against a server that only allows 1.3:

$ curl --tls-max 1.2 https://localhost:9001/
curl: (35) TLS connect error: error:0A00042E:SSL routines::tlsv1 alert protocol version

$ openssl s_client -connect localhost:9001 -tls1_2
error:0A00042E:SSL routines:ssl3_read_bytes:tlsv1 alert protocol version:ssl/record/rec_layer_s3.c:916:SSL alert number 70

# Java
javax.net.ssl.SSLHandshakeException: (protocol_version) Received fatal alert: protocol_version

# Python
[SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version (_ssl.c:1147)

The tlsv1 in that message is just OpenSSL's name for the alert; it shows up whatever version was attempted. Unless you control every client, allow both TLS 1.2 and 1.3 on the server. For nginx that's:

ssl_protocols TLSv1.2 TLSv1.3;

The goodtls.com nginx guide has the full block, and there are guides for Apache, HAProxy, Postfix, and the rest on the same site.

Alert 40: Handshake Failure

alert handshake failure (alert number 40) is the server saying it couldn't find a way forward, without saying why. The two usual reasons are no shared cipher and a missing SNI name.

A cipher mismatch, client and server with no suite in common:

$ curl --ciphers ECDHE-ECDSA-CHACHA20-POLY1305 https://localhost:9002/
curl: (35) TLS connect error: error:0A000410:SSL routines::ssl/tls alert handshake failure

The client side never learns which cipher was missing. The server's log does:

error:0A0000C1:SSL routines:tls_post_process_client_hello:no shared cipher

The same alert comes back from a server that only offers retired ciphers like RC4 or 3DES, which is what rc4.badssl.com and 3des.badssl.com do. Chrome shows ERR_SSL_VERSION_OR_CIPHER_MISMATCH and Firefox SSL_ERROR_NO_CYPHER_OVERLAP. The fix is a current cipher list on the server.

The missing-SNI case catches people out because the same host works one moment and fails the next. Some CDNs pick the certificate by SNI and abort the handshake when there isn't one:

$ openssl s_client -connect example.com:443 -noservername
error:0A000410:SSL routines:ssl3_read_bytes:ssl/tls alert handshake failure:ssl/record/rec_layer_s3.c:916:SSL alert number 40

Add -servername example.com and the same host connects with Verification: OK. s_client before OpenSSL 1.1.1 didn't send SNI unless asked, and no client sends it when you connect by IP address, because SNI can't carry one. If alert 40 only shows up in one script, check SNI before touching any ciphers.

The Certificate Was Rejected

When the version and cipher are agreed, the client checks the certificate, and a rejection here also ends the handshake. curl reports all of these as error 60, with OpenSSL's verify code in brackets:

curl: (60) SSL certificate OpenSSL verify result: certificate has expired (10)
curl: (60) SSL certificate OpenSSL verify result: certificate is not yet valid (9)
curl: (60) SSL certificate OpenSSL verify result: self-signed certificate (18)
curl: (60) SSL certificate OpenSSL verify result: self-signed certificate in certificate chain (19)
curl: (60) SSL certificate OpenSSL verify result: unable to get local issuer certificate (20)
curl: (60) SSL: no alternative certificate subject name matches target hostname 'wrong.host.badssl.com'
Verify result Browser (Chrome) Cause Fix
certificate has expired (10) NET::ERR_CERT_DATE_INVALID Past its Not After date Renew and deploy to every node
certificate is not yet valid (9) NET::ERR_CERT_DATE_INVALID Client clock is behind, or a cert deployed early Fix NTP on the client first
self-signed certificate (18) NET::ERR_CERT_AUTHORITY_INVALID No CA signed it Trust it explicitly, or use a CA-issued cert
self-signed certificate in certificate chain (19) NET::ERR_CERT_AUTHORITY_INVALID The chain ends at a private or unknown root Add the root to the client's trust store
unable to get local issuer certificate (20) Often none: browsers repair it Missing intermediate Serve the full chain file
no alternative certificate subject name matches NET::ERR_CERT_COMMON_NAME_INVALID Hostname isn't in the SAN Reissue with the right names

Runtimes phrase the same failures their own way. Java gives PKIX path building failed ... unable to find valid certification path to requested target for any untrusted chain, and Python gives [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed:, usually followed by the same reason text curl prints. The missing intermediate is the one that wastes the most time, since it works in a browser and fails everywhere else; why certificate chains break covers that in depth, and self-signed certificates in OpenSSL covers trusting a private certificate properly. Don't reach for curl -k or verify=False to get past any of these. That accepts every certificate, including an attacker's.

The Server Wants a Client Certificate

With mutual TLS the server checks a certificate from the client too. Connect without one and, under TLS 1.3, the error turns up after the handshake looked done:

$ curl https://localhost:9003/
curl: (56) OpenSSL SSL_read: OpenSSL/3.5.1: error:0A00045C:SSL routines::tlsv13 alert certificate required, errno 0

The server logs peer did not return a certificate. That's curl error 56, a receive failure, where everything above was error 35 or 60, which is why it's easy to misread as a network fault. Pass the client certificate and key with --cert and --key, and see mTLS in practice for the server side.

The Server Can't Load Its Own Certificate

After a renewal, the handshake sometimes fails because the server never started with the new certificate at all. nginx refuses the config when the certificate and key don't match:

$ nginx -t      # paths shortened
nginx: [emerg] SSL_CTX_use_PrivateKey("/etc/nginx/ssl/privkey.pem") failed (SSL: error:05800074:x509 certificate routines::key values mismatch)
nginx: configuration file /etc/nginx/nginx.conf test failed

Compare the public key inside each file. Matching hashes mean they belong together:

$ openssl x509 -in fullchain.pem -noout -pubkey | openssl sha256
SHA2-256(stdin)= 776e8d2b139b5d907ba0328dbaa665fe5548e6e4758c5d1691389261c9a913c6
$ openssl pkey -in privkey.pem -pubout | openssl sha256
SHA2-256(stdin)= 776e8d2b139b5d907ba0328dbaa665fe5548e6e4758c5d1691389261c9a913c6

A different hash means the key came from another request, usually an older CSR or the wrong directory. Find the key that was generated with the CSR you submitted, or start over with a fresh key and CSR.

Catch It Before Your Users Do

Most of these failures arrive without anyone touching the server: a certificate runs past its date, a CA rotates an intermediate, a renewal lands on one load balancer node and not the others. Generator Labs Certificate Monitoring completes a real TLS handshake with every IP behind a hostname, so a failed handshake is reported as its own finding along with the address it failed on. When the handshake works, the same check covers expiry against your thresholds, the full chain, SAN coverage, CRL revocation, and weak keys or signing algorithms. The point is to read these error strings in an alert, before your customers start pasting them into support tickets.

Start Monitoring Today

Free plan available. No credit card required.