OpenSSL 握手失败(TLS/SSL handshake failure)是常见但原因很多的问题。下面按最常见 → 较少见的顺序给你一个排查思路,并配合常见错误信息。
客户端和服务端支持的 TLS 版本不一致。
示例错误
no protocols available
protocol version mismatch
handshake failure
原因
排查
openssl s_client -connect host:443 -tls1_2
openssl s_client -connect host:443 -tls1_3
✅ 建议
证书无效或不可信。
常见错误
verify error:num=18:self signed certificate
verify error:num=20:unable to get local issuer certificate
verify error:num=21:unable to verify the first certificate
可能原因
排查
openssl s_client -connect host:443 -showcerts
✅ 解决
# 指定 CA
openssl s_client -connect host:443 -CAfile ca.crt
或:
# 跳过验证(仅调试)
openssl s_client -connect host:443 -verify 0
两边协商不到共同算法。
示例错误
no shared cipher
handshake failure
排查
openssl ciphers -v
openssl s_client -connect host:443 -cipher 'ECDHE-RSA-AES128-GCM-SHA256'
✅ 建议
虚拟主机场景非常常见。
现象
解决
openssl s_client -connect host:443 -servername example.com
✅ 必须带上 -servername
Common Name mismatch
✅ 证书中的:
错误示例
SSL_CTX_use_PrivateKey_file failed
验证:
openssl x509 -in cert.pem -noout -modulus
openssl rsa -in key.pem -noout -modulus
✅ modulus 必须一致
tlsv1 alert certificate required
✅ 客户端必须提供:
openssl s_client \
-connect host:443 \
-cert client.crt \
-key client.key \
-CAfile ca.crt
openssl version
✅ 用:
curl -v https://host
或抓包:
tcpdump / wireshark
openssl s_client -connect host:443 \
-servername example.com \
-showcerts \
-tls1_2
如果你愿意,可以把以下信息贴出来(可打码):
我可以一步步帮你定位是哪一类握手失败。