bpo-31429: Define TLS cipher suite on build time (#3532) · python/cpython@892d66e (original) (raw)
`@@ -115,6 +115,7 @@
`
115
115
``
116
116
``
117
117
`from _ssl import HAS_SNI, HAS_ECDH, HAS_NPN, HAS_ALPN, HAS_TLSv1_3
`
``
118
`+
from _ssl import _DEFAULT_CIPHERS
`
118
119
`from _ssl import _OPENSSL_API_VERSION
`
119
120
``
120
121
``
174
175
`HAS_NEVER_CHECK_COMMON_NAME = hasattr(_ssl, 'HOSTFLAG_NEVER_CHECK_SUBJECT')
`
175
176
``
176
177
``
177
``
`-
Disable weak or insecure ciphers by default
`
178
``
`-
(OpenSSL's default setting is 'DEFAULT:!aNULL:!eNULL')
`
179
``
`-
Enable a better set of ciphers by default
`
180
``
`-
This list has been explicitly chosen to:
`
181
``
`-
* TLS 1.3 ChaCha20 and AES-GCM cipher suites
`
182
``
`-
* Prefer cipher suites that offer perfect forward secrecy (DHE/ECDHE)
`
183
``
`-
* Prefer ECDHE over DHE for better performance
`
184
``
`-
* Prefer AEAD over CBC for better performance and security
`
185
``
`-
* Prefer AES-GCM over ChaCha20 because most platforms have AES-NI
`
186
``
`-
(ChaCha20 needs OpenSSL 1.1.0 or patched 1.0.2)
`
187
``
`-
* Prefer any AES-GCM and ChaCha20 over any AES-CBC for better
`
188
``
`-
performance and security
`
189
``
`-
* Then Use HIGH cipher suites as a fallback
`
190
``
`-
* Disable NULL authentication, NULL encryption, 3DES and MD5 MACs
`
191
``
`-
for security reasons
`
192
``
`-
_DEFAULT_CIPHERS = (
`
193
``
`-
'TLS13-AES-256-GCM-SHA384:TLS13-CHACHA20-POLY1305-SHA256:'
`
194
``
`-
'TLS13-AES-128-GCM-SHA256:'
`
195
``
`-
'ECDH+AESGCM:ECDH+CHACHA20:DH+AESGCM:DH+CHACHA20:ECDH+AES256:DH+AES256:'
`
196
``
`-
'ECDH+AES128:DH+AES:ECDH+HIGH:DH+HIGH:RSA+AESGCM:RSA+AES:RSA+HIGH:'
`
197
``
`-
'!aNULL:!eNULL:!MD5:!3DES'
`
198
``
`-
)
`
199
``
-
200
``
`-
Restricted and more secure ciphers for the server side
`
201
``
`-
This list has been explicitly chosen to:
`
202
``
`-
* TLS 1.3 ChaCha20 and AES-GCM cipher suites
`
203
``
`-
* Prefer cipher suites that offer perfect forward secrecy (DHE/ECDHE)
`
204
``
`-
* Prefer ECDHE over DHE for better performance
`
205
``
`-
* Prefer AEAD over CBC for better performance and security
`
206
``
`-
* Prefer AES-GCM over ChaCha20 because most platforms have AES-NI
`
207
``
`-
* Prefer any AES-GCM and ChaCha20 over any AES-CBC for better
`
208
``
`-
performance and security
`
209
``
`-
* Then Use HIGH cipher suites as a fallback
`
210
``
`-
* Disable NULL authentication, NULL encryption, MD5 MACs, DSS, RC4, and
`
211
``
`-
3DES for security reasons
`
212
``
`-
_RESTRICTED_SERVER_CIPHERS = (
`
213
``
`-
'TLS13-AES-256-GCM-SHA384:TLS13-CHACHA20-POLY1305-SHA256:'
`
214
``
`-
'TLS13-AES-128-GCM-SHA256:'
`
215
``
`-
'ECDH+AESGCM:ECDH+CHACHA20:DH+AESGCM:DH+CHACHA20:ECDH+AES256:DH+AES256:'
`
216
``
`-
'ECDH+AES128:DH+AES:ECDH+HIGH:DH+HIGH:RSA+AESGCM:RSA+AES:RSA+HIGH:'
`
217
``
`-
'!aNULL:!eNULL:!MD5:!DSS:!RC4:!3DES'
`
218
``
`-
)
`
``
178
`+
_RESTRICTED_SERVER_CIPHERS = _DEFAULT_CIPHERS
`
219
179
``
220
180
`CertificateError = SSLCertVerificationError
`
221
181
``
`@@ -393,8 +353,6 @@ class SSLContext(_SSLContext):
`
393
353
``
394
354
`def new(cls, protocol=PROTOCOL_TLS, *args, **kwargs):
`
395
355
`self = _SSLContext.new(cls, protocol)
`
396
``
`-
if protocol != _SSLv2_IF_EXISTS:
`
397
``
`-
self.set_ciphers(_DEFAULT_CIPHERS)
`
398
356
`return self
`
399
357
``
400
358
`def init(self, protocol=PROTOCOL_TLS):
`
`@@ -530,8 +488,6 @@ def create_default_context(purpose=Purpose.SERVER_AUTH, *, cafile=None,
`
530
488
`# verify certs and host name in client mode
`
531
489
`context.verify_mode = CERT_REQUIRED
`
532
490
`context.check_hostname = True
`
533
``
`-
elif purpose == Purpose.CLIENT_AUTH:
`
534
``
`-
context.set_ciphers(_RESTRICTED_SERVER_CIPHERS)
`
535
491
``
536
492
`if cafile or capath or cadata:
`
537
493
`context.load_verify_locations(cafile, capath, cadata)
`