@@ -179,7 +179,7 @@ def _import_symbols(prefix):
179179 'DH+RC4:RSA+RC4:!aNULL:!eNULL:!MD5'
180180)
181181
182- # Restricted and more secure ciphers
182+ # Restricted and more secure ciphers for the server side
183183# This list has been explicitly chosen to:
184184# * Prefer cipher suites that offer perfect forward secrecy (DHE/ECDHE)
185185# * Prefer ECDHE over DHE for better performance
@@ -188,7 +188,7 @@ def _import_symbols(prefix):
188188# * Then Use 3DES as fallback which is secure but slow
189189# * Disable NULL authentication, NULL encryption, MD5 MACs, DSS, and RC4 for
190190# security reasons
191- _RESTRICTED_CIPHERS = (
191+ _RESTRICTED_SERVER_CIPHERS = (
192192 'ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+HIGH:'
193193 'DH+HIGH:ECDH+3DES:DH+3DES:RSA+AESGCM:RSA+AES:RSA+HIGH:RSA+3DES:!aNULL:'
194194 '!eNULL:!MD5:!DSS:!RC4'
@@ -404,17 +404,35 @@ def create_default_context(purpose=Purpose.SERVER_AUTH, *, cafile=None,
404404 """
405405 if not isinstance (purpose , _ASN1Object ):
406406 raise TypeError (purpose )
407- context = SSLContext (PROTOCOL_TLSv1 )
407+
408+ context = SSLContext (PROTOCOL_SSLv23 )
409+
408410 # SSLv2 considered harmful.
409411 context .options |= OP_NO_SSLv2
412+
413+ # SSLv3 has problematic security and is only required for really old
414+ # clients such as IE6 on Windows XP
415+ context .options |= OP_NO_SSLv3
416+
410417 # disable compression to prevent CRIME attacks (OpenSSL 1.0+)
411418 context .options |= getattr (_ssl , "OP_NO_COMPRESSION" , 0 )
412- # disallow ciphers with known vulnerabilities
413- context .set_ciphers (_RESTRICTED_CIPHERS )
414- # verify certs and host name in client mode
419+
415420 if purpose == Purpose .SERVER_AUTH :
421+ # verify certs and host name in client mode
416422 context .verify_mode = CERT_REQUIRED
417423 context .check_hostname = True
424+ elif purpose == Purpose .CLIENT_AUTH :
425+ # Prefer the server's ciphers by default so that we get stronger
426+ # encryption
427+ context .options |= getattr (_ssl , "OP_CIPHER_SERVER_PREFERENCE" , 0 )
428+
429+ # Use single use keys in order to improve forward secrecy
430+ context .options |= getattr (_ssl , "OP_SINGLE_DH_USE" , 0 )
431+ context .options |= getattr (_ssl , "OP_SINGLE_ECDH_USE" , 0 )
432+
433+ # disallow ciphers with known vulnerabilities
434+ context .set_ciphers (_RESTRICTED_SERVER_CIPHERS )
435+
418436 if cafile or capath or cadata :
419437 context .load_verify_locations (cafile , capath , cadata )
420438 elif context .verify_mode != CERT_NONE :
0 commit comments