@@ -178,7 +178,7 @@ instead.
178
178
use. Typically, the server chooses a particular protocol version, and the
179
179
client must adapt to the server's choice. Most of the versions are not
180
180
interoperable with the other versions. If not specified, the default is
181
- :data: `PROTOCOL_SSLv23 `; it provides the most compatibility with other
181
+ :data: `PROTOCOL_TLS `; it provides the most compatibility with other
182
182
versions.
183
183
184
184
Here's a table showing which versions in a client (down the side) can connect
@@ -187,11 +187,11 @@ instead.
187
187
.. table ::
188
188
189
189
======================== ========= ========= ========== ========= =========== ===========
190
- *client * / **server ** **SSLv2 ** **SSLv3 ** **SSLv23 ** **TLSv1 ** **TLSv1.1 ** **TLSv1.2 **
190
+ *client * / **server ** **SSLv2 ** **SSLv3 ** **TLS ** **TLSv1 ** **TLSv1.1 ** **TLSv1.2 **
191
191
------------------------ --------- --------- ---------- --------- ----------- -----------
192
192
*SSLv2 * yes no yes no no no
193
193
*SSLv3 * no yes yes no no no
194
- *SSLv23 * no yes yes yes yes yes
194
+ *TLS * (* SSLv23 *) no yes yes yes yes yes
195
195
*TLSv1 * no no yes yes no no
196
196
*TLSv1.1 * no no yes no yes no
197
197
*TLSv1.2 * no no yes no no yes
@@ -244,7 +244,7 @@ purposes.
244
244
:const: `None `, this function can choose to trust the system's default
245
245
CA certificates instead.
246
246
247
- The settings are: :data: `PROTOCOL_SSLv23 `, :data: `OP_NO_SSLv2 `, and
247
+ The settings are: :data: `PROTOCOL_TLS `, :data: `OP_NO_SSLv2 `, and
248
248
:data: `OP_NO_SSLv3 ` with high encryption cipher suites without RC4 and
249
249
without unauthenticated cipher suites. Passing :data: `~Purpose.SERVER_AUTH `
250
250
as *purpose * sets :data: `~SSLContext.verify_mode ` to :data: `CERT_REQUIRED `
@@ -316,6 +316,11 @@ Random generation
316
316
317
317
.. versionadded :: 3.3
318
318
319
+ .. deprecated :: 3.5.3
320
+
321
+ OpenSSL has deprecated :func: `ssl.RAND_pseudo_bytes `, use
322
+ :func: `ssl.RAND_bytes ` instead.
323
+
319
324
.. function :: RAND_status()
320
325
321
326
Return ``True `` if the SSL pseudo-random number generator has been seeded
@@ -334,7 +339,7 @@ Random generation
334
339
See http://egd.sourceforge.net/ or http://prngd.sourceforge.net/ for sources
335
340
of entropy-gathering daemons.
336
341
337
- Availability: not available with LibreSSL.
342
+ Availability: not available with LibreSSL and OpenSSL > 1.1.0
338
343
339
344
.. function :: RAND_add(bytes, entropy)
340
345
@@ -409,7 +414,7 @@ Certificate handling
409
414
previously. Return an integer (no fractions of a second in the
410
415
input format)
411
416
412
- .. function :: get_server_certificate(addr, ssl_version=PROTOCOL_SSLv23 , ca_certs=None)
417
+ .. function :: get_server_certificate(addr, ssl_version=PROTOCOL_TLS , ca_certs=None)
413
418
414
419
Given the address ``addr `` of an SSL-protected server, as a (*hostname *,
415
420
*port-number *) pair, fetches the server's certificate, and returns it as a
@@ -425,7 +430,7 @@ Certificate handling
425
430
426
431
.. versionchanged :: 3.5
427
432
The default *ssl_version * is changed from :data: `PROTOCOL_SSLv3 ` to
428
- :data: `PROTOCOL_SSLv23 ` for maximum compatibility with modern servers.
433
+ :data: `PROTOCOL_TLS ` for maximum compatibility with modern servers.
429
434
430
435
.. function :: DER_cert_to_PEM_cert(DER_cert_bytes)
431
436
@@ -451,6 +456,9 @@ Certificate handling
451
456
* :attr: `openssl_capath_env ` - OpenSSL's environment key that points to a capath,
452
457
* :attr: `openssl_capath ` - hard coded path to a capath directory
453
458
459
+ Availability: LibreSSL ignores the environment vars
460
+ :attr: `openssl_cafile_env ` and :attr: `openssl_capath_env `
461
+
454
462
.. versionadded :: 3.4
455
463
456
464
.. function :: enum_certificates(store_name)
@@ -568,11 +576,21 @@ Constants
568
576
569
577
.. versionadded :: 3.4.4
570
578
571
- .. data :: PROTOCOL_SSLv23
579
+ .. data :: PROTOCOL_TLS
572
580
573
581
Selects the highest protocol version that both the client and server support.
574
582
Despite the name, this option can select "TLS" protocols as well as "SSL".
575
583
584
+ .. versionadded :: 3.5.3
585
+
586
+ .. data :: PROTOCOL_SSLv23
587
+
588
+ Alias for data:`PROTOCOL_TLS `.
589
+
590
+ .. deprecated :: 3.5.3
591
+
592
+ Use data:`PROTOCOL_TLS ` instead.
593
+
576
594
.. data :: PROTOCOL_SSLv2
577
595
578
596
Selects SSL version 2 as the channel encryption protocol.
@@ -584,6 +602,10 @@ Constants
584
602
585
603
SSL version 2 is insecure. Its use is highly discouraged.
586
604
605
+ .. deprecated :: 3.5.3
606
+
607
+ OpenSSL has removed support for SSLv2.
608
+
587
609
.. data :: PROTOCOL_SSLv3
588
610
589
611
Selects SSL version 3 as the channel encryption protocol.
@@ -595,17 +617,32 @@ Constants
595
617
596
618
SSL version 3 is insecure. Its use is highly discouraged.
597
619
620
+ .. deprecated :: 3.5.3
621
+
622
+ OpenSSL has deprecated all version specific protocols. Use the default
623
+ protocol data:`PROTOCOL_TLS ` with flags like data:`OP_NO_SSLv3 ` instead.
624
+
598
625
.. data :: PROTOCOL_TLSv1
599
626
600
627
Selects TLS version 1.0 as the channel encryption protocol.
601
628
629
+ .. deprecated :: 3.5.3
630
+
631
+ OpenSSL has deprecated all version specific protocols. Use the default
632
+ protocol data:`PROTOCOL_TLS ` with flags like data:`OP_NO_SSLv3 ` instead.
633
+
602
634
.. data :: PROTOCOL_TLSv1_1
603
635
604
636
Selects TLS version 1.1 as the channel encryption protocol.
605
637
Available only with openssl version 1.0.1+.
606
638
607
639
.. versionadded :: 3.4
608
640
641
+ .. deprecated :: 3.5.3
642
+
643
+ OpenSSL has deprecated all version specific protocols. Use the default
644
+ protocol data:`PROTOCOL_TLS ` with flags like data:`OP_NO_SSLv3 ` instead.
645
+
609
646
.. data :: PROTOCOL_TLSv1_2
610
647
611
648
Selects TLS version 1.2 as the channel encryption protocol. This is the
@@ -614,6 +651,11 @@ Constants
614
651
615
652
.. versionadded :: 3.4
616
653
654
+ .. deprecated :: 3.5.3
655
+
656
+ OpenSSL has deprecated all version specific protocols. Use the default
657
+ protocol data:`PROTOCOL_TLS ` with flags like data:`OP_NO_SSLv3 ` instead.
658
+
617
659
.. data :: OP_ALL
618
660
619
661
Enables workarounds for various bugs present in other SSL implementations.
@@ -625,39 +667,48 @@ Constants
625
667
.. data :: OP_NO_SSLv2
626
668
627
669
Prevents an SSLv2 connection. This option is only applicable in
628
- conjunction with :const: `PROTOCOL_SSLv23 `. It prevents the peers from
670
+ conjunction with :const: `PROTOCOL_TLS `. It prevents the peers from
629
671
choosing SSLv2 as the protocol version.
630
672
631
673
.. versionadded :: 3.2
632
674
675
+ .. deprecated :: 3.5.3
676
+
677
+ SSLv2 is deprecated
678
+
679
+
633
680
.. data :: OP_NO_SSLv3
634
681
635
682
Prevents an SSLv3 connection. This option is only applicable in
636
- conjunction with :const: `PROTOCOL_SSLv23 `. It prevents the peers from
683
+ conjunction with :const: `PROTOCOL_TLS `. It prevents the peers from
637
684
choosing SSLv3 as the protocol version.
638
685
639
686
.. versionadded :: 3.2
640
687
688
+ .. deprecated :: 3.5.3
689
+
690
+ SSLv3 is deprecated
691
+
641
692
.. data :: OP_NO_TLSv1
642
693
643
694
Prevents a TLSv1 connection. This option is only applicable in
644
- conjunction with :const: `PROTOCOL_SSLv23 `. It prevents the peers from
695
+ conjunction with :const: `PROTOCOL_TLS `. It prevents the peers from
645
696
choosing TLSv1 as the protocol version.
646
697
647
698
.. versionadded :: 3.2
648
699
649
700
.. data :: OP_NO_TLSv1_1
650
701
651
702
Prevents a TLSv1.1 connection. This option is only applicable in conjunction
652
- with :const: `PROTOCOL_SSLv23 `. It prevents the peers from choosing TLSv1.1 as
703
+ with :const: `PROTOCOL_TLS `. It prevents the peers from choosing TLSv1.1 as
653
704
the protocol version. Available only with openssl version 1.0.1+.
654
705
655
706
.. versionadded :: 3.4
656
707
657
708
.. data :: OP_NO_TLSv1_2
658
709
659
710
Prevents a TLSv1.2 connection. This option is only applicable in conjunction
660
- with :const: `PROTOCOL_SSLv23 `. It prevents the peers from choosing TLSv1.2 as
711
+ with :const: `PROTOCOL_TLS `. It prevents the peers from choosing TLSv1.2 as
661
712
the protocol version. Available only with openssl version 1.0.1+.
662
713
663
714
.. versionadded :: 3.4
@@ -1081,17 +1132,21 @@ such as SSL configuration options, certificate(s) and private key(s).
1081
1132
It also manages a cache of SSL sessions for server-side sockets, in order
1082
1133
to speed up repeated connections from the same clients.
1083
1134
1084
- .. class :: SSLContext(protocol)
1135
+ .. class :: SSLContext(protocol=PROTOCOL_TLS )
1085
1136
1086
- Create a new SSL context. You must pass *protocol * which must be one
1137
+ Create a new SSL context. You may pass *protocol * which must be one
1087
1138
of the ``PROTOCOL_* `` constants defined in this module.
1088
- :data: `PROTOCOL_SSLv23 ` is currently recommended for maximum
1089
- interoperability.
1139
+ :data: `PROTOCOL_TLS ` is currently recommended for maximum
1140
+ interoperability and default value .
1090
1141
1091
1142
.. seealso ::
1092
1143
:func: `create_default_context ` lets the :mod: `ssl ` module choose
1093
1144
security settings for a given purpose.
1094
1145
1146
+ .. versionchanged :: 3.5.3
1147
+
1148
+ :data: `PROTOCOL_TLS ` is the default value.
1149
+
1095
1150
1096
1151
:class: `SSLContext ` objects have the following methods and attributes:
1097
1152
@@ -1232,6 +1287,9 @@ to speed up repeated connections from the same clients.
1232
1287
This method will raise :exc: `NotImplementedError ` if :data: `HAS_ALPN ` is
1233
1288
False.
1234
1289
1290
+ OpenSSL 1.1.0+ will abort the handshake and raise :exc: `SSLError ` when
1291
+ both sides support ALPN but cannot agree on a protocol.
1292
+
1235
1293
.. versionadded :: 3.5
1236
1294
1237
1295
.. method :: SSLContext.set_npn_protocols(protocols)
@@ -1598,7 +1656,7 @@ If you prefer to tune security settings yourself, you might create
1598
1656
a context from scratch (but beware that you might not get the settings
1599
1657
right)::
1600
1658
1601
- >>> context = ssl.SSLContext(ssl.PROTOCOL_SSLv23 )
1659
+ >>> context = ssl.SSLContext(ssl.PROTOCOL_TLS )
1602
1660
>>> context.verify_mode = ssl.CERT_REQUIRED
1603
1661
>>> context.check_hostname = True
1604
1662
>>> context.load_verify_locations("/etc/ssl/certs/ca-bundle.crt")
@@ -1999,15 +2057,17 @@ Protocol versions
1999
2057
2000
2058
SSL versions 2 and 3 are considered insecure and are therefore dangerous to
2001
2059
use. If you want maximum compatibility between clients and servers, it is
2002
- recommended to use :const: `PROTOCOL_SSLv23 ` as the protocol version and then
2060
+ recommended to use :const: `PROTOCOL_TLS ` as the protocol version and then
2003
2061
disable SSLv2 and SSLv3 explicitly using the :data: `SSLContext.options `
2004
2062
attribute::
2005
2063
2006
- context = ssl.SSLContext(ssl.PROTOCOL_SSLv23 )
2064
+ context = ssl.SSLContext(ssl.PROTOCOL_TLS )
2007
2065
context.options |= ssl.OP_NO_SSLv2
2008
2066
context.options |= ssl.OP_NO_SSLv3
2067
+ context.options |= ssl.OP_NO_TLSv1
2068
+ context.options |= ssl.OP_NO_TLSv1_1
2009
2069
2010
- The SSL context created above will only allow TLSv1 and later (if
2070
+ The SSL context created above will only allow TLSv1.2 and later (if
2011
2071
supported by your system) connections.
2012
2072
2013
2073
Cipher selection
0 commit comments