Issue #12440: When testing whether some bits in SSLContext.options can be
authorAntoine Pitrou <solipsis@pitrou.net>
Fri, 8 Jul 2011 16:47:06 +0000 (18:47 +0200)
committerAntoine Pitrou <solipsis@pitrou.net>
Fri, 8 Jul 2011 16:47:06 +0000 (18:47 +0200)
reset, check the version of the OpenSSL headers Python was compiled against,
rather than the runtime version of the OpenSSL library.

Lib/ssl.py
Lib/test/test_ssl.py
Misc/NEWS
Modules/_ssl.c

index e9e9aa8db0455ab623f840a4a002cf3329a7df9c..ce9ebdf30ae6fa9e51ff8331890dedbd49f8fadf 100644 (file)
@@ -77,6 +77,8 @@ from _ssl import (
     )
 from _ssl import HAS_SNI
 from _ssl import PROTOCOL_SSLv3, PROTOCOL_SSLv23, PROTOCOL_TLSv1
+from _ssl import _OPENSSL_API_VERSION
+
 _PROTOCOL_NAMES = {
     PROTOCOL_TLSv1: "TLSv1",
     PROTOCOL_SSLv23: "SSLv23",
index 7edf5b2991bbf20ca4eeb5ce0fbf898090fda554..869381a5016b467734c6c5be8fd0538520b07eec 100644 (file)
@@ -60,7 +60,7 @@ def handle_error(prefix):
 
 def can_clear_options():
     # 0.9.8m or higher
-    return ssl.OPENSSL_VERSION_INFO >= (0, 9, 8, 13, 15)
+    return ssl._OPENSSL_API_VERSION >= (0, 9, 8, 13, 15)
 
 def no_sslv2_implies_sslv3_hello():
     # 0.9.7h or higher
index 0bc7cd76e045ad56de815a87f7141a681720ae44..018d79923438b8526588803db65adc7dabe300f5 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -47,6 +47,10 @@ C-API
 Tests
 -----
 
+- Issue #12440: When testing whether some bits in SSLContext.options can be
+  reset, check the version of the OpenSSL headers Python was compiled against,
+  rather than the runtime version of the OpenSSL library.
+
 - Issue #12497: Install test/data to prevent failures of the various codecmaps
   tests.
 
index a813d5fef27c80cef81ddd6b03730aa1b56595c7..27dcdbc5730dcc46927c8c576ae043d268d1f923 100644 (file)
@@ -2037,6 +2037,24 @@ static struct PyModuleDef _sslmodule = {
     NULL
 };
 
+
+static void
+parse_openssl_version(unsigned long libver,
+                      unsigned int *major, unsigned int *minor,
+                      unsigned int *fix, unsigned int *patch,
+                      unsigned int *status)
+{
+    *status = libver & 0xF;
+    libver >>= 4;
+    *patch = libver & 0xFF;
+    libver >>= 8;
+    *fix = libver & 0xFF;
+    libver >>= 8;
+    *minor = libver & 0xFF;
+    libver >>= 8;
+    *major = libver & 0xFF;
+}
+
 PyMODINIT_FUNC
 PyInit__ssl(void)
 {
@@ -2149,15 +2167,7 @@ PyInit__ssl(void)
         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;
+    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 NULL;
@@ -2165,5 +2175,11 @@ PyInit__ssl(void)
     if (r == NULL || PyModule_AddObject(m, "OPENSSL_VERSION", r))
         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))
+        return NULL;
+
     return m;
 }