← Back to DAGDA | Support | Source: https://github.com/python/cpython/commit/e6940856bb79526b78c4337ea17207595aaeb408
Skip to content

Commit e694085

Browse files
committed
Add CRYPTO_DLL_PATH and SSL_DLL_PATH to the _ssl module.
This allows an application which wants to use the OpenSSL crypto or ssl libraries via ctypes or cffi to find the path to the librares that are used by _ssl.c.
1 parent eca7a15 commit e694085

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

‎Modules/_ssl.c‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,31 @@
6565
# error "OPENSSL_THREADS is not defined, Python requires thread-safe OpenSSL"
6666
#endif
6767

68+
#if defined(HAVE_DLFCN_H)
69+
#include <dlfcn.h>
70+
#elif defined(MS_WIN32) || defined(MS_WIN64)
71+
#define WINDOWS_LEAN_AND_MEAN
72+
#include "windows.h"
6873

74+
#define HAVE_DLFCN_H
75+
76+
typedef struct {
77+
char dli_fname[MAX_PATH];
78+
} Dl_info;
79+
80+
static int dladdr(const void *addr, Dl_info *info)
81+
{
82+
HMODULE hmodule;
83+
if (GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS |
84+
GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
85+
(LPCSTR)addr, &hmodule)) {
86+
if (GetModuleFileName(hmodule, info->dli_fname, sizeof(info->dli_fname))) {
87+
info->dli_fname[sizeof(info->dli_fname)-1] = '\0';
88+
}
89+
}
90+
return 1;
91+
}
92+
#endif
6993

7094
struct py_ssl_error_code {
7195
const char *mnemonic;
@@ -5839,6 +5863,16 @@ sslmodule_init_constants(PyObject *m)
58395863
PyModule_AddIntConstant(m, "VERIFY_X509_TRUSTED_FIRST",
58405864
X509_V_FLAG_TRUSTED_FIRST);
58415865

5866+
#ifdef HAVE_DLFCN_H
5867+
{
5868+
Dl_info info;
5869+
if (dladdr(OpenSSL_version, &info))
5870+
PyModule_AddStringConstant(m, "CRYPTO_DLL_PATH", info.dli_fname);
5871+
if (dladdr(SSL_version, &info))
5872+
PyModule_AddStringConstant(m, "SSL_DLL_PATH", info.dli_fname);
5873+
}
5874+
#endif
5875+
58425876
#ifdef X509_V_FLAG_PARTIAL_CHAIN
58435877
PyModule_AddIntConstant(m, "VERIFY_X509_PARTIAL_CHAIN",
58445878
X509_V_FLAG_PARTIAL_CHAIN);

0 commit comments

Comments
 (0)