How to force TLS 1.3 version in Python

Viewed 3675

I have made Python sockets and am working on server and client Python files respectively. Some codes on the server.py are as below.(Code related to TLS connection)

context = ssl.SSLContext(ssl.PROTOCOL_TLSv1_3) 

When I checked the communication on the wire shark, I always did TLS1.2, so I proceeded with some measures to enforce TLS1.3

#context.options |= ssl.OP_NO_TLSv1 | ssl.OP_NO_TLSv1_1 | ssl.OP_NO_TLSv1_2 # optional
context.options |= ssl.OP_NO_TLSv1
context.options |= ssl.OP_NO_TLSv1_1
context.options |= ssl.OP_NO_TLSv1_2

context.set_ciphers('AES256+ECDH:AES256+EDH') #original

Despite my efforts to enforce TLS1.3, it still continues to communicate with TLS1.2.

print(ssl.HAS_TLSv1)    #TRUE
print(ssl.HAS_TLSv1_1)  #TRUE
print(ssl.HAS_TLSv1_2)  #TRUE
print(ssl.HAS_TLSv1_3)  #TRUE

Like this, I tried to print out to check if ssl supports each version of TLS, but all of them printed "True".

openssl req -new -x509 -days 365 -nodes -out mycert.pem -keyout mycert.pem

The command I used to generate the certificate is as above.

My Openssl version is also 1.1.1(which supports TLS 1.3). Everything seems fine, but I wonder why it still communicates with TLS 1.2. I'd like to know the option to keep the TLS 1.3 connection. enter image description here

0 Answers
Related