summaryrefslogtreecommitdiff
path: root/Modules/_ssl.c
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2010-04-05 21:35:07 +0000
committerAntoine Pitrou <solipsis@pitrou.net>2010-04-05 21:35:07 +0000
commitf9de534c218cfdab5b4114e6ed535c940ae6b8b5 (patch)
tree176bd640ca6f0c8d17f0a2644fcd734bc44d8580 /Modules/_ssl.c
parentfce1d31d4710c0280e2b646f72174de79a713430 (diff)
downloadcpython-git-f9de534c218cfdab5b4114e6ed535c940ae6b8b5.tar.gz
Issue #8321: Give access to OpenSSL version numbers from the `ssl` module,
using the new attributes `ssl.OPENSSL_VERSION`, `ssl.OPENSSL_VERSION_INFO` and `ssl.OPENSSL_VERSION_NUMBER`.
Diffstat (limited to 'Modules/_ssl.c')
-rw-r--r--Modules/_ssl.c30
1 files changed, 29 insertions, 1 deletions
diff --git a/Modules/_ssl.c b/Modules/_ssl.c
index 52fdf0ffd3..6befbefc9c 100644
--- a/Modules/_ssl.c
+++ b/Modules/_ssl.c
@@ -1574,7 +1574,9 @@ for documentation.");
PyMODINIT_FUNC
init_ssl(void)
{
- PyObject *m, *d;
+ PyObject *m, *d, *r;
+ unsigned long libver;
+ unsigned int major, minor, fix, patch, status;
Py_TYPE(&PySSL_Type) = &PyType_Type;
@@ -1644,4 +1646,30 @@ init_ssl(void)
PY_SSL_VERSION_SSL23);
PyModule_AddIntConstant(m, "PROTOCOL_TLSv1",
PY_SSL_VERSION_TLS1);
+
+ /* OpenSSL version */
+ /* SSLeay() gives us the version of the library linked against,
+ which could be different from the headers version.
+ */
+ libver = SSLeay();
+ r = PyLong_FromUnsignedLong(libver);
+ if (r == NULL)
+ return;
+ if (PyModule_AddObject(m, "OPENSSL_VERSION_NUMBER", r))
+ return;
+ status = libver & 0xF;
+ libver >>= 4;
+ patch = libver & 0xFF;
+ libver >>= 8;
+ fix = libver & 0xFF;
+ libver >>= 8;
+ minor = libver & 0xFF;
+ libver >>= 8;
+ major = libver & 0xFF;
+ r = Py_BuildValue("IIIII", major, minor, fix, patch, status);
+ if (r == NULL || PyModule_AddObject(m, "OPENSSL_VERSION_INFO", r))
+ return;
+ r = PyString_FromString(SSLeay_version(SSLEAY_VERSION));
+ if (r == NULL || PyModule_AddObject(m, "OPENSSL_VERSION", r))
+ return;
}