Skip to content

Commit cff1c20

Browse files
vstinnerillia-v
andauthored
gh-94199: Remove ssl.wrap_socket() documentation (#99023)
The function has been removed. In the ssl documentation, replace references to the ssl.wrap_socket() function with references to the ssl.SSLContext.wrap_socket() method. Co-authored-by: Illia Volochii <[email protected]>
1 parent f4adb97 commit cff1c20

File tree

1 file changed

+16
-51
lines changed

1 file changed

+16
-51
lines changed

Doc/library/ssl.rst

+16-51
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,10 @@ Functions, Constants, and Exceptions
7474
Socket creation
7575
^^^^^^^^^^^^^^^
7676

77-
Since Python 3.2 and 2.7.9, it is recommended to use the
78-
:meth:`SSLContext.wrap_socket` of an :class:`SSLContext` instance to wrap
79-
sockets as :class:`SSLSocket` objects. The helper functions
77+
Instances of :class:`SSLSocket` must be created using the
78+
:meth:`SSLContext.wrap_socket` method. The helper function
8079
:func:`create_default_context` returns a new context with secure default
81-
settings. The old :func:`wrap_socket` function is deprecated since it is
82-
both inefficient and has no support for server name indication (SNI) and
83-
hostname matching.
80+
settings.
8481

8582
Client socket example with default context and IPv4/IPv6 dual stack::
8683

@@ -369,10 +366,10 @@ Certificate handling
369366
Given the address ``addr`` of an SSL-protected server, as a (*hostname*,
370367
*port-number*) pair, fetches the server's certificate, and returns it as a
371368
PEM-encoded string. If ``ssl_version`` is specified, uses that version of
372-
the SSL protocol to attempt to connect to the server. If ``ca_certs`` is
369+
the SSL protocol to attempt to connect to the server. If *ca_certs* is
373370
specified, it should be a file containing a list of root certificates, the
374-
same format as used for the same parameter in
375-
:meth:`SSLContext.wrap_socket`. The call will attempt to validate the
371+
same format as used for the *cafile* parameter in
372+
:meth:`SSLContext.load_verify_locations`. The call will attempt to validate the
376373
server certificate against that set of root certificates, and will fail
377374
if the validation attempt fails. A timeout can be specified with the
378375
``timeout`` parameter.
@@ -451,33 +448,6 @@ Certificate handling
451448

452449
.. versionadded:: 3.4
453450

454-
.. function:: wrap_socket(sock, keyfile=None, certfile=None, \
455-
server_side=False, cert_reqs=CERT_NONE, ssl_version=PROTOCOL_TLS, \
456-
ca_certs=None, do_handshake_on_connect=True, \
457-
suppress_ragged_eofs=True, ciphers=None)
458-
459-
Takes an instance ``sock`` of :class:`socket.socket`, and returns an instance
460-
of :class:`ssl.SSLSocket`, a subtype of :class:`socket.socket`, which wraps
461-
the underlying socket in an SSL context. ``sock`` must be a
462-
:data:`~socket.SOCK_STREAM` socket; other socket types are unsupported.
463-
464-
Internally, function creates a :class:`SSLContext` with protocol
465-
*ssl_version* and :attr:`SSLContext.options` set to *cert_reqs*. If
466-
parameters *keyfile*, *certfile*, *ca_certs* or *ciphers* are set, then
467-
the values are passed to :meth:`SSLContext.load_cert_chain`,
468-
:meth:`SSLContext.load_verify_locations`, and
469-
:meth:`SSLContext.set_ciphers`.
470-
471-
The arguments *server_side*, *do_handshake_on_connect*, and
472-
*suppress_ragged_eofs* have the same meaning as
473-
:meth:`SSLContext.wrap_socket`.
474-
475-
.. deprecated:: 3.7
476-
477-
Since Python 3.2 and 2.7.9, it is recommended to use the
478-
:meth:`SSLContext.wrap_socket` instead of :func:`wrap_socket`. The
479-
top-level function is limited and creates an insecure client socket
480-
without server name indication or hostname matching.
481451

482452
Constants
483453
^^^^^^^^^
@@ -488,8 +458,8 @@ Constants
488458

489459
.. data:: CERT_NONE
490460

491-
Possible value for :attr:`SSLContext.verify_mode`, or the ``cert_reqs``
492-
parameter to :func:`wrap_socket`. Except for :const:`PROTOCOL_TLS_CLIENT`,
461+
Possible value for :attr:`SSLContext.verify_mode`.
462+
Except for :const:`PROTOCOL_TLS_CLIENT`,
493463
it is the default mode. With client-side sockets, just about any
494464
cert is accepted. Validation errors, such as untrusted or expired cert,
495465
are ignored and do not abort the TLS/SSL handshake.
@@ -501,8 +471,8 @@ Constants
501471

502472
.. data:: CERT_OPTIONAL
503473

504-
Possible value for :attr:`SSLContext.verify_mode`, or the ``cert_reqs``
505-
parameter to :func:`wrap_socket`. In client mode, :const:`CERT_OPTIONAL`
474+
Possible value for :attr:`SSLContext.verify_mode`.
475+
In client mode, :const:`CERT_OPTIONAL`
506476
has the same meaning as :const:`CERT_REQUIRED`. It is recommended to
507477
use :const:`CERT_REQUIRED` for client-side sockets instead.
508478

@@ -513,13 +483,12 @@ Constants
513483
the TLS handshake.
514484

515485
Use of this setting requires a valid set of CA certificates to
516-
be passed, either to :meth:`SSLContext.load_verify_locations` or as a
517-
value of the ``ca_certs`` parameter to :func:`wrap_socket`.
486+
be passed to :meth:`SSLContext.load_verify_locations`.
518487

519488
.. data:: CERT_REQUIRED
520489

521-
Possible value for :attr:`SSLContext.verify_mode`, or the ``cert_reqs``
522-
parameter to :func:`wrap_socket`. In this mode, certificates are
490+
Possible value for :attr:`SSLContext.verify_mode`.
491+
In this mode, certificates are
523492
required from the other side of the socket connection; an :class:`SSLError`
524493
will be raised if no certificate is provided, or if its validation fails.
525494
This mode is **not** sufficient to verify a certificate in client mode as
@@ -533,8 +502,7 @@ Constants
533502
the client must provide a valid and trusted certificate.
534503

535504
Use of this setting requires a valid set of CA certificates to
536-
be passed, either to :meth:`SSLContext.load_verify_locations` or as a
537-
value of the ``ca_certs`` parameter to :func:`wrap_socket`.
505+
be passed to :meth:`SSLContext.load_verify_locations`.
538506

539507
.. class:: VerifyMode
540508

@@ -1327,10 +1295,7 @@ SSL sockets also have the following additional methods and attributes:
13271295

13281296
.. attribute:: SSLSocket.context
13291297

1330-
The :class:`SSLContext` object this SSL socket is tied to. If the SSL
1331-
socket was created using the deprecated :func:`wrap_socket` function
1332-
(rather than :meth:`SSLContext.wrap_socket`), this is a custom context
1333-
object created for this SSL socket.
1298+
The :class:`SSLContext` object this SSL socket is tied to.
13341299

13351300
.. versionadded:: 3.2
13361301

@@ -2086,7 +2051,7 @@ Combined key and certificate
20862051

20872052
Often the private key is stored in the same file as the certificate; in this
20882053
case, only the ``certfile`` parameter to :meth:`SSLContext.load_cert_chain`
2089-
and :func:`wrap_socket` needs to be passed. If the private key is stored
2054+
needs to be passed. If the private key is stored
20902055
with the certificate, it should come before the first certificate in
20912056
the certificate chain::
20922057

0 commit comments

Comments
 (0)