8000 bpo-42333: Port _ssl extension module to heap types (GH-23392) by tiran · Pull Request #23392 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-42333: Port _ssl extension module to heap types (GH-23392) #23392

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Nov 20, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Move constants and version info
  • Loading branch information
tiran committed Nov 19, 2020
commit 0f88e0b29bd5c98b599fd2efc71242683ee1c064
155 changes: 86 additions & 69 deletions Modules/_ssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -6080,24 +6080,6 @@ sslmodule_init_errorcodes(PyObject *module)
return 0;
}

PyDoc_STRVAR(module_doc,
"Implementation module for SSL socket operations. See the socket module\n\
for documentation.");


static struct PyModuleDef _sslmodule = {
PyModuleDef_HEAD_INIT,
"_ssl",
module_doc,
-1,
PySSL_methods,
NULL,
NULL,
NULL,
NULL
};


static void
parse_openssl_version(unsigned long libver,
unsigned int *major, unsigned int *minor,
Expand All @@ -6115,49 +6097,43 @@ parse_openssl_version(unsigned long libver,
*major = libver & 0xFF;
}

PyMODINIT_FUNC
PyInit__ssl(void)
static int
sslmodule_init_versioninfo(PyObject *m)
{
PyObject *m, *r;
PyObject *r;
unsigned long libver;
unsigned int major, minor, fix, patch, status;
PySocketModule_APIObject *socket_api;

m = PyModule_Create(&_sslmodule);
if (m == NULL)
return NULL;
/* OpenSSL version */
/* SSLeay() gives us the version of the library linked against,
which could be different from the headers version.
*/
libver = OpenSSL_version_num();
r = PyLong_FromUnsignedLong(libver);
if (r == NULL || PyModule_AddObject(m, "OPENSSL_VERSION_NUMBER", r))
return -1;

if (sslmodule_init_types(m) != 0)
return NULL;
if (sslmodule_init_exceptions(m) != 0)
return NULL;
if (sslmodule_init_errorcodes(m) != 0)
return NULL;
parse_openssl_version(libver, &major, &minor, &fix, &patch, &status);
r = Py_BuildValue("IIIII", major, minor, fix, patch, status);
if (r == NULL || PyModule_AddObject(m, "OPENSSL_VERSION_INFO", r))
return -1;

/* Load _socket module and its C API */
socket_api = PySocketModule_ImportModuleAndAPI();
if (!socket_api)
return NULL;
PySocketModule = *socket_api;
r = PyUnicode_FromString(OpenSSL_version(OPENSSL_VERSION));
if (r == NULL || PyModule_AddObject(m, "OPENSSL_VERSION", r))
return -1;

#ifndef OPENSSL_VERSION_1_1
/* Load all algorithms and initialize cpuid */
OPENSSL_add_all_algorithms_noconf();
/* Init OpenSSL */
SSL_load_error_strings();
SSL_library_init();
#endif
libver = OPENSSL_VERSION_NUMBER;
parse_openssl_version(libver, &major, &minor, &fix, &patch, &status);
r = Py_BuildValue("IIIII", major, minor, fix, patch, status);
if (r == NULL || PyModule_AddObject(m, "_OPENSSL_API_VERSION", r))
return -1;

#ifdef HAVE_OPENSSL_CRYPTO_LOCK
/* note that this will start threading if not already started */
if (!_setup_ssl_threads()) {
return NULL;
}
#elif OPENSSL_VERSION_1_1
/* OpenSSL 1.1.0 builtin thread support is enabled */
_ssl_locks_count++;
#endif
return 0;
}

static int
sslmodule_init_constants(PyObject *m)
{
PyModule_AddStringConstant(m, "_DEFAULT_CIPHERS",
PY_SSL_DEFAULT_CIPHER_STRING);

Expand Down Expand Up @@ -6414,29 +6390,70 @@ PyInit__ssl(void)
addbool(m, "HAS_TLSv1_3", 0);
#endif

/* OpenSSL version */
/* SSLeay() gives us the version of the library linked against,
which could be different from the headers version.
*/
libver = OpenSSL_version_num();
r = PyLong_FromUnsignedLong(libver);
if (r == NULL)
return 0;
}

PyDoc_STRVAR(module_doc,
"Implementation module for SSL socket operations. See the socket module\n\
for documentation.");


static struct PyModuleDef _sslmodule = {
PyModuleDef_HEAD_INIT,
"_ssl",
module_doc,
-1,
PySSL_methods,
NULL,
NULL,
NULL,
NULL
};

PyMODINIT_FUNC
PyInit__ssl(void)
{
PyObject *m;
PySocketModule_APIObject *socket_api;

m = PyModule_Create(&_sslmodule);
if (m == NULL)
return NULL;

if (sslmodule_init_types(m) != 0)
return NULL;
if (PyModule_AddObject(m, "OPENSSL_VERSION_NUMBER", r))
if (sslmodule_init_exceptions(m) != 0)
return NULL;
parse_openssl_version(libver, &major, &minor, &fix, &patch, &status);
r = Py_BuildValue("IIIII", major, minor, fix, patch, status);
if (r == NULL || PyModule_AddObject(m, "OPENSSL_VERSION_INFO", r))
if (sslmodule_init_errorcodes(m) != 0)
return NULL;
r = PyUnicode_FromString(OpenSSL_version(OPENSSL_VERSION));
if (r == NULL || PyModule_AddObject(m, "OPENSSL_VERSION", r))
if (sslmodule_init_constants(m) != 0)
return NULL;
if (sslmodule_init_versioninfo(m) != 0)
return NULL;

libver = OPENSSL_VERSION_NUMBER;
parse_openssl_version(libver, &major, &minor, &fix, &patch, &status);
r = Py_BuildValue("IIIII", major, minor, fix, patch, status);
if (r == NULL || PyModule_AddObject(m, "_OPENSSL_API_VERSION", r))
/* Load _socket module and its C API */
socket_api = PySocketModule_ImportModuleAndAPI();
if (!socket_api)
return NULL;
PySocketModule = *socket_api;

#ifndef OPENSSL_VERSION_1_1
/* Load all algorithms and initialize cpuid */
OPENSSL_add_all_algorithms_noconf();
/* Init OpenSSL */
SSL_load_error_strings();
SSL_library_init();
#endif

#ifdef HAVE_OPENSSL_CRYPTO_LOCK
/* note that this will start threading if not already started */
if (!_setup_ssl_threads()) {
return NULL;
}
#elif OPENSSL_VERSION_1_1
/* OpenSSL 1.1.0 builtin thread support is enabled */
_ssl_locks_count++;
#endif

return m;
}
0