Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 79ccaa2

Browse files
committed
Issue #20995: Enhance default ciphers used by the ssl module
Closes #20995 by Enabling better security by prioritizing ciphers such that: * Prefer cipher suites that offer perfect forward secrecy (DHE/ECDHE) * Prefer ECDHE over DHE for better performance * Prefer any AES-GCM over any AES-CBC for better performance and security * Then Use HIGH cipher suites as a fallback * Then Use 3DES as fallback which is secure but slow * Finally use RC4 as a fallback which is problematic but needed for compatibility some times. * Disable NULL authentication, NULL encryption, and MD5 MACs for security reasons
1 parent 51f3129 commit 79ccaa2

3 files changed

Lines changed: 38 additions & 19 deletions

File tree

Doc/library/ssl.rst

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1665,17 +1665,10 @@ If you have advanced security requirements, fine-tuning of the ciphers
16651665
enabled when negotiating a SSL session is possible through the
16661666
:meth:`SSLContext.set_ciphers` method. Starting from Python 3.2.3, the
16671667
ssl module disables certain weak ciphers by default, but you may want
1668-
to further restrict the cipher choice. For example::
1669-
1670-
context = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
1671-
context.set_ciphers('HIGH:!aNULL:!eNULL')
1672-
1673-
The ``!aNULL:!eNULL`` part of the cipher spec is necessary to disable ciphers
1674-
which don't provide both encryption and authentication. Be sure to read
1675-
OpenSSL's documentation about the `cipher list
1676-
format <http://www.openssl.org/docs/apps/ciphers.html#CIPHER_LIST_FORMAT>`_.
1677-
If you want to check which ciphers are enabled by a given cipher list,
1678-
use the ``openssl ciphers`` command on your system.
1668+
to further restrict the cipher choice. Be sure to read OpenSSL's documentation
1669+
about the `cipher list format <http://www.openssl.org/docs/apps/ciphers.html#CIPHER_LIST_FORMAT>`_.
1670+
If you want to check which ciphers are enabled by a given cipher list, use the
1671+
``openssl ciphers`` command on your system.
16791672

16801673
Multi-processing
16811674
^^^^^^^^^^^^^^^^

Lib/ssl.py

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -162,14 +162,37 @@ def _import_symbols(prefix):
162162

163163
# Disable weak or insecure ciphers by default
164164
# (OpenSSL's default setting is 'DEFAULT:!aNULL:!eNULL')
165-
_DEFAULT_CIPHERS = 'DEFAULT:!aNULL:!eNULL:!LOW:!EXPORT:!SSLv2'
166-
167-
# restricted and more secure ciphers
168-
# HIGH: high encryption cipher suites with key length >= 128 bits (no MD5)
169-
# !aNULL: only authenticated cipher suites (no anonymous DH)
170-
# !RC4: no RC4 streaming cipher, RC4 is broken
171-
# !DSS: RSA is preferred over DSA
172-
_RESTRICTED_CIPHERS = 'HIGH:!aNULL:!RC4:!DSS'
165+
# Enable a better set of ciphers by default
166+
# This list has been explicitly chosen to:
167+
# * Prefer cipher suites that offer perfect forward secrecy (DHE/ECDHE)
168+
# * Prefer ECDHE over DHE for better performance
169+
# * Prefer any AES-GCM over any AES-CBC for better performance and security
170+
# * Then Use HIGH cipher suites as a fallback
171+
# * Then Use 3DES as fallback which is secure but slow
172+
# * Finally use RC4 as a fallback which is problematic but needed for
173+
# compatibility some times.
174+
# * Disable NULL authentication, NULL encryption, and MD5 MACs for security
175+
# reasons
176+
_DEFAULT_CIPHERS = (
177+
'ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+HIGH:'
178+
'DH+HIGH:ECDH+3DES:DH+3DES:RSA+AESGCM:RSA+AES:RSA+HIGH:RSA+3DES:ECDH+RC4:'
179+
'DH+RC4:RSA+RC4:!aNULL:!eNULL:!MD5'
180+
)
181+
182+
# Restricted and more secure ciphers
183+
# This list has been explicitly chosen to:
184+
# * Prefer cipher suites that offer perfect forward secrecy (DHE/ECDHE)
185+
# * Prefer ECDHE over DHE for better performance
186+
# * Prefer any AES-GCM over any AES-CBC for better performance and security
187+
# * Then Use HIGH cipher suites as a fallback
188+
# * Then Use 3DES as fallback which is secure but slow
189+
# * Disable NULL authentication, NULL encryption, MD5 MACs, DSS, and RC4 for
190+
# security reasons
191+
_RESTRICTED_CIPHERS = (
192+
'ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+HIGH:'
193+
'DH+HIGH:ECDH+3DES:DH+3DES:RSA+AESGCM:RSA+AES:RSA+HIGH:RSA+3DES:!aNULL:'
194+
'!eNULL:!MD5:!DSS:!RC4'
195+
)
173196

174197

175198
class CertificateError(ValueError):

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ Core and Builtins
2121
Library
2222
-------
2323

24+
- Issue #20995: Enhance default ciphers used by the ssl module to enable
25+
better security an prioritize perfect forward secrecy.
26+
2427
- Issue #20884: Don't assume that __file__ is defined on importlib.__init__.
2528

2629
- Issue #20879: Delay the initialization of encoding and decoding tables for

0 commit comments

Comments
 (0)