@@ -2761,6 +2761,46 @@ fails or if it does provide enough data to seed PRNG.");
27612761
27622762#endif
27632763
2764+ PyDoc_STRVAR (PySSL_get_default_verify_paths_doc ,
2765+ "get_default_verify_paths() -> tuple\n\
2766+ \n\
2767+ Return search paths and environment vars that are used by SSLContext's\n\
2768+ set_default_verify_paths() to load default CAs. The values are\n\
2769+ 'cert_file_env', 'cert_file', 'cert_dir_env', 'cert_dir'." );
2770+
2771+ static PyObject *
2772+ get_default_verify_paths (PyObject * self )
2773+ {
2774+ PyObject * ofile_env = NULL ;
2775+ PyObject * ofile = NULL ;
2776+ PyObject * odir_env = NULL ;
2777+ PyObject * odir = NULL ;
2778+
2779+ #define convert (info , target ) { \
2780+ const char *tmp = (info); \
2781+ target = NULL; \
2782+ if (!tmp) { Py_INCREF(Py_None); target = Py_None; } \
2783+ else if ((target = PyUnicode_DecodeFSDefault(tmp)) == NULL) { \
2784+ target = PyBytes_FromString(tmp); } \
2785+ if (!target) goto error; \
2786+ } while(0)
2787+
2788+ convert (X509_get_default_cert_file_env (), ofile_env );
2789+ convert (X509_get_default_cert_file (), ofile );
2790+ convert (X509_get_default_cert_dir_env (), odir_env );
2791+ convert (X509_get_default_cert_dir (), odir );
2792+ #undef convert
2793+
2794+ return Py_BuildValue ("(OOOO)" , ofile_env , ofile , odir_env , odir );
2795+
2796+ error :
2797+ Py_XDECREF (ofile_env );
2798+ Py_XDECREF (ofile );
2799+ Py_XDECREF (odir_env );
2800+ Py_XDECREF (odir );
2801+ return NULL ;
2802+ }
2803+
27642804
27652805
27662806/* List of functions exported by this module. */
@@ -2779,6 +2819,8 @@ static PyMethodDef PySSL_methods[] = {
27792819 PySSL_RAND_egd_doc },
27802820 {"RAND_status" , (PyCFunction )PySSL_RAND_status , METH_NOARGS ,
27812821 PySSL_RAND_status_doc },
2822+ {"get_default_verify_paths" , (PyCFunction )get_default_verify_paths ,
2823+ METH_NOARGS , PySSL_get_default_verify_paths_doc },
27822824#endif
27832825 {NULL , NULL } /* Sentinel */
27842826};
0 commit comments