question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

urllib3 v2 (unreleased) negotiates the wrong version of TLS when used with OpenSSL 1.0.2

See original GitHub issue

Subject

urllib3 v2 negotiates the wrong version of TLS when used with OpenSSL 1.0.2

Note: I secretly reported this issue, but was asked to make a public issue instead because this is in an unreleased version

Environment

Python 3.7 on centos 7 dockerfile here: https://gist.github.com/graingert/5013c338991753b059424d1d7a41b875

Steps to Reproduce

# import tlslite.messages
import sys
import ssl
import concurrent.futures
import socket
import urllib3.util
import pprint
import trustme


ca = trustme.CA()
hostname = "test-host.example.org"
server_cert = ca.issue_cert(hostname)


def client(sock):
    ctx = urllib3.util.create_urllib3_context(ssl_minimum_version=ssl.TLSVersion.TLSv1_2)
    ca.configure_trust(ctx)
    with ctx.wrap_socket(sock, server_hostname=hostname) as ssock:
        print(f"client connection made! ssock.cipher()={ssock.cipher()} ssock.version()={ssock.version()}")
        pass

def server(sock):
    ctx = ssl.create_default_context(purpose=ssl.Purpose.CLIENT_AUTH)
    ctx.minimum_version = ssl.TLSVersion.TLSv1
    ctx.maximum_version = ssl.TLSVersion.TLSv1
    ctx.options |= ssl.OP_NO_TLSv1_2 | ssl.OP_NO_TLSv1_1
    print(ctx.options)
    server_cert.configure_cert(ctx)
    with ctx.wrap_socket(sock, server_side=True) as ssock:
        print(f"server connection made! ssock.cipher()={ssock.cipher()} ssock.version()={ssock.version()}")
        pass


def main():
    with concurrent.futures.ThreadPoolExecutor(max_workers=2) as tpe:
        a, b = socket.socketpair()
        with a, b:
            a.settimeout(1)
            b.settimeout(2)
            client_fut = tpe.submit(client, a)
            server_fut = tpe.submit(server, b)
            for fut in concurrent.futures.as_completed([client_fut, server_fut]):
                fut.result()


if __name__ == "__main__":
    sys.exit(main())

Expected Behavior

Traceback (most recent call last):
  File "/home/graingert/projects/py37-old-ssl/demo.py", line 48, in <module>
    sys.exit(main())
  File "/home/graingert/projects/py37-old-ssl/demo.py", line 44, in main
    fut.result()
  File "/usr/lib/python3.10/concurrent/futures/_base.py", line 439, in result
    return self.__get_result()
  File "/usr/lib/python3.10/concurrent/futures/_base.py", line 391, in __get_result
    raise self._exception
  File "/usr/lib/python3.10/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/home/graingert/projects/py37-old-ssl/demo.py", line 30, in server
    with ctx.wrap_socket(sock, server_side=True) as ssock:
  File "/usr/lib/python3.10/ssl.py", line 512, in wrap_socket
    return self.sslsocket_class._create(
  File "/usr/lib/python3.10/ssl.py", line 1070, in _create
    self.do_handshake()
  File "/usr/lib/python3.10/ssl.py", line 1341, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLError: [SSL] internal error (_ssl.c:997)

Actual Behavior

Options.OP_ALL|OP_NO_TLSv1_1|OP_NO_TLSv1_2|OP_NO_SSLv3|OP_NO_SSLv2|OP_CIPHER_SERVER_PREFERENCE|OP_SINGLE_DH_USE|OP_SINGLE_ECDH_USE|OP_NO_COMPRESSION
server connection made! ssock.cipher()=('ECDHE-RSA-AES256-SHA', 'TLSv1/SSLv3', 256) ssock.version()=TLSv1
client connection made! ssock.cipher()=('ECDHE-RSA-AES256-SHA', 'TLSv1/SSLv3', 256) ssock.version()=TLSv1
Removing intermediate container 4123de09e3b3

this is because ssl.SSLContext.minimum_version is silently ignored in Python3.7 when running on openssl 1.0.2

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:11 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
sethmlarsoncommented, Jul 5, 2022
0reactions
sethmlarsoncommented, Jun 28, 2022

Now that we’ve changed https://github.com/urllib3/urllib3/issues/2168 to drop OpenSSL <1.1.1 I’m not sure this will be needed for v2.0.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Changelog - urllib3 2.0.0a2 documentation
Changed the error raised when connecting via HTTPS when the ssl module isn't available from SSLError to ImportError (#2589). Changed HTTPConnection.request() to ...
Read more >
urllib3 [python-library] - Occam :: Details
Deprecated negotiating TLSv1 and TLSv1.1 by default. Users that still wish to use TLS earlier than 1.2 without a deprecation warning should opt-in ......
Read more >
Python requests library using TLSv1 or TLSv1.1 despite ...
1. To do this, I configured my https server to force the SSL protocol to use either TLSv1 or TLSv1. 1. I expected...
Read more >
Rehash: How to Fix the SSL/TLS Handshake Failed Error
Authenticates the server as the rightful owner of the asymmetric public/private key pair. Determines the TLS version and cipher suite that will be...
Read more >
SSL/TLS Client - OpenSSLWiki
Using this method will negotiate the highest protocol version supported by both the server and the client. SSL/TLS versions currently supported by OpenSSL...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found