@@ -25,8 +25,8 @@ probably additional platforms, as long as OpenSSL is installed on that platform.
2525
2626 Some behavior may be platform dependent, since calls are made to the
2727 operating system socket APIs. The installed version of OpenSSL may also
28- cause variations in behavior. For example, TLSv1.1 and TLSv1.2 come with
29- openssl version 1.0 .1.
28+ cause variations in behavior. For example, TLSv1.3 with OpenSSL version
29+ 1.1 .1.
3030
3131.. warning ::
3232 Don't use this module without reading the :ref: `ssl-security `. Doing so
@@ -63,6 +63,8 @@ by SSL sockets created through the :meth:`SSLContext.wrap_socket` method.
6363 :pep: `644 ` has been implemented. The ssl module requires OpenSSL 1.1.1
6464 or newer.
6565
66+ Use of deprecated constants and functions result in deprecation warnings.
67+
6668
6769Functions, Constants, and Exceptions
6870------------------------------------
@@ -136,8 +138,9 @@ purposes.
136138 :const: `None `, this function can choose to trust the system's default
137139 CA certificates instead.
138140
139- The settings are: :data: `PROTOCOL_TLS `, :data: `OP_NO_SSLv2 `, and
140- :data: `OP_NO_SSLv3 ` with high encryption cipher suites without RC4 and
141+ The settings are: :data: `PROTOCOL_TLS_CLIENT ` or
142+ :data: `PROTOCOL_TLS_SERVER `, :data: `OP_NO_SSLv2 `, and :data: `OP_NO_SSLv3 `
143+ with high encryption cipher suites without RC4 and
141144 without unauthenticated cipher suites. Passing :data: `~Purpose.SERVER_AUTH `
142145 as *purpose * sets :data: `~SSLContext.verify_mode ` to :data: `CERT_REQUIRED `
143146 and either loads CA certificates (when at least one of *cafile *, *capath * or
@@ -185,6 +188,12 @@ purposes.
185188
186189 Support for key logging to :envvar: `SSLKEYLOGFILE ` was added.
187190
191+ .. versionchanged :: 3.10
192+
193+ The context now uses :data: `PROTOCOL_TLS_CLIENT ` or
194+ :data: `PROTOCOL_TLS_SERVER ` protocol instead of generic
195+ :data: `PROTOCOL_TLS `.
196+
188197
189198Exceptions
190199^^^^^^^^^^
@@ -417,7 +426,7 @@ Certificate handling
417426 previously. Return an integer (no fractions of a second in the
418427 input format)
419428
420- .. function :: get_server_certificate(addr, ssl_version=PROTOCOL_TLS , ca_certs=None)
429+ .. function :: get_server_certificate(addr, ssl_version=PROTOCOL_TLS_CLIENT , ca_certs=None)
421430
422431 Given the address ``addr `` of an SSL-protected server, as a (*hostname *,
423432 *port-number *) pair, fetches the server's certificate, and returns it as a
@@ -654,6 +663,8 @@ Constants
654663
655664 .. versionadded :: 3.6
656665
666+ .. deprecated :: 3.10
667+
657668.. data :: PROTOCOL_TLS_CLIENT
658669
659670 Auto-negotiate the highest protocol version like :data: `PROTOCOL_TLS `,
@@ -707,16 +718,18 @@ Constants
707718 .. deprecated :: 3.6
708719
709720 OpenSSL has deprecated all version specific protocols. Use the default
710- protocol :data: `PROTOCOL_TLS ` with flags like :data: `OP_NO_SSLv3 ` instead.
721+ protocol :data: `PROTOCOL_TLS_SERVER ` or :data: `PROTOCOL_TLS_CLIENT `
722+ with :attr: `SSLContext.minimum_version ` and
723+ :attr: `SSLContext.maximum_version ` instead.
724+
711725
712726.. data :: PROTOCOL_TLSv1
713727
714728 Selects TLS version 1.0 as the channel encryption protocol.
715729
716730 .. deprecated :: 3.6
717731
718- OpenSSL has deprecated all version specific protocols. Use the default
719- protocol :data: `PROTOCOL_TLS ` with flags like :data: `OP_NO_SSLv3 ` instead.
732+ OpenSSL has deprecated all version specific protocols.
720733
721734.. data :: PROTOCOL_TLSv1_1
722735
@@ -727,8 +740,7 @@ Constants
727740
728741 .. deprecated :: 3.6
729742
730- OpenSSL has deprecated all version specific protocols. Use the default
731- protocol :data: `PROTOCOL_TLS ` with flags like :data: `OP_NO_SSLv3 ` instead.
743+ OpenSSL has deprecated all version specific protocols.
732744
733745.. data :: PROTOCOL_TLSv1_2
734746
@@ -739,8 +751,7 @@ Constants
739751
740752 .. deprecated :: 3.6
741753
742- OpenSSL has deprecated all version specific protocols. Use the default
743- protocol :data: `PROTOCOL_TLS ` with flags like :data: `OP_NO_SSLv3 ` instead.
754+ OpenSSL has deprecated all version specific protocols.
744755
745756.. data :: OP_ALL
746757
@@ -762,7 +773,6 @@ Constants
762773
763774 SSLv2 is deprecated
764775
765-
766776.. data :: OP_NO_SSLv3
767777
768778 Prevents an SSLv3 connection. This option is only applicable in
@@ -1068,6 +1078,11 @@ Constants
10681078
10691079 SSL 3.0 to TLS 1.3.
10701080
1081+ .. deprecated :: 3.10
1082+
1083+ All :class: `TLSVersion ` members except :attr: `TLSVersion.TLSv1_2 ` and
1084+ :attr: `TLSVersion.TLSv1_3 ` are deprecated.
1085+
10711086
10721087SSL Sockets
10731088-----------
@@ -1423,7 +1438,7 @@ such as SSL configuration options, certificate(s) and private key(s).
14231438It also manages a cache of SSL sessions for server-side sockets, in order
14241439to speed up repeated connections from the same clients.
14251440
1426- .. class :: SSLContext(protocol=PROTOCOL_TLS )
1441+ .. class :: SSLContext(protocol=None )
14271442
14281443 Create a new SSL context. You may pass *protocol * which must be one
14291444 of the ``PROTOCOL_* `` constants defined in this module. The parameter
@@ -1472,6 +1487,12 @@ to speed up repeated connections from the same clients.
14721487 ciphers, no ``NULL `` ciphers and no ``MD5 `` ciphers (except for
14731488 :data: `PROTOCOL_SSLv2 `).
14741489
1490+ .. deprecated :: 3.10
1491+
1492+ :class: `SSLContext ` without protocol argument is deprecated. The
1493+ context class will either require :data: `PROTOCOL_TLS_CLIENT ` or
1494+ :data: `PROTOCOL_TLS_SERVER ` protocol in the future.
1495+
14751496
14761497:class: `SSLContext ` objects have the following methods and attributes:
14771498
@@ -1934,7 +1955,7 @@ to speed up repeated connections from the same clients.
19341955.. attribute :: SSLContext.num_tickets
19351956
19361957 Control the number of TLS 1.3 session tickets of a
1937- :attr: `TLS_PROTOCOL_SERVER ` context. The setting has no impact on TLS
1958+ :attr: `PROTOCOL_TLS_SERVER ` context. The setting has no impact on TLS
19381959 1.0 to 1.2 connections.
19391960
19401961 .. versionadded :: 3.8
@@ -1951,6 +1972,12 @@ to speed up repeated connections from the same clients.
19511972 >>> ssl.create_default_context().options # doctest: +SKIP
19521973 <Options.OP_ALL|OP_NO_SSLv3|OP_NO_SSLv2|OP_NO_COMPRESSION: 2197947391>
19531974
1975+ .. deprecated :: 3.7
1976+
1977+ All ``OP_NO_SSL* `` and ``OP_NO_TLS* `` options have been deprecated since
1978+ Python 3.7. Use :attr: `SSLContext.minimum_version ` and
1979+ :attr: `SSLContext.maximum_version ` instead.
1980+
19541981.. attribute :: SSLContext.post_handshake_auth
19551982
19561983 Enable TLS 1.3 post-handshake client authentication. Post-handshake auth
@@ -2623,8 +2650,8 @@ disabled by default.
26232650::
26242651
26252652 >>> client_context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
2626- >>> client_context.options | = ssl.OP_NO_TLSv1
2627- >>> client_context.options | = ssl.OP_NO_TLSv1_1
2653+ >>> client_context.minimum_version = ssl.TLSVersion.TLSv1_3
2654+ >>> client_context.maximum_version = ssl.TLSVersion.TLSv1_3
26282655
26292656
26302657The SSL context created above will only allow TLSv1.2 and later (if
0 commit comments