Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7128f95

Browse files
committed
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.
2 parents 4468e55 + b9ac25d commit 7128f95

4 files changed

Lines changed: 32 additions & 10 deletions

File tree

Lib/ssl.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@
7878
from _ssl import HAS_SNI
7979
from _ssl import (PROTOCOL_SSLv3, PROTOCOL_SSLv23,
8080
PROTOCOL_TLSv1)
81+
from _ssl import _OPENSSL_API_VERSION
82+
8183
_PROTOCOL_NAMES = {
8284
PROTOCOL_TLSv1: "TLSv1",
8385
PROTOCOL_SSLv23: "SSLv23",

Lib/test/test_ssl.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def handle_error(prefix):
6060

6161
def can_clear_options():
6262
# 0.9.8m or higher
63-
return ssl.OPENSSL_VERSION_INFO >= (0, 9, 8, 13, 15)
63+
return ssl._OPENSSL_API_VERSION >= (0, 9, 8, 13, 15)
6464

6565
def no_sslv2_implies_sslv3_hello():
6666
# 0.9.7h or higher

Misc/NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,6 +1004,10 @@ Extension Modules
10041004
Tests
10051005
-----
10061006

1007+
- Issue #12440: When testing whether some bits in SSLContext.options can be
1008+
reset, check the version of the OpenSSL headers Python was compiled against,
1009+
rather than the runtime version of the OpenSSL library.
1010+
10071011
- Issue #11512: Add a test suite for the cgitb module. Patch by Robbie Clemons.
10081012

10091013
- Issue #12497: Install test/data to prevent failures of the various codecmaps

Modules/_ssl.c

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2101,6 +2101,24 @@ static struct PyModuleDef _sslmodule = {
21012101
NULL
21022102
};
21032103

2104+
2105+
static void
2106+
parse_openssl_version(unsigned long libver,
2107+
unsigned int *major, unsigned int *minor,
2108+
unsigned int *fix, unsigned int *patch,
2109+
unsigned int *status)
2110+
{
2111+
*status = libver & 0xF;
2112+
libver >>= 4;
2113+
*patch = libver & 0xFF;
2114+
libver >>= 8;
2115+
*fix = libver & 0xFF;
2116+
libver >>= 8;
2117+
*minor = libver & 0xFF;
2118+
libver >>= 8;
2119+
*major = libver & 0xFF;
2120+
}
2121+
21042122
PyMODINIT_FUNC
21052123
PyInit__ssl(void)
21062124
{
@@ -2213,21 +2231,19 @@ PyInit__ssl(void)
22132231
return NULL;
22142232
if (PyModule_AddObject(m, "OPENSSL_VERSION_NUMBER", r))
22152233
return NULL;
2216-
status = libver & 0xF;
2217-
libver >>= 4;
2218-
patch = libver & 0xFF;
2219-
libver >>= 8;
2220-
fix = libver & 0xFF;
2221-
libver >>= 8;
2222-
minor = libver & 0xFF;
2223-
libver >>= 8;
2224-
major = libver & 0xFF;
2234+
parse_openssl_version(libver, &major, &minor, &fix, &patch, &status);
22252235
r = Py_BuildValue("IIIII", major, minor, fix, patch, status);
22262236
if (r == NULL || PyModule_AddObject(m, "OPENSSL_VERSION_INFO", r))
22272237
return NULL;
22282238
r = PyUnicode_FromString(SSLeay_version(SSLEAY_VERSION));
22292239
if (r == NULL || PyModule_AddObject(m, "OPENSSL_VERSION", r))
22302240
return NULL;
22312241

2242+
libver = OPENSSL_VERSION_NUMBER;
2243+
parse_openssl_version(libver, &major, &minor, &fix, &patch, &status);
2244+
r = Py_BuildValue("IIIII", major, minor, fix, patch, status);
2245+
if (r == NULL || PyModule_AddObject(m, "_OPENSSL_API_VERSION", r))
2246+
return NULL;
2247+
22322248
return m;
22332249
}

0 commit comments

Comments
 (0)