Search code examples
pythonssltls1.3

AttributeError: module 'ssl' has no attribute 'PROTOCOL_TLSv1_3'


I am trying to setup a tls context in python. I want to force TLSv1.3 usng:

context = ssl.SSLContext(ssl.PROTOCOL_TLSv1_3)

This does not work as I receive the following error:

AttributeError: module 'ssl' has no attribute 'PROTOCOL_TLSv1_3'

I am on Ubuntu 20.04 and am using python version 3.8 and openssl version 1.1.1f.

Why doesn't it support TLSv1.3?


Solution

  • TLS 1.3 protocol will be available with PROTOCOL_TLS in OpenSSL >= 1.1.1. There is no dedicated PROTOCOL constant for just TLS 1.3.

    https://docs.python.org/3.11/library/ssl.html#ssl.SSLContext

    Footnote 3.

    According to the protocol version description, this is how you set TLS 1.3 as the minimum version supported:

    client_context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
    client_context.minimum_version = ssl.TLSVersion.TLSv1_3
    client_context.maximum_version = ssl.TLSVersion.TLSv1_3
    

    https://docs.python.org/3.11/library/ssl.html#protocol-versions

    https://docs.python.org/3.11/library/ssl.html#tls-1-3