summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2010-04-05 21:40:07 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2010-04-05 21:40:07 (GMT)
commit04f6a32dff60d6f22b56b887338dd6ebbdc68dfe (patch)
tree1a8163e2cb9880e4502ac3dbbda2cdcd9e0d0e3a /Modules
parentc50846aaef3e38d466ac9a0a87f72f09238e2061 (diff)
downloadcpython-04f6a32dff60d6f22b56b887338dd6ebbdc68dfe.zip
cpython-04f6a32dff60d6f22b56b887338dd6ebbdc68dfe.tar.gz
cpython-04f6a32dff60d6f22b56b887338dd6ebbdc68dfe.tar.bz2
Merged revisions 79812 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r79812 | antoine.pitrou | 2010-04-05 23:35:07 +0200 (lun., 05 avril 2010) | 5 lines 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')
-rw-r--r--Modules/_ssl.c31
1 files changed, 30 insertions, 1 deletions
diff --git a/Modules/_ssl.c b/Modules/_ssl.c
index 66fd626..a41fd17 100644
--- a/Modules/_ssl.c
+++ b/Modules/_ssl.c
@@ -1636,7 +1636,9 @@ static struct PyModuleDef _sslmodule = {
PyMODINIT_FUNC
PyInit__ssl(void)
{
- PyObject *m, *d;
+ PyObject *m, *d, *r;
+ unsigned long libver;
+ unsigned int major, minor, fix, patch, status;
PySocketModule_APIObject *socket_api;
if (PyType_Ready(&PySSL_Type) < 0)
@@ -1710,5 +1712,32 @@ PyInit__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 NULL;
+ if (PyModule_AddObject(m, "OPENSSL_VERSION_NUMBER", r))
+ return NULL;
+ 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 NULL;
+ r = PyUnicode_FromString(SSLeay_version(SSLEAY_VERSION));
+ if (r == NULL || PyModule_AddObject(m, "OPENSSL_VERSION", r))
+ return NULL;
+
return m;
}