pyopenssl icon indicating copy to clipboard operation
pyopenssl copied to clipboard

TLSv1 handshake failure when called do_handshake() error : OpenSSL.SSL.Error: [('SSL routines', '', 'no protocols available')]

Open ratnapolepalli opened this issue 2 years ago • 1 comments

Details : Python 3.9.16 openssl version : OpenSSL 1.1.1v 1 Aug 2023 (Library: OpenSSL 1.1.1k FIPS 25 Mar 2021) pyOpenSSL==23.2.0

Info: I am trying to connect to my server using tlsv1 protocol, but facing error as

Traceback (most recent call last): File "/root/test/test_tlsv1.py", line 29, in ssl_connection(host, port) File "/root/test/test_tlsv1.py", line 14, in ssl_connection ssl_sock.do_handshake() File "/usr/local/lib/python3.9/site-packages/OpenSSL/SSL.py", line 2182, in do_handshake self._raise_ssl_error(self._ssl, result) File "/usr/local/lib/python3.9/site-packages/OpenSSL/SSL.py", line 1823, in _raise_ssl_error _openssl_assert( File "/usr/local/lib/python3.9/site-packages/OpenSSL/_util.py", line 71, in openssl_assert exception_from_error_queue(error) File "/usr/local/lib/python3.9/site-packages/OpenSSL/_util.py", line 57, in exception_from_error_queue raise exception_type(errors) OpenSSL.SSL.Error: [('SSL routines', '', 'no protocols available')]

Python script I am using

from OpenSSL import SSL
import socket

def ssl_connection(host, port):
    try:
        context = SSL.Context(SSL.TLSv1_METHOD)
        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        ssl_sock = SSL.Connection(context, sock)
    except Exception as e:
        print(e)
    ssl_sock.connect((host, port))
    ssl_sock.do_handshake()

    print("Connected to:", ssl_sock.getpeername())

    # Send and receive data
    ssl_sock.send(b"Hello, server!")
    data = ssl_sock.recv(1024)
    print("Received:", data)

    ssl_sock.shutdown()
    ssl_sock.close()

if __name__ == "__main__":
    host = "10.10.55.40"
    port = 20166
    ssl_connection(host, port)

Note: When I am using TLSv1_2 method it is working fine. My usecase is need to test with TLSv1 , TLSv1_1 and TLSv1_2 protocols.

Request to let me know how can I fix this issue. Let me know if need any detials

ratnapolepalli avatar Aug 20 '23 13:08 ratnapolepalli

Here adding some information to the bug

[root@2de2a940-f152-4a38-809b-6671313f8389 (test) ~]# python -m OpenSSL.debug
pyOpenSSL: 23.2.0
cryptography: 41.0.3
cffi: 1.15.1
cryptography's compiled against OpenSSL: OpenSSL 3.1.2 1 Aug 2023
cryptography's linked OpenSSL: OpenSSL 3.1.2 1 Aug 2023
Python's OpenSSL: OpenSSL 1.1.1k  FIPS 25 Mar 2021
Python executable: /usr/bin/python
Python version: 3.9.16 (main, Jul  4 2023, 06:14:41)
[GCC 8.5.0 20210514 (Red Hat 8.5.0-18.0.2)]
Platform: linux
sys.path: ['/root', '/usr/local/ite/lib/python', '/usr/local/staf/lib', '/root/static/support/lib/python', '/root/support/lib/python', '/root/testcaseRoot/default/lib', '/root', '/usr/lib64/python39.zip', '/usr/lib64/python3.9', '/usr/lib64/python3.9/lib-dynload', '/usr/local/lib64/python3.9/site-packages', '/usr/local/lib/python3.9/site-packages', '/usr/lib64/python3.9/site-packages', '/usr/lib/python3.9/site-packages']
[root@2de2a940-f152-4a38-809b-6671313f8389 (test) ~]#

[root@2de2a940-f152-4a38-809b-6671313f8389 (test) ~]# uname -a
Linux 2de2a940-f152-4a38-809b-6671313f8389 4.18.0-477.15.1.el8_8.x86_64 #1 SMP Thu Jul 20 11:31:48 PDT 2023 x86_64 x86_64 x86_64 GNU/Linux

vkosuri avatar Aug 20 '23 13:08 vkosuri