(purpose=Purpose.SERVER_AUTH, *, cafile=None,
                           capath=None, cadata=None)
return context
Create a SSLContext object with default settings.

    NOTE: The protocol and settings may change anytime without prior
          deprecation. The values represent a fair balance between maximum
          compatibility and security.
Create a SSLContext object with default settings.
Create a SSLContext object with default settings .
def create_default_context(purpose=Purpose.SERVER_AUTH, *, cafile=None,
                           capath=None, cadata=None):
    """Create a SSLContext object with default settings.

    NOTE: The protocol and settings may change anytime without prior
          deprecation. The values represent a fair balance between maximum
          compatibility and security.
    """
    if not isinstance(purpose, _ASN1Object):
        raise TypeError(purpose)

    # SSLContext sets OP_NO_SSLv2, OP_NO_SSLv3, OP_NO_COMPRESSION,
    # OP_CIPHER_SERVER_PREFERENCE, OP_SINGLE_DH_USE and OP_SINGLE_ECDH_USE
    # by default.
    if purpose == Purpose.SERVER_AUTH:
        # verify certs and host name in client mode
        context = SSLContext(PROTOCOL_TLS_CLIENT)
        context.verify_mode = CERT_REQUIRED
        context.check_hostname = True
    elif purpose == Purpose.CLIENT_AUTH:
        context = SSLContext(PROTOCOL_TLS_SERVER)
    else:
        raise ValueError(purpose)

    if cafile or capath or cadata:
        context.load_verify_locations(cafile, capath, cadata)
    elif context.verify_mode != CERT_NONE:
        # no explicit cafile, capath or cadata but the verify mode is
        # CERT_OPTIONAL or CERT_REQUIRED. Let's try to load default system
        # root CA certificates for the given purpose. This may fail silently.
        context.load_default_certs(purpose)
    # OpenSSL 1.1.1 keylog file
    if hasattr(context, 'keylog_filename'):
        keylogfile = os.environ.get('SSLKEYLOGFILE')
        if keylogfile and not sys.flags.ignore_environment:
            context.keylog_filename = keylogfile
    return context
def create_default_context ( purpose = Purpose . SERVER_AUTH , * , cafile = None , capath = None , cadata = None ) : if not isinstance ( purpose , _ASN1Object ) : raise TypeError ( purpose ) # SSLContext sets OP_NO_SSLv2, OP_NO_SSLv3, OP_NO_COMPRESSION, # OP_CIPHER_SERVER_PREFERENCE, OP_SINGLE_DH_USE and OP_SINGLE_ECDH_USE # by default. if purpose == Purpose . SERVER_AUTH : # verify certs and host name in client mode context = SSLContext ( PROTOCOL_TLS_CLIENT ) context . verify_mode = CERT_REQUIRED context . check_hostname = True elif purpose == Purpose . CLIENT_AUTH : context = SSLContext ( PROTOCOL_TLS_SERVER ) else : raise ValueError ( purpose ) if cafile or capath or cadata : context . load_verify_locations ( cafile , capath , cadata ) elif context . verify_mode != CERT_NONE : # no explicit cafile, capath or cadata but the verify mode is # CERT_OPTIONAL or CERT_REQUIRED. Let's try to load default system # root CA certificates for the given purpose. This may fail silently. context . load_default_certs ( purpose ) # OpenSSL 1.1.1 keylog file if hasattr ( context , 'keylog_filename' ) : keylogfile = os . environ . get ( 'SSLKEYLOGFILE' ) if keylogfile and not sys . flags . ignore_environment : context . keylog_filename = keylogfile return context