The SSL: SSLV3_ALERT_HANDSHAKE_FAILURE error in Python’s requests module typically occurs due to a failure in the SSL/TLS handshake process.
This can be caused by various issues, including incompatible SSL/TLS versions, cipher suites, or SSL certificate problems.
Table of Contents
Using OpenSSL to Diagnose SSL Issues
The OpenSSL command-line tool can be used to manually initiate an SSL handshake with the server, which can help determine if the issue is network-related or due to software configuration.
The command will show detailed information about the SSL handshake process and can help pinpoint the stage where the failure occurs.
Get Your Free Linux training!
Join our free Linux training and discover the power of open-source technology. Enhance your skills and boost your career!
Start Learning Linux today — Free!
How to Use OpenSSL for Diagnosis
- Open a terminal or command prompt.
- Run the OpenSSL command to initiate an SSL handshake:
openssl s_client -connect hostname:port -tls1_2
Replace hostname and port with the server’s details. Try different SSL/TLS versions as needed.
- Analyze the output for error messages or warnings, cipher suite compatibility, and certificate details.
Interpreting the Results
If OpenSSL successfully establishes a connection but the Python script does not, the issue is likely within the Python environment or script.
If OpenSSL also fails, the problem might be network-related or due to the server’s SSL configuration.
Steps to Fix SSLV3_ALERT_HANDSHAKE_FAILURE
Here are steps to resolve this issue:
Update Python and requests Module
- Ensure the latest versions of Python and the requests module are in use. Newer versions of Python often include security patches that fix vulnerabilities found in older versions. By updating, you protect your applications from known security risks.
- Update Python from the official Python website.
- Update requests module using pip:
pip install --upgrade requests
Install/Update pyOpenSSL, cryptography, and ndg-httpsclient
- These packages enhance SSL/TLS support in Python.
- Install or update them using pip:
pip install --upgrade pyOpenSSL cryptography ndg-httpsclient
Check Server SSL Configuration
Use tools like SSL Labs’ SSL Test to examine the server’s SSL setup. SSL Labs’ SSL Test is a free online service that performs a deep analysis of the configuration of any web server on the public internet.
It assesses the server’s SSL/TLS configuration by testing its public URL. The analysis includes checking supported protocols, cipher suites, key exchange methods, and certificate details.
Ensure the server supports modern SSL/TLS protocols and cipher suites.
Force Specific SSL Version or Cipher Suite (If Appropriate)
Forcing Python’s requests library to use a specific SSL version or cipher suite can sometimes be necessary, especially when interacting with older servers or in environments with specific security requirements.
Example:
import requests
from requests.packages.urllib3.util.ssl_ import create_urllib3_context
# Create an SSL context
ctx = create_urllib3_context(ssl_version='your_ssl_version', ciphers='your_cipher_suite')
# Use the context in a session
s = requests.Session()
s.mount('https://', SSLAdapter(ssl_context=ctx))
response = s.get('https://example.com')
It’s generally safer to rely on the requests library’s default settings, as they are configured to choose the most secure and compatible options.
Forcing specific SSL/TLS settings should be a last resort, used only when necessary and understanding the risks.
Check Client Certificate (If Using)
When making secure requests to a server, especially in enterprise or business-to-business scenarios, you might be required to use a client certificate.
This is a form of mutual authentication where both the client and the server authenticate each other.
Unlike a typical SSL/TLS handshake where only the server is authenticated by the client, client certificates are used to authenticate the client to the server.
This adds an extra layer of security by ensuring that only authorized clients can communicate with the server.
Ensure the client certificate is correctly specified and valid.
Example:
response = requests.get('https://example.com', cert=('/path/client.cert', '/path/client.key'))
This code snippet tells requests to present the specified client certificate and key when establishing an SSL/TLS connection to https://example.com.
Verify System’s Root Certificates
Keeping the system’s root certificates updated is crucial for maintaining secure communications and avoiding SSL/TLS handshake failures.
Root certificates are fundamental in the SSL/TLS protocol, as they establish the trustworthiness of SSL certificates presented by websites.
Root certificates are the topmost certificates in the SSL/TLS certificate chain. They are issued by trusted Certificate Authorities (CAs).
When you access a secure website (HTTPS), your browser or client software checks the website’s SSL certificate against these root certificates to verify its authenticity.
If the website’s certificate is not trusted by any root certificate on your system, the SSL/TLS handshake fails, leading to errors like SSLV3_ALERT_HANDSHAKE_FAILURE.
Conclusion
- Be careful with changing SSL settings, especially in production environments. Prioritize security and compatibility.
- Avoid disabling SSL verification (verify=False) in production to prevent security vulnerabilities.
SSLV3 alert handshake failure occurs when a client and server cannot establish communication using the TLS/SSL protocol.
As a part of our Server Management Services, we help our Customers to fix SSL-related errors regularly.
Let us today discuss the possible causes and fixes for this error.
What causes SSLV3 alert handshake failure?
A handshake is a process that enables the TLS/SSL client and server to establish a set of secret keys with which they can communicate. During this process, the client and server:
- Agree on the version of the protocol to use.
- Select the cryptographic algorithm to be used.
- Authenticate each other by exchanging and validating digital certificates.
When the client and server cannot establish communication using the TLS/SSL protocol, the client application receives an HTTP status 503 with the message Service Unavailable. The error message often looks like this:
The possible causes for TLS/SSL handshake failures are:
- Protocol mismatch
- Cipher Suite mismatch
- SNI enabled server
- Hostname mismatch
How to fix SSLV3 alert handshake failure?
The handshake failure error most commonly occurs when the protocol used by the client is not supported by the server.
Some sites disable support for SSL 3.0 because of many exploits/vulnerabilities. It is possible to force a specific SSL version by either -2/–sslv2 or -3/–sslv3.
To fix this error, we need to ensure that the same protocols are used in the client and server. If not, we have to upgrade the client’s protocol to match that of the server.
At times, the server may not support the cipher suite used by the client. In this scenario, we must ensure that the client uses the cipher suite algorithms that the server supports.
If the backend server is Server Name Indication (SNI) enabled, but the client still cannot communicate with the SNI servers, it will trigger the error.
To solve this error, first, we need to identify the hostname and port number of the server being used and check if it is SNI enabled or not. Then make the client compatible with SNI.
Another scenario that triggers the error is when the hostname in the URL used by the client does not match the hostname in the SSL certificate stored at the server end. It could be due to an incomplete, incorrect, expired, or invalid certificate. Let us now look at each of these cases one by one.
Case 1: Hostname Mismatch
This scenario explains when the hostname used in the URL and the certificate in the Keystore of the router do not match. Two ways to fix this error include:
- Obtain a certificate (if you do not have one already) where the subject CN has a wildcard certificate, then upload the new complete certificate chain to the Keystore. For example:
“subject”: “CN=*.domain.com, OU=Domain Control Validated, O=*.domain.com”, - Obtain a certificate (if you do not have one already) with an existing subject CN, but use your-org.your-domain as a subject alternative name, then upload the complete certificate chain to the Keystore.
Case 2: Incomplete or Incorrect certificate chain
Issues with an incomplete or incorrect certificate chain can be fixed with the steps below:
- Obtain a certificate (if you do not have one already) that includes a complete and valid certificate chain.
- Run the following openssl command to verify that the certificate chain is correct and complete:
openssl verify -CAfile root-cert -untrusted intermediate-cert main-cert
- Upload the validated certificate chain to the keystore.
Case 3: Expired or unknown certificate
This error is also triggered when an expired or unknown certificate is sent by the server or client either at the incoming or at the outgoing connection. Steps to fix this error include:
- Upload a new certificate and its complete chain to the keystore on the appropriate host.
- Upload the valid certificate to the trust store on the appropriate host.
[Need any further assistance in fixing SSL errors? – We’re available 24*7]
Conclusion
In short, an SSLV3 handshake failure alert occurs when a client and server cannot establish communication using the TLS/SSL protocol. Today, we saw how our Support Engineers fix this error.
PREVENT YOUR SERVER FROM CRASHING!
Never again lose customers to poor server speed! Let us help you.
Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.
GET STARTED
PREVENT YOUR SERVER FROM CRASHING!
Never again lose customers to poor server speed! Let us help you.
Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.
GET STARTED
var google_conversion_label = «owonCMyG5nEQ0aD71QM»;
Hi,
I used «openssl s_client -connect URL:port» command to visit 500 most popular websites (). But some URLs cause the following error:
140271130755520:error:14094410:SSL routines:ssl3_read_bytes:sslv3 alert handshake failure:../ssl/record/rec_layer_s3.c:1399:SSL alert number 40
The problematic hostnames are these (including the openssl command to connect to those HTTPS web servers):
openssl s_client -connect www.reuters.com:443
openssl s_client -connect www.bloomberg.org:443
openssl s_client -connect www.wsj.com:443
openssl s_client -connect stumbleupon.com:443
openssl s_client -connect www-media.stanford.edu:443
openssl s_client -connect www.deviantart.com:443
openssl s_client -connect www.wiley.com:443
openssl s_client -connect themeforest.net:443
openssl s_client -connect mashable.com:443
openssl s_client -connect www.trustpilot.com:443
openssl s_client -connect www.a8.net:443
openssl s_client -connect www.uol.com.br:443
openssl s_client -connect www.domraider.com:443
openssl s_client -connect us.sagepub.com:443
openssl s_client -connect hbr.org:443
openssl s_client -connect static-service.prweb.com:443
openssl s_client -connect www.usgs.gov:443
openssl s_client -connect www.archives.gov:443
openssl s_client -connect www.usc.edu:443
openssl s_client -connect www.usa.gov:443
openssl s_client -connect www.istockphoto.com:443
openssl s_client -connect www.snapchat.com:443
openssl s_client -connect www2.gotomeeting.com:443
openssl s_client -connect bitbucket-marketing-cdn.atlassian.com:443
openssl s_client -connect cdn-1.wp.nginx.com:443
openssl s_client -connect d1af033869koo7.cloudfront.net:443
openssl s_client -connect www.worldbank.org:443
openssl s_client -connect www.mlbstatic.com:443
But when I use curl, none of the above causes any error:
curl -i https://www.reuters.com
curl -i https://www.bloomberg.org
curl -i https://www.wsj.com handshake
curl -i https://stumbleupon.com
curl -i https://www-media.stanford.edu
curl -i https://www.deviantart.com
curl -i https://www.wiley.com
curl -i https://themeforest.net
curl -i https://mashable.com
curl -i https://www.trustpilot.com
curl -i https://www.a8.net
curl -i https://www.uol.com.br
curl -i https://www.domraider.com
curl -i https://us.sagepub.com
curl -i https://hbr.org
curl -i https://static-service.prweb.com
curl -i https://www.usgs.gov
curl -i https://www.archives.gov
curl -i https://www.usc.edu
curl -i https://www.usa.gov
curl -i https://www.istockphoto.com
curl -i https://www.snapchat.com
curl -i https://www2.gotomeeting.com
curl -i https://bitbucket-marketing-cdn.atlassian.com
curl -i https://cdn-1.wp.nginx.com
curl -i https://d1af033869koo7.cloudfront.net
curl -i https://www.worldbank.org
curl -i https://www.mlbstatic.com
My goal is to connect to the above web servers by using a nonblocking TLS. If I use a blocking TLS, I can connect to all of them fine. But if I use a non-blockching TLS, I get exactly the same error as connecting to the above web servers by using «opensssl.»
I thought the issue was not setting the Hostname extension value in the SSL structure of my source code. So I put the correct hostname as the following:
SSL_set_tlsext_host_name(ssl, hostname);
However, I still get the same error.. If someone has a brilliant insight to solve this problem, please help me out. Thanks!
The “SSL: SSLV3_ALERT_HANDSHAKE_FAILURE” error indicates that the server and client in your Python application couldn’t establish a secure connection using SSLv3.
I encountered the “SSL: SSLV3_ALERT_HANDSHAKE_FAILURE” error while working on a project with a tight deadline. This error message meant that the connection between my application and the server was being blocked.
Through research and troubleshooting, I discovered that the cause of the error was a mismatch in the supported cipher suites between my application and the server. A simple adjustment to the configuration settings solved the problem and allowed me to connect successfully.
So I summarized the following article. Hope it can help others.
This can occur due to various reasons, including:
- Outdated libraries: Your Python environment might use outdated libraries that lack support for newer TLS protocols or cipher suites.
- Incompatible configurations: The server and client might not be configured with compatible TLS versions, cipher suites, or certificate verification settings.
- Network issues: Temporary network issues could interfere with the handshake process.
Here’s how you can troubleshoot and fix this error in Python:
1. Update your libraries:
- Ensure you have the latest versions of the requests and urllib3 libraries installed. These libraries perform HTTP requests and manage SSL connections.
- Use
pip install --upgrade requests
andpip install --upgrade urllib3
to update them.
2. Configure TLS settings:
- Use the verify parameter in your requests to explicitly set the TLS version and verification mode.
- For example, to use TLS 1.2 and verify the server’s certificate, use:
import requests
response = requests.get("https://example.com", verify="/path/to/ca-certificates.pem")
Replace /path/to/ca-certificates.pem
with the actual path to your trusted certificate authority (CA) certificate file.
3. Disable SSLv3:
- SSLv3 is considered insecure due to known vulnerabilities. Disabling it might allow the connection to succeed using a more secure protocol.
- Use the ssl_version parameter in your requests to specify a different protocol like TLS 1.2:
response = requests.get("https://example.com", verify=False, ssl_version=ssl.PROTOCOL_TLSv1_2)
4. Check server configuration:
- Confirm the server supports a compatible TLS version and cipher suite.
- Contact the server administrator if you’re unsure about the configuration details.
5. Verify your network:
- Temporary network issues can sometimes interrupt the handshake process.
- Check your internet connection and ensure no firewall rules are blocking the connection.
6. Consider alternative libraries:
- If the error persists, consider using alternative libraries like pycurl or aiohttp that offer more advanced TLS configuration options.
Additional Resources:
- Python requests documentation: https://requests.readthedocs.io/
- Python urllib3 documentation: https://readthedocs.org/projects/urllib3/
By following these steps and investigating the specific context of your application, you should be able to identify the cause of the “SSL: SSLV3_ALERT_HANDSHAKE_FAILURE” error and establish a secure connection using a more robust TLS protocol.
@4ainik
начинал с бейсика на 286 в 1994
При выполнении запроса по https курл выдает ошибку
curl: error: 35, ‘error:14094410:ssl routines:ssl3_read_bytes:sslv3 alert handshake failure
В данном случае речь идет о модуле curl, который вызывается из php!
В чем причина?
-
Вопрос задан
-
10657 просмотров
Пригласить эксперта
Проблема с ssl сертификатом или curl. Обновить curl до последней версии или принудительно отправлять —force
Curl работает через openssl как правило. Либо стоит обновить openssl, либо сервер, на который вы обращаетесь выдает левый SSL сертификат
-
Показать ещё
Загружается…