@@ -74,13 +74,10 @@ Functions, Constants, and Exceptions
74
74
Socket creation
75
75
^^^^^^^^^^^^^^^
76
76
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
80
79
: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.
84
81
85
82
Client socket example with default context and IPv4/IPv6 dual stack::
86
83
@@ -369,10 +366,10 @@ Certificate handling
369
366
Given the address ``addr `` of an SSL-protected server, as a (*hostname *,
370
367
*port-number *) pair, fetches the server's certificate, and returns it as a
371
368
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
373
370
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
376
373
server certificate against that set of root certificates, and will fail
377
374
if the validation attempt fails. A timeout can be specified with the
378
375
``timeout `` parameter.
@@ -451,33 +448,6 @@ Certificate handling
451
448
452
449
.. versionadded :: 3.4
453
450
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.
481
451
482
452
Constants
483
453
^^^^^^^^^
@@ -488,8 +458,8 @@ Constants
488
458
489
459
.. data :: CERT_NONE
490
460
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 `,
493
463
it is the default mode. With client-side sockets, just about any
494
464
cert is accepted. Validation errors, such as untrusted or expired cert,
495
465
are ignored and do not abort the TLS/SSL handshake.
@@ -501,8 +471,8 @@ Constants
501
471
502
472
.. data :: CERT_OPTIONAL
503
473
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 `
506
476
has the same meaning as :const: `CERT_REQUIRED `. It is recommended to
507
477
use :const: `CERT_REQUIRED ` for client-side sockets instead.
508
478
@@ -513,13 +483,12 @@ Constants
513
483
the TLS handshake.
514
484
515
485
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 `.
518
487
519
488
.. data :: CERT_REQUIRED
520
489
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
523
492
required from the other side of the socket connection; an :class: `SSLError `
524
493
will be raised if no certificate is provided, or if its validation fails.
525
494
This mode is **not ** sufficient to verify a certificate in client mode as
@@ -533,8 +502,7 @@ Constants
533
502
the client must provide a valid and trusted certificate.
534
503
535
504
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 `.
538
506
539
507
.. class :: VerifyMode
540
508
@@ -1327,10 +1295,7 @@ SSL sockets also have the following additional methods and attributes:
1327
1295
1328
1296
.. attribute :: SSLSocket.context
1329
1297
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.
1334
1299
1335
1300
.. versionadded :: 3.2
1336
1301
@@ -2086,7 +2051,7 @@ Combined key and certificate
2086
2051
2087
2052
Often the private key is stored in the same file as the certificate; in this
2088
2053
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
2090
2055
with the certificate, it should come before the first certificate in
2091
2056
the certificate chain::
2092
2057
0 commit comments