| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -681,19 +681,23 @@ Constants | |||
| 681 | 681 | ||
| 682 | 682 | .. deprecated:: 3.10 | |
| 683 | 683 | ||
| 684 | + TLS clients and servers require different default settings for secure | ||
| 685 | + communication. The generic TLS protocol constant is deprecated in | ||
| 686 | + favor of :data:`PROTOCOL_TLS_CLIENT` and :data:`PROTOCOL_TLS_SERVER`. | ||
| 687 | + | ||
| 684 | 688 | .. data:: PROTOCOL_TLS_CLIENT | |
| 685 | 689 | ||
| 686 | - Auto-negotiate the highest protocol version like :data:`PROTOCOL_TLS`, | ||
| 687 | - but only support client-side :class:`SSLSocket` connections. The protocol | ||
| 688 | - enables :data:`CERT_REQUIRED` and :attr:`~SSLContext.check_hostname` by | ||
| 689 | - default. | ||
| 690 | + Auto-negotiate the highest protocol version that both the client and | ||
| 691 | + server support, and configure the context client-side connections. The | ||
| 692 | + protocol enables :data:`CERT_REQUIRED` and | ||
| 693 | + :attr:`~SSLContext.check_hostname` by default. | ||
| 690 | 694 | ||
| 691 | 695 | .. versionadded:: 3.6 | |
| 692 | 696 | ||
| 693 | 697 | .. data:: PROTOCOL_TLS_SERVER | |
| 694 | 698 | ||
| 695 | - Auto-negotiate the highest protocol version like :data:`PROTOCOL_TLS`, | ||
| 696 | - but only support server-side :class:`SSLSocket` connections. | ||
| 699 | + Auto-negotiate the highest protocol version that both the client and | ||
| 700 | + server support, and configure the context server-side connections. | ||
| 697 | 701 | ||
| 698 | 702 | .. versionadded:: 3.6 | |
| 699 | 703 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1214,18 +1214,11 @@ The ssl module has preliminary support for OpenSSL 3.0.0 and new option | |||
| 1214 | 1214 | :issue:`43789`, and :issue:`43811`.) | |
| 1215 | 1215 | ||
| 1216 | 1216 | Deprecated function and use of deprecated constants now result in | |
| 1217 | - a :exc:`DeprecationWarning`. The following features have been deprecated | ||
| 1218 | - since Python 3.6, Python 3.7, or OpenSSL 1.1.0: | ||
| 1219 | - :data:`~ssl.OP_NO_SSLv2`, :data:`~ssl.OP_NO_SSLv3`, :data:`~ssl.OP_NO_TLSv1`, | ||
| 1220 | - :data:`~ssl.OP_NO_TLSv1_1`, :data:`~ssl.OP_NO_TLSv1_2`, | ||
| 1221 | - :data:`~ssl.OP_NO_TLSv1_3`, :data:`~ssl.PROTOCOL_SSLv2`, | ||
| 1222 | - :data:`~ssl.PROTOCOL_SSLv3`, :data:`~ssl.PROTOCOL_SSLv23`, | ||
| 1223 | - :data:`~ssl.PROTOCOL_TLSv1`, :data:`~ssl.PROTOCOL_TLSv1_1`, | ||
| 1224 | - :data:`~ssl.PROTOCOL_TLSv1_2`, :data:`~ssl.PROTOCOL_TLS`, | ||
| 1225 | - :func:`~ssl.wrap_socket`, :func:`~ssl.match_hostname`, | ||
| 1226 | - :func:`~ssl.RAND_pseudo_bytes`, :func:`~ssl.RAND_egd`, | ||
| 1227 | - :meth:`ssl.SSLSocket.selected_npn_protocol`, | ||
| 1228 | - :meth:`ssl.SSLContext.set_npn_protocols`. | ||
| 1217 | + a :exc:`DeprecationWarning`. :attr:`ssl.SSLContext.options` has | ||
| 1218 | + :data:`~ssl.OP_NO_SSLv2` and :data:`~ssl.OP_NO_SSLv3` set by default and | ||
| 1219 | + therefore cannot warn about setting the flag again. The | ||
| 1220 | + :ref:`deprecation section <whatsnew310-deprecated>` has a list of deprecated | ||
| 1221 | + features. | ||
| 1229 | 1222 | (Contributed by Christian Heimes in :issue:`43880`.) | |
| 1230 | 1223 | ||
| 1231 | 1224 | The ssl module now has more secure default settings. Ciphers without forward | |
@@ -1441,6 +1434,8 @@ Optimizations | |||
| 1441 | 1434 | readers or writers, just like its equivalent classes in :mod:`gzip` and | |
| 1442 | 1435 | :mod:`lzma` have always been. (Contributed by Inada Naoki in :issue:`43785`). | |
| 1443 | 1436 | ||
| 1437 | + .. _whatsnew310-deprecated: | ||
| 1438 | + | ||
| 1444 | 1439 | Deprecated | |
| 1445 | 1440 | ========== | |
| 1446 | 1441 | ||
@@ -1609,6 +1604,30 @@ Deprecated | |||
| 1609 | 1604 | * ``cgi.log()`` is deprecated and slated for removal in Python 3.12. | |
| 1610 | 1605 | (Contributed by Inada Naoki in :issue:`41139`.) | |
| 1611 | 1606 | ||
| 1607 | + * The following :mod:`ssl` features have been deprecated since Python 3.6, | ||
| 1608 | + Python 3.7, or OpenSSL 1.1.0 and will be removed in 3.11: | ||
| 1609 | + | ||
| 1610 | + * :data:`~ssl.OP_NO_SSLv2`, :data:`~ssl.OP_NO_SSLv3`, :data:`~ssl.OP_NO_TLSv1`, | ||
| 1611 | + :data:`~ssl.OP_NO_TLSv1_1`, :data:`~ssl.OP_NO_TLSv1_2`, and | ||
| 1612 | + :data:`~ssl.OP_NO_TLSv1_3` are replaced by | ||
| 1613 | + :attr:`sslSSLContext.minimum_version` and | ||
| 1614 | + :attr:`sslSSLContext.maximum_version`. | ||
| 1615 | + | ||
| 1616 | + * :data:`~ssl.PROTOCOL_SSLv2`, :data:`~ssl.PROTOCOL_SSLv3`, | ||
| 1617 | + :data:`~ssl.PROTOCOL_SSLv23`, :data:`~ssl.PROTOCOL_TLSv1`, | ||
| 1618 | + :data:`~ssl.PROTOCOL_TLSv1_1`, :data:`~ssl.PROTOCOL_TLSv1_2`, and | ||
| 1619 | + :data:`~ssl.PROTOCOL_TLS` are deprecated in favor of | ||
| 1620 | + :data:`~ssl.PROTOCOL_TLS_CLIENT` and :data:`~ssl.PROTOCOL_TLS_SERVER` | ||
| 1621 | + | ||
| 1622 | + * :func:`~ssl.wrap_socket` is replaced by :meth:`ssl.SSLContext.wrap_socket` | ||
| 1623 | + | ||
| 1624 | + * :func:`~ssl.match_hostname` | ||
| 1625 | + | ||
| 1626 | + * :func:`~ssl.RAND_pseudo_bytes`, :func:`~ssl.RAND_egd` | ||
| 1627 | + | ||
| 1628 | + * NPN features like :meth:`ssl.SSLSocket.selected_npn_protocol` and | ||
| 1629 | + :meth:`ssl.SSLContext.set_npn_protocols` are replaced by ALPN. | ||
| 1630 | + | ||
| 1612 | 1631 | .. _whatsnew310-removed: | |
| 1613 | 1632 | ||
| 1614 | 1633 | Removed | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -94,7 +94,7 @@ | |||
| 94 | 94 | import os | |
| 95 | 95 | from collections import namedtuple | |
| 96 | 96 | from enum import Enum as _Enum, IntEnum as _IntEnum, IntFlag as _IntFlag | |
| 97 | - from enum import _simple_enum, _test_simple_enum | ||
| 97 | + from enum import _simple_enum | ||
| 98 | 98 | ||
| 99 | 99 | import _ssl # if we can't import it, let the error propagate | |
| 100 | 100 | ||
@@ -387,7 +387,7 @@ def match_hostname(cert, hostname): | |||
| 387 | 387 | returns nothing. | |
| 388 | 388 | """ | |
| 389 | 389 | warnings.warn( | |
| 390 | - "ssl module: match_hostname() is deprecated", | ||
| 390 | + "ssl.match_hostname() is deprecated", | ||
| 391 | 391 | category=DeprecationWarning, | |
| 392 | 392 | stacklevel=2 | |
| 393 | 393 | ) | |
@@ -492,8 +492,7 @@ class SSLContext(_SSLContext): | |||
| 492 | 492 | def __new__(cls, protocol=None, *args, **kwargs): | |
| 493 | 493 | if protocol is None: | |
| 494 | 494 | warnings.warn( | |
| 495 | - "ssl module: " | ||
| 496 | - "SSLContext() without protocol argument is deprecated.", | ||
| 495 | + "ssl.SSLContext() without protocol argument is deprecated.", | ||
| 497 | 496 | category=DeprecationWarning, | |
| 498 | 497 | stacklevel=2 | |
| 499 | 498 | ) | |
@@ -536,7 +535,11 @@ def wrap_bio(self, incoming, outgoing, server_side=False, | |||
| 536 | 535 | ) | |
| 537 | 536 | ||
| 538 | 537 | def set_npn_protocols(self, npn_protocols): | |
| 539 | - warnings.warn("NPN is deprecated, use ALPN instead", stacklevel=2) | ||
| 538 | + warnings.warn( | ||
| 539 | + "ssl NPN is deprecated, use ALPN instead", | ||
| 540 | + DeprecationWarning, | ||
| 541 | + stacklevel=2 | ||
| 542 | + ) | ||
| 540 | 543 | protos = bytearray() | |
| 541 | 544 | for protocol in npn_protocols: | |
| 542 | 545 | b = bytes(protocol, 'ascii') | |
@@ -940,7 +943,9 @@ def selected_npn_protocol(self): | |||
| 940 | 943 | if a next protocol was not negotiated or if NPN is not supported by one | |
| 941 | 944 | of the peers.""" | |
| 942 | 945 | warnings.warn( | |
| 943 | - "ssl module: NPN is deprecated, use ALPN instead", stacklevel=2 | ||
| 946 | + "ssl NPN is deprecated, use ALPN instead", | ||
| 947 | + DeprecationWarning, | ||
| 948 | + stacklevel=2 | ||
| 944 | 949 | ) | |
| 945 | 950 | ||
| 946 | 951 | def selected_alpn_protocol(self): | |
@@ -1157,7 +1162,9 @@ def getpeercert(self, binary_form=False): | |||
| 1157 | 1162 | def selected_npn_protocol(self): | |
| 1158 | 1163 | self._checkClosed() | |
| 1159 | 1164 | warnings.warn( | |
| 1160 | - "ssl module: NPN is deprecated, use ALPN instead", stacklevel=2 | ||
| 1165 | + "ssl NPN is deprecated, use ALPN instead", | ||
| 1166 | + DeprecationWarning, | ||
| 1167 | + stacklevel=2 | ||
| 1161 | 1168 | ) | |
| 1162 | 1169 | return None | |
| 1163 | 1170 | ||
@@ -1419,7 +1426,7 @@ def wrap_socket(sock, keyfile=None, certfile=None, | |||
| 1419 | 1426 | suppress_ragged_eofs=True, | |
| 1420 | 1427 | ciphers=None): | |
| 1421 | 1428 | warnings.warn( | |
| 1422 | - "ssl module: wrap_socket is deprecated, use SSLContext.wrap_socket()", | ||
| 1429 | + "ssl.wrap_socket() is deprecated, use SSLContext.wrap_socket()", | ||
| 1423 | 1430 | category=DeprecationWarning, | |
| 1424 | 1431 | stacklevel=2 | |
| 1425 | 1432 | ) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1750,7 +1750,7 @@ class MySSLObject(ssl.SSLObject): | |||
| 1750 | 1750 | ||
| 1751 | 1751 | with ctx.wrap_socket(socket.socket(), server_side=True) as sock: | |
| 1752 | 1752 | self.assertIsInstance(sock, MySSLSocket) | |
| 1753 | - obj = ctx.wrap_bio(ssl.MemoryBIO(), ssl.MemoryBIO()) | ||
| 1753 | + obj = ctx.wrap_bio(ssl.MemoryBIO(), ssl.MemoryBIO(), server_side=True) | ||
| 1754 | 1754 | self.assertIsInstance(obj, MySSLObject) | |
| 1755 | 1755 | ||
| 1756 | 1756 | def test_num_tickest(self): | |
@@ -2884,24 +2884,29 @@ def test_echo(self): | |||
| 2884 | 2884 | server_context=client_context, | |
| 2885 | 2885 | chatty=True, connectionchatty=True, | |
| 2886 | 2886 | sni_name=hostname) | |
| 2887 | - self.assertIn('called a function you should not call', | ||
| 2888 | - str(e.exception)) | ||
| 2887 | + self.assertIn( | ||
| 2888 | + 'Cannot create a client socket with a PROTOCOL_TLS_SERVER context', | ||
| 2889 | + str(e.exception) | ||
| 2890 | + ) | ||
| 2889 | 2891 | ||
| 2890 | 2892 | with self.subTest(client=ssl.PROTOCOL_TLS_SERVER, server=ssl.PROTOCOL_TLS_SERVER): | |
| 2891 | 2893 | with self.assertRaises(ssl.SSLError) as e: | |
| 2892 | 2894 | server_params_test(client_context=server_context, | |
| 2893 | 2895 | server_context=server_context, | |
| 2894 | 2896 | chatty=True, connectionchatty=True) | |
| 2895 | - self.assertIn('called a function you should not call', | ||
| 2896 | - str(e.exception)) | ||
| 2897 | + self.assertIn( | ||
| 2898 | + 'Cannot create a client socket with a PROTOCOL_TLS_SERVER context', | ||
| 2899 | + str(e.exception) | ||
| 2900 | + ) | ||
| 2897 | 2901 | ||
| 2898 | 2902 | with self.subTest(client=ssl.PROTOCOL_TLS_CLIENT, server=ssl.PROTOCOL_TLS_CLIENT): | |
| 2899 | 2903 | with self.assertRaises(ssl.SSLError) as e: | |
| 2900 | 2904 | server_params_test(client_context=server_context, | |
| 2901 | 2905 | server_context=client_context, | |
| 2902 | 2906 | chatty=True, connectionchatty=True) | |
| 2903 | - self.assertIn('called a function you should not call', | ||
| 2904 | - str(e.exception)) | ||
| 2907 | + self.assertIn( | ||
| 2908 | + 'Cannot create a client socket with a PROTOCOL_TLS_SERVER context', | ||
| 2909 | + str(e.exception)) | ||
| 2905 | 2910 | ||
| 2906 | 2911 | def test_getpeercert(self): | |
| 2907 | 2912 | if support.verbose: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,2 @@ | |||
| 1 | + Improve :mod:`ssl` module's deprecation messages, error reporting, and | ||
| 2 | + documentation for deprecations. | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -697,10 +697,9 @@ _setSSLError (_sslmodulestate *state, const char *errstr, int errcode, const cha | |||
| 697 | 697 | } | |
| 698 | 698 | ||
| 699 | 699 | static int | |
| 700 | - _ssl_deprecated(const char* name, int stacklevel) { | ||
| 701 | - return PyErr_WarnFormat( | ||
| 702 | - PyExc_DeprecationWarning, stacklevel, | ||
| 703 | - "ssl module: %s is deprecated", name | ||
| 700 | + _ssl_deprecated(const char* msg, int stacklevel) { | ||
| 701 | + return PyErr_WarnEx( | ||
| 702 | + PyExc_DeprecationWarning, msg, stacklevel | ||
| 704 | 703 | ); | |
| 705 | 704 | } | |
| 706 | 705 | ||
@@ -788,6 +787,21 @@ newPySSLSocket(PySSLContext *sslctx, PySocketSockObject *sock, | |||
| 788 | 787 | SSL_CTX *ctx = sslctx->ctx; | |
| 789 | 788 | _PySSLError err = { 0 }; | |
| 790 | 789 | ||
| 790 | + if ((socket_type == PY_SSL_SERVER) && | ||
| 791 | + (sslctx->protocol == PY_SSL_VERSION_TLS_CLIENT)) { | ||
| 792 | + _setSSLError(get_state_ctx(sslctx), | ||
| 793 | + "Cannot create a server socket with a " | ||
| 794 | + "PROTOCOL_TLS_CLIENT context", 0, __FILE__, __LINE__); | ||
| 795 | + return NULL; | ||
| 796 | + } | ||
| 797 | + if ((socket_type == PY_SSL_CLIENT) && | ||
| 798 | + (sslctx->protocol == PY_SSL_VERSION_TLS_SERVER)) { | ||
| 799 | + _setSSLError(get_state_ctx(sslctx), | ||
| 800 | + "Cannot create a client socket with a " | ||
| 801 | + "PROTOCOL_TLS_SERVER context", 0, __FILE__, __LINE__); | ||
| 802 | + return NULL; | ||
| 803 | + } | ||
| 804 | + | ||
| 791 | 805 | self = PyObject_GC_New(PySSLSocket, | |
| 792 | 806 | get_state_ctx(sslctx)->PySSLSocket_Type); | |
| 793 | 807 | if (self == NULL) | |
@@ -2980,36 +2994,36 @@ _ssl__SSLContext_impl(PyTypeObject *type, int proto_version) | |||
| 2980 | 2994 | switch(proto_version) { | |
| 2981 | 2995 | #if defined(SSL3_VERSION) && !defined(OPENSSL_NO_SSL3) | |
| 2982 | 2996 | case PY_SSL_VERSION_SSL3: | |
| 2983 | - PY_SSL_DEPRECATED("PROTOCOL_SSLv3", 2, NULL); | ||
| 2997 | + PY_SSL_DEPRECATED("ssl.PROTOCOL_SSLv3 is deprecated", 2, NULL); | ||
| 2984 | 2998 | method = SSLv3_method(); | |
| 2985 | 2999 | break; | |
| 2986 | 3000 | #endif | |
| 2987 | 3001 | #if (defined(TLS1_VERSION) && \ | |
| 2988 | 3002 | !defined(OPENSSL_NO_TLS1) && \ | |
| 2989 | 3003 | !defined(OPENSSL_NO_TLS1_METHOD)) | |
| 2990 | 3004 | case PY_SSL_VERSION_TLS1: | |
| 2991 | - PY_SSL_DEPRECATED("PROTOCOL_TLSv1", 2, NULL); | ||
| 3005 | + PY_SSL_DEPRECATED("ssl.PROTOCOL_TLSv1 is deprecated", 2, NULL); | ||
| 2992 | 3006 | method = TLSv1_method(); | |
| 2993 | 3007 | break; | |
| 2994 | 3008 | #endif | |
| 2995 | 3009 | #if (defined(TLS1_1_VERSION) && \ | |
| 2996 | 3010 | !defined(OPENSSL_NO_TLS1_1) && \ | |
| 2997 | 3011 | !defined(OPENSSL_NO_TLS1_1_METHOD)) | |
| 2998 | 3012 | case PY_SSL_VERSION_TLS1_1: | |
| 2999 | - PY_SSL_DEPRECATED("PROTOCOL_TLSv1_1", 2, NULL); | ||
| 3013 | + PY_SSL_DEPRECATED("ssl.PROTOCOL_TLSv1_1 is deprecated", 2, NULL); | ||
| 3000 | 3014 | method = TLSv1_1_method(); | |
| 3001 | 3015 | break; | |
| 3002 | 3016 | #endif | |
| 3003 | 3017 | #if (defined(TLS1_2_VERSION) && \ | |
| 3004 | 3018 | !defined(OPENSSL_NO_TLS1_2) && \ | |
| 3005 | 3019 | !defined(OPENSSL_NO_TLS1_2_METHOD)) | |
| 3006 | 3020 | case PY_SSL_VERSION_TLS1_2: | |
| 3007 | - PY_SSL_DEPRECATED("PROTOCOL_TLSv1_2", 2, NULL); | ||
| 3021 | + PY_SSL_DEPRECATED("ssl.PROTOCOL_TLSv1_2 is deprecated", 2, NULL); | ||
| 3008 | 3022 | method = TLSv1_2_method(); | |
| 3009 | 3023 | break; | |
| 3010 | 3024 | #endif | |
| 3011 | 3025 | case PY_SSL_VERSION_TLS: | |
| 3012 | - PY_SSL_DEPRECATED("PROTOCOL_TLS", 2, NULL); | ||
| 3026 | + PY_SSL_DEPRECATED("ssl.PROTOCOL_TLS is deprecated", 2, NULL); | ||
| 3013 | 3027 | method = TLS_method(); | |
| 3014 | 3028 | break; | |
| 3015 | 3029 | case PY_SSL_VERSION_TLS_CLIENT: | |
@@ -3433,13 +3447,13 @@ set_min_max_proto_version(PySSLContext *self, PyObject *arg, int what) | |||
| 3433 | 3447 | /* check for deprecations and supported values */ | |
| 3434 | 3448 | switch(v) { | |
| 3435 | 3449 | case PY_PROTO_SSLv3: | |
| 3436 | - PY_SSL_DEPRECATED("TLSVersion.SSLv3", 2, -1); | ||
| 3450 | + PY_SSL_DEPRECATED("ssl.TLSVersion.SSLv3 is deprecated", 2, -1); | ||
| 3437 | 3451 | break; | |
| 3438 | 3452 | case PY_PROTO_TLSv1: | |
| 3439 | - PY_SSL_DEPRECATED("TLSVersion.TLSv1", 2, -1); | ||
| 3453 | + PY_SSL_DEPRECATED("ssl.TLSVersion.TLSv1 is deprecated", 2, -1); | ||
| 3440 | 3454 | break; | |
| 3441 | 3455 | case PY_PROTO_TLSv1_1: | |
| 3442 | - PY_SSL_DEPRECATED("TLSVersion.TLSv1_1", 2, -1); | ||
| 3456 | + PY_SSL_DEPRECATED("ssl.TLSVersion.TLSv1_1 is deprecated", 2, -1); | ||
| 3443 | 3457 | break; | |
| 3444 | 3458 | case PY_PROTO_MINIMUM_SUPPORTED: | |
| 3445 | 3459 | case PY_PROTO_MAXIMUM_SUPPORTED: | |
@@ -3583,7 +3597,7 @@ set_options(PySSLContext *self, PyObject *arg, void *c) | |||
| 3583 | 3597 | set = ~opts & new_opts; | |
| 3584 | 3598 | ||
| 3585 | 3599 | if ((set & opt_no) != 0) { | |
| 3586 | - if (_ssl_deprecated("Setting OP_NO_SSL* or SSL_NO_TLS* options is " | ||
| 3600 | + if (_ssl_deprecated("ssl.OP_NO_SSL*/ssl.SSL_NO_TLS* options are " | ||
| 3587 | 3601 | "deprecated", 2) < 0) { | |
| 3588 | 3602 | return -1; | |
| 3589 | 3603 | } | |
@@ -5146,7 +5160,7 @@ static PyObject * | |||
| 5146 | 5160 | _ssl_RAND_pseudo_bytes_impl(PyObject *module, int n) | |
| 5147 | 5161 | /*[clinic end generated code: output=b1509e937000e52d input=58312bd53f9bbdd0]*/ | |
| 5148 | 5162 | { | |
| 5149 | - PY_SSL_DEPRECATED("RAND_pseudo_bytes", 1, NULL); | ||
| 5163 | + PY_SSL_DEPRECATED("ssl.RAND_pseudo_bytes() is deprecated", 1, NULL); | ||
| 5150 | 5164 | return PySSL_RAND(module, n, 1); | |
| 5151 | 5165 | } | |
| 5152 | 5166 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments