Search code examples
pythonpython-3.xsslcpython

Where is the python ssl.CERT_REQUIRED defined?


Where is the python ssl.CERT_REQUIRED defined?

I searched in the ssl.py, (https://github.com/python/cpython/blob/00464bbed66e5f64bdad7f930b315a88d5afccae/Lib/ssl.py), it seems there is only usage, no declaration found, how it works?


Solution

  • It's defined in sslmodule_init_constants(PyObject*) of Modules/_ssl.c:

        PyModule_AddIntConstant(m, "CERT_REQUIRED",
                                PY_SSL_CERT_REQUIRED);
    

    where PY_SSL_CERT_REQUIRED is defined in the enum

    enum py_ssl_cert_requirements {
        PY_SSL_CERT_NONE,
        PY_SSL_CERT_OPTIONAL,
        PY_SSL_CERT_REQUIRED
    };